@yydb/light-db 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.
@@ -1,6 +1,8 @@
1
- import { type WasmSession } from '@yydb/yydb-unknown-wasm32';
2
- import { type EmittableItem } from '@voml/vos';
3
- /** Schema 版本与文档。 */
1
+ /**
2
+ * Schema 版本与文档。
3
+ *
4
+ * 共享类型:纯 TS {@link Database} 与 WASM {@link WasmDatabase} 都使用同一版本模型。
5
+ */
4
6
  export interface SchemaVersion {
5
7
  version: number;
6
8
  document: string;
@@ -32,73 +34,68 @@ export interface MigrateOptions {
32
34
  toField: string;
33
35
  }>;
34
36
  }
35
- /** 打开浏览器数据库的选项。 */
37
+ /** 打开浏览器 WASM 数据库的选项。 */
36
38
  export interface OpenOptions {
37
39
  /** 使用内存 session(测试专用;默认使用 OPFS 持久 session)。 */
38
40
  memory?: boolean;
39
41
  }
40
- /** Transaction-local handle for callback-style transactions. */
41
- export declare class TransactionHandle {
42
- private readonly session;
43
- constructor(session: WasmSession);
44
- private parseResult;
45
- get(key: string): Promise<Uint8Array | null>;
46
- put(key: string, value: Uint8Array | string): Promise<void>;
47
- delete(key: string): Promise<void>;
48
- scan(options?: ScanOptions): Promise<ScanRow[]>;
49
- batch(changes: readonly BatchChange[]): Promise<void>;
50
- compareExchange(key: string, expected: Uint8Array | string | null, replacement: Uint8Array | string | null): Promise<boolean>;
51
- query<T = Record<string, unknown>>(source: string): Promise<T[]>;
52
- execute(source: string): Promise<void>;
53
- }
42
+ import type { CheckpointResult, StorageEngineStats } from '../core/engine.js';
43
+ import type { LightDatabase, LightDatabaseOptions } from './types.js';
54
44
  /**
55
- * Browser/WASM 侧 YYDB 数据库句柄。
45
+ * 浏览器可用的纯 TS 数据库实现。
56
46
  *
57
- * 与 `@yydb/yydb` 的 {@link Database} 同名——宿主靠 import 来源区分:
47
+ * 与 Node 侧 `@yydb/yydb` 的 {@link Database} 同构:宿主靠 import 来源区分:
58
48
  *
59
49
  * ```ts
60
50
  * import { Database } from '@yydb/yydb'; // Node 原生
61
- * import { Database } from '@yydb/light-db'; // 浏览器 WASM
51
+ * import { Database } from '@yydb/light-db'; // 浏览器纯 TS(本文件)
62
52
  * ```
53
+ *
54
+ * 完全不依赖 WASM;OPFS 持久化、WAL 恢复、检查点、事务都在 TypeScript 内完成。
55
+ *
56
+ * 默认后端是 `OpfsStorageAdapterFactory`;通过 `options.storage` 可以显式指定。
63
57
  */
