@yydb/yydb 0.0.7 → 0.0.10
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 +16 -55
- package/dist/api/database.d.ts +73 -0
- package/dist/api/database.js +124 -0
- package/dist/{node/cli → cli}/cli.js +1 -1
- package/dist/cli/info-cmd.js +37 -0
- package/dist/{node/cli → cli}/init-cmd.js +6 -6
- package/dist/{node/cli → cli}/serve-cmd.js +1 -1
- package/dist/{node/cli → cli}/version-cmd.js +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -0
- package/dist/native/binding.d.ts +50 -0
- package/dist/{node/native.js → native/binding.js} +1 -1
- package/dist/{node/resolve-bin.js → native/resolve.js} +1 -1
- package/dist/shared/errors.d.ts +57 -0
- package/dist/shared/errors.js +68 -0
- package/dist/shared/micro.d.ts +1 -1
- package/package.json +16 -27
- package/dist/node/cli/info-cmd.js +0 -10
- package/dist/node/database.d.ts +0 -50
- package/dist/node/database.js +0 -173
- package/dist/node/index.d.ts +0 -7
- package/dist/node/index.js +0 -5
- package/dist/node/native.d.ts +0 -9
- package/dist/shared/wasm-envelope.d.ts +0 -40
- package/dist/shared/wasm-envelope.js +0 -49
- package/dist/wasm/binding.d.ts +0 -1
- package/dist/wasm/binding.js +0 -1
- package/dist/wasm/database.d.ts +0 -50
- package/dist/wasm/database.js +0 -110
- package/dist/wasm/index.d.ts +0 -8
- package/dist/wasm/index.js +0 -5
- /package/dist/{node/cli → cli}/cli.d.ts +0 -0
- /package/dist/{node/cli → cli}/info-cmd.d.ts +0 -0
- /package/dist/{node/cli → cli}/init-cmd.d.ts +0 -0
- /package/dist/{node/cli → cli}/options.d.ts +0 -0
- /package/dist/{node/cli → cli}/options.js +0 -0
- /package/dist/{node/cli → cli}/serve-cmd.d.ts +0 -0
- /package/dist/{node/cli → cli}/version-cmd.d.ts +0 -0
- /package/dist/{node/cli.d.ts → cli.d.ts} +0 -0
- /package/dist/{node/cli.js → cli.js} +0 -0
- /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
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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+.
|
|
22
|
+
Node.js 18+.
|
|
24
23
|
|
|
25
|
-
Schema truth lives in the `.yydb` file via `ensureSchema` and VOS documents.
|
|
26
|
-
on the embedded core.
|
|
24
|
+
Schema truth lives in the `.yydb` file via `ensureSchema` and VOS documents.
|
|
27
25
|
|
|
28
|
-
##
|
|
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
|
-
##
|
|
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
|
|
115
|
-
| Browser
|
|
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
|
|
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.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type EmittableItem } from '@voml/vos';
|
|
2
|
+
import { defineMicro as buildMicro, type DefinedMicro, type MicroHandle } from '../shared/micro.js';
|
|
3
|
+
import type { UdfScalarDescriptor } from '../shared/udf-types.js';
|
|
4
|
+
/** Published schema metadata. */
|
|
5
|
+
export interface SchemaVersion {
|
|
6
|
+
version: number;
|
|
7
|
+
document: string;
|
|
8
|
+
}
|
|
9
|
+
/** Options for opening a local YYDB file. */
|
|
10
|
+
export interface OpenOptions {
|
|
11
|
+
/** Create parent directories when missing (default: true). */
|
|
12
|
+
mkdir?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Node-facing YYDB local database handle.
|
|
16
|
+
*
|
|
17
|
+
* Directly owns a native `yydb::Connection` via the Node-API binding. No
|
|
18
|
+
* child process, no loopback TCP, no wire protocol in the hot path.
|
|
19
|
+
*/
|
|
20
|
+
export declare class Database {
|
|
21
|
+
readonly path: string;
|
|
22
|
+
private readonly native;
|
|
23
|
+
private readonly microRegistry;
|
|
24
|
+
private constructor();
|
|
25
|
+
/** Open (create when missing) the database at `dbPath`. */
|
|
26
|
+
static open(dbPath: string, options?: OpenOptions): Promise<Database>;
|
|
27
|
+
/** Engine version string (same as `yydb --version`). */
|
|
28
|
+
serverVersion(): string;
|
|
29
|
+
/** Basic diagnostics: path, schema, record count, journal mode. */
|
|
30
|
+
info(): string;
|
|
31
|
+
/** Published schema metadata, or `null` before the first schema. */
|
|
32
|
+
getSchema(): Promise<{
|
|
33
|
+
version: number;
|
|
34
|
+
document: string;
|
|
35
|
+
} | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Validate and publish a VOS schema document.
|
|
38
|
+
*
|
|
39
|
+
* Accepts either a raw `.vos` source string, one `@voml/vos` descriptor
|
|
40
|
+
* (`v.table()`, `v.class()`) or a list of descriptors. When descriptors
|
|
41
|
+
* are supplied, they are rendered to source via `emitSource` first.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* // Raw source (unchanged behaviour):
|
|
45
|
+
* await db.ensureSchema('namespace demo { table User { @@id: uuid } }');
|
|
46
|
+
*
|
|
47
|
+
* // Zod-like builder — the Vos schema-ecosystem sweet spot:
|
|
48
|
+
* const User = v.table('User', { id: v.uuid().primary(), name: v.utf8() });
|
|
49
|
+
* await db.ensureSchema(User);
|
|
50
|
+
*
|
|
51
|
+
* // Multiple declarations in one shot:
|
|
52
|
+
* await db.ensureSchema(TableA, TableB, ClassC);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
ensureSchema(...input: [string] | [string, ...EmittableItem[]] | EmittableItem[]): Promise<void>;
|
|
56
|
+
/** Read one record, or `null` when the key is absent. */
|
|
57
|
+
get(key: string): Promise<Uint8Array | null>;
|
|
58
|
+
/** Insert or replace one record. */
|
|
59
|
+
put(key: string, value: Uint8Array | string): Promise<void>;
|
|
60
|
+
/** Fold the WAL into the main file and truncate the sidecar. */
|
|
61
|
+
checkpoint(): Promise<void>;
|
|
62
|
+
/** Build a typed session-local micro definition (without registering). */
|
|
63
|
+
defineMicro<TArgs extends readonly UdfScalarDescriptor[], TReturn extends UdfScalarDescriptor>(definition: Parameters<typeof buildMicro<TArgs, TReturn>>[0]): DefinedMicro<TArgs, TReturn>;
|
|
64
|
+
/**
|
|
65
|
+
* Install a session-local host micro into both the local registry and the
|
|
66
|
+
* native engine. Host micros never persist across processes.
|
|
67
|
+
*/
|
|
68
|
+
registerMicro<TArgs extends readonly UdfScalarDescriptor[], TReturn extends UdfScalarDescriptor>(definition: DefinedMicro<TArgs, TReturn>): Promise<MicroHandle>;
|
|
69
|
+
/** Invoke a registered scalar UDF on the native engine. */
|
|
70
|
+
callScalar(name: string, version: number, args: readonly (string | number | boolean | null)[]): Promise<string | number | boolean | null>;
|
|
71
|
+
/** Release the native handle (best-effort; the engine also drops on GC). */
|
|
72
|
+
close(): Promise<void>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { emitSource, } from '@voml/vos';
|
|
4
|
+
import { defineMicro as buildMicro, microFingerprint, udfWireKind, MicroSessionRegistry, } from '../shared/micro.js';
|
|
5
|
+
import { loadNative } from '../native/binding.js';
|
|
6
|
+
/**
|
|
7
|
+
* Node-facing YYDB local database handle.
|
|
8
|
+
*
|
|
9
|
+
* Directly owns a native `yydb::Connection` via the Node-API binding. No
|
|
10
|
+
* child process, no loopback TCP, no wire protocol in the hot path.
|
|
11
|
+
*/
|
|
12
|
+
export class Database {
|
|
13
|
+
path;
|
|
14
|
+
native;
|
|
15
|
+
microRegistry;
|
|
16
|
+
constructor(dbPath, native) {
|
|
17
|
+
this.path = dbPath;
|
|
18
|
+
this.native = native;
|
|
19
|
+
this.microRegistry = new MicroSessionRegistry();
|
|
20
|
+
}
|
|
21
|
+
/** Open (create when missing) the database at `dbPath`. */
|
|
22
|
+
static async open(dbPath, options = {}) {
|
|
23
|
+
const resolved = path.resolve(dbPath);
|
|
24
|
+
if (options.mkdir !== false) {
|
|
25
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
const native = loadNative();
|
|
28
|
+
const db = native.Database.open(resolved);
|
|
29
|
+
return new Database(resolved, db);
|
|
30
|
+
}
|
|
31
|
+
/** Engine version string (same as `yydb --version`). */
|
|
32
|
+
serverVersion() {
|
|
33
|
+
return loadNative().version();
|
|
34
|
+
}
|
|
35
|
+
/** Basic diagnostics: path, schema, record count, journal mode. */
|
|
36
|
+
info() {
|
|
37
|
+
const lines = [
|
|
38
|
+
`path=${this.native.path() ?? '<memory>'}`,
|
|
39
|
+
`schema.version=${this.native.schemaVersion() ?? ''}`,
|
|
40
|
+
`records=${this.native.recordCount()}`,
|
|
41
|
+
`journal_mode=${this.native.journalMode()}`,
|
|
42
|
+
];
|
|
43
|
+
return lines.join('\n') + '\n';
|
|
44
|
+
}
|
|
45
|
+
/** Published schema metadata, or `null` before the first schema. */
|
|
46
|
+
async getSchema() {
|
|
47
|
+
const version = this.native.schemaVersion();
|
|
48
|
+
const document = this.native.schemaDocument();
|
|
49
|
+
if (version === null || document === null) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return { version, document };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Validate and publish a VOS schema document.
|
|
56
|
+
*
|
|
57
|
+
* Accepts either a raw `.vos` source string, one `@voml/vos` descriptor
|
|
58
|
+
* (`v.table()`, `v.class()`) or a list of descriptors. When descriptors
|
|
59
|
+
* are supplied, they are rendered to source via `emitSource` first.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* // Raw source (unchanged behaviour):
|
|
63
|
+
* await db.ensureSchema('namespace demo { table User { @@id: uuid } }');
|
|
64
|
+
*
|
|
65
|
+
* // Zod-like builder — the Vos schema-ecosystem sweet spot:
|
|
66
|
+
* const User = v.table('User', { id: v.uuid().primary(), name: v.utf8() });
|
|
67
|
+
* await db.ensureSchema(User);
|
|
68
|
+
*
|
|
69
|
+
* // Multiple declarations in one shot:
|
|
70
|
+
* await db.ensureSchema(TableA, TableB, ClassC);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
async ensureSchema(...input) {
|
|
74
|
+
let document;
|
|
75
|
+
if (typeof input[0] === 'string') {
|
|
76
|
+
// Raw source string, optionally followed by descriptors we just ignore.
|
|
77
|
+
document = input[0];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// One or more Vos descriptor items → render to source.
|
|
81
|
+
document = emitSource(input);
|
|
82
|
+
}
|
|
83
|
+
this.native.ensureSchema(document);
|
|
84
|
+
}
|
|
85
|
+
/** Read one record, or `null` when the key is absent. */
|
|
86
|
+
async get(key) {
|
|
87
|
+
return this.native.get(key);
|
|
88
|
+
}
|
|
89
|
+
/** Insert or replace one record. */
|
|
90
|
+
async put(key, value) {
|
|
91
|
+
const bytes = typeof value === 'string' ? new TextEncoder().encode(value) : value;
|
|
92
|
+
this.native.put(key, bytes);
|
|
93
|
+
}
|
|
94
|
+
/** Fold the WAL into the main file and truncate the sidecar. */
|
|
95
|
+
async checkpoint() {
|
|
96
|
+
this.native.checkpoint();
|
|
97
|
+
}
|
|
98
|
+
/** Build a typed session-local micro definition (without registering). */
|
|
99
|
+
defineMicro(definition) {
|
|
100
|
+
return buildMicro(definition);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Install a session-local host micro into both the local registry and the
|
|
104
|
+
* native engine. Host micros never persist across processes.
|
|
105
|
+
*/
|
|
106
|
+
async registerMicro(definition) {
|
|
107
|
+
const handle = this.microRegistry.register(definition);
|
|
108
|
+
const argTypes = definition.args.map((d) => udfWireKind(d));
|
|
109
|
+
const returnType = udfWireKind(definition.returns);
|
|
110
|
+
this.native.registerMicro(definition.name, definition.version, argTypes, returnType, handle.hostId, handle.functionId, handle.implementationVersion, microFingerprint(definition.name, definition.version));
|
|
111
|
+
return handle;
|
|
112
|
+
}
|
|
113
|
+
/** Invoke a registered scalar UDF on the native engine. */
|
|
114
|
+
async callScalar(name, version, args) {
|
|
115
|
+
const argsJson = JSON.stringify(args);
|
|
116
|
+
const resultJson = this.native.callScalar(name, version, argsJson);
|
|
117
|
+
return JSON.parse(resultJson);
|
|
118
|
+
}
|
|
119
|
+
/** Release the native handle (best-effort; the engine also drops on GC). */
|
|
120
|
+
async close() {
|
|
121
|
+
// Native connections drop cleanly when the handle is garbage-collected.
|
|
122
|
+
// No explicit close() is exposed from yydb::Connection.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -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)), '
|
|
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
|
|
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
|
|
14
|
-
|
|
15
|
-
|
|
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
|
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Database, type OpenOptions, type SchemaVersion } from './api/database.js';
|
|
2
|
+
export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from './shared/errors.js';
|
|
3
|
+
export type { YydbErrorCode, YydbErrorOptions } from './shared/errors.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 './shared/errors.js';
|
|
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,50 @@
|
|
|
1
|
+
/** Schema version returned by N-API Database.schema_version / Client.schema_version. */
|
|
2
|
+
export interface NativeSchemaVersion {
|
|
3
|
+
version: number;
|
|
4
|
+
document: string;
|
|
5
|
+
}
|
|
6
|
+
/** One open `.yydb` handle exposed by the native binding. */
|
|
7
|
+
export interface NativeDatabase {
|
|
8
|
+
path(): string | null;
|
|
9
|
+
walPath(): string | null;
|
|
10
|
+
shmPath(): string | null;
|
|
11
|
+
schemaVersion(): number | null;
|
|
12
|
+
schemaDocument(): string | null;
|
|
13
|
+
ensureSchema(document: string): void;
|
|
14
|
+
recordCount(): number;
|
|
15
|
+
journalMode(): string;
|
|
16
|
+
setJournalMode(mode: string): void;
|
|
17
|
+
checkpoint(): void;
|
|
18
|
+
walFrameCount(): number;
|
|
19
|
+
get(key: string): Uint8Array | null;
|
|
20
|
+
put(key: string, value: Uint8Array): void;
|
|
21
|
+
registerMicro(name: string, version: number, args: string[], returns: string, hostId: number, functionId: string, handleVersion: number, fingerprint: Uint8Array): void;
|
|
22
|
+
callScalar(name: string, version: number, argsJson: string): string;
|
|
23
|
+
}
|
|
24
|
+
/** One remote `yydb serve` handle exposed by the native binding. */
|
|
25
|
+
export interface NativeClient {
|
|
26
|
+
endpoint(): string;
|
|
27
|
+
serverVersion(): string;
|
|
28
|
+
info(): string;
|
|
29
|
+
schemaVersion(): number | null;
|
|
30
|
+
schemaDocument(): string | null;
|
|
31
|
+
ensureSchema(document: string): void;
|
|
32
|
+
get(key: string): Uint8Array | null;
|
|
33
|
+
put(key: string, value: Uint8Array): void;
|
|
34
|
+
registerMicro(name: string, version: number, args: string[], returns: string, hostId: number, functionId: string, handleVersion: number, fingerprint: Uint8Array): void;
|
|
35
|
+
callScalar(name: string, version: number, argsJson: string): string;
|
|
36
|
+
close(): void;
|
|
37
|
+
}
|
|
38
|
+
/** Atomic operations exported by the Node-API binding. */
|
|
39
|
+
export interface YydbNative {
|
|
40
|
+
version(): string;
|
|
41
|
+
serve(dbPath: string, bind: string, insecureBind?: boolean): void;
|
|
42
|
+
Database: {
|
|
43
|
+
open(dbPath: string): NativeDatabase;
|
|
44
|
+
};
|
|
45
|
+
Client: {
|
|
46
|
+
connect(endpoint: string): NativeClient;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Load the platform native binding used by the `yydb` CLI. */
|
|
50
|
+
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
|
|
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
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-facing YYDB error surface.
|
|
3
|
+
*
|
|
4
|
+
* Every public failure carries a stable `code`: engine codes come from the
|
|
5
|
+
* Rust core (`yydb.schema.invalid`, …) over N-API or the wire, client codes
|
|
6
|
+
* are minted locally with the `yydb.client.` prefix. Branch on `code` —
|
|
7
|
+
* `message` is display text only.
|
|
8
|
+
*/
|
|
9
|
+
/** Stable codes known to the TypeScript hosts. */
|
|
10
|
+
export declare const YydbErrorCodes: {
|
|
11
|
+
readonly io: "yydb.io";
|
|
12
|
+
readonly corrupt: "yydb.corrupt";
|
|
13
|
+
readonly schemaConflict: "yydb.schema.conflict";
|
|
14
|
+
readonly schemaInvalid: "yydb.schema.invalid";
|
|
15
|
+
readonly udfNotFound: "yydb.udf.not_found";
|
|
16
|
+
readonly udfArity: "yydb.udf.arity";
|
|
17
|
+
readonly udfFailed: "yydb.udf.failed";
|
|
18
|
+
readonly udfVersionMismatch: "yydb.udf.version_mismatch";
|
|
19
|
+
readonly objectNotFound: "yydb.object.not_found";
|
|
20
|
+
readonly objectCorrupt: "yydb.object.corrupt";
|
|
21
|
+
readonly unsupported: "yydb.unsupported";
|
|
22
|
+
readonly protocol: "yydb.protocol";
|
|
23
|
+
readonly casConflict: "yydb.cas.conflict";
|
|
24
|
+
readonly leaseUnavailable: "yydb.lease.unavailable";
|
|
25
|
+
readonly fencingMismatch: "yydb.fencing.mismatch";
|
|
26
|
+
readonly leaseExpired: "yydb.lease.expired";
|
|
27
|
+
readonly quotaExceeded: "yydb.quota.exceeded";
|
|
28
|
+
readonly sessionClosed: "yydb.session.closed";
|
|
29
|
+
readonly clientInvalidEndpoint: "yydb.client.invalid_endpoint";
|
|
30
|
+
readonly clientTransportFailure: "yydb.client.transport_failure";
|
|
31
|
+
readonly clientRequestIdMismatch: "yydb.client.request_id_mismatch";
|
|
32
|
+
readonly clientUnexpectedResponse: "yydb.client.unexpected_response";
|
|
33
|
+
readonly clientDecodeFailure: "yydb.client.decode_failure";
|
|
34
|
+
};
|
|
35
|
+
/** A known code, or any future code the engine introduces. */
|
|
36
|
+
export type YydbErrorCode = (typeof YydbErrorCodes)[keyof typeof YydbErrorCodes] | (string & {});
|
|
37
|
+
/** Whether `code` may be retried with the same arguments. */
|
|
38
|
+
export declare function isRetryableYydbCode(code: string): boolean;
|
|
39
|
+
/** Options carried by a {@link YydbError}. */
|
|
40
|
+
export interface YydbErrorOptions {
|
|
41
|
+
/** Operation that failed (`schemaGet`, `kvPut`, `query`, …). */
|
|
42
|
+
operation?: string;
|
|
43
|
+
/** Underlying failure when this error wraps one. */
|
|
44
|
+
cause?: unknown;
|
|
45
|
+
}
|
|
46
|
+
/** YYDB failure with a stable machine-readable {@link YydbError.code}. */
|
|
47
|
+
export declare class YydbError extends Error {
|
|
48
|
+
/** Stable code — engine code or `yydb.client.*`. */
|
|
49
|
+
readonly code: string;
|
|
50
|
+
/** Operation that failed. */
|
|
51
|
+
readonly operation: string;
|
|
52
|
+
/** Whether the same call may be retried. */
|
|
53
|
+
readonly retryable: boolean;
|
|
54
|
+
constructor(code: YydbErrorCode, message: string, options?: YydbErrorOptions);
|
|
55
|
+
}
|
|
56
|
+
/** Narrowing helper so callers can branch without `instanceof` imports. */
|
|
57
|
+
export declare function isYydbError(value: unknown): value is YydbError;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-facing YYDB error surface.
|
|
3
|
+
*
|
|
4
|
+
* Every public failure carries a stable `code`: engine codes come from the
|
|
5
|
+
* Rust core (`yydb.schema.invalid`, …) over N-API or the wire, client codes
|
|
6
|
+
* are minted locally with the `yydb.client.` prefix. Branch on `code` —
|
|
7
|
+
* `message` is display text only.
|
|
8
|
+
*/
|
|
9
|
+
/** Stable codes known to the TypeScript hosts. */
|
|
10
|
+
export const YydbErrorCodes = {
|
|
11
|
+
io: 'yydb.io',
|
|
12
|
+
corrupt: 'yydb.corrupt',
|
|
13
|
+
schemaConflict: 'yydb.schema.conflict',
|
|
14
|
+
schemaInvalid: 'yydb.schema.invalid',
|
|
15
|
+
udfNotFound: 'yydb.udf.not_found',
|
|
16
|
+
udfArity: 'yydb.udf.arity',
|
|
17
|
+
udfFailed: 'yydb.udf.failed',
|
|
18
|
+
udfVersionMismatch: 'yydb.udf.version_mismatch',
|
|
19
|
+
objectNotFound: 'yydb.object.not_found',
|
|
20
|
+
objectCorrupt: 'yydb.object.corrupt',
|
|
21
|
+
unsupported: 'yydb.unsupported',
|
|
22
|
+
protocol: 'yydb.protocol',
|
|
23
|
+
casConflict: 'yydb.cas.conflict',
|
|
24
|
+
leaseUnavailable: 'yydb.lease.unavailable',
|
|
25
|
+
fencingMismatch: 'yydb.fencing.mismatch',
|
|
26
|
+
leaseExpired: 'yydb.lease.expired',
|
|
27
|
+
quotaExceeded: 'yydb.quota.exceeded',
|
|
28
|
+
sessionClosed: 'yydb.session.closed',
|
|
29
|
+
clientInvalidEndpoint: 'yydb.client.invalid_endpoint',
|
|
30
|
+
clientTransportFailure: 'yydb.client.transport_failure',
|
|
31
|
+
clientRequestIdMismatch: 'yydb.client.request_id_mismatch',
|
|
32
|
+
clientUnexpectedResponse: 'yydb.client.unexpected_response',
|
|
33
|
+
clientDecodeFailure: 'yydb.client.decode_failure',
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Codes where retrying the same operation can legitimately succeed: a socket or
|
|
37
|
+
* lease hiccup, or a compare-and-set that lost a benign race. Every other code
|
|
38
|
+
* needs the caller to change input, schema, or wiring first.
|
|
39
|
+
*/
|
|
40
|
+
const RETRYABLE_CODES = new Set([
|
|
41
|
+
YydbErrorCodes.clientTransportFailure,
|
|
42
|
+
YydbErrorCodes.casConflict,
|
|
43
|
+
YydbErrorCodes.leaseUnavailable,
|
|
44
|
+
]);
|
|
45
|
+
/** Whether `code` may be retried with the same arguments. */
|
|
46
|
+
export function isRetryableYydbCode(code) {
|
|
47
|
+
return RETRYABLE_CODES.has(code);
|
|
48
|
+
}
|
|
49
|
+
/** YYDB failure with a stable machine-readable {@link YydbError.code}. */
|
|
50
|
+
export class YydbError extends Error {
|
|
51
|
+
/** Stable code — engine code or `yydb.client.*`. */
|
|
52
|
+
code;
|
|
53
|
+
/** Operation that failed. */
|
|
54
|
+
operation;
|
|
55
|
+
/** Whether the same call may be retried. */
|
|
56
|
+
retryable;
|
|
57
|
+
constructor(code, message, options = {}) {
|
|
58
|
+
super(message, { cause: options.cause });
|
|
59
|
+
this.name = 'YydbError';
|
|
60
|
+
this.code = code;
|
|
61
|
+
this.operation = options.operation ?? 'unknown';
|
|
62
|
+
this.retryable = isRetryableYydbCode(code);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Narrowing helper so callers can branch without `instanceof` imports. */
|
|
66
|
+
export function isYydbError(value) {
|
|
67
|
+
return value instanceof YydbError;
|
|
68
|
+
}
|
package/dist/shared/micro.d.ts
CHANGED
|
@@ -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`](
|
|
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.
|
|
4
|
-
"description": "YYDB
|
|
3
|
+
"version": "0.0.10",
|
|
4
|
+
"description": "YYDB Node embedded engine and CLI",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"yydb": "./dist/
|
|
8
|
+
"yydb": "./dist/cli.js"
|
|
9
9
|
},
|
|
10
|
-
"main": "./dist/
|
|
11
|
-
"types": "./dist/
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"types": "./dist/
|
|
15
|
-
"
|
|
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/
|
|
28
|
-
"import": "./dist/
|
|
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.
|
|
37
|
-
"test": "pnpm run build && node --experimental-strip-types --test src
|
|
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",
|
|
@@ -57,9 +48,7 @@
|
|
|
57
48
|
},
|
|
58
49
|
"dependencies": {
|
|
59
50
|
"@vmz/commander": "^0.2.0",
|
|
60
|
-
"@voml/vos": "^0.0.1"
|
|
61
|
-
"@yydb/yydb-client": "0.0.7",
|
|
62
|
-
"@yydb/yydb-unknown-wasm32": "0.0.7"
|
|
51
|
+
"@voml/vos": "^0.0.1"
|
|
63
52
|
},
|
|
64
53
|
"devDependencies": {
|
|
65
54
|
"@types/node": "^20.10.0",
|
|
@@ -69,9 +58,9 @@
|
|
|
69
58
|
"node": ">=18"
|
|
70
59
|
},
|
|
71
60
|
"optionalDependencies": {
|
|
72
|
-
"@yydb/yydb-win32-x64": "0.0.
|
|
73
|
-
"@yydb/yydb-linux-x64": "0.0.
|
|
74
|
-
"@yydb/yydb-darwin-x64": "0.0.
|
|
75
|
-
"@yydb/yydb-darwin-arm64": "0.0.
|
|
61
|
+
"@yydb/yydb-win32-x64": "0.0.10",
|
|
62
|
+
"@yydb/yydb-linux-x64": "0.0.10",
|
|
63
|
+
"@yydb/yydb-darwin-x64": "0.0.10",
|
|
64
|
+
"@yydb/yydb-darwin-arm64": "0.0.10"
|
|
76
65
|
}
|
|
77
66
|
}
|
|
@@ -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
|
-
}
|
package/dist/node/database.d.ts
DELETED
|
@@ -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
|
-
export type { SchemaVersion } from '@yydb/yydb-client';
|
|
4
|
-
export interface OpenOptions {
|
|
5
|
-
/** Override CLI script path (tests / special installs). */
|
|
6
|
-
cli?: string;
|
|
7
|
-
/** @deprecated Use `cli`. */
|
|
8
|
-
binary?: string;
|
|
9
|
-
/** Prefer a specific loopback port; default = ephemeral free port. */
|
|
10
|
-
port?: number;
|
|
11
|
-
/** Extra args after `serve <path> --bind …`. */
|
|
12
|
-
serveArgs?: string[];
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Node-facing YYDB handle. Looks like one library; owns a private loopback
|
|
16
|
-
* `yydb serve` child under the hood.
|
|
17
|
-
*/
|
|
18
|
-
export declare class Database {
|
|
19
|
-
readonly path: string;
|
|
20
|
-
readonly endpoint: string;
|
|
21
|
-
private client;
|
|
22
|
-
private child;
|
|
23
|
-
private readonly microRegistry;
|
|
24
|
-
private constructor();
|
|
25
|
-
/**
|
|
26
|
-
* Open (create) a `.yydb` file. Spawns the engine on `127.0.0.1` automatically.
|
|
27
|
-
*/
|
|
28
|
-
static open(dbPath: string, options?: OpenOptions): Promise<Database>;
|
|
29
|
-
serverVersion(): Promise<string>;
|
|
30
|
-
info(): Promise<string>;
|
|
31
|
-
getSchema(): Promise<import("@yydb/yydb-client").SchemaVersion | null>;
|
|
32
|
-
ensureSchema(version: number, document: string): Promise<void>;
|
|
33
|
-
get(key: string): Promise<Uint8Array | null>;
|
|
34
|
-
put(key: string, value: Uint8Array | string): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Build a typed session-local micro definition. Does not register it with
|
|
37
|
-
* the engine until [`registerMicro`](./database.ts) is called.
|
|
38
|
-
*/
|
|
39
|
-
defineMicro<TArgs extends readonly UdfScalarDescriptor[], TReturn extends UdfScalarDescriptor>(definition: Parameters<typeof buildMicro<TArgs, TReturn>>[0]): DefinedMicro<TArgs, TReturn>;
|
|
40
|
-
/**
|
|
41
|
-
* Install a [`defineMicro`](./database.ts) definition into the current
|
|
42
|
-
* session registry and sync metadata to the private engine. Host micros are
|
|
43
|
-
* session-local and never written to `.yydb`.
|
|
44
|
-
*/
|
|
45
|
-
registerMicro<TArgs extends readonly UdfScalarDescriptor[], TReturn extends UdfScalarDescriptor>(definition: DefinedMicro<TArgs, TReturn>): Promise<MicroHandle>;
|
|
46
|
-
/** Invoke a registered scalar UDF on the private engine. */
|
|
47
|
-
callScalar(name: string, version: number, args: readonly (string | number | boolean | null)[]): Promise<string | number | boolean | null>;
|
|
48
|
-
/** Stop the private engine process. */
|
|
49
|
-
close(): Promise<void>;
|
|
50
|
-
}
|
package/dist/node/database.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import net from 'node:net';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { connect } from '@yydb/yydb-client/node';
|
|
6
|
-
import { defineMicro as buildMicro, microFingerprint, udfWireKind, MicroSessionRegistry, } from '../shared/micro.js';
|
|
7
|
-
import { resolveYydbCli } from './resolve-bin.js';
|
|
8
|
-
async function freeLoopbackPort() {
|
|
9
|
-
return await new Promise((resolve, reject) => {
|
|
10
|
-
const server = net.createServer();
|
|
11
|
-
server.listen(0, '127.0.0.1', () => {
|
|
12
|
-
const address = server.address();
|
|
13
|
-
if (!address || typeof address === 'string') {
|
|
14
|
-
server.close();
|
|
15
|
-
reject(new Error('could not allocate loopback port'));
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const { port } = address;
|
|
19
|
-
server.close((error) => {
|
|
20
|
-
if (error)
|
|
21
|
-
reject(error);
|
|
22
|
-
else
|
|
23
|
-
resolve(port);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
server.on('error', reject);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
async function waitForTcp(host, port, timeoutMs) {
|
|
30
|
-
const deadline = Date.now() + timeoutMs;
|
|
31
|
-
while (Date.now() < deadline) {
|
|
32
|
-
try {
|
|
33
|
-
await new Promise((resolve, reject) => {
|
|
34
|
-
const socket = net.connect({ host, port }, () => {
|
|
35
|
-
socket.end();
|
|
36
|
-
resolve();
|
|
37
|
-
});
|
|
38
|
-
socket.on('error', reject);
|
|
39
|
-
});
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
await new Promise((r) => setTimeout(r, 40));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
throw new Error(`yydb engine did not accept connections on ${host}:${port}`);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Node-facing YYDB handle. Looks like one library; owns a private loopback
|
|
50
|
-
* `yydb serve` child under the hood.
|
|
51
|
-
*/
|
|
52
|
-
export class Database {
|
|
53
|
-
path;
|
|
54
|
-
endpoint;
|
|
55
|
-
client;
|
|
56
|
-
child;
|
|
57
|
-
microRegistry;
|
|
58
|
-
constructor(dbPath, endpoint, client, child) {
|
|
59
|
-
this.path = dbPath;
|
|
60
|
-
this.endpoint = endpoint;
|
|
61
|
-
this.client = client;
|
|
62
|
-
this.child = child;
|
|
63
|
-
this.microRegistry = new MicroSessionRegistry();
|
|
64
|
-
this.client.setMicroHostHandler((payload) => this.microRegistry.invokeFromWire(payload));
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Open (create) a `.yydb` file. Spawns the engine on `127.0.0.1` automatically.
|
|
68
|
-
*/
|
|
69
|
-
static async open(dbPath, options = {}) {
|
|
70
|
-
const resolved = path.resolve(dbPath);
|
|
71
|
-
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
72
|
-
const cli = options.cli ?? options.binary ?? resolveYydbCli();
|
|
73
|
-
const port = options.port ?? (await freeLoopbackPort());
|
|
74
|
-
const bind = `127.0.0.1:${port}`;
|
|
75
|
-
const args = [cli, 'serve', resolved, '--bind', bind, ...(options.serveArgs ?? [])];
|
|
76
|
-
const child = spawn(process.execPath, args, {
|
|
77
|
-
stdio: 'pipe',
|
|
78
|
-
windowsHide: true,
|
|
79
|
-
});
|
|
80
|
-
let stderr = '';
|
|
81
|
-
child.stderr?.setEncoding('utf8');
|
|
82
|
-
child.stderr?.on('data', (chunk) => {
|
|
83
|
-
stderr += chunk;
|
|
84
|
-
});
|
|
85
|
-
const exitPromise = new Promise((_, reject) => {
|
|
86
|
-
child.once('exit', (code, signal) => {
|
|
87
|
-
reject(new Error(`yydb engine exited early (code=${code}, signal=${signal}): ${stderr.trim()}`));
|
|
88
|
-
});
|
|
89
|
-
child.once('error', reject);
|
|
90
|
-
});
|
|
91
|
-
try {
|
|
92
|
-
await Promise.race([waitForTcp('127.0.0.1', port, 8000), exitPromise]);
|
|
93
|
-
const client = await connect(bind);
|
|
94
|
-
child.removeAllListeners('exit');
|
|
95
|
-
child.removeAllListeners('error');
|
|
96
|
-
child.on('exit', () => {
|
|
97
|
-
/* closed via Database.close or crash */
|
|
98
|
-
});
|
|
99
|
-
return new Database(resolved, bind, client, child);
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
child.kill('SIGTERM');
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
async serverVersion() {
|
|
107
|
-
return this.client.serverVersion();
|
|
108
|
-
}
|
|
109
|
-
async info() {
|
|
110
|
-
return this.client.info();
|
|
111
|
-
}
|
|
112
|
-
async getSchema() {
|
|
113
|
-
return this.client.getSchema();
|
|
114
|
-
}
|
|
115
|
-
async ensureSchema(version, document) {
|
|
116
|
-
await this.client.ensureSchema(version, document);
|
|
117
|
-
}
|
|
118
|
-
async get(key) {
|
|
119
|
-
return this.client.get(key);
|
|
120
|
-
}
|
|
121
|
-
async put(key, value) {
|
|
122
|
-
await this.client.put(key, value);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Build a typed session-local micro definition. Does not register it with
|
|
126
|
-
* the engine until [`registerMicro`](./database.ts) is called.
|
|
127
|
-
*/
|
|
128
|
-
defineMicro(definition) {
|
|
129
|
-
return buildMicro(definition);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Install a [`defineMicro`](./database.ts) definition into the current
|
|
133
|
-
* session registry and sync metadata to the private engine. Host micros are
|
|
134
|
-
* session-local and never written to `.yydb`.
|
|
135
|
-
*/
|
|
136
|
-
async registerMicro(definition) {
|
|
137
|
-
const handle = this.microRegistry.register(definition);
|
|
138
|
-
await this.client.registerMicro({
|
|
139
|
-
hostId: handle.hostId,
|
|
140
|
-
handleVersion: handle.implementationVersion,
|
|
141
|
-
udfVersion: definition.version,
|
|
142
|
-
name: definition.name,
|
|
143
|
-
functionId: handle.functionId,
|
|
144
|
-
args: definition.args.map(udfWireKind),
|
|
145
|
-
returns: udfWireKind(definition.returns),
|
|
146
|
-
fingerprint: microFingerprint(definition.name, definition.version),
|
|
147
|
-
});
|
|
148
|
-
return handle;
|
|
149
|
-
}
|
|
150
|
-
/** Invoke a registered scalar UDF on the private engine. */
|
|
151
|
-
async callScalar(name, version, args) {
|
|
152
|
-
return this.client.callScalar(name, version, args);
|
|
153
|
-
}
|
|
154
|
-
/** Stop the private engine process. */
|
|
155
|
-
async close() {
|
|
156
|
-
this.client.close();
|
|
157
|
-
const child = this.child;
|
|
158
|
-
this.child = null;
|
|
159
|
-
if (!child || child.exitCode !== null || child.killed) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
await new Promise((resolve) => {
|
|
163
|
-
child.once('exit', () => resolve());
|
|
164
|
-
child.kill('SIGTERM');
|
|
165
|
-
setTimeout(() => {
|
|
166
|
-
if (child.exitCode === null && !child.killed) {
|
|
167
|
-
child.kill('SIGKILL');
|
|
168
|
-
}
|
|
169
|
-
resolve();
|
|
170
|
-
}, 2000);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
package/dist/node/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { Database, type OpenOptions } from './database.js';
|
|
2
|
-
export { YydbError, YydbErrorCodes, isRetryableYydbCode, isYydbError } from '@yydb/yydb-client';
|
|
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';
|
package/dist/node/index.js
DELETED
|
@@ -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';
|
package/dist/node/native.d.ts
DELETED
|
@@ -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
|
-
}
|
package/dist/wasm/binding.d.ts
DELETED
|
@@ -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';
|
package/dist/wasm/binding.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { checkSchema, createMemorySession, initWasm, introspectSchema, openPersistentSession, resetWasmBindingForTests, yydbVersion, } from '@yydb/yydb-unknown-wasm32';
|
package/dist/wasm/database.d.ts
DELETED
|
@@ -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
|
-
}
|
package/dist/wasm/database.js
DELETED
|
@@ -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
|
-
}
|
package/dist/wasm/index.d.ts
DELETED
|
@@ -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';
|
package/dist/wasm/index.js
DELETED
|
@@ -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
|