@based/db 0.0.62 → 0.0.64
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/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/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/flushModify.js +2 -2
- package/dist/src/client/modify/create.js +1 -1
- package/dist/src/client/modify/delete.js +2 -2
- package/dist/src/client/modify/expire.js +1 -1
- package/dist/src/client/modify/update.js +1 -1
- package/dist/src/client/query/BasedDbQuery.js +12 -7
- package/dist/src/client/query/subscription/index.js +6 -1
- package/dist/src/hooks.js +1 -1
- package/dist/src/server/DbWorker.js +3 -1
- package/dist/src/server/index.d.ts +3 -3
- package/dist/src/server/index.js +15 -10
- package/dist/src/server/migrate/index.js +1 -1
- package/dist/src/server/migrate/worker.js +1 -0
- package/dist/src/server/save.js +1 -1
- package/dist/src/server/start.js +1 -1
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -169,12 +169,12 @@ export const startDrain = (db) => {
|
|
|
169
169
|
db.isDraining = true;
|
|
170
170
|
if (db.flushTime === 0) {
|
|
171
171
|
process.nextTick(() => {
|
|
172
|
-
flushBuffer(db);
|
|
172
|
+
void flushBuffer(db);
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
else {
|
|
176
176
|
setTimeout(() => {
|
|
177
|
-
flushBuffer(db);
|
|
177
|
+
void flushBuffer(db);
|
|
178
178
|
}, db.flushTime);
|
|
179
179
|
}
|
|
180
180
|
};
|
|
@@ -15,7 +15,7 @@ export const deleteFn = (db, type, id, opts) => {
|
|
|
15
15
|
if (separate) {
|
|
16
16
|
const size = 11 /* SIZE.DEFAULT_CURSOR */ + 2 + separate.length * 12;
|
|
17
17
|
if (ctx.len + size > ctx.max) {
|
|
18
|
-
flushBuffer(db);
|
|
18
|
+
void flushBuffer(db);
|
|
19
19
|
return deleteFn(db, type, id);
|
|
20
20
|
}
|
|
21
21
|
setCursor(ctx, schema, 0, MICRO_BUFFER, id, UPDATE);
|
|
@@ -28,7 +28,7 @@ export const deleteFn = (db, type, id, opts) => {
|
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
30
|
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 2 > ctx.max) {
|
|
31
|
-
flushBuffer(db);
|
|
31
|
+
void flushBuffer(db);
|
|
32
32
|
return deleteFn(db, type, id);
|
|
33
33
|
}
|
|
34
34
|
setCursor(ctx, schema, 0, MICRO_BUFFER, id, UPDATE);
|
|
@@ -9,7 +9,7 @@ export function expire(db, type, id, seconds) {
|
|
|
9
9
|
}
|
|
10
10
|
const ctx = db.modifyCtx;
|
|
11
11
|
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 > ctx.max) {
|
|
12
|
-
flushBuffer(db);
|
|
12
|
+
void flushBuffer(db);
|
|
13
13
|
return expire(db, type, id, seconds);
|
|
14
14
|
}
|
|
15
15
|
setCursor(ctx, def, 0, MICRO_BUFFER, id, EXPIRE);
|
|
@@ -11,7 +11,6 @@ import { langCodesMap } from '@based/schema';
|
|
|
11
11
|
import { convertFilter } from './filter/convertFilter.js';
|
|
12
12
|
import { validateLocale, validateRange } from './validation.js';
|
|
13
13
|
import { DEF_RANGE_PROP_LIMIT } from './thresholds.js';
|
|
14
|
-
import { wait } from '@saulx/utils';
|
|
15
14
|
import { displayTarget } from './display.js';
|
|
16
15
|
import picocolors from 'picocolors';
|
|
17
16
|
export class QueryBranch {
|
|
@@ -338,13 +337,19 @@ export class BasedDbQuery extends QueryBranch {
|
|
|
338
337
|
const res = await this.db.hooks.getQueryBuf(buf);
|
|
339
338
|
if (res.byteLength === 1) {
|
|
340
339
|
if (res[0] === 0) {
|
|
341
|
-
this.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
340
|
+
if (this.def && this.def.schemaChecksum === this.db.schema?.hash) {
|
|
341
|
+
// my schema did not change since last time, wait for the schema to change
|
|
342
|
+
this.reset();
|
|
343
|
+
this.db.emit('info', 'query get schema mismatch - awaiting new schema');
|
|
344
|
+
await this.db.once('schema');
|
|
345
|
+
return this.#getInternal(resolve, reject);
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
// its changed so lets send again
|
|
349
|
+
this.db.emit('info', 'query get schema mismatch - got the same already');
|
|
350
|
+
this.reset();
|
|
351
|
+
return this.#getInternal(resolve, reject);
|
|
346
352
|
}
|
|
347
|
-
return this.#getInternal(resolve, reject);
|
|
348
353
|
}
|
|
349
354
|
else {
|
|
350
355
|
reject(new Error('unexpected error'));
|
|
@@ -32,7 +32,9 @@ export class SubStore {
|
|
|
32
32
|
};
|
|
33
33
|
let killed = false;
|
|
34
34
|
if (!q.db.schema) {
|
|
35
|
-
q.db
|
|
35
|
+
q.db
|
|
36
|
+
.schemaIsSet()
|
|
37
|
+
.then(() => {
|
|
36
38
|
if (!killed) {
|
|
37
39
|
try {
|
|
38
40
|
registerQuery(q);
|
|
@@ -42,6 +44,9 @@ export class SubStore {
|
|
|
42
44
|
onError(err);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
47
|
+
})
|
|
48
|
+
.catch((err) => {
|
|
49
|
+
onError(err);
|
|
45
50
|
});
|
|
46
51
|
this.onClose = () => {
|
|
47
52
|
killed = true;
|
package/dist/src/hooks.js
CHANGED
|
@@ -29,7 +29,9 @@ export class DbWorker {
|
|
|
29
29
|
});
|
|
30
30
|
this.worker.on('error', (err) => {
|
|
31
31
|
console.error('error in query worker:', err);
|
|
32
|
-
this.worker.terminate()
|
|
32
|
+
this.worker.terminate().catch((err) => {
|
|
33
|
+
console.error('error terminating query worker:', err);
|
|
34
|
+
});
|
|
33
35
|
});
|
|
34
36
|
this.worker.on('exit', (code) => {
|
|
35
37
|
if (!this.db.stopped) {
|
|
@@ -67,10 +67,10 @@ export declare class DbServer extends DbShared {
|
|
|
67
67
|
getSortIndex(typeId: number, field: number, start: number, lang: number): SortIndex;
|
|
68
68
|
createSortIndexBuffer(typeId: number, field: number, start: number, lang: number): SortIndex;
|
|
69
69
|
setSchema(strictSchema: StrictSchema, transformFns?: TransformFns): Promise<SchemaChecksum>;
|
|
70
|
-
modify(
|
|
71
|
-
addToQueryQueue(resolve: any, buf: any):
|
|
70
|
+
modify(bufWithHash: Uint8Array): Record<number, number> | null;
|
|
71
|
+
addToQueryQueue(resolve: any, buf: any): Promise<Uint8Array>;
|
|
72
72
|
getQueryBuf(buf: Uint8Array, fromQueue?: boolean): Promise<Uint8Array>;
|
|
73
|
-
onQueryEnd():
|
|
73
|
+
onQueryEnd(): any;
|
|
74
74
|
stop(noSave?: boolean): Promise<void>;
|
|
75
75
|
destroy(): Promise<void>;
|
|
76
76
|
}
|
package/dist/src/server/index.js
CHANGED
|
@@ -242,14 +242,13 @@ export class DbServer extends DbShared {
|
|
|
242
242
|
});
|
|
243
243
|
return schema.hash;
|
|
244
244
|
}
|
|
245
|
-
modify(
|
|
246
|
-
const schemaHash = readUint64(
|
|
247
|
-
// if !schema
|
|
245
|
+
modify(bufWithHash) {
|
|
246
|
+
const schemaHash = readUint64(bufWithHash, 0);
|
|
248
247
|
if (schemaHash !== this.schema?.hash) {
|
|
249
248
|
this.emit('info', 'Schema mismatch in modify');
|
|
250
249
|
return null;
|
|
251
250
|
}
|
|
252
|
-
buf =
|
|
251
|
+
const buf = bufWithHash.subarray(8);
|
|
253
252
|
const offsets = {};
|
|
254
253
|
const dataLen = readUint32(buf, buf.length - 4);
|
|
255
254
|
let typesSize = readUint16(buf, dataLen);
|
|
@@ -277,7 +276,7 @@ export class DbServer extends DbShared {
|
|
|
277
276
|
offsets[typeId] = offset;
|
|
278
277
|
}
|
|
279
278
|
if (this.processingQueries) {
|
|
280
|
-
this.modifyQueue.push(new Uint8Array(
|
|
279
|
+
this.modifyQueue.push(new Uint8Array(bufWithHash));
|
|
281
280
|
}
|
|
282
281
|
else {
|
|
283
282
|
this.#modify(buf);
|
|
@@ -334,6 +333,10 @@ export class DbServer extends DbShared {
|
|
|
334
333
|
resolve(new Error('Query queue exceeded'));
|
|
335
334
|
return;
|
|
336
335
|
}
|
|
336
|
+
const schemaChecksum = readUint64(buf, buf.byteLength - 8);
|
|
337
|
+
if (schemaChecksum !== this.schema?.hash) {
|
|
338
|
+
return Promise.resolve(new Uint8Array(1));
|
|
339
|
+
}
|
|
337
340
|
this.queryQueue.set(resolve, buf);
|
|
338
341
|
}
|
|
339
342
|
getQueryBuf(buf, fromQueue = false) {
|
|
@@ -341,10 +344,6 @@ export class DbServer extends DbShared {
|
|
|
341
344
|
console.error('Db is stopped - trying to query', buf.byteLength);
|
|
342
345
|
return Promise.resolve(new Uint8Array(8));
|
|
343
346
|
}
|
|
344
|
-
const schemaChecksum = readUint64(buf, buf.byteLength - 8);
|
|
345
|
-
if (schemaChecksum !== this.schema?.hash) {
|
|
346
|
-
return Promise.resolve(new Uint8Array(1));
|
|
347
|
-
}
|
|
348
347
|
if (this.modifyQueue.length) {
|
|
349
348
|
return new Promise((resolve) => {
|
|
350
349
|
this.addToQueryQueue(resolve, buf);
|
|
@@ -393,7 +392,13 @@ export class DbServer extends DbShared {
|
|
|
393
392
|
if (this.modifyQueue.length) {
|
|
394
393
|
const modifyQueue = this.modifyQueue;
|
|
395
394
|
this.modifyQueue = [];
|
|
396
|
-
for (const
|
|
395
|
+
for (const bufWithHash of modifyQueue) {
|
|
396
|
+
const schemaHash = readUint64(bufWithHash, 0);
|
|
397
|
+
if (schemaHash !== this.schema?.hash) {
|
|
398
|
+
this.emit('info', 'Schema mismatch in modify');
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
const buf = bufWithHash.subarray(8);
|
|
397
402
|
this.#modify(buf);
|
|
398
403
|
}
|
|
399
404
|
}
|
|
@@ -113,7 +113,7 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
|
|
|
113
113
|
if (server.dirtyRanges.size) {
|
|
114
114
|
rangesToMigrate = [];
|
|
115
115
|
i = 0;
|
|
116
|
-
foreachDirtyBlock(server, (_mtKey, typeId, start, end) => {
|
|
116
|
+
void foreachDirtyBlock(server, (_mtKey, typeId, start, end) => {
|
|
117
117
|
rangesToMigrate.push({
|
|
118
118
|
typeId,
|
|
119
119
|
start,
|
|
@@ -13,6 +13,7 @@ else if (workerData?.isDbMigrateWorker) {
|
|
|
13
13
|
const { from, to, fromSchema, toSchema, channel, workerState, transformFns } = workerData;
|
|
14
14
|
const fromCtx = native.externalFromInt(from);
|
|
15
15
|
const toCtx = native.externalFromInt(to);
|
|
16
|
+
native.workerCtxInit();
|
|
16
17
|
const fromDb = new BasedDb({ path: null });
|
|
17
18
|
const toDb = new BasedDb({ path: null });
|
|
18
19
|
const cp = (obj) => {
|
package/dist/src/server/save.js
CHANGED
|
@@ -69,7 +69,7 @@ export function save(db, sync = false, forceFullDump = false, skipMigrationCheck
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
foreachDirtyBlock(db, (mtKey, typeId, start, end) => {
|
|
72
|
+
void foreachDirtyBlock(db, (mtKey, typeId, start, end) => {
|
|
73
73
|
const hash = new Uint8Array(16);
|
|
74
74
|
const file = saveRange(db, typeId, start, end, hash);
|
|
75
75
|
if (file === null) {
|
package/dist/src/server/start.js
CHANGED