@yydb/yydb-unknown-wasm32 0.0.15 → 0.0.16

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 +27 -27
  2. package/package.json +5 -5
  3. package/src/index.ts +150 -150
package/README.md CHANGED
@@ -1,27 +1,27 @@
1
- # `@yydb/yydb-unknown-wasm32`
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.
5
-
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.
9
-
10
- ## Example
11
-
12
- ```ts
13
- import {initWasm, checkSchema, yydbVersion} from "@yydb/yydb/wasm";
14
-
15
- await initWasm();
16
-
17
- console.log(yydbVersion());
18
- console.log(
19
- checkSchema("table Setting { @@id: uuid, key: utf8 }"),
20
- );
21
- ```
22
-
23
- Call `initWasm()` once before semantic methods. Omit `options.module` to load the bundled `lib/yydb_wasm_bg.wasm` asset.
24
-
25
- Low-level glue: `@yydb/yydb-unknown-wasm32/wasm` (raw `.wasm` path).
26
-
27
- [YYDB overview](https://github.com/yy-database/yydb.rs)
1
+ # `@yydb/yydb-unknown-wasm32`
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.
5
+
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.
9
+
10
+ ## Example
11
+
12
+ ```ts
13
+ import {initWasm, checkSchema, yydbVersion} from "@yydb/yydb/wasm";
14
+
15
+ await initWasm();
16
+
17
+ console.log(yydbVersion());
18
+ console.log(
19
+ checkSchema("table Setting { @@id: uuid, key: utf8 }"),
20
+ );
21
+ ```
22
+
23
+ Call `initWasm()` once before semantic methods. Omit `options.module` to load the bundled `lib/yydb_wasm_bg.wasm` asset.
24
+
25
+ Low-level glue: `@yydb/yydb-unknown-wasm32/wasm` (raw `.wasm` path).
26
+
27
+ [YYDB overview](https://github.com/yy-database/yydb.rs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "bugs": {
3
- "url": "https://github.com/yy-database/yydb.rs/issues"
3
+ "url": "https://github.com/yy-database/yydb/issues"
4
4
  },
5
5
  "description": "Browser WebAssembly binary for `@yydb/yydb`",
6
6
  "devDependencies": {
@@ -20,16 +20,16 @@
20
20
  "lib",
21
21
  "README.md"
22
22
  ],
23
- "homepage": "https://github.com/yy-database/yydb.rs/tree/dev/projects/packages/yydb-unknown-wasm32#readme",
23
+ "homepage": "https://github.com/yy-database/yydb/tree/dev/projects/packages/yydb-unknown-wasm32#readme",
24
24
  "license": "MPL-2.0",
25
25
  "name": "@yydb/yydb-unknown-wasm32",
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
29
  "repository": {
30
- "directory": "projects/packages/yydb-unknown-wasm32",
31
30
  "type": "git",
32
- "url": "git+https://github.com/yy-database/yydb.rs.git"
31
+ "url": "git+https://github.com/yy-database/yydb.git",
32
+ "directory": "projects/packages/yydb-unknown-wasm32"
33
33
  },
34
34
  "scripts": {
35
35
  "test": "pnpm run typecheck",
@@ -39,5 +39,5 @@
39
39
  "./lib/yydb_wasm.js"
40
40
  ],
41
41
  "type": "module",
42
- "version": "0.0.15"
42
+ "version": "0.0.16"
43
43
  }
