@based/db 0.0.66 → 0.0.67

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 (121) hide show
  1. package/README.md +2 -2
  2. package/dist/lib/darwin_aarch64/include/selva/colvec.h +71 -0
  3. package/dist/lib/darwin_aarch64/include/selva/db.h +3 -0
  4. package/dist/lib/darwin_aarch64/include/selva/fields.h +1 -1
  5. package/dist/lib/darwin_aarch64/include/selva/types.h +7 -0
  6. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  7. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  8. package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
  9. package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
  10. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  11. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  12. package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
  13. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  14. package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
  15. package/dist/lib/linux_aarch64/include/selva/colvec.h +71 -0
  16. package/dist/lib/linux_aarch64/include/selva/db.h +3 -0
  17. package/dist/lib/linux_aarch64/include/selva/fields.h +1 -1
  18. package/dist/lib/linux_aarch64/include/selva/types.h +7 -0
  19. package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
  20. package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
  21. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  22. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  23. package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
  24. package/dist/lib/linux_aarch64/libselva.so +0 -0
  25. package/dist/lib/linux_x86_64/include/selva/colvec.h +71 -0
  26. package/dist/lib/linux_x86_64/include/selva/db.h +3 -0
  27. package/dist/lib/linux_x86_64/include/selva/fields.h +1 -1
  28. package/dist/lib/linux_x86_64/include/selva/types.h +7 -0
  29. package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
  30. package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
  31. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  32. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  33. package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
  34. package/dist/lib/linux_x86_64/libselva.so +0 -0
  35. package/dist/src/client/flushModify.d.ts +2 -1
  36. package/dist/src/client/flushModify.js +12 -4
  37. package/dist/src/client/modify/create.js +11 -0
  38. package/dist/src/client/modify/delete.js +3 -0
  39. package/dist/src/client/modify/modify.js +2 -2
  40. package/dist/src/client/modify/setCursor.d.ts +2 -1
  41. package/dist/src/client/query/BasedDbQuery.d.ts +7 -2
  42. package/dist/src/client/query/BasedDbQuery.js +111 -14
  43. package/dist/src/client/query/aggregates/aggregation.js +24 -11
  44. package/dist/src/client/query/aggregates/types.d.ts +21 -2
  45. package/dist/src/client/query/aggregates/types.js +34 -1
  46. package/dist/src/client/query/display.js +8 -2
  47. package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -3
  48. package/dist/src/client/query/filter/createVariableFilterBuffer.js +20 -7
  49. package/dist/src/client/query/filter/filter.js +13 -3
  50. package/dist/src/client/query/filter/primitiveFilter.d.ts +1 -2
  51. package/dist/src/client/query/include/props.js +18 -2
  52. package/dist/src/client/query/include/toBuffer.js +11 -3
  53. package/dist/src/client/query/include/walk.js +5 -1
  54. package/dist/src/client/query/queryDef.js +4 -1
  55. package/dist/src/client/query/read/read.js +50 -23
  56. package/dist/src/client/query/registerQuery.js +1 -0
  57. package/dist/src/client/query/search/index.d.ts +1 -1
  58. package/dist/src/client/query/search/index.js +21 -7
  59. package/dist/src/client/query/sort.d.ts +1 -1
  60. package/dist/src/client/query/toByteCode/default.d.ts +1 -1
  61. package/dist/src/client/query/toByteCode/default.js +0 -2
  62. package/dist/src/client/query/toByteCode/toBuffer.js +0 -7
  63. package/dist/src/client/query/types.d.ts +16 -5
  64. package/dist/src/client/query/validation.js +25 -2
  65. package/dist/src/client/xxHash64.d.ts +1 -1
  66. package/dist/src/index.d.ts +0 -1
  67. package/dist/src/index.js +0 -1
  68. package/dist/src/native.d.ts +2 -2
  69. package/dist/src/native.js +7 -8
  70. package/dist/src/server/IoWorker.d.ts +8 -0
  71. package/dist/src/server/IoWorker.js +39 -0
  72. package/dist/src/server/QueryWorker.d.ts +8 -0
  73. package/dist/src/server/QueryWorker.js +26 -0
  74. package/dist/src/server/blocks.d.ts +24 -0
  75. package/dist/src/server/blocks.js +112 -0
  76. package/dist/src/server/dbHash.d.ts +1 -1
  77. package/dist/src/server/index.d.ts +9 -16
  78. package/dist/src/server/index.js +37 -15
  79. package/dist/src/server/migrate/index.d.ts +5 -0
  80. package/dist/src/server/migrate/index.js +10 -7
  81. package/dist/src/server/save.d.ts +8 -6
  82. package/dist/src/server/save.js +34 -78
  83. package/dist/src/server/schema.js +6 -5
  84. package/dist/src/server/start.js +57 -60
  85. package/dist/src/server/tree.d.ts +24 -13
  86. package/dist/src/server/tree.js +95 -66
  87. package/dist/src/server/workers/DbWorker.d.ts +17 -0
  88. package/dist/src/server/{DbWorker.js → workers/DbWorker.js} +15 -17
  89. package/dist/src/server/workers/io_worker.js +39 -0
  90. package/dist/src/server/workers/io_worker_types.d.ts +12 -0
  91. package/dist/src/server/workers/io_worker_types.js +2 -0
  92. package/dist/src/server/workers/query_worker.d.ts +1 -0
  93. package/dist/src/server/workers/query_worker.js +4 -0
  94. package/dist/src/server/workers/worker.d.ts +1 -0
  95. package/dist/src/server/workers/worker.js +41 -0
  96. package/dist/src/shared/Emitter.d.ts +1 -0
  97. package/dist/src/types.d.ts +1 -1
  98. package/dist/src/types.js +1 -1
  99. package/package.json +3 -3
  100. package/dist/lib/darwin_aarch64/include/selva/history.h +0 -64
  101. package/dist/lib/linux_aarch64/include/selva/history.h +0 -64
  102. package/dist/lib/linux_x86_64/include/selva/history.h +0 -64
  103. package/dist/src/client/query/serialize.d.ts +0 -4
  104. package/dist/src/client/query/serialize.js +0 -26
  105. package/dist/src/server/DbWorker.d.ts +0 -13
  106. package/dist/src/server/csmt/draw-dot.d.ts +0 -4
  107. package/dist/src/server/csmt/draw-dot.js +0 -38
  108. package/dist/src/server/csmt/index.d.ts +0 -4
  109. package/dist/src/server/csmt/index.js +0 -5
  110. package/dist/src/server/csmt/match.d.ts +0 -7
  111. package/dist/src/server/csmt/match.js +0 -10
  112. package/dist/src/server/csmt/memebership-proof.d.ts +0 -7
  113. package/dist/src/server/csmt/memebership-proof.js +0 -122
  114. package/dist/src/server/csmt/tree-utils.d.ts +0 -6
  115. package/dist/src/server/csmt/tree-utils.js +0 -33
  116. package/dist/src/server/csmt/tree.d.ts +0 -3
  117. package/dist/src/server/csmt/tree.js +0 -270
  118. package/dist/src/server/csmt/types.d.ts +0 -46
  119. package/dist/src/server/csmt/types.js +0 -2
  120. package/dist/src/server/worker.js +0 -33
  121. /package/dist/src/server/{worker.d.ts → workers/io_worker.d.ts} +0 -0
