@based/db 0.0.40 → 0.0.42

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 (30) hide show
  1. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  2. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  3. package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
  4. package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
  5. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  6. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  7. package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
  8. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  9. package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
  10. package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
  11. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  12. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  13. package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
  14. package/dist/lib/linux_aarch64/libselva.so +0 -0
  15. package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
  16. package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
  17. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  18. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  19. package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
  20. package/dist/lib/linux_x86_64/libselva.so +0 -0
  21. package/dist/src/client/modify/references/appendEdgeRefs.d.ts +3 -3
  22. package/dist/src/client/modify/references/appendEdgeRefs.js +1 -1
  23. package/dist/src/client/query/read/read.js +4 -4
  24. package/dist/src/index.d.ts +1 -0
  25. package/dist/src/index.js +1 -0
  26. package/dist/src/server/index.d.ts +4 -0
  27. package/dist/src/server/index.js +3 -0
  28. package/dist/src/server/start.js +1 -1
  29. package/dist/src/utils.js +1 -1
  30. package/package.json +1 -1
Binary file
Binary file
@@ -1,4 +1,4 @@
1
- import { PropDefEdge } from '@based/schema/def';
2
- import { ModifyCtx } from '../../flushModify.js';
3
- import { ModifyErr } from '../types.js';
1
+ import type { PropDefEdge } from '@based/schema/def';
2
+ import type { ModifyCtx } from '../../flushModify.js';
3
+ import type { ModifyErr } from '../types.js';
4
4
  export declare function appendEdgeRefs(t: PropDefEdge, ctx: ModifyCtx, value: any[]): ModifyErr;