package/src/index.ts CHANGED
@@ -1,150 +1,150 @@
1
- import initGlue, * as glue from '../lib/yydb_wasm.js';
2
-
3
- export type WasmInitInput = URL | Request | Response | ArrayBuffer | Uint8Array | WebAssembly.Module;
4
-
5
- export type InitWasmOptions = {
6
- /** When omitted, loads the bundled `lib/yydb_wasm_bg.wasm` asset. */
7
- module?: WasmInitInput;
8
- };
9
-
10
- export type CheckSchemaResult = {
11
- ok: boolean;
12
- tableCount: number;
13
- schemaFingerprint: string;
14
- error?: string;
15
- };
16
-
17
- export type MicroHostInvokePayload = {
18
- hostId: number;
19
- handleVersion: number;
20
- functionId: string;
21
- args: readonly unknown[];
22
- };
23
-
24
- /** Stateful wasm session (memory or OPFS-backed). */
25
- export type WasmSession = {
26
- ensureSchema(document: string): string;
27
- get(key: string): string;
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;
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;
41
- info(): string;
42
- setMicroHostInvoker(invoker: (payload: MicroHostInvokePayload) => unknown): void;
43
- registerMicro(body: Uint8Array): string;
44
- callScalar(body: Uint8Array): string;
45
- close(): void;
46
- readonly path?: string;
47
- };
48
-
49
- const glueApi = glue as {
50
- yydbVersion?: () => string;
51
- checkSchema?: (source: string) => CheckSchemaResult;
52
- introspectSchema?: (source: string) => string;
53
- MemorySession?: new () => WasmSession;
54
- PersistentSession?: new (path: string) => WasmSession;
55
- };
56
-
57
- let ready = false;
58
-
59
- function assertReady(): void {
60
- if (!ready) {
61
- throw new Error('@yydb/yydb-unknown-wasm32: call initWasm() before semantic core methods');
62
- }
63
- }
64
-
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;
73
- }
74
-
75
- async function normalizeInitInput(input: WasmInitInput | undefined): Promise<WasmInitInput | ArrayBuffer | Uint8Array> {
76
- if (input === undefined) {
77
- return resolveDefaultWasmBytes();
78
- }
79
- if (
80
- input instanceof URL ||
81
- input instanceof Request ||
82
- input instanceof Response ||
83
- input instanceof ArrayBuffer ||
84
- input instanceof Uint8Array ||
85
- input instanceof WebAssembly.Module
86
- ) {
87
- return input;
88
- }
89
- throw new Error(`@yydb/yydb-unknown-wasm32: unsupported WASM init input (${typeof input})`);
90
- }
91
-
92
- /** One-time WASM init. Required before semantic core methods. */
93
- export async function initWasm(options: InitWasmOptions = {}): Promise<void> {
94
- if (ready) {
95
- return;
96
- }
97
- const moduleOrPath = await normalizeInitInput(options.module);
98
- await initGlue({ module_or_path: moduleOrPath });
99
- ready = true;
100
- }
101
-
102
- /** Library version (matches workspace `@yydb/yydb` semver). */
103
- export function yydbVersion(): string {
104
- assertReady();
105
- if (!glueApi.yydbVersion) {
106
- throw new Error('@yydb/yydb-unknown-wasm32: yydbVersion export missing, rebuild wasm artifacts');
107
- }
108
- return glueApi.yydbVersion();
109
- }
110
-
111
- /** Parse and validate a VOS schema document via the Rust core. */
112
- export function checkSchema(source: string): CheckSchemaResult {
113
- assertReady();
114
- if (!glueApi.checkSchema) {
115
- throw new Error('@yydb/yydb-unknown-wasm32: checkSchema export missing, rebuild wasm artifacts');
116
- }
117
- return glueApi.checkSchema(source);
118
- }
119
-
120
- /** Read-only schema introspection JSON. */
121
- export function introspectSchema(source: string): string {
122
- assertReady();
123
- if (!glueApi.introspectSchema) {
124
- throw new Error('@yydb/yydb-unknown-wasm32: introspectSchema export missing, rebuild wasm artifacts');
125
- }
126
- return glueApi.introspectSchema(source);
127
- }
128
-
129
- /** Open a stateful in-memory session. */
130
- export function createMemorySession(): WasmSession {
131
- assertReady();
132
- if (!glueApi.MemorySession) {
133
- throw new Error('@yydb/yydb-unknown-wasm32: MemorySession export missing, rebuild wasm artifacts');
134
- }
135
- return new glueApi.MemorySession();
136
- }
137
-
138
- /** Open a stateful OPFS-backed session at `path`. */
139
- export function openPersistentSession(path: string): WasmSession {
140
- assertReady();
141
- if (!glueApi.PersistentSession) {
142
- throw new Error('@yydb/yydb-unknown-wasm32: PersistentSession export missing, rebuild wasm artifacts');
143
- }
144
- return new glueApi.PersistentSession(path);
145
- }
146
-
147
- /** @internal Reset init gate (binding tests only). */
148
- export function resetWasmBindingForTests(): void {
149
- ready = false;
150
- }
1
+ import initGlue, * as glue from '../lib/yydb_wasm.js';
2
+
3
+ export type WasmInitInput = URL | Request | Response | ArrayBuffer | Uint8Array | WebAssembly.Module;
4
+
5
+ export type InitWasmOptions = {
6
+ /** When omitted, loads the bundled `lib/yydb_wasm_bg.wasm` asset. */
7
+ module?: WasmInitInput;
8
+ };
9
+
10
+ export type CheckSchemaResult = {
11
+ ok: boolean;
12
+ tableCount: number;
13
+ schemaFingerprint: string;
14
+ error?: string;
15
+ };
16
+
17
+ export type MicroHostInvokePayload = {
18
+ hostId: number;
19
+ handleVersion: number;
20
+ functionId: string;
21
+ args: readonly unknown[];
22
+ };
23
+
24
+ /** Stateful wasm session (memory or OPFS-backed). */
25
+ export type WasmSession = {
26
+ ensureSchema(document: string): string;
27
+ get(key: string): string;
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;
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;
41
+ info(): string;
42
+ setMicroHostInvoker(invoker: (payload: MicroHostInvokePayload) => unknown): void;
43
+ registerMicro(body: Uint8Array): string;
44
+ callScalar(body: Uint8Array): string;
45
+ close(): void;
46
+ readonly path?: string;
47
+ };
48
+
49
+ const glueApi = glue as {
50
+ yydbVersion?: () => string;
51
+ checkSchema?: (source: string) => CheckSchemaResult;
52
+ introspectSchema?: (source: string) => string;
53
+ MemorySession?: new () => WasmSession;
54
+ PersistentSession?: new (path: string) => WasmSession;
55
+ };
56
+
57
+ let ready = false;
58
+
59
+ function assertReady(): void {
60
+ if (!ready) {
61
+ throw new Error('@yydb/yydb-unknown-wasm32: call initWasm() before semantic core methods');
62
+ }
63
+ }
64
+
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;
73
+ }
74
+
75
+ async function normalizeInitInput(input: WasmInitInput | undefined): Promise<WasmInitInput | ArrayBuffer | Uint8Array> {
76
+ if (input === undefined) {
77
+ return resolveDefaultWasmBytes();
78
+ }
79
+ if (
80
+ input instanceof URL ||
81
+ input instanceof Request ||
82
+ input instanceof Response ||
83
+ input instanceof ArrayBuffer ||
84
+ input instanceof Uint8Array ||
85
+ input instanceof WebAssembly.Module
86
+ ) {
87
+ return input;
88
+ }
89
+ throw new Error(`@yydb/yydb-unknown-wasm32: unsupported WASM init input (${typeof input})`);
90
+ }
91
+
92
+ /** One-time WASM init. Required before semantic core methods. */
93
+ export async function initWasm(options: InitWasmOptions = {}): Promise<void> {
94
+ if (ready) {
95
+ return;
96
+ }
97
+ const moduleOrPath = await normalizeInitInput(options.module);
98
+ await initGlue({ module_or_path: moduleOrPath });
99
+ ready = true;
100
+ }
101
+
102
+ /** Library version (matches workspace `@yydb/yydb` semver). */
103
+ export function yydbVersion(): string {
104
+ assertReady();
105
+ if (!glueApi.yydbVersion) {
106
+ throw new Error('@yydb/yydb-unknown-wasm32: yydbVersion export missing, rebuild wasm artifacts');
107
+ }
108
+ return glueApi.yydbVersion();
109
+ }
110
+
111
+ /** Parse and validate a VOS schema document via the Rust core. */
112
+ export function checkSchema(source: string): CheckSchemaResult {
113
+ assertReady();
114
+ if (!glueApi.checkSchema) {
115
+ throw new Error('@yydb/yydb-unknown-wasm32: checkSchema export missing, rebuild wasm artifacts');
116
+ }
117
+ return glueApi.checkSchema(source);
118
+ }
119
+
120
+ /** Read-only schema introspection JSON. */
121
+ export function introspectSchema(source: string): string {
122
+ assertReady();
123
+ if (!glueApi.introspectSchema) {
124
+ throw new Error('@yydb/yydb-unknown-wasm32: introspectSchema export missing, rebuild wasm artifacts');
125
+ }
126
+ return glueApi.introspectSchema(source);
127
+ }
128
+
129
+ /** Open a stateful in-memory session. */
130
+ export function createMemorySession(): WasmSession {
131
+ assertReady();
132
+ if (!glueApi.MemorySession) {
133
+ throw new Error('@yydb/yydb-unknown-wasm32: MemorySession export missing, rebuild wasm artifacts');
134
+ }
135
+ return new glueApi.MemorySession();
136
+ }
137
+
138
+ /** Open a stateful OPFS-backed session at `path`. */
139
+ export function openPersistentSession(path: string): WasmSession {
140
+ assertReady();
141
+ if (!glueApi.PersistentSession) {
142
+ throw new Error('@yydb/yydb-unknown-wasm32: PersistentSession export missing, rebuild wasm artifacts');
143
+ }
144
+ return new glueApi.PersistentSession(path);
145
+ }
146
+
147
+ /** @internal Reset init gate (binding tests only). */
148
+ export function resetWasmBindingForTests(): void {
149
+ ready = false;
150
+ }