@based/db 0.0.69 → 0.0.71

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.
Files changed (31) hide show
  1. package/dist/lib/darwin_aarch64/include/selva/hll.h +1 -1
  2. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  3. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  4. package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
  5. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  6. package/dist/lib/linux_aarch64/include/selva/hll.h +1 -1
  7. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  8. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  9. package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
  10. package/dist/lib/linux_aarch64/libselva.so +0 -0
  11. package/dist/lib/linux_x86_64/include/selva/hll.h +1 -1
  12. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  13. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  14. package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
  15. package/dist/lib/linux_x86_64/libselva.so +0 -0
  16. package/dist/src/client/modify/create.js +4 -0
  17. package/dist/src/client/modify/references/edge.js +20 -6
  18. package/dist/src/client/modify/references/reference.js +21 -9
  19. package/dist/src/client/modify/references/references.js +9 -1
  20. package/dist/src/client/modify/update.js +4 -0
  21. package/dist/src/client/query/BasedDbQuery.d.ts +1 -1
  22. package/dist/src/client/query/BasedDbQuery.js +4 -4
  23. package/dist/src/client/query/aggregates/types.d.ts +1 -1
  24. package/dist/src/client/query/aggregates/types.js +1 -1
  25. package/dist/src/client/query/validation.js +1 -1
  26. package/dist/src/server/migrate/index.js +21 -7
  27. package/dist/src/server/migrate/worker.js +70 -62
  28. package/dist/src/server/save.js +7 -6
  29. package/dist/src/server/schema.js +8 -6
  30. package/dist/src/types.d.ts +1 -1
  31. package/package.json +4 -3
@@ -19,7 +19,7 @@ uint8_t *hll_count(struct selva_string *hllss);
19
19
  SELVA_EXPORT
20
20
  void hll_array_union(struct selva_string *res, struct selva_string *hll_array, size_t count);
21
21
  SELVA_EXPORT
22
- void hll_union(char*, size_t, const char*, size_t);
22
+ void hll_union(struct selva_string *, struct selva_string *);
23
23
 
24
24
  // size_t actual_cols[13] = { 79, 159, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
25
25
  // float raw_estimate_data[13][200] =
@@ -19,7 +19,7 @@ uint8_t *hll_count(struct selva_string *hllss);
19
19
  SELVA_EXPORT
20
20
  void hll_array_union(struct selva_string *res, struct selva_string *hll_array, size_t count);
21
21
  SELVA_EXPORT
22
- void hll_union(char*, size_t, const char*, size_t);
22
+ void hll_union(struct selva_string *, struct selva_string *);
23
23
 
24
24
  // size_t actual_cols[13] = { 79, 159, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
25
25
  // float raw_estimate_data[13][200] =
Binary file
@@ -19,7 +19,7 @@ uint8_t *hll_count(struct selva_string *hllss);
19
19
  SELVA_EXPORT
20
20
  void hll_array_union(struct selva_string *res, struct selva_string *hll_array, size_t count);
21
21
  SELVA_EXPORT
22
- void hll_union(char*, size_t, const char*, size_t);
22
+ void hll_union(struct selva_string *, struct selva_string *);
23
23
 
24
24
  // size_t actual_cols[13] = { 79, 159, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
25
25
  // float raw_estimate_data[13][200] =
Binary file
@@ -11,6 +11,7 @@ import { writeString } from './string.js';
11
11
  import { writeText } from './text.js';
12
12
  import { writeJson } from './json.js';
13
13
  import { writeAlias } from './alias.js';
