@based/db 0.0.63 → 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.
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
  };
@@ -145,7 +145,7 @@ export function create(db, type, obj, opts) {
145
145
  if (pos === 8) {
146
146
  throw new Error('!No range available');
147
147
  }
148
- flushBuffer(db);
148
+ void flushBuffer(db);
149
149
  return db.create(type, obj, opts);
150
150
  }
151
151
  res.error = err;
@@ -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);
@@ -70,7 +70,7 @@ export const update = (db, type, id, obj, opts) => {
70
70
  if (pos === 8) {
71
71
  throw new Error('out of range');
72
72
  }
73
- flushBuffer(db);
73
+ void flushBuffer(db);
74
74
  return update(db, type, id, obj, opts);
75
75
  }
76
76
  res.error = err;
@@ -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.reset();
342
- this.db.emit('info', 'query get schema mismatch - awaiting new schema (max 15s)');
343
- const ok = await Promise.race([wait(15e3), this.db.once('schema')]);
344
- if (!ok) {
345
- reject(new Error('schema mismath'));
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.schemaIsSet().then(() => {
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
@@ -25,7 +25,7 @@ export const getDefaultHooks = (server, subInterval = 200) => {
25
25
  }
26
26
  timer = setTimeout(poll, subInterval);
27
27
  };
28
- poll();
28
+ void poll();
29
29
  return () => {
30
30
  clearTimeout(timer);
31
31
  killed = true;
@@ -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) {
@@ -333,7 +333,6 @@ export class DbServer extends DbShared {
333
333
  resolve(new Error('Query queue exceeded'));
334
334
  return;
335
335
  }
336
- // TODO should we check here as well? Already will check in DbWorker
337
336
  const schemaChecksum = readUint64(buf, buf.byteLength - 8);
338
337
  if (schemaChecksum !== this.schema?.hash) {
339
338
  return Promise.resolve(new Uint8Array(1));
@@ -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,
@@ -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) {
@@ -124,7 +124,7 @@ export async function start(db, opts) {
124
124
  // use timeout
125
125
  if (db.saveIntervalInSeconds > 0) {
126
126
  db.saveInterval ??= setInterval(() => {
127
- save(db);
127
+ void save(db);
128
128
  }, db.saveIntervalInSeconds * 1e3);
129
129
  }
130
130
  if (db.schema) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.0.63",
3
+ "version": "0.0.64",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",