@yydb/yydb 0.0.6 → 0.1.1

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 (36) hide show
  1. package/README.md +16 -55
  2. package/dist/{node → api}/database.js +1 -1
  3. package/dist/{node/cli → cli}/cli.js +1 -1
  4. package/dist/cli/info-cmd.js +37 -0
  5. package/dist/{node/cli → cli}/init-cmd.js +6 -6
  6. package/dist/{node/cli → cli}/serve-cmd.js +1 -1
  7. package/dist/{node/cli → cli}/version-cmd.js +1 -1
  8. package/dist/{node/index.d.ts → index.d.ts} +5 -5
  9. package/dist/index.js +5 -0
  10. package/dist/native/binding.d.ts +26 -0
  11. package/dist/{node/native.js → native/binding.js} +1 -1
  12. package/dist/{node/resolve-bin.js → native/resolve.js} +1 -1
  13. package/dist/shared/micro.d.ts +1 -1
  14. package/package.json +16 -26
  15. package/dist/node/cli/info-cmd.js +0 -10
  16. package/dist/node/index.js +0 -5
  17. package/dist/node/native.d.ts +0 -9
  18. package/dist/shared/wasm-envelope.d.ts +0 -40
  19. package/dist/shared/wasm-envelope.js +0 -49
  20. package/dist/wasm/binding.d.ts +0 -1
  21. package/dist/wasm/binding.js +0 -1
  22. package/dist/wasm/database.d.ts +0 -50
  23. package/dist/wasm/database.js +0 -110
  24. package/dist/wasm/index.d.ts +0 -8
  25. package/dist/wasm/index.js +0 -5
  26. /package/dist/{node → api}/database.d.ts +0 -0
  27. /package/dist/{node/cli → cli}/cli.d.ts +0 -0
  28. /package/dist/{node/cli → cli}/info-cmd.d.ts +0 -0
  29. /package/dist/{node/cli → cli}/init-cmd.d.ts +0 -0
  30. /package/dist/{node/cli → cli}/options.d.ts +0 -0
  31. /package/dist/{node/cli → cli}/options.js +0 -0
  32. /package/dist/{node/cli → cli}/serve-cmd.d.ts +0 -0
  33. /package/dist/{node/cli → cli}/version-cmd.d.ts +0 -0
  34. /package/dist/{node/cli.d.ts → cli.d.ts} +0 -0
  35. /package/dist/{node/cli.js → cli.js} +0 -0
  36. /package/dist/{node/resolve-bin.d.ts → native/resolve.d.ts} +0 -0
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # `@yydb/yydb`
2
2
 
3
- Node all-in-one and browser wasm core from one package. On Node.js, `Database.open` starts a private loopback `yydb serve`
4
- process and talks over the YY wire protocol. In browsers, `@yydb/yydb/wasm` loads an in-process wasm session with KV
5
- and schema on memory or OPFS paths.
3
+ Node embedded engine and CLI. `Database.open` starts a private loopback `yydb serve` process and talks over the YY
4
+ wire protocol; platform `.node` bindings install through optional dependencies.
5
+
6
+ Browsers are served by the pure TypeScript [`@yydb/light-db`](../light-db/readme.md) package. This package no longer
7
+ ships a WebAssembly entry.
6
8
 
7
9
  For a wire client only (renderer or an app that already runs `yydb serve`), use