@@ -1,4 +1,4 @@
1
- import { ModifyState, ModifyError } from '../ModifyRes.js';
1
+ import { ModifyError, ModifyState } from '../ModifyRes.js';
2
2
  export function appendEdgeRefs(t, ctx, value) {
3
3
  for (let i = 0; i < value.length; i++) {
4
4
  let id = value[i];
@@ -227,12 +227,12 @@ export const readAllFields = (q, result, offset, end, item, id) => {
227
227
  const t = edgeDef.typeIndex;
228
228
  if (t === JSON) {
229
229
  const size = readUint32(result, i);
230
- addField(edgeDef, global.JSON.parse(readUtf8(result, i + 6, size + i)), item);
230
+ addField(edgeDef, global.JSON.parse(read(result, i + 4, size, true)), item);
231
231
  i += size + 4;
232
232
  }
233
233
  else if (t === BINARY) {
234
234
  const size = readUint32(result, i);
235
- addField(edgeDef, result.subarray(i + 6, size + i), item);
235
+ addField(edgeDef, result.subarray(i + 6, size + i + 4), item);
236
236
  i += size + 4;
237
237
  }
238
238
  else if (t === STRING || t === ALIAS || t === ALIASES) {
@@ -302,13 +302,13 @@ export const readAllFields = (q, result, offset, end, item, id) => {
302
302
  else if (prop.typeIndex === JSON) {
303
303
  q.include.propsRead[index] = id;
304
304
  const size = readUint32(result, i);
305
- addField(prop, global.JSON.parse(readUtf8(result, i + 6, size - 6)), item);
305
+ addField(prop, global.JSON.parse(read(result, i + 4, size, true)), item);
306
306
  i += size + 4;
307
307
  }
308
308
  else if (prop.typeIndex === BINARY) {
309
309
  q.include.propsRead[index] = id;
310
310
  const size = readUint32(result, i);
311
- addField(prop, result.subarray(i + 6, i + size), item);
311
+ addField(prop, result.subarray(i + 6, i + size + 4), item);
312
312
  i += size + 4;
313
313
  }
314
314
  else if (prop.typeIndex === STRING) {
@@ -8,6 +8,7 @@ export { ModifyCtx };
8
8
  export { DbClient, DbServer };
9
9
  export { xxHash64 } from './client/xxHash64.js';
10
10
  export { crc32 } from './client/crc32.js';
11
+ export { default as createHash } from './server/dbHash.js';
11
12
  export * from './client/query/serialize.js';
12
13
  export * from './utils.js';
13
14
  export * from './client/query/query.js';
package/dist/src/index.js CHANGED
@@ -11,6 +11,7 @@ export { ModifyCtx }; // TODO move this somewhere
11
11
  export { DbClient, DbServer };
12
12
  export { xxHash64 } from './client/xxHash64.js';
13
13
  export { crc32 } from './client/crc32.js';
14
+ export { default as createHash } from './server/dbHash.js';
14
15
  export * from './client/query/serialize.js';
15
16
  export * from './utils.js';
16
17
  export * from './client/query/query.js';
@@ -30,6 +30,7 @@ export declare class DbServer {
30
30
  dbCtxExternal: any;
31
31
  schema: StrictSchema & {
32
32
  lastId: number;
33
+ hash?: number;
33
34
  };
34
35
  migrating: number;
35
36
  schemaTypesParsed: SchemaTypesParsed;
@@ -88,12 +89,15 @@ export declare class DbServer {
88
89
  getSortIndex(typeId: number, field: number, start: number, lang: number): SortIndex;
89
90
  migrateSchema(schema: StrictSchema, transform?: Record<string, (node: Record<string, any>) => Record<string, any> | [string, Record<string, any>]>): Promise<StrictSchema & {
90
91
  lastId: number;
92
+ hash?: number;
91
93
  }>;
92
94
  createSortIndexBuffer(typeId: number, field: number, start: number, lang: number): SortIndex;
93
95
  setSchema(strictSchema: StrictSchema, fromStart?: boolean, transformFns?: TransformFns): (StrictSchema & {
94
96
  lastId: number;
97
+ hash?: number;
95
98
  }) | Promise<StrictSchema & {
96
99
  lastId: number;
100
+ hash?: number;
97
101
  }>;
98
102
  modify(buf: Uint8Array): Record<number, number>;
99
103
  addToQueryQueue(resolve: any, buf: any): void;
@@ -12,6 +12,7 @@ import { fileURLToPath } from 'node:url';
12
12
  import { setTimeout } from 'node:timers/promises';
13
13
  import { migrate } from './migrate/index.js';
14
14
  import { debugServer, schemaLooseEqual } from '../utils.js';
15
+ import { hash } from '@saulx/hash';
15
16
  export const SCHEMA_FILE = 'schema.json';
16
17
  export const WRITELOG_FILE = 'writelog.json';
17
18
  const __filename = fileURLToPath(import.meta.url);
@@ -339,6 +340,8 @@ export class DbServer {
339
340
  }
340
341
  }
341
342
  updateTypeDefs(this.schema, this.schemaTypesParsed, this.schemaTypesParsedById);
343
+ const { hash: _, ...schemaWithoutHash } = this.schema;
344
+ this.schema.hash = hash(schemaWithoutHash);
342
345
  if (!fromStart) {
343
346
  writeFile(join(this.fileSystemPath, SCHEMA_FILE), JSON.stringify(this.schema)).catch((err) => console.error('!!!', SCHEMA_FILE, err));
344
347
  let types = Object.keys(this.schemaTypesParsed);
@@ -47,7 +47,7 @@ export async function start(db, opts) {
47
47
  const schema = await readFile(join(path, SCHEMA_FILE));
48
48
  if (schema) {
49
49
  // Prop need to not call setting in selva
50
- db.setSchema(JSON.parse(schema.toString()), true);
50
+ await db.setSchema(JSON.parse(schema.toString()), true);
51
51
  }
52
52
  }
53
53
  catch (err) {
package/dist/src/utils.js CHANGED
@@ -43,7 +43,7 @@ export const debugMode = (target, getInfo = null) => {
43
43
  }
44
44
  };
45
45
  export const debugServer = (server) => debugMode(server, () => `p: ${server.processingQueries} m: ${server.modifyQueue.length} q: ${server.queryQueue.size}`);
46
- const exclude = new Set(['id', 'lastId']);
46
+ const exclude = new Set(['id', 'lastId', 'hash']);
47
47
  export const schemaLooseEqual = (a, b, key) => {
48
48
  if (a === b) {
49
49
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",