@based/db 0.0.50 → 0.0.52

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
package/dist/src/hooks.js CHANGED
@@ -1,3 +1,5 @@
1
+ import picocolors from 'picocolors';
2
+ import { displayTarget } from './client/query/display.js';
1
3
  export const getDefaultHooks = (server, subInterval = 200) => {
2
4
  return {
3
5
  subscribe(q, onData, onError) {
@@ -8,7 +10,7 @@ export const getDefaultHooks = (server, subInterval = 200) => {
8
10
  if (killed) {
9
11
  return;
10
12
  }
11
- if (res.byteLength >= 8) {
13
+ if (res.byteLength >= 4) {
12
14
  onData(res);
13
15
  }
14
16
  else if (res.byteLength === 1 && res[0] === 0) {
@@ -17,7 +19,10 @@ export const getDefaultHooks = (server, subInterval = 200) => {
17
19
  return;
18
20
  }
19
21
  else {
20
- onError(new Error('unexpected error'));
22
+ const def = this.def;
23
+ let name = picocolors.red(`QueryError[${displayTarget(def)}]\n`);
24
+ name += ` Incorrect buffer received in subscription (maybe server not started ${res.byteLength}) bytes\n`;
25
+ onError(new Error(name));
21
26
  }
22
27
  timer = setTimeout(poll, subInterval);
23
28
  };
@@ -1,4 +1,5 @@
1
1
  import { getPropType } from '@based/schema';
2
+ import { deepCopy } from '@saulx/utils';
2
3
  const exclude = new Set(['id', 'lastId', 'hash']);
3
4
  export const schemaLooseEqual = (a, b, key) => {
4
5
  if (a === b) {
@@ -49,13 +50,10 @@ export const schemaLooseEqual = (a, b, key) => {
49
50
  export const parseSchema = (strictSchema) => {
50
51
  let parsedSchema = strictSchema;
51
52
  if (strictSchema.props) {
52
- parsedSchema = {
53
- ...strictSchema,
54
- types: { ...parsedSchema.types },
55
- };
56
- const props = { ...strictSchema.props };
57
- for (const key in props) {
58
- const prop = props[key];
53
+ // TODO do this more precise
54
+ parsedSchema = deepCopy(strictSchema);
55
+ for (const key in parsedSchema.props) {
56
+ const prop = parsedSchema.props[key];
59
57
  const propType = getPropType(prop);
60
58
  let refProp;
61
59
  if (propType === 'reference') {
@@ -63,6 +61,7 @@ export const parseSchema = (strictSchema) => {
63
61
  }
64
62
  else if (propType === 'references') {
65
63
  refProp = prop.items;
64
+ prop.items = refProp;
66
65
  }
67
66
  if (refProp) {
68
67
  const type = parsedSchema.types[refProp.ref];
@@ -82,10 +81,11 @@ export const parseSchema = (strictSchema) => {
82
81
  refProp.prop = inverseKey;
83
82
  }
84
83
  }
84
+ parsedSchema.types ??= {};
85
85
  // @ts-ignore This creates an internal type to use for root props
86
86
  parsedSchema.types._root = {
87
87
  id: 1,
88
- props,
88
+ props: parsedSchema.props,
89
89
  };
90
90
  delete parsedSchema.props;
91
91
  }
@@ -287,7 +287,13 @@ export class DbServer {
287
287
  if (schemaLooseEqual(parsedSchema, this.schema)) {
288
288
  return this.schema;
289
289
  }
290
- return this.migrateSchema(strictSchema, transformFns);
290
+ try {
291
+ return this.migrateSchema(strictSchema, transformFns);
292
+ }
293
+ catch (e) {
294
+ console.error('error migrating schema:', e);
295
+ return this.schema;
296
+ }
291
297
  }
292
298
  this.schema = {
293
299
  lastId: this.schema.lastId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.0.50",
3
+ "version": "0.0.52",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
@@ -57,4 +57,4 @@
57
57
  "tar": "^7.4.3",
58
58
  "typescript": "^5.6.3"
59
59
  }
60
- }
60
+ }