Code Monkey home page Code Monkey logo

surrealdb.wasm's Introduction


 

A WebAssembly engine for the SurrealDB JavaScript SDK.


   

     

@surrealdb/wasm

A WebAssembly engine for the SurrealDB JavaScript SDK.

This library is a plugin for the SurrealDB JavaScript SDK, which can be used to run SurrealDB as an embedded database within a browser environment, not server side environments.

It enables SurrealDB to be run in-memory, or to persist data by running on top of IndexedDB. It allows for a consistent JavaScript and TypeScript API when using the surrealdb.js library by adding support for embedded storage engines (memory, indxdb) alongside the remote connection protocols (http, https, ws, wss).

This library works with ES modules (import), not CommonJS (require).

Example usage

import { Surreal } from 'surrealdb';
import { surrealdbWasmEngines } from '@surrealdb/wasm';

// Enable the WebAssembly engines
const db = new Surreal({
    engines: surrealdbWasmEngines(),
});

// Now we can start SurrealDB as an in-memory database
await db.connect("mem://");
// Or we can start a persisted IndexedDB database
await db.connect("indxdb://demo");

// Now use the JavaScript SDK as normal.

Usage with Vite

When using Vite the following configuration is recommended to be placed in your vite.config.ts

optimizeDeps: {
    exclude: ['@surrealdb/wasm', 'surrealql.wasm'],
    esbuildOptions: {
        target: 'esnext',
    },
},
esbuild: {
    supported: {
        'top-level-await': true
    },
}

surrealdb.wasm's People

Contributors

kearfy avatar macjuul avatar naisofly avatar orimay avatar raphaeldarley avatar rushmorem avatar tobiemh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

surrealdb.wasm's Issues

Consider adding todo list

I'd like to help out with this library as WASM, and Rust in general is my native tongue. Perhaps adding a list of tasks that need to be done, or throwing up issues, even internal ones, so people like myself can take a swing at them, would be great!

Top-level await is not available in the configured target environment

I have run into several issues trying to use this package in an Electron environment, so I have now created a minimal Vue.js app with Vite to see if the issues are Electron related.

I am now encountering a different issue.

I have the following file, based on the example in the README:

import { Surreal } from 'surrealdb.wasm';

const db = new Surreal();

try {
    // Connect to the database
    await db.connect("indxdb");
} catch (e) {
    console.error("ERROR", e);
}

export default db

In my entry point file I have:

import { createApp } from 'vue'
import db from './db'
import './style.css'
import App from './App.vue'

createApp(App).mount('#app')

Running yarn dev I get a number of errors relating to top level await being used in surrealdb.wasm/dist/full/index.js

Screenshot 2023-07-19 at 1 39 22 pm

Bug: recursive use of an object detected which would lead to unsafe aliasing in rust

Describe the bug

I keep getting the same error, can't track the root of where it's coming from.

patched.js:1121 
 Uncaught 
Error: recursive use of an object detected which would lead to unsafe aliasing in rust
    at __wbindgen_throw (patched.js:1121:19)
    at 036c96f6:0xbb3af6
    at 036c96f6:0xbb3b05
    at 036c96f6:0xa8912e
    at 036c96f6:0x4c57dc
    at 036c96f6:0x7d5013
    at 036c96f6:0xab61d3
    at __wbg_adapter_58 (patched.js:264:10)
    at real (patched.js:231:20)
__wbindgen_throw	@	patched.js:1121
$func17604	@	036c96f6:0xbb3af6
$func17605	@	036c96f6:0xbb3b05
$func12906	@	036c96f6:0xa8912e
$func782	@	036c96f6:0x4c57dc
$func3470	@	036c96f6:0x7d5013
$__wbindgen_export_5	@	036c96f6:0xab61d3
__wbg_adapter_58	@	patched.js:264
real	@	patched.js:231
IndexedDB (async)		
(anonymous)	@	patched.js:751
handleError	@	patched.js:269
__wbg_get_5361b64cac0d0826	@	patched.js:750
$func8944	@	036c96f6:0xa1c086
$func1879	@	036c96f6:0x68527a
$func2734	@	036c96f6:0x7256e9
$func4368	@	036c96f6:0x8a7f36
$func1194	@	036c96f6:0x58df33
$func15310	@	036c96f6:0xac05be
$func169	@	036c96f6:0x1c8bc9
$func144	@	036c96f6:0x8ed9c
$func172	@	036c96f6:0x1d343b
$func2943	@	036c96f6:0x73e7ef
$func1642	@	036c96f6:0x61884f
$func854	@	036c96f6:0x4f7e35
$func782	@	036c96f6:0x4d3466
$func3470	@	036c96f6:0x7d5013
$__wbindgen_export_5	@	036c96f6:0xab61d3
__wbg_adapter_58	@	patched.js:264
real	@	patched.js:231

