@based/db 0.0.30 → 0.0.32

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 (175) hide show
  1. package/README.md +565 -3
  2. package/dist/lib/darwin_aarch64/include/selva/db.h +3 -2
  3. package/dist/lib/darwin_aarch64/include/selva/fields.h +10 -7
  4. package/dist/lib/darwin_aarch64/include/selva/types.h +3 -1
  5. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  6. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  7. package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
  8. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  9. package/dist/src/client/flushModify.d.ts +1 -1
  10. package/dist/src/client/flushModify.js +5 -4
  11. package/dist/src/client/index.d.ts +3 -2
  12. package/dist/src/client/modify/binary.js +1 -1
  13. package/dist/src/client/modify/cardinality.js +1 -1
  14. package/dist/src/client/modify/references/appendEdgeRefs.js +3 -0
  15. package/dist/src/client/modify/references/edge.js +6 -0
  16. package/dist/src/client/modify/references/getEdgeSize.js +1 -1
  17. package/dist/src/client/modify/string.js +10 -4
  18. package/dist/src/client/modify/text.js +1 -9
  19. package/dist/src/client/modify/types.d.ts +1 -0
  20. package/dist/src/client/modify/types.js +1 -0
  21. package/dist/src/client/modify/upsert.js +33 -21
  22. package/dist/src/client/query/BasedDbQuery.js +1 -1
  23. package/dist/src/client/query/BasedIterable.d.ts +2 -2
  24. package/dist/src/client/query/BasedIterable.js +7 -1
  25. package/dist/src/client/query/aggregates/aggregation.d.ts +4 -0
  26. package/dist/src/client/query/aggregates/aggregation.js +12 -0
  27. package/dist/src/client/query/aggregation.d.ts +1 -1
  28. package/dist/src/client/query/debug.js +3 -2
  29. package/dist/src/client/query/display.js +1 -1
  30. package/dist/src/client/query/filter/createFixedFilterBuffer.js +1 -1
  31. package/dist/src/client/query/filter/createVariableFilterBuffer.js +1 -1
  32. package/dist/src/client/query/filter/parseFilterValue.js +1 -2
  33. package/dist/src/client/query/queryDef.js +2 -2
  34. package/dist/src/client/query/read/read.js +4 -14
  35. package/dist/src/client/query/registerQuery.js +1 -1
  36. package/dist/src/client/query/search/index.d.ts +1 -1
  37. package/dist/src/client/query/search/index.js +1 -1
  38. package/dist/src/client/query/sort.d.ts +1 -1
  39. package/dist/src/client/query/toBuffer.js +11 -15
  40. package/dist/src/client/query/types.d.ts +7 -0
  41. package/dist/src/client/query/types.js +8 -0
  42. package/dist/src/client/query/validation.d.ts +1 -1
  43. package/dist/src/client/query/validation.js +4 -5
  44. package/dist/src/client/string.js +1 -3
  45. package/dist/src/client/xxHash64.d.ts +1 -1
  46. package/dist/src/index.d.ts +1 -0
  47. package/dist/src/index.js +31 -3
  48. package/dist/src/native.d.ts +1 -2
  49. package/dist/src/native.js +2 -5
  50. package/dist/src/server/csmt/draw-dot.d.ts +3 -1
  51. package/dist/src/server/csmt/draw-dot.js +7 -2
  52. package/dist/src/server/csmt/match.d.ts +1 -1
  53. package/dist/src/server/csmt/memebership-proof.d.ts +1 -1
  54. package/dist/src/server/csmt/tree-utils.d.ts +4 -4
  55. package/dist/src/server/csmt/tree.d.ts +1 -1
  56. package/dist/src/server/csmt/tree.js +1 -1
  57. package/dist/src/server/csmt/types.d.ts +10 -10
  58. package/dist/src/server/dbHash.d.ts +1 -1
  59. package/dist/src/server/dbHash.js +1 -1
  60. package/dist/src/server/index.d.ts +8 -4
  61. package/dist/src/server/index.js +28 -13
  62. package/dist/src/server/migrate/worker.js +11 -0
  63. package/dist/src/server/save.js +4 -6
  64. package/dist/src/server/start.js +17 -11
  65. package/dist/src/server/tree.d.ts +1 -1
  66. package/dist/src/server/tree.js +2 -2
  67. package/dist/src/utils.d.ts +0 -10
  68. package/dist/src/utils.js +0 -152
  69. package/package.json +3 -3
  70. package/dist/lib/darwin_aarch64/include/selva/xxhash64.h +0 -23
  71. package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
  72. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  73. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  74. package/dist/lib/linux_aarch64/include/cdefs.h +0 -317
  75. package/dist/lib/linux_aarch64/include/jemalloc.h +0 -468
  76. package/dist/lib/linux_aarch64/include/libdeflate.h +0 -322
  77. package/dist/lib/linux_aarch64/include/libdeflate_strings.h +0 -35
  78. package/dist/lib/linux_aarch64/include/linker_set.h +0 -109
  79. package/dist/lib/linux_aarch64/include/queue.h +0 -627
  80. package/dist/lib/linux_aarch64/include/selva/_export.h +0 -7
  81. package/dist/lib/linux_aarch64/include/selva/align.h +0 -9
  82. package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +0 -29
  83. package/dist/lib/linux_aarch64/include/selva/bitmap.h +0 -95
  84. package/dist/lib/linux_aarch64/include/selva/crc32c.h +0 -17
  85. package/dist/lib/linux_aarch64/include/selva/ctime.h +0 -135
  86. package/dist/lib/linux_aarch64/include/selva/db.h +0 -417
  87. package/dist/lib/linux_aarch64/include/selva/endian.h +0 -301
  88. package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +0 -23
  89. package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +0 -18
  90. package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +0 -11
  91. package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +0 -36
  92. package/dist/lib/linux_aarch64/include/selva/fields.h +0 -378
  93. package/dist/lib/linux_aarch64/include/selva/find.h +0 -47
  94. package/dist/lib/linux_aarch64/include/selva/history.h +0 -64
  95. package/dist/lib/linux_aarch64/include/selva/hll.h +0 -81
  96. package/dist/lib/linux_aarch64/include/selva/lpf.h +0 -28
  97. package/dist/lib/linux_aarch64/include/selva/node_id_set.h +0 -43
  98. package/dist/lib/linux_aarch64/include/selva/poptop.h +0 -114
  99. package/dist/lib/linux_aarch64/include/selva/queue_r.h +0 -190
  100. package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +0 -49
  101. package/dist/lib/linux_aarch64/include/selva/selva_lang.h +0 -105
  102. package/dist/lib/linux_aarch64/include/selva/selva_math.h +0 -37
  103. package/dist/lib/linux_aarch64/include/selva/selva_string.h +0 -674
  104. package/dist/lib/linux_aarch64/include/selva/sort.h +0 -140
  105. package/dist/lib/linux_aarch64/include/selva/strsearch.h +0 -43
  106. package/dist/lib/linux_aarch64/include/selva/timestamp.h +0 -25
  107. package/dist/lib/linux_aarch64/include/selva/traverse.h +0 -65
  108. package/dist/lib/linux_aarch64/include/selva/types.h +0 -104
  109. package/dist/lib/linux_aarch64/include/selva/vector.h +0 -35
  110. package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -13
  111. package/dist/lib/linux_aarch64/include/selva/xxhash64.h +0 -23
  112. package/dist/lib/linux_aarch64/include/selva_error.h +0 -137
  113. package/dist/lib/linux_aarch64/include/selva_lang_code.h +0 -157
  114. package/dist/lib/linux_aarch64/include/tree.h +0 -852
  115. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  116. package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
  117. package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
  118. package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
  119. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  120. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  121. package/dist/lib/linux_aarch64/libselva.so +0 -0
  122. package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
  123. package/dist/lib/linux_x86_64/include/cdefs.h +0 -317
  124. package/dist/lib/linux_x86_64/include/jemalloc.h +0 -468
  125. package/dist/lib/linux_x86_64/include/libdeflate.h +0 -322
  126. package/dist/lib/linux_x86_64/include/libdeflate_strings.h +0 -35
  127. package/dist/lib/linux_x86_64/include/linker_set.h +0 -109
  128. package/dist/lib/linux_x86_64/include/queue.h +0 -627
  129. package/dist/lib/linux_x86_64/include/selva/_export.h +0 -7
  130. package/dist/lib/linux_x86_64/include/selva/align.h +0 -9
  131. package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +0 -29
  132. package/dist/lib/linux_x86_64/include/selva/bitmap.h +0 -95
  133. package/dist/lib/linux_x86_64/include/selva/crc32c.h +0 -17
  134. package/dist/lib/linux_x86_64/include/selva/ctime.h +0 -135
  135. package/dist/lib/linux_x86_64/include/selva/db.h +0 -417
  136. package/dist/lib/linux_x86_64/include/selva/endian.h +0 -301
  137. package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +0 -23
  138. package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +0 -18
  139. package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +0 -11
  140. package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +0 -36
  141. package/dist/lib/linux_x86_64/include/selva/fields.h +0 -378
  142. package/dist/lib/linux_x86_64/include/selva/find.h +0 -47
  143. package/dist/lib/linux_x86_64/include/selva/history.h +0 -64
  144. package/dist/lib/linux_x86_64/include/selva/hll.h +0 -81
  145. package/dist/lib/linux_x86_64/include/selva/lpf.h +0 -28
  146. package/dist/lib/linux_x86_64/include/selva/node_id_set.h +0 -43
  147. package/dist/lib/linux_x86_64/include/selva/poptop.h +0 -114
  148. package/dist/lib/linux_x86_64/include/selva/queue_r.h +0 -190
  149. package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +0 -49
  150. package/dist/lib/linux_x86_64/include/selva/selva_lang.h +0 -105
  151. package/dist/lib/linux_x86_64/include/selva/selva_math.h +0 -37
  152. package/dist/lib/linux_x86_64/include/selva/selva_string.h +0 -674
  153. package/dist/lib/linux_x86_64/include/selva/sort.h +0 -140
  154. package/dist/lib/linux_x86_64/include/selva/strsearch.h +0 -43
  155. package/dist/lib/linux_x86_64/include/selva/timestamp.h +0 -25
  156. package/dist/lib/linux_x86_64/include/selva/traverse.h +0 -65
  157. package/dist/lib/linux_x86_64/include/selva/types.h +0 -104
  158. package/dist/lib/linux_x86_64/include/selva/vector.h +0 -35
  159. package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -13
  160. package/dist/lib/linux_x86_64/include/selva/xxhash64.h +0 -23
  161. package/dist/lib/linux_x86_64/include/selva_error.h +0 -137
  162. package/dist/lib/linux_x86_64/include/selva_lang_code.h +0 -157
  163. package/dist/lib/linux_x86_64/include/tree.h +0 -852
  164. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  165. package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
  166. package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
  167. package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
  168. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  169. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  170. package/dist/lib/linux_x86_64/libselva.so +0 -0
  171. package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
  172. package/dist/src/client/query/subscription/markers.d.ts +0 -10
  173. package/dist/src/client/query/subscription/markers.js +0 -213
  174. package/dist/src/client/query/subscription/run.d.ts +0 -5
  175. package/dist/src/client/query/subscription/run.js +0 -76
