@yydb/yydb 0.0.15 → 0.0.17

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 (42) hide show
  1. package/README.md +86 -86
  2. package/package.json +40 -40
  3. package/dist/database.d.ts +0 -50
  4. package/dist/database.js +0 -181
  5. package/dist/micro.d.ts +0 -63
  6. package/dist/micro.js +0 -160
  7. package/dist/native.d.ts +0 -9
  8. package/dist/native.js +0 -32
  9. package/dist/node/cli/cli.d.ts +0 -1
  10. package/dist/node/cli/cli.js +0 -25
  11. package/dist/node/cli/info-cmd.d.ts +0 -3
  12. package/dist/node/cli/info-cmd.js +0 -10
  13. package/dist/node/cli/init-cmd.d.ts +0 -3
  14. package/dist/node/cli/init-cmd.js +0 -18
  15. package/dist/node/cli/options.d.ts +0 -4
  16. package/dist/node/cli/options.js +0 -14
  17. package/dist/node/cli/serve-cmd.d.ts +0 -3
  18. package/dist/node/cli/serve-cmd.js +0 -14
  19. package/dist/node/cli/version-cmd.d.ts +0 -3
  20. package/dist/node/cli/version-cmd.js +0 -8
  21. package/dist/node/cli.d.ts +0 -2
  22. package/dist/node/cli.js +0 -6
  23. package/dist/node/database.d.ts +0 -50
  24. package/dist/node/database.js +0 -173
  25. package/dist/node/index.d.ts +0 -7
  26. package/dist/node/index.js +0 -5
  27. package/dist/node/native.d.ts +0 -9
  28. package/dist/node/native.js +0 -32
  29. package/dist/node/resolve-bin.d.ts +0 -15
  30. package/dist/node/resolve-bin.js +0 -62
  31. package/dist/resolve-bin.d.ts +0 -15
  32. package/dist/resolve-bin.js +0 -62
  33. package/dist/shared/wasm-envelope.d.ts +0 -41
  34. package/dist/shared/wasm-envelope.js +0 -56
  35. package/dist/udf-types.d.ts +0 -26
  36. package/dist/udf-types.js +0 -16
  37. package/dist/wasm/binding.d.ts +0 -1
  38. package/dist/wasm/binding.js +0 -1
  39. package/dist/wasm/database.d.ts +0 -54
  40. package/dist/wasm/database.js +0 -118
  41. package/dist/wasm/index.d.ts +0 -8
  42. package/dist/wasm/index.js +0 -5