package/README.md CHANGED
@@ -17,9 +17,9 @@ BasedDb is a powerful database solution that supports various data types, refere
17
17
  **Prerequisites:**
18
18
 
19
19
  - recent GNU make
20
- - gcc with recent enough C23 support
20
+ - gcc 14.2 on Linux or clang 17.0.0 on macOS
21
21
  - zig 0.14.0
22
- - npm & node.js, v20.11.1 or newer
22
+ - npm & node.js v22.14.0 or newer
23
23
 
24
24
  ```bash
25
25
  npm i
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright (c) 2025 SAULX
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ #pragma once
6
+
7
+ #include <stddef.h>
8
+ #include <stdint.h>
9
+ #include "selva/types.h"
10
+ #include "selva/selva_hash128.h"
11
+ #include "selva/_export.h"
12
+
13
+ struct SelvaColvec {
14
+ field_t field;
15
+ uint16_t vec_size;
16
+ size_t slab_size; /* Size of each slab in v. */
17
+
18
+ /**
19
+ * Array of pointers to vector slabs.
20
+ * te->blocks->len number of pointers to vector blocks each containing
21
+ * te->blocks->block_capacity vectors.
22
+ */
23
+ void **v;
24
+ };
25
+
26
+ /**
27
+ * Initialize colvec record keeping under te->col_fields.
28
+ */
29
+ void colvec_init_te(struct SelvaTypeEntry *te);
30
+
31
+ /**
32
+ * Deinitialize colvec record keeping and col slabs under te->col_fields.
33
+ */
34
+ void colvec_deinit_te(struct SelvaTypeEntry *te);
35
+
36
+ /**
37
+ * Initialize a slab at block_i if not already Initialized.
38
+ */
39
+ void *colvec_init_slab(struct SelvaColvec *colvec, block_id_t block_i);
40
+
41
+ /**
42
+ * Initialize all columnar fields of node.
43
+ * This function will also initialize the slab(s) if it's not allocated.
44
+ */
45
+ void colvec_init_node(struct SelvaTypeEntry *te, struct SelvaNode *node);
46
+
47
+ /**
48
+ * Compute the hash for a node_id in colvec.
49
+ */
50
+ void colvec_hash_update(struct SelvaTypeEntry *te, node_id_t node_id, struct SelvaColvec *colvec, selva_hash_state_t *hash_state);
51
+
52
+ /**
53
+ * Get the whole column for fs.
54
+ */
55
+ SELVA_EXPORT
56
+ struct SelvaColvec *colvec_get(struct SelvaTypeEntry *te, const struct SelvaFieldSchema *fs);
57
+
58
+ /**
59
+ * Get a single vector in a colvec field by node_id.
60
+ */
61
+ SELVA_EXPORT
62
+ void *colvec_get_vec(struct SelvaTypeEntry *te, node_id_t node_id, const struct SelvaFieldSchema *fs);
63
+
64
+ /**
65
+ * Set a single vector in a colvec field.
66
+ */
67
+ SELVA_EXPORT
68
+ void colvec_set_vec(struct SelvaTypeEntry *te, node_id_t node_id, const struct SelvaFieldSchema *fs, const void *vec);
69
+
70
+ SELVA_EXPORT
71
+ int colvec_foreach(struct SelvaTypeEntry *te, const struct SelvaFieldSchema *fs, node_id_t start, uint32_t len, void (*cb)(node_id_t node_id, void *vec, void *arg), void *arg);
@@ -241,6 +241,9 @@ void selva_db_expire_tick(struct SelvaDb *db, selva_dirty_node_cb_t dirty_cb, vo
241
241
  SELVA_EXPORT
242
242
  void selva_del_node(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx) __attribute__((nonnull(1, 2, 3)));
243
243
 
244
+ SELVA_EXPORT
245
+ void selva_del_block(struct SelvaDb *db, struct SelvaTypeEntry *te, node_id_t start);
246
+
244
247
  /**
245
248
  * Get a node by id.
246
249
  */
@@ -239,7 +239,7 @@ int selva_fields_get_reference_meta_mutable_string(
239
239
  struct SelvaNode *node,
240
240
  struct SelvaNodeReference *ref,
241
241
  const struct EdgeFieldConstraint *efc,
242
- field_t field,
242
+ const struct SelvaFieldSchema *efs,
243
243
  size_t len,
244
244
  struct selva_string **s);
245
245
 
@@ -32,6 +32,7 @@ enum SelvaFieldType {
32
32
  SELVA_FIELD_TYPE_WEAK_REFERENCES = 7,
33
33
  SELVA_FIELD_TYPE_ALIAS = 8,
34
34
  SELVA_FIELD_TYPE_ALIASES = 9,
35
+ SELVA_FIELD_TYPE_COLVEC = 10,
35
36
  } __packed;
36
37
 
37
38
  struct EdgeFieldConstraint {
@@ -71,6 +72,11 @@ struct SelvaFieldSchema {
71
72
  uint16_t len;
72
73
  } smb; /*!< SELVA_FIELD_TYPE_MICRO_BUFFER */
73
74
  size_t alias_index; /*!< Index in aliases for SELVA_FIELD_TYPE_ALIAS and SELVA_FIELD_TYPE_ALIASES. */
75
+ struct {
76
+ uint16_t vec_len; /*!< Length of a single vector. */
77
+ uint16_t comp_size; /*!< Component size in the vector. */
78
+ field_t index; /*!< Index in te->col_fields.colvec.v. */
79
+ } colvec;
74
80
  };
75
81
  } __designated_init;
76
82
 
@@ -87,6 +93,7 @@ struct SelvaFieldsSchema {
87
93
 
88
94
  struct SelvaNodeSchema {
89
95
  size_t nr_aliases; /*!< Number of alias fields in this type. */
96
+ size_t nr_colvecs; /*!< Number of columnar vector fields. */
90
97
  struct SelvaFieldsSchema fields_schema;
91
98
  /* Nothing must be put after this line. */
92
99
  };
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright (c) 2025 SAULX
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ #pragma once
6
+
7
+ #include <stddef.h>
8
+ #include <stdint.h>
9
+ #include "selva/types.h"
10
+ #include "selva/selva_hash128.h"
11
+ #include "selva/_export.h"
12
+
13
+ struct SelvaColvec {
14
+ field_t field;
15
+ uint16_t vec_size;
16
+ size_t slab_size; /* Size of each slab in v. */
17
+
18
+ /**
19
+ * Array of pointers to vector slabs.
20
+ * te->blocks->len number of pointers to vector blocks each containing
21
+ * te->blocks->block_capacity vectors.
22
+ */
23
+ void **v;
24
+ };
25
+
26
+ /**
27
+ * Initialize colvec record keeping under te->col_fields.
28
+ */
29
+ void colvec_init_te(struct SelvaTypeEntry *te);
30
+
31
+ /**
32
+ * Deinitialize colvec record keeping and col slabs under te->col_fields.
33
+ */
34
+ void colvec_deinit_te(struct SelvaTypeEntry *te);
35
+
36
+ /**
37
+ * Initialize a slab at block_i if not already Initialized.
38
+ */
39
+ void *colvec_init_slab(struct SelvaColvec *colvec, block_id_t block_i);
40
+
41
+ /**
42
+ * Initialize all columnar fields of node.
43
+ * This function will also initialize the slab(s) if it's not allocated.
44
+ */
45
+ void colvec_init_node(struct SelvaTypeEntry *te, struct SelvaNode *node);
46
+
47
+ /**
48
+ * Compute the hash for a node_id in colvec.
49
+ */
50
+ void colvec_hash_update(struct SelvaTypeEntry *te, node_id_t node_id, struct SelvaColvec *colvec, selva_hash_state_t *hash_state);
51
+
52
+ /**
53
+ * Get the whole column for fs.
54
+ */
55
+ SELVA_EXPORT
56
+ struct SelvaColvec *colvec_get(struct SelvaTypeEntry *te, const struct SelvaFieldSchema *fs);
57
+
58
+ /**
59
+ * Get a single vector in a colvec field by node_id.
60
+ */
61
+ SELVA_EXPORT
62
+ void *colvec_get_vec(struct SelvaTypeEntry *te, node_id_t node_id, const struct SelvaFieldSchema *fs);
63
+
64
+ /**
65
+ * Set a single vector in a colvec field.
66
+ */
67
+ SELVA_EXPORT
68
+ void colvec_set_vec(struct SelvaTypeEntry *te, node_id_t node_id, const struct SelvaFieldSchema *fs, const void *vec);
69
+
70
+ SELVA_EXPORT
71
+ int colvec_foreach(struct SelvaTypeEntry *te, const struct SelvaFieldSchema *fs, node_id_t start, uint32_t len, void (*cb)(node_id_t node_id, void *vec, void *arg), void *arg);
@@ -241,6 +241,9 @@ void selva_db_expire_tick(struct SelvaDb *db, selva_dirty_node_cb_t dirty_cb, vo
241
241
  SELVA_EXPORT
242
242
  void selva_del_node(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx) __attribute__((nonnull(1, 2, 3)));
243
243
 
244
+ SELVA_EXPORT
245
+ void selva_del_block(struct SelvaDb *db, struct SelvaTypeEntry *te, node_id_t start);
246
+
244
247
  /**
245
248
  * Get a node by id.
246
249
  */
@@ -239,7 +239,7 @@ int selva_fields_get_reference_meta_mutable_string(
239
239
  struct SelvaNode *node,
240
240
  struct SelvaNodeReference *ref,
241
241
  const struct EdgeFieldConstraint *efc,
242
- field_t field,
242
+ const struct SelvaFieldSchema *efs,
243
243
  size_t len,
244
244
  struct selva_string **s);
245
245
 
@@ -32,6 +32,7 @@ enum SelvaFieldType {
32
32
  SELVA_FIELD_TYPE_WEAK_REFERENCES = 7,
33
33
  SELVA_FIELD_TYPE_ALIAS = 8,
34
34
  SELVA_FIELD_TYPE_ALIASES = 9,
35
+ SELVA_FIELD_TYPE_COLVEC = 10,
35
36
  } __packed;
36
37
 
37
38
  struct EdgeFieldConstraint {
@@ -71,6 +72,11 @@ struct SelvaFieldSchema {
71
72
  uint16_t len;
72
73
  } smb; /*!< SELVA_FIELD_TYPE_MICRO_BUFFER */
73
74
  size_t alias_index; /*!< Index in aliases for SELVA_FIELD_TYPE_ALIAS and SELVA_FIELD_TYPE_ALIASES. */
75
+ struct {
76
+ uint16_t vec_len; /*!< Length of a single vector. */
77
+ uint16_t comp_size; /*!< Component size in the vector. */
78
+ field_t index; /*!< Index in te->col_fields.colvec.v. */
79
+ } colvec;
74
80
  };
75
81
  } __designated_init;
76
82
 
@@ -87,6 +93,7 @@ struct SelvaFieldsSchema {
87
93
 
88
94
  struct SelvaNodeSchema {
89
95
  size_t nr_aliases; /*!< Number of alias fields in this type. */
96
+ size_t nr_colvecs; /*!< Number of columnar vector fields. */
90
97
  struct SelvaFieldsSchema fields_schema;
91
98
  /* Nothing must be put after this line. */
92
99
  };
Binary file
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright (c) 2025 SAULX
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ #pragma once
6
+
7
+ #include <stddef.h>
8
+ #include <stdint.h>
9
+ #include "selva/types.h"
10
+ #include "selva/selva_hash128.h"
11
+ #include "selva/_export.h"
12
+
13
+ struct SelvaColvec {
14
+ field_t field;
15
+ uint16_t vec_size;
16
+ size_t slab_size; /* Size of each slab in v. */
17
+
18
+ /**
19
+ * Array of pointers to vector slabs.
20
+ * te->blocks->len number of pointers to vector blocks each containing
21
+ * te->blocks->block_capacity vectors.
22
+ */
23
+ void **v;
24
+ };
25
+
26
+ /**
27
+ * Initialize colvec record keeping under te->col_fields.
28
+ */
29
+ void colvec_init_te(struct SelvaTypeEntry *te);
30
+
31
+ /**
32
+ * Deinitialize colvec record keeping and col slabs under te->col_fields.
33
+ */
34
+ void colvec_deinit_te(struct SelvaTypeEntry *te);
35
+
36
+ /**
37
+ * Initialize a slab at block_i if not already Initialized.
38
+ */
39
+ void *colvec_init_slab(struct SelvaColvec *colvec, block_id_t block_i);
40
+
41
+ /**
42
+ * Initialize all columnar fields of node.
43
+ * This function will also initialize the slab(s) if it's not allocated.
44
+ */
45
+ void colvec_init_node(struct SelvaTypeEntry *te, struct SelvaNode *node);
46
+
47
+ /**
48
+ * Compute the hash for a node_id in colvec.
49
+ */
50
+ void colvec_hash_update(struct SelvaTypeEntry *te, node_id_t node_id, struct SelvaColvec *colvec, selva_hash_state_t *hash_state);
51
+
52
+ /**
53
+ * Get the whole column for fs.
54
+ */
55
+ SELVA_EXPORT
56
+ struct SelvaColvec *colvec_get(struct SelvaTypeEntry *te, const struct SelvaFieldSchema *fs);
57
+
58
+ /**
59
+ * Get a single vector in a colvec field by node_id.
60
+ */
61
+ SELVA_EXPORT
62
+ void *colvec_get_vec(struct SelvaTypeEntry *te, node_id_t node_id, const struct SelvaFieldSchema *fs);
63
+
64
+ /**
65
+ * Set a single vector in a colvec field.
66
+ */
67
+ SELVA_EXPORT
68
+ void colvec_set_vec(struct SelvaTypeEntry *te, node_id_t node_id, const struct SelvaFieldSchema *fs, const void *vec);
69
+
70
+ SELVA_EXPORT
71
+ int colvec_foreach(struct SelvaTypeEntry *te, const struct SelvaFieldSchema *fs, node_id_t start, uint32_t len, void (*cb)(node_id_t node_id, void *vec, void *arg), void *arg);
@@ -241,6 +241,9 @@ void selva_db_expire_tick(struct SelvaDb *db, selva_dirty_node_cb_t dirty_cb, vo
241
241
  SELVA_EXPORT
242
242
  void selva_del_node(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node, selva_dirty_node_cb_t dirty_cb, void *dirty_ctx) __attribute__((nonnull(1, 2, 3)));
243
243
 
244
+ SELVA_EXPORT
245
+ void selva_del_block(struct SelvaDb *db, struct SelvaTypeEntry *te, node_id_t start);
246
+
244
247
  /**
245
248
  * Get a node by id.
246
249
  */
@@ -239,7 +239,7 @@ int selva_fields_get_reference_meta_mutable_string(
239
239
  struct SelvaNode *node,
240
240
  struct SelvaNodeReference *ref,
241
241
  const struct EdgeFieldConstraint *efc,
242
- field_t field,
242
+ const struct SelvaFieldSchema *efs,
243
243
  size_t len,
244
244
  struct selva_string **s);
245
245
 
@@ -32,6 +32,7 @@ enum SelvaFieldType {
32
32
  SELVA_FIELD_TYPE_WEAK_REFERENCES = 7,
33
33
  SELVA_FIELD_TYPE_ALIAS = 8,
34
34
  SELVA_FIELD_TYPE_ALIASES = 9,
35
+ SELVA_FIELD_TYPE_COLVEC = 10,
35
36
  } __packed;
36
37
 
37
38
  struct EdgeFieldConstraint {
@@ -71,6 +72,11 @@ struct SelvaFieldSchema {
71
72
  uint16_t len;
72
73
  } smb; /*!< SELVA_FIELD_TYPE_MICRO_BUFFER */
73
74
  size_t alias_index; /*!< Index in aliases for SELVA_FIELD_TYPE_ALIAS and SELVA_FIELD_TYPE_ALIASES. */
75
+ struct {
76
+ uint16_t vec_len; /*!< Length of a single vector. */
77
+ uint16_t comp_size; /*!< Component size in the vector. */
78
+ field_t index; /*!< Index in te->col_fields.colvec.v. */
79
+ } colvec;
74
80
  };
75
81
  } __designated_init;
76
82
 
@@ -87,6 +93,7 @@ struct SelvaFieldsSchema {
87
93
 
88
94
  struct SelvaNodeSchema {
89
95
  size_t nr_aliases; /*!< Number of alias fields in this type. */
96
+ size_t nr_colvecs; /*!< Number of columnar vector fields. */
90
97
  struct SelvaFieldsSchema fields_schema;
91
98
  /* Nothing must be put after this line. */
92
99
  };
Binary file
@@ -7,6 +7,7 @@ export declare class ModifyCtx {
7
7
  id: number;
8
8
  hasSortField: number;
9
9
  hasSortText: number;
10
+ hasDefaults: number;
10
11
  ctx: {
11
12
  queue?: Map<(payload: any) => void, ModifyState>;
12
13
  offsets?: Record<number, number>;
@@ -26,7 +27,7 @@ export declare class ModifyCtx {
26
27
  markNodeDirty(schema: SchemaTypeDef, nodeId: number): void;
27
28
  markTypeDirty(schema: SchemaTypeDef): void;
28
29
  updateMax(): void;
29
- getData(lastIds: Record<number, number>): Uint8Array;
30
+ getData(lastIds: Record<number, number>): Uint8Array<ArrayBufferLike>;
30
31
  reset(): void;
31
32
  }
32
33
  export declare const execCtxQueue: (resCtx: ModifyCtx["ctx"], error?: boolean) => void;
@@ -1,6 +1,6 @@
1
1
  import { writeUint64 } from '@saulx/utils';
2
2
  // TODO This definitely shouldn't be copy-pasted here from server/tree.ts
3
- const makeCsmtKeyFromNodeId = (typeId, blockCapacity, nodeId) => {
3
+ const makeTreeKeyFromNodeId = (typeId, blockCapacity, nodeId) => {
4
4
  const tmp = nodeId - +!(nodeId % blockCapacity);
5
5
  return typeId * 4294967296 + ((tmp / blockCapacity) | 0) * blockCapacity + 1;
6
6
  };
@@ -16,6 +16,7 @@ export class ModifyCtx {
16
16
  id = -1;
17
17
  hasSortField = -1;
18
18
  hasSortText = -1;
19
+ hasDefaults = -1;
19
20
  ctx = {};
20
21
  payload;
21
22
  max;
@@ -30,7 +31,7 @@ export class ModifyCtx {
30
31
  dirtyRanges = new Set();
31
32
  dirtyTypes = new Map();
32
33
  markNodeDirty(schema, nodeId) {
33
- const key = makeCsmtKeyFromNodeId(schema.id, schema.blockCapacity, nodeId);
34
+ const key = makeTreeKeyFromNodeId(schema.id, schema.blockCapacity, nodeId);
34
35
  if (this.dirtyRanges.has(key)) {
35
36
  return;
36
37
  }
@@ -77,9 +78,16 @@ export class ModifyCtx {
77
78
  data[i++] = lastId >>> 24;
78
79
  }
79
80
  const view = new DataView(data.buffer, data.byteOffset);
81
+ // this is a problem need to remove these dirtyRanges in general...
80
82
  for (let key of this.dirtyRanges) {
81
- view.setFloat64(i, key, true);
82
- i += 8;
83
+ if (i < view.byteLength - 8) {
84
+ view.setFloat64(i, key, true);
85
+ i += 8;
86
+ }
87
+ else {
88
+ console.warn('Dirty range does not fit - will remove this', this.dirtyRanges.size, i);
89
+ break;
90
+ }
83
91
  }
84
92
  const lenMinusSchemaHash = this.len - 8;
85
93
  data[i++] = lenMinusSchemaHash;
@@ -52,6 +52,7 @@ const appendCreate = (ctx, def, obj, res, unsafe) => {
52
52
  ctx.buf.set(def.mainEmpty, ctx.len);
53
53
  ctx.len += def.mainLen;
54
54
  }
55
+ // add text & string here
55
56
  }
56
57
  if (def.hasSeperateSort) {
57
58
  if (ctx.hasSortField !== def.seperateSort.size - 1) {
@@ -79,6 +80,16 @@ const appendCreate = (ctx, def, obj, res, unsafe) => {
79
80
  // add test for this
80
81
  ctx.hasSortField = -1;
81
82
  }
83
+ // if (def.hasSeperateDefaults) {
84
+ // const buf = def.seperateDefaults.bufferTmp
85
+ // if (ctx.hasDefaults !== def.seperateDefaults.props.size - 1) {
86
+ // //
87
+ // }
88
+ // if (ctx.hasDefaults !== -1) {
89
+ // buf.set(def.seperateTextSort.buffer, 0)
90
+ // }
91
+ // ctx.hasDefaults = -1
92
+ // }
82
93
  if (def.hasSeperateTextSort) {
83
94
  const buf = def.seperateTextSort.bufferTmp;
84
95
  if (ctx.hasSortText !== def.seperateTextSort.size - 1) {
@@ -8,6 +8,9 @@ export const deleteFn = (db, type, id, opts) => {
8
8
  if (!def) {
9
9
  throw new Error(`Unknown type: ${type}. Did you mean on of: ${Object.keys(db.schemaTypesParsed).join(', ')}`);
10
10
  }
11
+ if (def.insertOnly) {
12
+ throw new Error(`This type is insertOnly`);
13
+ }
11
14
  const ctx = db.modifyCtx;
12
15
  const res = new ModifyState(def.id, id, db, opts);
13
16
  const schema = db.schemaTypesParsed[type];
@@ -1,4 +1,4 @@
1
- import { isPropDef, REFERENCE, REFERENCES, STRING, TEXT, ALIAS, BINARY, CARDINALITY, VECTOR, MICRO_BUFFER, JSON, } from '@based/schema/def';
1
+ import { isPropDef, REFERENCE, REFERENCES, STRING, TEXT, ALIAS, BINARY, CARDINALITY, VECTOR, MICRO_BUFFER, JSON, COLVEC, } from '@based/schema/def';
2
2
  import { ModifyError } from './ModifyRes.js';
3
3
  import { writeReference } from './references/reference.js';
4
4
  import { writeReferences } from './references/references.js';
@@ -50,7 +50,7 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
50
50
  else if (type === CARDINALITY) {
51
51
  err = writeHll(val, ctx, schema, def, res.tmpId, mod);
52
52
  }
53
- else if (type === VECTOR) {
53
+ else if (type === VECTOR || type === COLVEC) {
54
54
  err = writeVector(val, ctx, schema, def, res.tmpId, mod);
55
55
  }
56
56
  else if (type === JSON) {
@@ -1,4 +1,5 @@
1
1
  import { ModifyCtx } from '../../index.js';
2
2
  import { SchemaTypeDef } from '@based/schema/def';
3
3
  import { ModifyOp } from './types.js';
4
- export declare const setCursor: (ctx: ModifyCtx, schema: SchemaTypeDef, field: number, typeIndex: number, id: number, modifyOp: ModifyOp, ignoreField?: boolean) => void;
4
+ export declare const setCursor: (ctx: ModifyCtx, schema: SchemaTypeDef, field: number, // TODO pass propdef better
5
+ typeIndex: number, id: number, modifyOp: ModifyOp, ignoreField?: boolean) => void;
@@ -1,4 +1,4 @@
1
- import { QueryDef, QueryTarget, Operator, QueryByAliasObj } from './query.js';
1
+ import { QueryDef, QueryTarget, Operator, QueryByAliasObj, LangFallback } from './query.js';
2
2
  import { BasedQueryResponse } from './BasedIterable.js';
3
3
  import { Search } from './search/index.js';
4
4
  import { OnData, OnError } from './subscription/index.js';
@@ -26,6 +26,11 @@ export declare class QueryBranch<T> {
26
26
  count(field?: string): T;
27
27
  sum(...fields: (string | string[])[]): T;
28
28
  cardinality(...fields: (string | string[])[]): T;
29
+ stddev(...fields: (string | string[])[]): T;
30
+ var(...fields: (string | string[])[]): T;
31
+ avg(...fields: (string | string[])[]): T;
32
+ max(...fields: (string | string[])[]): T;
33
+ min(...fields: (string | string[])[]): T;
29
34
  or(fn: FilterBranchFn): T;
30
35
  or(field: string, operator?: Operator | boolean, value?: any, opts?: FilterOpts): T;
31
36
  range(start: number, end?: number): T;
@@ -48,7 +53,7 @@ export declare class BasedDbQuery extends QueryBranch<BasedDbQuery> {
48
53
  get(): GetPromise;
49
54
  buffer: Uint8Array;
50
55
  register(): void;
51
- locale(locale: LangName): this;
56
+ locale(locale: LangName, fallBack?: LangFallback): this;
52
57
  subscribe(onData: OnData, onError?: OnError): import("./subscription/types.js").OnClose;
53
58
  _getSync(dbCtxExternal: any): BasedQueryResponse;
54
59
  }