surrealdb / surrealist

Surrealist is the ultimate way to visually manage your SurrealDB database
https://surrealist.app/
MIT License
1.06k stars 81 forks source link

In-browser sandbox: Embedded functions are not enabled #181

Closed orimay closed 4 months ago

orimay commented 6 months ago

Describe your feature request In-browser sandbox doesn't allow to use embedded functions, throws error Embedded functions are not enabled. It would've been nice to have access to this functionality. Thank you!

Are you willing to contribute this feature? I am not willing to contribute

macjuul commented 4 months ago

Unfortunately this isn't currently supported as the JavaScript engine doesn't compile to WebAssembly

orimay commented 2 months ago

@macjuul It now seems to be possible:

import {
  Surreal,
  type Emitter,
  type Engine,
  type EngineEvents,
} from 'surrealdb.js';
import { surrealdbWasmEngines } from 'surrealdb.wasm';

const db = new Surreal({
  engines: surrealdbWasmEngines({
    strict: false,
    capabilities: {
      guest_access: true,
      functions: true,
      network_targets: true,
    },
  }) as Record<string, new (emitter: Emitter<EngineEvents>) => Engine>,
});
macjuul commented 2 months ago

The functions capability refers to regular built-in and SurrealQL functions, not embedded scripting functions written in JavaScript. I cannot guarantee these will ever be supported due to the complexity behind exposing these through WebAssembly

orimay commented 2 months ago

Oh, that's a pity. Thank you!