package/README.md CHANGED
@@ -1,86 +1,86 @@
1
- # `@yydb/yydb`
2
-
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.
8
-
9
- For a wire client only (renderer or an app that already runs `yydb serve`), use
10
- [`@yydb/yydb-client`](https://www.npmjs.com/package/@yydb/yydb-client).
11
-
12
- [![npm](https://img.shields.io/npm/v/@yydb/yydb)](https://www.npmjs.com/package/@yydb/yydb)
13
- [![Node.js](https://img.shields.io/node/v/@yydb/yydb)](https://www.npmjs.com/package/@yydb/yydb)
14
-
15
- ## Exports
16
-
17
- | Import | Runtime | Role |
18
- |--------|---------|------|
19
- | `@yydb/yydb` | Node | `Database.open`, micro helpers, VOS re-exports |
20
- | `@yydb/yydb/cli` | Node | CLI (`version`, `init`, `info`, `serve`) |
21
-
22
- Node.js 18+.
23
-
24
- Schema truth lives in the `.yydb` file via `ensureSchema` and VOS documents.
25
-
26
- ## Example
27
-
28
- ```ts
29
- import { Database } from '@yydb/yydb';
30
-
31
- const db = await Database.open('./data/app.yydb');
32
-
33
- await db.ensureSchema(
34
- 1,
35
- `table Setting {
36
- @@id: uuid,
37
- key: utf8,
38
- value: utf8,
39
- }`,
40
- );
41
-
42
- await db.put('theme', 'dark');
43
- console.log(await db.get('theme'));
44
- await db.close();
45
- ```
46
-
47
- The file is created when missing. Schema version and VOS document persist with the data.
48
-
49
- ## API
50
-
51
- ```ts
52
- const db = await Database.open(path, options?);
53
-
54
- await db.ensureSchema(version, vosDocument);
55
- await db.getSchema();
56
- await db.put(key, stringOrBytes);
57
- await db.get(key);
58
- await db.info();
59
- await db.serverVersion();
60
- await db.registerMicro(microDefinition);
61
- await db.callScalar('double', 1, [21]);
62
- await db.close();
63
- ```
64
-
65
- `OpenOptions`: `cli` (explicit CLI script path), `port` (preferred loopback port), `serveArgs` (extra `yydb serve`
66
- arguments). `binary` is a deprecated alias for `cli`.
67
-
68
- The native binding exposes additive operations (`schemaVersion`, `schemaDocument`, `recordCount`, `journalMode`,
69
- `checkpoint`, `walFrameCount`, `get`, `put`); the CLI composes commands from them.
70
-
71
- ## Related packages
72
-
73
- | Need | Package |
74
- |------|---------|
75
- | Node embedded engine and CLI (this package) | **`@yydb/yydb`** |
76
- | Browser, pure TypeScript | **`@yydb/light-db`** |
77
- | Wire client only | [`@yydb/yydb-client`](https://www.npmjs.com/package/@yydb/yydb-client) |
78
- | In-process Rust embed | [`yydb`](https://crates.io/crates/yydb) |
79
- | Agent skills (wire protocol) | [`@yydb/yydb-skills`](https://www.npmjs.com/package/@yydb/yydb-skills) |
80
-
81
- Electron: main process can use `@yydb/yydb`; renderer code can use `@yydb/yydb-client` against the main-process
82
- endpoint.
83
-
84
- The managed engine listens on `127.0.0.1` with no authentication — keep the endpoint private.
85
-
86
- [YYDB overview](https://github.com/yy-database/yydb.rs) · [User guides](https://github.com/yy-database/yydb.rs/tree/dev/projects/packages/homepage/documentation/zh-hans)
1
+ # `@yydb/yydb`
2
+
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.
8
+
9
+ For a wire client only (renderer or an app that already runs `yydb serve`), use
10
+ [`@yydb/yydb-client`](https://www.npmjs.com/package/@yydb/yydb-client).
11
+
12
+ [![npm](https://img.shields.io/npm/v/@yydb/yydb)](https://www.npmjs.com/package/@yydb/yydb)
13
+ [![Node.js](https://img.shields.io/node/v/@yydb/yydb)](https://www.npmjs.com/package/@yydb/yydb)
14
+
15
+ ## Exports
16
+
17
+ | Import | Runtime | Role |
18
+ |--------|---------|------|
19
+ | `@yydb/yydb` | Node | `Database.open`, micro helpers, VOS re-exports |
20
+ | `@yydb/yydb/cli` | Node | CLI (`version`, `init`, `info`, `serve`) |
21
+
22
+ Node.js 18+.
23
+
24
+ Schema truth lives in the `.yydb` file via `ensureSchema` and VOS documents.
25
+
26
+ ## Example
27
+
28
+ ```ts
29
+ import { Database } from '@yydb/yydb';
30
+
31
+ const db = await Database.open('./data/app.yydb');
32
+
33
+ await db.ensureSchema(
34
+ 1,
35
+ `table Setting {
36
+ @@id: uuid,
37
+ key: utf8,
38
+ value: utf8,
39
+ }`,
40
+ );
41
+
42
+ await db.put('theme', 'dark');
43
+ console.log(await db.get('theme'));
44
+ await db.close();
45
+ ```
46
+
47
+ The file is created when missing. Schema version and VOS document persist with the data.
48
+
49
+ ## API
50
+
51
+ ```ts
52
+ const db = await Database.open(path, options?);
53
+
54
+ await db.ensureSchema(version, vosDocument);
55
+ await db.getSchema();
56
+ await db.put(key, stringOrBytes);
57
+ await db.get(key);
58
+ await db.info();
59
+ await db.serverVersion();
60
+ await db.registerMicro(microDefinition);
61
+ await db.callScalar('double', 1, [21]);
62
+ await db.close();
63
+ ```
64
+
65
+ `OpenOptions`: `cli` (explicit CLI script path), `port` (preferred loopback port), `serveArgs` (extra `yydb serve`
66
+ arguments). `binary` is a deprecated alias for `cli`.
67
+
68
+ The native binding exposes additive operations (`schemaVersion`, `schemaDocument`, `recordCount`, `journalMode`,
69
+ `checkpoint`, `walFrameCount`, `get`, `put`); the CLI composes commands from them.
70
+
71
+ ## Related packages
72
+
73
+ | Need | Package |
74
+ |------|---------|
75
+ | Node embedded engine and CLI (this package) | **`@yydb/yydb`** |
76
+ | Browser, pure TypeScript | **`@yydb/light-db`** |
77
+ | Wire client only | [`@yydb/yydb-client`](https://www.npmjs.com/package/@yydb/yydb-client) |
78
+ | In-process Rust embed | [`yydb`](https://crates.io/crates/yydb) |
79
+ | Agent skills (wire protocol) | [`@yydb/yydb-skills`](https://www.npmjs.com/package/@yydb/yydb-skills) |
80
+
81
+ Electron: main process can use `@yydb/yydb`; renderer code can use `@yydb/yydb-client` against the main-process
82
+ endpoint.
83
+
84
+ The managed engine listens on `127.0.0.1` with no authentication — keep the endpoint private.
85
+
86
+ [YYDB overview](https://github.com/yy-database/yydb.rs) · [User guides](https://github.com/yy-database/yydb.rs/tree/dev/projects/packages/homepage/documentation/zh-hans)
package/package.json CHANGED
@@ -1,38 +1,41 @@
1
1
  {
2
+ "name": "@yydb/yydb",
3
+ "version": "0.0.17",
4
+ "description": "YYDB Node embedded engine and CLI",
5
+ "license": "MPL-2.0",
6
+ "type": "module",
2
7
  "bin": {
3
8
  "yydb": "./dist/cli.js"
4
9
  },
5
- "bugs": {
6
- "url": "https://github.com/yy-database/yydb.rs/issues"
7
- },
8
- "dependencies": {
9
- "@vmz/commander": "^0.3.5",
10
- "@vmz/diagnostic": "^0.3.5",
11
- "@voml/vos": "^0.0.1"
12
- },
13
- "description": "YYDB Node embedded engine and CLI",
14
- "devDependencies": {
15
- "@types/node": "^20.10.0",
16
- "typescript": "~5.3.0"
17
- },
18
- "engines": {
19
- "node": ">=18"
20
- },
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
21
12
  "exports": {
22
13
  ".": {
23
- "import": "./dist/index.js",
24
- "types": "./dist/index.d.ts"
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
25
16
  },
26
17
  "./cli": {
27
- "import": "./dist/cli.js",
28
- "types": "./dist/cli.d.ts"
18
+ "types": "./dist/cli.d.ts",
19
+ "import": "./dist/cli.js"
29
20
  }
30
21
  },
31
22
  "files": [
32
23
  "dist",
33
24
  "README.md"
34
25
  ],
35
- "homepage": "https://github.com/yy-database/yydb.rs/tree/dev/projects/packages/yydb#readme",
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.json",
28
+ "test": "pnpm run build && node --experimental-strip-types --test src/**/*.test.ts"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/yy-database/yydb.git",
33
+ "directory": "projects/packages/yydb"
34
+ },
35
+ "homepage": "https://github.com/yy-database/yydb/tree/dev/projects/packages/yydb#readme",
36
+ "bugs": {
37
+ "url": "https://github.com/yy-database/yydb/issues"
38
+ },
36
39
  "keywords": [
37
40
  "yydb",
38
41
  "vos",
@@ -40,28 +43,25 @@
40
43
  "embedded",
41
44
  "typescript"
42
45
  ],
43
- "license": "MPL-2.0",
44
- "main": "./dist/index.js",
45
- "name": "@yydb/yydb",
46
- "optionalDependencies": {
47
- "@yydb/yydb-darwin-arm64": "0.0.15",
48
- "@yydb/yydb-darwin-x64": "0.0.15",
49
- "@yydb/yydb-linux-x64": "0.0.15",
50
- "@yydb/yydb-win32-x64": "0.0.15"
51
- },
52
46
  "publishConfig": {
53
47
  "access": "public"
54
48
  },
55
- "repository": {
56
- "directory": "projects/packages/yydb",
57
- "type": "git",
58
- "url": "git+https://github.com/yy-database/yydb.rs.git"
49
+ "dependencies": {
50
+ "@vmz/commander": "^0.3.5",
51
+ "@vmz/diagnostic": "^0.3.5",
52
+ "@voml/vos": "^0.0.1"
59
53
  },
60
- "scripts": {
61
- "build": "tsc -p tsconfig.json",
62
- "test": "pnpm run build && node --experimental-strip-types --test src/**/*.test.ts"
54
+ "devDependencies": {
55
+ "@types/node": "^20.10.0",
56
+ "typescript": "~5.3.0"
63
57
  },
64
- "type": "module",
65
- "types": "./dist/index.d.ts",
66
- "version": "0.0.15"
58
+ "engines": {
59
+ "node": ">=18"
60
+ },
61
+ "optionalDependencies": {
62
+ "@yydb/yydb-darwin-arm64": "0.0.17",
63
+ "@yydb/yydb-darwin-x64": "0.0.17",
64
+ "@yydb/yydb-linux-x64": "0.0.17",
65
+ "@yydb/yydb-win32-x64": "0.0.17"
66
+ }
67
67
  }
@@ -1,50 +0,0 @@
1
- import { defineMicro as buildMicro, type DefinedMicro, type MicroHandle } from './micro.js';
2
- import type { UdfTypeDescriptor } from './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 UdfTypeDescriptor[], TReturn extends UdfTypeDescriptor>(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 UdfTypeDescriptor[], TReturn extends UdfTypeDescriptor>(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/database.js DELETED
@@ -1,181 +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, MicroSessionRegistry } from './micro.js';
7
- import { resolveYydbCli } from './resolve-bin.js';
8
- function microFingerprint(name, version) {
9
- const bytes = new Uint8Array(32);
10
- const seed = `${name}@${version}`;
11
- for (let index = 0; index < bytes.byteLength; index += 1) {
12
- bytes[index] = seed.charCodeAt(index % seed.length) & 0xff;
13
- }
14
- return bytes;
15
- }
16
- async function freeLoopbackPort() {
17
- return await new Promise((resolve, reject) => {
18
- const server = net.createServer();
19
- server.listen(0, '127.0.0.1', () => {
20
- const address = server.address();
21
- if (!address || typeof address === 'string') {
22
- server.close();
23
- reject(new Error('could not allocate loopback port'));
24
- return;
25
- }
26
- const { port } = address;
27
- server.close((error) => {
28
- if (error)
29
- reject(error);
30
- else
31
- resolve(port);
32
- });
33
- });
34
- server.on('error', reject);
35
- });
36
- }
37
- async function waitForTcp(host, port, timeoutMs) {
38
- const deadline = Date.now() + timeoutMs;
39
- while (Date.now() < deadline) {
40
- try {
41
- await new Promise((resolve, reject) => {
42
- const socket = net.connect({ host, port }, () => {
43
- socket.end();
44
- resolve();
45
- });
46
- socket.on('error', reject);
47
- });
48
- return;
49
- }
50
- catch {
51
- await new Promise((r) => setTimeout(r, 40));
52
- }
53
- }
54
- throw new Error(`yydb engine did not accept connections on ${host}:${port}`);
55
- }
56
- /**
57
- * Node-facing YYDB handle. Looks like one library; owns a private loopback
58
- * `yydb serve` child under the hood.
59
- */
60
- export class Database {
61
- path;
62
- endpoint;
63
- client;
64
- child;
65
- microRegistry;
66
- constructor(dbPath, endpoint, client, child) {
67
- this.path = dbPath;
68
- this.endpoint = endpoint;
69
- this.client = client;
70
- this.child = child;
71
- this.microRegistry = new MicroSessionRegistry();
72
- this.client.setMicroHostHandler((payload) => this.microRegistry.invokeFromWire(payload));
73
- }
74
- /**
75
- * Open (create) a `.yydb` file. Spawns the engine on `127.0.0.1` automatically.
76
- */
77
- static async open(dbPath, options = {}) {
78
- const resolved = path.resolve(dbPath);
79
- fs.mkdirSync(path.dirname(resolved), { recursive: true });
80
- const cli = options.cli ?? options.binary ?? resolveYydbCli();
81
- const port = options.port ?? (await freeLoopbackPort());
82
- const bind = `127.0.0.1:${port}`;
83
- const args = [cli, 'serve', resolved, '--bind', bind, ...(options.serveArgs ?? [])];
84
- const child = spawn(process.execPath, args, {
85
- stdio: 'pipe',
86
- windowsHide: true,
87
- });
88
- let stderr = '';
89
- child.stderr?.setEncoding('utf8');
90
- child.stderr?.on('data', (chunk) => {
91
- stderr += chunk;
92
- });
93
- const exitPromise = new Promise((_, reject) => {
94
- child.once('exit', (code, signal) => {
95
- reject(new Error(`yydb engine exited early (code=${code}, signal=${signal}): ${stderr.trim()}`));
96
- });
97
- child.once('error', reject);
98
- });
99
- try {
100
- await Promise.race([waitForTcp('127.0.0.1', port, 8000), exitPromise]);
101
- const client = await connect(bind);
102
- child.removeAllListeners('exit');
103
- child.removeAllListeners('error');
104
- child.on('exit', () => {
105
- /* closed via Database.close or crash */
106
- });
107
- return new Database(resolved, bind, client, child);
108
- }
109
- catch (error) {
110
- child.kill('SIGTERM');
111
- throw error;
112
- }
113
- }
114
- async serverVersion() {
115
- return this.client.serverVersion();
116
- }
117
- async info() {
118
- return this.client.info();
119
- }
120
- async getSchema() {
121
- return this.client.getSchema();
122
- }
123
- async ensureSchema(version, document) {
124
- await this.client.ensureSchema(version, document);
125
- }
126
- async get(key) {
127
- return this.client.get(key);
128
- }
129
- async put(key, value) {
130
- await this.client.put(key, value);
131
- }
132
- /**
133
- * Build a typed session-local micro definition. Does not register it with
134
- * the engine until [`registerMicro`](./database.ts) is called.
135
- */
136
- defineMicro(definition) {
137
- return buildMicro(definition);
138
- }
139
- /**
140
- * Install a [`defineMicro`](./database.ts) definition into the current
141
- * session registry and sync metadata to the private engine. Host micros are
142
- * session-local and never written to `.yydb`.
143
- */
144
- async registerMicro(definition) {
145
- const handle = this.microRegistry.register(definition);
146
- await this.client.registerMicro({
147
- hostId: handle.hostId,
148
- handleVersion: handle.implementationVersion,
149
- udfVersion: definition.version,
150
- name: definition.name,
151
- functionId: handle.functionId,
152
- args: definition.args.map((arg) => arg.kind),
153
- returns: definition.returns.kind,
154
- fingerprint: microFingerprint(definition.name, definition.version),
155
- });
156
- return handle;
157
- }
158
- /** Invoke a registered scalar UDF on the private engine. */
159
- async callScalar(name, version, args) {
160
- return this.client.callScalar(name, version, args);
161
- }
162
- /** Stop the private engine process. */
163
- async close() {
164
- this.client.close();
165
- const child = this.child;
166
- this.child = null;
167
- if (!child || child.exitCode !== null || child.killed) {
168
- return;
169
- }
170
- await new Promise((resolve) => {
171
- child.once('exit', () => resolve());
172
- child.kill('SIGTERM');
173
- setTimeout(() => {
174
- if (child.exitCode === null && !child.killed) {
175
- child.kill('SIGKILL');
176
- }
177
- resolve();
178
- }, 2000);
179
- });
180
- }
181
- }
package/dist/micro.d.ts DELETED
@@ -1,63 +0,0 @@
1
- import type { InferUdfArgs, InferUdfReturn, MicroEffect, MicroInvocationMode, UdfTypeDescriptor } from './udf-types.js';
2
- /** Input accepted by [`Database.defineMicro`](./database.ts). */
3
- export interface TsMicroDefinitionInput<TArgs extends readonly UdfTypeDescriptor[], TReturn extends UdfTypeDescriptor> {
4
- readonly name: string;
5
- readonly version: number;
6
- readonly args: TArgs;
7
- readonly returns: TReturn;
8
- readonly effect: MicroEffect;
9
- readonly deterministic: boolean;
10
- readonly mode?: MicroInvocationMode;
11
- readonly fn: (...args: InferUdfArgs<TArgs>) => InferUdfReturn<TReturn>;
12
- }
13
- /** Opaque definition produced by `defineMicro` before session registration. */
14
- export interface DefinedMicro<TArgs extends readonly UdfTypeDescriptor[] = readonly UdfTypeDescriptor[], TReturn extends UdfTypeDescriptor = UdfTypeDescriptor> {
15
- readonly name: string;
16
- readonly version: number;
17
- readonly args: TArgs;
18
- readonly returns: TReturn;
19
- readonly effect: MicroEffect;
20
- readonly deterministic: boolean;
21
- readonly mode: MicroInvocationMode;
22
- readonly placement: 'host';
23
- readonly fn: (...args: InferUdfArgs<TArgs>) => InferUdfReturn<TReturn>;
24
- }
25
- /** Handle returned after `registerMicro` installs a micro into the session. */
26
- export interface MicroHandle {
27
- readonly name: string;
28
- readonly version: number;
29
- readonly functionId: string;
30
- readonly hostId: number;
31
- /** Monotonic host implementation version for opaque handle checks. */
32
- readonly implementationVersion: number;
33
- }
34
- type AnyDefinedMicro = DefinedMicro<readonly UdfTypeDescriptor[], UdfTypeDescriptor>;
35
- /**
36
- * Process-local registry for JS functions behind opaque host handles.
37
- * Rust keeps `host_id + function_id + version`, not the closure.
38
- */
39
- export declare class MicroSessionRegistry {
40
- readonly hostId: number;
41
- private nextFunctionId;
42
- private readonly byKey;
43
- private readonly byFunctionId;
44
- constructor(hostId?: number);
45
- /** Installs a defined micro into the current session registry. */
46
- register<TArgs extends readonly UdfTypeDescriptor[], TReturn extends UdfTypeDescriptor>(definition: DefinedMicro<TArgs, TReturn>): MicroHandle;
47
- /** Returns a registered micro by opaque host handle. */
48
- resolve(handle: MicroHandle): AnyDefinedMicro | undefined;
49
- /** Invokes a registered micro from a wire `MicroHostInvoke` payload. */
50
- invokeFromWire(payload: {
51
- hostId: number;
52
- handleVersion: number;
53
- functionId: string;
54
- args: readonly unknown[];
55
- }): string | number | boolean | null;
56
- /** Invokes a registered scalar micro (host adapter entry point). */
57
- invokeScalar(handle: MicroHandle, args: unknown[]): unknown;
58
- /** Lists logical names currently registered in this session. */
59
- list(): string[];
60
- }
61
- /** Builds a session-local micro definition without registering it. */
62
- export declare function defineMicro<TArgs extends readonly UdfTypeDescriptor[], TReturn extends UdfTypeDescriptor>(input: TsMicroDefinitionInput<TArgs, TReturn>): DefinedMicro<TArgs, TReturn>;
63
- export {};