Steps to reproduce

Not sure if this is enough (the project is big), but here's my setup:

import { Emitter, Engine, Surreal, 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>, // this is not properly typed in surrealdb.wasm
});

Expected behaviour

Should not error out

SurrealDB version

surrealdb.js: 1.0.0-beta.9, surrealdb.wasm: 1.0.0-beta.12

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: FullText search bug. "The analyzer 'ascii' does not exist"

Describe the bug

I try to create a FullText search DEFINE INDEX IF NOT EXISTS userNameIndex ON TABLE user COLUMNS name SEARCH ANALYZER ascii BM25 HIGHLIGHTS. But Surreal gives error "The analyzer 'ascii' does not exist". And for other analyzers too. So That feature is not working in WASM.

Steps to reproduce

Create FullText Search Index DEFINE INDEX IF NOT EXISTS userNameIndex ON TABLE user COLUMNS name SEARCH ANALYZER ascii BM25 HIGHLIGHTS

Expected behaviour

For the Analyzers in the Wasm build to work like native builds of SurrealDB

SurrealDB version

surrealdb.js: 1.0.0-beta.18 ; surrealdb.wasm: 1.0.0-beta.15 and 0.9.0 ; arch64 Linux Mint 21

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Feature: live queries

Is your feature request related to a problem?

Currently, live queries are not supported

Describe the solution

New API that would utilize async generators. It would've been awesome to have it typed

Alternative methods

Use with no live queries, just track updates out of database for local IndexDB cases

SurrealDB version

surrealdb.wasm^0.7.0

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: The transaction is not active in IndexedDB

Describe the bug

Error: There was a problem with a datastore transaction: An IndexedDB error occured: failed to
execute indexed db request: TransactionInactiveError: Failed to execute 'get' on 'IDBObjectStore':
The transaction is not active.

The error being threw when executing the following statement:

await db.query('UPDATE ONLY main_chats:0000danjtr1rdkh233rjgrk08s MERGE {"name":"This virtual assistant","created":"2024-01-18T03:43:37.285Z","updated":"2024-01-18T03:43:49.715Z"}');

Steps to reproduce

It is hard to re-produce as the issue is coming out irregularly.

Expected behaviour

The SurrealQL statement should be executed successfully

SurrealDB version

surreal 1.0.0

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

`convert.rs` - `else if` chain to `match`

Issue: Big O

Something about this in a rust + wasm repo doesn't feel right :)

Solution:

Switch else if chain to match

Too early for PR's on this repo? Do not feel like you need to wait for me on updating/changing this :)

I may be jumping the gun on code audits here...

