@based/db 0.0.31 → 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 (172) hide show
  1. package/README.md +565 -3
  2. package/dist/lib/darwin_aarch64/include/selva/db.h +1 -1
  3. package/dist/lib/darwin_aarch64/include/selva/fields.h +0 -2
  4. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  5. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  6. package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
  7. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  8. package/dist/src/client/flushModify.d.ts +1 -1
  9. package/dist/src/client/flushModify.js +5 -4
  10. package/dist/src/client/index.d.ts +3 -2
  11. package/dist/src/client/modify/binary.js +1 -1
  12. package/dist/src/client/modify/cardinality.js +1 -1
  13. package/dist/src/client/modify/references/appendEdgeRefs.js +3 -0
  14. package/dist/src/client/modify/references/edge.js +6 -0
  15. package/dist/src/client/modify/references/getEdgeSize.js +1 -1
  16. package/dist/src/client/modify/string.js +10 -4
  17. package/dist/src/client/modify/text.js +1 -9
  18. package/dist/src/client/modify/types.d.ts +1 -0
  19. package/dist/src/client/modify/types.js +1 -0
  20. package/dist/src/client/modify/upsert.js +33 -21
  21. package/dist/src/client/query/BasedDbQuery.js +1 -1
  22. package/dist/src/client/query/BasedIterable.d.ts +2 -2
  23. package/dist/src/client/query/BasedIterable.js +7 -1
  24. package/dist/src/client/query/aggregates/aggregation.d.ts +4 -0
  25. package/dist/src/client/query/aggregates/aggregation.js +12 -0
  26. package/dist/src/client/query/aggregation.d.ts +1 -1
  27. package/dist/src/client/query/debug.js +3 -2
  28. package/dist/src/client/query/display.js +1 -1
  29. package/dist/src/client/query/filter/createFixedFilterBuffer.js +1 -1
  30. package/dist/src/client/query/filter/createVariableFilterBuffer.js +1 -1
  31. package/dist/src/client/query/filter/parseFilterValue.js +1 -2
  32. package/dist/src/client/query/queryDef.js +2 -2
  33. package/dist/src/client/query/read/read.js +4 -14
  34. package/dist/src/client/query/registerQuery.js +1 -1
  35. package/dist/src/client/query/search/index.d.ts +1 -1
  36. package/dist/src/client/query/search/index.js +1 -1
  37. package/dist/src/client/query/sort.d.ts +1 -1
  38. package/dist/src/client/query/toBuffer.js +11 -15
  39. package/dist/src/client/query/types.d.ts +7 -0
  40. package/dist/src/client/query/types.js +8 -0
  41. package/dist/src/client/query/validation.d.ts +1 -1
  42. package/dist/src/client/query/validation.js +4 -5
  43. package/dist/src/client/string.js +1 -3
  44. package/dist/src/client/xxHash64.d.ts +1 -1
  45. package/dist/src/index.d.ts +1 -0
  46. package/dist/src/index.js +5 -1
  47. package/dist/src/native.d.ts +1 -2
  48. package/dist/src/native.js +2 -5
  49. package/dist/src/server/csmt/draw-dot.d.ts +3 -1
  50. package/dist/src/server/csmt/draw-dot.js +7 -2
  51. package/dist/src/server/csmt/match.d.ts +1 -1
  52. package/dist/src/server/csmt/memebership-proof.d.ts +1 -1
  53. package/dist/src/server/csmt/tree-utils.d.ts +4 -4
  54. package/dist/src/server/csmt/tree.d.ts +1 -1
  55. package/dist/src/server/csmt/tree.js +1 -1
  56. package/dist/src/server/csmt/types.d.ts +10 -10
  57. package/dist/src/server/dbHash.d.ts +1 -1
  58. package/dist/src/server/dbHash.js +1 -1
  59. package/dist/src/server/index.d.ts +8 -4
  60. package/dist/src/server/index.js +28 -13
  61. package/dist/src/server/migrate/worker.js +11 -0
  62. package/dist/src/server/save.js +3 -2
  63. package/dist/src/server/start.js +9 -5
  64. package/dist/src/utils.d.ts +0 -10
  65. package/dist/src/utils.js +0 -152
  66. package/package.json +3 -3
  67. package/dist/lib/darwin_aarch64/include/selva/xxhash64.h +0 -23
  68. package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
  69. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  70. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  71. package/dist/lib/linux_aarch64/include/cdefs.h +0 -317
  72. package/dist/lib/linux_aarch64/include/jemalloc.h +0 -468
  73. package/dist/lib/linux_aarch64/include/libdeflate.h +0 -322
  74. package/dist/lib/linux_aarch64/include/libdeflate_strings.h +0 -35
  75. package/dist/lib/linux_aarch64/include/linker_set.h +0 -109
  76. package/dist/lib/linux_aarch64/include/queue.h +0 -627
  77. package/dist/lib/linux_aarch64/include/selva/_export.h +0 -7
  78. package/dist/lib/linux_aarch64/include/selva/align.h +0 -9
  79. package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +0 -29
  80. package/dist/lib/linux_aarch64/include/selva/bitmap.h +0 -95
  81. package/dist/lib/linux_aarch64/include/selva/crc32c.h +0 -17
  82. package/dist/lib/linux_aarch64/include/selva/ctime.h +0 -135
  83. package/dist/lib/linux_aarch64/include/selva/db.h +0 -418
  84. package/dist/lib/linux_aarch64/include/selva/endian.h +0 -301
  85. package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +0 -23
  86. package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +0 -18
  87. package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +0 -11
  88. package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +0 -36
  89. package/dist/lib/linux_aarch64/include/selva/fields.h +0 -383
  90. package/dist/lib/linux_aarch64/include/selva/find.h +0 -47
  91. package/dist/lib/linux_aarch64/include/selva/history.h +0 -64
  92. package/dist/lib/linux_aarch64/include/selva/hll.h +0 -81
  93. package/dist/lib/linux_aarch64/include/selva/lpf.h +0 -28
  94. package/dist/lib/linux_aarch64/include/selva/node_id_set.h +0 -43
  95. package/dist/lib/linux_aarch64/include/selva/poptop.h +0 -114
  96. package/dist/lib/linux_aarch64/include/selva/queue_r.h +0 -190
  97. package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +0 -49
  98. package/dist/lib/linux_aarch64/include/selva/selva_lang.h +0 -105
  99. package/dist/lib/linux_aarch64/include/selva/selva_math.h +0 -37
  100. package/dist/lib/linux_aarch64/include/selva/selva_string.h +0 -674
  101. package/dist/lib/linux_aarch64/include/selva/sort.h +0 -140
  102. package/dist/lib/linux_aarch64/include/selva/strsearch.h +0 -43
  103. package/dist/lib/linux_aarch64/include/selva/timestamp.h +0 -25
  104. package/dist/lib/linux_aarch64/include/selva/traverse.h +0 -65
  105. package/dist/lib/linux_aarch64/include/selva/types.h +0 -106
  106. package/dist/lib/linux_aarch64/include/selva/vector.h +0 -35
  107. package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -13
  108. package/dist/lib/linux_aarch64/include/selva/xxhash64.h +0 -23
  109. package/dist/lib/linux_aarch64/include/selva_error.h +0 -137
  110. package/dist/lib/linux_aarch64/include/selva_lang_code.h +0 -157
  111. package/dist/lib/linux_aarch64/include/tree.h +0 -852
  112. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  113. package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
  114. package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
  115. package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
  116. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  117. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  118. package/dist/lib/linux_aarch64/libselva.so +0 -0
  119. package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
  120. package/dist/lib/linux_x86_64/include/cdefs.h +0 -317
  121. package/dist/lib/linux_x86_64/include/jemalloc.h +0 -468
  122. package/dist/lib/linux_x86_64/include/libdeflate.h +0 -322
  123. package/dist/lib/linux_x86_64/include/libdeflate_strings.h +0 -35
  124. package/dist/lib/linux_x86_64/include/linker_set.h +0 -109
  125. package/dist/lib/linux_x86_64/include/queue.h +0 -627
  126. package/dist/lib/linux_x86_64/include/selva/_export.h +0 -7
  127. package/dist/lib/linux_x86_64/include/selva/align.h +0 -9
  128. package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +0 -29
  129. package/dist/lib/linux_x86_64/include/selva/bitmap.h +0 -95
  130. package/dist/lib/linux_x86_64/include/selva/crc32c.h +0 -17
  131. package/dist/lib/linux_x86_64/include/selva/ctime.h +0 -135
  132. package/dist/lib/linux_x86_64/include/selva/db.h +0 -418
  133. package/dist/lib/linux_x86_64/include/selva/endian.h +0 -301
  134. package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +0 -23
  135. package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +0 -18
  136. package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +0 -11
  137. package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +0 -36
  138. package/dist/lib/linux_x86_64/include/selva/fields.h +0 -383
  139. package/dist/lib/linux_x86_64/include/selva/find.h +0 -47
  140. package/dist/lib/linux_x86_64/include/selva/history.h +0 -64
  141. package/dist/lib/linux_x86_64/include/selva/hll.h +0 -81
  142. package/dist/lib/linux_x86_64/include/selva/lpf.h +0 -28
  143. package/dist/lib/linux_x86_64/include/selva/node_id_set.h +0 -43
  144. package/dist/lib/linux_x86_64/include/selva/poptop.h +0 -114
  145. package/dist/lib/linux_x86_64/include/selva/queue_r.h +0 -190
  146. package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +0 -49
  147. package/dist/lib/linux_x86_64/include/selva/selva_lang.h +0 -105
  148. package/dist/lib/linux_x86_64/include/selva/selva_math.h +0 -37
  149. package/dist/lib/linux_x86_64/include/selva/selva_string.h +0 -674
  150. package/dist/lib/linux_x86_64/include/selva/sort.h +0 -140
  151. package/dist/lib/linux_x86_64/include/selva/strsearch.h +0 -43
  152. package/dist/lib/linux_x86_64/include/selva/timestamp.h +0 -25
  153. package/dist/lib/linux_x86_64/include/selva/traverse.h +0 -65
  154. package/dist/lib/linux_x86_64/include/selva/types.h +0 -106
  155. package/dist/lib/linux_x86_64/include/selva/vector.h +0 -35
  156. package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -13
  157. package/dist/lib/linux_x86_64/include/selva/xxhash64.h +0 -23
  158. package/dist/lib/linux_x86_64/include/selva_error.h +0 -137
  159. package/dist/lib/linux_x86_64/include/selva_lang_code.h +0 -157
  160. package/dist/lib/linux_x86_64/include/tree.h +0 -852
  161. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  162. package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
  163. package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
  164. package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
  165. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  166. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  167. package/dist/lib/linux_x86_64/libselva.so +0 -0
  168. package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
  169. package/dist/src/client/query/subscription/markers.d.ts +0 -10
  170. package/dist/src/client/query/subscription/markers.js +0 -213
  171. package/dist/src/client/query/subscription/run.d.ts +0 -5
  172. 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,418 +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
