@yydb/yydb-unknown-wasm32 0.0.17 → 0.1.0

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.
Files changed (3) hide show
  1. package/README.md +8 -11
  2. package/package.json +1 -1
  3. package/src/index.ts +9 -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. **App authors should use
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
- Import here only when you need the raw glue or bundled `.wasm` path. For durable reads and writes in production, prefer
7
- [`@yydb/yydb-client`](https://www.npmjs.com/package/@yydb/yydb-client) against `yydb serve` until wasm persistence
8
- lands.
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 {initWasm, checkSchema, yydbVersion} from "@yydb/yydb/wasm";
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
- Low-level glue: `@yydb/yydb-unknown-wasm32/wasm` (raw `.wasm` path).
22
+ Raw asset path: `@yydb/yydb-unknown-wasm32/wasm`.
26
23
 
27
- [YYDB overview](https://github.com/yy-database/yydb.rs)
24
+ [YYDB overview](https://github.com/yy-database/yydb) · [Browser product](https://www.npmjs.com/package/@yydb/light-db)
package/package.json CHANGED
@@ -39,5 +39,5 @@
39
39
  "./lib/yydb_wasm.js"
40
40
  ],
41
41
  "type": "module",
42
- "version": "0.0.17"
42
+ "version": "0.1.0"
43
43
  }
package/src/index.ts CHANGED
@@ -42,6 +42,10 @@ export type WasmSession = {
42
42
  setMicroHostInvoker(invoker: (payload: MicroHostInvokePayload) => unknown): void;
43
43
  registerMicro(body: Uint8Array): string;
44
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;
45
49
  close(): void;
46
50
  readonly path?: string;
47
51
  };
@@ -62,19 +66,13 @@ function assertReady(): void {
62
66
  }
63
67
  }
64
68
 
65
- async function resolveDefaultWasmBytes(): Promise<ArrayBuffer | Uint8Array | URL> {
66
- const wasmUrl = new URL('../lib/yydb_wasm_bg.wasm', import.meta.url);
67
- if (typeof process !== 'undefined' && process.versions?.node) {
68
- const { readFileSync } = await import('node:fs');
69
- const { fileURLToPath } = await import('node:url');
70
- return readFileSync(fileURLToPath(wasmUrl));
71
- }
72
- return wasmUrl;
69
+ function resolveDefaultWasmUrl(): URL {
70
+ return new URL('../lib/yydb_wasm_bg.wasm', import.meta.url);
73
71
  }
74
72
 
75
- async function normalizeInitInput(input: WasmInitInput | undefined): Promise<WasmInitInput | ArrayBuffer | Uint8Array> {
73
+ function normalizeInitInput(input: WasmInitInput | undefined): WasmInitInput | ArrayBuffer | Uint8Array {
76
74
  if (input === undefined) {
77
- return resolveDefaultWasmBytes();
75
+ return resolveDefaultWasmUrl();
78
76
  }
79
77
  if (
80
78
  input instanceof URL ||
@@ -94,7 +92,7 @@ export async function initWasm(options: InitWasmOptions = {}): Promise<void> {
94
92
  if (ready) {
95
93
  return;
96
94
  }
97
- const moduleOrPath = await normalizeInitInput(options.module);
95
+ const moduleOrPath = normalizeInitInput(options.module);
98
96
  await initGlue({ module_or_path: moduleOrPath });
99
97
  ready = true;
100
98
  }