@based/db 0.0.32 → 0.0.34

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 (125) 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/libselva.dylib +0 -0
  8. package/dist/lib/linux_aarch64/include/cdefs.h +317 -0
  9. package/dist/lib/linux_aarch64/include/jemalloc.h +468 -0
  10. package/dist/lib/linux_aarch64/include/libdeflate.h +322 -0
  11. package/dist/lib/linux_aarch64/include/libdeflate_strings.h +35 -0
  12. package/dist/lib/linux_aarch64/include/linker_set.h +109 -0
  13. package/dist/lib/linux_aarch64/include/queue.h +627 -0
  14. package/dist/lib/linux_aarch64/include/selva/_export.h +7 -0
  15. package/dist/lib/linux_aarch64/include/selva/align.h +9 -0
  16. package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +29 -0
  17. package/dist/lib/linux_aarch64/include/selva/bitmap.h +95 -0
  18. package/dist/lib/linux_aarch64/include/selva/crc32c.h +17 -0
  19. package/dist/lib/linux_aarch64/include/selva/ctime.h +135 -0
  20. package/dist/lib/linux_aarch64/include/selva/db.h +418 -0
  21. package/dist/lib/linux_aarch64/include/selva/endian.h +301 -0
  22. package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +23 -0
  23. package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +18 -0
  24. package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +11 -0
  25. package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +36 -0
  26. package/dist/lib/linux_aarch64/include/selva/fields.h +381 -0
  27. package/dist/lib/linux_aarch64/include/selva/find.h +47 -0
  28. package/dist/lib/linux_aarch64/include/selva/history.h +64 -0
  29. package/dist/lib/linux_aarch64/include/selva/hll.h +81 -0
  30. package/dist/lib/linux_aarch64/include/selva/lpf.h +28 -0
  31. package/dist/lib/linux_aarch64/include/selva/node_id_set.h +43 -0
  32. package/dist/lib/linux_aarch64/include/selva/poptop.h +114 -0
  33. package/dist/lib/linux_aarch64/include/selva/queue_r.h +190 -0
  34. package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +49 -0
  35. package/dist/lib/linux_aarch64/include/selva/selva_lang.h +105 -0
  36. package/dist/lib/linux_aarch64/include/selva/selva_math.h +37 -0
  37. package/dist/lib/linux_aarch64/include/selva/selva_string.h +674 -0
  38. package/dist/lib/linux_aarch64/include/selva/sort.h +140 -0
  39. package/dist/lib/linux_aarch64/include/selva/strsearch.h +43 -0
  40. package/dist/lib/linux_aarch64/include/selva/timestamp.h +25 -0
  41. package/dist/lib/linux_aarch64/include/selva/traverse.h +65 -0
  42. package/dist/lib/linux_aarch64/include/selva/types.h +106 -0
  43. package/dist/lib/linux_aarch64/include/selva/vector.h +35 -0
  44. package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +13 -0
  45. package/dist/lib/linux_aarch64/include/selva_error.h +137 -0
  46. package/dist/lib/linux_aarch64/include/selva_lang_code.h +157 -0
  47. package/dist/lib/linux_aarch64/include/tree.h +852 -0
  48. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  49. package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
  50. package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
  51. package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
  52. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  53. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  54. package/dist/lib/linux_aarch64/libselva.so +0 -0
  55. package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
  56. package/dist/lib/linux_x86_64/include/cdefs.h +317 -0
  57. package/dist/lib/linux_x86_64/include/jemalloc.h +468 -0
  58. package/dist/lib/linux_x86_64/include/libdeflate.h +322 -0
  59. package/dist/lib/linux_x86_64/include/libdeflate_strings.h +35 -0
  60. package/dist/lib/linux_x86_64/include/linker_set.h +109 -0
  61. package/dist/lib/linux_x86_64/include/queue.h +627 -0
  62. package/dist/lib/linux_x86_64/include/selva/_export.h +7 -0
  63. package/dist/lib/linux_x86_64/include/selva/align.h +9 -0
  64. package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +29 -0
  65. package/dist/lib/linux_x86_64/include/selva/bitmap.h +95 -0
  66. package/dist/lib/linux_x86_64/include/selva/crc32c.h +17 -0
  67. package/dist/lib/linux_x86_64/include/selva/ctime.h +135 -0
  68. package/dist/lib/linux_x86_64/include/selva/db.h +418 -0
  69. package/dist/lib/linux_x86_64/include/selva/endian.h +301 -0
  70. package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +23 -0
  71. package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +18 -0
  72. package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +11 -0
  73. package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +36 -0
  74. package/dist/lib/linux_x86_64/include/selva/fields.h +381 -0
  75. package/dist/lib/linux_x86_64/include/selva/find.h +47 -0
  76. package/dist/lib/linux_x86_64/include/selva/history.h +64 -0
  77. package/dist/lib/linux_x86_64/include/selva/hll.h +81 -0
  78. package/dist/lib/linux_x86_64/include/selva/lpf.h +28 -0
  79. package/dist/lib/linux_x86_64/include/selva/node_id_set.h +43 -0
  80. package/dist/lib/linux_x86_64/include/selva/poptop.h +114 -0
  81. package/dist/lib/linux_x86_64/include/selva/queue_r.h +190 -0
  82. package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +49 -0
  83. package/dist/lib/linux_x86_64/include/selva/selva_lang.h +105 -0
  84. package/dist/lib/linux_x86_64/include/selva/selva_math.h +37 -0
  85. package/dist/lib/linux_x86_64/include/selva/selva_string.h +674 -0
  86. package/dist/lib/linux_x86_64/include/selva/sort.h +140 -0
  87. package/dist/lib/linux_x86_64/include/selva/strsearch.h +43 -0
  88. package/dist/lib/linux_x86_64/include/selva/timestamp.h +25 -0
  89. package/dist/lib/linux_x86_64/include/selva/traverse.h +65 -0
  90. package/dist/lib/linux_x86_64/include/selva/types.h +106 -0
  91. package/dist/lib/linux_x86_64/include/selva/vector.h +35 -0
  92. package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +13 -0
  93. package/dist/lib/linux_x86_64/include/selva_error.h +137 -0
  94. package/dist/lib/linux_x86_64/include/selva_lang_code.h +157 -0
  95. package/dist/lib/linux_x86_64/include/tree.h +852 -0
  96. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  97. package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
  98. package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
  99. package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
  100. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  101. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  102. package/dist/lib/linux_x86_64/libselva.so +0 -0
  103. package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
  104. package/dist/src/client/flushModify.d.ts +1 -1
  105. package/dist/src/client/modify/create.js +3 -4
  106. package/dist/src/client/modify/references/references.js +1 -1
  107. package/dist/src/client/modify/setCursor.js +0 -4
  108. package/dist/src/client/modify/text.js +1 -1
  109. package/dist/src/client/modify/update.js +2 -1
  110. package/dist/src/client/modify/upsert.js +1 -0
  111. package/dist/src/client/query/aggregation.d.ts +1 -1
  112. package/dist/src/client/query/read/read.js +5 -4
  113. package/dist/src/client/query/search/index.d.ts +1 -1
  114. package/dist/src/client/query/sort.d.ts +1 -1
  115. package/dist/src/client/string.d.ts +1 -1
  116. package/dist/src/client/string.js +9 -4
  117. package/dist/src/client/xxHash64.d.ts +1 -1
  118. package/dist/src/server/csmt/match.d.ts +1 -1
  119. package/dist/src/server/dbHash.d.ts +1 -1
  120. package/dist/src/server/index.d.ts +2 -2
  121. package/package.json +1 -1
  122. package/dist/src/client/query/aggregates/aggregation.d.ts +0 -4
  123. package/dist/src/client/query/aggregates/aggregation.js +0 -12
  124. package/dist/src/client/tmpBuffer.d.ts +0 -3
  125. package/dist/src/client/tmpBuffer.js +0 -20