impl Convert<Value> for JsValue {
	fn convert(self) -> Value {
		if self.is_null() {
			Value::Null
		} else if self.is_undefined() {
		...

Feature: Closely matches the API of the Javascript library

Is your feature request related to a problem?

The surrealdb.js uses this code to connect:

	// Signin as a namespace, database, or root user
	await db.signin({
		user: "root",
		pass: "root",
	});

	// Select a specific namespace / database
	await db.use({ ns: "test", db: "test" });

but the surrealdb.wasm uses this code to connect:

	// Signin as a namespace, database, or root user
	await db.signin({
		username: "root",
		password: "root",
	});

	// Select a specific namespace / database
	await db.use({ namespace: "test", database: "test" });

Why not use the same params for closely matches the API of the Javascript library ?

Describe the solution

Closely matches the API of the Javascript library using the same params to connect.

Alternative methods

Use the same params for closely matches the API of the Javascript library ?

SurrealDB version

1.0.0+20231002.920cdfc for linux on x86_64

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Documentation: How can we build surrealdb.wasm with SurrealDB 2.0 Alpha?

Description

I am primarily using surrealdb in the browser, so would love the opportunity to test the new v2 alpha and provide feedback on bugs and features.

How would I go about building this? Just change the

surrealdb = { version = "1.5.2" to 2.0.0-alpha.1 in Cargo.toml?

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

The default port conflicts with the default port used by `surreal start`

The default port we use here 8000 coincides with the default surreal start port. This causes a conflict when trying to test one of the remote engines while running the SurrealDB server on the same machine with the default port. Previously we were using 8080 in this repo, which is fine as it avoids the conflict.

Feature: Proper typings

Is your feature request related to a problem?

I can see that the typings are generated automagically, but there's a bunch of anys and some function arguments are marked required (as addressed here). It would've been nice to have proper typings for the library

Describe the solution

Explicitly defined TS typings

Alternative methods

Use as is or define custom typings

SurrealDB version

surreal.wasm-v0.7.0

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Documentation: How to build surrealdb.wasm

Description

There aren't any instructions in the Readme on how to build surrealdb.wasm.

I found this comment in the discord

Heya! We really need to include this stuff in the README, sorry about that! Should be as simple as:
Having installed PNPM and Wasm-Pack
pnpm i
make build

I haven't tried it, but assume it'll work. This should be added to the readme.

Install docs for pnpm and wasm-pack

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: The demo (index.html) throwing error "Uncaught UnsupportedVersion at versionCheck"

Describe the bug

Unable to run the surrealdb.wasm in Chrome browser due to the error above.

Steps to reproduce

I clone the latest source from surrealdb.wasm repo and run the following commands:

pnpm i
make build
pnpm serve

Then, I open http://127.0.0.1:8000/ in the chrome browser, the demo (index.html) is loaded successfully. But when I tried running await surreal.connect("indxdb://test") in browser console, it is throwing the following error:

Uncaught UnsupportedVersion
    at versionCheck (http://127.0.0.1:8000/node_modules/surrealdb.js/dist/esm.bundled.js:1:34314)
    at Surreal.connect (http://127.0.0.1:8000/node_modules/surrealdb.js/dist/esm.bundled.js:1:42891)
    at async <anonymous>:1:1

Expected behaviour

It should connect successfully.

SurrealDB version

surrealdb.wasm v1.0.0-beta.13

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Feature: Smaller surrealdb.wasm binary with more feature flags

Is your feature request related to a problem?

Surrealdb.wasm is 14MB, which is quite large. It can be compressed with brotli or zstd down to about 2.5-3.5MB (depending on compression level), which is more palatable. But still large, especially if you want to make surrealdb at the core of your webapp and it therefore needs to download and load as quickly as possible. This is even moreso the case for users who have slow and/or expensive bandwidth.

Also, it isn't guaranteed that compression will always happen. Literally right now https://surrealist.app is not compressing the wasm, so it takes 5+ seconds to download and 10+ seconds for the whole site to be ready. And it was 30 seconds on my phone!

image

Describe the solution

SurrealDB is massively comprehensive, and it is highly unlikely that every application will make use of its full range of features. This is especially the case for when Surrealdb is to be run in a browser - particularly on mobile devices with limited storage and compute capability.

For example, I very much doubt that I'll want to offer my users the ability to do any of the machine learning or vector search stuff - I will reserve such things for my backend servers. In fact, I might even want to leave graph capabilities out and simply use Surrealdb.wasm as a document/kv store with full text search and live queries (something that isn't all that possible with existing javascript-based indexeddb libraries)

So, I wonder if there could be a way to offer some build config flags that allow us to only include particular features/modules in the binary? I'm sure some features simply cannot be extricated from the database, but surely some of them might be?

Alternative methods

Brotli and zstd (which is mostly supported by browsers now) can get it down to a palatable 2.5-3.5MB. But if we can "tree-shake" the binary, that would be ideal.

And shared dictionary compression is in early phases of testing, which will make static asset sizes nearly inconsequential. But it could be a while til this is ubiquitous.

SurrealDB version

all versions

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: Unable to run the Development Server (index.html) of the v1.0.0-beta.9

Describe the bug

After the development server started, the browser console reported the following error: Uncaught ReferenceError: surrealdbWasmEngines is not defined.

Initial response from Micha on May 6:

I think that that demo is actually broken at the moment. I used to include the minified version of the js and wasm library, but I realized that that caused for example the RecordID class to be defined in two different spots, which would then in turn break CBOR serialization and deserialization. A best workaround is probably to have a single JS module which imports both libraries, then bundles it all and which gets included by the html file :)

Steps to reproduce

I tried make serve and then access localhost:8000 in the browser, the ./dist/embedded/web.js not found? Then I change the code of index.html file to use ./dist/embedded/index.js, and re-run the make serve.

Expected behaviour

The Development Server should run without issue.

SurrealDB version

1.0.0-beta.9

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: ERROR Encountered a non-object value in array

Describe the bug

The db.select() and db.delete() throw the error above when the given id is not found.

Steps to reproduce

  1. Add the following code to the development server, index.html:
      const db = new Surreal();
      await db.connect("indxdb://test");
      await db.use({ namespace: "test", database: "test" });
      await db.select("person:1");
  2. Run the development server with command npm run serve.
  3. Access the http://localhost:8000 and you should see the error in developer console of Chrome browser.

Expected behaviour

It should return null or [].

SurrealDB version

1.2.0 and 1.3.0

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: jsonwebtoken dependency breaks building the surrealdb crate for WASM targets

Describe the bug

Because of an issue in the jsonwebtoken issue, it is currently not possible to build the surrealdb crate to any wasm targets on main

There already is a mostly finished PR on the jsonwebtoken package which solves the issue: Keats/jsonwebtoken#318

Steps to reproduce

Pin rev to latest commit on surrealdb main, then build

Expected behaviour

for wasm targets to build

SurrealDB version

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Feature: surrealdb.wasm without wasm-bindgen

Is your feature request related to a problem?

The original issue at surrealdb/surrealdb#2332

Describe the solution

Refer to the original issue.

Alternative methods

Refer to the original issue.

SurrealDB version

1.1.1

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Package imports aren't hinted properly in VSCode

I'm trying to import the WS module, however the imports are listed properly not sure if this is a package issue with the files it exports, tsconfig or something on my end

image

But I expect it to show: "/ws" and "/http" and not dist and lib

on version 0.6.0

Feature: relesse .wasm

Is your feature request related to a problem?

make it easy for non rust users to try this out.

Describe the solution

Can we have a .wasm release out of GitHub workflow

https://github.com/surrealdb/surrealdb.wasm/releases

then we can build up usage examples for JS or typescript devs using it.

Alternative methods

not applicable....

SurrealDB version

all

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Feature: OPFS rather than Indexeddb for Persistence

Is your feature request related to a problem?

Indexeddb is known to be slow and limited. And, when surreal is an abstraction on top of it, it has to go through many levels of abstractions - surreal.wasm > js > indexeddb > leveldb/sqlite.

(see here for info about how chromium currently uses leveldb - which rocksdb evolved out of - as the backing store for indexeddb, but are changing it to sqlite https://issues.chromium.org/issues/40253999)

Describe the solution

The Origin Private File System (OPFS) is a new-ish browser api that allows for high performance file system access. https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system

It has support of all major browsers (look at the opfs-specific footnotes) https://caniuse.com/native-filesystem-api

A high profile example of it being used is SQLite Wasm, which seemingly allows for full sqlite usage in the browser. https://developer.chrome.com/blog/sqlite-wasm-in-the-browser-backed-by-the-origin-private-file-system/

Presumably surreal's rocksdb, speedb, and tikv backends could be used in a similar manner, which would surely simplify and improve performance for your wasm efforts. Likewise surrealkv when that is ready.

Alternative methods

SQLite wasm is getting a lot of attention and would probably be the easiest and most stable option. But it doesn't appear that Surreal uses SQLite as a storage backend, so there's probably no point in looking into it.

SurrealDB version

N/a

Contact Details

Reply to this issue

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Feature: provide a pre-built surrealdb.wasm binary

Is your feature request related to a problem?

I want to try using surrealdb.wasm in a webapp, but there doesn't appear to be any wasm binary available anywhere, so I have to figure out how to build one myself. This doesnt make any sense.

Describe the solution

Provide a pre-built wasm binary for each release, perhaps even also stored in a cdn should we choose to import it like that.

Alternative methods

Building myself, which requires setting up lots of tooling and takes a long time.

SurrealDB version

all versions

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: The Development Server (index.html) is not working in 0.8.0 release

Describe the bug

I added the following code to the index.html:

const db = new Surreal();

The Chrome browser console throw the following error:

index.js:463 Uncaught TypeError: Cannot read properties of undefined (reading 'surreal_init')
    at new Surreal (index.js:463:26)
    at index.html:15:15

Appreciate the effort to fix the Development Server code as it is important to developers to learn about surrealdb.wasm.

Steps to reproduce

  1. Run the development server with npm run serve, you first need to build the wasm module before this step.
  2. Add const db = new Surreal(); to index.html.
  3. Access http://localhost:8000 from the Chrome browser, you will see the error I reported in developer console of the chrome.

Expected behaviour

No error reported. The db should instantiate successfully.

SurrealDB version

1.2.0

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Feature: Add `export`/`import` support for `indexeddb` ?

Is your feature request related to a problem?

/

Describe the solution

/

Alternative methods

/

SurrealDB version

0.6.0 for Linux

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: doesn't compile on Apple M1?

Describe the bug

After running compilation on rust level, that can be ivoced also by npm run build command after downloading sources from git, I get:
`...
Compiling cipher v0.4.4
error: failed to build archive: 'wasm32.o': section too large

The following warnings were emitted during compilation:

warning: warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: /Users/(...)/surrealdb.wasm/target/wasm32-unknown-unknown/release/build/psm-e7fd6e39c2c90a79/out/libpsm_s.a the table of contents is empty (no object file members in the library define global symbols)

error: could not compile psm (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
Error: Compiling your crate to WebAssembly failed
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute cargo build: exited with exit status: 101
full command: cd "/Users/pedropuchalski/Documents/praca/FirmaNext/sceneMgm/surrealdb.wasm" && "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown" "--no-default-features" "--features" "protocol-ws,protocol-http,kv-indxdb,kv-mem,rustls"`

Steps to reproduce

Try to compile on Apple MacBook Air with M1, Ventura.

Expected behaviour

Compiled *.wasm file.

SurrealDB version

"1.0.0", default-features = false

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: Instantiating Surreal causes "node:crypto" error

Describe the bug

Instantiating Surreal wasm within the Reactjs part of the Nextjs project causes an error:

Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).

Steps to reproduce

Create a NextJs app and instantiate the Surreal database within the page.tsx.

"use client"
import {Surreal} from 'surrealdb.wasm';
export default function NameDoesntMatter() {
  prepareSurreal();
  return(<p>demo</p>);
}

async function prepareSurreal() {
  let db  = new Surreal();
  try {
    await db.connect('memory');
    await db.use({database: "db", namespace: "ns"});
  } catch (error) {
    console.log(error)
  }
}

Expected behaviour

I expect it to instantiate the database so that I can use in-memory one, on the browser.

I expect to be able to create a new user and query that user back.

SurrealDB version

surrealdb wasm 0.8.0 ubuntu 22.04.3 LST

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Can `rlib` be added to `crate-type`?

I wanted to try and play around with the crate from within another WASM rust crate, but I can't import anything because the crate isn't being compiled as a rust library.

Currently:

[lib]
crate-type = ["cdylib"]

Could be changed to:

[lib]
crate-type = ["cdylib", "rlib"]

Documentation: add a list of API changes from 0.7 to 0.8

Description

It seems there are some breaking changes between the V0.8 and V0.7 of the surrealdb.wasm lib:

  • the 'use()' method now needs 'namespace' and 'database' instead of 'ns' and 'db'
  • the 'query()' method now always returns the results encaspsulated within an array even if there was a single result set (before, if the query was designed as returning a single result set, it would come directly as an array of values in the javascript response)

More generally, it would be appreciated to list the features/changes between versions of this wasm library. It would also be nice to cite which version of the surrealdb engine the wasm library is built on, as some SQL language features might not be available. Last suggestion: the documentation is lacking the structure of the returned values when calling the API.

Finally, the examples are lacking on how to use the library either as clientside-memory or with indexdb persistence. I could pick-up some tricks from some youtube video tutorials, but a bit tough to reach.

I believe this product is great, keep going guys!

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: surrealdbWasmEngines is not assignable to Surreal engines

Describe the bug

This:

import { Emitter, Engine, Surreal, 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,
    },
  }),
});