14
+ import { getByPath } from '@saulx/utils';
14
15
  const appendCreate = (ctx, schema, obj, res, unsafe) => {
15
16
  const len = ctx.len;
16
17
  let err = modify(ctx, res, obj, schema, CREATE, schema.tree, true, unsafe);
@@ -26,6 +27,9 @@ const appendCreate = (ctx, schema, obj, res, unsafe) => {
26
27
  if (schema.createTs) {
27
28
  const createTs = Date.now();
28
29
  for (const prop of schema.createTs) {
30
+ if (getByPath(obj, prop.path) !== undefined) {
31
+ continue;
32
+ }
29
33
  if (ctx.lastMain === -1) {
30
34
  let mainLenU32 = schema.mainLen;
31
35
  setCursor(ctx, schema, prop.prop, MICRO_BUFFER, res.tmpId, CREATE);
@@ -7,6 +7,7 @@ import { ModifyError, ModifyState } from '../ModifyRes.js';
7
7
  import { DECREMENT, INCREMENT, RANGE_ERR, UPDATE, UPDATE_PARTIAL, } from '../types.js';
8
8
  import { appendFixedValue } from '../fixed.js';
9
9
  import { appendEdgeRefs } from './appendEdgeRefs.js';
10
+ import { writeUint32 } from '@saulx/utils';
10
11
  function valueOperation(value) {
11
12
  if (typeof value === 'object' && value !== null) {
12
13
  if (value.increment > 0) {
@@ -24,6 +25,15 @@ export function writeEdges(t, ref, ctx) {
24
25
  let mainFields;
25
26
  let mainSize = 0;
26
27
  let hasIncr = false;
28
+ if (t.hasDefaultEdges) {
29
+ for (const key in t.edges) {
30
+ if (t.edges[key].separate === true &&
31
+ (!(key in ref) || ref[key] === undefined)) {
32
+ const edge = t.edges[key];
33
+ ref[key] = edge.default;
34
+ }
35
+ }
36
+ }
27
37
  for (const key in ref) {
28
38
  if (key === 'id' || key === '$index') {
29
39
  continue;
@@ -224,7 +234,9 @@ export function writeEdges(t, ref, ctx) {
224
234
  }
225
235
  }
226
236
  }
227
- if (mainFields) {
237
+ // double check if has default edges has mainfields - add extra thing
238
+ if (mainFields || t.hasDefaultEdges) {
239
+ // add all
228
240
  // Single field in main buffer can immediately setup the main buffer
229
241
  if (!hasIncr && mainSize === t.edgeMainLen) {
230
242
  /*
@@ -245,10 +257,8 @@ export function writeEdges(t, ref, ctx) {
245
257
  ctx.buf[ctx.len++] = 0;
246
258
  ctx.buf[ctx.len++] = MICRO_BUFFER;
247
259
  let sizeU32 = mainSize;
248
- ctx.buf[ctx.len++] = sizeU32;
249
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
250
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
251
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
260
+ writeUint32(ctx.buf, sizeU32, ctx.len);
261
+ ctx.len += 4;
252
262
  for (let i = 0; i < mainFields.length; i += 3) {
253
263
  const edge = mainFields[i];
254
264
  const err = appendFixedValue(ctx, mainFields[i + 1], edge, UPDATE);
@@ -258,6 +268,9 @@ export function writeEdges(t, ref, ctx) {
258
268
  }
259
269
  }
260
270
  else {
271
+ if (!mainFields) {
272
+ mainFields = [];
273
+ }
261
274
  /*
262
275
  Partial main update:
263
276
 
@@ -293,7 +306,8 @@ export function writeEdges(t, ref, ctx) {
293
306
  const sIndex = ctx.len;
294
307
  ctx.len += mainFieldsStartSize;
295
308
  // Add zeroes
296
- ctx.buf.fill(0, ctx.len, ctx.len + t.edgeMainLen);
309
+ ctx.buf.set(t.edgeMainEmpty, ctx.len);
310
+ // ctx.buf.fill(0, ctx.len, ctx.len + t.edgeMainLen)
297
311
  // Keep track of written bytes from append fixed
298
312
  let startMain = ctx.len;
299
313
  for (let i = 0; i < mainFields.length; i += 3) {
@@ -24,7 +24,7 @@ function writeRef(id, ctx, schema, def, parentId, modifyOp, hasEdges, isTmpId) {
24
24
  ctx.buf[ctx.len++] = id >>>= 8;
25
25
  ctx.buf[ctx.len++] = id >>>= 8;
26
26
  }
27
- function singleReferenceEdges(ref, ctx, schema, def, parentId, modifyOp) {
27
+ function singleReferenceEdges(ref, ctx, schema, def, parentId, modifyOp, processDefaultEdges) {
28
28
  let id = ref.id;
29
29
  let isTmpId;
30
30
  if (typeof id !== 'number') {
@@ -77,23 +77,35 @@ export function writeReference(value, ctx, schema, def, res, modifyOp) {
77
77
  }
78
78
  setCursor(ctx, schema, def.prop, def.typeIndex, res.tmpId, modifyOp);
79
79
  ctx.buf[ctx.len++] = DELETE;
80
+ return;
80
81
  }
81
- else if (typeof value === 'number') {
82
- return writeRef(value, ctx, schema, def, res.tmpId, modifyOp, false, false);
82
+ const processDefaultEdges = def.hasDefaultEdges;
83
+ if (typeof value === 'number') {
84
+ if (processDefaultEdges) {
85
+ value = { id: value };
86
+ }
87
+ else {
88
+ return writeRef(value, ctx, schema, def, res.tmpId, modifyOp, false, false);
89
+ }
83
90
  }
84
- else if (value instanceof ModifyState) {
91
+ if (value instanceof ModifyState) {
85
92
  if (value.error) {
86
93
  return value.error;
87
94
  }
88
95
  const id = value.getId();
89
- if (id) {
90
- return writeRef(id, ctx, schema, def, res.tmpId, modifyOp, false, false);
96
+ if (processDefaultEdges) {
97
+ value = { id: id || value.tmpId };
98
+ }
99
+ else {
100
+ if (id) {
101
+ return writeRef(id, ctx, schema, def, res.tmpId, modifyOp, false, false);
102
+ }
103
+ return writeRef(value.tmpId, ctx, schema, def, res.tmpId, modifyOp, false, true);
91
104
  }
92
- return writeRef(value.tmpId, ctx, schema, def, res.tmpId, modifyOp, false, true);
93
105
  }
94
- else if (typeof value === 'object' && value !== null) {
106
+ if (typeof value === 'object') {
95
107
  if (def.edges) {
96
- return singleReferenceEdges(value, ctx, schema, def, res.tmpId, modifyOp);
108
+ return singleReferenceEdges(value, ctx, schema, def, res.tmpId, modifyOp, processDefaultEdges);
97
109
  }
98
110
  else if (typeof value.id === 'number') {
99
111
  return writeRef(value.id, ctx, schema, def, res.tmpId, modifyOp, false, false);
@@ -130,10 +130,18 @@ function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
130
130
  ctx.buf[ctx.len++] = remaining >>>= 8;
131
131
  ctx.buf[ctx.len++] = remaining >>>= 8;
132
132
  for (; i < refs.length; i++) {
133
- const ref = refs[i];
133
+ let ref = refs[i];
134
134
  let id;
135
135
  let index;
136
136
  let isTmpId;
137
+ if (def.hasDefaultEdges) {
138
+ if (typeof ref !== 'object') {
139
+ ref = { id: ref };
140
+ }
141
+ else if (ref instanceof ModifyState) {
142
+ ref = { id: ref };
143
+ }
144
+ }
137
145
  if (typeof ref === 'object') {
138
146
  if (ref instanceof ModifyState) {
139
147
  if (ref.error) {
@@ -5,6 +5,7 @@ import { modify } from './modify.js';
5
5
  import { ModifyState } from './ModifyRes.js';
6
6
  import { RANGE_ERR, UPDATE } from './types.js';
7
7
  import { appendFixedValue } from './fixed.js';
8
+ import { getByPath } from '@saulx/utils';
8
9
  const appendUpdate = (ctx, def, obj, res, overwrite) => {
9
10
  const err = modify(ctx, res, obj, def, UPDATE, def.tree, overwrite);
10
11
  if (err) {
@@ -13,6 +14,9 @@ const appendUpdate = (ctx, def, obj, res, overwrite) => {
13
14
  if (def.updateTs) {
14
15
  const updateTs = Date.now();
15
16
  for (const prop of def.updateTs) {
17
+ if (getByPath(obj, prop.path) !== undefined) {
18
+ continue;
19
+ }
16
20
  if (ctx.mergeMain) {
17
21
  ctx.mergeMain.push(prop, updateTs);
18
22
  ctx.mergeMainSize += prop.len + 4;
@@ -25,7 +25,7 @@ export declare class QueryBranch<T> {
25
25
  groupBy(field: string): T;
26
26
  count(field?: string): T;
27
27
  sum(...fields: (string | string[])[]): T;
28
- cardinality(...fields: (string | string[])[]): T;
28
+ cardinality(field: string): T;
29
29
  stddev(...fields: (string | string[])[]): T;
30
30
  var(...fields: (string | string[])[]): T;
31
31
  avg(...fields: (string | string[])[]): T;
@@ -173,18 +173,18 @@ export class QueryBranch {
173
173
  // @ts-ignore
174
174
  return this;
175
175
  }
176
- cardinality(...fields) {
177
- if (fields.length === 0) {
176
+ cardinality(field) {
177
+ if (field.length === 0) {
178
178
  throw new Error('Empty cardinality() called');
179
179
  }
180
180
  if (this.queryCommands) {
181
181
  this.queryCommands.push({
182
182
  method: 'cardinality',
183
- args: fields,
183
+ args: [field],
184
184
  });
185
185
  }
186
186
  else {
187
- addAggregate(AggregateType.CARDINALITY, this.def, fields);
187
+ addAggregate(AggregateType.CARDINALITY, this.def, [field]);
188
188
  }
189
189
  // @ts-ignore
190
190
  return this;
@@ -11,7 +11,7 @@ export declare enum AggregateType {
11
11
  export declare const enum AccumulatorSize {
12
12
  SUM = 8,
13
13
  COUNT = 4,
14
- CARDINALITY = 254,// TODO: accordinly to sparse or dense modes
14
+ CARDINALITY = 4,
15
15
  STDDEV = 24,// count (u64) + sum (f64) + sum_sq (f64) = 8 + 8 + 8 = 24
16
16
  AVERAGE = 16,// count (u64) + sum (f64) = 16
17
17
  VARIANCE = 24,// count (u64) + sum (f64) + sum_sq (f64) = 8 + 8 + 8 = 24
@@ -12,7 +12,7 @@ export var AggregateType;
12
12
  export const aggregateTypeMap = new Map([
13
13
  [
14
14
  AggregateType.CARDINALITY,
15
- { resultsSize: 4, accumulatorSize: 254 /* AccumulatorSize.CARDINALITY */ },
15
+ { resultsSize: 4, accumulatorSize: 4 /* AccumulatorSize.CARDINALITY */ },
16
16
  ],
17
17
  [
18
18
  AggregateType.COUNT,
@@ -424,7 +424,7 @@ export const handleErrors = (def) => {
424
424
  }
425
425
  const err = new Error(`Query\n`);
426
426
  err.message = name;
427
- err.stack = '';
427
+ err.stack = name;
428
428
  throw err;
429
429
  }
430
430
  };
@@ -7,6 +7,7 @@ import { foreachDirtyBlock } from '../blocks.js';
7
7
  import { fileURLToPath } from 'url';
8
8
  import { setNativeSchema, setSchemaOnServer, writeSchemaFile, } from '../schema.js';
9
9
  import { setToAwake, waitUntilSleeping } from './utils.js';
10
+ import { serialize } from '@based/schema';
10
11
  const __filename = fileURLToPath(import.meta.url);
11
12
  const __dirname = dirname(__filename);
12
13
  const workerPath = join(__dirname, 'worker.js');
@@ -74,8 +75,14 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
74
75
  isDbMigrateWorker: true,
75
76
  from: fromAddress,
76
77
  to: toAddress,
77
- fromSchema,
78
- toSchema,
78
+ fromSchema: serialize(fromSchema, {
79
+ stripMetaInformation: true,
80
+ stripTransform: true,
81
+ }),
82
+ toSchema: serialize(toSchema, {
83
+ stripMetaInformation: true,
84
+ stripTransform: true,
85
+ }),
79
86
  channel: port2,
80
87
  workerState,
81
88
  transformFns,
@@ -83,9 +90,12 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
83
90
  transferList: [port2],
84
91
  });
85
92
  // handle?
86
- worker.on('error', (err) => {
87
- killed = true;
88
- console.error(`Error in migration ${err.message}`);
93
+ const errorPromise = new Promise((resolve) => {
94
+ worker.once('error', (err) => {
95
+ killed = true;
96
+ console.error(`Error in migration ${err.message}, aborting migration`);
97
+ resolve();
98
+ });
89
99
  });
90
100
  // Block handling
91
101
  let i = 0;
@@ -107,7 +117,7 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
107
117
  const leafData = rangesToMigrate[i++];
108
118
  port1.postMessage(leafData);
109
119
  setToAwake(workerState, true);
110
- await waitUntilSleeping(workerState);
120
+ await Promise.race([errorPromise, waitUntilSleeping(workerState)]);
111
121
  // exec queued modifies
112
122
  server.activeReaders--;
113
123
  server.onQueryEnd();
@@ -156,7 +166,11 @@ export const migrate = async (server, fromSchema, toSchema, transform) => {
156
166
  return;
157
167
  }
158
168
  native.membarSyncRead();
159
- await save(server, { forceFullDump: true, skipDirtyCheck: true, skipMigrationCheck: true });
169
+ await save(server, {
170
+ forceFullDump: true,
171
+ skipDirtyCheck: true,
172
+ skipMigrationCheck: true,
173
+ });
160
174
  await writeSchemaFile(server, toSchema);
161
175
  server.migrating = 0;
162
176
  process.nextTick(() => server.emit('schema', server.schema));
@@ -6,6 +6,7 @@ import { isTypedArray } from 'node:util/types';
6
6
  import { setSchemaOnServer } from '../schema.js';
7
7
  import { setToSleep } from './utils.js';
8
8
  import { setLocalClientSchema } from '../../client/setLocalClientSchema.js';
9
+ import { deSerialize } from '@based/schema';
9
10
  if (isMainThread) {
10
11
  console.warn('running worker.ts in mainthread');
11
12
  }
@@ -41,80 +42,87 @@ else if (workerData?.isDbMigrateWorker) {
41
42
  };
42
43
  fromDb.server.dbCtxExternal = fromCtx;
43
44
  toDb.server.dbCtxExternal = toCtx;
44
- setSchemaOnServer(fromDb.server, fromSchema);
45
- setSchemaOnServer(toDb.server, toSchema);
45
+ setSchemaOnServer(fromDb.server, deSerialize(fromSchema));
46
+ setSchemaOnServer(toDb.server, deSerialize(toSchema));
46
47
  setLocalClientSchema(fromDb.client, fromDb.server.schema);
47
48
  setLocalClientSchema(toDb.client, toDb.server.schema);
48
- const map = {};
49
- for (const type in fromDb.server.schemaTypesParsed) {
50
- const { id, props } = fromDb.server.schemaTypesParsed[type];
51
- const include = Object.keys(props);
52
- let i = include.length;
53
- while (i--) {
54
- const path = include[i];
55
- if (props[path].typeIndex === REFERENCE ||
56
- props[path].typeIndex === REFERENCES) {
57
- include[i] = `${path}.id`;
58
- if (props[path].edges) {
59
- for (const key in props[path].edges) {
60
- const prop = props[path].edges[key];
61
- if (prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES) {
62
- include.push(`${path}.${key}.id`);
63
- }
64
- else {
65
- include.push(`${path}.${key}`);
49
+ try {
50
+ const map = {};
51
+ for (const type in fromDb.server.schemaTypesParsed) {
52
+ const { id, props } = fromDb.server.schemaTypesParsed[type];
53
+ const include = Object.keys(props);
54
+ let i = include.length;
55
+ while (i--) {
56
+ const path = include[i];
57
+ if (props[path].typeIndex === REFERENCE ||
58
+ props[path].typeIndex === REFERENCES) {
59
+ include[i] = `${path}.id`;
60
+ if (props[path].edges) {
61
+ for (const key in props[path].edges) {
62
+ const prop = props[path].edges[key];
63
+ if (prop.typeIndex === REFERENCE ||
64
+ prop.typeIndex === REFERENCES) {
65
+ include.push(`${path}.${key}.id`);
66
+ }
67
+ else {
68
+ include.push(`${path}.${key}`);
69
+ }
66
70
  }
67
71
  }
68
72
  }
69
73
  }
74
+ map[id] = { type, include };
70
75
  }
71
- map[id] = { type, include };
72
- }
73
- for (const type in transformFns) {
74
- const fnOrNull = transformFns[type];
75
- transformFns[type] = eval(`(${fnOrNull})`);
76
- }
77
- while (true) {
78
- let msg;
79
- while ((msg = receiveMessageOnPort(channel))) {
80
- const leafData = msg.message;
81
- const { type, include } = map[leafData.typeId];
82
- const typeTransformFn = transformFns[type];
83
- if (typeTransformFn) {
84
- const nodes = fromDb
85
- .query(type)
86
- .include(include)
87
- .range(leafData.start - 1, leafData.end)
88
- ._getSync(fromCtx);
89
- for (const node of nodes) {
90
- const res = typeTransformFn(node);
91
- if (res === null) {
92
- continue;
93
- }
94
- if (Array.isArray(res)) {
95
- toDb.create(res[0], res[1] || node, { unsafe: true });
96
- }
97
- else {
98
- toDb.create(type, res || node, { unsafe: true });
76
+ for (const type in transformFns) {
77
+ const fnOrNull = transformFns[type];
78
+ transformFns[type] = eval(`(${fnOrNull})`);
79
+ }
80
+ while (true) {
81
+ let msg;
82
+ while ((msg = receiveMessageOnPort(channel))) {
83
+ const leafData = msg.message;
84
+ const { type, include } = map[leafData.typeId];
85
+ const typeTransformFn = transformFns[type];
86
+ if (typeTransformFn) {
87
+ const nodes = fromDb
88
+ .query(type)
89
+ .include(include)
90
+ .range(leafData.start - 1, leafData.end)
91
+ ._getSync(fromCtx);
92
+ for (const node of nodes) {
93
+ const res = typeTransformFn(node);
94
+ if (res === null) {
95
+ continue;
96
+ }
97
+ if (Array.isArray(res)) {
98
+ toDb.create(res[0], res[1] || node, { unsafe: true });
99
+ }
100
+ else {
101
+ toDb.create(type, res || node, { unsafe: true });
102
+ }
99
103
  }
100
104
  }
101
- }
102
- else if (type in toDb.server.schemaTypesParsed) {
103
- const nodes = fromDb
104
- .query(type)
105
- .include(include)
106
- .range(leafData.start - 1, leafData.end)
107
- ._getSync(fromCtx);
108
- for (const node of nodes) {
109
- toDb.create(type, node, { unsafe: true });
105
+ else if (type in toDb.server.schemaTypesParsed) {
106
+ const nodes = fromDb
107
+ .query(type)
108
+ .include(include)
109
+ .range(leafData.start - 1, leafData.end)
110
+ ._getSync(fromCtx);
111
+ for (const node of nodes) {
112
+ toDb.create(type, node, { unsafe: true });
113
+ }
110
114
  }
111
115
  }
116
+ await toDb.drain();
117
+ native.membarSyncWrite();
118
+ // WE ARE ONLY GOING TO SEND { type: lastNodeId }
119
+ channel.postMessage(cp(toDb.server.schemaTypesParsed));
120
+ setToSleep(workerState);
112
121
  }
113
- await toDb.drain();
114
- native.membarSyncWrite();
115
- // WE ARE ONLY GOING TO SEND { type: lastNodeId }
116
- channel.postMessage(cp(toDb.server.schemaTypesParsed));
117
- setToSleep(workerState);
122
+ }
123
+ catch (e) {
124
+ console.error(e);
125
+ throw e;
118
126
  }
119
127
  }
120
128
  else {
@@ -2,17 +2,18 @@ import native from '../native.js';
2
2
  import { isMainThread } from 'node:worker_threads';
3
3
  import { writeFile } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
- import { VerifTree, destructureTreeKey, } from './tree.js';
5
+ import { VerifTree, destructureTreeKey } from './tree.js';
6
6
  import { saveBlock, foreachBlock, foreachDirtyBlock, saveBlocks, } from './blocks.js';
7
7
  import { writeFileSync } from 'node:fs';
8
8
  import { bufToHex } from '@saulx/utils';
9
9
  import { COMMON_SDB_FILE, WRITELOG_FILE } from '../types.js';
10
10
  function hasPartialTypes(db) {
11
- let res = false;
12
- for (let id in db.schemaTypesParsedById) {
13
- res = res || db.schemaTypesParsedById[id].partial;
11
+ for (const id in db.schemaTypesParsedById) {
12
+ if (db.schemaTypesParsedById[id].partial) {
13
+ return true;
14
+ }
14
15
  }
15
- return res;
16
+ return false;
16
17
  }
17
18
  function inhibitSave(db, { skipDirtyCheck, forceFullDump, skipMigrationCheck }) {
18
19
  // RFE isMainThread needed??
@@ -138,7 +139,7 @@ export async function save(db, opts = {}) {
138
139
  blocks.push({
139
140
  filepath,
140
141
  typeId,
141
- start
142
+ start,
142
143
  });
143
144
  });
144
145
  }
@@ -15,12 +15,14 @@ export const setSchemaOnServer = (server, schema) => {
15
15
  server.schemaTypesParsedById = schemaTypesParsedById;
16
16
  };
17
17
  export const writeSchemaFile = async (server, schema) => {
18
- const schemaFilePath = join(server.fileSystemPath, SCHEMA_FILE);
19
- try {
20
- await writeFile(schemaFilePath, serialize(schema));
21
- }
22
- catch (err) {
23
- throw new Error(`Error writing schema to a file path ${schemaFilePath}}`);
18
+ if (server.fileSystemPath) {
19
+ const schemaFilePath = join(server.fileSystemPath, SCHEMA_FILE);
20
+ try {
21
+ await writeFile(schemaFilePath, serialize(schema));
22
+ }
23
+ catch (err) {
24
+ throw new Error(`Error writing schema to a file path ${schemaFilePath}}`);
25
+ }
24
26
  }
25
27
  };
26
28
  export const setNativeSchema = (server, schema) => {
@@ -3,7 +3,7 @@ export declare const SCHEMA_FILE = "schema.bin";
3
3
  export declare const WRITELOG_FILE = "writelog.json";
4
4
  export declare const COMMON_SDB_FILE = "common.sdb";
5
5
  export type BasedDbOpts = {
6
- path: string;
6
+ path: string | null;
7
7
  maxModifySize?: number;
8
8
  debug?: boolean | 'server' | 'client';
9
9
  saveIntervalInSeconds?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
@@ -39,7 +39,7 @@
39
39
  "basedDbNative.cjs"
40
40
  ],
41
41
  "dependencies": {
42
- "@based/schema": "5.0.0-alpha.25",
42
+ "@based/schema": "5.0.0-alpha.27",
43
43
  "@saulx/hash": "^3.0.0",
44
44
  "@saulx/utils": "^6.7.2",
45
45
  "exit-hook": "^4.0.0",
@@ -56,6 +56,7 @@
56
56
  "axios": "^1.7.9",
57
57
  "rimraf": "^3.0.2",
58
58
  "tar": "^7.4.3",
59
- "typescript": "^5.6.3"
59
+ "typescript": "^5.6.3",
60
+ "fs-extra": "^11.1.1"
60
61
  }
61
62
  }