@yydb/yydb 0.0.12 → 0.0.15

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 (53) hide show
  1. package/README.md +86 -86
  2. package/dist/api/database.d.ts +40 -0
  3. package/dist/api/database.js +16 -0
  4. package/dist/cli/cli.js +28 -1
  5. package/dist/cli/info-cmd.js +30 -1
  6. package/dist/cli/verify-cmd.d.ts +11 -0
  7. package/dist/cli/verify-cmd.js +73 -0
  8. package/dist/database.d.ts +50 -0
  9. package/dist/database.js +181 -0
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/micro.d.ts +63 -0
  13. package/dist/micro.js +160 -0
  14. package/dist/native/binding.d.ts +8 -0
  15. package/dist/native.d.ts +9 -0
  16. package/dist/native.js +32 -0
  17. package/dist/node/cli/cli.d.ts +1 -0
  18. package/dist/node/cli/cli.js +25 -0
  19. package/dist/node/cli/info-cmd.d.ts +3 -0
  20. package/dist/node/cli/info-cmd.js +10 -0
  21. package/dist/node/cli/init-cmd.d.ts +3 -0
  22. package/dist/node/cli/init-cmd.js +18 -0
  23. package/dist/node/cli/options.d.ts +4 -0
  24. package/dist/node/cli/options.js +14 -0
  25. package/dist/node/cli/serve-cmd.d.ts +3 -0
  26. package/dist/node/cli/serve-cmd.js +14 -0
  27. package/dist/node/cli/version-cmd.d.ts +3 -0
  28. package/dist/node/cli/version-cmd.js +8 -0
  29. package/dist/node/cli.d.ts +2 -0
  30. package/dist/node/cli.js +6 -0
  31. package/dist/node/database.d.ts +50 -0
  32. package/dist/node/database.js +173 -0
  33. package/dist/node/index.d.ts +7 -0
  34. package/dist/node/index.js +5 -0
  35. package/dist/node/native.d.ts +9 -0
  36. package/dist/node/native.js +32 -0
  37. package/dist/node/resolve-bin.d.ts +15 -0
  38. package/dist/node/resolve-bin.js +62 -0
  39. package/dist/resolve-bin.d.ts +15 -0
  40. package/dist/resolve-bin.js +62 -0
  41. package/dist/shared/errors.d.ts +62 -15
  42. package/dist/shared/errors.js +64 -41
  43. package/dist/shared/wasm-envelope.d.ts +41 -0
  44. package/dist/shared/wasm-envelope.js +56 -0
  45. package/dist/udf-types.d.ts +26 -0
  46. package/dist/udf-types.js +16 -0
  47. package/dist/wasm/binding.d.ts +1 -0
  48. package/dist/wasm/binding.js +1 -0
  49. package/dist/wasm/database.d.ts +54 -0
  50. package/dist/wasm/database.js +118 -0
  51. package/dist/wasm/index.d.ts +8 -0
  52. package/dist/wasm/index.js +5 -0
  53. package/package.json +40 -40
@@ -0,0 +1,118 @@
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
+ }
@@ -0,0 +1,8 @@
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';
@@ -0,0 +1,5 @@
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';
package/package.json CHANGED
@@ -1,41 +1,38 @@
1
1
  {
2
- "name": "@yydb/yydb",
3
- "version": "0.0.12",
4
- "description": "YYDB Node embedded engine and CLI",
5
- "license": "MPL-2.0",
6
- "type": "module",
7
2
  "bin": {
8
3
  "yydb": "./dist/cli.js"
9
4
  },
10
- "main": "./dist/index.js",
11
- "types": "./dist/index.d.ts",
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
+ },
12
21
  "exports": {
13
22
  ".": {
14
- "types": "./dist/index.d.ts",
15
- "import": "./dist/index.js"
23
+ "import": "./dist/index.js",
24
+ "types": "./dist/index.d.ts"
16
25
  },
17
26
  "./cli": {
18
- "types": "./dist/cli.d.ts",
19
- "import": "./dist/cli.js"
27
+ "import": "./dist/cli.js",
28
+ "types": "./dist/cli.d.ts"
20
29
  }
21
30
  },
22
31
  "files": [
23
32
  "dist",
24
33
  "README.md"
25
34
  ],
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
- },
35
+ "homepage": "https://github.com/yy-database/yydb.rs/tree/dev/projects/packages/yydb#readme",
39
36
  "keywords": [
40
37
  "yydb",
41
38
  "vos",
@@ -43,25 +40,28 @@
43
40
  "embedded",
44
41
  "typescript"
45
42
  ],
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
+ },
46
52
  "publishConfig": {
47
53
  "access": "public"
48
54
  },
49
- "dependencies": {
50
- "@vmz/commander": "^0.3.5",
51
- "@vmz/diagnostic": "^0.3.5",
52
- "@voml/vos": "^0.0.1"
53
- },
54
- "devDependencies": {
55
- "@types/node": "^20.10.0",
56
- "typescript": "~5.3.0"
55
+ "repository": {
56
+ "directory": "projects/packages/yydb",
57
+ "type": "git",
58
+ "url": "git+https://github.com/yy-database/yydb.rs.git"
57
59
  },
58
- "engines": {
59
- "node": ">=18"
60
+ "scripts": {
61
+ "build": "tsc -p tsconfig.json",
62
+ "test": "pnpm run build && node --experimental-strip-types --test src/**/*.test.ts"
60
63
  },
61
- "optionalDependencies": {
62
- "@yydb/yydb-darwin-arm64": "0.0.12",
63
- "@yydb/yydb-darwin-x64": "0.0.12",
64
- "@yydb/yydb-linux-x64": "0.0.12",
65
- "@yydb/yydb-win32-x64": "0.0.12"
66
- }
64
+ "type": "module",
65
+ "types": "./dist/index.d.ts",
66
+ "version": "0.0.15"
67
67
  }