@@ -26,7 +26,7 @@ export declare class ModifyCtx {
26
26
  markNodeDirty(schema: SchemaTypeDef, nodeId: number): void;
27
27
  markTypeDirty(schema: SchemaTypeDef): void;
28
28
  updateMax(): void;
29
- getData(lastIds: Record<number, number>): Uint8Array<ArrayBufferLike>;
29
+ getData(lastIds: Record<number, number>): Uint8Array;
30
30
  }
31
31
  export declare const flushBuffer: (db: DbClient) => Promise<void>;
32
32
  export declare const startDrain: (db: DbClient) => void;
@@ -148,12 +148,11 @@ export function create(db, type, obj, opts) {
148
148
  flushBuffer(db);
149
149
  return db.create(type, obj, opts);
150
150
  }
151
- // res.error = err
152
- // @ts-ignore
153
- // return Promise.reject(err)
154
- // return res
151
+ res.error = err;
155
152
  throw err;
156
153
  }
154
+ ctx.markTypeDirty(def);
155
+ ctx.markNodeDirty(def, id);
157
156
  if (!db.isDraining) {
158
157
  startDrain(db);
159
158
  }
@@ -53,7 +53,7 @@ export const dbUpdateFromUpsert = (ctx, schema, def, res, promise) => {
53
53
  payload = payload[def.path[i]] = {};
54
54
  }
