Skip to content

Commit

Permalink
feat: surrealdb 2.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
macjuul committed Aug 28, 2024
1 parent 7c8e85c commit c9365b6
Show file tree
Hide file tree
Showing 11 changed files with 813 additions and 734 deletions.
1,462 changes: 784 additions & 678 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,17 @@ crate-type = ["cdylib", "rlib"]

[features]
default = []
parser-v1 = []
parser-v2 = ["surrealdb/experimental-parser"]
stack-traces = ["dep:console_error_panic_hook"]

[dependencies]
chrono = { version = "0.4.37", features = ["serde", "wasmbind"] }
surrealdb = { package = "surrealdb-core", git = "https://github.com/surrealdb/surrealdb", rev = "6fbf847", default-features = false , features = ["jwks"]}
ciborium = "0.2.1"
console_error_panic_hook = { version = "0.1.7", optional = true }
dmp = "0.2.0"
fern = "0.6.2"
futures = "0.3.30"
log = "0.4.21"
serde = { version = "1.0.197", features = ["derive"] }
serde-wasm-bindgen = "0.6.5"
serde_json = "1.0.115"
surrealdb = { package="surrealdb-core", version = "=2.0.0-1.5.2", default-features = false , features = ["jwks"]}
wasm-bindgen = "0.2.92"
wasm-bindgen-futures = "0.4.42"
web-sys = { version = "0.3.69", features = ["console"] }

[dev-dependencies]
wasm-bindgen-test = "0.3.41"
web-sys = { version = "0.3.69", features = ["console"] }
16 changes: 10 additions & 6 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import copyFilePlugin from 'esbuild-plugin-copy-file';
import fs from 'fs';

const shimContent = new Buffer.from(await fs.readFileSync('./build/shim.js'));
const targets = ['v1', 'v2'];
const targets = ['surrealql'];

await Promise.all(targets.map(build));

Expand All @@ -14,17 +14,21 @@ async function build(target) {

async function applyPatches(target) {
let content = fs.readFileSync(`compiled/${target}/index.js`).toString();
content = shimContent + content;
content = shimContent + content;

const tauriPatch = fs.readFileSync(`build/tauri.patch`).toString().split("===========\n");
content = content.replace(tauriPatch[0], tauriPatch[1]);
const tauriPatch = fs
.readFileSync("build/tauri.patch")
.toString()
.split("===========\n");

content = content.replace(tauriPatch[0], tauriPatch[1]);

fs.writeFileSync(`compiled/${target}/patched.js`, content)
fs.writeFileSync(`compiled/${target}/index.js`, content);
}

async function bundle(target) {
await esbuild.build({
entryPoints: [`compiled/${target}/patched.js`],
entryPoints: [`lib/${target}.js`],
sourcemap: true,
bundle: true,
format: "esm",
Expand Down
14 changes: 3 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@
<title>Development server</title>
</head>
<body>
<p>All exports from parser1 and parser2 is respectively assigned to window as parser1 and parser2. Open your browser console to play around with it!</p>
<p>All exports from @surrealdb/ql-wasm are assigned to "surrealql". Open your browser console to play around with it!</p>
<script type="module">
import * as v1 from './compiled/v1/index.js';
window.parser1 = {
SurrealQL: v1,
Value: v1.Value,
};
import * as surrealql from './dist/surrealql/index.js';

import * as v2 from './compiled/v2/index.js';
window.parser2 = {
SurrealQL: v2,
Value: v2.Value,
};
window.surrealql = surrealql;
</script>
</body>
</html>
4 changes: 4 additions & 0 deletions lib/surrealql.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as SurrealQL from "../compiled/surrealql";
import { Value } from "../compiled/surrealql";

export { Value, SurrealQL, SurrealQL as default };
4 changes: 4 additions & 0 deletions lib/surrealql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as SurrealQL from "../compiled/surrealql";
import { Value } from "../compiled/surrealql";

export { Value, SurrealQL, SurrealQL as default };
3 changes: 0 additions & 3 deletions lib/v1.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions lib/v1.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/v2.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions lib/v2.js

This file was deleted.

19 changes: 6 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "surrealql.wasm",
"name": "@surrealdb/ql-wasm",
"version": "0.1.8",
"packageManager": "[email protected]",
"description": "WebAssembly utility functions for SurrealQL",
Expand All @@ -13,25 +13,18 @@
},
"type": "module",
"files": [
"dist/",
"lib/"
"dist/"
],
"exports": {
"./v1": {
"types": "./lib/v1.d.ts",
"default": "./lib/v1.js"
},
"./v2": {
"types": "./lib/v2.d.ts",
"default": "./lib/v2.js"
".": {
"types": "./dist/surrealql.d.ts",
"default": "./dist/surrealql.js"
}
},
"scripts": {
"serve": "esbuild --bundle --servedir=.",
"build": "npm run compile && npm run build-literal",
"compile": "npm run compile:v1 && npm run compile:v2",
"compile:v1": "wasm-pack build --release --target deno --out-name index --out-dir compiled/v1 --no-default-features --features parser-v1",
"compile:v2": "wasm-pack build --release --target deno --out-name index --out-dir compiled/v2 --no-default-features --features parser-v2",
"compile": "wasm-pack build --release --target deno --out-name index --out-dir compiled/surrealql --no-default-features",
"build-literal": "node build/index.js"
},
"devDependencies": {
Expand Down

0 comments on commit c9365b6

Please sign in to comment.