gives a type error:

Type '{ mem: new (emitter: Emitter<EngineEvents>) => { ready: Promise<void> | undefined; reader?: Promise<void> | undefined; status: ConnectionStatus; ... 8 more ...; readonly connected: boolean; }; indxdb: new (emitter: Emitter<...>) => { ...; }; }' is not assignable to type 'Engines'.
  Property 'mem' is incompatible with index signature.
    Type 'new (emitter: Emitter<EngineEvents>) => { ready: Promise<void> | undefined; reader?: Promise<void> | undefined; status: ConnectionStatus; ... 8 more ...; readonly connected: boolean; }' is not assignable to type 'new (emitter: Emitter<EngineEvents>) => Engine'.
      Construct signature return types '{ ready: Promise<void> | undefined; reader?: Promise<void> | undefined; status: ConnectionStatus; connection: { url?: URL | undefined; namespace?: string | undefined; database?: string | undefined; token?: string | undefined; }; ... 7 more ...; readonly connected: boolean; }' and 'Engine' are incompatible.
        The types of 'rpc' are incompatible between these types.
          Type '<Method extends string, Params extends unknown[], Result extends unknown>(request: RpcRequest<Method, Params>) => Promise<RpcResponse<Result>>' is not assignable to type '<Method extends string, Params extends unknown[] | undefined, Result extends unknown>(request: RpcRequest<Method, Params>) => Promise<RpcResponse<Result>>'.
            Types of parameters 'request' and 'request' are incompatible.
              Type 'RpcRequest<Method, Params>' is not assignable to type 'RpcRequest<Method, unknown[]>'.
                Type 'Params' is not assignable to type 'unknown[]'.
                  Type 'unknown[] | undefined' is not assignable to type 'unknown[]'.
                    Type 'undefined' is not assignable to type 'unknown[]'.ts(2322)