55
55
  payload[def.path[i]] = result;
56
- return ctx.db.update(schema.type, res.tmpId, payload);
56
+ return ctx.db.update(schema.type, res.getId(), payload);
57
57
  }));
58
58
  };
59
59
  function deleteRefs(def, ctx, schema, modifyOp, refs, parentId) {
@@ -12,9 +12,6 @@ typeIndex, id, modifyOp, ignoreField) => {
12
12
  ctx.field = -1;
13
13
  ctx.id = -1;
14
14
  ctx.lastMain = -1;
15
- if (modifyOp === CREATE) {
16
- ctx.markTypeDirty(schema);
17
- }
18
15
  }
19
16
  if (!ignoreField && ctx.field !== field) {
20
17
  ctx.buf[ctx.len++] = SWITCH_FIELD; // switch field
@@ -23,7 +20,6 @@ typeIndex, id, modifyOp, ignoreField) => {
23
20
  ctx.field = field;
24
21
  }
25
22
  if (ctx.id !== id) {
26
- ctx.markNodeDirty(schema, id);
27
23
  ctx.id = id;
28
24
  ctx.lastMain = -1;
29
25
  ctx.buf[ctx.len++] =
@@ -25,7 +25,7 @@ export function writeText(value, ctx, def, t, res, parentId, modifyOp) {
25
25
  if (!def.seperateTextSort.localeToIndex.has(locale)) {
26
26
  return new ModifyError(t, locale, 'Invalid locale');
27
27
  }
28
- const err = writeString(res.locale, value, ctx, def, t, res.tmpId, modifyOp);
28
+ const err = writeString(locale, value, ctx, def, t, res.tmpId, modifyOp);
29
29
  if (modifyOp === CREATE) {
30
30
  const index = t.prop * (def.localeSize + 1);
31
31
  const langIndex = def.seperateTextSort.localeToIndex.get(locale);
@@ -73,9 +73,10 @@ export const update = (db, type, id, obj, opts) => {
73
73
  flushBuffer(db);
74
74
  return update(db, type, id, obj, opts);
75
75
  }
76
- // res.error = err
76
+ res.error = err;
77
77
  throw err;
78
78
  }
79
+ ctx.markNodeDirty(def, id);
79
80
  if (!db.isDraining) {
80
81
  startDrain(db);
81
82
  }
@@ -43,6 +43,7 @@ export async function upsert(db, type, obj, opts) {
43
43
  else {
44
44
  const obj = res.toObject();
45
45
  const id = Array.isArray(obj) ? obj[0].id : obj.id;
46
+ // don't call update if it's not necessary
46
47
  return db.update(type, id, store.o, opts);
47
48
  }
48
49
  }),
@@ -1,3 +1,3 @@
1
1
  import { QueryDef, AggFlag } from './types.js';
2
- export declare const createAggFlagBuffer: (aggregation: AggFlag) => Uint8Array<ArrayBuffer>;
2
+ export declare const createAggFlagBuffer: (aggregation: AggFlag) => Uint8Array;
3
3
  export declare const count: (def: QueryDef) => void;
@@ -243,7 +243,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
243
243
  addField(edgeDef, '', item);
244
244
  }
