ducjs 4.0.1 → 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/dist/ducjs_wasm.js +2 -2
- package/dist/ducjs_wasm_bg.wasm +0 -0
- package/dist/opfs-import.d.ts +11 -0
- package/dist/opfs-import.js +54 -4
- package/package.json +1 -1
package/dist/ducjs_wasm.js
CHANGED
|
@@ -404,7 +404,7 @@ export function applyDeltaChangeset(base_state, changeset) {
|
|
|
404
404
|
return v3;
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
-
function
|
|
407
|
+
function __wbg_adapter_14(arg0, arg1, arg2) {
|
|
408
408
|
wasm.closure101_externref_shim(arg0, arg1, arg2);
|
|
409
409
|
}
|
|
410
410
|
|
|
@@ -1408,7 +1408,7 @@ function __wbg_get_imports() {
|
|
|
1408
1408
|
};
|
|
1409
1409
|
imports.wbg.__wbindgen_cast_9f0223d8557fdf20 = function(arg0, arg1) {
|
|
1410
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,
|
|
1411
|
+
const ret = makeMutClosure(arg0, arg1, 100, __wbg_adapter_14);
|
|
1412
1412
|
return ret;
|
|
1413
1413
|
};
|
|
1414
1414
|
imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
|
package/dist/ducjs_wasm_bg.wasm
CHANGED
|
Binary file
|
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();
|