because typeEngine has a method

abstract rpc<Method extends string, Params extends unknown[] | undefined, Result extends unknown>(request: RpcRequest<Method, Params>): Promise<RpcResponse<Result>>;

which is

rpc<Method extends string, Params extends unknown[], Result extends unknown>(request: RpcRequest<Method, Params>): Promise<RpcResponse<Result>>;

for both mem and indxdb

Steps to reproduce

import { Emitter, Engine, Surreal, 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,
    },
  }),
});

Expected behaviour

Should not error out. Currently, I use the following fix:

import { Emitter, Engine, Surreal, 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>,
});

SurrealDB version

surrealdb.js: 1.0.0-beta.9, surrealdb.wasm: 1.0.0-beta.12

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: Statement ONLY ignored - result is always an array

Describe the bug

The newly introduced ONLY statement indicates that the result is a single result.
The result should not be wrapped into an extra array.

Steps to reproduce

--- without ONLY
CREATE test:1 SET some='value'

returns

[
    {
        "id": "test:1",
        "some": "value"
    }
]
--- with ONLY
CREATE ONLY test:2 SET some='value'

returns

[
    {
        "id": "test:2",
        "some": "value"
    }
]

Expected behaviour

The behaviour should be the same as on the regular server

--- with ONLY
CREATE ONLY test:2 SET some='value'

returns

{
    "id": "test:2",
    "some": "value"
}

Same for SELECT statement.

SurrealDB version

local build from current master - surrealdb to beta.11 - on macOS

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Bug: GitHub actions failed to build and push to npmjs

Describe the bug

The GitHub actions are failing to push v1.0.0-beta.13 to npmjs.com for some reason and still in v1.0.0-beta.12.

Steps to reproduce

Check the link:
surrealdb.wasm

Expected behaviour

The surrealdb.wasm npm package should be updated to v1.0.0-beta.13.

SurrealDB version

v1.0.0-beta.12

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.