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/dist/wasm.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { applyDeltaChangeset as _applyDeltaChangeset, createDeltaChangeset as _createDeltaChangeset, getCurrentSchemaVersion as _getCurrentSchemaVersion, getExternalFile as _getExternalFile, listExternalFiles as _listExternalFiles, listVersions as _listVersions, parseDuc as _parseDuc, parseDucLazy as _parseDucLazy, readVersionGraph as _readVersionGraph, restoreCheckpoint as _restoreCheckpoint, restoreVersion as _restoreVersion, revertToVersion as _revertToVersion, serializeDuc as _serializeDuc } from "../dist/ducjs_wasm";
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.
@@ -7,16 +7,28 @@ export declare function ensureWasm(wasmUrl?: string | URL | BufferSource): Promi
7
7
  * without being able to resolve the file URL itself.
8
8
  */
9
9
  export declare function getWasmBinary(): Promise<ArrayBuffer>;
10
+ export declare const wasmGetCurrentSchemaVersion: typeof _getCurrentSchemaVersion;
11
+ export declare const wasmCreateDeltaChangeset: typeof _createDeltaChangeset;
12
+ export declare const wasmApplyDeltaChangeset: typeof _applyDeltaChangeset;
13
+ /**
14
+ * Low-level Origin Private File System (OPFS) SQLite document handle generated by WebAssembly.
15
+ *
16
+ * Provides high-performance, atomic read/write access to `.duc` binary databases inside browser OPFS storage
17
+ * using synchronous file access handles (`SyncAccessHandle`) and embedded WASM SQLite.
18
+ *
19
+ * @see {@link BrowserDucDocument} for the high-level idiomatic browser document API wrapper.
20
+ */
21
+ export declare const DucOpfsDocument: typeof _DucOpfsDocument;
22
+ /**
23
+ * Streaming importer handle generated by WebAssembly for writing chunked `.duc` data directly into OPFS storage.
24
+ *
25
+ * Allows high-throughput chunked stream ingestion without buffering full files into memory.
26
+ */
27
+ export declare const DucOpfsImporter: typeof _DucOpfsImporter;
10
28
  export declare const wasmParseDuc: typeof _parseDuc;
11
- export declare const wasmParseDucLazy: typeof _parseDucLazy;
12
29
  export declare const wasmSerializeDuc: typeof _serializeDuc;
13
- export declare const wasmGetExternalFile: typeof _getExternalFile;
14
- export declare const wasmListExternalFiles: typeof _listExternalFiles;
15
30
  export declare const wasmRestoreVersion: typeof _restoreVersion;
16
31
  export declare const wasmRestoreCheckpoint: typeof _restoreCheckpoint;
17
32
  export declare const wasmListVersions: typeof _listVersions;
18
33
  export declare const wasmReadVersionGraph: typeof _readVersionGraph;
19
34
  export declare const wasmRevertToVersion: typeof _revertToVersion;
20
- export declare const wasmGetCurrentSchemaVersion: typeof _getCurrentSchemaVersion;
21
- export declare const wasmCreateDeltaChangeset: typeof _createDeltaChangeset;
22
- export declare const wasmApplyDeltaChangeset: typeof _applyDeltaChangeset;
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, { applyDeltaChangeset as _applyDeltaChangeset, createDeltaChangeset as _createDeltaChangeset, getCurrentSchemaVersion as _getCurrentSchemaVersion, getExternalFile as _getExternalFile, listExternalFiles as _listExternalFiles, listVersions as _listVersions, parseDuc as _parseDuc, parseDucLazy as _parseDucLazy, readVersionGraph as _readVersionGraph, restoreCheckpoint as _restoreCheckpoint, restoreVersion as _restoreVersion, revertToVersion as _revertToVersion, serializeDuc as _serializeDuc, } from "../dist/ducjs_wasm";
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);
@@ -58,16 +58,29 @@ export function getWasmBinary() {
58
58
  return resp.arrayBuffer();
59
59
  });
60
60
  }
61
+ export const wasmGetCurrentSchemaVersion = _getCurrentSchemaVersion;
62
+ export const wasmCreateDeltaChangeset = _createDeltaChangeset;
63
+ export const wasmApplyDeltaChangeset = _applyDeltaChangeset;
64
+ /**
65
+ * Low-level Origin Private File System (OPFS) SQLite document handle generated by WebAssembly.
66
+ *
67
+ * Provides high-performance, atomic read/write access to `.duc` binary databases inside browser OPFS storage
68
+ * using synchronous file access handles (`SyncAccessHandle`) and embedded WASM SQLite.
69
+ *
70
+ * @see {@link BrowserDucDocument} for the high-level idiomatic browser document API wrapper.
71
+ */
72
+ export const DucOpfsDocument = _DucOpfsDocument;
73
+ /**
74
+ * Streaming importer handle generated by WebAssembly for writing chunked `.duc` data directly into OPFS storage.
75
+ *
76
+ * Allows high-throughput chunked stream ingestion without buffering full files into memory.
77
+ */
78
+ export const DucOpfsImporter = _DucOpfsImporter;
79
+ // Byte-buffer compatibility API
61
80
  export const wasmParseDuc = _parseDuc;
62
- export const wasmParseDucLazy = _parseDucLazy;
63
81
  export const wasmSerializeDuc = _serializeDuc;
64
- export const wasmGetExternalFile = _getExternalFile;
65
- export const wasmListExternalFiles = _listExternalFiles;
66
82
  export const wasmRestoreVersion = _restoreVersion;
67
83
  export const wasmRestoreCheckpoint = _restoreCheckpoint;
68
84
  export const wasmListVersions = _listVersions;
69
85
  export const wasmReadVersionGraph = _readVersionGraph;
70
86
  export const wasmRevertToVersion = _revertToVersion;
71
- export const wasmGetCurrentSchemaVersion = _getCurrentSchemaVersion;
72
- export const wasmCreateDeltaChangeset = _createDeltaChangeset;
73
- export const wasmApplyDeltaChangeset = _applyDeltaChangeset;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ducjs",
3
- "version": "3.5.1",
4
- "description": "The duc 2D CAD file format is a cornerstone of our advanced design system, conceived to cater to professionals seeking precision and efficiency in their design work.",
3
+ "version": "4.0.1",
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",
@@ -29,16 +29,22 @@
29
29
  },
30
30
  "scripts": {
31
31
  "build": "node scripts/build.js",
32
- "test": "bun run check-types",
32
+ "build:wasi": "node scripts/build.js --wasi",
33
+ "test": "bun test tests && bun run check-types",
33
34
  "check-types": "tsc --noEmit",
35
+ "gen:docs": "bunx typedoc",
36
+ "dev:docs": "bun run gen:docs && python3 -m http.server 8241 --directory docs",
34
37
  "semantic-release": "semantic-release"
35
38
  },
36
39
  "author": "Ducflair",
37
40
  "license": "MIT",