8
10
  [`@yydb/yydb-client`](https://www.npmjs.com/package/@yydb/yydb-client).
@@ -14,18 +16,14 @@ For a wire client only (renderer or an app that already runs `yydb serve`), use
14
16
 
15
17
  | Import | Runtime | Role |
16
18
  |--------|---------|------|
17
- | `@yydb/yydb` | Node (`node` export condition) | `Database.open`, micro helpers |
18
- | `@yydb/yydb` | Browser / bundler (`default`) | wasm `Database` |
19
- | `@yydb/yydb/node` | Node (explicit) | Same as Node default |
20
- | `@yydb/yydb/wasm` | Browser (explicit) | wasm `Database`, `initWasm`, `checkSchema` |
19
+ | `@yydb/yydb` | Node | `Database.open`, micro helpers, VOS re-exports |
21
20
  | `@yydb/yydb/cli` | Node | CLI (`version`, `init`, `info`, `serve`) |
22
21
 
23
- Node.js 18+. Platform `.node` bindings install via optional dependencies.
22
+ Node.js 18+.
24
23
 
25
- Schema truth lives in the `.yydb` file via `ensureSchema` and VOS documents. Wasm sessions mirror KV and schema calls
26
- on the embedded core.
24
+ Schema truth lives in the `.yydb` file via `ensureSchema` and VOS documents.
27
25
 
28
- ## Node example
26
+ ## Example
29
27
 
30
28
  ```ts
31
29
  import { Database } from '@yydb/yydb';
@@ -48,47 +46,7 @@ await db.close();
48
46
 
49
47
  The file is created when missing. Schema version and VOS document persist with the data.
50
48
 
51
- ## Browser example
52
-
53
- ```ts
54
- import { Database } from '@yydb/yydb/wasm';
55
-
56
- const db = await Database.openInMemory();
57
-
58
- await db.ensureSchema(
59
- 1,
60
- `table Setting {
61
- @@id: uuid,
62
- key: utf8,
63
- value: utf8,
64
- }`,
65
- );
66
-
67
- await db.put('theme', 'dark');
68
- console.log(await db.get('theme'));
69
- db.close();
70
- ```
71
-
72
- Use `Database.open('app.yydb')` for OPFS-backed paths in supported browsers.
73
-
74
- ## Wasm API
75
-
76
- ```ts
77
- const db = await Database.openInMemory();
78
- // or: const db = await Database.open('app.yydb');
79
-
80
- await db.ensureSchema(version, vosDocument);
81
- await db.getSchema();
82
- await db.put(key, stringOrBytes);
83
- await db.get(key);
84
- await db.info();
85
- await db.serverVersion();
86
- await db.registerMicro(microDefinition);
87
- await db.callScalar('double', 1, [21]);
88
- db.close();
89
- ```
90
-
91
- ## Node API
49
+ ## API
92
50
 
93
51
  ```ts
94
52
  const db = await Database.open(path, options?);
@@ -107,17 +65,20 @@ await db.close();
107
65
  `OpenOptions`: `cli` (explicit CLI script path), `port` (preferred loopback port), `serveArgs` (extra `yydb serve`
108
66
  arguments). `binary` is a deprecated alias for `cli`.
109
67
 
68
+ The native binding exposes additive operations (`schemaVersion`, `schemaDocument`, `recordCount`, `journalMode`,
69
+ `checkpoint`, `walFrameCount`, `get`, `put`); the CLI composes commands from them.
70
+
110
71
  ## Related packages
111
72
 
112
73
  | Need | Package |
113
74
  |------|---------|
114
- | Node all-in-one (this package) | **`@yydb/yydb`** or `@yydb/yydb/node` |
115
- | Browser wasm entry | **`@yydb/yydb/wasm`** |
75
+ | Node embedded engine and CLI (this package) | **`@yydb/yydb`** |
76
+ | Browser, pure TypeScript | **`@yydb/light-db`** |
116
77
  | Wire client only | [`@yydb/yydb-client`](https://www.npmjs.com/package/@yydb/yydb-client) |
117
78
  | In-process Rust embed | [`yydb`](https://crates.io/crates/yydb) |
118
79
  | Agent skills (wire protocol) | [`@yydb/yydb-skills`](https://www.npmjs.com/package/@yydb/yydb-skills) |
119
80
 
120
- Electron: main process can use `@yydb/yydb/node`; renderer code can use `@yydb/yydb-client` against the main-process
81
+ Electron: main process can use `@yydb/yydb`; renderer code can use `@yydb/yydb-client` against the main-process
121
82
  endpoint.
122
83
 
123
84
  The managed engine listens on `127.0.0.1` with no authentication — keep the endpoint private.
@@ -4,7 +4,7 @@ import net from 'node:net';
4
4
  import path from 'node:path';
5
5
  import { connect } from '@yydb/yydb-client/node';
6
6
  import { defineMicro as buildMicro, microFingerprint, udfWireKind, MicroSessionRegistry, } from '../shared/micro.js';
7
- import { resolveYydbCli } from './resolve-bin.js';
7
+ import { resolveYydbCli } from '../native/resolve.js';
8
8
  async function freeLoopbackPort() {
9
9
  return await new Promise((resolve, reject) => {
10
10
  const server = net.createServer();
@@ -6,7 +6,7 @@ import { registerInitCommand } from './init-cmd.js';
6
6
  import { registerServeCommand } from './serve-cmd.js';
7
7
  import { registerVersionCommand } from './version-cmd.js';
8
8
  function buildYydbCli() {
9
- const localesRoot = join(dirname(fileURLToPath(import.meta.url)), '../../../locales');
9
+ const localesRoot = join(dirname(fileURLToPath(import.meta.url)), '../../locales');
10
10
  const cli = createCli('yydb').locales(localesRoot).intro('cli.intro');
11
11
  registerVersionCommand(cli);
12
12
  registerInitCommand(cli);
@@ -0,0 +1,37 @@
1
+ import { loadNative } from '../native/binding.js';
2
+ import { requiredPositional } from './options.js';
3
+ export function registerInfoCommand(cli) {
4
+ cli.command('info', 'cli.cmd.info').action((options) => cmdInfo(options));
5
+ }
6
+ export function cmdInfo(options) {
7
+ const dbPath = requiredPositional(options, 'info');
8
+ const database = loadNative().Database.open(dbPath);
9
+ const lines = [`path=${database.path() ?? '<memory>'}`];
10
+ const schemaVersion = database.schemaVersion();
11
+ if (schemaVersion === null) {
12
+ lines.push('schema=(none)');
13
+ }
14
+ else {
15
+ lines.push(`schema.version=${schemaVersion}`);
16
+ lines.push(`schema.document=${summarizeDocument(database.schemaDocument())}`);
17
+ }
18
+ lines.push(`records=${database.recordCount()}`);
19
+ lines.push(`journal_mode=${database.journalMode()}`);
20
+ const wal = database.walPath();
21
+ const shm = database.shmPath();
22
+ if (wal !== null)
23
+ lines.push(`wal=${wal}`);
24
+ if (shm !== null)
25
+ lines.push(`shm=${shm}`);
26
+ lines.push(`wal_frames=${database.walFrameCount()}`);
27
+ console.log(lines.join('\n'));
28
+ return 0;
29
+ }
30
+ function summarizeDocument(document) {
31
+ const trimmed = (document ?? '').trim();
32
+ if (trimmed.length === 0)
33
+ return '(empty)';
34
+ const limit = 120;
35
+ const flat = trimmed.replace(/\n/g, ' ');
36
+ return flat.length <= limit ? flat : `${flat.slice(0, limit)}…`;
37
+ }
@@ -1,18 +1,18 @@
1
- import { loadNative } from '../native.js';
1
+ import fs from 'node:fs';
2
+ import { loadNative } from '../native/binding.js';
2
3
  import { requiredPositional, str } from './options.js';
3
4
  export function registerInitCommand(cli) {
4
5
  cli.command('init', 'cli.cmd.init')
5
- .option('--schema-version <n>', 'cli.opt.schema-version')
6
6
  .option('--schema-file <path>', 'cli.opt.schema-file')
7
7
  .action((options) => cmdInit(options));
8
8
  }
9
9
  export function cmdInit(options) {
10
10
  const dbPath = requiredPositional(options, 'init');
11
- const schemaVersion = Number.parseInt(str(options, 'schema-version') ?? '1', 10);
12
11
  const schemaFile = str(options, 'schema-file');
13
- const native = loadNative();
14
- const schemaDocument = schemaFile ? native.readSchemaFile(schemaFile) : null;
15
- native.initDb(dbPath, schemaVersion, schemaDocument);
12
+ const database = loadNative().Database.open(dbPath);
13
+ if (schemaFile) {
14
+ database.ensureSchema(fs.readFileSync(schemaFile, 'utf8'));
15
+ }
16
16
  console.log(`initialized ${dbPath}`);
17
17
  return 0;
18
18
  }
@@ -1,4 +1,4 @@
1
- import { loadNative } from '../native.js';
1
+ import { loadNative } from '../native/binding.js';
2
2
  import { flag, requiredPositional, str } from './options.js';
3
3
  export function registerServeCommand(cli) {
4
4
  cli.command('serve', 'cli.cmd.serve')
@@ -1,4 +1,4 @@
1
- import { loadNative } from '../native.js';
1
+ import { loadNative } from '../native/binding.js';
2
2
  export function registerVersionCommand(cli) {
3
3
  cli.command('version', 'cli.cmd.version').action(() => cmdVersion());
4
4
  }
@@ -1,7 +1,7 @@
1
- export { Database, type OpenOptions } from './database.js';
1
+ export { Database, type OpenOptions } from './api/database.js';
2
2
  export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from '@yydb/yydb-client';
3
3
  export type { YydbErrorCode, YydbErrorOptions } from '@yydb/yydb-client';
4
- export { defineMicro, type DefinedMicro, type MicroHandle, type TsMicroDefinitionInput, MicroSessionRegistry } from '../shared/micro.js';
5
- export { type InferUdfArgs, type InferUdfReturn, type MicroEffect, type MicroInvocationMode, type UdfScalarDescriptor, type UdfScalarKind, } from '../shared/udf-types.js';
6
- export { nativeBindingName, platformKey, resolveYydbBinary, resolveYydbCli } from './resolve-bin.js';
7
- export * from '../shared/vos.js';
4
+ export { defineMicro, type DefinedMicro, type MicroHandle, type TsMicroDefinitionInput, MicroSessionRegistry } from './shared/micro.js';
5
+ export { type InferUdfArgs, type InferUdfReturn, type MicroEffect, type MicroInvocationMode, type UdfScalarDescriptor, type UdfScalarKind, } from './shared/udf-types.js';
6
+ export { nativeBindingName, platformKey, resolveYydbBinary, resolveYydbCli } from './native/resolve.js';
7
+ export * from './shared/vos.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { Database } from './api/database.js';
2
+ export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from '@yydb/yydb-client';
3
+ export { defineMicro, MicroSessionRegistry } from './shared/micro.js';
4
+ export { nativeBindingName, platformKey, resolveYydbBinary, resolveYydbCli } from './native/resolve.js';
5
+ export * from './shared/vos.js';
@@ -0,0 +1,26 @@
1
+ /** One open `.yydb` handle exposed by the native binding. */
2
+ export interface NativeDatabase {
3
+ path(): string | null;
4
+ walPath(): string | null;
5
+ shmPath(): string | null;
6
+ schemaVersion(): number | null;
7
+ schemaDocument(): string | null;
8
+ ensureSchema(document: string): void;
9
+ recordCount(): number;
10
+ journalMode(): string;
11
+ setJournalMode(mode: string): void;
12
+ checkpoint(): void;
13
+ walFrameCount(): number;
14
+ get(key: string): Uint8Array | null;
15
+ put(key: string, value: Uint8Array): void;
16
+ }
17
+ /** Atomic operations exported by the Node-API binding. */
18
+ export interface YydbNative {
19
+ version(): string;
20
+ serve(dbPath: string, bind: string, insecureBind?: boolean): void;
21
+ Database: {
22
+ open(dbPath: string): NativeDatabase;
23
+ };
24
+ }
25
+ /** Load the platform native binding used by the `yydb` CLI. */
26
+ export declare function loadNative(): YydbNative;
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
- import { platformKey } from './resolve-bin.js';
4
+ import { platformKey } from './resolve.js';
5
5
  function loadModule(specifier) {
6
6
  const require = createRequire(import.meta.url);
7
7
  const loaded = require(specifier);
@@ -48,7 +48,7 @@ export function resolveYydbCli() {
48
48
  return path.resolve(fromEnv);
49
49
  }
50
50
  const here = path.dirname(fileURLToPath(import.meta.url));
51
- const candidate = path.join(here, 'cli.js');
51
+ const candidate = path.join(here, '..', 'cli.js');
52
52
  if (!existsFile(candidate)) {
53
53
  throw new Error('YYDB CLI script not found. Build `@yydb/yydb` (`pnpm --filter @yydb/yydb build`) or set YYDB_CLI.');
54
54
  }
@@ -12,7 +12,7 @@ type UdfWireKind = 'i64' | 'bool' | 'text';
12
12
  * subset instead of letting it reach the engine.
13
13
  */
14
14
  export declare function udfWireKind(descriptor: AnyTypeDescriptor): UdfWireKind;
15
- /** Input accepted by [`Database.defineMicro`](./database.ts). */
15
+ /** Input accepted by [`Database.defineMicro`](../api/database.ts). */
16
16
  export interface TsMicroDefinitionInput<TArgs extends readonly UdfScalarDescriptor[], TReturn extends UdfScalarDescriptor> {
17
17
  readonly name: string;
18
18
  readonly version: number;
package/package.json CHANGED
@@ -1,31 +1,22 @@
1
1
  {
2
2
  "name": "@yydb/yydb",
3
- "version": "0.0.6",
4
- "description": "YYDB all-in-one: Node embedded engine and CLI, browser wasm core",
3
+ "version": "0.1.1",
4
+ "description": "YYDB Node embedded engine and CLI",
5
5
  "license": "MPL-2.0",
6
6
  "type": "module",
7
7
  "bin": {
8
- "yydb": "./dist/node/cli.js"
8
+ "yydb": "./dist/cli.js"
9
9
  },
10
- "main": "./dist/node/index.js",
11
- "types": "./dist/node/index.d.ts",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
12
  "exports": {
13
13
  ".": {
14
- "types": "./dist/node/index.d.ts",
15
- "node": "./dist/node/index.js",
16
- "default": "./dist/wasm/index.js"
17
- },
18
- "./node": {
19
- "types": "./dist/node/index.d.ts",
20
- "import": "./dist/node/index.js"
21
- },
22
- "./wasm": {
23
- "types": "./dist/wasm/index.d.ts",
24
- "import": "./dist/wasm/index.js"
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
25
16
  },
26
17
  "./cli": {
27
- "types": "./dist/node/cli.d.ts",
28
- "import": "./dist/node/cli.js"
18
+ "types": "./dist/cli.d.ts",
19
+ "import": "./dist/cli.js"
29
20
  }
30
21
  },
31
22
  "files": [
@@ -33,8 +24,8 @@
33
24
  "README.md"
34
25
  ],
35
26
  "scripts": {
36
- "build": "tsc -p tsconfig.node.json && tsc -p tsconfig.wasm.json",
37
- "test": "pnpm run build && node --experimental-strip-types --test src/node/**/*.test.ts src/shared/**/*.test.ts"
27
+ "build": "tsc -p tsconfig.json",
28
+ "test": "pnpm run build && node --experimental-strip-types --test src/**/*.test.ts"
38
29
  },
39
30
  "repository": {
40
31
  "type": "git",
@@ -58,8 +49,7 @@
58
49
  "dependencies": {
59
50
  "@vmz/commander": "^0.2.0",
60
51
  "@voml/vos": "^0.0.1",
61
- "@yydb/yydb-client": "0.0.6",
62
- "@yydb/yydb-unknown-wasm32": "0.0.6"
52
+ "@yydb/yydb-client": "0.1.1"
63
53
  },
64
54
  "devDependencies": {
65
55
  "@types/node": "^20.10.0",
@@ -69,9 +59,9 @@
69
59
  "node": ">=18"
70
60
  },
71
61
  "optionalDependencies": {
72
- "@yydb/yydb-win32-x64": "0.0.6",
73
- "@yydb/yydb-linux-x64": "0.0.6",
74
- "@yydb/yydb-darwin-x64": "0.0.6",
75
- "@yydb/yydb-darwin-arm64": "0.0.6"
62
+ "@yydb/yydb-win32-x64": "0.1.1",
63
+ "@yydb/yydb-linux-x64": "0.1.1",
64
+ "@yydb/yydb-darwin-x64": "0.1.1",
65
+ "@yydb/yydb-darwin-arm64": "0.1.1"
76
66
  }
77
67
  }
@@ -1,10 +0,0 @@
1
- import { loadNative } from '../native.js';
2
- import { requiredPositional } from './options.js';
3
- export function registerInfoCommand(cli) {
4
- cli.command('info', 'cli.cmd.info').action((options) => cmdInfo(options));
5
- }
6
- export function cmdInfo(options) {
7
- const dbPath = requiredPositional(options, 'info');
8
- console.log(loadNative().infoText(dbPath));
9
- return 0;
10
- }
@@ -1,5 +0,0 @@
1
- export { Database } from './database.js';
2
- export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from '@yydb/yydb-client';
3
- export { defineMicro, MicroSessionRegistry } from '../shared/micro.js';
4
- export { nativeBindingName, platformKey, resolveYydbBinary, resolveYydbCli } from './resolve-bin.js';
5
- export * from '../shared/vos.js';
@@ -1,9 +0,0 @@
1
- export interface YydbNative {
2
- version(): string;
3
- serve(dbPath: string, bind: string, insecureBind?: boolean): void;
4
- initDb(dbPath: string, schemaVersion: number, schemaDocument?: string | null): void;
5
- infoText(dbPath: string): string;
6
- readSchemaFile(schemaPath: string): string;
7
- }
8
- /** Load the platform native binding used by the `yydb` CLI. */
9
- export declare function loadNative(): YydbNative;
@@ -1,40 +0,0 @@
1
- /** Parsed `{ ok, rows, error, code }` envelope from wasm unit-valued calls. */
2
- export type WasmRowsResult = {
3
- ok: boolean;
4
- rows: Record<string, unknown>[];
5
- error: string | null;
6
- code: string | null;
7
- };
8
- /** Parsed `{ ok, schema, error, code }` envelope from wasm `getSchema`. */
9
- export type WasmSchemaResult = {
10
- ok: boolean;
11
- schema: {
12
- version: number;
13
- document: string;
14
- } | null;
15
- error: string | null;
16
- code: string | null;
17
- };
18
- /** Parsed `{ ok, value, error, code }` envelope from wasm `get`. */
19
- export type WasmKvGetResult = {
20
- ok: boolean;
21
- value: number[] | null;
22
- error: string | null;
23
- code: string | null;
24
- };
25
- /** Parsed `{ ok, value, error, code }` envelope from wasm `callScalar`. */
26
- export type WasmScalarResult = {
27
- ok: boolean;
28
- value: string | number | boolean | null;
29
- error: string | null;
30
- code: string | null;
31
- };
32
- export type WireScalarValue = string | number | boolean | null;
33
- export type SchemaVersion = {
34
- version: number;
35
- document: string;
36
- };
37
- export declare function parseWasmUnitResult(payload: string, operation: string): void;
38
- export declare function parseWasmSchemaResult(payload: string, operation: string): SchemaVersion | null;
39
- export declare function parseWasmScalarResult(payload: string, operation: string): WireScalarValue;
40
- export declare function parseWasmKvGetResult(payload: string, operation: string): Uint8Array | null;
@@ -1,49 +0,0 @@
1
- import { YydbError, YydbErrorCodes } from '@yydb/yydb-client';
2
- function parseJson(payload, operation) {
3
- try {
4
- return JSON.parse(payload);
5
- }
6
- catch (cause) {
7
- throw new YydbError(YydbErrorCodes.clientDecodeFailure, `${operation}: invalid JSON envelope`, { operation, cause });
8
- }
9
- }
10
- /**
11
- * Build the error for a failed wasm envelope. The Rust core always sends a
12
- * stable `code`; a missing one means the wasm artifact is stale, which is a
13
- * decode failure rather than an engine failure.
14
- */
15
- function envelopeError(envelope, operation) {
16
- const code = envelope.code ?? YydbErrorCodes.clientDecodeFailure;
17
- const message = envelope.error ?? `${operation}: wasm envelope carried no message`;
18
- return new YydbError(code, message, { operation });
19
- }
20
- export function parseWasmUnitResult(payload, operation) {
21
- const parsed = parseJson(payload, operation);
22
- if (!parsed.ok) {
23
- throw envelopeError(parsed, operation);
24
- }
25
- }
26
- export function parseWasmSchemaResult(payload, operation) {
27
- const parsed = parseJson(payload, operation);
28
- if (!parsed.ok) {
29
- throw envelopeError(parsed, operation);
30
- }
31
- return parsed.schema;
32
- }
33
- export function parseWasmScalarResult(payload, operation) {
34
- const parsed = parseJson(payload, operation);
35
- if (!parsed.ok) {
36
- throw envelopeError(parsed, operation);
37
- }
38
- return parsed.value;
39
- }
40
- export function parseWasmKvGetResult(payload, operation) {
41
- const parsed = parseJson(payload, operation);
42
- if (!parsed.ok) {
43
- throw envelopeError(parsed, operation);
44
- }
45
- if (parsed.value === null) {
46
- return null;
47
- }
48
- return Uint8Array.from(parsed.value);
49
- }
@@ -1 +0,0 @@
1
- export { checkSchema, createMemorySession, initWasm, introspectSchema, openPersistentSession, resetWasmBindingForTests, yydbVersion, type CheckSchemaResult, type InitWasmOptions, type WasmInitInput, type WasmSession, } from '@yydb/yydb-unknown-wasm32';
@@ -1 +0,0 @@
1
- export { checkSchema, createMemorySession, initWasm, introspectSchema, openPersistentSession, resetWasmBindingForTests, yydbVersion, } from '@yydb/yydb-unknown-wasm32';
@@ -1,50 +0,0 @@
1
- import { defineMicro as buildMicro, type DefinedMicro, type MicroHandle } from '../shared/micro.js';
2
- import type { UdfScalarDescriptor } from '../shared/udf-types.js';
3
- import { type SchemaVersion } from '../shared/wasm-envelope.js';
4
- import { type CheckSchemaResult, type InitWasmOptions } from './binding.js';
5
- export type WasmOpenOptions = InitWasmOptions;
6
- /**
7
- * Browser-facing YYDB handle backed by an in-process wasm session.
8
- * Use `open` for OPFS-backed paths and `openInMemory` for ephemeral state.
9
- */
10
- export declare class Database {
11
- readonly path: string;
12
- private session;
13
- private readonly kind;
14
- private readonly microRegistry;
15
- private constructor();
16
- /** Open an OPFS-backed database at `path` (for example `app.yydb`). */
17
- static open(path: string, options?: WasmOpenOptions): Promise<Database>;
18
- /** Open a stateful in-memory database session. */
19
- static openInMemory(options?: WasmOpenOptions): Promise<Database>;
20
- /** Library version from the wasm binding. */
21
- version(): string;
22
- /** Engine version string (Node API parity). */
23
- serverVersion(): Promise<string>;
24
- /** Database info text (`path=…\\n…`), matching the YY wire `Info` reply. */
25
- info(): Promise<string>;
26
- /** Parse and validate a VOS schema document without opening a session. */
27
- checkSchema(source: string): CheckSchemaResult;
28
- /** Persist schema document. `version` is accepted for Node API parity; wasm uses the document body. */
29
- ensureSchema(_version: number, document: string): Promise<void>;
30
- getSchema(): Promise<SchemaVersion | null>;
31
- get(key: string): Promise<Uint8Array | null>;
32
- put(key: string, value: Uint8Array | string): Promise<void>;
33
- /**
34
- * Build a typed session-local micro definition. Does not register it with
35
- * the engine until `registerMicro` is called.
36
- */
37
- defineMicro<TArgs extends readonly UdfScalarDescriptor[], TReturn extends UdfScalarDescriptor>(definition: Parameters<typeof buildMicro<TArgs, TReturn>>[0]): DefinedMicro<TArgs, TReturn>;
38
- /**
39
- * Install a `defineMicro` definition into the current session registry and
40
- * sync metadata to the embedded engine. Host micros are session-local.
41
- */
42
- registerMicro<TArgs extends readonly UdfScalarDescriptor[], TReturn extends UdfScalarDescriptor>(definition: DefinedMicro<TArgs, TReturn>): Promise<MicroHandle>;
43
- /** Invoke a registered scalar UDF on the embedded engine. */
44
- callScalar(name: string, version: number, args: readonly (string | number | boolean | null)[]): Promise<string | number | boolean | null>;
45
- /** Whether this handle owns a persistent OPFS session. */
46
- isPersistent(): boolean;
47
- /** Close the embedded session. Idempotent; further calls fail with `yydb.session.closed`. */
48
- close(): Promise<void>;
49
- private requireSession;
50
- }
@@ -1,110 +0,0 @@
1
- import { encodeMicroRegister, encodeScalarCall, YydbError, YydbErrorCodes } from '@yydb/yydb-client';
2
- import { defineMicro as buildMicro, microFingerprint, udfWireKind, MicroSessionRegistry, } from '../shared/micro.js';
3
- import { parseWasmKvGetResult, parseWasmScalarResult, parseWasmSchemaResult, parseWasmUnitResult, } from '../shared/wasm-envelope.js';
4
- import { checkSchema, createMemorySession, initWasm, openPersistentSession, yydbVersion, } from './binding.js';
5
- /**
6
- * Browser-facing YYDB handle backed by an in-process wasm session.
7
- * Use `open` for OPFS-backed paths and `openInMemory` for ephemeral state.
8
- */
9
- export class Database {
10
- path;
11
- session;
12
- kind;
13
- microRegistry;
14
- constructor(kind, path, session) {
15
- this.kind = kind;
16
- this.path = path;
17
- this.session = session;
18
- this.microRegistry = new MicroSessionRegistry();
19
- session.setMicroHostInvoker((payload) => this.microRegistry.invokeFromWire(payload));
20
- }
21
- /** Open an OPFS-backed database at `path` (for example `app.yydb`). */
22
- static async open(path, options = {}) {
23
- await initWasm(options);
24
- const session = openPersistentSession(path);
25
- return new Database('persistent', session.path ?? path, session);
26
- }
27
- /** Open a stateful in-memory database session. */
28
- static async openInMemory(options = {}) {
29
- await initWasm(options);
30
- const session = createMemorySession();
31
- return new Database('memory', ':memory:', session);
32
- }
33
- /** Library version from the wasm binding. */
34
- version() {
35
- return yydbVersion();
36
- }
37
- /** Engine version string (Node API parity). */
38
- async serverVersion() {
39
- return yydbVersion();
40
- }
41
- /** Database info text (`path=…\\n…`), matching the YY wire `Info` reply. */
42
- async info() {
43
- return this.requireSession('info').info();
44
- }
45
- /** Parse and validate a VOS schema document without opening a session. */
46
- checkSchema(source) {
47
- return checkSchema(source);
48
- }
49
- /** Persist schema document. `version` is accepted for Node API parity; wasm uses the document body. */
50
- async ensureSchema(_version, document) {
51
- parseWasmUnitResult(this.requireSession('schemaEnsure').ensureSchema(document), 'schemaEnsure');
52
- }
53
- async getSchema() {
54
- return parseWasmSchemaResult(this.requireSession('schemaGet').getSchema(), 'schemaGet');
55
- }
56
- async get(key) {
57
- return parseWasmKvGetResult(this.requireSession('kvGet').get(key), 'kvGet');
58
- }
59
- async put(key, value) {
60
- const bytes = typeof value === 'string' ? new TextEncoder().encode(value) : value;
61
- parseWasmUnitResult(this.requireSession('kvPut').put(key, bytes), 'kvPut');
62
- }
63
- /**
64
- * Build a typed session-local micro definition. Does not register it with
65
- * the engine until `registerMicro` is called.
66
- */
67
- defineMicro(definition) {
68
- return buildMicro(definition);
69
- }
70
- /**
71
- * Install a `defineMicro` definition into the current session registry and
72
- * sync metadata to the embedded engine. Host micros are session-local.
73
- */
74
- async registerMicro(definition) {
75
- const handle = this.microRegistry.register(definition);
76
- const body = encodeMicroRegister({
77
- hostId: handle.hostId,
78
- handleVersion: handle.implementationVersion,
79
- udfVersion: definition.version,
80
- name: definition.name,
81
- functionId: handle.functionId,
82
- args: definition.args.map(udfWireKind),
83
- returns: udfWireKind(definition.returns),
84
- fingerprint: microFingerprint(definition.name, definition.version),
85
- });
86
- parseWasmUnitResult(this.requireSession('microRegister').registerMicro(body), 'microRegister');
87
- return handle;
88
- }
89
- /** Invoke a registered scalar UDF on the embedded engine. */
90
- async callScalar(name, version, args) {
91
- const body = encodeScalarCall(name, version, args);
92
- return parseWasmScalarResult(this.requireSession('callScalar').callScalar(body), 'callScalar');
93
- }
94
- /** Whether this handle owns a persistent OPFS session. */
95
- isPersistent() {
96
- return this.kind === 'persistent';
97
- }
98
- /** Close the embedded session. Idempotent; further calls fail with `yydb.session.closed`. */
99
- async close() {
100
- const session = this.session;
101
- this.session = null;
102
- session?.close();
103
- }
104
- requireSession(operation) {
105
- if (!this.session) {
106
- throw new YydbError(YydbErrorCodes.sessionClosed, `${operation}: @yydb/yydb/wasm session is closed`, { operation });
107
- }
108
- return this.session;
109
- }
110
- }
@@ -1,8 +0,0 @@
1
- export { Database, type WasmOpenOptions } from './database.js';
2
- export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from '@yydb/yydb-client';
3
- export type { YydbErrorCode, YydbErrorOptions } from '@yydb/yydb-client';
4
- export { checkSchema, createMemorySession, initWasm, introspectSchema, openPersistentSession, resetWasmBindingForTests, yydbVersion, type CheckSchemaResult, type InitWasmOptions, type WasmInitInput, type WasmSession, } from './binding.js';
5
- export { defineMicro, type DefinedMicro, type MicroHandle, type TsMicroDefinitionInput, MicroSessionRegistry } from '../shared/micro.js';
6
- export { type InferUdfArgs, type InferUdfReturn, type MicroEffect, type MicroInvocationMode, type UdfScalarDescriptor, type UdfScalarKind, } from '../shared/udf-types.js';
7
- export type { SchemaVersion } from '../shared/wasm-envelope.js';
8
- export * from '../shared/vos.js';
@@ -1,5 +0,0 @@
1
- export { Database } from './database.js';
2
- export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from '@yydb/yydb-client';
3
- export { checkSchema, createMemorySession, initWasm, introspectSchema, openPersistentSession, resetWasmBindingForTests, yydbVersion, } from './binding.js';
4
- export { defineMicro, MicroSessionRegistry } from '../shared/micro.js';
5
- export * from '../shared/vos.js';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes