@based/db 0.0.26 → 0.0.27

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 (68) hide show
  1. package/dist/lib/darwin_aarch64/include/cdefs.h +1 -1
  2. package/dist/lib/darwin_aarch64/include/selva/db.h +11 -11
  3. package/dist/lib/darwin_aarch64/include/selva/fields.h +47 -12
  4. package/dist/lib/darwin_aarch64/include/selva/hll.h +59 -0
  5. package/dist/lib/darwin_aarch64/include/selva/types.h +2 -0
  6. package/dist/lib/darwin_aarch64/include/tree.h +69 -69
  7. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  8. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  9. package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
  10. package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
  11. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  12. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  13. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  14. package/dist/lib/linux_aarch64/include/cdefs.h +1 -1
  15. package/dist/lib/linux_aarch64/include/selva/db.h +11 -11
  16. package/dist/lib/linux_aarch64/include/selva/fields.h +47 -12
  17. package/dist/lib/linux_aarch64/include/selva/hll.h +59 -0
  18. package/dist/lib/linux_aarch64/include/selva/types.h +2 -0
  19. package/dist/lib/linux_aarch64/include/tree.h +69 -69
  20. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  21. package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
  22. package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
  23. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  24. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  25. package/dist/lib/linux_aarch64/libselva.so +0 -0
  26. package/dist/lib/linux_x86_64/include/cdefs.h +1 -1
  27. package/dist/lib/linux_x86_64/include/selva/db.h +11 -11
  28. package/dist/lib/linux_x86_64/include/selva/fields.h +47 -12
  29. package/dist/lib/linux_x86_64/include/selva/hll.h +59 -0
  30. package/dist/lib/linux_x86_64/include/selva/types.h +2 -0
  31. package/dist/lib/linux_x86_64/include/tree.h +69 -69
  32. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  33. package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
  34. package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
  35. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  36. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  37. package/dist/lib/linux_x86_64/libselva.so +0 -0
  38. package/dist/src/client/modify/alias.js +3 -0
  39. package/dist/src/client/modify/binary.js +1 -1
  40. package/dist/src/client/modify/cardinality.d.ts +2 -2
  41. package/dist/src/client/modify/cardinality.js +17 -6
  42. package/dist/src/client/modify/fixed.js +6 -51
  43. package/dist/src/client/modify/json.js +15 -1
  44. package/dist/src/client/modify/references/edge.js +1 -1
  45. package/dist/src/client/modify/references/references.js +21 -6
  46. package/dist/src/client/modify/string.js +5 -6
  47. package/dist/src/client/modify/text.js +0 -11
  48. package/dist/src/client/modify/vector.js +3 -3
  49. package/dist/src/client/query/BasedDbQuery.js +6 -1
  50. package/dist/src/client/query/filter/parseFilterValue.js +2 -4
  51. package/dist/src/client/query/include/walk.js +1 -0
  52. package/dist/src/client/query/read/read.js +8 -1
  53. package/dist/src/client/query/validation.js +3 -0
  54. package/dist/src/index.d.ts +3 -0
  55. package/dist/src/index.js +8 -2
  56. package/dist/src/server/index.js +10 -3
  57. package/dist/src/server/migrate/index.js +9 -5
  58. package/dist/src/server/migrate/worker.js +26 -1
  59. package/dist/src/server/save.js +1 -1
  60. package/package.json +3 -2
  61. package/dist/src/client/bitWise.d.ts +0 -6
  62. package/dist/src/client/bitWise.js +0 -72
  63. package/dist/src/client/operations.d.ts +0 -32
  64. package/dist/src/client/operations.js +0 -137
  65. package/dist/src/client/query/aggregationFn.d.ts +0 -3
  66. package/dist/src/client/query/aggregationFn.js +0 -9
  67. package/dist/src/client/tree.d.ts +0 -1
  68. package/dist/src/client/tree.js +0 -5
@@ -77,10 +77,10 @@ struct name { \
77
77
  }
78
78
 
79
79
  #define SPLAY_INITIALIZER(root) \
80
- { NULL }
80
+ { nullptr }
81
81
 
82
82
  #define SPLAY_INIT(root) do { \
83
- (root)->sph_root = NULL; \
83
+ (root)->sph_root = nullptr; \
84
84
  } while (/*CONSTCOND*/ 0)
85
85
 
86
86
  #define SPLAY_ENTRY(type) \
@@ -92,7 +92,7 @@ struct { \
92
92
  #define SPLAY_LEFT(elm, field) (elm)->field.spe_left
93
93
  #define SPLAY_RIGHT(elm, field) (elm)->field.spe_right
94
94
  #define SPLAY_ROOT(head) (head)->sph_root
95
- #define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL)
95
+ #define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == nullptr)
96
96
 
97
97
  /* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */
98
98
  #define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \
@@ -139,24 +139,24 @@ static __unused __inline struct type * \
139
139
  name##_SPLAY_FIND(struct name *head, struct type *elm) \
140
140
  { \
141
141
  if (SPLAY_EMPTY(head)) \
142
- return(NULL); \
142
+ return nullptr; \
143
143
  name##_SPLAY(head, elm); \
144
144
  if ((cmp)(elm, (head)->sph_root) == 0) \
145
145
  return (head->sph_root); \
146
- return (NULL); \
146
+ return nullptr; \
147
147
  } \
148
148
  \
149
149
  static __unused __inline struct type * \
150
150
  name##_SPLAY_NEXT(struct name *head, struct type *elm) \
151
151
  { \
152
152
  name##_SPLAY(head, elm); \
153
- if (SPLAY_RIGHT(elm, field) != NULL) { \
153
+ if (SPLAY_RIGHT(elm, field) != nullptr) { \
154
154
  elm = SPLAY_RIGHT(elm, field); \
155
- while (SPLAY_LEFT(elm, field) != NULL) { \
155
+ while (SPLAY_LEFT(elm, field) != nullptr) { \
156
156
  elm = SPLAY_LEFT(elm, field); \
157
157
  } \
158
158
  } else \
159
- elm = NULL; \
159
+ elm = nullptr; \
160
160
  return (elm); \
161
161
  } \
162
162
  \
@@ -175,24 +175,24 @@ struct type * \
175
175
  name##_SPLAY_INSERT(struct name *head, struct type *elm) \
176
176
  { \
177
177
  if (SPLAY_EMPTY(head)) { \
178
- SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \
178
+ SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = nullptr; \
179
179
  } else { \
180
- __typeof(cmp(NULL, NULL)) __comp; \
180
+ __typeof(cmp((void *)1, (void *)1)) __comp; \
181
181
  name##_SPLAY(head, elm); \
182
182
  __comp = (cmp)(elm, (head)->sph_root); \
183
183
  if (__comp < 0) { \
184
184
  SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\
185
185
  SPLAY_RIGHT(elm, field) = (head)->sph_root; \
186
- SPLAY_LEFT((head)->sph_root, field) = NULL; \
186
+ SPLAY_LEFT((head)->sph_root, field) = nullptr; \
187
187
  } else if (__comp > 0) { \
188
188
  SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\
189
189
  SPLAY_LEFT(elm, field) = (head)->sph_root; \
190
- SPLAY_RIGHT((head)->sph_root, field) = NULL; \
190
+ SPLAY_RIGHT((head)->sph_root, field) = nullptr; \
191
191
  } else \
192
192
  return ((head)->sph_root); \
193
193
  } \
194
194
  (head)->sph_root = (elm); \
195
- return (NULL); \
195
+ return nullptr; \
196
196
  } \
197
197
  \
198
198
  struct type * \
@@ -200,10 +200,10 @@ name##_SPLAY_REMOVE(struct name *head, struct type *elm) \
200
200
  { \
201
201
  struct type *__tmp; \
202
202
  if (SPLAY_EMPTY(head)) \
203
- return (NULL); \
203
+ return nullptr; \
204
204
  name##_SPLAY(head, elm); \
205
205
  if ((cmp)(elm, (head)->sph_root) == 0) { \
206
- if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \
206
+ if (SPLAY_LEFT((head)->sph_root, field) == nullptr) { \
207
207
  (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\
208
208
  } else { \
209
209
  __tmp = SPLAY_RIGHT((head)->sph_root, field); \
@@ -213,36 +213,36 @@ name##_SPLAY_REMOVE(struct name *head, struct type *elm) \
213
213
  } \
214
214
  return (elm); \
215
215
  } \
216
- return (NULL); \
216
+ return nullptr; \
217
217
  } \
218
218
  \
219
219
  void \
220
220
  name##_SPLAY(struct name *head, struct type *elm) \
221
221
  { \
222
222
  struct type __node, *__left, *__right, *__tmp; \
223
- __typeof(cmp(NULL, NULL)) __comp; \
223
+ __typeof(cmp((void *)1, (void *)1)) __comp; \
224
224
  \
225
- SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
225
+ SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = nullptr;\
226
226
  __left = __right = &__node; \
227
227
  \
228
228
  while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \
229
229
  if (__comp < 0) { \
230
230
  __tmp = SPLAY_LEFT((head)->sph_root, field); \
231
- if (__tmp == NULL) \
231
+ if (__tmp == nullptr) \
232
232
  break; \
233
233
  if ((cmp)(elm, __tmp) < 0){ \
234
234
  SPLAY_ROTATE_RIGHT(head, __tmp, field); \
235
- if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
235
+ if (SPLAY_LEFT((head)->sph_root, field) == nullptr)\
236
236
  break; \
237
237
  } \
238
238
  SPLAY_LINKLEFT(head, __right, field); \
239
239
  } else if (__comp > 0) { \
240
240
  __tmp = SPLAY_RIGHT((head)->sph_root, field); \
241
- if (__tmp == NULL) \
241
+ if (__tmp == nullptr) \
242
242
  break; \
243
243
  if ((cmp)(elm, __tmp) > 0){ \
244
244
  SPLAY_ROTATE_LEFT(head, __tmp, field); \
245
- if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
245
+ if (SPLAY_RIGHT((head)->sph_root, field) == nullptr)\
246
246
  break; \
247
247
  } \
248
248
  SPLAY_LINKRIGHT(head, __left, field); \
@@ -258,27 +258,27 @@ void name##_SPLAY_MINMAX(struct name *head, int __comp) \
258
258
  { \
259
259
  struct type __node, *__left, *__right, *__tmp; \
260
260
  \
261
- SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
261
+ SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = nullptr;\
262
262
  __left = __right = &__node; \
263
263
  \
264
264
  while (1) { \
265
265
  if (__comp < 0) { \
266
266
  __tmp = SPLAY_LEFT((head)->sph_root, field); \
267
- if (__tmp == NULL) \
267
+ if (__tmp == nullptr) \
268
268
  break; \
269
269
  if (__comp < 0){ \
270
270
  SPLAY_ROTATE_RIGHT(head, __tmp, field); \
271
- if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
271
+ if (SPLAY_LEFT((head)->sph_root, field) == nullptr)\
272
272
  break; \
273
273
  } \
274
274
  SPLAY_LINKLEFT(head, __right, field); \
275
275
  } else if (__comp > 0) { \
276
276
  __tmp = SPLAY_RIGHT((head)->sph_root, field); \
277
- if (__tmp == NULL) \
277
+ if (__tmp == nullptr) \
278
278
  break; \
279
279
  if (__comp > 0) { \
280
280
  SPLAY_ROTATE_LEFT(head, __tmp, field); \
281
- if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
281
+ if (SPLAY_RIGHT((head)->sph_root, field) == nullptr)\
282
282
  break; \
283
283
  } \
284
284
  SPLAY_LINKRIGHT(head, __left, field); \
@@ -294,14 +294,14 @@ void name##_SPLAY_MINMAX(struct name *head, int __comp) \
294
294
  #define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y)
295
295
  #define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y)
296
296
  #define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y)
297
- #define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \
297
+ #define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? nullptr \
298
298
  : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF))
299
- #define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \
299
+ #define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? nullptr \
300
300
  : name##_SPLAY_MIN_MAX(x, SPLAY_INF))
301
301
 
302
302
  #define SPLAY_FOREACH(x, name, head) \
303
303
  for ((x) = SPLAY_MIN(name, head); \
304
- (x) != NULL; \
304
+ (x) != nullptr; \
305
305
  (x) = SPLAY_NEXT(name, head, x))
306
306
 
307
307
  /* Macros that define a rank-balanced tree */
@@ -311,10 +311,10 @@ struct name { \
311
311
  }
312
312
 
313
313
  #define RB_INITIALIZER(root) \
314
- { NULL }
314
+ { nullptr }
315
315
 
316
316
  #define RB_INIT(root) do { \
317
- (root)->rbh_root = NULL; \
317
+ (root)->rbh_root = nullptr; \
318
318
  } while (/*CONSTCOND*/ 0)
319
319
 
320
320
  #define RB_ENTRY(type) \
@@ -350,7 +350,7 @@ struct { \
350
350
  #define RB_PARENT(elm, field) ((__typeof(RB_UP(elm, field))) \
351
351
  (RB_BITS(elm, field) & ~RB_RED_MASK))
352
352
  #define RB_ROOT(head) (head)->rbh_root
353
- #define RB_EMPTY(head) (RB_ROOT(head) == NULL)
353
+ #define RB_EMPTY(head) (RB_ROOT(head) == nullptr)
354
354
 
355
355
  #define RB_SET_PARENT(dst, src, field) do { \
356
356
  RB_BITS(dst, field) &= RB_RED_MASK; \
@@ -359,10 +359,10 @@ struct { \
359
359
 
360
360
  #define RB_SET(elm, parent, field) do { \
361
361
  RB_UP(elm, field) = parent; \
362
- RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \
362
+ RB_LEFT(elm, field) = RB_RIGHT(elm, field) = nullptr; \
363
363
  } while (/*CONSTCOND*/ 0)
364
364
 
365
- #define RB_COLOR(elm, field) (RB_PARENT(elm, field) == NULL ? 0 : \
365
+ #define RB_COLOR(elm, field) (RB_PARENT(elm, field) == nullptr ? 0 : \
366
366
  RB_LEFT(RB_PARENT(elm, field), field) == elm ? \
367
367
  RB_RED_LEFT(RB_PARENT(elm, field), field) : \
368
368
  RB_RED_RIGHT(RB_PARENT(elm, field), field))
@@ -376,7 +376,7 @@ struct { \
376
376
  #endif
377
377
 
378
378
  #define RB_SWAP_CHILD(head, out, in, field) do { \
379
- if (RB_PARENT(out, field) == NULL) \
379
+ if (RB_PARENT(out, field) == nullptr) \
380
380
  RB_ROOT(head) = (in); \
381
381
  else if ((out) == RB_LEFT(RB_PARENT(out, field), field)) \
382
382
  RB_LEFT(RB_PARENT(out, field), field) = (in); \
@@ -386,7 +386,7 @@ struct { \
386
386
 
387
387
  #define RB_ROTATE_LEFT(head, elm, tmp, field) do { \
388
388
  (tmp) = RB_RIGHT(elm, field); \
389
- if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \
389
+ if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != nullptr) { \
390
390
  RB_SET_PARENT(RB_RIGHT(elm, field), elm, field); \
391
391
  } \
392
392
  RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \
@@ -398,7 +398,7 @@ struct { \
398
398
 
399
399
  #define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \
400
400
  (tmp) = RB_LEFT(elm, field); \
401
- if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \
401
+ if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != nullptr) { \
402
402
  RB_SET_PARENT(RB_LEFT(elm, field), elm, field); \
403
403
  } \
404
404
  RB_SET_PARENT(tmp, RB_PARENT(elm, field), field); \
@@ -524,7 +524,7 @@ name##_RB_INSERT_COLOR(struct name *head, struct type *parent, struct type *elm)
524
524
  } \
525
525
  RB_BITS(elm, field) &= ~RB_RED_MASK; \
526
526
  break; \
527
- } while ((parent = RB_PARENT(elm, field)) != NULL); \
527
+ } while ((parent = RB_PARENT(elm, field)) != nullptr); \
528
528
  }
529
529
 
530
530
  #define RB_GENERATE_REMOVE_COLOR(name, type, field, attr) \
@@ -538,7 +538,7 @@ name##_RB_REMOVE_COLOR(struct name *head, \
538
538
  RB_BITS(parent, field) &= ~RB_RED_MASK; \
539
539
  elm = parent; \
540
540
  parent = RB_PARENT(elm, field); \
541
- if (parent == NULL) \
541
+ if (parent == nullptr) \
542
542
  return; \
543
543
  } \
544
544
  do { \
@@ -604,7 +604,7 @@ name##_RB_REMOVE_COLOR(struct name *head, \
604
604
  RB_ROTATE_RIGHT(head, parent, sib, field); \
605
605
  } \
606
606
  break; \
607
- } while ((parent = RB_PARENT(elm, field)) != NULL); \
607
+ } while ((parent = RB_PARENT(elm, field)) != nullptr); \
608
608
  }
609
609
 
610
610
  #define RB_GENERATE_REMOVE(name, type, field, attr) \
@@ -616,19 +616,19 @@ name##_RB_REMOVE(struct name *head, struct type *elm) \
616
616
  old = elm; \
617
617
  parent = RB_PARENT(elm, field); \
618
618
  right = RB_RIGHT(elm, field); \
619
- if (RB_LEFT(elm, field) == NULL) \
619
+ if (RB_LEFT(elm, field) == nullptr) \
620
620
  elm = child = right; \
621
- else if (right == NULL) \
621
+ else if (right == nullptr) \
622
622
  elm = child = RB_LEFT(elm, field); \
623
623
  else { \
624
- if ((child = RB_LEFT(right, field)) == NULL) { \
624
+ if ((child = RB_LEFT(right, field)) == nullptr) { \
625
625
  child = RB_RIGHT(right, field); \
626
626
  RB_RIGHT(old, field) = child; \
627
627
  parent = elm = right; \
628
628
  } else { \
629
629
  do \
630
630
  elm = child; \
631
- while ((child = RB_LEFT(elm, field)) != NULL); \
631
+ while ((child = RB_LEFT(elm, field)) != nullptr); \
632
632
  child = RB_RIGHT(elm, field); \
633
633
  parent = RB_PARENT(elm, field); \
634
634
  RB_LEFT(parent, field) = child; \
@@ -638,11 +638,11 @@ name##_RB_REMOVE(struct name *head, struct type *elm) \
638
638
  elm->field = old->field; \
639
639
  } \
640
640
  RB_SWAP_CHILD(head, old, elm, field); \
641
- if (child != NULL) \
641
+ if (child != nullptr) \
642
642
  RB_SET_PARENT(child, parent, field); \
643
- if (parent != NULL) \
643
+ if (parent != nullptr) \
644
644
  name##_RB_REMOVE_COLOR(head, parent, child); \
645
- while (parent != NULL) { \
645
+ while (parent != nullptr) { \
646
646
  RB_AUGMENT(parent); \
647
647
  parent = RB_PARENT(parent, field); \
648
648
  } \
@@ -657,12 +657,12 @@ name##_RB_INSERT_FINISH(struct name *head, struct type *parent, \
657
657
  { \
658
658
  RB_SET(elm, parent, field); \
659
659
  *pptr = elm; \
660
- if (parent != NULL) name##_RB_INSERT_COLOR(head, parent, elm); \
661
- while (elm != NULL) { \
660
+ if (parent != nullptr) name##_RB_INSERT_COLOR(head, parent, elm); \
661
+ while (elm != nullptr) { \
662
662
  RB_AUGMENT(elm); \
663
663
  elm = RB_PARENT(elm, field); \
664
664
  } \
665
- return NULL; \
665
+ return nullptr; \
666
666
  }
667
667
 
668
668
  #define RB_GENERATE_INSERT(name, type, field, cmp, attr) \
@@ -672,10 +672,10 @@ name##_RB_INSERT(struct name *head, struct type *elm) \
672
672
  { \
673
673
  struct type *tmp; \
674
674
  struct type **tmpp = &RB_ROOT(head); \
675
- struct type *parent = NULL; \
676
- while ((tmp = *tmpp) != NULL) { \
675
+ struct type *parent = nullptr; \
676
+ while ((tmp = *tmpp) != nullptr) { \
677
677
  parent = tmp; \
678
- __typeof(cmp(NULL, NULL)) comp = (cmp)(elm, parent); \
678
+ __typeof(cmp((void *)1, (void *)1)) comp = (cmp)(elm, parent); \
679
679
  if (comp < 0) tmpp = &RB_LEFT(parent, field); \
680
680
  else if (comp > 0) tmpp = &RB_RIGHT(parent, field); \
681
681
  else return (parent); \
@@ -689,7 +689,7 @@ name##_RB_INSERT_NEXT(struct name *head, struct type * restrict elm, struct type
689
689
  { \
690
690
  struct type *tmp; \
691
691
  struct type **tmpp = &RB_RIGHT(elm, field); \
692
- while ((tmp = *tmpp) != NULL) { \
692
+ while ((tmp = *tmpp) != nullptr) { \
693
693
  elm = tmp; \
694
694
  tmpp = &RB_LEFT(elm, field); \
695
695
  } \
@@ -702,7 +702,7 @@ attr struct type * \
702
702
  name##_RB_FIND(struct name *head, struct type *elm) \
703
703
  { \
704
704
  struct type *tmp = RB_ROOT(head); \
705
- __typeof(cmp(NULL, NULL)) comp; \
705
+ __typeof(cmp((void *)1, (void *)1)) comp; \
706
706
  while (tmp) { \
707
707
  comp = cmp(elm, tmp); \
708
708
  if (comp < 0) \
@@ -712,7 +712,7 @@ name##_RB_FIND(struct name *head, struct type *elm) \
712
712
  else \
713
713
  return (tmp); \
714
714
  } \
715
- return (NULL); \
715
+ return nullptr; \
716
716
  }
717
717
 
718
718
  #define RB_GENERATE_NFIND(name, type, field, cmp, attr) \
@@ -721,8 +721,8 @@ attr struct type * \
721
721
  name##_RB_NFIND(struct name *head, struct type *elm) \
722
722
  { \
723
723
  struct type *tmp = RB_ROOT(head); \
724
- struct type *res = NULL; \
725
- __typeof(cmp(NULL, NULL)) comp; \
724
+ struct type *res = nullptr; \
725
+ __typeof(cmp((void *)1, (void *)1)) comp; \
726
726
  while (tmp) { \
727
727
  comp = cmp(elm, tmp); \
728
728
  if (comp < 0) { \
@@ -778,7 +778,7 @@ attr struct type * \
778
778
  name##_RB_MINMAX(struct name *head, int val) \
779
779
  { \
780
780
  struct type *tmp = RB_ROOT(head); \
781
- struct type *parent = NULL; \
781
+ struct type *parent = nullptr; \
782
782
  while (tmp) { \
783
783
  parent = tmp; \
784
784
  if (val < 0) \
@@ -794,15 +794,15 @@ attr struct type * \
794
794
  name##_RB_REINSERT(struct name *head, struct type *elm) \
795
795
  { \
796
796
  struct type *cmpelm; \
797
- if (((cmpelm = RB_PREV(name, head, elm)) != NULL && \
797
+ if (((cmpelm = RB_PREV(name, head, elm)) != nullptr && \
798
798
  cmp(cmpelm, elm) >= 0) || \
799
- ((cmpelm = RB_NEXT(name, head, elm)) != NULL && \
799
+ ((cmpelm = RB_NEXT(name, head, elm)) != nullptr && \
800
800
  cmp(elm, cmpelm) >= 0)) { \
801
801
  /* XXXLAS: Remove/insert is heavy handed. */ \
802
802
  RB_REMOVE(name, head, elm); \
803
803
  return (RB_INSERT(name, head, elm)); \
804
804
  } \
805
- return (NULL); \
805
+ return nullptr; \
806
806
  } \
807
807
 
808
808
  #define RB_NEGINF -1
@@ -821,32 +821,32 @@ name##_RB_REINSERT(struct name *head, struct type *elm) \
821
821
 
822
822
  #define RB_FOREACH(x, name, head) \
823
823
  for ((x) = RB_MIN(name, head); \
824
- (x) != NULL; \
824
+ (x) != nullptr; \
825
825
  (x) = name##_RB_NEXT(x))
826
826
 
827
827
  #define RB_FOREACH_FROM(x, name, y) \
828
828
  for ((x) = (y); \
829
- ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \
829
+ ((x) != nullptr) && ((y) = name##_RB_NEXT(x), (x) != nullptr); \
830
830
  (x) = (y))
831
831
 
832
832
  #define RB_FOREACH_SAFE(x, name, head, y) \
833
833
  for ((x) = RB_MIN(name, head); \
834
- ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \
834
+ ((x) != nullptr) && ((y) = name##_RB_NEXT(x), (x) != nullptr); \
835
835
  (x) = (y))
836
836
 
837
837
  #define RB_FOREACH_REVERSE(x, name, head) \
838
838
  for ((x) = RB_MAX(name, head); \
839
- (x) != NULL; \
839
+ (x) != nullptr; \
840
840
  (x) = name##_RB_PREV(x))
841
841
 
842
842
  #define RB_FOREACH_REVERSE_FROM(x, name, y) \
843
843
  for ((x) = (y); \
844
- ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \
844
+ ((x) != nullptr) && ((y) = name##_RB_PREV(x), (x) != nullptr); \
845
845
  (x) = (y))
846
846
 
847
847
  #define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \
848
848
  for ((x) = RB_MAX(name, head); \
849
- ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \
849
+ ((x) != nullptr) && ((y) = name##_RB_PREV(x), (x) != nullptr); \
850
850
  (x) = (y))
851
851
 
852
852
  #endif /* _SYS_TREE_H_ */
Binary file
Binary file
@@ -14,6 +14,9 @@ export function writeAlias(value, ctx, def, t, parentId, modifyOp) {
14
14
  }
15
15
  }
16
16
  else {
17
+ if (!t.validation(value, t)) {
18
+ return new ModifyError(t, value);
19
+ }
17
20
  const valueBuf = ENCODER.encode(value);
18
21
  let size = valueBuf.byteLength;
19
22
  if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 + size > ctx.max) {
@@ -39,7 +39,7 @@ export function writeBinary(value, ctx, schema, t, parentId, modifyOp) {
39
39
  }
40
40
  else {
41
41
  value = getBuffer(value);
42
- if (!value) {
42
+ if (!value || !t.validation(value, t)) {
43
43
  return new ModifyError(t, value);
44
44
  }
45
45
  size = value.byteLength + 6;
@@ -1,6 +1,6 @@
1
1
  import { ModifyCtx } from '../../index.js';
2
- import { SchemaTypeDef, PropDef } from '@based/schema/def';
2
+ import { SchemaTypeDef, PropDef, PropDefEdge } from '@based/schema/def';
3
3
  import { ModifyOp, ModifyErr } from './types.js';
4
4
  import { ModifyError } from './ModifyRes.js';
5
5
  export declare function writeHll(value: string | null | Uint8Array | Array<string | Uint8Array>, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
6
- export declare function writeHllBuf(value: (string | Uint8Array)[], ctx: ModifyCtx, t: PropDef, len: number): ModifyError;
6
+ export declare function writeHllBuf(value: (string | Uint8Array)[], ctx: ModifyCtx, t: PropDef | PropDefEdge, len: number): ModifyError;
@@ -29,23 +29,34 @@ function addHll(value, ctx, def, t, parentId, modifyOp) {
29
29
  }
30
30
  setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
31
31
  ctx.buf[ctx.len++] = modifyOp;
32
- writeHllBuf(value, ctx, t, len);
32
+ return writeHllBuf(value, ctx, t, len);
33
33
  }
34
34
  export function writeHllBuf(value, ctx, t, len) {
35
+ let startLen = ctx.len;
35
36
  ctx.buf[ctx.len++] = len;
36
37
  ctx.buf[ctx.len++] = len >>> 8;
37
38
  ctx.buf[ctx.len++] = len >>> 16;
38
39
  ctx.buf[ctx.len++] = len >>> 24;
39
40
  for (let val of value) {
40
- if (typeof val === 'string') {
41
+ if (val === undefined) {
42
+ // not sure if this makes sense....
43
+ continue;
44
+ }
45
+ else if (!t.validation(val, t)) {
46
+ ctx.len = startLen;
47
+ len = 0;
48
+ ctx.buf[ctx.len++] = len;
49
+ ctx.buf[ctx.len++] = len >>> 8;
50
+ ctx.buf[ctx.len++] = len >>> 16;
51
+ ctx.buf[ctx.len++] = len >>> 24;
52
+ return new ModifyError(t, val);
53
+ }
54
+ else if (typeof val === 'string') {
41
55
  xxHash64(ENCODER.encode(val), ctx.buf, ctx.len);
42
56
  }
43
- else if ((val instanceof Uint8Array) && val.byteLength === 8) {
57
+ else if (val instanceof Uint8Array && val.byteLength === 8) {
44
58
  ctx.buf.set(val, ctx.len);
45
59
  }
46
- else {
47
- return new ModifyError(t, val);
48
- }
49
60
  ctx.len += 8;
50
61
  }
51
62
  }
@@ -19,12 +19,6 @@ map[BINARY] = (ctx, val, def) => {
19
19
  ctx.len += buf.byteLength;
20
20
  };
21
21
  map[STRING] = (ctx, val, def) => {
22
- if (typeof val !== 'string') {
23
- if (val !== null) {
24
- return new ModifyError(def, val);
25
- }
26
- val = '';
27
- }
28
22
  const valBuf = ENCODER.encode(val);
29
23
  const size = valBuf.byteLength;
30
24
  if (size + 1 > def.len) {
@@ -66,9 +60,6 @@ map[ENUM] = (ctx, val, def) => {
66
60
  }
67
61
  };
68
62
  map[NUMBER] = (ctx, val, def) => {
69
- if (typeof val !== 'number') {
70
- return new ModifyError(def, val);
71
- }
72
63
  if (ctx.len + 8 > ctx.max) {
73
64
  return RANGE_ERR;
74
65
  }
@@ -78,100 +69,61 @@ map[NUMBER] = (ctx, val, def) => {
78
69
  };
79
70
  map[TIMESTAMP] = (ctx, val, def) => {
80
71
  const parsedValue = convertToTimestamp(val);
81
- if (typeof parsedValue !== 'number') {
82
- return new ModifyError(def, val);
83
- }
84
72
  if (ctx.len + 8 > ctx.max) {
85
73
  return RANGE_ERR;
86
74
  }
87
- if (val < 0) {
88
- return new ModifyError(def, val);
89
- }
90
75
  const view = new DataView(ctx.buf.buffer, ctx.buf.byteOffset + ctx.len, 8);
91
76
  ctx.len += 8;
92
77
  view.setFloat64(0, parsedValue, true);
93
78
  };
94
79
  map[UINT32] = (ctx, val, def) => {
95
- if (typeof val !== 'number') {
96
- return new ModifyError(def, val);
97
- }
98
80
  if (ctx.len + 4 > ctx.max) {
99
81
  return RANGE_ERR;
100
82
  }
101
- if (val > 4294967295 || val < 0) {
102
- return new ModifyError(def, val);
103
- }
104
83
  ctx.buf[ctx.len++] = val;
105
84
  ctx.buf[ctx.len++] = val >>>= 8;
106
85
  ctx.buf[ctx.len++] = val >>>= 8;
107
86
  ctx.buf[ctx.len++] = val >>>= 8;
108
87
  };
109
88
  map[UINT16] = (ctx, val, def) => {
110
- if (typeof val !== 'number') {
111
- return new ModifyError(def, val);
112
- }
113
89
  if (ctx.len + 2 > ctx.max) {
114
90
  return RANGE_ERR;
115
91
  }
116
- if (val > 65535 || val < 0) {
117
- return new ModifyError(def, val);
118
- }
119
92
  ctx.buf[ctx.len++] = val;
120
93
  ctx.buf[ctx.len++] = val >>>= 8;
121
94
  };
122
95
  map[UINT8] = (ctx, val, def) => {
123
- if (typeof val !== 'number') {
124
- return new ModifyError(def, val);
125
- }
126
96
  if (ctx.len + 1 > ctx.max) {
127
97
  return RANGE_ERR;
128
98
  }
129
- if (val > 255 || val < 0) {
130
- return new ModifyError(def, val);
131
- }
132
99
  ctx.buf[ctx.len++] = val;
133
100
  };
134
101
  map[INT32] = (ctx, val, def) => {
135
- if (typeof val !== 'number') {
136
- return new ModifyError(def, val);
137
- }
138
102
  if (ctx.len + 4 > ctx.max) {
139
103
  return RANGE_ERR;
140
104
  }
141
- if (val > 2147483647 || val < -2147483648) {
142
- return new ModifyError(def, val);
143
- }
144
105
  ctx.buf[ctx.len++] = val;
145
106
  ctx.buf[ctx.len++] = val >>>= 8;
146
107
  ctx.buf[ctx.len++] = val >>>= 8;
147
108
  ctx.buf[ctx.len++] = val >>>= 8;
148
109
  };
149
110
  map[INT16] = (ctx, val, def) => {
150
- if (typeof val !== 'number') {
151
- return new ModifyError(def, val);
152
- }
153
111
  if (ctx.len + 2 > ctx.max) {
154
112
  return RANGE_ERR;
155
113
  }
156
- if (val > 32767 || val < -32768) {
157
- return new ModifyError(def, val);
158
- }
159
114
  ctx.buf[ctx.len++] = val;
160
115
  ctx.buf[ctx.len++] = val >>>= 8;
161
116
  };
162
117
  map[INT8] = (ctx, val, def) => {
163
- if (typeof val !== 'number') {
164
- return new ModifyError(def, val);
165
- }
166
118
  if (ctx.len + 1 > ctx.max) {
167
119
  return RANGE_ERR;
168
120
  }
169
- if (val > 127 || val < -128) {
170
- return new ModifyError(def, val);
171
- }
172
121
  ctx.buf[ctx.len++] = val;
173
122
  };
174
123
  export const writeFixedValue = (ctx, val, def, pos) => {
124
+ if (!def.validation(val, def)) {
125
+ return new ModifyError(def, val);
126
+ }
175
127
  const len = ctx.len;
176
128
  ctx.len = pos;
177
129
  const res = map[def.typeIndex](ctx, val, def);
@@ -179,6 +131,9 @@ export const writeFixedValue = (ctx, val, def, pos) => {
179
131
  return res;
180
132
  };
181
133
  export const appendFixedValue = (ctx, val, def) => {
134
+ if (!def.validation(val, def)) {
135
+ return new ModifyError(def, val);
136
+ }
182
137
  return map[def.typeIndex](ctx, val, def);
183
138
  };
184
139
  //# sourceMappingURL=fixed.js.map