38
41
  "devDependencies": {
39
42
  "@types/bun": "latest",
43
+ "@types/node": "^22.10.0",
44
+ "@types/react": "^19.0.0",
40
45
  "@types/tinycolor2": "^1.4.6",
41
46
  "semantic-release": "^24.1.2",
47
+ "typedoc": "^0.27.9",
42
48
  "turbo": "^2.1.3",
43
49
  "typescript": "^5.8.3",
44
50
  "undici-types": "^6.21.0"
@@ -1,50 +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
- constructor(buffer: Uint8Array);
21
- get isReleased(): boolean;
22
- get size(): number;
23
- /** Check if a file with this ID exists. */
24
- has(fileId: string): boolean;
25
- /** Get metadata (without data blob) for a specific file. */
26
- getMetadata(fileId: string): LazyFileMetadata | undefined;
27
- /** Get metadata for all files. */
28
- getAllMetadata(): LazyFileMetadata[];
29
- /** Fetch the full file (including data blobs for all revisions) for a specific file. */
30
- getFile(fileId: string): ExternalFileLoaded | null;
31
- /** Get the active revision data for a specific file. */
32
- getFileData(fileId: string): ResolvedFileData | null;
33
- /** Fetch active revision data and return a copy of the data buffer (safe for transfer). */
34
- getFileDataCopy(fileId: string): ResolvedFileData | null;
35
- /** Add a file at runtime (not persisted in .duc until next serialize). */
36
- addRuntimeFile(fileId: string, file: DucExternalFile, data: Record<string, Uint8Array>): void;
37
- /** Remove a runtime file. */
38
- removeRuntimeFile(fileId: string): boolean;
39
- /** Unload a runtime file's data from memory while keeping metadata. */
40
- unloadRuntimeFileData(fileId: string): boolean;
41
- /** Export all files metadata as a DucExternalFiles record. */
42
- toExternalFiles(): DucExternalFiles;
43
- /** Export all revision data blobs as an ExternalFilesData record. */
44
- toExternalFilesData(): ExternalFilesData;
45
- /** Merge files from another source. Adds missing files and merges new revisions into existing ones. */
46
- mergeFiles(files: DucExternalFiles, filesData?: ExternalFilesData): void;
47
- /** Release the underlying buffer to free memory. */
48
- release(): void;
49
- private getMetadataMap;
50
- }
@@ -1,231 +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.buffer = buffer;
25
- }
26
- get isReleased() {
27
- return this.buffer === null;
28
- }
29
- get size() {
30
- return this.getMetadataMap().size + this.runtimeFiles.size;
31
- }
32
- /** Check if a file with this ID exists. */
33
- has(fileId) {
34
- return this.runtimeFiles.has(fileId) || this.getMetadataMap().has(fileId);
35
- }
36
- /** Get metadata (without data blob) for a specific file. */
37
- getMetadata(fileId) {
38
- const rt = this.runtimeFiles.get(fileId);
39
- if (rt) {
40
- const active = rt.revisions[rt.activeRevisionId];
41
- if (!active)
42
- return undefined;
43
- return {
44
- id: rt.id,
45
- mimeType: active.mimeType,
46
- created: active.created,
47
- lastRetrieved: active.lastRetrieved,
48
- version: rt.version,
49
- };
50
- }
51
- return this.getMetadataMap().get(fileId);
52
- }
53
- /** Get metadata for all files. */
54
- getAllMetadata() {
55
- const result = [];
56
- const persisted = this.getMetadataMap();
57
- for (const meta of persisted.values()) {
58
- result.push(meta);
59
- }
60
- for (const [id, file] of this.runtimeFiles) {
61
- if (!persisted.has(id)) {
62
- const active = file.revisions[file.activeRevisionId];
63
- if (active) {
64
- result.push({
65
- id: file.id,
66
- mimeType: active.mimeType,
67
- created: active.created,
68
- lastRetrieved: active.lastRetrieved,
69
- version: file.version,
70
- });
71
- }
72
- }
73
- }
74
- return result;
75
- }
76
- /** Fetch the full file (including data blobs for all revisions) for a specific file. */
77
- getFile(fileId) {
78
- const rt = this.runtimeFiles.get(fileId);
79
- if (rt)
80
- return rt;
81
- if (!this.buffer)
82
- return null;
83
- const result = wasmGetExternalFile(this.buffer, fileId);
84
- if (!result)
85
- return null;
86
- return result;
87
- }
88
- /** Get the active revision data for a specific file. */
89
- getFileData(fileId) {
90
- const loaded = this.getFile(fileId);
91
- if (!loaded)
92
- return null;
93
- const meta = loaded.revisions[loaded.activeRevisionId];
94
- if (!meta)
95
- return null;
96
- const dataBlob = loaded.data[loaded.activeRevisionId];
97
- if (!dataBlob)
98
- return null;
99
- return { data: dataBlob, mimeType: meta.mimeType };
100
- }
101
- /** Fetch active revision data and return a copy of the data buffer (safe for transfer). */
102
- getFileDataCopy(fileId) {
103
- const data = this.getFileData(fileId);
104
- if (!data)
105
- return null;
106
- return Object.assign(Object.assign({}, data), { data: new Uint8Array(data.data) });
107
- }
108
- /** Add a file at runtime (not persisted in .duc until next serialize). */
109
- addRuntimeFile(fileId, file, data) {
110
- this.runtimeFiles.set(fileId, Object.assign(Object.assign({}, file), { data }));
111
- }
112
- /** Remove a runtime file. */
113
- removeRuntimeFile(fileId) {
114
- return this.runtimeFiles.delete(fileId);
115
- }
116
- /** Unload a runtime file's data from memory while keeping metadata. */
117
- unloadRuntimeFileData(fileId) {
118
- const file = this.runtimeFiles.get(fileId);
119
- if (file) {
120
- file.data = {};
121
- return true;
122
- }
123
- return false;
124
- }
125
- /** Export all files metadata as a DucExternalFiles record. */
126
- toExternalFiles() {
127
- const result = {};
128
- if (this.buffer) {
129
- for (const [id] of this.getMetadataMap()) {
130
- const loaded = this.getFile(id);
131
- if (loaded) {
132
- const { data: _ } = loaded, file = __rest(loaded, ["data"]);
133
- result[id] = file;
134
- }
135
- }
136
- }
137
- for (const [id, loaded] of this.runtimeFiles) {
138
- const { data: _ } = loaded, file = __rest(loaded, ["data"]);
139
- result[id] = file;
140
- }
141
- return result;
142
- }
143
- /** Export all revision data blobs as an ExternalFilesData record. */
144
- toExternalFilesData() {
145
- const result = {};
146
- if (this.buffer) {
147
- for (const [id] of this.getMetadataMap()) {
148
- const loaded = this.getFile(id);
149
- if (loaded) {
150
- for (const [revId, blob] of Object.entries(loaded.data)) {
151
- result[revId] = blob;
152
- }
153
- }
154
- }
155
- }
156
- for (const [, loaded] of this.runtimeFiles) {
157
- for (const [revId, blob] of Object.entries(loaded.data)) {
158
- result[revId] = blob;
159
- }
160
- }
161
- return result;
162
- }
163
- /** Merge files from another source. Adds missing files and merges new revisions into existing ones. */
164
- mergeFiles(files, filesData) {
165
- var _a, _b, _c;
166
- for (const [id, file] of Object.entries(files)) {
167
- const existing = (_a = this.runtimeFiles.get(id)) !== null && _a !== void 0 ? _a : this.getFile(id);
168
- if (!existing) {
169
- const dataMap = {};
170
- if (filesData) {
171
- for (const revId of Object.keys(file.revisions)) {
172
- if (filesData[revId]) {
173
- dataMap[revId] = filesData[revId];
174
- }
175
- }
176
- }
177
- this.runtimeFiles.set(id, Object.assign(Object.assign({}, file), { data: dataMap }));
178
- continue;
179
- }
180
- let merged = false;
181
- const mergedRevisions = Object.assign({}, existing.revisions);
182
- const mergedData = Object.assign({}, existing.data);
183
- for (const [revId, rev] of Object.entries(file.revisions)) {
184
- if (!mergedRevisions[revId]) {
185
- mergedRevisions[revId] = rev;
186
- if (filesData === null || filesData === void 0 ? void 0 : filesData[revId]) {
187
- mergedData[revId] = filesData[revId];
188
- }
189
- merged = true;
190
- continue;
191
- }
192
- if ((filesData === null || filesData === void 0 ? void 0 : filesData[revId]) && mergedData[revId] !== filesData[revId]) {
193
- mergedData[revId] = filesData[revId];
194
- merged = true;
195
- }
196
- if (rev.sizeBytes !== mergedRevisions[revId].sizeBytes ||
197
- rev.lastRetrieved !== mergedRevisions[revId].lastRetrieved ||
198
- rev.created !== mergedRevisions[revId].created ||
199
- rev.mimeType !== mergedRevisions[revId].mimeType ||
200
- rev.sourceName !== mergedRevisions[revId].sourceName ||
201
- rev.message !== mergedRevisions[revId].message) {
202
- mergedRevisions[revId] = rev;
203
- merged = true;
204
- }
205
- }
206
- const activeRevisionChanged = file.activeRevisionId !== existing.activeRevisionId;
207
- if (merged || activeRevisionChanged || file.updated > existing.updated) {
208
- 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 }));
209
- }
210
- }
211
- }
212
- /** Release the underlying buffer to free memory. */
213
- release() {
214
- this.buffer = null;
215
- this.metadataCache = null;
216
- }
217
- getMetadataMap() {
218
- if (!this.metadataCache) {
219
- this.metadataCache = new Map();
220
- if (this.buffer) {
221
- const metas = wasmListExternalFiles(this.buffer);
222
- if (metas) {
223
- for (const meta of metas) {
224
- this.metadataCache.set(meta.id, meta);
225
- }
226
- }
227
- }
228
- }
229
- return this.metadataCache;
230
- }
231
- }