core-3nweb-client-lib 0.27.4 → 0.27.6
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/build/api-defs/files.d.ts +40 -10
- package/build/core/asmail/delivery/per-recipient-wip.js +2 -2
- package/build/core/asmail/inbox/inbox-events.js +10 -5
- package/build/core/asmail/inbox/index.d.ts +3 -2
- package/build/core/asmail/inbox/index.js +14 -10
- package/build/core/asmail/inbox/msg-indexing.d.ts +17 -64
- package/build/core/asmail/inbox/msg-indexing.js +440 -311
- package/build/core/asmail/inbox/msg-on-disk.js +2 -1
- package/build/core/asmail/index.js +3 -2
- package/build/core/asmail/keyring/correspondent-keys.js +3 -1
- package/build/core/asmail/keyring/index.d.ts +1 -4
- package/build/core/asmail/keyring/index.js +6 -6
- package/build/core/asmail/msg/opener.js +4 -3
- package/build/core/asmail/msg/packer.d.ts +1 -0
- package/build/core/asmail/msg/packer.js +8 -4
- package/build/core/index.js +2 -3
- package/build/core/storage/local/obj-files.js +2 -1
- package/build/core/storage/synced/storage.js +3 -2
- package/build/core/storage/synced/upload-header-file.js +4 -2
- package/build/core/storage/synced/upsyncer.js +3 -5
- package/build/ipc-via-protobuf/asmail-cap.js +14 -15
- package/build/ipc-via-protobuf/bytes.js +42 -18
- package/build/ipc-via-protobuf/file.js +43 -39
- package/build/ipc-via-protobuf/fs.js +72 -67
- package/build/ipc-via-protobuf/mailerid.js +2 -2
- package/build/ipc-via-protobuf/protobuf-msg.d.ts +1 -0
- package/build/ipc-via-protobuf/protobuf-msg.js +5 -1
- package/build/ipc-via-protobuf/startup-cap.js +8 -8
- package/build/ipc-via-protobuf/storage-cap.js +4 -4
- package/build/ipc.d.ts +1 -0
- package/build/ipc.js +3 -1
- package/build/lib-client/3nstorage/xsp-fs/common.js +2 -0
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +0 -17
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +13 -7
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/fs.js +1 -1
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +2 -2
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +7 -3
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +7 -5
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +3 -4
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +20 -15
- package/build/lib-client/cryptor/cryptor-in-worker.js +37 -47
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-js.js +15 -12
- package/build/lib-client/cryptor/in-proc-wasm.js +11 -8
- package/build/lib-client/cryptor/serialization-for-wasm.d.ts +36 -0
- package/build/lib-client/cryptor/serialization-for-wasm.js +58 -0
- package/build/lib-client/cryptor-work-labels.d.ts +26 -0
- package/build/lib-client/cryptor-work-labels.js +152 -0
- package/build/lib-client/fs-sync-utils.d.ts +7 -1
- package/build/lib-client/fs-sync-utils.js +18 -7
- package/build/lib-client/local-files/dev-file-src.d.ts +2 -1
- package/build/lib-client/local-files/dev-file-src.js +5 -1
- package/build/lib-client/local-files/device-fs.js +2 -1
- package/build/lib-client/objs-on-disk/obj-on-disk.js +5 -1
- package/build/lib-client/request-utils.js +14 -14
- package/build/lib-common/async-cryptor-wrap.d.ts +9 -9
- package/build/lib-common/async-cryptor-wrap.js +13 -13
- package/build/lib-common/byte-streaming/pipe.d.ts +1 -1
- package/build/lib-common/byte-streaming/pipe.js +3 -3
- package/build/lib-common/byte-streaming/wrapping.js +4 -2
- package/build/lib-common/json-utils.js +0 -3
- package/build/lib-common/processes/synced.js +0 -184
- package/build/lib-sqlite-on-3nstorage/index.d.ts +32 -0
- package/build/lib-sqlite-on-3nstorage/index.js +117 -0
- package/build/lib-sqlite-on-3nstorage/sqljs.d.ts +279 -0
- package/build/lib-sqlite-on-3nstorage/sqljs.js +223 -0
- package/build/protos/asmail.proto.js +3748 -1121
- package/build/protos/bytes.proto.js +731 -204
- package/build/protos/common.proto.js +192 -44
- package/build/protos/cryptor.proto.js +184 -61
- package/build/protos/file.proto.js +1336 -324
- package/build/protos/fs.proto.js +3099 -846
- package/build/protos/ipc.proto.js +244 -61
- package/build/protos/logger.proto.js +219 -53
- package/build/protos/mailerid.proto.js +230 -50
- package/build/protos/startup.proto.js +341 -77
- package/build/protos/storage.proto.js +276 -62
- package/package.json +8 -7
- package/protos/bytes.proto +13 -4
- package/protos/file.proto +4 -1
- package/protos/fs.proto +4 -1
|
@@ -11,5 +11,5 @@ declare type FileByteSink = web3n.files.FileByteSink;
|
|
|
11
11
|
* @param bufSize is an optional parameter for buffer, used for byte transfer.
|
|
12
12
|
* Default value is 64K.
|
|
13
13
|
*/
|
|
14
|
-
export declare function pipe(src: FileByteSource, sink: FileByteSink, progressCB?: ((bytesPiped: number) => void)
|
|
14
|
+
export declare function pipe(src: FileByteSource, sink: FileByteSink, progressCB?: ((bytesPiped: number) => void), closeSink?: boolean, bufSize?: number): Promise<number>;
|
|
15
15
|
export {};
|
|
@@ -28,10 +28,10 @@ const sink_utils_1 = require("../obj-streaming/sink-utils");
|
|
|
28
28
|
* @param bufSize is an optional parameter for buffer, used for byte transfer.
|
|
29
29
|
* Default value is 64K.
|
|
30
30
|
*/
|
|
31
|
-
async function pipe(src, sink, progressCB
|
|
31
|
+
async function pipe(src, sink, progressCB, closeSink = true, bufSize = 64 * 1024) {
|
|
32
32
|
const contSink = (0, sink_utils_1.makeContinuousSink)(sink);
|
|
33
33
|
try {
|
|
34
|
-
let buf = await src.
|
|
34
|
+
let buf = await src.readNext(bufSize);
|
|
35
35
|
let bytesPiped = 0;
|
|
36
36
|
while (buf) {
|
|
37
37
|
await contSink(buf);
|
|
@@ -39,7 +39,7 @@ async function pipe(src, sink, progressCB = undefined, closeSink = true, bufSize
|
|
|
39
39
|
if (progressCB) {
|
|
40
40
|
progressCB(bytesPiped);
|
|
41
41
|
}
|
|
42
|
-
buf = await src.
|
|
42
|
+
buf = await src.readNext(bufSize);
|
|
43
43
|
}
|
|
44
44
|
if (closeSink) {
|
|
45
45
|
await contSink(null);
|
|
@@ -35,7 +35,8 @@ function wrapAndSyncSource(src) {
|
|
|
35
35
|
const w = {
|
|
36
36
|
getPosition: (0, synced_1.makeSyncedFunc)(syncProc, src, src.getPosition),
|
|
37
37
|
getSize: (0, synced_1.makeSyncedFunc)(syncProc, src, src.getSize),
|
|
38
|
-
|
|
38
|
+
readNext: (0, synced_1.makeSyncedFunc)(syncProc, src, src.readNext),
|
|
39
|
+
readAt: (0, synced_1.makeSyncedFunc)(syncProc, src, src.readAt),
|
|
39
40
|
seek: (0, synced_1.makeSyncedFunc)(syncProc, src, src.seek)
|
|
40
41
|
};
|
|
41
42
|
return w;
|
|
@@ -46,7 +47,8 @@ function wrapAndSyncFileSource(src) {
|
|
|
46
47
|
const w = {
|
|
47
48
|
getPosition: (0, synced_1.makeSyncedFunc)(syncProc, src, src.getPosition),
|
|
48
49
|
getSize: (0, synced_1.makeSyncedFunc)(syncProc, src, src.getSize),
|
|
49
|
-
|
|
50
|
+
readNext: (0, synced_1.makeSyncedFunc)(syncProc, src, src.readNext),
|
|
51
|
+
readAt: (0, synced_1.makeSyncedFunc)(syncProc, src, src.readAt),
|
|
50
52
|
seek: (0, synced_1.makeSyncedFunc)(syncProc, src, src.seek),
|
|
51
53
|
};
|
|
52
54
|
return w;
|
|
@@ -158,49 +158,6 @@ class SingleProc {
|
|
|
158
158
|
exports.SingleProc = SingleProc;
|
|
159
159
|
Object.freeze(SingleProc.prototype);
|
|
160
160
|
Object.freeze(SingleProc);
|
|
161
|
-
// export class DeduppedRunner<T> {
|
|
162
|
-
// private proc: Promise<T>|undefined = undefined;
|
|
163
|
-
// private waiting: Deferred<T>|undefined = undefined;
|
|
164
|
-
// constructor(
|
|
165
|
-
// private readonly action: Action<T>
|
|
166
|
-
// ) {
|
|
167
|
-
// Object.seal(this);
|
|
168
|
-
// }
|
|
169
|
-
// trigger(): Promise<T> {
|
|
170
|
-
// if (this.proc) {
|
|
171
|
-
// if (!this.waiting) {
|
|
172
|
-
// this.waiting = defer();
|
|
173
|
-
// }
|
|
174
|
-
// return this.waiting.promise;
|
|
175
|
-
// } else {
|
|
176
|
-
// this.proc = this.startAction();
|
|
177
|
-
// return this.proc;
|
|
178
|
-
// }
|
|
179
|
-
// }
|
|
180
|
-
// private async startAction(): Promise<T> {
|
|
181
|
-
// const deferredBeforeStart = this.waiting;
|
|
182
|
-
// this.waiting = undefined;
|
|
183
|
-
// try {
|
|
184
|
-
// const result = await this.action();
|
|
185
|
-
// if (deferredBeforeStart) {
|
|
186
|
-
// deferredBeforeStart.resolve(result);
|
|
187
|
-
// }
|
|
188
|
-
// return result;
|
|
189
|
-
// } catch (err) {
|
|
190
|
-
// if (deferredBeforeStart) {
|
|
191
|
-
// deferredBeforeStart.reject(err);
|
|
192
|
-
// }
|
|
193
|
-
// throw err;
|
|
194
|
-
// } finally {
|
|
195
|
-
// this.proc = undefined;
|
|
196
|
-
// if (this.waiting) {
|
|
197
|
-
// this.proc = this.startAction();
|
|
198
|
-
// }
|
|
199
|
-
// }
|
|
200
|
-
// }
|
|
201
|
-
// }
|
|
202
|
-
// Object.freeze(DeduppedRunner.prototype);
|
|
203
|
-
// Object.freeze(DeduppedRunner);
|
|
204
161
|
/**
|
|
205
162
|
* This wraps given function/method into syncing wrap.
|
|
206
163
|
*/
|
|
@@ -208,145 +165,4 @@ function makeSyncedFunc(syncProc, thisArg, func) {
|
|
|
208
165
|
return ((...args) => syncProc.startOrChain(() => func.apply(thisArg, args)));
|
|
209
166
|
}
|
|
210
167
|
exports.makeSyncedFunc = makeSyncedFunc;
|
|
211
|
-
// export interface Deferred<T> {
|
|
212
|
-
// promise: Promise<T>;
|
|
213
|
-
// resolve: (result?: T|PromiseLike<T>) => void;
|
|
214
|
-
// reject: (err: any) => void;
|
|
215
|
-
// }
|
|
216
|
-
// export function defer<T>(): Deferred<T> {
|
|
217
|
-
// const d = <Deferred<T>> {};
|
|
218
|
-
// d.promise = new Promise<T>((resolve, reject) => {
|
|
219
|
-
// d.resolve = resolve;
|
|
220
|
-
// d.reject = reject;
|
|
221
|
-
// });
|
|
222
|
-
// Object.freeze(d);
|
|
223
|
-
// return d;
|
|
224
|
-
// }
|
|
225
|
-
// export class PressureValve {
|
|
226
|
-
// private stopper: Deferred<void>|undefined = undefined;
|
|
227
|
-
// constructor() {
|
|
228
|
-
// Object.seal(this);
|
|
229
|
-
// }
|
|
230
|
-
// toggle(flag: boolean): void {
|
|
231
|
-
// if (flag) {
|
|
232
|
-
// if (this.stopper) { return; }
|
|
233
|
-
// this.stopper = defer();
|
|
234
|
-
// } else {
|
|
235
|
-
// if (!this.stopper) { return; }
|
|
236
|
-
// this.stopper.resolve();
|
|
237
|
-
// this.stopper = undefined;
|
|
238
|
-
// }
|
|
239
|
-
// }
|
|
240
|
-
// pressWithError(err: any): void {
|
|
241
|
-
// this.toggle(true);
|
|
242
|
-
// this.stopper!.reject(errWithCause(err, `Backpressure error`));
|
|
243
|
-
// }
|
|
244
|
-
// readonly pressure = async (): Promise<void> => {
|
|
245
|
-
// if (!this.stopper) { return; }
|
|
246
|
-
// await this.stopper.promise;
|
|
247
|
-
// }
|
|
248
|
-
// }
|
|
249
|
-
// Object.freeze(PressureValve.prototype);
|
|
250
|
-
// Object.freeze(PressureValve);
|
|
251
|
-
// export function callWithTimeout<T>(
|
|
252
|
-
// f: () => Promise<T>, timeout: number, timeoutErr: () => any
|
|
253
|
-
// ): Promise<T> {
|
|
254
|
-
// let isDone = false;
|
|
255
|
-
// const deferred = defer<T>();
|
|
256
|
-
// f().then(res => {
|
|
257
|
-
// if (isDone) { return; }
|
|
258
|
-
// isDone = true;
|
|
259
|
-
// deferred.resolve(res);
|
|
260
|
-
// }, err => {
|
|
261
|
-
// if (isDone) { return; }
|
|
262
|
-
// isDone = true;
|
|
263
|
-
// deferred.reject(err);
|
|
264
|
-
// });
|
|
265
|
-
// sleep(timeout).then(() => {
|
|
266
|
-
// if (isDone) { return; }
|
|
267
|
-
// isDone = true;
|
|
268
|
-
// const err = timeoutErr();
|
|
269
|
-
// if (err) {
|
|
270
|
-
// deferred.reject(err);
|
|
271
|
-
// }
|
|
272
|
-
// });
|
|
273
|
-
// return deferred.promise;
|
|
274
|
-
// }
|
|
275
|
-
// export interface WorkerTask<WorkerLabel extends string> {
|
|
276
|
-
// neededWorker(): WorkerLabel|undefined;
|
|
277
|
-
// process(): Promise<void>;
|
|
278
|
-
// cancel(): Promise<void>;
|
|
279
|
-
// }
|
|
280
|
-
// interface Worker {
|
|
281
|
-
// readonly procs: Promise<void>[];
|
|
282
|
-
// readonly maxProcs: number;
|
|
283
|
-
// }
|
|
284
|
-
// export class QueueAndWorkers<WorkerLabel extends string> {
|
|
285
|
-
// private readonly queue: WorkerTask<WorkerLabel>[] = [];
|
|
286
|
-
// private readonly workers = new Map<WorkerLabel, Worker>();
|
|
287
|
-
// // private readonly set = new Set<WorkerTask>();
|
|
288
|
-
// private isRunning = false;
|
|
289
|
-
// // private readonly procs: Promise<void>[] = [];
|
|
290
|
-
// // private maxProcs = 1;
|
|
291
|
-
// constructor() {
|
|
292
|
-
// Object.seal(this);
|
|
293
|
-
// }
|
|
294
|
-
// add(w: WorkerTask<WorkerLabel>, queueIfNotRunning = false): void {
|
|
295
|
-
// if (this.isRunning) {
|
|
296
|
-
// this.queue.push();
|
|
297
|
-
// this.processNextQueued();
|
|
298
|
-
// } else if (queueIfNotRunning) {
|
|
299
|
-
// this.addToQueueOnce(w);
|
|
300
|
-
// }
|
|
301
|
-
// }
|
|
302
|
-
// private addToQueueOnce(w: WorkerTask<WorkerLabel>): void {
|
|
303
|
-
// if (!this.set.has(w)) {
|
|
304
|
-
// this.queue.push(w);
|
|
305
|
-
// this.set.add(w);
|
|
306
|
-
// }
|
|
307
|
-
// }
|
|
308
|
-
// private getFromQueueHead(): WorkerTask<WorkerLabel>|undefined {
|
|
309
|
-
// const w = this.queue.shift();
|
|
310
|
-
// if (!w) { return; }
|
|
311
|
-
// this.set.delete(w);
|
|
312
|
-
// return w;
|
|
313
|
-
// }
|
|
314
|
-
// private async processNextQueued(): Promise<void> {
|
|
315
|
-
// if (!this.isRunning || (this.procs.length >= this.maxProcs)) { return; }
|
|
316
|
-
// const w = this.getFromQueueHead();
|
|
317
|
-
// if (!w) { return; }
|
|
318
|
-
// const proc = w.process();
|
|
319
|
-
// this.procs.push(proc);
|
|
320
|
-
// try {
|
|
321
|
-
// await proc;
|
|
322
|
-
// } finally {
|
|
323
|
-
// const i = this.procs.indexOf(proc);
|
|
324
|
-
// if (i >= 0) {
|
|
325
|
-
// this.procs.splice(i, 1);
|
|
326
|
-
// }
|
|
327
|
-
// this.processNextQueued();
|
|
328
|
-
// }
|
|
329
|
-
// }
|
|
330
|
-
// start(maxNumOfProcs = 1): void {
|
|
331
|
-
// this.maxProcs = maxNumOfProcs;
|
|
332
|
-
// this.isRunning = true;
|
|
333
|
-
// this.processNextQueued();
|
|
334
|
-
// }
|
|
335
|
-
// pause(): void {
|
|
336
|
-
// this.isRunning = false;
|
|
337
|
-
// }
|
|
338
|
-
// async stop(): Promise<void> {
|
|
339
|
-
// this.isRunning = false;
|
|
340
|
-
// const queue = this.queue.splice(0, this.queue.length);
|
|
341
|
-
// this.set.clear();
|
|
342
|
-
// for (const w of queue) {
|
|
343
|
-
// await w.cancel();
|
|
344
|
-
// }
|
|
345
|
-
// while (this.procs.length > 0) {
|
|
346
|
-
// await this.procs.pop();
|
|
347
|
-
// }
|
|
348
|
-
// }
|
|
349
|
-
// }
|
|
350
|
-
// Object.freeze(Worker.prototype);
|
|
351
|
-
// Object.freeze(Worker);
|
|
352
168
|
Object.freeze(exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Action, SingleProc } from '../lib-common/processes/synced';
|
|
2
|
+
import { Database as DBClass, BindParams as QueryParams, QueryExecResult as QueryResult } from './sqljs';
|
|
3
|
+
export declare type Database = DBClass;
|
|
4
|
+
export declare type BindParams = QueryParams;
|
|
5
|
+
export declare type QueryExecResult = QueryResult;
|
|
6
|
+
declare type WritableFile = web3n.files.WritableFile;
|
|
7
|
+
declare type ReadonlyFile = web3n.files.ReadonlyFile;
|
|
8
|
+
export declare abstract class SQLiteOn3NStorage {
|
|
9
|
+
protected readonly database: Database;
|
|
10
|
+
protected readonly file: WritableFile;
|
|
11
|
+
protected readonly syncProc: SingleProc;
|
|
12
|
+
protected constructor(database: Database, file: WritableFile);
|
|
13
|
+
get db(): Database;
|
|
14
|
+
get dbFile(): WritableFile;
|
|
15
|
+
sync<T>(action: Action<T>): Promise<T>;
|
|
16
|
+
listTables(): string[];
|
|
17
|
+
}
|
|
18
|
+
export declare class SQLiteOnUnversionedFS extends SQLiteOn3NStorage {
|
|
19
|
+
static makeAndStart(file: WritableFile): Promise<SQLiteOnUnversionedFS>;
|
|
20
|
+
saveToFile(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare class SQLiteOnVersionedFS extends SQLiteOn3NStorage {
|
|
23
|
+
protected constructor(db: Database, file: WritableFile);
|
|
24
|
+
static makeAndStart(file: WritableFile): Promise<SQLiteOnVersionedFS>;
|
|
25
|
+
saveToFile(): Promise<number>;
|
|
26
|
+
}
|
|
27
|
+
export declare class SQLiteOnSyncedFS extends SQLiteOnVersionedFS {
|
|
28
|
+
protected constructor(db: Database, file: WritableFile);
|
|
29
|
+
static makeAndStart(file: WritableFile): Promise<SQLiteOnSyncedFS>;
|
|
30
|
+
}
|
|
31
|
+
export declare function readDbFrom(file: ReadonlyFile): Promise<Database>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2022 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.readDbFrom = exports.SQLiteOnSyncedFS = exports.SQLiteOnVersionedFS = exports.SQLiteOnUnversionedFS = exports.SQLiteOn3NStorage = void 0;
|
|
20
|
+
const synced_1 = require("../lib-common/processes/synced");
|
|
21
|
+
const sqljs_1 = require("./sqljs");
|
|
22
|
+
class SQLiteOn3NStorage {
|
|
23
|
+
constructor(database, file) {
|
|
24
|
+
this.database = database;
|
|
25
|
+
this.file = file;
|
|
26
|
+
this.syncProc = new synced_1.SingleProc();
|
|
27
|
+
}
|
|
28
|
+
get db() {
|
|
29
|
+
return this.database;
|
|
30
|
+
}
|
|
31
|
+
get dbFile() {
|
|
32
|
+
return this.file;
|
|
33
|
+
}
|
|
34
|
+
sync(action) {
|
|
35
|
+
return this.syncProc.startOrChain(action);
|
|
36
|
+
}
|
|
37
|
+
listTables() {
|
|
38
|
+
const result = this.database.exec(`SELECT tbl_name FROM sqlite_schema WHERE type='table' AND name NOT LIKE 'sqlite_%'`);
|
|
39
|
+
return ((result.length > 0) ?
|
|
40
|
+
result[0].values.map(row => row[0]) :
|
|
41
|
+
[]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.SQLiteOn3NStorage = SQLiteOn3NStorage;
|
|
45
|
+
Object.freeze(SQLiteOn3NStorage.prototype);
|
|
46
|
+
Object.freeze(SQLiteOn3NStorage);
|
|
47
|
+
class SQLiteOnUnversionedFS extends SQLiteOn3NStorage {
|
|
48
|
+
static async makeAndStart(file) {
|
|
49
|
+
const db = await readDbFrom(file);
|
|
50
|
+
return new SQLiteOnUnversionedFS(db, file);
|
|
51
|
+
}
|
|
52
|
+
async saveToFile() {
|
|
53
|
+
await this.syncProc.startOrChain(async () => {
|
|
54
|
+
const dbFileContent = this.database.export();
|
|
55
|
+
await this.file.writeBytes(dbFileContent);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.SQLiteOnUnversionedFS = SQLiteOnUnversionedFS;
|
|
60
|
+
Object.freeze(SQLiteOnUnversionedFS.prototype);
|
|
61
|
+
Object.freeze(SQLiteOnUnversionedFS);
|
|
62
|
+
class SQLiteOnVersionedFS extends SQLiteOn3NStorage {
|
|
63
|
+
constructor(db, file) {
|
|
64
|
+
super(db, file);
|
|
65
|
+
if (!file.v) {
|
|
66
|
+
throw new Error(`Given file is not versioned`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static async makeAndStart(file) {
|
|
70
|
+
const db = await readDbFrom(file);
|
|
71
|
+
return new SQLiteOnVersionedFS(db, file);
|
|
72
|
+
}
|
|
73
|
+
async saveToFile() {
|
|
74
|
+
return await this.syncProc.startOrChain(async () => {
|
|
75
|
+
const dbFileContent = this.database.export();
|
|
76
|
+
return await this.file.v.writeBytes(dbFileContent);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.SQLiteOnVersionedFS = SQLiteOnVersionedFS;
|
|
81
|
+
Object.freeze(SQLiteOnVersionedFS.prototype);
|
|
82
|
+
Object.freeze(SQLiteOnVersionedFS);
|
|
83
|
+
class SQLiteOnSyncedFS extends SQLiteOnVersionedFS {
|
|
84
|
+
constructor(db, file) {
|
|
85
|
+
var _a;
|
|
86
|
+
super(db, file);
|
|
87
|
+
if (!((_a = file.v) === null || _a === void 0 ? void 0 : _a.sync)) {
|
|
88
|
+
throw new Error(`Given file is not synced`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
static async makeAndStart(file) {
|
|
92
|
+
const db = await readDbFrom(file);
|
|
93
|
+
return new SQLiteOnSyncedFS(db, file);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.SQLiteOnSyncedFS = SQLiteOnSyncedFS;
|
|
97
|
+
Object.freeze(SQLiteOnSyncedFS.prototype);
|
|
98
|
+
Object.freeze(SQLiteOnSyncedFS);
|
|
99
|
+
async function readDbFrom(file) {
|
|
100
|
+
const SQL = await (0, sqljs_1.default)(true);
|
|
101
|
+
const fileContent = await readFileContent(file);
|
|
102
|
+
return new SQL.Database(fileContent);
|
|
103
|
+
}
|
|
104
|
+
exports.readDbFrom = readDbFrom;
|
|
105
|
+
async function readFileContent(file) {
|
|
106
|
+
try {
|
|
107
|
+
return await file.readBytes();
|
|
108
|
+
}
|
|
109
|
+
catch (exc) {
|
|
110
|
+
if (exc.notFound) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
throw exc;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// Type definitions for sql.js 1.4
|
|
2
|
+
// Project: https://github.com/sql-js/sql.js
|
|
3
|
+
// Definitions by: Florian Imdahl <https://github.com/ffflorian>
|
|
4
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
// TypeScript Version: 2.3
|
|
6
|
+
|
|
7
|
+
// This file has been simplified to not need node or emscrypten
|
|
8
|
+
|
|
9
|
+
export type SqlValue = number | string | Uint8Array | null;
|
|
10
|
+
export type ParamsObject = Record<string, SqlValue>;
|
|
11
|
+
export type ParamsCallback = (obj: ParamsObject) => void;
|
|
12
|
+
export type BindParams = SqlValue[] | ParamsObject | null;
|
|
13
|
+
|
|
14
|
+
export interface QueryExecResult {
|
|
15
|
+
columns: string[];
|
|
16
|
+
values: SqlValue[][];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface StatementIteratorResult {
|
|
20
|
+
/** `true` if there are no more available statements */
|
|
21
|
+
done: boolean;
|
|
22
|
+
/** the next available Statement (as returned by `Database.prepare`) */
|
|
23
|
+
value: Statement;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SqlJsStatic {
|
|
27
|
+
Database: typeof Database;
|
|
28
|
+
Statement: typeof Statement;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare class Database {
|
|
32
|
+
/**
|
|
33
|
+
* Represents an SQLite database
|
|
34
|
+
* @see [https://sql.js.org/documentation/Database.html#Database](https://sql.js.org/documentation/Database.html#Database)
|
|
35
|
+
*
|
|
36
|
+
* @param data An array of bytes representing an SQLite database file
|
|
37
|
+
*/
|
|
38
|
+
constructor(data?: ArrayLike<number> | null);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Close the database, and all associated prepared statements. The
|
|
42
|
+
* memory associated to the database and all associated statements will
|
|
43
|
+
* be freed.
|
|
44
|
+
*
|
|
45
|
+
* **Warning**: A statement belonging to a database that has been closed
|
|
46
|
+
* cannot be used anymore.
|
|
47
|
+
*
|
|
48
|
+
* Databases must be closed when you're finished with them, or the
|
|
49
|
+
* memory consumption will grow forever
|
|
50
|
+
* @see [https://sql.js.org/documentation/Database.html#["close"]](https://sql.js.org/documentation/Database.html#%5B%22close%22%5D)
|
|
51
|
+
*/
|
|
52
|
+
close(): void;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Register a custom function with SQLite
|
|
56
|
+
* @see [https://sql.js.org/documentation/Database.html#["create_function"]](https://sql.js.org/documentation/Database.html#%5B%22create_function%22%5D)
|
|
57
|
+
*
|
|
58
|
+
* @param name the name of the function as referenced in SQL statements.
|
|
59
|
+
* @param func the actual function to be executed.
|
|
60
|
+
*/
|
|
61
|
+
create_function(name: string, func: (...args: any[]) => any): Database;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Execute an sql statement, and call a callback for each row of result.
|
|
65
|
+
*
|
|
66
|
+
* Currently this method is synchronous, it will not return until the
|
|
67
|
+
* callback has been called on every row of the result. But this might
|
|
68
|
+
* change.
|
|
69
|
+
* @see [https://sql.js.org/documentation/Database.html#["each"]](https://sql.js.org/documentation/Database.html#%5B%22each%22%5D)
|
|
70
|
+
*
|
|
71
|
+
* @param sql A string of SQL text. Can contain placeholders that will
|
|
72
|
+
* be bound to the parameters given as the second argument
|
|
73
|
+
* @param params Parameters to bind to the query
|
|
74
|
+
* @param callback Function to call on each row of result
|
|
75
|
+
* @param done A function that will be called when all rows have been
|
|
76
|
+
* retrieved
|
|
77
|
+
*/
|
|
78
|
+
each(sql: string, params: BindParams, callback: ParamsCallback, done: () => void): Database;
|
|
79
|
+
each(sql: string, callback: ParamsCallback, done: () => void): Database;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Execute an SQL query, and returns the result.
|
|
83
|
+
*
|
|
84
|
+
* This is a wrapper against `Database.prepare`, `Statement.bind`, `Statement.step`, `Statement.get`, and `Statement.free`.
|
|
85
|
+
*
|
|
86
|
+
* The result is an array of result elements. There are as many result elements as the number of statements in your sql string (statements are separated by a semicolon)
|
|
87
|
+
* @see [https://sql.js.org/documentation/Database.html#["exec"]](https://sql.js.org/documentation/Database.html#%5B%22exec%22%5D)
|
|
88
|
+
*
|
|
89
|
+
* @param sql a string containing some SQL text to execute
|
|
90
|
+
* @param params When the SQL statement contains placeholders, you can
|
|
91
|
+
* pass them in here. They will be bound to the statement before it is
|
|
92
|
+
* executed. If you use the params argument as an array, you **cannot**
|
|
93
|
+
* provide an sql string that contains several statements (separated by
|
|
94
|
+
* `;`). This limitation does not apply to params as an object.
|
|
95
|
+
*/
|
|
96
|
+
exec(sql: string, params?: BindParams): QueryExecResult[];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Exports the contents of the database to a binary array
|
|
100
|
+
* @see [https://sql.js.org/documentation/Database.html#["export"]](https://sql.js.org/documentation/Database.html#%5B%22export%22%5D)
|
|
101
|
+
*/
|
|
102
|
+
export(): Uint8Array;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Returns the number of changed rows (modified, inserted or deleted) by
|
|
106
|
+
* the latest completed `INSERT`, `UPDATE` or `DELETE` statement on the
|
|
107
|
+
* database. Executing any other type of SQL statement does not modify
|
|
108
|
+
* the value returned by this function.
|
|
109
|
+
* @see [https://sql.js.org/documentation/Database.html#["getRowsModified"]](https://sql.js.org/documentation/Database.html#%5B%22getRowsModified%22%5D)
|
|
110
|
+
*/
|
|
111
|
+
getRowsModified(): number;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Analyze a result code, return null if no error occured, and throw an
|
|
115
|
+
* error with a descriptive message otherwise
|
|
116
|
+
* @see [https://sql.js.org/documentation/Database.html#["handleError"]](https://sql.js.org/documentation/Database.html#%5B%22handleError%22%5D)
|
|
117
|
+
*/
|
|
118
|
+
handleError(): null | never;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Iterate over multiple SQL statements in a SQL string. This function
|
|
122
|
+
* returns an iterator over Statement objects. You can use a `for..of`
|
|
123
|
+
* loop to execute the returned statements one by one.
|
|
124
|
+
* @see [https://sql.js.org/documentation/Database.html#["iterateStatements"]](https://sql.js.org/documentation/Database.html#%5B%22iterateStatements%22%5D)
|
|
125
|
+
*
|
|
126
|
+
* @param sql a string of SQL that can contain multiple statements
|
|
127
|
+
*/
|
|
128
|
+
iterateStatements(sql: string): StatementIterator;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Prepare an SQL statement
|
|
132
|
+
* @see [https://sql.js.org/documentation/Database.html#["prepare"]](https://sql.js.org/documentation/Database.html#%5B%22prepare%22%5D)
|
|
133
|
+
*
|
|
134
|
+
* @param sql a string of SQL, that can contain placeholders (`?`, `:VVV`, `:AAA`, `@AAA`)
|
|
135
|
+
* @param params values to bind to placeholders
|
|
136
|
+
*/
|
|
137
|
+
prepare(sql: string, params?: BindParams): Statement;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Execute an SQL query, ignoring the rows it returns.
|
|
141
|
+
* @see [https://sql.js.org/documentation/Database.html#["run"]](https://sql.js.org/documentation/Database.html#%5B%22run%22%5D)
|
|
142
|
+
*
|
|
143
|
+
* @param sql a string containing some SQL text to execute
|
|
144
|
+
* @param params When the SQL statement contains placeholders, you can
|
|
145
|
+
* pass them in here. They will be bound to the statement before it is
|
|
146
|
+
* executed. If you use the params argument as an array, you **cannot**
|
|
147
|
+
* provide an sql string that contains several statements (separated by
|
|
148
|
+
* `;`). This limitation does not apply to params as an object.
|
|
149
|
+
*/
|
|
150
|
+
run(sql: string, params?: BindParams): Database;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export declare class Statement {
|
|
154
|
+
/**
|
|
155
|
+
* Bind values to the parameters, after having reseted the statement. If
|
|
156
|
+
* values is null, do nothing and return true.
|
|
157
|
+
*
|
|
158
|
+
* SQL statements can have parameters, named '?', '?NNN', ':VVV',
|
|
159
|
+
* '@VVV', '$VVV', where NNN is a number and VVV a string. This function
|
|
160
|
+
* binds these parameters to the given values.
|
|
161
|
+
*
|
|
162
|
+
* Warning: ':', '@', and '$' are included in the parameters names
|
|
163
|
+
*
|
|
164
|
+
* ### Value types
|
|
165
|
+
*
|
|
166
|
+
* |Javascript type|SQLite type|
|
|
167
|
+
* |-|-|
|
|
168
|
+
* |number|REAL, INTEGER|
|
|
169
|
+
* |boolean|INTEGER|
|
|
170
|
+
* |string|TEXT|
|
|
171
|
+
* |Array, Uint8Array|BLOB|
|
|
172
|
+
* |null|NULL|
|
|
173
|
+
* @see [https://sql.js.org/documentation/Statement.html#["bind"]](https://sql.js.org/documentation/Statement.html#%5B%22bind%22%5D)
|
|
174
|
+
*
|
|
175
|
+
* @param values The values to bind
|
|
176
|
+
*/
|
|
177
|
+
bind(values?: BindParams): boolean;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Free the memory used by the statement
|
|
181
|
+
* @see [https://sql.js.org/documentation/Statement.html#["free"]](https://sql.js.org/documentation/Statement.html#%5B%22free%22%5D)
|
|
182
|
+
*/
|
|
183
|
+
free(): boolean;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Free the memory allocated during parameter binding
|
|
187
|
+
* @see [https://sql.js.org/documentation/Statement.html#["freemem"]](https://sql.js.org/documentation/Statement.html#%5B%22freemem%22%5D)
|
|
188
|
+
*/
|
|
189
|
+
freemem(): void;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Get one row of results of a statement. If the first parameter is not
|
|
193
|
+
* provided, step must have been called before.
|
|
194
|
+
* @see [https://sql.js.org/documentation/Statement.html#["get"]](https://sql.js.org/documentation/Statement.html#%5B%22get%22%5D)
|
|
195
|
+
*
|
|
196
|
+
* @param params If set, the values will be bound to the statement
|
|
197
|
+
* before it is executed
|
|
198
|
+
*/
|
|
199
|
+
get(params?: BindParams): SqlValue[];
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Get one row of result as a javascript object, associating column
|
|
203
|
+
* names with their value in the current row
|
|
204
|
+
* @see [https://sql.js.org/documentation/Statement.html#["getAsObject"]](https://sql.js.org/documentation/Statement.html#%5B%22getAsObject%22%5D)
|
|
205
|
+
*
|
|
206
|
+
* @param params If set, the values will be bound to the statement, and
|
|
207
|
+
* it will be executed
|
|
208
|
+
*/
|
|
209
|
+
getAsObject(params?: BindParams): ParamsObject;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Get the list of column names of a row of result of a statement.
|
|
213
|
+
* @see [https://sql.js.org/documentation/Statement.html#["getColumnNames"]](https://sql.js.org/documentation/Statement.html#%5B%22getColumnNames%22%5D)
|
|
214
|
+
*/
|
|
215
|
+
getColumnNames(): string[];
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Get the SQLite's normalized version of the SQL string used in
|
|
219
|
+
* preparing this statement. The meaning of "normalized" is not
|
|
220
|
+
* well-defined: see
|
|
221
|
+
* [the SQLite documentation](https://sqlite.org/c3ref/expanded_sql.html).
|
|
222
|
+
* @see [https://sql.js.org/documentation/Statement.html#["getNormalizedSQL"]](https://sql.js.org/documentation/Statement.html#%5B%22getNormalizedSQL%22%5D)
|
|
223
|
+
*/
|
|
224
|
+
getNormalizedSQL(): string;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Get the SQL string used in preparing this statement.
|
|
228
|
+
* @see [https://sql.js.org/documentation/Statement.html#["getSQL"]](https://sql.js.org/documentation/Statement.html#%5B%22getSQL%22%5D)
|
|
229
|
+
*/
|
|
230
|
+
getSQL(): string;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Reset a statement, so that it's parameters can be bound to new
|
|
234
|
+
* values. It also clears all previous bindings, freeing the memory used
|
|
235
|
+
* by bound parameters.
|
|
236
|
+
* @see [https://sql.js.org/documentation/Statement.html#["reset"]](https://sql.js.org/documentation/Statement.html#%5B%22reset%22%5D)
|
|
237
|
+
*/
|
|
238
|
+
reset(): void;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Shorthand for bind + step + reset Bind the values, execute the
|
|
242
|
+
* statement, ignoring the rows it returns, and resets it
|
|
243
|
+
* @param values Value to bind to the statement
|
|
244
|
+
*/
|
|
245
|
+
run(values?: BindParams): void;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Execute the statement, fetching the the next line of result, that can
|
|
249
|
+
* be retrieved with `Statement.get`.
|
|
250
|
+
* @see [https://sql.js.org/documentation/Statement.html#["step"]](https://sql.js.org/documentation/Statement.html#%5B%22step%22%5D)
|
|
251
|
+
*/
|
|
252
|
+
step(): boolean;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* An iterator over multiple SQL statements in a string, preparing and
|
|
257
|
+
* returning a Statement object for the next SQL statement on each
|
|
258
|
+
* iteration.
|
|
259
|
+
*
|
|
260
|
+
* You can't instantiate this class directly, you have to use a Database
|
|
261
|
+
* object in order to create a statement iterator
|
|
262
|
+
* @see [https://sql.js.org/documentation/StatementIterator.html#StatementIterator](https://sql.js.org/documentation/StatementIterator.html#StatementIterator)
|
|
263
|
+
*/
|
|
264
|
+
export declare class StatementIterator implements Iterator<Statement>, Iterable<Statement> {
|
|
265
|
+
[Symbol.iterator](): Iterator<Statement>;
|
|
266
|
+
/**
|
|
267
|
+
* Get any un-executed portions remaining of the original SQL string
|
|
268
|
+
* @see [https://sql.js.org/documentation/StatementIterator.html#["getRemainingSQL"]](https://sql.js.org/documentation/StatementIterator.html#%5B%22getRemainingSQL%22%5D)
|
|
269
|
+
*/
|
|
270
|
+
getRemainingSql(): string;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Prepare the next available SQL statement
|
|
274
|
+
* @see [https://sql.js.org/documentation/StatementIterator.html#["next"]](https://sql.js.org/documentation/StatementIterator.html#%5B%22next%22%5D)
|
|
275
|
+
*/
|
|
276
|
+
next(): StatementIteratorResult;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export default function(keepWasm?: boolean): Promise<SqlJsStatic>;
|