@yydb/yydb-unknown-wasm32 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -11
- package/package.json +1 -1
- package/src/index.ts +28 -11
package/README.md
CHANGED
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
# `@yydb/yydb-unknown-wasm32`
|
|
2
2
|
|
|
3
|
-
Low-level wasm-pack artifacts for the YYDB browser core
|
|
4
|
-
[`@yydb/yydb/wasm`](https://www.npmjs.com/package/@yydb/yydb)** instead of this package.
|
|
3
|
+
Low-level wasm-pack artifacts for the YYDB browser core: init glue, schema checks, and memory / persistent sessions.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Application authors should use [`@yydb/light-db`](https://www.npmjs.com/package/@yydb/light-db), which wraps these
|
|
6
|
+
artifacts as `WasmDatabase` and `openLightDatabase`. Import this package directly only when you need the raw glue or
|
|
7
|
+
the bundled `.wasm` asset path.
|
|
9
8
|
|
|
10
9
|
## Example
|
|
11
10
|
|
|
12
11
|
```ts
|
|
13
|
-
import {
|
|
12
|
+
import { checkSchema, initWasm, yydbVersion } from '@yydb/yydb-unknown-wasm32';
|
|
14
13
|
|
|
15
14
|
await initWasm();
|
|
16
15
|
|
|
17
16
|
console.log(yydbVersion());
|
|
18
|
-
console.log(
|
|
19
|
-
checkSchema("table Setting { @@id: uuid, key: utf8 }"),
|
|
20
|
-
);
|
|
17
|
+
console.log(checkSchema('table Setting { @@id: uuid, key: utf8 }'));
|
|
21
18
|
```
|
|
22
19
|
|
|
23
20
|
Call `initWasm()` once before semantic methods. Omit `options.module` to load the bundled `lib/yydb_wasm_bg.wasm` asset.
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
Raw asset path: `@yydb/yydb-unknown-wasm32/wasm`.
|
|
26
23
|
|
|
27
|
-
[YYDB overview](https://github.com/yy-database/yydb.
|
|
24
|
+
[YYDB overview](https://github.com/yy-database/yydb) · [Browser product](https://www.npmjs.com/package/@yydb/light-db)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -26,11 +26,34 @@ export type WasmSession = {
|
|
|
26
26
|
ensureSchema(document: string): string;
|
|
27
27
|
get(key: string): string;
|
|
28
28
|
put(key: string, value: Uint8Array): string;
|
|
29
|
+
delete(key: string): string;
|
|
30
|
+
scanPrefix(prefix: string, after: string | null | undefined, limit: number): string;
|
|
31
|
+
writeBatch(body: Uint8Array): string;
|
|
32
|
+
compareExchange(key: string, expected?: Uint8Array | null, replacement?: Uint8Array | null): string;
|
|
29
33
|
getSchema(): string;
|
|
34
|
+
queryVos(source: string): string;
|
|
35
|
+
executeVosWrite(source: string): string;
|
|
36
|
+
migrateSchema(document: string, renames_json?: string | null): string;
|
|
37
|
+
begin(): string;
|
|
38
|
+
commit(): string;
|
|
39
|
+
rollback(): string;
|
|
40
|
+
checkpoint(): string;
|
|
30
41
|
info(): string;
|
|
31
42
|
setMicroHostInvoker(invoker: (payload: MicroHostInvokePayload) => unknown): void;
|
|
32
43
|
registerMicro(body: Uint8Array): string;
|
|
33
44
|
callScalar(body: Uint8Array): string;
|
|
45
|
+
/** High-level JSON descriptor for host micro registration. */
|
|
46
|
+
registerMicroJson(json: string): string;
|
|
47
|
+
/** High-level JSON args for scalar UDF invocation. */
|
|
48
|
+
callScalarJson(json: string): string;
|
|
49
|
+
/** Read-only consistency probes. Returns JSON `{ ok, report?, error? }`. */
|
|
50
|
+
doctorJson(): string;
|
|
51
|
+
/** Prepare a VOS query plan. Returns JSON `{ ok, statement_id?, ..., error? }`. */
|
|
52
|
+
prepareJson(source: string): string;
|
|
53
|
+
/** Execute a previously prepared statement. Returns JSON `{ ok, rows?, error? }`. */
|
|
54
|
+
queryPreparedJson(json: string): string;
|
|
55
|
+
/** Release a prepared statement's plan. Returns true if present. */
|
|
56
|
+
closeStatement(statementId: string): boolean;
|
|
34
57
|
close(): void;
|
|
35
58
|
readonly path?: string;
|
|
36
59
|
};
|
|
@@ -51,19 +74,13 @@ function assertReady(): void {
|
|
|
51
74
|
}
|
|
52
75
|
}
|
|
53
76
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (typeof process !== 'undefined' && process.versions?.node) {
|
|
57
|
-
const { readFileSync } = await import('node:fs');
|
|
58
|
-
const { fileURLToPath } = await import('node:url');
|
|
59
|
-
return readFileSync(fileURLToPath(wasmUrl));
|
|
60
|
-
}
|
|
61
|
-
return wasmUrl;
|
|
77
|
+
function resolveDefaultWasmUrl(): URL {
|
|
78
|
+
return new URL('../lib/yydb_wasm_bg.wasm', import.meta.url);
|
|
62
79
|
}
|
|
63
80
|
|
|
64
|
-
|
|
81
|
+
function normalizeInitInput(input: WasmInitInput | undefined): WasmInitInput | ArrayBuffer | Uint8Array {
|
|
65
82
|
if (input === undefined) {
|
|
66
|
-
return
|
|
83
|
+
return resolveDefaultWasmUrl();
|
|
67
84
|
}
|
|
68
85
|
if (
|
|
69
86
|
input instanceof URL ||
|
|
@@ -83,7 +100,7 @@ export async function initWasm(options: InitWasmOptions = {}): Promise<void> {
|
|
|
83
100
|
if (ready) {
|
|
84
101
|
return;
|
|
85
102
|
}
|
|
86
|
-
const moduleOrPath =
|
|
103
|
+
const moduleOrPath = normalizeInitInput(options.module);
|
|
87
104
|
await initGlue({ module_or_path: moduleOrPath });
|
|
88
105
|
ready = true;
|
|
89
106
|
}
|