- * @param dirty_cb is called for any newly dirty nodes in addition to the node being deleted.
213
- */
214
- SELVA_EXPORT
215
- 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)));
216
-
217
- /**
218
- * Get a node by id.
219
- */
220
- SELVA_EXPORT
221
- struct SelvaNode *selva_find_node(struct SelvaTypeEntry *type, node_id_t node_id) __attribute__((nonnull));
222
-
223
- /**
224
- * Find the first node greater than or equal to the provided id, or NULL.
225
- */
226
- SELVA_EXPORT
227
- struct SelvaNode *selva_nfind_node(struct SelvaTypeEntry *type, node_id_t node_id) __attribute__((nonnull));
228
-
229
- /**
230
- * Get or create a node by id.
231
- */
232
- SELVA_EXPORT
233
- struct SelvaNode *selva_upsert_node(struct SelvaTypeEntry *type, node_id_t node_id) __attribute__((nonnull));
234
-
235
- /**
236
- * **Example**
237
- * ```c
238
- * for (struct SelvaNode *np = selva_min_node(type); np; np = selva_next_node(type, np))
239
- * ```
240
- */
241
- SELVA_EXPORT
242
- struct SelvaNode *selva_min_node(struct SelvaTypeEntry *type) __attribute__((nonnull));
243
-
244
- /**
245
- * **Example**
246
- * ```c
247
- * for (struct SelvaNode *np = selva_max_node(type); np; np = selva_prev_node(type, np))
248
- * ```
249
- */
250
- SELVA_EXPORT
251
- struct SelvaNode *selva_max_node(struct SelvaTypeEntry *type) __attribute__((nonnull));
252
-
253
- /**
254
- * Get previous node with a lower node id.
255
- */
256
- SELVA_EXPORT
257
- struct SelvaNode *selva_prev_node(struct SelvaTypeEntry *type, struct SelvaNode *node) __attribute__((nonnull));
258
-
259
- /**
260
- * Get next node with higher node id.
261
- */
262
- SELVA_EXPORT
263
- struct SelvaNode *selva_next_node(struct SelvaTypeEntry *type, struct SelvaNode *node) __attribute__((nonnull));
264
-
265
- /**
266
- * \addtogroup db_cursor
267
- * @{
268
- */
269
-
270
- /**
271
- * Create a new cursor pointing to node.
272
- * If the node is deleted later then the cursor is updated to point to the next
273
- * node using selva_next_node().
274
- */
275
- SELVA_EXPORT
276
- cursor_id_t selva_cursor_new(struct SelvaTypeEntry *type, struct SelvaNode *node) __attribute__((nonnull));
277
-
278
- /**
279
- * Get a pointer to the node from a cursor.
280
- */
281
- SELVA_EXPORT
282
- struct SelvaNode *selva_cursor_get(struct SelvaTypeEntry *type, cursor_id_t id) __attribute__((nonnull));
283
-
284
- /**
285
- * Update a cursor to point to a new node.
286
- */
287
- SELVA_EXPORT
288
- int selva_cursor_update(struct SelvaTypeEntry *type, cursor_id_t id, struct SelvaNode *node) __attribute__((nonnull));
289
-
290
- /**
291
- * Delete a cursor.
292
- */
293
- SELVA_EXPORT
294
- void selva_cursor_del(struct SelvaTypeEntry *type, cursor_id_t id) __attribute__((nonnull));
295
-
296
- /**
297
- * Total count of cursors of type.
298
- */
299
- SELVA_EXPORT
300
- size_t selva_cursor_count(const struct SelvaTypeEntry *type) __attribute__((nonnull));
301
-
302
- /**
303
- * @}
304
- */
305
-
306
- /**
307
- * Total count of nodes of type.
308
- */
309
- SELVA_EXPORT
310
- size_t selva_node_count(const struct SelvaTypeEntry *type) __attribute__((nonnull));
311
-
312
- /**
313
- * Get the node id of of node.
314
- */
315
- SELVA_EXPORT
316
- __attribute__((nonnull, pure))
317
- inline node_id_t selva_get_node_id(const struct SelvaNode *node)
318
- #ifndef __zig
319
- {
320
- return node->node_id;
321
- }
322
- #else
323
- ;
324
- #endif
325
-
326
- /**
327
- * Get the type of of node.
328
- */
329
- SELVA_EXPORT
330
- __attribute__((nonnull, pure))
331
- inline node_type_t selva_get_node_type(const struct SelvaNode *node)
332
- #ifndef __zig
333
- {
334
- return node->type;
335
- }
336
- #else
337
- ;
338
- #endif
339
-
340
- /**
341
- * \addtogroup node_hash
342
- * @{
343
- */
344
-
345
- /**
346
- * Calculate the node hash.
347
- * Update node hash by using a temp hash state allocated earlier.
348
- * @param tmp_hash_state is only used for computation and it's reset before use.
349
- */
350
- SELVA_EXPORT
351
- selva_hash128_t selva_node_hash_update(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node, struct XXH3_state_s *tmp_hash_state);
352
-
353
- SELVA_EXPORT
354
- selva_hash128_t selva_node_hash(struct SelvaDb *db, struct SelvaTypeEntry *type, struct SelvaNode *node);
355
-
356
- SELVA_EXPORT
357
- 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));
358
-
359
- /**
360
- * @}
361
- */
362
-
363
- /**
364
- * Get the number of aliases under given type.
365
- */
366
- SELVA_EXPORT
367
- size_t selva_alias_count(const struct SelvaAliases *aliases);
368
-
369
- /**
370
- * Set new alias.
371
- * @param name is copied.
372
- * @returns the previous node_id the alias was pointing to; Otherwise 0.
373
- */
374
- SELVA_EXPORT
375
- node_id_t selva_set_alias(struct SelvaAliases *aliases, node_id_t dest, const char *name_str, size_t name_len);
376
-
377
- /**
378
- * Delete alias by name.
379
- * @return the destination node_id the alias was pointing to; 0 if SELVA_ENOENT.
380
- */
381
- SELVA_EXPORT
382
- node_id_t selva_del_alias_by_name(struct SelvaAliases *aliases, const char *name_str, size_t name_len);
383
-
384
- /**
385
- * Delete all aliases pointing to dest.
386
- */
387
- SELVA_EXPORT
388
- void selva_del_alias_by_dest(struct SelvaAliases *aliases, node_id_t dest);
389
-
390
- /**
391
- * Get alias by name.
392
- */
393
- SELVA_EXPORT
394
- struct SelvaNode *selva_get_alias(struct SelvaTypeEntry *type, struct SelvaAliases *aliases, const char *name_str, size_t name_len);
395
-
396
- /**
397
- * Get alias by destination id.
398
- * This may not seem very useful but this is actually the way that allows you to
399
- * traverse all aliases to the given node_id by following the `next` pointer or
400
- * by calling selva_get_next_alias().
401
- */
402
- SELVA_EXPORT
403
- const struct SelvaAlias *selva_get_alias_by_dest(struct SelvaAliases *aliases, node_id_t dest);
404
-
405
- SELVA_EXPORT
406
- const struct SelvaAlias *selva_get_next_alias(const struct SelvaAlias *alias);
407
-
408
- SELVA_EXPORT
409
- const char *selva_get_alias_name(const struct SelvaAlias *alias, size_t *len) __attribute__((nonnull(1), pure));
410
-
411
- SELVA_EXPORT
412
- struct SelvaAliases *selva_get_aliases(struct SelvaTypeEntry *type, field_t field);
413
-
414
- /***
415
- * Remove all aliases to the given node_id.
416
- */
417
- SELVA_EXPORT
418
- void selva_remove_all_aliases(struct SelvaTypeEntry *type, node_id_t node_id);