64
- export declare class Database {
65
- /** 数据库名(OPFS 路径)。 */
58
+ export declare class Database implements LightDatabase {
59
+ /** 数据库名 */
66
60
  readonly name: string;
67
- private readonly session;
61
+ private readonly engine;
62
+ private readonly transaction;
68
63
  private constructor();
69
- /** 初始化 WASM 并打开一个 session(memory 或 OPFS persistent)。 */
70
- static open(name: string, options?: OpenOptions): Promise<Database>;
71
- /** 解析 WASM JSON 结果,失败时转 LightDbError。 */
72
- private parseResult;
73
- /** 读取已持久化的 schema,或 `null`。 */
74
- getSchema(): Promise<SchemaVersion | null>;
75
- /** 声明 schema 文档。 */
76
- ensureSchema(...input: [string] | EmittableItem[]): Promise<void>;
77
- /** 读取键,或 `null`。 */
64
+ /**
65
+ * 打开数据库
66
+ * @param name 数据库名
67
+ * @param options 打开选项
68
+ */
69
+ static open(name: string, options?: LightDatabaseOptions): Promise<Database>;
70
+ /** 读取已持久化的 schema */
71
+ schema(): Promise<SchemaVersion | null>;
72
+ /**
73
+ * 声明 schema 文档
74
+ *
75
+ * 文档是唯一真相:首次写入后,重复调用必须传入完全相同的文档。
76
+ */
77
+ ensureSchema(document: string): Promise<void>;
78
+ /** 读取键 */
78
79
  get(key: string): Promise<Uint8Array | null>;
79
- /** 写入键。 */
80
- put(key: string, value: Uint8Array | string): Promise<void>;
81
- /** 删除键。 */
82
- delete(key: string): Promise<void>;
83
- /** 扫描键值对。 */
84
- scan(options?: ScanOptions): Promise<ScanRow[]>;
85
- /** 原子批量写入/删除。 */
86
- batch(changes: readonly BatchChange[]): Promise<void>;
87
- /** Compare-and-swap。 */
88
- compareExchange(key: string, expected: Uint8Array | string | null, replacement: Uint8Array | string | null): Promise<boolean>;
89
- /** Callback-style 事务:自动 begin/commit,异常自动 rollback。 */
90
- transaction<T>(fn: (tx: TransactionHandle) => Promise<T>): Promise<T>;
91
- /** 执行 VOS read pipeline,返回 typed rows。 */
92
- query<T = Record<string, unknown>>(source: string): Promise<T[]>;
93
- /** 执行 VOS write program。 */
94
- execute(source: string): Promise<void>;
95
- /** 发布新 schema 版本。 */
96
- migrateSchema(documentOrSource: string | EmittableItem, ...rest: (EmittableItem | MigrateOptions)[]): Promise<void>;
97
- /** 执行检查点(折叠 WAL)。 */
98
- checkpoint(): Promise<void>;
99
- /** 关闭 session。 */
80
+ /** 写入键 */
81
+ put(key: string, value: Uint8Array): Promise<void>;
82
+ /** 删除键 */
83
+ delete(key: string): Promise<boolean>;
84
+ /** 开始事务 */
85
+ begin(): Promise<void>;
86
+ /** 提交事务 */
87
+ commit(): Promise<void>;
88
+ /** 回滚事务 */
89
+ rollback(): Promise<void>;
90
+ /** 执行检查点 */
91
+ checkpoint(): Promise<CheckpointResult>;
92
+ /** 统计信息 */
93
+ stats(): StorageEngineStats;
94
+ /** 关闭数据库 */
100
95
  close(): Promise<void>;
96
+ /**
97
+ * 校验用户键
98
+ */
99
+ private assertUserKey;
101
100
  }
102
- /** 打开浏览器数据库的便捷函数(等价于 {@link Database.open})。 */
103
- export declare function openLightDatabase(name: string, options?: OpenOptions): Promise<Database>;
104
101
  //# sourceMappingURL=database.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/api/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,WAAW,EACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAc3D,oBAAoB;AACpB,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,MAAM,C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AAE,oBAAyB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAmB7F,qBAAqB;IACR,MAAM,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAKpD;;;;OAIG;IACU,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB1D,UAAU;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAIzD,UAAU;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,UAAU;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlD,WAAW;IACE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAInC,WAAW;IACE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC,WAAW;IACE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAItC,YAAY;IACC,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAIpD,WAAW;IACJ,KAAK,IAAI,kBAAkB;IAIlC,YAAY;IACC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOnC;;OAEG;IACH,OAAO,CAAC,aAAa;CAWxB"}
@@ -1,228 +1,149 @@
1
- import { initWasm, openPersistentSession, createMemorySession, } from '@yydb/yydb-unknown-wasm32';
2
- import { emitSource } from '@voml/vos';
3
- import { LightDbError } from '../errors/index.js';
4
- /** Transaction-local handle for callback-style transactions. */
5
- export class TransactionHandle {
6
- session;
7
- constructor(session) {
8
- this.session = session;
9
- }
10
- parseResult(raw) {
11
- const parsed = JSON.parse(raw);
12
- if (!parsed.ok) {
13
- const err = LightDbError.fromDiagnosticJson(parsed.error);
14
- throw err ?? new Error(typeof parsed.error === 'string' ? parsed.error : 'wasm error');
15
- }
16
- return parsed;
17
- }
18
- async get(key) {
19
- const raw = JSON.parse(this.session.get(key));
20
- if (!raw.ok)
21
- throw new Error(raw.error);
22
- if (raw.value === null || raw.value === undefined)
23
- return null;
24
- if (Array.isArray(raw.value))
25
- return new Uint8Array(raw.value);
26
- return new Uint8Array(raw.value);
27
- }
28
- async put(key, value) {
29
- const bytes = typeof value === 'string' ? new TextEncoder().encode(value) : value;
30
- this.parseResult(this.session.put(key, bytes));
31
- }
32
- async delete(key) {
33
- this.parseResult(this.session.delete(key));
34
- }
35
- async scan(options = {}) {
36
- const raw = JSON.parse(this.session.scanPrefix(options.prefix ?? '', options.after ?? null, options.limit ?? 1000));
37
- if (!raw.ok)
38
- throw new Error(raw.error);
39
- return (raw.rows ?? []).map((r) => ({
40
- key: r.key,
41
- value: new Uint8Array(r.value),
42
- }));
43
- }
44
- async batch(changes) {
45
- const body = changes.map((c) => ({
46
- key: c.key,
47
- value: c.value === null ? null : typeof c.value === 'string' ? Array.from(new TextEncoder().encode(c.value)) : Array.from(c.value),
48
- }));
49
- this.parseResult(this.session.writeBatch(new TextEncoder().encode(JSON.stringify(body))));
50
- }
51
- async compareExchange(key, expected, replacement) {
52
- const toBytes = (v) => v === null ? null : typeof v === 'string' ? new TextEncoder().encode(v) : v;
53
- const raw = JSON.parse(this.session.compareExchange(key, toBytes(expected), toBytes(replacement)));
54
- if (!raw.ok)
55
- throw new Error(raw.error);
56
- return raw.success ?? false;
57
- }
58
- async query(source) {
59
- const raw = JSON.parse(this.session.queryVos(source));
60
- if (!raw.ok)
61
- throw new Error(raw.error);
62
- return (raw.rows ?? []);
63
- }
64
- async execute(source) {
65
- this.parseResult(this.session.executeVosWrite(source));
66
- }
67
- }
1
+ // ---------------------------------------------------------------------------
2
+ // Pure-TS Database (StorageEngine wrapper — browser-friendly, no WASM)
3
+ // ---------------------------------------------------------------------------
4
+ import { StorageEngine } from '../core/engine.js';
5
+ import { LightDbError, LightDbErrorCodes } from '../errors/index.js';
6
+ import { isOpfsAvailable, OpfsStorageAdapterFactory } from '../storage/opfs/OpfsStorageAdapter.js';
7
+ import { decodeSchema, encodeSchema, parseSchemaDocument, RESERVED_KEY_PREFIX, SCHEMA_KEY } from './schema.js';
8
+ import { Transaction } from './transaction.js';
9
+ /** 数据库名最大长度 */
10
+ const MAX_DATABASE_NAME_LENGTH = 128;
68
11
  /**
69
- * Browser/WASM 侧 YYDB 数据库句柄。
12
+ * 浏览器可用的纯 TS 数据库实现。
70
13
  *
71
- * 与 `@yydb/yydb` 的 {@link Database} 同名——宿主靠 import 来源区分:
14
+ * 与 Node 侧 `@yydb/yydb` 的 {@link Database} 同构:宿主靠 import 来源区分:
72
15
  *
73
16
  * ```ts
74
17
  * import { Database } from '@yydb/yydb'; // Node 原生
75
- * import { Database } from '@yydb/light-db'; // 浏览器 WASM
18
+ * import { Database } from '@yydb/light-db'; // 浏览器纯 TS(本文件)
76
19
  * ```
20
+ *
21
+ * 完全不依赖 WASM;OPFS 持久化、WAL 恢复、检查点、事务都在 TypeScript 内完成。
22
+ *
23
+ * 默认后端是 `OpfsStorageAdapterFactory`;通过 `options.storage` 可以显式指定。
77
24
  */
78
25
  export class Database {
79
- /** 数据库名(OPFS 路径)。 */
26
+ /** 数据库名 */
80
27
  name;
81
- session;
82
- constructor(name, session) {
28
+ engine;
29
+ transaction;
30
+ constructor(name, engine) {
83
31
  this.name = name;
84
- this.session = session;
85
- }
86
- /** 初始化 WASM 并打开一个 session(memory 或 OPFS persistent)。 */
32
+ this.engine = engine;
33
+ this.transaction = new Transaction(engine);
34
+ }
35
+ /**
36
+ * 打开数据库
37
+ * @param name 数据库名
38
+ * @param options 打开选项
39
+ */
87
40
  static async open(name, options = {}) {
88
- if (!name || name.length === 0) {
89
- throw new Error('database name must not be empty');
41
+ if (name.trim().length === 0 || name.length > MAX_DATABASE_NAME_LENGTH) {
42
+ throw new LightDbError(LightDbErrorCodes.unsupported, `database name must be 1-${MAX_DATABASE_NAME_LENGTH} characters`, {
43
+ operation: 'open',
44
+ });
90
45
  }
91
- await initWasm();
92
- const session = options.memory
93
- ? createMemorySession()
94
- : openPersistentSession(name);
95
- return new Database(name, session);
96
- }
97
- /** 解析 WASM JSON 结果,失败时转 LightDbError。 */
98
- parseResult(raw) {
99
- const parsed = JSON.parse(raw);
100
- if (!parsed.ok) {
101
- const err = LightDbError.fromDiagnosticJson(parsed.error);
102
- throw err ?? new Error(typeof parsed.error === 'string' ? parsed.error : 'wasm error');
46
+ const storage = resolveStorageFactory(options);
47
+ const engineOptions = {};
48
+ if (options.pageSize !== undefined)
49
+ engineOptions.pageSize = options.pageSize;
50
+ if (options.walThreshold !== undefined)
51
+ engineOptions.walThreshold = options.walThreshold;
52
+ if (options.autoCheckpoint !== undefined)
53
+ engineOptions.autoCheckpoint = options.autoCheckpoint;
54
+ if (options.lease !== undefined)
55
+ engineOptions.lease = options.lease;
56
+ const engine = await StorageEngine.open(name, storage, engineOptions);
57
+ return new Database(name, engine);
58
+ }
59
+ /** 读取已持久化的 schema */
60
+ async schema() {
61
+ const value = await this.engine.get(SCHEMA_KEY);
62
+ return value ? decodeSchema(value) : null;
63
+ }
64
+ /**
65
+ * 声明 schema 文档
66
+ *
67
+ * 文档是唯一真相:首次写入后,重复调用必须传入完全相同的文档。
68
+ */
69
+ async ensureSchema(document) {
70
+ const version = parseSchemaDocument(document);
71
+ const existing = await this.schema();
72
+ if (existing) {
73
+ if (existing.document !== document) {
74
+ throw new LightDbError(LightDbErrorCodes.schemaConflict, `schema document conflict: stored version ${existing.version}, incoming version ${version}`, { operation: 'ensureSchema' });
75
+ }
76
+ return;
103
77
  }
104
- return parsed;
78
+ await this.engine.put(SCHEMA_KEY, encodeSchema({ version, document }));
79
+ this.engine.notifySchemaChange();
105
80
  }
106
- /** 读取已持久化的 schema,或 `null`。 */
107
- async getSchema() {
108
- const raw = this.parseResult(this.session.getSchema());
109
- if (!raw.schema)
110
- return null;
111
- return raw.schema;
112
- }
113
- /** 声明 schema 文档。 */
114
- async ensureSchema(...input) {
115
- const document = typeof input[0] === 'string' ? input[0] : emitSource(input);
116
- this.parseResult(this.session.ensureSchema(document));
117
- }
118
- /** 读取键,或 `null`。 */
81
+ /** 读取键 */
119
82
  async get(key) {
120
- const raw = JSON.parse(this.session.get(key));
121
- if (!raw.ok)
122
- throw (LightDbError.fromDiagnosticJson(raw.error) ?? new Error(raw.error));
123
- if (raw.value === null || raw.value === undefined)
124
- return null;
125
- if (Array.isArray(raw.value))
126
- return new Uint8Array(raw.value);
127
- return new Uint8Array(raw.value);
128
- }
129
- /** 写入键。 */
83
+ return this.engine.get(this.assertUserKey(key, 'kvGet'));
84
+ }
85
+ /** 写入键 */
130
86
  async put(key, value) {
131
- const bytes = typeof value === 'string' ? new TextEncoder().encode(value) : value;
132
- this.parseResult(this.session.put(key, bytes));
87
+ await this.engine.put(this.assertUserKey(key, 'kvPut'), value);
133
88
  }
134
- /** 删除键。 */
89
+ /** 删除键 */
135
90
  async delete(key) {
136
- this.parseResult(this.session.delete(key));
137
- }
138
- /** 扫描键值对。 */
139
- async scan(options = {}) {
140
- const raw = JSON.parse(this.session.scanPrefix(options.prefix ?? '', options.after ?? null, options.limit ?? 1000));
141
- if (!raw.ok)
142
- throw (LightDbError.fromDiagnosticJson(raw.error) ?? new Error(raw.error));
143
- return (raw.rows ?? []).map((r) => ({
144
- key: r.key,
145
- value: new Uint8Array(r.value),
146
- }));
147
- }
148
- /** 原子批量写入/删除。 */
149
- async batch(changes) {
150
- const body = changes.map((c) => ({
151
- key: c.key,
152
- value: c.value === null ? null : typeof c.value === 'string' ? Array.from(new TextEncoder().encode(c.value)) : Array.from(c.value),
153
- }));
154
- this.parseResult(this.session.writeBatch(new TextEncoder().encode(JSON.stringify(body))));
155
- }
156
- /** Compare-and-swap。 */
157
- async compareExchange(key, expected, replacement) {
158
- const toBytes = (v) => v === null ? null : typeof v === 'string' ? new TextEncoder().encode(v) : v;
159
- const raw = JSON.parse(this.session.compareExchange(key, toBytes(expected), toBytes(replacement)));
160
- if (!raw.ok)
161
- throw (LightDbError.fromDiagnosticJson(raw.error) ?? new Error(raw.error));
162
- return raw.success ?? false;
163
- }
164
- /** Callback-style 事务:自动 begin/commit,异常自动 rollback。 */
165
- async transaction(fn) {
166
- this.parseResult(this.session.begin());
167
- const tx = new TransactionHandle(this.session);
168
- try {
169
- const result = await fn(tx);
170
- this.parseResult(this.session.commit());
171
- return result;
172
- }
173
- catch (err) {
174
- try {
175
- this.session.rollback();
176
- }
177
- catch {
178
- // don't mask original
179
- }
180
- throw err;
181
- }
91
+ return this.engine.delete(this.assertUserKey(key, 'kvDelete'));
182
92
  }
183
- /** 执行 VOS read pipeline,返回 typed rows。 */
184
- async query(source) {
185
- const raw = JSON.parse(this.session.queryVos(source));
186
- if (!raw.ok)
187
- throw (LightDbError.fromDiagnosticJson(raw.error) ?? new Error(raw.error));
188
- return (raw.rows ?? []);
189
- }
190
- /** 执行 VOS write program。 */
191
- async execute(source) {
192
- this.parseResult(this.session.executeVosWrite(source));
193
- }
194
- /** 发布新 schema 版本。 */
195
- async migrateSchema(documentOrSource, ...rest) {
196
- let document;
197
- let options = {};
198
- const all = [documentOrSource, ...rest];
199
- const last = all[all.length - 1];
200
- if (last && typeof last === 'object' &&
201
- !('table' in last) &&
202
- !('class' in last) &&
203
- ('renames' in last || Object.keys(last).length === 0)) {
204
- options = all.pop() ?? {};
205
- }
206
- if (typeof all[0] === 'string') {
207
- document = all[0];
208
- }
209
- else {
210
- document = emitSource(all);
211
- }
212
- const renamesJson = options.renames?.length ? JSON.stringify(options.renames) : null;
213
- this.parseResult(this.session.migrateSchema(document, renamesJson));
93
+ /** 开始事务 */
94
+ async begin() {
95
+ await this.transaction.begin();
96
+ }
97
+ /** 提交事务 */
98
+ async commit() {
99
+ await this.transaction.commit();
100
+ }
101
+ /** 回滚事务 */
102
+ async rollback() {
103
+ await this.transaction.rollback();
214
104
  }
215
- /** 执行检查点(折叠 WAL)。 */
105
+ /** 执行检查点 */
216
106
  async checkpoint() {
217
- this.parseResult(this.session.checkpoint());
107
+ return this.engine.checkpoint();
218
108
  }
219
- /** 关闭 session。 */
109
+ /** 统计信息 */
110
+ stats() {
111
+ return this.engine.getStats();
112
+ }
113
+ /** 关闭数据库 */
220
114
  async close() {
221
- this.session.close();
115
+ if (this.transaction.isActive) {
116
+ await this.transaction.rollback();
117
+ }
118
+ await this.engine.close();
119
+ }
120
+ /**
121
+ * 校验用户键
122
+ */
123
+ assertUserKey(key, operation) {
124
+ if (key.length === 0) {
125
+ throw new LightDbError(LightDbErrorCodes.unsupported, 'key must not be empty', { operation });
126
+ }
127
+ if (key.startsWith(RESERVED_KEY_PREFIX)) {
128
+ throw new LightDbError(LightDbErrorCodes.unsupported, `key prefix "${RESERVED_KEY_PREFIX}" is reserved for the database`, {
129
+ operation,
130
+ });
131
+ }
132
+ return key;
222
133
  }
223
134
  }
224
- /** 打开浏览器数据库的便捷函数(等价于 {@link Database.open})。 */
225
- export async function openLightDatabase(name, options = {}) {
226
- return Database.open(name, options);
135
+ /**
136
+ * 解析存储后端
137
+ */
138
+ function resolveStorageFactory(options) {
139
+ if (options.storage) {
140
+ return options.storage;
141
+ }
142
+ if (!isOpfsAvailable()) {
143
+ throw new LightDbError(LightDbErrorCodes.unsupported, 'OPFS is unavailable, pass an explicit storage adapter', {
144
+ operation: 'open',
145
+ });
146
+ }
147
+ return new OpfsStorageAdapterFactory();
227
148
  }
228
149
  //# sourceMappingURL=database.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/api/database.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,qBAAqB,EACrB,mBAAmB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAsB,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAoDlD,gEAAgE;AAChE,MAAM,OAAO,iBAAiB;IACG;IAA7B,YAA6B,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAE7C,WAAW,CA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M,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;IAED,YAAY;IACL,KAAK,CAAC,KAAK;QACd,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;QACtC,CAAC;QACD,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,GAAW,EAAE,SAAiB;QAChD,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,YAAY,CAAC,iBAAiB,CAAC,WAAW,EAAE,uBAAuB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QAClG,CAAC;QACD,IAAI,GAAG,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,YAAY,CAAC,iBAAiB,CAAC,WAAW,EAAE,eAAe,mBAAmB,gCAAgC,EAAE;gBACtH,SAAS;aACZ,CAAC,CAAC;QACP,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AAED;;GAEG;AACH,SAAS,qBAAqB,CAAC,OAA6B;IACxD,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC,OAAO,CAAC;IAC3B,CAAC;IAED,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,YAAY,CAAC,iBAAiB,CAAC,WAAW,EAAE,uDAAuD,EAAE;YAC3G,SAAS,EAAE,MAAM;SACpB,CAAC,CAAC;IACP,CAAC;IAED,OAAO,IAAI,yBAAyB,EAAE,CAAC;AAC3C,CAAC"}
@@ -1,10 +1,14 @@
1
1
  /**
2
2
  * api 层导出
3
+ *
4
+ * 主线是 {@link Database}(纯 TS,无 WASM 依赖,与 Node 侧 `@yydb/yydb` 同构)。
5
+ * 需要 WASM 可选后端的宿主显式从 `./wasm-database` 引入 {@link WasmDatabase}。
3
6
  */
4
- export { Database, openLightDatabase } from './database';
5
- export type { OpenOptions, ScanRow, ScanOptions, BatchChange, MigrateOptions } from './database';
7
+ export { Database } from './database';
8
+ export type { OpenOptions, ScanRow, ScanOptions, BatchChange, MigrateOptions, SchemaVersion } from './database';
9
+ export { WasmDatabase, TransactionHandle, openLightDatabase } from './wasm-database';
6
10
  export { Transaction } from './transaction';
7
11
  export type { TransactionState } from './transaction';
8
12
  export { SCHEMA_KEY, RESERVED_KEY_PREFIX, documentVersion, parseSchemaDocument, encodeSchema, decodeSchema } from './schema';
9
- export type { LightDatabase, LightDatabaseOptions, SchemaVersion } from './types';
13
+ export type { LightDatabase, LightDatabaseOptions } from './types';
10
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7H,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAErF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7H,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC"}
package/dist/api/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  /**
2
2
  * api 层导出
3
+ *
4
+ * 主线是 {@link Database}(纯 TS,无 WASM 依赖,与 Node 侧 `@yydb/yydb` 同构)。
5
+ * 需要 WASM 可选后端的宿主显式从 `./wasm-database` 引入 {@link WasmDatabase}。
3
6
  */
4
- export { Database, openLightDatabase } from './database';
7
+ export { Database } from './database';
8
+ export { WasmDatabase, TransactionHandle, openLightDatabase } from './wasm-database';
5
9
  export { Transaction } from './transaction';
6
10
  export { SCHEMA_KEY, RESERVED_KEY_PREFIX, documentVersion, parseSchemaDocument, encodeSchema, decodeSchema } from './schema';
7
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAErF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { type WasmSession } from '@yydb/yydb-unknown-wasm32';
2
+ import { type EmittableItem } from '@voml/vos';
3
+ import type { BatchChange, MigrateOptions, OpenOptions, ScanOptions, ScanRow, SchemaVersion } from './database.js';
4
+ /** Transaction-local handle for callback-style transactions. */
5
+ export declare class TransactionHandle {
6
+ private readonly session;
7
+ constructor(session: WasmSession);
8
+ private parseResult;
9
+ get(key: string): Promise<Uint8Array | null>;
10
+ put(key: string, value: Uint8Array | string): Promise<void>;
11
+ delete(key: string): Promise<void>;
12
+ scan(options?: ScanOptions): Promise<ScanRow[]>;
13
+ batch(changes: readonly BatchChange[]): Promise<void>;
14
+ compareExchange(key: string, expected: Uint8Array | string | null, replacement: Uint8Array | string | null): Promise<boolean>;
15
+ query<T = Record<string, unknown>>(source: string): Promise<T[]>;
16
+ execute(source: string): Promise<void>;
17
+ }
18
+ /**
19
+ * Browser/WASM 侧 YYDB 数据库句柄(可选后端)。
20
+ *
21
+ * 这是 `@yydb/light-db` 的 WASM 路径。默认可选——包主线是 {@link Database}
22
+ * (`api/database.ts`,纯 TS,无 WASM 依赖),宿主按需显式 import 本文件以引入 WASM。
23
+ */
24
+ export declare class WasmDatabase {
25
+ /** 数据库名(OPFS 路径)。 */
26
+ readonly name: string;
27
+ private readonly session;
28
+ private constructor();
29
+ /** 初始化 WASM 并打开一个 session(memory 或 OPFS persistent)。 */
30
+ static open(name: string, options?: OpenOptions): Promise<WasmDatabase>;
31
+ /** 解析 WASM JSON 结果,失败时转 LightDbError。 */
32
+ private parseResult;
33
+ /** 读取已持久化的 schema,或 `null`。 */
34
+ getSchema(): Promise<SchemaVersion | null>;
35
+ /** 声明 schema 文档。 */
36
+ ensureSchema(...input: [string] | EmittableItem[]): Promise<void>;
37
+ /** 读取键,或 `null`。 */
38
+ get(key: string): Promise<Uint8Array | null>;
39
+ /** 写入键。 */
40
+ put(key: string, value: Uint8Array | string): Promise<void>;
41
+ /** 删除键。 */
42
+ delete(key: string): Promise<void>;
43
+ /** 扫描键值对。 */
44
+ scan(options?: ScanOptions): Promise<ScanRow[]>;
45
+ /** 原子批量写入/删除。 */
46
+ batch(changes: readonly BatchChange[]): Promise<void>;
47
+ /** Compare-and-swap。 */
48
+ compareExchange(key: string, expected: Uint8Array | string | null, replacement: Uint8Array | string | null): Promise<boolean>;
49
+ /** Callback-style 事务:自动 begin/commit,异常自动 rollback。 */
50
+ transaction<T>(fn: (tx: TransactionHandle) => Promise<T>): Promise<T>;
51
+ /** 执行 VOS read pipeline,返回 typed rows。 */
52
+ query<T = Record<string, unknown>>(source: string): Promise<T[]>;
53
+ /** 执行 VOS write program。 */
54
+ execute(source: string): Promise<void>;
55
+ /** 发布新 schema 版本。 */
56
+ migrateSchema(documentOrSource: string | EmittableItem, ...rest: (EmittableItem | MigrateOptions)[]): Promise<void>;
57
+ /** 执行检查点(折叠 WAL)。 */
58
+ checkpoint(): Promise<void>;
59
+ /** 关闭 session。 */
60
+ close(): Promise<void>;
61
+ }
62
+ /** 打开浏览器 WASM 数据库的便捷函数(等价于 {@link WasmDatabase.open})。 */
63
+ export declare function openLightDatabase(name: string, options?: OpenOptions): Promise<WasmDatabase>;
64
+ //# sourceMappingURL=wasm-database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-database.d.ts","sourceRoot":"","sources":["../../src/api/wasm-database.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,WAAW,EACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAc,KAAK,aAAa,EAAE,M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AAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD,qBAAqB;IACR,aAAa,CACtB,gBAAgB,EAAE,MAAM,GAAG,aAAa,EACxC,GAAG,IAAI,EAAE,CAAC,aAAa,GAAG,cAAc,CAAC,EAAE,GAC5C,OAAO,CAAC,IAAI,CAAC;IAsBhB,qBAAqB;IACR,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC,kBAAkB;IACL,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGtC;AAED,0DAA0D;AAC1D,wBAAsB,iBAAiB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAgB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAEvB"}
@@ -0,0 +1,224 @@
1
+ import { initWasm, openPersistentSession, createMemorySession, } from '@yydb/yydb-unknown-wasm32';
2
+ import { emitSource } from '@voml/vos';
3
+ import { LightDbError } from '../errors/index.js';
4
+ /** Transaction-local handle for callback-style transactions. */
5
+ export class TransactionHandle {
6
+ session;
7
+ constructor(session) {
8
+ this.session = session;
9
+ }
10
+ parseResult(raw) {
11
+ const parsed = JSON.parse(raw);
12
+ if (!parsed.ok) {
13
+ const err = LightDbError.fromDiagnosticJson(parsed.error);
14
+ throw err ?? new Error(typeof parsed.error === 'string' ? parsed.error : 'wasm error');
15
+ }
16
+ return parsed;
17
+ }
18
+ async get(key) {
19
+ const raw = JSON.parse(this.session.get(key));
20
+ if (!raw.ok)
21
+ throw new Error(raw.error);
22
+ if (raw.value === null || raw.value === undefined)
23
+ return null;
24
+ if (Array.isArray(raw.value))
25
+ return new Uint8Array(raw.value);
26
+ return new Uint8Array(raw.value);
27
+ }
28
+ async put(key, value) {
29
+ const bytes = typeof value === 'string' ? new TextEncoder().encode(value) : value;
30
+ this.parseResult(this.session.put(key, bytes));
31
+ }
32
+ async delete(key) {
33
+ this.parseResult(this.session.delete(key));
34
+ }
35
+ async scan(options = {}) {
36
+ const raw = JSON.parse(this.session.scanPrefix(options.prefix ?? '', options.after ?? null, options.limit ?? 1000));
37
+ if (!raw.ok)
38
+ throw new Error(raw.error);
39
+ return (raw.rows ?? []).map((r) => ({
40
+ key: r.key,
41
+ value: new Uint8Array(r.value),
42
+ }));
43
+ }
44
+ async batch(changes) {
45
+ const body = changes.map((c) => ({
46
+ key: c.key,
47
+ value: c.value === null ? null : typeof c.value === 'string' ? Array.from(new TextEncoder().encode(c.value)) : Array.from(c.value),
48
+ }));
49
+ this.parseResult(this.session.writeBatch(new TextEncoder().encode(JSON.stringify(body))));
50
+ }
51
+ async compareExchange(key, expected, replacement) {
52
+ const toBytes = (v) => v === null ? null : typeof v === 'string' ? new TextEncoder().encode(v) : v;
53
+ const raw = JSON.parse(this.session.compareExchange(key, toBytes(expected), toBytes(replacement)));
54
+ if (!raw.ok)
55
+ throw new Error(raw.error);
56
+ return raw.success ?? false;
57
+ }
58
+ async query(source) {
59
+ const raw = JSON.parse(this.session.queryVos(source));
60
+ if (!raw.ok)
61
+ throw new Error(raw.error);
62
+ return (raw.rows ?? []);
63
+ }
64
+ async execute(source) {
65
+ this.parseResult(this.session.executeVosWrite(source));
66
+ }
67
+ }
68
+ /**
69
+ * Browser/WASM 侧 YYDB 数据库句柄(可选后端)。
70
+ *
71
+ * 这是 `@yydb/light-db` 的 WASM 路径。默认可选——包主线是 {@link Database}
72
+ * (`api/database.ts`,纯 TS,无 WASM 依赖),宿主按需显式 import 本文件以引入 WASM。
73
+ */
74
+ export class WasmDatabase {
75
+ /** 数据库名(OPFS 路径)。 */
76
+ name;
77
+ session;
78
+ constructor(name, session) {
79
+ this.name = name;
80
+ this.session = session;
81
+ }
82
+ /** 初始化 WASM 并打开一个 session(memory 或 OPFS persistent)。 */
83
+ static async open(name, options = {}) {
84
+ if (!name || name.length === 0) {
85
+ throw new Error('database name must not be empty');
86
+ }
87
+ await initWasm();
88
+ const session = options.memory
89
+ ? createMemorySession()
90
+ : openPersistentSession(name);
91
+ return new WasmDatabase(name, session);
92
+ }
93
+ /** 解析 WASM JSON 结果,失败时转 LightDbError。 */
94
+ parseResult(raw) {
95
+ const parsed = JSON.parse(raw);
96
+ if (!parsed.ok) {
97
+ const err = LightDbError.fromDiagnosticJson(parsed.error);
98
+ throw err ?? new Error(typeof parsed.error === 'string' ? parsed.error : 'wasm error');
99
+ }
100
+ return parsed;
101
+ }
102
+ /** 读取已持久化的 schema,或 `null`。 */
103
+ async getSchema() {
104
+ const raw = this.parseResult(this.session.getSchema());
105
+ if (!raw.schema)
106
+ return null;
107
+ return raw.schema;
108
+ }
109
+ /** 声明 schema 文档。 */
110
+ async ensureSchema(...input) {
111
+ const document = typeof input[0] === 'string' ? input[0] : emitSource(input);
112
+ this.parseResult(this.session.ensureSchema(document));
113
+ }
114
+ /** 读取键,或 `null`。 */
115
+ async get(key) {
116
+ const raw = JSON.parse(this.session.get(key));
117
+ if (!raw.ok)
118
+ throw (LightDbError.fromDiagnosticJson(raw.error) ?? new Error(raw.error));
119
+ if (raw.value === null || raw.value === undefined)
120
+ return null;
121
+ if (Array.isArray(raw.value))
122
+ return new Uint8Array(raw.value);
123
+ return new Uint8Array(raw.value);
124
+ }
125
+ /** 写入键。 */
126
+ async put(key, value) {
127
+ const bytes = typeof value === 'string' ? new TextEncoder().encode(value) : value;
128
+ this.parseResult(this.session.put(key, bytes));
129
+ }
130
+ /** 删除键。 */
131
+ async delete(key) {
132
+ this.parseResult(this.session.delete(key));
133
+ }
134
+ /** 扫描键值对。 */
135
+ async scan(options = {}) {
136
+ const raw = JSON.parse(this.session.scanPrefix(options.prefix ?? '', options.after ?? null, options.limit ?? 1000));
137
+ if (!raw.ok)
138
+ throw (LightDbError.fromDiagnosticJson(raw.error) ?? new Error(raw.error));
139
+ return (raw.rows ?? []).map((r) => ({
140
+ key: r.key,
141
+ value: new Uint8Array(r.value),
142
+ }));
143
+ }
144
+ /** 原子批量写入/删除。 */
145
+ async batch(changes) {
146
+ const body = changes.map((c) => ({
147
+ key: c.key,
148
+ value: c.value === null ? null : typeof c.value === 'string' ? Array.from(new TextEncoder().encode(c.value)) : Array.from(c.value),
149
+ }));
150
+ this.parseResult(this.session.writeBatch(new TextEncoder().encode(JSON.stringify(body))));
151
+ }
152
+ /** Compare-and-swap。 */
153
+ async compareExchange(key, expected, replacement) {
154
+ const toBytes = (v) => v === null ? null : typeof v === 'string' ? new TextEncoder().encode(v) : v;
155
+ const raw = JSON.parse(this.session.compareExchange(key, toBytes(expected), toBytes(replacement)));
156
+ if (!raw.ok)
157
+ throw (LightDbError.fromDiagnosticJson(raw.error) ?? new Error(raw.error));
158
+ return raw.success ?? false;
159
+ }
160
+ /** Callback-style 事务:自动 begin/commit,异常自动 rollback。 */
161
+ async transaction(fn) {
162
+ this.parseResult(this.session.begin());
163
+ const tx = new TransactionHandle(this.session);
164
+ try {
165
+ const result = await fn(tx);
166
+ this.parseResult(this.session.commit());
167
+ return result;
168
+ }
169
+ catch (err) {
170
+ try {
171
+ this.session.rollback();
172
+ }
173
+ catch {
174
+ // don't mask original
175
+ }
176
+ throw err;
177
+ }
178
+ }
179
+ /** 执行 VOS read pipeline,返回 typed rows。 */
180
+ async query(source) {
181
+ const raw = JSON.parse(this.session.queryVos(source));
182
+ if (!raw.ok)
183
+ throw (LightDbError.fromDiagnosticJson(raw.error) ?? new Error(raw.error));
184
+ return (raw.rows ?? []);
185
+ }
186
+ /** 执行 VOS write program。 */
187
+ async execute(source) {
188
+ this.parseResult(this.session.executeVosWrite(source));
189
+ }
190
+ /** 发布新 schema 版本。 */
191
+ async migrateSchema(documentOrSource, ...rest) {
192
+ let document;
193
+ let options = {};
194
+ const all = [documentOrSource, ...rest];
195
+ const last = all[all.length - 1];
196
+ if (last && typeof last === 'object' &&
197
+ !('table' in last) &&
198
+ !('class' in last) &&
199
+ ('renames' in last || Object.keys(last).length === 0)) {
200
+ options = all.pop() ?? {};
201
+ }
202
+ if (typeof all[0] === 'string') {
203
+ document = all[0];
204
+ }
205
+ else {
206
+ document = emitSource(all);
207
+ }
208
+ const renamesJson = options.renames?.length ? JSON.stringify(options.renames) : null;
209
+ this.parseResult(this.session.migrateSchema(document, renamesJson));
210
+ }
211
+ /** 执行检查点(折叠 WAL)。 */
212
+ async checkpoint() {
213
+ this.parseResult(this.session.checkpoint());
214
+ }
215
+ /** 关闭 session。 */
216
+ async close() {
217
+ this.session.close();
218
+ }
219
+ }
220
+ /** 打开浏览器 WASM 数据库的便捷函数(等价于 {@link WasmDatabase.open})。 */
221
+ export async function openLightDatabase(name, options = {}) {
222
+ return WasmDatabase.open(name, options);
223
+ }
224
+ //# sourceMappingURL=wasm-database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-database.js","sourceRoot":"","sources":["../../src/api/wasm-database.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,qBAAqB,EACrB,mBAAmB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAsB,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAclD,gEAAgE;AAChE,MAAM,OAAO,iBAAiB;IACG;IAA7B,YAA6B,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAE7C,WAAW,CAAI,GAAW;QAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAe,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,YAAY,CAAC,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1D,MAAM,GAAG,IAAI,IAAI,KAAK,CAAC,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAC3F,CAAC;QACD,OAAO,MAAW,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACjB,MAAM,GAAG,GAAG,IAA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C,KAAK,QAAQ,EAAE,CAAC;YAC7B,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAW,CAAC;QAChC,CAAC;aAAM,CAAC;YACJ,QAAQ,GAAG,UAAU,CAAC,GAAsB,CAAC,CAAC;QAClD,CAAC;QACD,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,qBAAqB;IACd,KAAK,CAAC,UAAU;QACnB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,kBAAkB;IACX,KAAK,CAAC,KAAK;QACd,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACJ;AAED,0DAA0D;AAC1D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACnC,IAAY,EACZ,UAAuB,EAAE;IAEzB,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -14,6 +14,6 @@ export { STORAGE_FILES, MemoryStorageAdapter, MemoryStorageBackend, OpfsStorageA
14
14
  export type { StorageAdapter, StorageAdapterFactory, StorageAdapterKind, StorageFile, StorageHandle, StorageOpenMode } from './storage';
15
15
  export { StorageEngine, DEFAULT_WAL_THRESHOLD, acquireWriterLease, listenDatabaseEvents } from './core';
16
16
  export type { CheckpointResult, LeaseMode, RecoveryOutcome, StorageEngineOptions, StorageEngineStats, TransactionState, DatabaseEvent, DatabaseEventType, WriterLease, } from './core';
17
- export { Database, openLightDatabase, Transaction, SCHEMA_KEY, RESERVED_KEY_PREFIX, documentVersion, parseSchemaDocument, encodeSchema, decodeSchema, } from './api';
17
+ export { Database, WasmDatabase, openLightDatabase, Transaction, SCHEMA_KEY, RESERVED_KEY_PREFIX, documentVersion, parseSchemaDocument, encodeSchema, decodeSchema, } from './api';
18
18
  export type { OpenOptions, ScanRow, ScanOptions, BatchChange, MigrateOptions, LightDatabase, LightDatabaseOptions, SchemaVersion } from './api';
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC3D,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGpD,OAAO,EACH,WAAW,EACX,UAAU,EACV,UAAU,EACV,qBAAqB,EACrB,KAAK,EACL,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,eAAe,EACf,eAAe,GAClB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG9F,OAAO,EACH,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,oBAAoB,GACvB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAGxI,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AACxG,YAAY,EACR,gBAAgB,EACh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AAGxI,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AACxG,YAAY,EACR,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,WAAW,GACd,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACH,QAAQ,EACR,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,YAAY,GACf,MAAM,OAAO,CAAC;AACf,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC"}
package/dist/index.js CHANGED
@@ -15,5 +15,5 @@ export { STORAGE_FILES, MemoryStorageAdapter, MemoryStorageBackend, OpfsStorageA
15
15
  // 数据库语义
16
16
  export { StorageEngine, DEFAULT_WAL_THRESHOLD, acquireWriterLease, listenDatabaseEvents } from './core';
17
17
  // 作者面
18
- export { Database, openLightDatabase, Transaction, SCHEMA_KEY, RESERVED_KEY_PREFIX, documentVersion, parseSchemaDocument, encodeSchema, decodeSchema, } from './api';
18
+ export { Database, WasmDatabase, openLightDatabase, Transaction, SCHEMA_KEY, RESERVED_KEY_PREFIX, documentVersion, parseSchemaDocument, encodeSchema, decodeSchema, } from './api';
19
19
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO;AACP,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG3D,MAAM;AACN,OAAO,EACH,WAAW,EACX,UAAU,EACV,UAAU,EACV,qBAAqB,EACrB,KAAK,EACL,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,eAAe,EACf,eAAe,GAClB,MAAM,SAAS,CAAC;AAGjB,SAAS;AACT,OAAO,EACH,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,oBAAoB,GACvB,MAAM,WAAW,CAAC;AAGnB,QAAQ;AACR,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAaxG,MAAM;AACN,OAAO,EACH,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,YAAY,GACf,MAAM,OAAO,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO;AACP,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG3D,MAAM;AACN,OAAO,EACH,WAAW,EACX,UAAU,EACV,UAAU,EACV,qBAAqB,EACrB,KAAK,EACL,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,eAAe,EACf,eAAe,GAClB,MAAM,SAAS,CAAC;AAGjB,SAAS;AACT,OAAO,EACH,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,oBAAoB,GACvB,MAAM,WAAW,CAAC;AAGnB,QAAQ;AACR,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAaxG,MAAM;AACN,OAAO,EACH,QAAQ,EACR,YAAY,EACZ,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,YAAY,GACf,MAAM,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,23 +1,18 @@
1
1
  {
2
- "author": "YYDB Contributors",
3
- "bugs": {
4
- "url": "https://github.com/yy-database/yydb.rs/issues"
5
- },
6
- "dependencies": {
7
- "@voml/vos": "^0.0.1",
8
- "@yydb/yydb-unknown-wasm32": "0.0.15"
9
- },
2
+ "name": "@yydb/light-db",
3
+ "version": "0.0.17",
10
4
  "description": "Light DB — browser-native YYDB database written in pure TypeScript",
11
- "devDependencies": {
12
- "@types/node": "^20.19.43",
13
- "playwright-core": "^1.64.1",
14
- "tsx": "^4.23.15",
15
- "typescript": "^5.3.0"
16
- },
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
17
7
  "files": [
18
8
  "dist"
19
9
  ],
20
- "homepage": "https://github.com/yy-database/yydb.rs/tree/dev/projects/packages/light-db#readme",
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "typecheck": "tsc --noEmit",
13
+ "test": "tsx tests/index.ts",
14
+ "test:browser": "tsx tests/browser/run.ts"
15
+ },
21
16
  "keywords": [
22
17
  "yydb",
23
18
  "light-db",
@@ -28,22 +23,27 @@
28
23
  "typescript"
29
24
  ],
30
25
  "license": "MPL-2.0",
31
- "main": "dist/index.js",
32
- "name": "@yydb/light-db",
33
- "publishConfig": {
34
- "access": "public"
35
- },
26
+ "author": "YYDB Contributors",
36
27
  "repository": {
37
- "directory": "projects/packages/light-db",
38
28
  "type": "git",
39
- "url": "git+https://github.com/yy-database/yydb.rs.git"
29
+ "url": "git+https://github.com/yy-database/yydb.git",
30
+ "directory": "projects/packages/light-db"
40
31
  },
41
- "scripts": {
42
- "build": "tsc",
43
- "test": "tsx tests/index.ts",
44
- "test:browser": "tsx tests/browser/run.ts",
45
- "typecheck": "tsc --noEmit"
32
+ "homepage": "https://github.com/yy-database/yydb/tree/dev/projects/packages/light-db#readme",
33
+ "bugs": {
34
+ "url": "https://github.com/yy-database/yydb/issues"
46
35
  },
47
- "types": "dist/index.d.ts",
48
- "version": "0.0.15"
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^20.19.43",
41
+ "playwright-core": "^1.64.1",
42
+ "tsx": "^4.23.15",
43
+ "typescript": "^5.3.0"
44
+ },
45
+ "dependencies": {
46
+ "@voml/vos": "^0.0.1",
47
+ "@yydb/yydb-unknown-wasm32": "0.0.17"
48
+ }
49
49
  }
package/readme.md CHANGED
@@ -1,110 +1,110 @@
1
- # `@yydb/light-db`
2
-
3
- **Light DB** is the browser edition of YYDB: a database written in pure TypeScript that stores `.yydb`-style
4
- snapshots, WAL records and checkpoints in browser storage. It has no Node built-ins, no N-API bindings and no WASM in
5
- its runtime path.
6
-
7
- ## Product relationship
8
-
9
- | Package | Role |
10
- |---------|------|
11
- | `@yydb/yydb` | Node product: native Rust engine, N-API, local `.yydb` / `.yydx` files and CLI |
12
- | `@yydb/light-db` | Browser product: pure TypeScript, OPFS / IndexedDB storage, Web APIs, same author surface |
13
- | `@yydb/yydb-client` | Remote wire client for a running `yydb serve` |
14
-
15
- ## Status
16
-
17
- Light DB is a migration of the original `LightDB.ts` engine, rebuilt around a browser-native architecture. The package
18
- ships as a pre-1.0 release of the browser product, so the author surface may still change between patch releases.
19
-
20
- Current coverage:
21
-
22
- - `pnpm test` runs the Node-side runner over codec, adapter and database logic (29 cases).
23
- - `pnpm test:browser` runs the conformance suite in an installed Chrome (16 cases): OPFS persistence across reopen, WAL
24
- recovery, checkpoint truncation, corruption detection, single-writer exclusion, transaction rollback and commit,
25
- schema and close notifications, and two-tab lease and broadcast behaviour.
26
-
27
- ## Usage
28
-
29
- ```ts
30
- import { LightDbError, openLightDatabase } from '@yydb/light-db';
31
-
32
- const db = await openLightDatabase('app');
33
-
34
- await db.ensureSchema('// @yydb-schema-version: 1\nkv users');
35
- await db.put('user:1', new TextEncoder().encode('Ada'));
36
-
37
- const value = await db.get('user:1');
38
- await db.checkpoint();
39
- await db.close();
40
- ```
41
-
42
- Public data types are browser-native: keys and values use `Uint8Array`, databases are addressed by name rather than by
43
- file path, and every lifecycle call is asynchronous.
44
-
45
- ## Author surface
46
-
47
- ```ts
48
- const db: LightDatabase = await openLightDatabase('app', options);
49
-
50
- await db.schema();
51
- await db.ensureSchema(document);
52
- await db.get(key);
53
- await db.put(key, value);
54
- await db.delete(key);
55
- await db.begin();
56
- await db.commit();
57
- await db.rollback();
58
- await db.checkpoint();
59
- db.stats();
60
- await db.close();
61
- ```
62
-
63
- `schema()` returns the persisted schema version and document. The document is the single source of truth: a second
64
- `ensureSchema` call must pass the identical document, otherwise it fails with `yydb.schema.conflict`. Keys starting with
65
- `__yydb__/` are reserved for the database.
66
-
67
- ## Storage backends
68
-
69
- | Adapter | Use |
70
- |---------|-----|
71
- | `OpfsStorageAdapterFactory` | Default. Origin Private File System, positional reads and writes, atomic snapshot publication |
72
- | `IndexedDbStorageAdapterFactory` | Compatibility backend for hosts without OPFS |
73
- | `MemoryStorageBackend` | Tests and throwaway sessions |
74
-
75
- `StorageAdapter` is the only platform boundary. Transactions, recovery and checkpoint semantics live in `core`, so
76
- backends implement files, not database behaviour.
77
-
78
- ## Concurrency
79
-
80
- A writer holds a session-scoped `Web Locks` lease. A second tab that opens the same database fails with
81
- `yydb.lease.unavailable` and `retryable: true` instead of silently writing alongside the first one. When a lock manager
82
- is missing the call fails the same way; it never degrades to multiple writers.
83
-
84
- `BroadcastChannel` carries `commit`, `schema` and `close` events so other same-origin contexts can discard stale views
85
- and retry after the lease is released. `listenDatabaseEvents(name, handler)` subscribes without opening the database.
86
-
87
- ## Layout
88
-
89
- | Path | Role |
90
- |------|------|
91
- | `src/api/` | Public database, transaction, schema and shared types |
92
- | `src/core/` | Records, WAL, checkpoint, recovery, writer lease and broadcast |
93
- | `src/storage/` | `StorageAdapter` plus OPFS, IndexedDB and memory backends |
94
- | `src/codec/` | Page, snapshot and WAL record encoding over `Uint8Array` |
95
- | `src/errors/` | Stable `yydb.*` error codes |
96
-
97
- ## Errors
98
-
99
- | Code | Meaning |
100
- |------|---------|
101
- | `yydb.io` | Storage operation failed |
102
- | `yydb.corrupt` | Persisted bytes failed validation |
103
- | `yydb.schema.conflict` | Schema document differs from the stored one |
104
- | `yydb.schema.invalid` | Schema document is not usable |
105
- | `yydb.unsupported` | Host or operation is not supported |
106
- | `yydb.session.closed` | Database or handle is closed |
107
- | `yydb.lease.unavailable` | Writer lease is held elsewhere or Web Locks is missing (retryable) |
108
- | `yydb.quota.exceeded` | Browser storage quota is exhausted |
109
-
110
- [YYDB overview](https://github.com/yy-database/yydb.rs)
1
+ # `@yydb/light-db`
2
+
3
+ **Light DB** is the browser edition of YYDB: a database written in pure TypeScript that stores `.yydb`-style
4
+ snapshots, WAL records and checkpoints in browser storage. It has no Node built-ins, no N-API bindings and no WASM in
5
+ its runtime path.
6
+
7
+ ## Product relationship
8
+
9
+ | Package | Role |
10
+ |---------|------|
11
+ | `@yydb/yydb` | Node product: native Rust engine, N-API, local `.yydb` / `.yydx` files and CLI |
12
+ | `@yydb/light-db` | Browser product: pure TypeScript, OPFS / IndexedDB storage, Web APIs, same author surface |
13
+ | `@yydb/yydb-client` | Remote wire client for a running `yydb serve` |
14
+
15
+ ## Status
16
+
17
+ Light DB is a migration of the original `LightDB.ts` engine, rebuilt around a browser-native architecture. The package
18
+ ships as a pre-1.0 release of the browser product, so the author surface may still change between patch releases.
19
+
20
+ Current coverage:
21
+
22
+ - `pnpm test` runs the Node-side runner over codec, adapter and database logic (29 cases).
23
+ - `pnpm test:browser` runs the conformance suite in an installed Chrome (16 cases): OPFS persistence across reopen, WAL
24
+ recovery, checkpoint truncation, corruption detection, single-writer exclusion, transaction rollback and commit,
25
+ schema and close notifications, and two-tab lease and broadcast behaviour.
26
+
27
+ ## Usage
28
+
29
+ ```ts
30
+ import { LightDbError, openLightDatabase } from '@yydb/light-db';
31
+
32
+ const db = await openLightDatabase('app');
33
+
34
+ await db.ensureSchema('// @yydb-schema-version: 1\nkv users');
35
+ await db.put('user:1', new TextEncoder().encode('Ada'));
36
+
37
+ const value = await db.get('user:1');
38
+ await db.checkpoint();
39
+ await db.close();
40
+ ```
41
+
42
+ Public data types are browser-native: keys and values use `Uint8Array`, databases are addressed by name rather than by
43
+ file path, and every lifecycle call is asynchronous.
44
+
45
+ ## Author surface
46
+
47
+ ```ts
48
+ const db: LightDatabase = await openLightDatabase('app', options);
49
+
50
+ await db.schema();
51
+ await db.ensureSchema(document);
52
+ await db.get(key);
53
+ await db.put(key, value);
54
+ await db.delete(key);
55
+ await db.begin();
56
+ await db.commit();
57
+ await db.rollback();
58
+ await db.checkpoint();
59
+ db.stats();
60
+ await db.close();
61
+ ```
62
+
63
+ `schema()` returns the persisted schema version and document. The document is the single source of truth: a second
64
+ `ensureSchema` call must pass the identical document, otherwise it fails with `yydb.schema.conflict`. Keys starting with
65
+ `__yydb__/` are reserved for the database.
66
+
67
+ ## Storage backends
68
+
69
+ | Adapter | Use |
70
+ |---------|-----|
71
+ | `OpfsStorageAdapterFactory` | Default. Origin Private File System, positional reads and writes, atomic snapshot publication |
72
+ | `IndexedDbStorageAdapterFactory` | Compatibility backend for hosts without OPFS |
73
+ | `MemoryStorageBackend` | Tests and throwaway sessions |
74
+
75
+ `StorageAdapter` is the only platform boundary. Transactions, recovery and checkpoint semantics live in `core`, so
76
+ backends implement files, not database behaviour.
77
+
78
+ ## Concurrency
79
+
80
+ A writer holds a session-scoped `Web Locks` lease. A second tab that opens the same database fails with
81
+ `yydb.lease.unavailable` and `retryable: true` instead of silently writing alongside the first one. When a lock manager
82
+ is missing the call fails the same way; it never degrades to multiple writers.
83
+
84
+ `BroadcastChannel` carries `commit`, `schema` and `close` events so other same-origin contexts can discard stale views
85
+ and retry after the lease is released. `listenDatabaseEvents(name, handler)` subscribes without opening the database.
86
+
87
+ ## Layout
88
+
89
+ | Path | Role |
90
+ |------|------|
91
+ | `src/api/` | Public database, transaction, schema and shared types |
92
+ | `src/core/` | Records, WAL, checkpoint, recovery, writer lease and broadcast |
93
+ | `src/storage/` | `StorageAdapter` plus OPFS, IndexedDB and memory backends |
94
+ | `src/codec/` | Page, snapshot and WAL record encoding over `Uint8Array` |
95
+ | `src/errors/` | Stable `yydb.*` error codes |
96
+
97
+ ## Errors
98
+
99
+ | Code | Meaning |
100
+ |------|---------|
101
+ | `yydb.io` | Storage operation failed |
102
+ | `yydb.corrupt` | Persisted bytes failed validation |
103
+ | `yydb.schema.conflict` | Schema document differs from the stored one |
104
+ | `yydb.schema.invalid` | Schema document is not usable |
105
+ | `yydb.unsupported` | Host or operation is not supported |
106
+ | `yydb.session.closed` | Database or handle is closed |
107
+ | `yydb.lease.unavailable` | Writer lease is held elsewhere or Web Locks is missing (retryable) |
108
+ | `yydb.quota.exceeded` | Browser storage quota is exhausted |
109
+
110
+ [YYDB overview](https://github.com/yy-database/yydb.rs)