@based/db 0.0.44 → 0.0.45
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/lib/darwin_aarch64/libdeflate.dylib +0 -0
- package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/modify/create.js +1 -1
- package/dist/src/client/modify/update.js +1 -1
- package/dist/src/client/query/BasedDbQuery.js +15 -1
- package/dist/src/client/query/registerQuery.js +0 -1
- package/dist/src/index.js +10 -0
- package/dist/src/server/index.js +4 -0
- package/dist/src/server/worker.js +1 -2
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -285,6 +285,7 @@ export class BasedDbQuery extends QueryBranch {
|
|
|
285
285
|
throw new Error('Query: No schema yet - use await db.schemaIsSet()');
|
|
286
286
|
}
|
|
287
287
|
const def = createQueryDef(db, QueryDefType.Root, target, skipValidation);
|
|
288
|
+
def.schemaChecksum = db.schema?.hash || 0;
|
|
288
289
|
super(db, def);
|
|
289
290
|
this.db = db;
|
|
290
291
|
this.skipValidation = skipValidation;
|
|
@@ -295,6 +296,7 @@ export class BasedDbQuery extends QueryBranch {
|
|
|
295
296
|
this.id = undefined;
|
|
296
297
|
this.buffer = undefined;
|
|
297
298
|
const def = createQueryDef(this.db, QueryDefType.Root, this.target, this.skipValidation);
|
|
299
|
+
def.schemaChecksum = this.db.schema?.hash || 0;
|
|
298
300
|
this.def = def;
|
|
299
301
|
const q = this.queryCommands;
|
|
300
302
|
this.queryCommands = [];
|
|
@@ -316,8 +318,20 @@ export class BasedDbQuery extends QueryBranch {
|
|
|
316
318
|
}
|
|
317
319
|
const d = performance.now();
|
|
318
320
|
await this.db.isModified();
|
|
321
|
+
if (this.db.schema?.hash !== this.def.schemaChecksum) {
|
|
322
|
+
this.reBuildQuery();
|
|
323
|
+
return this.#getInternal(resolve, reject);
|
|
324
|
+
}
|
|
319
325
|
const res = await this.db.hooks.getQueryBuf(buf);
|
|
320
|
-
if (res
|
|
326
|
+
if (res.byteLength === 1) {
|
|
327
|
+
if (res[0] === 0) {
|
|
328
|
+
reject(new Error('schema mismatch'));
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
reject(new Error('unexpected error'));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else if (res instanceof Error) {
|
|
321
335
|
reject(res);
|
|
322
336
|
}
|
|
323
337
|
else {
|
|
@@ -4,7 +4,6 @@ import { defToBuffer } from './toBuffer.js';
|
|
|
4
4
|
import { handleErrors } from './validation.js';
|
|
5
5
|
export const registerQuery = (q) => {
|
|
6
6
|
if (!q.id) {
|
|
7
|
-
q.def.schemaChecksum = q.db.schema.hash;
|
|
8
7
|
const b = defToBuffer(q.db, q.def);
|
|
9
8
|
const buf = concatUint8Arr(b);
|
|
10
9
|
let id = native.crc32(buf);
|
package/dist/src/index.js
CHANGED
|
@@ -53,6 +53,7 @@ export class BasedDb {
|
|
|
53
53
|
maxModifySize,
|
|
54
54
|
hooks: {
|
|
55
55
|
subscribe(q, onData, onError) {
|
|
56
|
+
let killed = false;
|
|
56
57
|
let timer;
|
|
57
58
|
let prevChecksum;
|
|
58
59
|
let lastLen = 0;
|
|
@@ -63,8 +64,16 @@ export class BasedDb {
|
|
|
63
64
|
q.reBuildQuery();
|
|
64
65
|
registerQuery(q);
|
|
65
66
|
response = undefined;
|
|
67
|
+
timer = setTimeout(get, 0);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (killed) {
|
|
71
|
+
return;
|
|
66
72
|
}
|
|
67
73
|
const res = await server.getQueryBuf(q.buffer);
|
|
74
|
+
if (killed) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
68
77
|
if (!response) {
|
|
69
78
|
response = new BasedQueryResponse(q.id, q.def, res, 0);
|
|
70
79
|
}
|
|
@@ -82,6 +91,7 @@ export class BasedDb {
|
|
|
82
91
|
};
|
|
83
92
|
get();
|
|
84
93
|
return () => {
|
|
94
|
+
killed = true;
|
|
85
95
|
clearTimeout(timer);
|
|
86
96
|
};
|
|
87
97
|
},
|
package/dist/src/server/index.js
CHANGED
|
@@ -469,6 +469,10 @@ export class DbServer {
|
|
|
469
469
|
console.error('Db is stopped - trying to query', buf.byteLength);
|
|
470
470
|
return Promise.resolve(new Uint8Array(8));
|
|
471
471
|
}
|
|
472
|
+
const schemaChecksum = readUint64(buf, buf.byteLength - 8);
|
|
473
|
+
if (schemaChecksum !== this.schema?.hash) {
|
|
474
|
+
return Promise.resolve(new Uint8Array(1));
|
|
475
|
+
}
|
|
472
476
|
if (this.modifyQueue.length) {
|
|
473
477
|
return new Promise((resolve) => {
|
|
474
478
|
this.addToQueryQueue(resolve, buf);
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { isMainThread, receiveMessageOnPort, workerData, } from 'node:worker_threads';
|
|
2
2
|
import native from '../native.js';
|
|
3
|
-
let workerCtx;
|
|
4
3
|
if (isMainThread) {
|
|
5
4
|
console.warn('running query worker.ts in mainthread');
|
|
6
5
|
}
|
|
7
6
|
else {
|
|
8
7
|
let { address, channel } = workerData;
|
|
9
8
|
let dbCtx = native.externalFromInt(address);
|
|
10
|
-
|
|
9
|
+
native.workerCtxInit();
|
|
11
10
|
// const transferList = new Array(1)
|
|
12
11
|
const handleMsg = (msg) => {
|
|
13
12
|
try {
|