@based/db 0.0.56 → 0.0.57

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
@@ -340,11 +340,17 @@ export class BasedDbQuery extends QueryBranch {
340
340
  const res = await this.db.hooks.getQueryBuf(buf);
341
341
  if (res.byteLength === 1) {
342
342
  if (res[0] === 0) {
343
- if (this.db.schema?.hash !== this.def.schemaChecksum) {
343
+ if (this.def && this.db.schema?.hash !== this.def.schemaChecksum) {
344
+ this.reset();
345
+ this.db.emit('info', 'query get schema mismatch - awaiting new schema');
346
+ await this.db.once('schema');
347
+ return this.#getInternal(resolve, reject);
348
+ }
349
+ else {
350
+ this.db.emit('info', 'query get schema mismatch - got the same already');
344
351
  this.reset();
345
352
  return this.#getInternal(resolve, reject);
346
353
  }
347
- reject(new Error('schema mismatch'));
348
354
  }
349
355
  else {
350
356
  reject(new Error('unexpected error'));
@@ -31,7 +31,11 @@ const parseTransform = (transform) => {
31
31
  export const migrate = async (server, fromSchema, toSchema, transform) => {
32
32
  const migrationId = toSchema.hash;
33
33
  server.migrating = migrationId;
34
- const abort = () => server.migrating !== migrationId;
34
+ server.emit('info', `migrating schema ${migrationId}`);
35
+ const abort = () => {
36
+ server.emit('info', `abort migration - migrating: ${server.migrating} abort: ${migrationId}`);
37
+ return server.migrating !== migrationId;
38
+ };
35
39
  const tmpDb = new BasedDb({
36
40
  path: null,
37
41
  });
@@ -1,6 +1,7 @@
1
1
  import { DbSchema } from '../schema.js';
2
2
  export type EventMap = {
3
3
  schema: DbSchema;
4
+ info: string;
4
5
  };
5
6
  export type Event = keyof EventMap;
6
7
  export type Listener<T> = (data: T) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.0.56",
3
+ "version": "0.0.57",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",