ducjs 3.5.1 → 4.0.1

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 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">2D CAD File Format</p>
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 `duc` CAD file format. Built with SQLite and optimized for performance, this package enables you to parse, validate, and manipulate `duc` files with ease.
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
 
@@ -4,12 +4,39 @@
4
4
  * Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
5
5
  */
6
6
  export function parseDuc(buf: Uint8Array): any;
7
+ /**
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;
7
15
  /**
8
16
  * Restore a specific checkpoint by its ID from a `.duc` file buffer.
9
- *
10
- * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
11
17
  */
12
18
  export function restoreCheckpoint(duc_buf: Uint8Array, checkpoint_id: string): any;
19
+ /**
20
+ * List all versions (checkpoints + deltas) from a `.duc` file buffer.
21
+ */
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;
31
+ /**
32
+ * Returns the current version-control schema version defined in Rust.
33
+ *
34
+ * TypeScript should use this as the source of truth instead of hardcoding
35
+ * its own constant. When this value is bumped in Rust, the version control
36
+ * system will automatically handle migration bookkeeping (closing old chains,
37
+ * recording migrations) the next time a checkpoint or delta is created.
38
+ */
39
+ export function getCurrentSchemaVersion(): number;
13
40
  /**
14
41
  * Compute a checkpoint-relative binary diff changeset using bsdiff.
15
42
  *
@@ -21,12 +48,6 @@ export function restoreCheckpoint(duc_buf: Uint8Array, checkpoint_id: string): a
21
48
  * offsets, which is critical for SQLite databases.
22
49
  */
23
50
  export function createDeltaChangeset(base_state: Uint8Array, current_state: Uint8Array): Uint8Array;
24
- /**
25
- * Fetch a single external file from a `.duc` buffer by file ID.
26
- *
27
- * Returns the file entry as a JS object, or `undefined` if not found.
28
- */
29
- export function getExternalFile(buf: Uint8Array, file_id: string): any;
30
51
  /**
31
52
  * Apply a changeset to reconstruct document state.
32
53
  *
@@ -37,70 +58,149 @@ export function getExternalFile(buf: Uint8Array, file_id: string): any;
37
58
  * - v3 (bsdiff), v2 (XOR diff), v1 (gzip full snapshot)
38
59
  */
39
60
  export function applyDeltaChangeset(base_state: Uint8Array, changeset: Uint8Array): Uint8Array;