@@ -1,95 +0,0 @@
1
- /*
2
- * Copyright (c) 2021, 2023, 2025 SAULX
3
- * SPDX-License-Identifier: BSD-2-Clause
4
- */
5
-
6
- #pragma once
7
-
8
- #include <stddef.h>
9
- #include <stdint.h>
10
- #include "selva/_export.h"
11
-
12
- #if __SIZEOF_INT128__ != 16
13
- #error The compiler and architecture must have Tetra-Integer support
14
- #endif
15
-
16
- typedef unsigned __int128 bitmap_t;
17
-
18
- /**
19
- * A flexible bitmap.
20
- */
21
- struct bitmap {
22
- size_t nbits;
23
- bitmap_t d[];
24
- };
25
-
26
- #define BITMAP_CEILING(x, y) \
27
- (((x) + (y) - (size_t)1) / (y))
28
-
29
- /*
30
- * We use this instead of max() to avoid GCC compound statements that don't work
31
- * outside of functions. C23 constexpr might make compound statements available
32
- * for initialization but compound statements are currently only supported in
33
- * GCC 13 and there is no support in Clang.
34
- */
35
- #define BITMAP_MAX(a, b) \
36
- ((a) > (b) ? (a) : (b))
37
-
38
- #define BITMAP_D_SIZE(nbits) \
39
- (BITMAP_CEILING(BITMAP_MAX((size_t)(nbits), (size_t)8) / (size_t)8, sizeof(bitmap_t)) * sizeof(bitmap_t))
40
-
41
- /**
42
- * Byte size of a bitmap struct passable to a malloc()-like function.
43
- * nbits must be a literal or variable.
44
- */
45
- #define BITMAP_ALLOC_SIZE(nbits) \
46
- (sizeof(struct bitmap) + BITMAP_D_SIZE(nbits))
47
-
48
- /**
49
- * Get the status of a bit in a bitmap pointed by bitmap.
50
- * @param bitmap is a pointer to a bitmap.
51
- * @param pos is the bit position to be checked.
52
- * @return Boolean value or -1.
53
- */
54
- SELVA_EXPORT
55
- int bitmap_get(const struct bitmap *bitmap, size_t pos)
56
- __attribute__((pure, access(read_only, 1)));
57
-
58
- /**
59
- * Set a bit in a bitmap pointed by bitmap.
60
- * @param bitmap is a pointer to a bitmap.
61
- * @param pos is the bit position to be set.
62
- * @return 0 or -1.
63
- */
64
- SELVA_EXPORT
65
- int bitmap_set(struct bitmap *bitmap, size_t pos)
66
- __attribute__((access(read_write, 1)));
67
-
68
- /**
69
- * Clear a bit in a bitmap pointed by bitmap.
70
- * @param bitmap is a pointer to a bitmap.
71
- * @param pos is the bit position to be cleared.
72
- * @return 0 or -1.
73
- */
74
- SELVA_EXPORT
75
- int bitmap_clear(struct bitmap *bitmap, size_t pos)
76
- __attribute__((access(read_write, 1)));
77
-
78
- /**
79
- * Erase the whole bitmap.
80
- * @param bitmap is a pointer to a bitmap.
81
- */
82
- SELVA_EXPORT
83
- void bitmap_erase(struct bitmap *bitmap)
84
- __attribute__((access(read_write, 1)));
85
-
86
- SELVA_EXPORT
87
- long long bitmap_popcount(const struct bitmap *bitmap)
88
- __attribute__((pure, access(read_only, 1)));
89
-
90
- /**
91
- * Find first set.
92
- */
93
- SELVA_EXPORT
94
- int bitmap_ffs(const struct bitmap *bitmap)
95
- __attribute__((pure, access(read_only, 1)));
@@ -1,17 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 SAULX
3
- * Copyright (C) 2013, 2021 Mark Adler <madler@alumni.caltech.edu>
4
- * SPDX-License-Identifier: Zlib
5
- */
6
- #pragma once
7
-
8
- #include <stddef.h>
9
- #include <stdint.h>
10
- #include "selva/_export.h"
11
-
12
- /**
13
- * Compute CRC-32C.
14
- */
15
- SELVA_EXPORT
16
- uint32_t crc32c(uint32_t crc, void const *buf, size_t len)
17
- __attribute__((pure, access(read_only, 2, 3)));
@@ -1,135 +0,0 @@
1
- /**
2
- *******************************************************************************
3
- * @file ctime.h
4
- * @author Olli Vanhoja
5
- * @brief time types.
6
- * @section LICENSE
7
- * Copyright (c) 2022-2025 Saulx
8
- * Copyright (c) 2020 Olli Vanhoja <olli.vanhoja@alumni.helsinki.fi>
9
- * Copyright (c) 2014 - 2016 Olli Vanhoja <olli.vanhoja@cs.helsinki.fi>
10
- * All rights reserved.
11
- *
12
- * Redistribution and use in source and binary forms, with or without
13
- * modification, are permitted provided that the following conditions are met:
14
- *
15
- * 1. Redistributions of source code must retain the above copyright notice,
16
- * this list of conditions and the following disclaimer.
17
- * 2. Redistributions in binary form must reproduce the above copyright notice,
18
- * this list of conditions and the following disclaimer in the documentation
19
- * and/or other materials provided with the distribution.
20
- *
21
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
- * POSSIBILITY OF SUCH DAMAGE.
32
- * SPDX-License-Identifier: BSD-2-Clause
33
- *******************************************************************************
34
- */
35
-
36
- #pragma once
37
-
38
- #include <stdint.h>
39
- #include <time.h>
40
- #include "selva/_export.h"
41
-
42
- /**
43
- * Conver an msec value to a timespec struct.
44
- * @param[out] ts is a pointer to the destination struct.
45
- * @param[in] nsec is the value in milliseconds.
46
- */
47
- SELVA_EXPORT
48
- struct timespec *msec2timespec(struct timespec * ts, int64_t msec);
49
-
50
- #define MSEC2TIMESPEC(msec) \
51
- ({ struct timespec _ts; (void)msec2timespec(&_ts, msec); _ts; })
52
-
53
- /**
54
- * Convert a nsec value to a timespec struct.
55
- * @param[out] ts is a pointer to the destination struct.
56
- * @param[in] nsec is the value in nanoseconds.
57
- */
58
- SELVA_EXPORT
59
- struct timespec *nsec2timespec(struct timespec * ts, int64_t nsec);
60
-
61
- #define NSEC2TIMESPEC(nsec) \
62
- ({ struct timespec _ts; (void)NSEC2TIMESPEC(&_ts, nsec); _ts; })
63
-
64
- /**
65
- * Compare two timespec structs.
66
- * @param[in] left is a pointer to the left value.
67
- * @param[in] right is a pointer to the right value.
68
- * @param[in] cmp is the operator (<, >, ==, <=, or >=).
69
- * @returns a boolean value.
70
- */
71
- #define timespec_cmp(left_tsp, right_tsp, cmp) ({ \
72
- (((left_tsp)->tv_sec == (right_tsp)->tv_sec) \
73
- ? ((left_tsp)->tv_nsec cmp (right_tsp)->tv_nsec) \
74
- : ((left_tsp)->tv_sec cmp (right_tsp)->tv_sec)); \
75
- })
76
-
77
- /**
78
- * Calculate the sum of two timespec structs.
79
- * @param[out] sum is a pointer to the destination struct.
80
- * @param[in] left is a pointer to the left value.
81
- * @param[in] right is a pointer to the right value.
82
- */
83
- SELVA_EXPORT
84
- void timespec_add(struct timespec * sum, const struct timespec * left,
85
- const struct timespec * right)
86
- __attribute__((access(write_only, 1), access(read_only, 2), access(read_only, 3)));
87
-
88
- /**
89
- * Calculate the difference of two timespec structs.
90
- * @param[out] sum is a pointer to the destination struct.
91
- * @param[in] left is a pointer to the left value.
92
- * @param[in] right is a pointer to the right value.
93
- */
94
- SELVA_EXPORT
95
- void timespec_sub(struct timespec * diff, const struct timespec * left,
96
- const struct timespec * right)
97
- __attribute__((access(write_only, 1), access(read_only, 2), access(read_only, 3)));
98
-
99
- /**
100
- * Calculate the product of two timespec structs.
101
- * @param[out] sum is a pointer to the destination struct.
102
- * @param[in] left is a pointer to the left value.
103
- * @param[in] right is a pointer to the right value.
104
- */
105
- SELVA_EXPORT
106
- void timespec_mul(struct timespec * prod, const struct timespec * left,
107
- const struct timespec * right)
108
- __attribute__((access(write_only, 1), access(read_only, 2), access(read_only, 3)));
109
-
110
- /**
111
- * Calculate the quotient of two timespec structs.
112
- * @param[out] sum is a pointer to the destination struct.
113
- * @param[in] left is a pointer to the left value.
114
- * @param[in] right is a pointer to the right value.
115
- */
116
- SELVA_EXPORT
117
- void timespec_div(struct timespec * quot, const struct timespec * left,
118
- const struct timespec * right)
119
- __attribute__((access(write_only, 1), access(read_only, 2), access(read_only, 3)));
120
-
121
- /**
122
- * Calculate the modulo of two timespec structs.
123
- * @param[out] sum is a pointer to the destination struct.
124
- * @param[in] left is a pointer to the left value.
125
- * @param[in] right is a pointer to the right value.
126
- */
127
- void timespec_mod(struct timespec * rem, const struct timespec * left,
128
- const struct timespec * right)
129
- __attribute__((access(write_only, 1), access(read_only, 2), access(read_only, 3)));
130
-
131
- static inline double timespec2ms(const struct timespec *ts)
132
- {
133
- return (double)ts->tv_sec * 1000.0 + (double)ts->tv_nsec / 1.0e6;
134
- }
135
-
@@ -1,417 +0,0 @@
1
- /*
2
- * Copyright (c) 2024-2025 SAULX
3
- * SPDX-License-Identifier: MIT
4
- */
5
- #pragma once
6
-
7
- #include <assert.h>
8
- #include <sys/types.h>
9
- #include "selva/_export.h"
10
- #include "selva/types.h"
11
-
12
- /*
13
- * TODO Don't like this one but it compiles.
14
- * We should have something with selva_hash_state;
15
- */
16
- struct XXH3_state_s;
17
-
18
- /**
19
- * Create a new DB instance.
20
- */
21
- SELVA_EXPORT
22
- struct SelvaDb *selva_db_create(void);
23
-
24
- /**
25
- * Destroy a DB instance.
26
- */
27
- SELVA_EXPORT
28
- void selva_db_destroy(struct SelvaDb *db) __attribute__((nonnull));
29
-
30
- /**
31
- * Create a new node type with a schema.
32
- * @param type must not exist before.
33
- */
34
- SELVA_EXPORT
35
- int selva_db_create_type(struct SelvaDb *db, node_type_t type, const char *schema_buf, size_t schema_len) __attribute__((nonnull));
36
-
37
- /**
38
- * Save the common/shared data of the database.
39
- */
40
- SELVA_EXPORT
41
- int selva_dump_save_common(struct SelvaDb *db, const char *filename) __attribute__((nonnull));
42
-
43
- /**
44
- * Save a range of nodes from te.
45
- */
46
- SELVA_EXPORT
47
- int selva_dump_save_range(struct SelvaDb *db, struct SelvaTypeEntry *te, const char *filename, node_id_t start, node_id_t end, selva_hash128_t *range_hash_out) __attribute__((nonnull));
48
-
49
- /**
50
- * **Usage:**
51
- * ```c
52
- * struct SelvaDb *db = selva_db_create();
53
- * selva_dump_load_common(db, filename_common);
54
- * selva_dump_load_range(db, filename_range_n);
55
- * ```
56
- */
57
- SELVA_EXPORT
58
- int selva_dump_load_common(struct SelvaDb *db, const char *filename, char *errlog_buf, size_t errlog_size) __attribute__((nonnull));
59
-
60
- SELVA_EXPORT
61
- int selva_dump_load_range(struct SelvaDb *db, const char *filename, char *errlog_buf, size_t errlog_size) __attribute__((nonnull));
62
-
63
- /**
64
- * Find a type by type id.
65
- */
66
- SELVA_EXPORT
67
- struct SelvaTypeEntry *selva_get_type_by_index(const struct SelvaDb *db, node_type_t type) __attribute__((nonnull));
68
-
69
- /**
70
- * Get the type for node.
71
- */
72
- SELVA_EXPORT
73
- struct SelvaTypeEntry *selva_get_type_by_node(const struct SelvaDb *db, struct SelvaNode *node) __attribute__((nonnull, pure));
74
-
75
- SELVA_EXPORT
76
- inline block_id_t selva_get_block_capacity(const struct SelvaTypeEntry *te)
77
- #ifndef __zig
78
- {
79
- return te->blocks->block_capacity;
80
- }
81
- #else
82
- ;
83
- #endif
84
-
85
- /**
86
- * Get the node schema for type.
87
- */
88
- SELVA_EXPORT
89
- __attribute__((nonnull, pure))
90
- inline const struct SelvaNodeSchema *selva_get_ns_by_te(const struct SelvaTypeEntry *te)
91
- #ifndef __zig
92
- {
93
- return &te->ns;
94
- }
95
- #else
96
- ;
97
- #endif
98
-
99
- SELVA_EXPORT
100
- __attribute__((nonnull, pure))
101
- inline const struct SelvaFieldSchema *get_fs_by_fields_schema_field(const struct SelvaFieldsSchema *fields_schema, field_t field)
102
- #ifndef __zig
103
- {
104
- if (field >= fields_schema->nr_fields) {
105
- return nullptr;
106
- }
107
-
108
- return &fields_schema->field_schemas[field];
109
- }
110
- #else
111
- ;
112
- #endif
113
-
114
- /**
115
- * Get the field schema for field.
116
- */
117
- SELVA_EXPORT
118
- __attribute__((nonnull, pure))
119
- inline const struct SelvaFieldSchema *selva_get_fs_by_te_field(const struct SelvaTypeEntry *te, field_t field)
120
- #ifndef __zig
121
- {
122
- return get_fs_by_fields_schema_field(&te->ns.fields_schema, field);
123
- }
124
- #else
125
- ;
126
- #endif
127
-
128
- /**
129
- * Get the field schema for field.
130
- */
131
- SELVA_EXPORT
132
- __attribute__((nonnull, pure))
133
- inline const struct SelvaFieldSchema *selva_get_fs_by_ns_field(const struct SelvaNodeSchema *ns, field_t field)
134
- #ifndef __zig
135
- {
136
- return get_fs_by_fields_schema_field(&ns->fields_schema, field);
137
- }
138
- #else
139
- ;
140
- #endif
141
-
142
- /**
143
- * Get the field schema for field.
144
- */
145
- SELVA_EXPORT
146
- __attribute__((nonnull, pure))
147
- inline const struct SelvaFieldSchema *selva_get_fs_by_node(struct SelvaDb *db, struct SelvaNode *node, field_t field)
148
- #ifndef __zig
149
- {
150
- struct SelvaTypeEntry *type;
151
-
152
- type = selva_get_type_by_node(db, node);
153
- if (!type) {
154
- return nullptr;
155
- }
156
-
157
- return selva_get_fs_by_ns_field(&type->ns, field);
158
- }
159
- #else
160
- ;
161
- #endif
162
-
163
- SELVA_EXPORT
164
- #if __has_c_attribute(reproducible)
165
- [[reproducible]]
166
- #endif
167
- inline enum SelvaFieldType selva_get_fs_type(const struct SelvaFieldSchema *fs)
168
- #ifndef __zig
169
- {
170
- return fs->type;
171
- }
172
- #else
173
- ;
174
- #endif
175
-
176
- /**
177
- * Get the EdgeFieldConstraint from a ref field schema.
178
- * struct EdgeFieldConstraint *efc = selva_get_edge_field_constraint(src_fs);
179
- * struct SelvaTypeEntry *dst_type = selva_get_type_by_index(db, efc->dst_node_type);
180
- * struct SelvaFieldSchema *dst_fs = selva_get_fs_by_node(db, dst, efc->inverse_field);
181
- */
182
- SELVA_EXPORT
183
- __attribute__((returns_nonnull))
184
- __attribute__((nonnull))
185
- inline const struct EdgeFieldConstraint *selva_get_edge_field_constraint(const struct SelvaFieldSchema *fs)
186
- #ifndef __zig
187
- {
188
- assert(fs->type == SELVA_FIELD_TYPE_REFERENCE ||
189
- fs->type == SELVA_FIELD_TYPE_REFERENCES ||
190
- fs->type == SELVA_FIELD_TYPE_WEAK_REFERENCE ||
191
- fs->type == SELVA_FIELD_TYPE_WEAK_REFERENCES);
192
- return &fs->edge_constraint;
193
- }
194
- #else
195
- ;
196
- #endif
197
-
198
- SELVA_EXPORT
199
- const struct SelvaFieldsSchema *selva_get_edge_field_fields_schema(struct SelvaDb *db, const struct EdgeFieldConstraint *efc);
200
-
201
- SELVA_EXPORT
202
- void selva_expire_node(struct SelvaDb *db, node_type_t type, node_id_t node_id, int64_t ts);
203
-
204
- SELVA_EXPORT
205
- void selva_expire_node_cancel(struct SelvaDb *db, node_type_t type, node_id_t node_id);
206
-
207
- SELVA_EXPORT
208
- void selva_db_expire_tick(struct SelvaDb *db, int64_t now);
209
-
210
- /**
211
- * Delete a node.
212
- */
213
- SELVA_EXPORT
214
- void selva_del_node(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node) __attribute__((nonnull));
215
-
216
- /**
217
- * Get a node by id.
218
- */
219
- SELVA_EXPORT
220
- struct SelvaNode *selva_find_node(struct SelvaTypeEntry *type, node_id_t node_id) __attribute__((nonnull));
221
-
222
- /**
223
- * Find the first node greater than or equal to the provided id, or NULL.
224
- */
225
- SELVA_EXPORT
226
- struct SelvaNode *selva_nfind_node(struct SelvaTypeEntry *type, node_id_t node_id) __attribute__((nonnull));
227
-
228
- /**
229
- * Get or create a node by id.
230
- */
231
- SELVA_EXPORT
232
- struct SelvaNode *selva_upsert_node(struct SelvaTypeEntry *type, node_id_t node_id) __attribute__((nonnull));
233
-
234
- /**
235
- * **Example**
236
- * ```c
237
- * for (struct SelvaNode *np = selva_min_node(type); np; np = selva_next_node(type, np))
238
- * ```
239
- */
240
- SELVA_EXPORT
241
- struct SelvaNode *selva_min_node(struct SelvaTypeEntry *type) __attribute__((nonnull));
242
-
243
- /**
244
- * **Example**
245
- * ```c
246
- * for (struct SelvaNode *np = selva_max_node(type); np; np = selva_prev_node(type, np))
247
- * ```
248
- */
249
- SELVA_EXPORT
250
- struct SelvaNode *selva_max_node(struct SelvaTypeEntry *type) __attribute__((nonnull));
251
-
252
- /**
253
- * Get previous node with a lower node id.
254
- */
255
- SELVA_EXPORT
256
- struct SelvaNode *selva_prev_node(struct SelvaTypeEntry *type, struct SelvaNode *node) __attribute__((nonnull));
257
-
258
- /**
259
- * Get next node with higher node id.
260
- */
261
- SELVA_EXPORT
262
- struct SelvaNode *selva_next_node(struct SelvaTypeEntry *type, struct SelvaNode *node) __attribute__((nonnull));
263
-
264
- /**
265
- * \addtogroup db_cursor
266
- * @{
267
- */
268
-
269
- /**
270
- * Create a new cursor pointing to node.
271
- * If the node is deleted later then the cursor is updated to point to the next
272
- * node using selva_next_node().
273
- */
274
- SELVA_EXPORT
275
- cursor_id_t selva_cursor_new(struct SelvaTypeEntry *type, struct SelvaNode *node) __attribute__((nonnull));
276
-
277
- /**
278
- * Get a pointer to the node from a cursor.
279
- */
280
- SELVA_EXPORT
281
- struct SelvaNode *selva_cursor_get(struct SelvaTypeEntry *type, cursor_id_t id) __attribute__((nonnull));
282
-
283
- /**
284
- * Update a cursor to point to a new node.
285
- */
286
- SELVA_EXPORT
287
- int selva_cursor_update(struct SelvaTypeEntry *type, cursor_id_t id, struct SelvaNode *node) __attribute__((nonnull));
288
-
289
- /**
290
- * Delete a cursor.
291
- */
292
- SELVA_EXPORT
293
- void selva_cursor_del(struct SelvaTypeEntry *type, cursor_id_t id) __attribute__((nonnull));
294
-
295
- /**
296
- * Total count of cursors of type.
297
- */
298
- SELVA_EXPORT
299
- size_t selva_cursor_count(const struct SelvaTypeEntry *type) __attribute__((nonnull));
300
-
301
- /**
302
- * @}
303
- */
304
-
305
- /**
306
- * Total count of nodes of type.
307
- */
308
- SELVA_EXPORT
309
- size_t selva_node_count(const struct SelvaTypeEntry *type) __attribute__((nonnull));
310
-
311
- /**
312
- * Get the node id of of node.
313
- */
314
- SELVA_EXPORT
315
- __attribute__((nonnull, pure))
316
- inline node_id_t selva_get_node_id(const struct SelvaNode *node)
317
- #ifndef __zig
318
- {
319
- return node->node_id;
320
- }
321
- #else
322
- ;
323
- #endif
324
-
325
- /**
326
- * Get the type of of node.
327
- */
328
- SELVA_EXPORT
329
- __attribute__((nonnull, pure))
330
- inline node_type_t selva_get_node_type(const struct SelvaNode *node)
331
- #ifndef __zig
332
- {
333
- return node->type;
334
- }
335
- #else
336
- ;
337
- #endif
338
-
339
- /**
340
- * \addtogroup node_hash
341
- * @{
342
- */
343
-
344
- /**
345
- * Calculate the node hash.
346
- * Update node hash by using a temp hash state allocated earlier.
347
- * @param tmp_hash_state is only used for computation and it's reset before use.
348
- */
349
- SELVA_EXPORT
350
- selva_hash128_t selva_node_hash_update(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node, struct XXH3_state_s *tmp_hash_state);
351
-
352
- SELVA_EXPORT
353
- selva_hash128_t selva_node_hash(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node);
354
-
355
- SELVA_EXPORT
356
- int selva_node_hash_range(struct SelvaDb *db, struct SelvaTypeEntry *type, node_id_t start, node_id_t end, selva_hash128_t *hash_out) __attribute__((nonnull, warn_unused_result));
357
-
358
- /**
359
- * @}
360
- */
361
-
362
- /**
363
- * Get the number of aliases under given type.
364
- */
365
- SELVA_EXPORT
366
- size_t selva_alias_count(const struct SelvaAliases *aliases);
367
-
368
- /**
369
- * Set new alias.
370
- * @param name is copied.
371
- * @returns the previous node_id the alias was pointing to; Otherwise 0.
372
- */
373
- SELVA_EXPORT
374
- node_id_t selva_set_alias(struct SelvaAliases *aliases, node_id_t dest, const char *name_str, size_t name_len);
375
-
376
- /**
377
- * Delete alias by name.
378
- * @return the destination node_id the alias was pointing to; 0 if SELVA_ENOENT.
379
- */
380
- SELVA_EXPORT
381
- node_id_t selva_del_alias_by_name(struct SelvaAliases *aliases, const char *name_str, size_t name_len);
382
-
383
- /**
384
- * Delete all aliases pointing to dest.
385
- */
386
- SELVA_EXPORT
387
- void selva_del_alias_by_dest(struct SelvaAliases *aliases, node_id_t dest);
388
-
389
- /**
390
- * Get alias by name.
391
- */
392
- SELVA_EXPORT
393
- struct SelvaNode *selva_get_alias(struct SelvaTypeEntry *type, struct SelvaAliases *aliases, const char *name_str, size_t name_len);
394
-
395
- /**
396
- * Get alias by destination id.
397
- * This may not seem very useful but this is actually the way that allows you to
398
- * traverse all aliases to the given node_id by following the `next` pointer or
399
- * by calling selva_get_next_alias().
400
- */
401
- SELVA_EXPORT
402
- const struct SelvaAlias *selva_get_alias_by_dest(struct SelvaAliases *aliases, node_id_t dest);
403
-
404
- SELVA_EXPORT
405
- const struct SelvaAlias *selva_get_next_alias(const struct SelvaAlias *alias);
406
-
407
- SELVA_EXPORT
408
- const char *selva_get_alias_name(const struct SelvaAlias *alias, size_t *len) __attribute__((nonnull(1), pure));
409
-
410
- SELVA_EXPORT
411
- struct SelvaAliases *selva_get_aliases(struct SelvaTypeEntry *type, field_t field);
412
-
413
- /***
414
- * Remove all aliases to the given node_id.
415
- */
416
- SELVA_EXPORT
417
- void selva_remove_all_aliases(struct SelvaTypeEntry *type, node_id_t node_id);