@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.
- package/README.md +86 -86
- package/package.json +40 -40
- package/dist/database.d.ts +0 -50
- package/dist/database.js +0 -181
- package/dist/micro.d.ts +0 -63
- package/dist/micro.js +0 -160
- package/dist/native.d.ts +0 -9
- package/dist/native.js +0 -32
- package/dist/node/cli/cli.d.ts +0 -1
- package/dist/node/cli/cli.js +0 -25
- package/dist/node/cli/info-cmd.d.ts +0 -3
- package/dist/node/cli/info-cmd.js +0 -10
- package/dist/node/cli/init-cmd.d.ts +0 -3
- package/dist/node/cli/init-cmd.js +0 -18
- package/dist/node/cli/options.d.ts +0 -4
- package/dist/node/cli/options.js +0 -14
- package/dist/node/cli/serve-cmd.d.ts +0 -3
- package/dist/node/cli/serve-cmd.js +0 -14
- package/dist/node/cli/version-cmd.d.ts +0 -3
- package/dist/node/cli/version-cmd.js +0 -8
- package/dist/node/cli.d.ts +0 -2
- package/dist/node/cli.js +0 -6
- 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/node/native.js +0 -32
- package/dist/node/resolve-bin.d.ts +0 -15
- package/dist/node/resolve-bin.js +0 -62
- package/dist/resolve-bin.d.ts +0 -15
- package/dist/resolve-bin.js +0 -62
- package/dist/shared/wasm-envelope.d.ts +0 -41
- package/dist/shared/wasm-envelope.js +0 -56
- package/dist/udf-types.d.ts +0 -26
- package/dist/udf-types.js +0 -16
- package/dist/wasm/binding.d.ts +0 -1
- package/dist/wasm/binding.js +0 -1
- package/dist/wasm/database.d.ts +0 -54
- package/dist/wasm/database.js +0 -118
- package/dist/wasm/index.d.ts +0 -8
- package/dist/wasm/index.js +0 -5
package/dist/node/resolve-bin.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
/** Map Node platform/arch to optionalDependency package suffix. */
|
|
5
|
-
export function platformKey(platform = process.platform, arch = process.arch) {
|
|
6
|
-
if (platform === 'win32' && arch === 'x64')
|
|
7
|
-
return 'win32-x64';
|
|
8
|
-
if (platform === 'linux' && arch === 'x64')
|
|
9
|
-
return 'linux-x64';
|
|
10
|
-
if (platform === 'darwin' && arch === 'x64')
|
|
11
|
-
return 'darwin-x64';
|
|
12
|
-
if (platform === 'darwin' && arch === 'arm64')
|
|
13
|
-
return 'darwin-arm64';
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
/** Native binding filename inside each `@yydb/yydb-<platform>` package `lib/`. */
|
|
17
|
-
export function nativeBindingName(key) {
|
|
18
|
-
switch (key) {
|
|
19
|
-
case 'win32-x64':
|
|
20
|
-
return 'yydb-win32-x64-msvc.node';
|
|
21
|
-
case 'linux-x64':
|
|
22
|
-
return 'yydb-linux-x64-gnu.node';
|
|
23
|
-
case 'darwin-x64':
|
|
24
|
-
return 'yydb-darwin-x64.node';
|
|
25
|
-
case 'darwin-arm64':
|
|
26
|
-
return 'yydb-darwin-arm64.node';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function existsFile(filePath) {
|
|
30
|
-
try {
|
|
31
|
-
fs.accessSync(filePath, fs.constants.F_OK);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Resolve the TypeScript `yydb` CLI entry script.
|
|
40
|
-
* Order: `YYDB_CLI` → this package `dist/cli.js`.
|
|
41
|
-
*/
|
|
42
|
-
export function resolveYydbCli() {
|
|
43
|
-
const fromEnv = process.env.YYDB_CLI?.trim();
|
|
44
|
-
if (fromEnv) {
|
|
45
|
-
if (!existsFile(fromEnv)) {
|
|
46
|
-
throw new Error(`YYDB_CLI points to missing script: ${fromEnv}`);
|
|
47
|
-
}
|
|
48
|
-
return path.resolve(fromEnv);
|
|
49
|
-
}
|
|
50
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
51
|
-
const candidate = path.join(here, 'cli.js');
|
|
52
|
-
if (!existsFile(candidate)) {
|
|
53
|
-
throw new Error('YYDB CLI script not found. Build `@yydb/yydb` (`pnpm --filter @yydb/yydb build`) or set YYDB_CLI.');
|
|
54
|
-
}
|
|
55
|
-
return candidate;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @deprecated Use {@link resolveYydbCli}. Kept for callers that still import this name.
|
|
59
|
-
*/
|
|
60
|
-
export function resolveYydbBinary() {
|
|
61
|
-
return resolveYydbCli();
|
|
62
|
-
}
|
package/dist/resolve-bin.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
export type PlatformKey = 'win32-x64' | 'linux-x64' | 'darwin-x64' | 'darwin-arm64';
|
|
3
|
-
/** Map Node platform/arch to optionalDependency package suffix. */
|
|
4
|
-
export declare function platformKey(platform?: NodeJS.Platform, arch?: NodeJS.Architecture): PlatformKey | null;
|
|
5
|
-
/** Native binding filename inside each `@yydb/yydb-<platform>` package `lib/`. */
|
|
6
|
-
export declare function nativeBindingName(key: PlatformKey): string;
|
|
7
|
-
/**
|
|
8
|
-
* Resolve the TypeScript `yydb` CLI entry script.
|
|
9
|
-
* Order: `YYDB_CLI` → this package `dist/cli.js`.
|
|
10
|
-
*/
|
|
11
|
-
export declare function resolveYydbCli(): string;
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Use {@link resolveYydbCli}. Kept for callers that still import this name.
|
|
14
|
-
*/
|
|
15
|
-
export declare function resolveYydbBinary(): string;
|
package/dist/resolve-bin.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
/** Map Node platform/arch to optionalDependency package suffix. */
|
|
5
|
-
export function platformKey(platform = process.platform, arch = process.arch) {
|
|
6
|
-
if (platform === 'win32' && arch === 'x64')
|
|
7
|
-
return 'win32-x64';
|
|
8
|
-
if (platform === 'linux' && arch === 'x64')
|
|
9
|
-
return 'linux-x64';
|
|
10
|
-
if (platform === 'darwin' && arch === 'x64')
|
|
11
|
-
return 'darwin-x64';
|
|
12
|
-
if (platform === 'darwin' && arch === 'arm64')
|
|
13
|
-
return 'darwin-arm64';
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
/** Native binding filename inside each `@yydb/yydb-<platform>` package `lib/`. */
|
|
17
|
-
export function nativeBindingName(key) {
|
|
18
|
-
switch (key) {
|
|
19
|
-
case 'win32-x64':
|
|
20
|
-
return 'yydb-win32-x64-msvc.node';
|
|
21
|
-
case 'linux-x64':
|
|
22
|
-
return 'yydb-linux-x64-gnu.node';
|
|
23
|
-
case 'darwin-x64':
|
|
24
|
-
return 'yydb-darwin-x64.node';
|
|
25
|
-
case 'darwin-arm64':
|
|
26
|
-
return 'yydb-darwin-arm64.node';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function existsFile(filePath) {
|
|
30
|
-
try {
|
|
31
|
-
fs.accessSync(filePath, fs.constants.F_OK);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Resolve the TypeScript `yydb` CLI entry script.
|
|
40
|
-
* Order: `YYDB_CLI` → this package `dist/cli.js`.
|
|
41
|
-
*/
|
|
42
|
-
export function resolveYydbCli() {
|
|
43
|
-
const fromEnv = process.env.YYDB_CLI?.trim();
|
|
44
|
-
if (fromEnv) {
|
|
45
|
-
if (!existsFile(fromEnv)) {
|
|
46
|
-
throw new Error(`YYDB_CLI points to missing script: ${fromEnv}`);
|
|
47
|
-
}
|
|
48
|
-
return path.resolve(fromEnv);
|
|
49
|
-
}
|
|
50
|
-
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
51
|
-
const candidate = path.join(here, 'cli.js');
|
|
52
|
-
if (!existsFile(candidate)) {
|
|
53
|
-
throw new Error('YYDB CLI script not found. Build `@yydb/yydb` (`pnpm --filter @yydb/yydb build`) or set YYDB_CLI.');
|
|
54
|
-
}
|
|
55
|
-
return candidate;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @deprecated Use {@link resolveYydbCli}. Kept for callers that still import this name.
|
|
59
|
-
*/
|
|
60
|
-
export function resolveYydbBinary() {
|
|
61
|
-
return resolveYydbCli();
|
|
62
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/** Parsed `{ ok, rows, error, code }` envelope from wasm VOS 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 parseWasmRowsResult(payload: string, operation: string): WasmRowsResult;
|
|
38
|
-
export declare function parseWasmUnitResult(payload: string, operation: string): void;
|
|
39
|
-
export declare function parseWasmSchemaResult(payload: string, operation: string): SchemaVersion | null;
|
|
40
|
-
export declare function parseWasmScalarResult(payload: string, operation: string): WireScalarValue;
|
|
41
|
-
export declare function parseWasmKvGetResult(payload: string, operation: string): Uint8Array | null;
|
|
@@ -1,56 +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 parseWasmRowsResult(payload, operation) {
|
|
21
|
-
const parsed = parseJson(payload, operation);
|
|
22
|
-
if (!parsed.ok) {
|
|
23
|
-
throw envelopeError(parsed, operation);
|
|
24
|
-
}
|
|
25
|
-
return parsed;
|
|
26
|
-
}
|
|
27
|
-
export function parseWasmUnitResult(payload, operation) {
|
|
28
|
-
const parsed = parseJson(payload, operation);
|
|
29
|
-
if (!parsed.ok) {
|
|
30
|
-
throw envelopeError(parsed, operation);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export function parseWasmSchemaResult(payload, operation) {
|
|
34
|
-
const parsed = parseJson(payload, operation);
|
|
35
|
-
if (!parsed.ok) {
|
|
36
|
-
throw envelopeError(parsed, operation);
|
|
37
|
-
}
|
|
38
|
-
return parsed.schema;
|
|
39
|
-
}
|
|
40
|
-
export function parseWasmScalarResult(payload, operation) {
|
|
41
|
-
const parsed = parseJson(payload, operation);
|
|
42
|
-
if (!parsed.ok) {
|
|
43
|
-
throw envelopeError(parsed, operation);
|
|
44
|
-
}
|
|
45
|
-
return parsed.value;
|
|
46
|
-
}
|
|
47
|
-
export function parseWasmKvGetResult(payload, operation) {
|
|
48
|
-
const parsed = parseJson(payload, operation);
|
|
49
|
-
if (!parsed.ok) {
|
|
50
|
-
throw envelopeError(parsed, operation);
|
|
51
|
-
}
|
|
52
|
-
if (parsed.value === null) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return Uint8Array.from(parsed.value);
|
|
56
|
-
}
|
package/dist/udf-types.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/** Phase-1 scalar UDF wire kinds aligned with `yydb-udf`. */
|
|
2
|
-
export type UdfScalarKind = 'i64' | 'bool' | 'text' | 'null';
|
|
3
|
-
/** Runtime type descriptor used in `defineMicro` contracts. */
|
|
4
|
-
export interface UdfTypeDescriptor<T = unknown> {
|
|
5
|
-
readonly kind: UdfScalarKind;
|
|
6
|
-
/** Phantom type for author-side inference only. */
|
|
7
|
-
readonly _type?: T;
|
|
8
|
-
}
|
|
9
|
-
/** `i64` argument or return descriptor. */
|
|
10
|
-
export declare function i64(): UdfTypeDescriptor<number>;
|
|
11
|
-
/** `bool` argument or return descriptor. */
|
|
12
|
-
export declare function bool(): UdfTypeDescriptor<boolean>;
|
|
13
|
-
/** `text` argument or return descriptor. */
|
|
14
|
-
export declare function text(): UdfTypeDescriptor<string>;
|
|
15
|
-
/** `null` return descriptor. */
|
|
16
|
-
export declare function nullType(): UdfTypeDescriptor<null>;
|
|
17
|
-
/** Maps descriptor tuple types to positional argument types. */
|
|
18
|
-
export type InferUdfArgs<T extends readonly UdfTypeDescriptor[]> = {
|
|
19
|
-
[K in keyof T]: T[K] extends UdfTypeDescriptor<infer V> ? V : never;
|
|
20
|
-
};
|
|
21
|
-
/** Maps a return descriptor to its value type. */
|
|
22
|
-
export type InferUdfReturn<T extends UdfTypeDescriptor> = T extends UdfTypeDescriptor<infer V> ? V : never;
|
|
23
|
-
/** Session micro effect surface (Phase 1: pure only). */
|
|
24
|
-
export type MicroEffect = 'pure';
|
|
25
|
-
/** Invocation mode stored with the definition for future batch host calls. */
|
|
26
|
-
export type MicroInvocationMode = 'scalar' | 'batch';
|
package/dist/udf-types.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** `i64` argument or return descriptor. */
|
|
2
|
-
export function i64() {
|
|
3
|
-
return { kind: 'i64' };
|
|
4
|
-
}
|
|
5
|
-
/** `bool` argument or return descriptor. */
|
|
6
|
-
export function bool() {
|
|
7
|
-
return { kind: 'bool' };
|
|
8
|
-
}
|
|
9
|
-
/** `text` argument or return descriptor. */
|
|
10
|
-
export function text() {
|
|
11
|
-
return { kind: 'text' };
|
|
12
|
-
}
|
|
13
|
-
/** `null` return descriptor. */
|
|
14
|
-
export function nullType() {
|
|
15
|
-
return { kind: 'null' };
|
|
16
|
-
}
|
package/dist/wasm/binding.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { checkSchema, createMemorySession, initWasm, introspectSchema, openPersistentSession, queryMemory, 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, queryMemory, resetWasmBindingForTests, yydbVersion, } from '@yydb/yydb-unknown-wasm32';
|
package/dist/wasm/database.d.ts
DELETED
|
@@ -1,54 +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
|
-
/** VOS read pipeline (for example `User.filter(x => x.active).collect()`). */
|
|
34
|
-
query(source: string): Record<string, unknown>[];
|
|
35
|
-
/** Unit-valued VOS write programs (for example `User { … }.insert()`). */
|
|
36
|
-
execute(source: string): void;
|
|
37
|
-
/**
|
|
38
|
-
* Build a typed session-local micro definition. Does not register it with
|
|
39
|
-
* the engine until `registerMicro` is called.
|
|
40
|
-
*/
|
|
41
|
-
defineMicro<TArgs extends readonly UdfScalarDescriptor[], TReturn extends UdfScalarDescriptor>(definition: Parameters<typeof buildMicro<TArgs, TReturn>>[0]): DefinedMicro<TArgs, TReturn>;
|
|
42
|
-
/**
|
|
43
|
-
* Install a `defineMicro` definition into the current session registry and
|
|
44
|
-
* sync metadata to the embedded engine. Host micros are session-local.
|
|
45
|
-
*/
|
|
46
|
-
registerMicro<TArgs extends readonly UdfScalarDescriptor[], TReturn extends UdfScalarDescriptor>(definition: DefinedMicro<TArgs, TReturn>): Promise<MicroHandle>;
|
|
47
|
-
/** Invoke a registered scalar UDF on the embedded engine. */
|
|
48
|
-
callScalar(name: string, version: number, args: readonly (string | number | boolean | null)[]): Promise<string | number | boolean | null>;
|
|
49
|
-
/** Whether this handle owns a persistent OPFS session. */
|
|
50
|
-
isPersistent(): boolean;
|
|
51
|
-
/** Close the embedded session. Idempotent; further calls fail with `yydb.session.closed`. */
|
|
52
|
-
close(): Promise<void>;
|
|
53
|
-
private requireSession;
|
|
54
|
-
}
|
package/dist/wasm/database.js
DELETED
|
@@ -1,118 +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, parseWasmRowsResult, 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
|
-
/** VOS read pipeline (for example `User.filter(x => x.active).collect()`). */
|
|
64
|
-
query(source) {
|
|
65
|
-
return parseWasmRowsResult(this.requireSession('query').query(source), 'query').rows;
|
|
66
|
-
}
|
|
67
|
-
/** Unit-valued VOS write programs (for example `User { … }.insert()`). */
|
|
68
|
-
execute(source) {
|
|
69
|
-
parseWasmUnitResult(this.requireSession('execute').execute(source), 'execute');
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Build a typed session-local micro definition. Does not register it with
|
|
73
|
-
* the engine until `registerMicro` is called.
|
|
74
|
-
*/
|
|
75
|
-
defineMicro(definition) {
|
|
76
|
-
return buildMicro(definition);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Install a `defineMicro` definition into the current session registry and
|
|
80
|
-
* sync metadata to the embedded engine. Host micros are session-local.
|
|
81
|
-
*/
|
|
82
|
-
async registerMicro(definition) {
|
|
83
|
-
const handle = this.microRegistry.register(definition);
|
|
84
|
-
const body = encodeMicroRegister({
|
|
85
|
-
hostId: handle.hostId,
|
|
86
|
-
handleVersion: handle.implementationVersion,
|
|
87
|
-
udfVersion: definition.version,
|
|
88
|
-
name: definition.name,
|
|
89
|
-
functionId: handle.functionId,
|
|
90
|
-
args: definition.args.map(udfWireKind),
|
|
91
|
-
returns: udfWireKind(definition.returns),
|
|
92
|
-
fingerprint: microFingerprint(definition.name, definition.version),
|
|
93
|
-
});
|
|
94
|
-
parseWasmUnitResult(this.requireSession('microRegister').registerMicro(body), 'microRegister');
|
|
95
|
-
return handle;
|
|
96
|
-
}
|
|
97
|
-
/** Invoke a registered scalar UDF on the embedded engine. */
|
|
98
|
-
async callScalar(name, version, args) {
|
|
99
|
-
const body = encodeScalarCall(name, version, args);
|
|
100
|
-
return parseWasmScalarResult(this.requireSession('callScalar').callScalar(body), 'callScalar');
|
|
101
|
-
}
|
|
102
|
-
/** Whether this handle owns a persistent OPFS session. */
|
|
103
|
-
isPersistent() {
|
|
104
|
-
return this.kind === 'persistent';
|
|
105
|
-
}
|
|
106
|
-
/** Close the embedded session. Idempotent; further calls fail with `yydb.session.closed`. */
|
|
107
|
-
async close() {
|
|
108
|
-
const session = this.session;
|
|
109
|
-
this.session = null;
|
|
110
|
-
session?.close();
|
|
111
|
-
}
|
|
112
|
-
requireSession(operation) {
|
|
113
|
-
if (!this.session) {
|
|
114
|
-
throw new YydbError(YydbErrorCodes.sessionClosed, `${operation}: @yydb/yydb/wasm session is closed`, { operation });
|
|
115
|
-
}
|
|
116
|
-
return this.session;
|
|
117
|
-
}
|
|
118
|
-
}
|
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, queryMemory, 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, queryMemory, resetWasmBindingForTests, yydbVersion, } from './binding.js';
|
|
4
|
-
export { defineMicro, MicroSessionRegistry } from '../shared/micro.js';
|
|
5
|
-
export * from '../shared/vos.js';
|