245
245
  else {
246
- addField(edgeDef, read(result, i + 4, size), item);
246
+ addField(edgeDef, read(result, i + 4, size, true), item);
247
247
  }
248
248
  i += size + 4;
249
249
  }
@@ -341,21 +341,22 @@ export const readAllFields = (q, result, offset, end, item, id) => {
341
341
  addField(prop, '', item);
342
342
  }
343
343
  else {
344
- addField(prop, read(result, i + 4, size), item);
344
+ addField(prop, read(result, i + 4, size, true), item);
345
345
  }
346
346
  i += size + 4;
347
347
  }
348
348
  else if (prop.typeIndex == TEXT) {
349
349
  const size = readUint32(result, i);
350
350
  if (size === 0) {
351
+ // do nothing
351
352
  }
352
353
  else {
353
354
  if (q.lang != 0) {
354
355
  q.include.propsRead[index] = id;
355
- addField(prop, read(result, i + 4, size), item);
356
+ addField(prop, read(result, i + 4, size, false), item);
356
357
  }
357
358
  else {
358
- addField(prop, read(result, i + 4, size), item, false, result[i + 4]);
359
+ addField(prop, read(result, i + 4, size, false), item, false, result[i + 4]);
359
360
  }
360
361
  }
361
362
  i += size + 4;
@@ -5,4 +5,4 @@ export type Search = string[] | {
5
5
  } | string;
6
6
  export declare const vectorSearch: (def: QueryDef, q: ArrayBufferView, field: string, opts: Omit<FilterOpts, "lowerCase">) => void;
7
7
  export declare const search: (def: QueryDef, q: string, s?: Search) => void;
8
- export declare const searchToBuffer: (search: QueryDefSearch) => Uint8Array<ArrayBuffer>;
8
+ export declare const searchToBuffer: (search: QueryDefSearch) => Uint8Array;
@@ -1,3 +1,3 @@
1
1
  import { QueryDef, QueryDefSort } from './types.js';
2
- export declare const createSortBuffer: (sort: QueryDefSort) => Uint8Array<ArrayBuffer>;
2
+ export declare const createSortBuffer: (sort: QueryDefSort) => Uint8Array;
3
3
  export declare const sort: (def: QueryDef, field: string, order?: "asc" | "desc") => void;
@@ -4,5 +4,5 @@ export declare const NOT_COMPRESSED = 0;
4
4
  export declare const write: (buf: Uint8Array, value: string, offset: number, noCompression: boolean, lang?: LangCode) => number;
5
5
  export declare const compress: (str: string) => Uint8Array;
6
6
  export declare const decompress: (val: Uint8Array) => string;
7
- export declare const read: (val: Uint8Array, offset: number, len: number) => string;
7
+ export declare const read: (val: Uint8Array, offset: number, len: number, stripCrc32: boolean) => string;
8
8
  export declare const readUtf8: (val: Uint8Array, offset: number, len: number) => string;
@@ -53,19 +53,24 @@ export const compress = (str) => {
53
53
  return nBuffer;
54
54
  };
55
55
  export const decompress = (val) => {
56
- return read(val, 0, val.length);
56
+ return read(val, 0, val.length, false);
57
57
  };
58
- export const read = (val, offset, len) => {
58
+ export const read = (val, offset, len, stripCrc32) => {
59
59
  const type = val[offset + 1];
60
60
  if (type == COMPRESSED) {
61
61
  const origSize = readUint32(val, offset + 2);
62
62
  const newBuffer = getTmpBuffer(origSize);
63
63
  // Browser fallback required for this
64
- native.decompress(val, newBuffer, offset + 6, len - 6);
64
+ native.decompress(val, newBuffer, offset + 6, stripCrc32 ? len - 2 : len - 6);
65
65
  return DECODER.decode(newBuffer);
66
66
  }
67
67
  else if (type == NOT_COMPRESSED) {
68
- return DECODER.decode(val.subarray(offset + 2, len + offset - 4));
68
+ if (stripCrc32) {
69
+ return DECODER.decode(val.subarray(offset + 2, len + offset));
70
+ }
71
+ else {
72
+ return DECODER.decode(val.subarray(offset + 2, len + offset - 4));
73
+ }
69
74
  }
70
75
  return '';
71
76
  };
@@ -1 +1 @@
1
- export declare const xxHash64: (buf: Uint8Array, target?: Uint8Array, index?: number) => Uint8Array<ArrayBufferLike>;
1
+ export declare const xxHash64: (buf: Uint8Array, target?: Uint8Array, index?: number) => Uint8Array;
@@ -1,7 +1,7 @@
1
1
  type Predicate = (x: any) => boolean;
2
2
  type Func = (x: any) => any;
3
3
  declare const match: (x: any) => {
4
- on: (pred: Predicate, fn: Func) => /*elided*/ any;
4
+ on: (pred: Predicate, fn: Func) => any;
5
5
  otherwise: (fn: Func) => any;
6
6
  };
7
7
  export default match;
@@ -1,5 +1,5 @@
1
1
  export default function createHash(): {
2
- update: (buf: Uint8Array) => /*elided*/ any;
2
+ update: (buf: Uint8Array) => any;
3
3
  digest: (encoding?: "hex") => Uint8Array | string;
4
4
  reset: () => void;
5
5
  };
@@ -39,7 +39,7 @@ export declare class DbServer {
39
39
  merkleTree: ReturnType<typeof createTree<CsmtNodeRange>>;
40
40
  dirtyRanges: Set<number>;
41
41
  csmtHashFun: {
42
- update: (buf: Uint8Array) => /*elided*/ any;
42
+ update: (buf: Uint8Array) => any;
43
43
  digest: (encoding?: "hex") => Uint8Array | string;
44
44
  reset: () => void;
45
45
  };
@@ -68,7 +68,7 @@ export declare class DbServer {
68
68
  forceFullDump?: boolean;
69
69
  }): Promise<void>;
70
70
  createCsmtHashFun: () => {
71
- update: (buf: Uint8Array) => /*elided*/ any;
71
+ update: (buf: Uint8Array) => any;
72
72
  digest: (encoding?: "hex") => Uint8Array | string;
73
73
  reset: () => void;
74
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
@@ -1,4 +0,0 @@
1
- import { QueryDef, AggFlag } from '../types.js';
2
- export declare const createAggFlagBuffer: (aggregation: AggFlag) => Uint8Array;
3
- export declare const count: (def: QueryDef) => void;
4
- export declare const sum: (def: QueryDef) => void;
@@ -1,12 +0,0 @@
1
- export const createAggFlagBuffer = (aggregation) => {
2
- const buf = new Uint8Array(1);
3
- buf[0] = aggregation;
4
- return buf;
5
- };
6
- export const count = (def) => {
7
- def.aggregation = 4 /* AggFlag.COUNT */;
8
- };
9
- export const sum = (def) => {
10
- def.aggregation = 11 /* AggFlag.SUM */;
11
- };
12
- //# sourceMappingURL=aggregation.js.map
@@ -1,3 +0,0 @@
1
- export default function makeTmpBuffer(initialSize: number): {
2
- getUint8Array: (size: number) => Uint8Array;
3
- };
@@ -1,20 +0,0 @@
1
- export default function makeTmpBuffer(initialSize) {
2
- // @ts-ignore
3
- let tmpBuffer = new ArrayBuffer(initialSize, { maxByteLength: initialSize });
4
- return {
5
- getUint8Array: (size) => {
6
- const opts = {
7
- maxByteLength: Math.min(Math.round(1.5 * size), 274877906944)
8
- };
9
- // @ts-ignore
10
- if (tmpBuffer.maxByteLength < size) {
11
- // @ts-ignore
12
- tmpBuffer = new ArrayBuffer(size, opts);
13
- }
14
- // @ts-ignore
15
- tmpBuffer.resize(size);
16
- return new Uint8Array(tmpBuffer);
17
- }
18
- };
19
- }
20
- //# sourceMappingURL=tmpBuffer.js.map