61
+ export class DucOpfsDocument {
62
+ private constructor();
63
+ free(): void;
64
+ [Symbol.dispose](): void;
65
+ static openInPool(name: string, namespace: string): Promise<DucOpfsDocument>;
66
+ /**
67
+ * Read a chunk from the SQLite database backing this OPFS document.
68
+ *
69
+ * Call [`checkpointWal`] first so the main database file contains all
70
+ * committed data. JavaScript can gzip successive chunks without loading
71
+ * the whole database into WASM memory.
72
+ */
73
+ exportDbChunk(offset_bytes: number, length: number): Promise<Uint8Array>;
74
+ static listOpfsDatabases(): Promise<any>;
75
+ static deleteOpfsDatabase(name: string): Promise<boolean>;
76
+ static listOpfsDatabasesInPool(namespace: string): Promise<any>;
77
+ static deleteOpfsDatabaseInPool(name: string, namespace: string): Promise<boolean>;
78
+ /**
79
+ * Open or create a persistent OPFS-backed DUC SQLite document.
80
+ *
81
+ * This must run from a Dedicated Worker because the OPFS SAH-pool VFS uses
82
+ * FileSystemSyncAccessHandle.
83
+ */
84
+ static open(name: string): Promise<DucOpfsDocument>;
85
+ /**
86
+ * Return the filename used to open this document.
87
+ */
88
+ getFilename(): string;
89
+ /**
90
+ * Execute an arbitrary SQL batch (e.g. `VACUUM INTO 'export.sqlite'`).
91
+ */
92
+ executeBatch(sql: string): void;
93
+ listVersions(): any;
94
+ /**
95
+ * Flush the WAL journal into the main database file.
96
+ *
97
+ * After calling this, the OPFS file backing this document contains
98
+ * all committed data. JavaScript can then read the file directly
99
+ * from OPFS in chunks and gzip-compress it.
100
+ */
101
+ checkpointWal(): void;
102
+ /**
103
+ * Return the estimated database file size in bytes
104
+ * (`page_count × page_size`). Call [`checkpoint_wal`] first for
105
+ * an accurate value.
106
+ */
107
+ getDbSizeBytes(): number;
108
+ readVersionGraph(): any;
109
+ listExternalFiles(): any;
110
+ readDocumentState(): any;
111
+ writeDocumentState(data: any): void;
112
+ readCheckpointDataChunk(checkpoint_id: string, chunk_index: number): any;
113
+ readDeltaChangesetChunk(delta_id: string, chunk_index: number): any;
114
+ writeCheckpointDataChunk(checkpoint_id: string, chunk_index: number, offset_bytes: number, data: Uint8Array): void;
115
+ writeDeltaChangesetChunk(delta_id: string, chunk_index: number, offset_bytes: number, data: Uint8Array): void;
116
+ clearCheckpointDataChunks(checkpoint_id: string): void;
117
+ clearDeltaChangesetChunks(delta_id: string): void;
118
+ readExternalFileRevisionChunk(revision_id: string, chunk_index: number): any;
119
+ /**
120
+ * Read a bounded byte range, including from legacy one-row BLOB revisions.
121
+ */
122
+ readExternalFileRevisionRange(revision_id: string, offset_bytes: number, length_bytes: number): any;
123
+ /**
124
+ * Read a bounded batch of external-file chunks with one SQL query and one
125
+ * JS/WASM call. Batches are capped at 4 chunks to bound peak memory.
126
+ */
127
+ readExternalFileRevisionChunks(revision_id: string, start_chunk_index: number, max_chunks: number): Array<any>;
128
+ writeExternalFileRevisionChunk(revision_id: string, chunk_index: number, offset_bytes: number, data: Uint8Array): void;
129
+ clearExternalFileRevisionChunks(revision_id: string): void;
130
+ }
40
131
  /**
41
- * List metadata for all external files (without loading the heavy data blobs).
42
- */
43
- export function listExternalFiles(buf: Uint8Array): any;
44
- /**
45
- * Read the full VersionGraph from a `.duc` file buffer.
46
- *
47
- * Returns a JS object matching the `VersionGraph` TypeScript interface,
48
- * or `undefined` if no version graph exists.
49
- */
50
- export function readVersionGraph(duc_buf: Uint8Array): any;
51
- /**
52
- * List all versions (checkpoints + deltas) from a `.duc` file buffer.
53
- *
54
- * Returns a JS array of `VersionEntry` objects (no heavy data blobs).
55
- */
56
- export function listVersions(duc_buf: Uint8Array): any;
57
- /**
58
- * Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
59
- *
60
- * Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
61
- */
62
- export function parseDucLazy(buf: Uint8Array): any;
63
- /**
64
- * Restore the document state at `version_number` from a `.duc` file buffer.
65
- *
66
- * The `.duc` file is a SQLite database — this function opens it and queries
67
- * the `checkpoints` / `deltas` tables directly for version restoration.
68
- *
69
- * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
70
- */
71
- export function restoreVersion(duc_buf: Uint8Array, version_number: number): any;
72
- /**
73
- * Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
74
- */
75
- export function serializeDuc(data: any): Uint8Array;
76
- /**
77
- * Returns the current version-control schema version defined in Rust.
78
- *
79
- * TypeScript should use this as the source of truth instead of hardcoding
80
- * its own constant. When this value is bumped in Rust, the version control
81
- * system will automatically handle migration bookkeeping (closing old chains,
82
- * recording migrations) the next time a checkpoint or delta is created.
83
- */
84
- export function getCurrentSchemaVersion(): number;
85
- /**
86
- * Revert the document to a specific version, removing all newer versions.
87
- *
88
- * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
132
+ * Incrementally replaces one OPFS database without retaining the imported
133
+ * SQLite payload in WASM memory.
89
134
  */
90
- export function revertToVersion(duc_buf: Uint8Array, target_version: number): any;
135
+ export class DucOpfsImporter {
136
+ private constructor();
137
+ free(): void;
138
+ [Symbol.dispose](): void;
139
+ static beginInPool(name: string, namespace: string): Promise<DucOpfsImporter>;
140
+ /**
141
+ * Begin replacing `name`. Any prior database with the same closed name is
142
+ * released back to the SAH pool before the new import claims a slot.
143
+ */
144
+ static begin(name: string): Promise<DucOpfsImporter>;
145
+ /**
146
+ * Write the next decompressed SQLite chunk.
147
+ */
148
+ writeChunk(data: Uint8Array): void;
149
+ getBytesWritten(): number;
150
+ /**
151
+ * Delete a partial import. Safe to call after a failed stream read.
152
+ */
153
+ abort(): boolean;
154
+ /**
155
+ * Flush the imported database and make it ready for SQLite to open.
156
+ */
157
+ finish(): number;
158
+ }
91
159
 
92
160
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
93
161
 
