ducjs 4.0.0 → 4.0.2
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 +2 -2
- package/dist/ducjs_wasm.d.ts +25 -42
- package/dist/ducjs_wasm.js +78 -128
- package/dist/ducjs_wasm_bg.wasm +0 -0
- package/dist/ducjs_wasm_bg.wasm.d.ts +3 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/opfs-import.d.ts +11 -0
- package/dist/opfs-import.js +54 -4
- package/dist/opfs.d.ts +2 -0
- package/dist/opfs.js +6 -0
- package/dist/parse.d.ts +0 -10
- package/dist/parse.js +1 -33
- package/dist/wasm.d.ts +1 -4
- package/dist/wasm.js +1 -4
- package/package.json +2 -2
- package/dist/lazy-files.d.ts +0 -51
- package/dist/lazy-files.js +0 -233
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
<br/>
|
|
5
5
|
<a href="https://duc.ducflair.com" target="_blank"><img width="256px" src="https://cdn.jsdelivr.net/gh/ducflair/assets@main/src/duc/duc-extended.png" /></a>
|
|
6
|
-
<p align="center">
|
|
6
|
+
<p align="center">SQLite-backed project-state format for physical-engineering work before execution</p>
|
|
7
7
|
<p align="center" style="align: center;">
|
|
8
8
|
<a href="https://www.npmjs.com/package/ducjs"><img src="https://shields.io/badge/NPM-cc3534?logo=Npm&logoColor=white&style=round-square" alt="NPM" /></a>
|
|
9
9
|
<a href="https://github.com/ducflair/duc/releases"><img src="https://img.shields.io/npm/v/ducjs/latest?style=round-square&label=latest%20stable" alt="NPM ducjs@latest release" /></a>
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
</p>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
The `ducjs` package offers comprehensive TypeScript types and helper functions to work effortlessly with the
|
|
15
|
+
The `ducjs` package offers comprehensive TypeScript types and helper functions to work effortlessly with the `.duc` project-state format. Built with SQLite and optimized for performance, this package enables you to parse, validate, and manipulate `duc` files with ease.
|
|
16
16
|
|
|
17
17
|
## Documentation
|
|
18
18
|
|
package/dist/ducjs_wasm.d.ts
CHANGED
|
@@ -5,9 +5,29 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export function parseDuc(buf: Uint8Array): any;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
|
|
9
|
+
*/
|
|
10
|
+
export function serializeDuc(data: any): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Restore the document state at `version_number` from a `.duc` file buffer.
|
|
13
|
+
*/
|
|
14
|
+
export function restoreVersion(duc_buf: Uint8Array, version_number: number): any;
|
|
15
|
+
/**
|
|
16
|
+
* Restore a specific checkpoint by its ID from a `.duc` file buffer.
|
|
17
|
+
*/
|
|
18
|
+
export function restoreCheckpoint(duc_buf: Uint8Array, checkpoint_id: string): any;
|
|
19
|
+
/**
|
|
20
|
+
* List all versions (checkpoints + deltas) from a `.duc` file buffer.
|
|
9
21
|
*/
|
|
10
|
-
export function
|
|
22
|
+
export function listVersions(duc_buf: Uint8Array): any;
|
|
23
|
+
/**
|
|
24
|
+
* Read the full VersionGraph from a `.duc` file buffer.
|
|
25
|
+
*/
|
|
26
|
+
export function readVersionGraph(duc_buf: Uint8Array): any;
|
|
27
|
+
/**
|
|
28
|
+
* Revert the document to a specific version, removing all newer versions.
|
|
29
|
+
*/
|
|
30
|
+
export function revertToVersion(duc_buf: Uint8Array, target_version: number): any;
|
|
11
31
|
/**
|
|
12
32
|
* Returns the current version-control schema version defined in Rust.
|
|
13
33
|
*
|
|
@@ -38,40 +58,6 @@ export function createDeltaChangeset(base_state: Uint8Array, current_state: Uint
|
|
|
38
58
|
* - v3 (bsdiff), v2 (XOR diff), v1 (gzip full snapshot)
|
|
39
59
|
*/
|
|
40
60
|
export function applyDeltaChangeset(base_state: Uint8Array, changeset: Uint8Array): Uint8Array;
|
|
41
|
-
/**
|
|
42
|
-
* Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
|
|
43
|
-
*/
|
|
44
|
-
export function serializeDuc(data: any): Uint8Array;
|
|
45
|
-
/**
|
|
46
|
-
* Fetch a single external file from a `.duc` buffer by file ID.
|
|
47
|
-
*
|
|
48
|
-
* Returns the file's binary data as a Uint8Array, or `undefined` if not found.
|
|
49
|
-
*/
|
|
50
|
-
export function getExternalFile(buf: Uint8Array, file_id: string): any;
|
|
51
|
-
/**
|
|
52
|
-
* List metadata for all external files (without loading the heavy data blobs).
|
|
53
|
-
*/
|
|
54
|
-
export function listExternalFiles(buf: Uint8Array): any;
|
|
55
|
-
/**
|
|
56
|
-
* Restore the document state at `version_number` from a `.duc` file buffer.
|
|
57
|
-
*/
|
|
58
|
-
export function restoreVersion(duc_buf: Uint8Array, version_number: number): any;
|
|
59
|
-
/**
|
|
60
|
-
* Restore a specific checkpoint by its ID from a `.duc` file buffer.
|
|
61
|
-
*/
|
|
62
|
-
export function restoreCheckpoint(duc_buf: Uint8Array, checkpoint_id: string): any;
|
|
63
|
-
/**
|
|
64
|
-
* List all versions (checkpoints + deltas) from a `.duc` file buffer.
|
|
65
|
-
*/
|
|
66
|
-
export function listVersions(duc_buf: Uint8Array): any;
|
|
67
|
-
/**
|
|
68
|
-
* Read the full VersionGraph from a `.duc` file buffer.
|
|
69
|
-
*/
|
|
70
|
-
export function readVersionGraph(duc_buf: Uint8Array): any;
|
|
71
|
-
/**
|
|
72
|
-
* Revert the document to a specific version, removing all newer versions.
|
|
73
|
-
*/
|
|
74
|
-
export function revertToVersion(duc_buf: Uint8Array, target_version: number): any;
|
|
75
61
|
export class DucOpfsDocument {
|
|
76
62
|
private constructor();
|
|
77
63
|
free(): void;
|
|
@@ -213,11 +199,8 @@ export interface InitOutput {
|
|
|
213
199
|
readonly ducopfsimporter_getBytesWritten: (a: number) => number;
|
|
214
200
|
readonly ducopfsimporter_writeChunk: (a: number, b: number, c: number) => [number, number];
|
|
215
201
|
readonly getCurrentSchemaVersion: () => number;
|
|
216
|
-
readonly getExternalFile: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
217
|
-
readonly listExternalFiles: (a: number, b: number) => [number, number, number];
|
|
218
202
|
readonly listVersions: (a: number, b: number) => [number, number, number];
|
|
219
203
|
readonly parseDuc: (a: number, b: number) => [number, number, number];
|
|
220
|
-
readonly parseDucLazy: (a: number, b: number) => [number, number, number];
|
|
221
204
|
readonly readVersionGraph: (a: number, b: number) => [number, number, number];
|
|
222
205
|
readonly restoreCheckpoint: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
223
206
|
readonly restoreVersion: (a: number, b: number, c: number) => [number, number, number];
|
|
@@ -238,11 +221,11 @@ export interface InitOutput {
|
|
|
238
221
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
239
222
|
readonly __externref_table_alloc: () => number;
|
|
240
223
|
readonly __wbindgen_export_4: WebAssembly.Table;
|
|
241
|
-
readonly __wbindgen_export_5: WebAssembly.Table;
|
|
242
224
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
225
|
+
readonly __wbindgen_export_6: WebAssembly.Table;
|
|
243
226
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
244
|
-
readonly
|
|
245
|
-
readonly
|
|
227
|
+
readonly closure101_externref_shim: (a: number, b: number, c: any) => void;
|
|
228
|
+
readonly closure82_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
246
229
|
readonly __wbindgen_start: () => void;
|
|
247
230
|
}
|
|
248
231
|
|
package/dist/ducjs_wasm.js
CHANGED
|
@@ -186,7 +186,7 @@ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
|
|
|
186
186
|
? { register: () => {}, unregister: () => {} }
|
|
187
187
|
: new FinalizationRegistry(
|
|
188
188
|
state => {
|
|
189
|
-
wasm.
|
|
189
|
+
wasm.__wbindgen_export_6.get(state.dtor)(state.a, state.b);
|
|
190
190
|
}
|
|
191
191
|
);
|
|
192
192
|
|
|
@@ -204,7 +204,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
|
|
|
204
204
|
return f(a, state.b, ...args);
|
|
205
205
|
} finally {
|
|
206
206
|
if (--state.cnt === 0) {
|
|
207
|
-
wasm.
|
|
207
|
+
wasm.__wbindgen_export_6.get(state.dtor)(a, state.b);
|
|
208
208
|
CLOSURE_DTORS.unregister(state);
|
|
209
209
|
} else {
|
|
210
210
|
state.a = a;
|
|
@@ -243,87 +243,6 @@ export function parseDuc(buf) {
|
|
|
243
243
|
return takeFromExternrefTable0(ret[0]);
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
/**
|
|
247
|
-
* Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
|
|
248
|
-
* @param {Uint8Array} buf
|
|
249
|
-
* @returns {any}
|
|
250
|
-
*/
|
|
251
|
-
export function parseDucLazy(buf) {
|
|
252
|
-
const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
|
|
253
|
-
const len0 = WASM_VECTOR_LEN;
|
|
254
|
-
const ret = wasm.parseDucLazy(ptr0, len0);
|
|
255
|
-
if (ret[2]) {
|
|
256
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
257
|
-
}
|
|
258
|
-
return takeFromExternrefTable0(ret[0]);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Returns the current version-control schema version defined in Rust.
|
|
263
|
-
*
|
|
264
|
-
* TypeScript should use this as the source of truth instead of hardcoding
|
|
265
|
-
* its own constant. When this value is bumped in Rust, the version control
|
|
266
|
-
* system will automatically handle migration bookkeeping (closing old chains,
|
|
267
|
-
* recording migrations) the next time a checkpoint or delta is created.
|
|
268
|
-
* @returns {number}
|
|
269
|
-
*/
|
|
270
|
-
export function getCurrentSchemaVersion() {
|
|
271
|
-
return 4000000;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Compute a checkpoint-relative binary diff changeset using bsdiff.
|
|
276
|
-
*
|
|
277
|
-
* `base_state` is the checkpoint's full data blob.
|
|
278
|
-
* `current_state` is the full document state at the new version.
|
|
279
|
-
*
|
|
280
|
-
* Returns an encoded changeset (`Uint8Array`) ready for storage in a
|
|
281
|
-
* `Delta.payload`. bsdiff finds matching blocks even when they shift
|
|
282
|
-
* offsets, which is critical for SQLite databases.
|
|
283
|
-
* @param {Uint8Array} base_state
|
|
284
|
-
* @param {Uint8Array} current_state
|
|
285
|
-
* @returns {Uint8Array}
|
|
286
|
-
*/
|
|
287
|
-
export function createDeltaChangeset(base_state, current_state) {
|
|
288
|
-
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
289
|
-
const len0 = WASM_VECTOR_LEN;
|
|
290
|
-
const ptr1 = passArray8ToWasm0(current_state, wasm.__wbindgen_malloc);
|
|
291
|
-
const len1 = WASM_VECTOR_LEN;
|
|
292
|
-
const ret = wasm.createDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
293
|
-
if (ret[3]) {
|
|
294
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
295
|
-
}
|
|
296
|
-
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
297
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
298
|
-
return v3;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Apply a changeset to reconstruct document state.
|
|
303
|
-
*
|
|
304
|
-
* `base_state` must be the exact checkpoint data used when the changeset
|
|
305
|
-
* was created. Returns the full document state as `Uint8Array`.
|
|
306
|
-
*
|
|
307
|
-
* Handles all changeset formats transparently:
|
|
308
|
-
* - v3 (bsdiff), v2 (XOR diff), v1 (gzip full snapshot)
|
|
309
|
-
* @param {Uint8Array} base_state
|
|
310
|
-
* @param {Uint8Array} changeset
|
|
311
|
-
* @returns {Uint8Array}
|
|
312
|
-
*/
|
|
313
|
-
export function applyDeltaChangeset(base_state, changeset) {
|
|
314
|
-
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
315
|
-
const len0 = WASM_VECTOR_LEN;
|
|
316
|
-
const ptr1 = passArray8ToWasm0(changeset, wasm.__wbindgen_malloc);
|
|
317
|
-
const len1 = WASM_VECTOR_LEN;
|
|
318
|
-
const ret = wasm.applyDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
319
|
-
if (ret[3]) {
|
|
320
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
321
|
-
}
|
|
322
|
-
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
323
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
324
|
-
return v3;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
246
|
/**
|
|
328
247
|
* Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
|
|
329
248
|
* @param {any} data
|
|
@@ -339,41 +258,6 @@ export function serializeDuc(data) {
|
|
|
339
258
|
return v1;
|
|
340
259
|
}
|
|
341
260
|
|
|
342
|
-
/**
|
|
343
|
-
* Fetch a single external file from a `.duc` buffer by file ID.
|
|
344
|
-
*
|
|
345
|
-
* Returns the file's binary data as a Uint8Array, or `undefined` if not found.
|
|
346
|
-
* @param {Uint8Array} buf
|
|
347
|
-
* @param {string} file_id
|
|
348
|
-
* @returns {any}
|
|
349
|
-
*/
|
|
350
|
-
export function getExternalFile(buf, file_id) {
|
|
351
|
-
const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
|
|
352
|
-
const len0 = WASM_VECTOR_LEN;
|
|
353
|
-
const ptr1 = passStringToWasm0(file_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
354
|
-
const len1 = WASM_VECTOR_LEN;
|
|
355
|
-
const ret = wasm.getExternalFile(ptr0, len0, ptr1, len1);
|
|
356
|
-
if (ret[2]) {
|
|
357
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
358
|
-
}
|
|
359
|
-
return takeFromExternrefTable0(ret[0]);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* List metadata for all external files (without loading the heavy data blobs).
|
|
364
|
-
* @param {Uint8Array} buf
|
|
365
|
-
* @returns {any}
|
|
366
|
-
*/
|
|
367
|
-
export function listExternalFiles(buf) {
|
|
368
|
-
const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
|
|
369
|
-
const len0 = WASM_VECTOR_LEN;
|
|
370
|
-
const ret = wasm.listExternalFiles(ptr0, len0);
|
|
371
|
-
if (ret[2]) {
|
|
372
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
373
|
-
}
|
|
374
|
-
return takeFromExternrefTable0(ret[0]);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
261
|
/**
|
|
378
262
|
* Restore the document state at `version_number` from a `.duc` file buffer.
|
|
379
263
|
* @param {Uint8Array} duc_buf
|
|
@@ -454,12 +338,78 @@ export function revertToVersion(duc_buf, target_version) {
|
|
|
454
338
|
return takeFromExternrefTable0(ret[0]);
|
|
455
339
|
}
|
|
456
340
|
|
|
457
|
-
|
|
458
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Returns the current version-control schema version defined in Rust.
|
|
343
|
+
*
|
|
344
|
+
* TypeScript should use this as the source of truth instead of hardcoding
|
|
345
|
+
* its own constant. When this value is bumped in Rust, the version control
|
|
346
|
+
* system will automatically handle migration bookkeeping (closing old chains,
|
|
347
|
+
* recording migrations) the next time a checkpoint or delta is created.
|
|
348
|
+
* @returns {number}
|
|
349
|
+
*/
|
|
350
|
+
export function getCurrentSchemaVersion() {
|
|
351
|
+
return 4000000;
|
|
459
352
|
}
|
|
460
353
|
|
|
461
|
-
|
|
462
|
-
|
|
354
|
+
/**
|
|
355
|
+
* Compute a checkpoint-relative binary diff changeset using bsdiff.
|
|
356
|
+
*
|
|
357
|
+
* `base_state` is the checkpoint's full data blob.
|
|
358
|
+
* `current_state` is the full document state at the new version.
|
|
359
|
+
*
|
|
360
|
+
* Returns an encoded changeset (`Uint8Array`) ready for storage in a
|
|
361
|
+
* `Delta.payload`. bsdiff finds matching blocks even when they shift
|
|
362
|
+
* offsets, which is critical for SQLite databases.
|
|
363
|
+
* @param {Uint8Array} base_state
|
|
364
|
+
* @param {Uint8Array} current_state
|
|
365
|
+
* @returns {Uint8Array}
|
|
366
|
+
*/
|
|
367
|
+
export function createDeltaChangeset(base_state, current_state) {
|
|
368
|
+
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
369
|
+
const len0 = WASM_VECTOR_LEN;
|
|
370
|
+
const ptr1 = passArray8ToWasm0(current_state, wasm.__wbindgen_malloc);
|
|
371
|
+
const len1 = WASM_VECTOR_LEN;
|
|
372
|
+
const ret = wasm.createDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
373
|
+
if (ret[3]) {
|
|
374
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
375
|
+
}
|
|
376
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
377
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
378
|
+
return v3;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Apply a changeset to reconstruct document state.
|
|
383
|
+
*
|
|
384
|
+
* `base_state` must be the exact checkpoint data used when the changeset
|
|
385
|
+
* was created. Returns the full document state as `Uint8Array`.
|
|
386
|
+
*
|
|
387
|
+
* Handles all changeset formats transparently:
|
|
388
|
+
* - v3 (bsdiff), v2 (XOR diff), v1 (gzip full snapshot)
|
|
389
|
+
* @param {Uint8Array} base_state
|
|
390
|
+
* @param {Uint8Array} changeset
|
|
391
|
+
* @returns {Uint8Array}
|
|
392
|
+
*/
|
|
393
|
+
export function applyDeltaChangeset(base_state, changeset) {
|
|
394
|
+
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
395
|
+
const len0 = WASM_VECTOR_LEN;
|
|
396
|
+
const ptr1 = passArray8ToWasm0(changeset, wasm.__wbindgen_malloc);
|
|
397
|
+
const len1 = WASM_VECTOR_LEN;
|
|
398
|
+
const ret = wasm.applyDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
399
|
+
if (ret[3]) {
|
|
400
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
401
|
+
}
|
|
402
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
403
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
404
|
+
return v3;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function __wbg_adapter_14(arg0, arg1, arg2) {
|
|
408
|
+
wasm.closure101_externref_shim(arg0, arg1, arg2);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function __wbg_adapter_126(arg0, arg1, arg2, arg3) {
|
|
412
|
+
wasm.closure82_externref_shim(arg0, arg1, arg2, arg3);
|
|
463
413
|
}
|
|
464
414
|
|
|
465
415
|
const DucOpfsDocumentFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
@@ -1193,7 +1143,7 @@ function __wbg_get_imports() {
|
|
|
1193
1143
|
const a = state0.a;
|
|
1194
1144
|
state0.a = 0;
|
|
1195
1145
|
try {
|
|
1196
|
-
return
|
|
1146
|
+
return __wbg_adapter_126(a, state0.b, arg0, arg1);
|
|
1197
1147
|
} finally {
|
|
1198
1148
|
state0.a = a;
|
|
1199
1149
|
}
|
|
@@ -1439,11 +1389,6 @@ function __wbg_get_imports() {
|
|
|
1439
1389
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
1440
1390
|
return ret;
|
|
1441
1391
|
};
|
|
1442
|
-
imports.wbg.__wbindgen_cast_31f66333318e4864 = function(arg0, arg1) {
|
|
1443
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx: 98, function: Function { arguments: [Externref], shim_idx: 99, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1444
|
-
const ret = makeMutClosure(arg0, arg1, 98, __wbg_adapter_16);
|
|
1445
|
-
return ret;
|
|
1446
|
-
};
|
|
1447
1392
|
imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
|
|
1448
1393
|
// Cast intrinsic for `U64 -> Externref`.
|
|
1449
1394
|
const ret = BigInt.asUintN(64, arg0);
|
|
@@ -1461,6 +1406,11 @@ function __wbg_get_imports() {
|
|
|
1461
1406
|
const ret = arg0;
|
|
1462
1407
|
return ret;
|
|
1463
1408
|
};
|
|
1409
|
+
imports.wbg.__wbindgen_cast_9f0223d8557fdf20 = function(arg0, arg1) {
|
|
1410
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 100, function: Function { arguments: [Externref], shim_idx: 101, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1411
|
+
const ret = makeMutClosure(arg0, arg1, 100, __wbg_adapter_14);
|
|
1412
|
+
return ret;
|
|
1413
|
+
};
|
|
1464
1414
|
imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
|
|
1465
1415
|
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
1466
1416
|
const ret = getArrayU8FromWasm0(arg0, arg1);
|
package/dist/ducjs_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -39,11 +39,8 @@ export const ducopfsimporter_finish: (a: number) => [number, number, number];
|
|
|
39
39
|
export const ducopfsimporter_getBytesWritten: (a: number) => number;
|
|
40
40
|
export const ducopfsimporter_writeChunk: (a: number, b: number, c: number) => [number, number];
|
|
41
41
|
export const getCurrentSchemaVersion: () => number;
|
|
42
|
-
export const getExternalFile: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
43
|
-
export const listExternalFiles: (a: number, b: number) => [number, number, number];
|
|
44
42
|
export const listVersions: (a: number, b: number) => [number, number, number];
|
|
45
43
|
export const parseDuc: (a: number, b: number) => [number, number, number];
|
|
46
|
-
export const parseDucLazy: (a: number, b: number) => [number, number, number];
|
|
47
44
|
export const readVersionGraph: (a: number, b: number) => [number, number, number];
|
|
48
45
|
export const restoreCheckpoint: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
49
46
|
export const restoreVersion: (a: number, b: number, c: number) => [number, number, number];
|
|
@@ -64,9 +61,9 @@ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) =>
|
|
|
64
61
|
export const __wbindgen_exn_store: (a: number) => void;
|
|
65
62
|
export const __externref_table_alloc: () => number;
|
|
66
63
|
export const __wbindgen_export_4: WebAssembly.Table;
|
|
67
|
-
export const __wbindgen_export_5: WebAssembly.Table;
|
|
68
64
|
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
65
|
+
export const __wbindgen_export_6: WebAssembly.Table;
|
|
69
66
|
export const __externref_table_dealloc: (a: number) => void;
|
|
70
|
-
export const
|
|
71
|
-
export const
|
|
67
|
+
export const closure101_externref_shim: (a: number, b: number, c: any) => void;
|
|
68
|
+
export const closure82_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
72
69
|
export const __wbindgen_start: () => void;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/opfs-import.d.ts
CHANGED
|
@@ -4,6 +4,17 @@ export type OpfsChunkImporter = {
|
|
|
4
4
|
export type DucStreamImportOptions = {
|
|
5
5
|
compressedChunkSize?: number;
|
|
6
6
|
writeBufferSize?: number;
|
|
7
|
+
progressIntervalMs?: number;
|
|
8
|
+
onProgress?: (progress: DucStreamImportProgress) => void;
|
|
9
|
+
};
|
|
10
|
+
export type DucStreamImportProgress = {
|
|
11
|
+
phase: "streaming" | "complete";
|
|
12
|
+
compressedBytes: number;
|
|
13
|
+
uncompressedBytes: number;
|
|
14
|
+
elapsedMs: number;
|
|
15
|
+
readWaitMs: number;
|
|
16
|
+
processingMs: number;
|
|
17
|
+
opfsWriteMs: number;
|
|
7
18
|
};
|
|
8
19
|
/**
|
|
9
20
|
* Incrementally copy raw SQLite or decompress a compressed DUC stream into an
|
package/dist/opfs-import.js
CHANGED
|
@@ -12,8 +12,9 @@ const DEFAULT_COMPRESSED_CHUNK_SIZE = 64 * 1024;
|
|
|
12
12
|
const DEFAULT_WRITE_BUFFER_SIZE = 1024 * 1024;
|
|
13
13
|
const SQLITE_HEADER = new TextEncoder().encode("SQLite format 3\0");
|
|
14
14
|
class BufferedImporterWriter {
|
|
15
|
-
constructor(importer, bufferSize) {
|
|
15
|
+
constructor(importer, bufferSize, onWrite) {
|
|
16
16
|
this.importer = importer;
|
|
17
|
+
this.onWrite = onWrite;
|
|
17
18
|
this.offset = 0;
|
|
18
19
|
this.totalBytes = 0;
|
|
19
20
|
if (!Number.isSafeInteger(bufferSize) || bufferSize <= 0) {
|
|
@@ -37,10 +38,19 @@ class BufferedImporterWriter {
|
|
|
37
38
|
this.flush();
|
|
38
39
|
return this.totalBytes;
|
|
39
40
|
}
|
|
41
|
+
get pendingByteLength() {
|
|
42
|
+
return this.offset;
|
|
43
|
+
}
|
|
44
|
+
get writtenByteLength() {
|
|
45
|
+
return this.totalBytes;
|
|
46
|
+
}
|
|
40
47
|
flush() {
|
|
48
|
+
var _a;
|
|
41
49
|
if (this.offset === 0)
|
|
42
50
|
return;
|
|
51
|
+
const startedAt = performance.now();
|
|
43
52
|
this.importer.writeChunk(this.buffer.subarray(0, this.offset));
|
|
53
|
+
(_a = this.onWrite) === null || _a === void 0 ? void 0 : _a.call(this, this.offset, performance.now() - startedAt);
|
|
44
54
|
this.totalBytes += this.offset;
|
|
45
55
|
this.offset = 0;
|
|
46
56
|
}
|
|
@@ -51,12 +61,42 @@ class BufferedImporterWriter {
|
|
|
51
61
|
*/
|
|
52
62
|
export function importDucStreamToOpfs(stream_1, importer_1) {
|
|
53
63
|
return __awaiter(this, arguments, void 0, function* (stream, importer, options = {}) {
|
|
54
|
-
var _a, _b;
|
|
64
|
+
var _a, _b, _c;
|
|
55
65
|
const compressedChunkSize = (_a = options.compressedChunkSize) !== null && _a !== void 0 ? _a : DEFAULT_COMPRESSED_CHUNK_SIZE;
|
|
56
66
|
if (!Number.isSafeInteger(compressedChunkSize) || compressedChunkSize <= 0) {
|
|
57
67
|
throw new RangeError("compressedChunkSize must be a positive safe integer");
|
|
58
68
|
}
|
|
59
|
-
const
|
|
69
|
+
const startedAt = performance.now();
|
|
70
|
+
const progressIntervalMs = (_b = options.progressIntervalMs) !== null && _b !== void 0 ? _b : 500;
|
|
71
|
+
if (!Number.isFinite(progressIntervalMs) || progressIntervalMs <= 0) {
|
|
72
|
+
throw new RangeError("progressIntervalMs must be a positive number");
|
|
73
|
+
}
|
|
74
|
+
let lastProgressAt = startedAt;
|
|
75
|
+
let compressedBytes = 0;
|
|
76
|
+
let readWaitMs = 0;
|
|
77
|
+
let processingMs = 0;
|
|
78
|
+
let opfsWriteMs = 0;
|
|
79
|
+
const writer = new BufferedImporterWriter(importer, (_c = options.writeBufferSize) !== null && _c !== void 0 ? _c : DEFAULT_WRITE_BUFFER_SIZE, (_byteLength, elapsedMs) => {
|
|
80
|
+
opfsWriteMs += elapsedMs;
|
|
81
|
+
});
|
|
82
|
+
const emitProgress = (phase) => {
|
|
83
|
+
if (!options.onProgress)
|
|
84
|
+
return;
|
|
85
|
+
const now = performance.now();
|
|
86
|
+
if (phase === "streaming" && now - lastProgressAt < progressIntervalMs) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
options.onProgress({
|
|
90
|
+
phase,
|
|
91
|
+
compressedBytes,
|
|
92
|
+
uncompressedBytes: writer.writtenByteLength + writer.pendingByteLength,
|
|
93
|
+
elapsedMs: now - startedAt,
|
|
94
|
+
readWaitMs,
|
|
95
|
+
processingMs,
|
|
96
|
+
opfsWriteMs,
|
|
97
|
+
});
|
|
98
|
+
lastProgressAt = now;
|
|
99
|
+
};
|
|
60
100
|
const decompressor = new Decompress((chunk) => writer.write(chunk));
|
|
61
101
|
const reader = stream.getReader();
|
|
62
102
|
const header = new Uint8Array(SQLITE_HEADER.byteLength);
|
|
@@ -77,11 +117,15 @@ export function importDucStreamToOpfs(stream_1, importer_1) {
|
|
|
77
117
|
};
|
|
78
118
|
try {
|
|
79
119
|
while (true) {
|
|
120
|
+
const readStartedAt = performance.now();
|
|
80
121
|
const { done, value } = yield reader.read();
|
|
122
|
+
readWaitMs += performance.now() - readStartedAt;
|
|
81
123
|
if (done)
|
|
82
124
|
break;
|
|
83
125
|
if (!(value === null || value === void 0 ? void 0 : value.byteLength))
|
|
84
126
|
continue;
|
|
127
|
+
compressedBytes += value.byteLength;
|
|
128
|
+
const processingStartedAt = performance.now();
|
|
85
129
|
let valueOffset = 0;
|
|
86
130
|
if (isRawSqlite === null) {
|
|
87
131
|
const headerBytes = Math.min(header.byteLength - headerLength, value.byteLength);
|
|
@@ -96,7 +140,10 @@ export function importDucStreamToOpfs(stream_1, importer_1) {
|
|
|
96
140
|
if (isRawSqlite !== null && valueOffset < value.byteLength) {
|
|
97
141
|
writeDetected(value.subarray(valueOffset));
|
|
98
142
|
}
|
|
143
|
+
processingMs += performance.now() - processingStartedAt;
|
|
144
|
+
emitProgress("streaming");
|
|
99
145
|
}
|
|
146
|
+
const finalProcessingStartedAt = performance.now();
|
|
100
147
|
if (isRawSqlite === null) {
|
|
101
148
|
isRawSqlite = false;
|
|
102
149
|
writeCompressed(header.subarray(0, headerLength));
|
|
@@ -104,7 +151,10 @@ export function importDucStreamToOpfs(stream_1, importer_1) {
|
|
|
104
151
|
if (!isRawSqlite) {
|
|
105
152
|
decompressor.push(new Uint8Array(), true);
|
|
106
153
|
}
|
|
107
|
-
|
|
154
|
+
const writtenBytes = writer.finish();
|
|
155
|
+
processingMs += performance.now() - finalProcessingStartedAt;
|
|
156
|
+
emitProgress("complete");
|
|
157
|
+
return writtenBytes;
|
|
108
158
|
}
|
|
109
159
|
finally {
|
|
110
160
|
reader.releaseLock();
|
package/dist/opfs.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export declare class BrowserDucDocument {
|
|
|
22
22
|
readRestoredState(elementsConfig?: ElementsConfig, restoreConfig?: RestoreConfig): RestoredDataState;
|
|
23
23
|
writeState(data: Partial<ExportedDataState>): void;
|
|
24
24
|
listExternalFiles(): unknown;
|
|
25
|
+
readCheckpointDataChunk(checkpointId: string, chunkIndex: number): Uint8Array | undefined;
|
|
26
|
+
readDeltaChangesetChunk(deltaId: string, chunkIndex: number): Uint8Array | undefined;
|
|
25
27
|
clearExternalFileRevisionChunks(revisionId: string): void;
|
|
26
28
|
writeExternalFileRevisionChunk(revisionId: string, chunkIndex: number, offsetBytes: number, data: Uint8Array): void;
|
|
27
29
|
readExternalFileRevisionChunk(revisionId: string, chunkIndex: number): Uint8Array | undefined;
|
package/dist/opfs.js
CHANGED
|
@@ -111,6 +111,12 @@ export class BrowserDucDocument {
|
|
|
111
111
|
listExternalFiles() {
|
|
112
112
|
return this.document.listExternalFiles();
|
|
113
113
|
}
|
|
114
|
+
readCheckpointDataChunk(checkpointId, chunkIndex) {
|
|
115
|
+
return this.document.readCheckpointDataChunk(checkpointId, chunkIndex);
|
|
116
|
+
}
|
|
117
|
+
readDeltaChangesetChunk(deltaId, chunkIndex) {
|
|
118
|
+
return this.document.readDeltaChangesetChunk(deltaId, chunkIndex);
|
|
119
|
+
}
|
|
114
120
|
clearExternalFileRevisionChunks(revisionId) {
|
|
115
121
|
this.document.clearExternalFileRevisionChunks(revisionId);
|
|
116
122
|
}
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { ElementsConfig, RestoreConfig, RestoredDataState } from "./restore";
|
|
2
2
|
export type { RestoredDataState };
|
|
3
|
-
export type LazyRestoredDataState = RestoredDataState & {
|
|
4
|
-
lazyFileStore: LazyExternalFileStore;
|
|
5
|
-
};
|
|
6
|
-
import { LazyExternalFileStore } from "./lazy-files";
|
|
7
|
-
export { LazyExternalFileStore };
|
|
8
3
|
/**
|
|
9
4
|
* Parse a `.duc` file (Blob/File) into a RestoredDataState.
|
|
10
5
|
*
|
|
@@ -14,8 +9,3 @@ export { LazyExternalFileStore };
|
|
|
14
9
|
* 4. restore() for defaults & migrations
|
|
15
10
|
*/
|
|
16
11
|
export declare function parseDuc(blob: Blob | File, _fileHandle?: FileSystemFileHandle | null, elementsConfig?: ElementsConfig, restoreConfig?: RestoreConfig): Promise<RestoredDataState>;
|
|
17
|
-
/**
|
|
18
|
-
* Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
|
|
19
|
-
* Use `LazyExternalFileStore` for on-demand file access.
|
|
20
|
-
*/
|
|
21
|
-
export declare function parseDucLazy(buffer: Uint8Array, elementsConfig?: ElementsConfig, restoreConfig?: RestoreConfig): Promise<LazyRestoredDataState>;
|
package/dist/parse.js
CHANGED
|
@@ -8,10 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { restoreParsedData } from "./restore-parsed";
|
|
11
|
-
import { ensureWasm, wasmParseDuc
|
|
12
|
-
// Re-export from lazy-files for backwards compatibility
|
|
13
|
-
import { LazyExternalFileStore } from "./lazy-files";
|
|
14
|
-
export { LazyExternalFileStore };
|
|
11
|
+
import { ensureWasm, wasmParseDuc } from "./wasm";
|
|
15
12
|
/**
|
|
16
13
|
* Parse a `.duc` file (Blob/File) into a RestoredDataState.
|
|
17
14
|
*
|
|
@@ -41,32 +38,3 @@ export function parseDuc(blob, _fileHandle, elementsConfig, restoreConfig) {
|
|
|
41
38
|
return restoreParsedData(raw, elementsConfig, restoreConfig);
|
|
42
39
|
});
|
|
43
40
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
|
|
46
|
-
* Use `LazyExternalFileStore` for on-demand file access.
|
|
47
|
-
*/
|
|
48
|
-
export function parseDucLazy(buffer, elementsConfig, restoreConfig) {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
yield ensureWasm();
|
|
51
|
-
if (buffer.byteLength === 0) {
|
|
52
|
-
throw new Error(`[parseDucLazy] buffer too small (${buffer.byteLength} bytes) — not a valid .duc file`);
|
|
53
|
-
}
|
|
54
|
-
const header = new TextDecoder().decode(buffer.slice(0, 15));
|
|
55
|
-
let raw;
|
|
56
|
-
try {
|
|
57
|
-
raw = wasmParseDucLazy(buffer);
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
const prefixHex = Array.from(buffer.slice(0, 16))
|
|
61
|
-
.map((b) => b.toString(16).padStart(2, "0"))
|
|
62
|
-
.join(" ");
|
|
63
|
-
throw new Error(`[parseDucLazy] wasm parse failed (size=${buffer.byteLength}, header="${header}", prefix=${prefixHex}): ${error instanceof Error ? error.message : String(error)}`);
|
|
64
|
-
}
|
|
65
|
-
const lazyFileStore = new LazyExternalFileStore(buffer);
|
|
66
|
-
const files = {};
|
|
67
|
-
const filesData = {};
|
|
68
|
-
const restored = restoreParsedData(raw, elementsConfig, restoreConfig, { files, filesData });
|
|
69
|
-
restored.lazyFileStore = lazyFileStore;
|
|
70
|
-
return restored;
|
|
71
|
-
});
|
|
72
|
-
}
|
package/dist/wasm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DucOpfsDocument as _DucOpfsDocument, DucOpfsImporter as _DucOpfsImporter, applyDeltaChangeset as _applyDeltaChangeset, createDeltaChangeset as _createDeltaChangeset, getCurrentSchemaVersion as _getCurrentSchemaVersion, parseDuc as _parseDuc,
|
|
1
|
+
import { DucOpfsDocument as _DucOpfsDocument, DucOpfsImporter as _DucOpfsImporter, applyDeltaChangeset as _applyDeltaChangeset, createDeltaChangeset as _createDeltaChangeset, getCurrentSchemaVersion as _getCurrentSchemaVersion, parseDuc as _parseDuc, serializeDuc as _serializeDuc, restoreVersion as _restoreVersion, restoreCheckpoint as _restoreCheckpoint, listVersions as _listVersions, readVersionGraph as _readVersionGraph, revertToVersion as _revertToVersion } from "../dist/ducjs_wasm";
|
|
2
2
|
export declare function ensureWasm(wasmUrl?: string | URL | BufferSource): Promise<void>;
|
|
3
3
|
/**
|
|
4
4
|
* Fetch the raw WASM binary as an ArrayBuffer.
|
|
@@ -26,10 +26,7 @@ export declare const DucOpfsDocument: typeof _DucOpfsDocument;
|
|
|
26
26
|
*/
|
|
27
27
|
export declare const DucOpfsImporter: typeof _DucOpfsImporter;
|
|
28
28
|
export declare const wasmParseDuc: typeof _parseDuc;
|
|
29
|
-
export declare const wasmParseDucLazy: typeof _parseDucLazy;
|
|
30
29
|
export declare const wasmSerializeDuc: typeof _serializeDuc;
|
|
31
|
-
export declare const wasmGetExternalFile: typeof _getExternalFile;
|
|
32
|
-
export declare const wasmListExternalFiles: typeof _listExternalFiles;
|
|
33
30
|
export declare const wasmRestoreVersion: typeof _restoreVersion;
|
|
34
31
|
export declare const wasmRestoreCheckpoint: typeof _restoreCheckpoint;
|
|
35
32
|
export declare const wasmListVersions: typeof _listVersions;
|
package/dist/wasm.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import init, { DucOpfsDocument as _DucOpfsDocument, DucOpfsImporter as _DucOpfsImporter, applyDeltaChangeset as _applyDeltaChangeset, createDeltaChangeset as _createDeltaChangeset, getCurrentSchemaVersion as _getCurrentSchemaVersion, parseDuc as _parseDuc,
|
|
10
|
+
import init, { DucOpfsDocument as _DucOpfsDocument, DucOpfsImporter as _DucOpfsImporter, applyDeltaChangeset as _applyDeltaChangeset, createDeltaChangeset as _createDeltaChangeset, getCurrentSchemaVersion as _getCurrentSchemaVersion, parseDuc as _parseDuc, serializeDuc as _serializeDuc, restoreVersion as _restoreVersion, restoreCheckpoint as _restoreCheckpoint, listVersions as _listVersions, readVersionGraph as _readVersionGraph, revertToVersion as _revertToVersion, } from "../dist/ducjs_wasm";
|
|
11
11
|
let initialized = false;
|
|
12
12
|
let initPromise = null;
|
|
13
13
|
const DEFAULT_WASM_URL = new URL("../dist/ducjs_wasm_bg.wasm", import.meta.url);
|
|
@@ -78,10 +78,7 @@ export const DucOpfsDocument = _DucOpfsDocument;
|
|
|
78
78
|
export const DucOpfsImporter = _DucOpfsImporter;
|
|
79
79
|
// Byte-buffer compatibility API
|
|
80
80
|
export const wasmParseDuc = _parseDuc;
|
|
81
|
-
export const wasmParseDucLazy = _parseDucLazy;
|
|
82
81
|
export const wasmSerializeDuc = _serializeDuc;
|
|
83
|
-
export const wasmGetExternalFile = _getExternalFile;
|
|
84
|
-
export const wasmListExternalFiles = _listExternalFiles;
|
|
85
82
|
export const wasmRestoreVersion = _restoreVersion;
|
|
86
83
|
export const wasmRestoreCheckpoint = _restoreCheckpoint;
|
|
87
84
|
export const wasmListVersions = _listVersions;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ducjs",
|
|
3
|
-
"version": "4.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.0.2",
|
|
4
|
+
"description": "SQLite-backed project-state format for physical-engineering work before execution.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
package/dist/lazy-files.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { DucExternalFile, DucExternalFiles, ExternalFileLoaded, ResolvedFileData, ExternalFilesData } from "./types";
|
|
2
|
-
export type LazyFileMetadata = {
|
|
3
|
-
id: string;
|
|
4
|
-
mimeType: string;
|
|
5
|
-
created: number;
|
|
6
|
-
lastRetrieved?: number;
|
|
7
|
-
version?: number;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Provides lazy access to external files embedded inside a `.duc` buffer.
|
|
11
|
-
*
|
|
12
|
-
* Instead of loading all file blobs into memory at parse time, this store
|
|
13
|
-
* keeps a reference to the raw `.duc` buffer and fetches individual files
|
|
14
|
-
* on demand via WASM calls.
|
|
15
|
-
*/
|
|
16
|
-
export declare class LazyExternalFileStore {
|
|
17
|
-
private buffer;
|
|
18
|
-
private metadataCache;
|
|
19
|
-
private runtimeFiles;
|
|
20
|
-
private released;
|
|
21
|
-
constructor(buffer: Uint8Array);
|
|
22
|
-
get isReleased(): boolean;
|
|
23
|
-
get size(): number;
|
|
24
|
-
/** Check if a file with this ID exists. */
|
|
25
|
-
has(fileId: string): boolean;
|
|
26
|
-
/** Get metadata (without data blob) for a specific file. */
|
|
27
|
-
getMetadata(fileId: string): LazyFileMetadata | undefined;
|
|
28
|
-
/** Get metadata for all files. */
|
|
29
|
-
getAllMetadata(): LazyFileMetadata[];
|
|
30
|
-
/** Fetch the full file (including data blobs for all revisions) for a specific file. */
|
|
31
|
-
getFile(fileId: string): ExternalFileLoaded | null;
|
|
32
|
-
/** Get the active revision data for a specific file. */
|
|
33
|
-
getFileData(fileId: string): ResolvedFileData | null;
|
|
34
|
-
/** Fetch active revision data and return a copy of the data buffer (safe for transfer). */
|
|
35
|
-
getFileDataCopy(fileId: string): ResolvedFileData | null;
|
|
36
|
-
/** Add a file at runtime (not persisted in .duc until next serialize). */
|
|
37
|
-
addRuntimeFile(fileId: string, file: DucExternalFile, data: Record<string, Uint8Array>): void;
|
|
38
|
-
/** Remove a runtime file. */
|
|
39
|
-
removeRuntimeFile(fileId: string): boolean;
|
|
40
|
-
/** Unload a runtime file's data from memory while keeping metadata. */
|
|
41
|
-
unloadRuntimeFileData(fileId: string): boolean;
|
|
42
|
-
/** Export all files metadata as a DucExternalFiles record. */
|
|
43
|
-
toExternalFiles(): DucExternalFiles;
|
|
44
|
-
/** Export all revision data blobs as an ExternalFilesData record. */
|
|
45
|
-
toExternalFilesData(): ExternalFilesData;
|
|
46
|
-
/** Merge files from another source. Adds missing files and merges new revisions into existing ones. */
|
|
47
|
-
mergeFiles(files: DucExternalFiles, filesData?: ExternalFilesData): void;
|
|
48
|
-
/** Release the underlying buffer to free memory. */
|
|
49
|
-
release(): void;
|
|
50
|
-
private getMetadataMap;
|
|
51
|
-
}
|
package/dist/lazy-files.js
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { wasmGetExternalFile, wasmListExternalFiles } from "./wasm";
|
|
13
|
-
/**
|
|
14
|
-
* Provides lazy access to external files embedded inside a `.duc` buffer.
|
|
15
|
-
*
|
|
16
|
-
* Instead of loading all file blobs into memory at parse time, this store
|
|
17
|
-
* keeps a reference to the raw `.duc` buffer and fetches individual files
|
|
18
|
-
* on demand via WASM calls.
|
|
19
|
-
*/
|
|
20
|
-
export class LazyExternalFileStore {
|
|
21
|
-
constructor(buffer) {
|
|
22
|
-
this.metadataCache = null;
|
|
23
|
-
this.runtimeFiles = new Map();
|
|
24
|
-
this.released = false;
|
|
25
|
-
this.buffer = buffer.byteLength > 0 ? buffer : null;
|
|
26
|
-
}
|
|
27
|
-
get isReleased() {
|
|
28
|
-
return this.released;
|
|
29
|
-
}
|
|
30
|
-
get size() {
|
|
31
|
-
return this.getMetadataMap().size + this.runtimeFiles.size;
|
|
32
|
-
}
|
|
33
|
-
/** Check if a file with this ID exists. */
|
|
34
|
-
has(fileId) {
|
|
35
|
-
return this.runtimeFiles.has(fileId) || this.getMetadataMap().has(fileId);
|
|
36
|
-
}
|
|
37
|
-
/** Get metadata (without data blob) for a specific file. */
|
|
38
|
-
getMetadata(fileId) {
|
|
39
|
-
const rt = this.runtimeFiles.get(fileId);
|
|
40
|
-
if (rt) {
|
|
41
|
-
const active = rt.revisions[rt.activeRevisionId];
|
|
42
|
-
if (!active)
|
|
43
|
-
return undefined;
|
|
44
|
-
return {
|
|
45
|
-
id: rt.id,
|
|
46
|
-
mimeType: active.mimeType,
|
|
47
|
-
created: active.created,
|
|
48
|
-
lastRetrieved: active.lastRetrieved,
|
|
49
|
-
version: rt.version,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
return this.getMetadataMap().get(fileId);
|
|
53
|
-
}
|
|
54
|
-
/** Get metadata for all files. */
|
|
55
|
-
getAllMetadata() {
|
|
56
|
-
const result = [];
|
|
57
|
-
const persisted = this.getMetadataMap();
|
|
58
|
-
for (const meta of persisted.values()) {
|
|
59
|
-
result.push(meta);
|
|
60
|
-
}
|
|
61
|
-
for (const [id, file] of this.runtimeFiles) {
|
|
62
|
-
if (!persisted.has(id)) {
|
|
63
|
-
const active = file.revisions[file.activeRevisionId];
|
|
64
|
-
if (active) {
|
|
65
|
-
result.push({
|
|
66
|
-
id: file.id,
|
|
67
|
-
mimeType: active.mimeType,
|
|
68
|
-
created: active.created,
|
|
69
|
-
lastRetrieved: active.lastRetrieved,
|
|
70
|
-
version: file.version,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
/** Fetch the full file (including data blobs for all revisions) for a specific file. */
|
|
78
|
-
getFile(fileId) {
|
|
79
|
-
const rt = this.runtimeFiles.get(fileId);
|
|
80
|
-
if (rt)
|
|
81
|
-
return rt;
|
|
82
|
-
if (!this.buffer)
|
|
83
|
-
return null;
|
|
84
|
-
const result = wasmGetExternalFile(this.buffer, fileId);
|
|
85
|
-
if (!result)
|
|
86
|
-
return null;
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
/** Get the active revision data for a specific file. */
|
|
90
|
-
getFileData(fileId) {
|
|
91
|
-
const loaded = this.getFile(fileId);
|
|
92
|
-
if (!loaded)
|
|
93
|
-
return null;
|
|
94
|
-
const meta = loaded.revisions[loaded.activeRevisionId];
|
|
95
|
-
if (!meta)
|
|
96
|
-
return null;
|
|
97
|
-
const dataBlob = loaded.data[loaded.activeRevisionId];
|
|
98
|
-
if (!dataBlob)
|
|
99
|
-
return null;
|
|
100
|
-
return { data: dataBlob, mimeType: meta.mimeType };
|
|
101
|
-
}
|
|
102
|
-
/** Fetch active revision data and return a copy of the data buffer (safe for transfer). */
|
|
103
|
-
getFileDataCopy(fileId) {
|
|
104
|
-
const data = this.getFileData(fileId);
|
|
105
|
-
if (!data)
|
|
106
|
-
return null;
|
|
107
|
-
return Object.assign(Object.assign({}, data), { data: new Uint8Array(data.data) });
|
|
108
|
-
}
|
|
109
|
-
/** Add a file at runtime (not persisted in .duc until next serialize). */
|
|
110
|
-
addRuntimeFile(fileId, file, data) {
|
|
111
|
-
this.runtimeFiles.set(fileId, Object.assign(Object.assign({}, file), { data }));
|
|
112
|
-
}
|
|
113
|
-
/** Remove a runtime file. */
|
|
114
|
-
removeRuntimeFile(fileId) {
|
|
115
|
-
return this.runtimeFiles.delete(fileId);
|
|
116
|
-
}
|
|
117
|
-
/** Unload a runtime file's data from memory while keeping metadata. */
|
|
118
|
-
unloadRuntimeFileData(fileId) {
|
|
119
|
-
const file = this.runtimeFiles.get(fileId);
|
|
120
|
-
if (file) {
|
|
121
|
-
file.data = {};
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
/** Export all files metadata as a DucExternalFiles record. */
|
|
127
|
-
toExternalFiles() {
|
|
128
|
-
const result = {};
|
|
129
|
-
if (this.buffer) {
|
|
130
|
-
for (const [id] of this.getMetadataMap()) {
|
|
131
|
-
const loaded = this.getFile(id);
|
|
132
|
-
if (loaded) {
|
|
133
|
-
const { data: _ } = loaded, file = __rest(loaded, ["data"]);
|
|
134
|
-
result[id] = file;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
for (const [id, loaded] of this.runtimeFiles) {
|
|
139
|
-
const { data: _ } = loaded, file = __rest(loaded, ["data"]);
|
|
140
|
-
result[id] = file;
|
|
141
|
-
}
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
/** Export all revision data blobs as an ExternalFilesData record. */
|
|
145
|
-
toExternalFilesData() {
|
|
146
|
-
const result = {};
|
|
147
|
-
if (this.buffer) {
|
|
148
|
-
for (const [id] of this.getMetadataMap()) {
|
|
149
|
-
const loaded = this.getFile(id);
|
|
150
|
-
if (loaded) {
|
|
151
|
-
for (const [revId, blob] of Object.entries(loaded.data)) {
|
|
152
|
-
result[revId] = blob;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
for (const [, loaded] of this.runtimeFiles) {
|
|
158
|
-
for (const [revId, blob] of Object.entries(loaded.data)) {
|
|
159
|
-
result[revId] = blob;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return result;
|
|
163
|
-
}
|
|
164
|
-
/** Merge files from another source. Adds missing files and merges new revisions into existing ones. */
|
|
165
|
-
mergeFiles(files, filesData) {
|
|
166
|
-
var _a, _b, _c;
|
|
167
|
-
for (const [id, file] of Object.entries(files)) {
|
|
168
|
-
const existing = (_a = this.runtimeFiles.get(id)) !== null && _a !== void 0 ? _a : this.getFile(id);
|
|
169
|
-
if (!existing) {
|
|
170
|
-
const dataMap = {};
|
|
171
|
-
if (filesData) {
|
|
172
|
-
for (const revId of Object.keys(file.revisions)) {
|
|
173
|
-
if (filesData[revId]) {
|
|
174
|
-
dataMap[revId] = filesData[revId];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
this.runtimeFiles.set(id, Object.assign(Object.assign({}, file), { data: dataMap }));
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
let merged = false;
|
|
182
|
-
const mergedRevisions = Object.assign({}, existing.revisions);
|
|
183
|
-
const mergedData = Object.assign({}, existing.data);
|
|
184
|
-
for (const [revId, rev] of Object.entries(file.revisions)) {
|
|
185
|
-
if (!mergedRevisions[revId]) {
|
|
186
|
-
mergedRevisions[revId] = rev;
|
|
187
|
-
if (filesData === null || filesData === void 0 ? void 0 : filesData[revId]) {
|
|
188
|
-
mergedData[revId] = filesData[revId];
|
|
189
|
-
}
|
|
190
|
-
merged = true;
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
if ((filesData === null || filesData === void 0 ? void 0 : filesData[revId]) && mergedData[revId] !== filesData[revId]) {
|
|
194
|
-
mergedData[revId] = filesData[revId];
|
|
195
|
-
merged = true;
|
|
196
|
-
}
|
|
197
|
-
if (rev.sizeBytes !== mergedRevisions[revId].sizeBytes ||
|
|
198
|
-
rev.lastRetrieved !== mergedRevisions[revId].lastRetrieved ||
|
|
199
|
-
rev.created !== mergedRevisions[revId].created ||
|
|
200
|
-
rev.mimeType !== mergedRevisions[revId].mimeType ||
|
|
201
|
-
rev.sourceName !== mergedRevisions[revId].sourceName ||
|
|
202
|
-
rev.message !== mergedRevisions[revId].message) {
|
|
203
|
-
mergedRevisions[revId] = rev;
|
|
204
|
-
merged = true;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
const activeRevisionChanged = file.activeRevisionId !== existing.activeRevisionId;
|
|
208
|
-
if (merged || activeRevisionChanged || file.updated > existing.updated) {
|
|
209
|
-
this.runtimeFiles.set(id, Object.assign(Object.assign({}, existing), { activeRevisionId: file.activeRevisionId, updated: Math.max(file.updated, existing.updated), version: Math.max((_b = file.version) !== null && _b !== void 0 ? _b : 0, (_c = existing.version) !== null && _c !== void 0 ? _c : 0), revisions: mergedRevisions, data: mergedData }));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
/** Release the underlying buffer to free memory. */
|
|
214
|
-
release() {
|
|
215
|
-
this.buffer = null;
|
|
216
|
-
this.metadataCache = null;
|
|
217
|
-
this.released = true;
|
|
218
|
-
}
|
|
219
|
-
getMetadataMap() {
|
|
220
|
-
if (!this.metadataCache) {
|
|
221
|
-
this.metadataCache = new Map();
|
|
222
|
-
if (this.buffer) {
|
|
223
|
-
const metas = wasmListExternalFiles(this.buffer);
|
|
224
|
-
if (metas) {
|
|
225
|
-
for (const meta of metas) {
|
|
226
|
-
this.metadataCache.set(meta.id, meta);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return this.metadataCache;
|
|
232
|
-
}
|
|
233
|
-
}
|