94
162
  export interface InitOutput {
95
163
  readonly memory: WebAssembly.Memory;
164
+ readonly __wbg_ducopfsdocument_free: (a: number, b: number) => void;
165
+ readonly __wbg_ducopfsimporter_free: (a: number, b: number) => void;
96
166
  readonly applyDeltaChangeset: (a: number, b: number, c: number, d: number) => [number, number, number, number];
97
167
  readonly createDeltaChangeset: (a: number, b: number, c: number, d: number) => [number, number, number, number];
168
+ readonly ducopfsdocument_checkpointWal: (a: number) => [number, number];
169
+ readonly ducopfsdocument_clearCheckpointDataChunks: (a: number, b: number, c: number) => [number, number];
170
+ readonly ducopfsdocument_clearDeltaChangesetChunks: (a: number, b: number, c: number) => [number, number];
171
+ readonly ducopfsdocument_clearExternalFileRevisionChunks: (a: number, b: number, c: number) => [number, number];
172
+ readonly ducopfsdocument_deleteOpfsDatabase: (a: number, b: number) => any;
173
+ readonly ducopfsdocument_deleteOpfsDatabaseInPool: (a: number, b: number, c: number, d: number) => any;
174
+ readonly ducopfsdocument_executeBatch: (a: number, b: number, c: number) => [number, number];
175
+ readonly ducopfsdocument_exportDbChunk: (a: number, b: number, c: number) => any;
176
+ readonly ducopfsdocument_getDbSizeBytes: (a: number) => [number, number, number];
177
+ readonly ducopfsdocument_getFilename: (a: number) => [number, number];
178
+ readonly ducopfsdocument_listExternalFiles: (a: number) => [number, number, number];
179
+ readonly ducopfsdocument_listOpfsDatabases: () => any;
180
+ readonly ducopfsdocument_listOpfsDatabasesInPool: (a: number, b: number) => any;
181
+ readonly ducopfsdocument_listVersions: (a: number) => [number, number, number];
182
+ readonly ducopfsdocument_open: (a: number, b: number) => any;
183
+ readonly ducopfsdocument_openInPool: (a: number, b: number, c: number, d: number) => any;
184
+ readonly ducopfsdocument_readCheckpointDataChunk: (a: number, b: number, c: number, d: number) => [number, number, number];
185
+ readonly ducopfsdocument_readDeltaChangesetChunk: (a: number, b: number, c: number, d: number) => [number, number, number];
186
+ readonly ducopfsdocument_readDocumentState: (a: number) => [number, number, number];
187
+ readonly ducopfsdocument_readExternalFileRevisionChunk: (a: number, b: number, c: number, d: number) => [number, number, number];
188
+ readonly ducopfsdocument_readExternalFileRevisionChunks: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
189
+ readonly ducopfsdocument_readExternalFileRevisionRange: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
190
+ readonly ducopfsdocument_readVersionGraph: (a: number) => [number, number, number];
191
+ readonly ducopfsdocument_writeCheckpointDataChunk: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
192
+ readonly ducopfsdocument_writeDeltaChangesetChunk: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
193
+ readonly ducopfsdocument_writeDocumentState: (a: number, b: any) => [number, number];
194
+ readonly ducopfsdocument_writeExternalFileRevisionChunk: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
195
+ readonly ducopfsimporter_abort: (a: number) => [number, number, number];
196
+ readonly ducopfsimporter_begin: (a: number, b: number) => any;
197
+ readonly ducopfsimporter_beginInPool: (a: number, b: number, c: number, d: number) => any;
198
+ readonly ducopfsimporter_finish: (a: number) => [number, number, number];
199
+ readonly ducopfsimporter_getBytesWritten: (a: number) => number;
200
+ readonly ducopfsimporter_writeChunk: (a: number, b: number, c: number) => [number, number];
98
201
  readonly getCurrentSchemaVersion: () => number;
99
- readonly getExternalFile: (a: number, b: number, c: number, d: number) => [number, number, number];
100
- readonly listExternalFiles: (a: number, b: number) => [number, number, number];
101
202
  readonly listVersions: (a: number, b: number) => [number, number, number];
102
203
  readonly parseDuc: (a: number, b: number) => [number, number, number];
103
- readonly parseDucLazy: (a: number, b: number) => [number, number, number];
104
204
  readonly readVersionGraph: (a: number, b: number) => [number, number, number];
105
205
  readonly restoreCheckpoint: (a: number, b: number, c: number, d: number) => [number, number, number];
106
206
  readonly restoreVersion: (a: number, b: number, c: number) => [number, number, number];
@@ -121,8 +221,11 @@ export interface InitOutput {
121
221
  readonly __wbindgen_exn_store: (a: number) => void;
122
222
  readonly __externref_table_alloc: () => number;
123
223
  readonly __wbindgen_export_4: WebAssembly.Table;
124
- readonly __externref_table_dealloc: (a: number) => void;
125
224
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
225
+ readonly __wbindgen_export_6: WebAssembly.Table;
226
+ readonly __externref_table_dealloc: (a: number) => void;
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;
126
229
  readonly __wbindgen_start: () => void;
127
230
  }
128
231