@based/db 0.0.1

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 (296) hide show
  1. package/README.md +43 -0
  2. package/dist/lib/darwin_aarch64/include/cdefs.h +317 -0
  3. package/dist/lib/darwin_aarch64/include/libdeflate.h +322 -0
  4. package/dist/lib/darwin_aarch64/include/libdeflate_strings.h +35 -0
  5. package/dist/lib/darwin_aarch64/include/linker_set.h +109 -0
  6. package/dist/lib/darwin_aarch64/include/queue.h +627 -0
  7. package/dist/lib/darwin_aarch64/include/selva/_export.h +7 -0
  8. package/dist/lib/darwin_aarch64/include/selva/align.h +9 -0
  9. package/dist/lib/darwin_aarch64/include/selva/backoff_timeout.h +29 -0
  10. package/dist/lib/darwin_aarch64/include/selva/base64.h +59 -0
  11. package/dist/lib/darwin_aarch64/include/selva/base64url.h +59 -0
  12. package/dist/lib/darwin_aarch64/include/selva/bitmap.h +95 -0
  13. package/dist/lib/darwin_aarch64/include/selva/crc32c.h +17 -0
  14. package/dist/lib/darwin_aarch64/include/selva/ctime.h +135 -0
  15. package/dist/lib/darwin_aarch64/include/selva/db.h +284 -0
  16. package/dist/lib/darwin_aarch64/include/selva/endian.h +301 -0
  17. package/dist/lib/darwin_aarch64/include/selva/fast_linear_search.h +23 -0
  18. package/dist/lib/darwin_aarch64/include/selva/fast_memmem.h +11 -0
  19. package/dist/lib/darwin_aarch64/include/selva/fast_parsei.h +36 -0
  20. package/dist/lib/darwin_aarch64/include/selva/fields.h +338 -0
  21. package/dist/lib/darwin_aarch64/include/selva/find.h +47 -0
  22. package/dist/lib/darwin_aarch64/include/selva/lpf.h +28 -0
  23. package/dist/lib/darwin_aarch64/include/selva/node_id_set.h +43 -0
  24. package/dist/lib/darwin_aarch64/include/selva/poptop.h +114 -0
  25. package/dist/lib/darwin_aarch64/include/selva/queue_r.h +190 -0
  26. package/dist/lib/darwin_aarch64/include/selva/selva_hash128.h +39 -0
  27. package/dist/lib/darwin_aarch64/include/selva/selva_lang.h +105 -0
  28. package/dist/lib/darwin_aarch64/include/selva/selva_math.h +37 -0
  29. package/dist/lib/darwin_aarch64/include/selva/selva_string.h +672 -0
  30. package/dist/lib/darwin_aarch64/include/selva/sort.h +119 -0
  31. package/dist/lib/darwin_aarch64/include/selva/strsearch.h +43 -0
  32. package/dist/lib/darwin_aarch64/include/selva/timestamp.h +25 -0
  33. package/dist/lib/darwin_aarch64/include/selva/traverse.h +65 -0
  34. package/dist/lib/darwin_aarch64/include/selva/types.h +110 -0
  35. package/dist/lib/darwin_aarch64/include/selva/vector.h +14 -0
  36. package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +13 -0
  37. package/dist/lib/darwin_aarch64/include/selva_error.h +137 -0
  38. package/dist/lib/darwin_aarch64/include/selva_lang_code.h +157 -0
  39. package/dist/lib/darwin_aarch64/include/tree.h +852 -0
  40. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  41. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  42. package/dist/lib/darwin_aarch64/libnode-v20.11.1.node +0 -0
  43. package/dist/lib/darwin_aarch64/libnode-v20.18.1.node +0 -0
  44. package/dist/lib/darwin_aarch64/libnode-v22.13.0.node +0 -0
  45. package/dist/lib/darwin_aarch64/libnode-v22.8.0.node +0 -0
  46. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  47. package/dist/lib/darwin_aarch64/libxxhash.0.8.2.dylib +0 -0
  48. package/dist/lib/darwin_aarch64/libxxhash.0.dylib +0 -0
  49. package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
  50. package/dist/lib/linux_aarch64/include/cdefs.h +317 -0
  51. package/dist/lib/linux_aarch64/include/libdeflate.h +322 -0
  52. package/dist/lib/linux_aarch64/include/libdeflate_strings.h +35 -0
  53. package/dist/lib/linux_aarch64/include/linker_set.h +109 -0
  54. package/dist/lib/linux_aarch64/include/queue.h +627 -0
  55. package/dist/lib/linux_aarch64/include/selva/_export.h +7 -0
  56. package/dist/lib/linux_aarch64/include/selva/align.h +9 -0
  57. package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +29 -0
  58. package/dist/lib/linux_aarch64/include/selva/base64.h +59 -0
  59. package/dist/lib/linux_aarch64/include/selva/base64url.h +59 -0
  60. package/dist/lib/linux_aarch64/include/selva/bitmap.h +95 -0
  61. package/dist/lib/linux_aarch64/include/selva/crc32c.h +17 -0
  62. package/dist/lib/linux_aarch64/include/selva/ctime.h +135 -0
  63. package/dist/lib/linux_aarch64/include/selva/db.h +284 -0
  64. package/dist/lib/linux_aarch64/include/selva/endian.h +301 -0
  65. package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +23 -0
  66. package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +11 -0
  67. package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +36 -0
  68. package/dist/lib/linux_aarch64/include/selva/fields.h +338 -0
  69. package/dist/lib/linux_aarch64/include/selva/find.h +47 -0
  70. package/dist/lib/linux_aarch64/include/selva/lpf.h +28 -0
  71. package/dist/lib/linux_aarch64/include/selva/node_id_set.h +43 -0
  72. package/dist/lib/linux_aarch64/include/selva/poptop.h +114 -0
  73. package/dist/lib/linux_aarch64/include/selva/queue_r.h +190 -0
  74. package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +39 -0
  75. package/dist/lib/linux_aarch64/include/selva/selva_lang.h +105 -0
  76. package/dist/lib/linux_aarch64/include/selva/selva_math.h +37 -0
  77. package/dist/lib/linux_aarch64/include/selva/selva_string.h +672 -0
  78. package/dist/lib/linux_aarch64/include/selva/sort.h +119 -0
  79. package/dist/lib/linux_aarch64/include/selva/strsearch.h +43 -0
  80. package/dist/lib/linux_aarch64/include/selva/timestamp.h +25 -0
  81. package/dist/lib/linux_aarch64/include/selva/traverse.h +65 -0
  82. package/dist/lib/linux_aarch64/include/selva/types.h +110 -0
  83. package/dist/lib/linux_aarch64/include/selva/vector.h +14 -0
  84. package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +13 -0
  85. package/dist/lib/linux_aarch64/include/selva_error.h +137 -0
  86. package/dist/lib/linux_aarch64/include/selva_lang_code.h +157 -0
  87. package/dist/lib/linux_aarch64/include/tree.h +852 -0
  88. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  89. package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
  90. package/dist/lib/linux_aarch64/libnode-v20.11.1.node +0 -0
  91. package/dist/lib/linux_aarch64/libnode-v20.18.1.node +0 -0
  92. package/dist/lib/linux_aarch64/libnode-v22.13.0.node +0 -0
  93. package/dist/lib/linux_aarch64/libselva.so +0 -0
  94. package/dist/lib/linux_aarch64/libxxhash.so +0 -0
  95. package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
  96. package/dist/lib/linux_aarch64/libxxhash.so.0.8.2 +0 -0
  97. package/dist/lib/linux_x86_64/include/cdefs.h +317 -0
  98. package/dist/lib/linux_x86_64/include/libdeflate.h +322 -0
  99. package/dist/lib/linux_x86_64/include/libdeflate_strings.h +35 -0
  100. package/dist/lib/linux_x86_64/include/linker_set.h +109 -0
  101. package/dist/lib/linux_x86_64/include/queue.h +627 -0
  102. package/dist/lib/linux_x86_64/include/selva/_export.h +7 -0
  103. package/dist/lib/linux_x86_64/include/selva/align.h +9 -0
  104. package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +29 -0
  105. package/dist/lib/linux_x86_64/include/selva/base64.h +59 -0
  106. package/dist/lib/linux_x86_64/include/selva/base64url.h +59 -0
  107. package/dist/lib/linux_x86_64/include/selva/bitmap.h +95 -0
  108. package/dist/lib/linux_x86_64/include/selva/crc32c.h +17 -0
  109. package/dist/lib/linux_x86_64/include/selva/ctime.h +135 -0
  110. package/dist/lib/linux_x86_64/include/selva/db.h +284 -0
  111. package/dist/lib/linux_x86_64/include/selva/endian.h +301 -0
  112. package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +23 -0
  113. package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +11 -0
  114. package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +36 -0
  115. package/dist/lib/linux_x86_64/include/selva/fields.h +338 -0
  116. package/dist/lib/linux_x86_64/include/selva/find.h +47 -0
  117. package/dist/lib/linux_x86_64/include/selva/lpf.h +28 -0
  118. package/dist/lib/linux_x86_64/include/selva/node_id_set.h +43 -0
  119. package/dist/lib/linux_x86_64/include/selva/poptop.h +114 -0
  120. package/dist/lib/linux_x86_64/include/selva/queue_r.h +190 -0
  121. package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +39 -0
  122. package/dist/lib/linux_x86_64/include/selva/selva_lang.h +105 -0
  123. package/dist/lib/linux_x86_64/include/selva/selva_math.h +37 -0
  124. package/dist/lib/linux_x86_64/include/selva/selva_string.h +672 -0
  125. package/dist/lib/linux_x86_64/include/selva/sort.h +119 -0
  126. package/dist/lib/linux_x86_64/include/selva/strsearch.h +43 -0
  127. package/dist/lib/linux_x86_64/include/selva/timestamp.h +25 -0
  128. package/dist/lib/linux_x86_64/include/selva/traverse.h +65 -0
  129. package/dist/lib/linux_x86_64/include/selva/types.h +110 -0
  130. package/dist/lib/linux_x86_64/include/selva/vector.h +14 -0
  131. package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +13 -0
  132. package/dist/lib/linux_x86_64/include/selva_error.h +137 -0
  133. package/dist/lib/linux_x86_64/include/selva_lang_code.h +157 -0
  134. package/dist/lib/linux_x86_64/include/tree.h +852 -0
  135. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  136. package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
  137. package/dist/lib/linux_x86_64/libnode-v20.11.1.node +0 -0
  138. package/dist/lib/linux_x86_64/libnode-v20.18.1.node +0 -0
  139. package/dist/lib/linux_x86_64/libnode-v22.13.0.node +0 -0
  140. package/dist/lib/linux_x86_64/libselva.so +0 -0
  141. package/dist/lib/linux_x86_64/libxxhash.so +0 -0
  142. package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
  143. package/dist/lib/linux_x86_64/libxxhash.so.0.8.2 +0 -0
  144. package/dist/src/client/crc32.d.ts +1 -0
  145. package/dist/src/client/crc32.js +281 -0
  146. package/dist/src/client/index.d.ts +58 -0
  147. package/dist/src/client/index.js +120 -0
  148. package/dist/src/client/modify/ModifyRes.d.ts +26 -0
  149. package/dist/src/client/modify/ModifyRes.js +98 -0
  150. package/dist/src/client/modify/alias.d.ts +4 -0
  151. package/dist/src/client/modify/alias.js +47 -0
  152. package/dist/src/client/modify/binary.d.ts +6 -0
  153. package/dist/src/client/modify/binary.js +61 -0
  154. package/dist/src/client/modify/create.d.ts +4 -0
  155. package/dist/src/client/modify/create.js +108 -0
  156. package/dist/src/client/modify/fixed.d.ts +5 -0
  157. package/dist/src/client/modify/fixed.js +118 -0
  158. package/dist/src/client/modify/hll.d.ts +4 -0
  159. package/dist/src/client/modify/hll.js +58 -0
  160. package/dist/src/client/modify/index.d.ts +4 -0
  161. package/dist/src/client/modify/index.js +4 -0
  162. package/dist/src/client/modify/modify.d.ts +5 -0
  163. package/dist/src/client/modify/modify.js +126 -0
  164. package/dist/src/client/modify/references/edge.d.ts +6 -0
  165. package/dist/src/client/modify/references/edge.js +158 -0
  166. package/dist/src/client/modify/references/reference.d.ts +11 -0
  167. package/dist/src/client/modify/references/reference.js +92 -0
  168. package/dist/src/client/modify/references/references.d.ts +17 -0
  169. package/dist/src/client/modify/references/references.js +271 -0
  170. package/dist/src/client/modify/remove.d.ts +2 -0
  171. package/dist/src/client/modify/remove.js +36 -0
  172. package/dist/src/client/modify/setCursor.d.ts +4 -0
  173. package/dist/src/client/modify/setCursor.js +36 -0
  174. package/dist/src/client/modify/string.d.ts +5 -0
  175. package/dist/src/client/modify/string.js +56 -0
  176. package/dist/src/client/modify/text.d.ts +5 -0
  177. package/dist/src/client/modify/text.js +14 -0
  178. package/dist/src/client/modify/types.d.ts +14 -0
  179. package/dist/src/client/modify/types.js +12 -0
  180. package/dist/src/client/modify/update.d.ts +5 -0
  181. package/dist/src/client/modify/update.js +80 -0
  182. package/dist/src/client/modify/upsert.d.ts +2 -0
  183. package/dist/src/client/modify/upsert.js +40 -0
  184. package/dist/src/client/operations.d.ts +31 -0
  185. package/dist/src/client/operations.js +110 -0
  186. package/dist/src/client/query/BasedDbQuery.d.ts +40 -0
  187. package/dist/src/client/query/BasedDbQuery.js +235 -0
  188. package/dist/src/client/query/BasedIterable.d.ts +26 -0
  189. package/dist/src/client/query/BasedIterable.js +113 -0
  190. package/dist/src/client/query/debug.d.ts +3 -0
  191. package/dist/src/client/query/debug.js +117 -0
  192. package/dist/src/client/query/display.d.ts +5 -0
  193. package/dist/src/client/query/display.js +233 -0
  194. package/dist/src/client/query/filter/FilterBranch.d.ts +13 -0
  195. package/dist/src/client/query/filter/FilterBranch.js +29 -0
  196. package/dist/src/client/query/filter/createFixedFilterBuffer.d.ts +3 -0
  197. package/dist/src/client/query/filter/createFixedFilterBuffer.js +101 -0
  198. package/dist/src/client/query/filter/createReferenceFilter.d.ts +2 -0
  199. package/dist/src/client/query/filter/createReferenceFilter.js +24 -0
  200. package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -0
  201. package/dist/src/client/query/filter/createVariableFilterBuffer.js +81 -0
  202. package/dist/src/client/query/filter/filter.d.ts +10 -0
  203. package/dist/src/client/query/filter/filter.js +134 -0
  204. package/dist/src/client/query/filter/operators.d.ts +6 -0
  205. package/dist/src/client/query/filter/operators.js +98 -0
  206. package/dist/src/client/query/filter/parseFilterValue.d.ts +2 -0
  207. package/dist/src/client/query/filter/parseFilterValue.js +99 -0
  208. package/dist/src/client/query/filter/primitiveFilter.d.ts +4 -0
  209. package/dist/src/client/query/filter/primitiveFilter.js +47 -0
  210. package/dist/src/client/query/filter/toBuffer.d.ts +3 -0
  211. package/dist/src/client/query/filter/toBuffer.js +100 -0
  212. package/dist/src/client/query/filter/types.d.ts +6 -0
  213. package/dist/src/client/query/filter/types.js +7 -0
  214. package/dist/src/client/query/include/props.d.ts +6 -0
  215. package/dist/src/client/query/include/props.js +44 -0
  216. package/dist/src/client/query/include/toBuffer.d.ts +3 -0
  217. package/dist/src/client/query/include/toBuffer.js +82 -0
  218. package/dist/src/client/query/include/utils.d.ts +6 -0
  219. package/dist/src/client/query/include/utils.js +41 -0
  220. package/dist/src/client/query/include/walk.d.ts +3 -0
  221. package/dist/src/client/query/include/walk.js +70 -0
  222. package/dist/src/client/query/query.d.ts +10 -0
  223. package/dist/src/client/query/query.js +11 -0
  224. package/dist/src/client/query/queryDef.d.ts +3 -0
  225. package/dist/src/client/query/queryDef.js +54 -0
  226. package/dist/src/client/query/read/read.d.ts +8 -0
  227. package/dist/src/client/query/read/read.js +303 -0
  228. package/dist/src/client/query/registerQuery.d.ts +2 -0
  229. package/dist/src/client/query/registerQuery.js +31 -0
  230. package/dist/src/client/query/search/index.d.ts +6 -0
  231. package/dist/src/client/query/search/index.js +82 -0
  232. package/dist/src/client/query/sort.d.ts +3 -0
  233. package/dist/src/client/query/sort.js +18 -0
  234. package/dist/src/client/query/subscription/index.d.ts +5 -0
  235. package/dist/src/client/query/subscription/index.js +52 -0
  236. package/dist/src/client/query/subscription/markers.d.ts +10 -0
  237. package/dist/src/client/query/subscription/markers.js +213 -0
  238. package/dist/src/client/query/subscription/run.d.ts +5 -0
  239. package/dist/src/client/query/subscription/run.js +69 -0
  240. package/dist/src/client/query/subscription/types.d.ts +33 -0
  241. package/dist/src/client/query/subscription/types.js +3 -0
  242. package/dist/src/client/query/thresholds.d.ts +6 -0
  243. package/dist/src/client/query/thresholds.js +16 -0
  244. package/dist/src/client/query/toBuffer.d.ts +3 -0
  245. package/dist/src/client/query/toBuffer.js +229 -0
  246. package/dist/src/client/query/types.d.ts +88 -0
  247. package/dist/src/client/query/types.js +15 -0
  248. package/dist/src/client/query/validation.d.ts +15 -0
  249. package/dist/src/client/query/validation.js +59 -0
  250. package/dist/src/client/string.d.ts +5 -0
  251. package/dist/src/client/string.js +73 -0
  252. package/dist/src/client/tree.d.ts +1 -0
  253. package/dist/src/client/tree.js +5 -0
  254. package/dist/src/index.d.ts +31 -0
  255. package/dist/src/index.js +85 -0
  256. package/dist/src/native.d.ts +28 -0
  257. package/dist/src/native.js +96 -0
  258. package/dist/src/server/csmt/draw-dot.d.ts +2 -0
  259. package/dist/src/server/csmt/draw-dot.js +32 -0
  260. package/dist/src/server/csmt/index.d.ts +4 -0
  261. package/dist/src/server/csmt/index.js +5 -0
  262. package/dist/src/server/csmt/match.d.ts +7 -0
  263. package/dist/src/server/csmt/match.js +10 -0
  264. package/dist/src/server/csmt/memebership-proof.d.ts +7 -0
  265. package/dist/src/server/csmt/memebership-proof.js +122 -0
  266. package/dist/src/server/csmt/tree-utils.d.ts +6 -0
  267. package/dist/src/server/csmt/tree-utils.js +33 -0
  268. package/dist/src/server/csmt/tree.d.ts +2 -0
  269. package/dist/src/server/csmt/tree.js +209 -0
  270. package/dist/src/server/csmt/types.d.ts +40 -0
  271. package/dist/src/server/csmt/types.js +2 -0
  272. package/dist/src/server/index.d.ts +85 -0
  273. package/dist/src/server/index.js +407 -0
  274. package/dist/src/server/migrate/index.d.ts +7 -0
  275. package/dist/src/server/migrate/index.js +108 -0
  276. package/dist/src/server/migrate/worker.d.ts +1 -0
  277. package/dist/src/server/migrate/worker.js +81 -0
  278. package/dist/src/server/save.d.ts +2 -0
  279. package/dist/src/server/save.js +66 -0
  280. package/dist/src/server/schema/schema.d.ts +3 -0
  281. package/dist/src/server/schema/schema.js +4 -0
  282. package/dist/src/server/schema/selvaBuffer.d.ts +4 -0
  283. package/dist/src/server/schema/selvaBuffer.js +102 -0
  284. package/dist/src/server/schema/typeDef.d.ts +6 -0
  285. package/dist/src/server/schema/typeDef.js +315 -0
  286. package/dist/src/server/schema/types.d.ts +127 -0
  287. package/dist/src/server/schema/types.js +113 -0
  288. package/dist/src/server/schema/utils.d.ts +6 -0
  289. package/dist/src/server/schema/utils.js +21 -0
  290. package/dist/src/server/start.d.ts +6 -0
  291. package/dist/src/server/start.js +86 -0
  292. package/dist/src/server/tree.d.ts +13 -0
  293. package/dist/src/server/tree.js +33 -0
  294. package/dist/src/server/worker.d.ts +1 -0
  295. package/dist/src/server/worker.js +35 -0
  296. package/package.json +48 -0
@@ -0,0 +1 @@
1
+ export declare const crc32: (buf: Buffer) => any;
@@ -0,0 +1,281 @@
1
+ import native from '../native.js';
2
+ export const crc32 = (buf) => {
3
+ return native.crc32(buf);
4
+ };
5
+ // Pure js version:
6
+ // /**
7
+ // * This code is a manual javascript translation of c code generated by
8
+ // * pycrc 0.7.1 (http://www.tty1.net/pycrc/). Command line used:
9
+ // * './pycrc.py --model=crc-32c --generate c --algorithm=table-driven'
10
+ // */
11
+ //
12
+ // const kCRCTable = Int32Array.of(
13
+ // 0x00000000,
14
+ // 0xf26b8303,
15
+ // 0xe13b70f7,
16
+ // 0x1350f3f4,
17
+ // 0xc79a971f,
18
+ // 0x35f1141c,
19
+ // 0x26a1e7e8,
20
+ // 0xd4ca64eb,
21
+ // 0x8ad958cf,
22
+ // 0x78b2dbcc,
23
+ // 0x6be22838,
24
+ // 0x9989ab3b,
25
+ // 0x4d43cfd0,
26
+ // 0xbf284cd3,
27
+ // 0xac78bf27,
28
+ // 0x5e133c24,
29
+ // 0x105ec76f,
30
+ // 0xe235446c,
31
+ // 0xf165b798,
32
+ // 0x030e349b,
33
+ // 0xd7c45070,
34
+ // 0x25afd373,
35
+ // 0x36ff2087,
36
+ // 0xc494a384,
37
+ // 0x9a879fa0,
38
+ // 0x68ec1ca3,
39
+ // 0x7bbcef57,
40
+ // 0x89d76c54,
41
+ // 0x5d1d08bf,
42
+ // 0xaf768bbc,
43
+ // 0xbc267848,
44
+ // 0x4e4dfb4b,
45
+ // 0x20bd8ede,
46
+ // 0xd2d60ddd,
47
+ // 0xc186fe29,
48
+ // 0x33ed7d2a,
49
+ // 0xe72719c1,
50
+ // 0x154c9ac2,
51
+ // 0x061c6936,
52
+ // 0xf477ea35,
53
+ // 0xaa64d611,
54
+ // 0x580f5512,
55
+ // 0x4b5fa6e6,
56
+ // 0xb93425e5,
57
+ // 0x6dfe410e,
58
+ // 0x9f95c20d,
59
+ // 0x8cc531f9,
60
+ // 0x7eaeb2fa,
61
+ // 0x30e349b1,
62
+ // 0xc288cab2,
63
+ // 0xd1d83946,
64
+ // 0x23b3ba45,
65
+ // 0xf779deae,
66
+ // 0x05125dad,
67
+ // 0x1642ae59,
68
+ // 0xe4292d5a,
69
+ // 0xba3a117e,
70
+ // 0x4851927d,
71
+ // 0x5b016189,
72
+ // 0xa96ae28a,
73
+ // 0x7da08661,
74
+ // 0x8fcb0562,
75
+ // 0x9c9bf696,
76
+ // 0x6ef07595,
77
+ // 0x417b1dbc,
78
+ // 0xb3109ebf,
79
+ // 0xa0406d4b,
80
+ // 0x522bee48,
81
+ // 0x86e18aa3,
82
+ // 0x748a09a0,
83
+ // 0x67dafa54,
84
+ // 0x95b17957,
85
+ // 0xcba24573,
86
+ // 0x39c9c670,
87
+ // 0x2a993584,
88
+ // 0xd8f2b687,
89
+ // 0x0c38d26c,
90
+ // 0xfe53516f,
91
+ // 0xed03a29b,
92
+ // 0x1f682198,
93
+ // 0x5125dad3,
94
+ // 0xa34e59d0,
95
+ // 0xb01eaa24,
96
+ // 0x42752927,
97
+ // 0x96bf4dcc,
98
+ // 0x64d4cecf,
99
+ // 0x77843d3b,
100
+ // 0x85efbe38,
101
+ // 0xdbfc821c,
102
+ // 0x2997011f,
103
+ // 0x3ac7f2eb,
104
+ // 0xc8ac71e8,
105
+ // 0x1c661503,
106
+ // 0xee0d9600,
107
+ // 0xfd5d65f4,
108
+ // 0x0f36e6f7,
109
+ // 0x61c69362,
110
+ // 0x93ad1061,
111
+ // 0x80fde395,
112
+ // 0x72966096,
113
+ // 0xa65c047d,
114
+ // 0x5437877e,
115
+ // 0x4767748a,
116
+ // 0xb50cf789,
117
+ // 0xeb1fcbad,
118
+ // 0x197448ae,
119
+ // 0x0a24bb5a,
120
+ // 0xf84f3859,
121
+ // 0x2c855cb2,
122
+ // 0xdeeedfb1,
123
+ // 0xcdbe2c45,
124
+ // 0x3fd5af46,
125
+ // 0x7198540d,
126
+ // 0x83f3d70e,
127
+ // 0x90a324fa,
128
+ // 0x62c8a7f9,
129
+ // 0xb602c312,
130
+ // 0x44694011,
131
+ // 0x5739b3e5,
132
+ // 0xa55230e6,
133
+ // 0xfb410cc2,
134
+ // 0x092a8fc1,
135
+ // 0x1a7a7c35,
136
+ // 0xe811ff36,
137
+ // 0x3cdb9bdd,
138
+ // 0xceb018de,
139
+ // 0xdde0eb2a,
140
+ // 0x2f8b6829,
141
+ // 0x82f63b78,
142
+ // 0x709db87b,
143
+ // 0x63cd4b8f,
144
+ // 0x91a6c88c,
145
+ // 0x456cac67,
146
+ // 0xb7072f64,
147
+ // 0xa457dc90,
148
+ // 0x563c5f93,
149
+ // 0x082f63b7,
150
+ // 0xfa44e0b4,
151
+ // 0xe9141340,
152
+ // 0x1b7f9043,
153
+ // 0xcfb5f4a8,
154
+ // 0x3dde77ab,
155
+ // 0x2e8e845f,
156
+ // 0xdce5075c,
157
+ // 0x92a8fc17,
158
+ // 0x60c37f14,
159
+ // 0x73938ce0,
160
+ // 0x81f80fe3,
161
+ // 0x55326b08,
162
+ // 0xa759e80b,
163
+ // 0xb4091bff,
164
+ // 0x466298fc,
165
+ // 0x1871a4d8,
166
+ // 0xea1a27db,
167
+ // 0xf94ad42f,
168
+ // 0x0b21572c,
169
+ // 0xdfeb33c7,
170
+ // 0x2d80b0c4,
171
+ // 0x3ed04330,
172
+ // 0xccbbc033,
173
+ // 0xa24bb5a6,
174
+ // 0x502036a5,
175
+ // 0x4370c551,
176
+ // 0xb11b4652,
177
+ // 0x65d122b9,
178
+ // 0x97baa1ba,
179
+ // 0x84ea524e,
180
+ // 0x7681d14d,
181
+ // 0x2892ed69,
182
+ // 0xdaf96e6a,
183
+ // 0xc9a99d9e,
184
+ // 0x3bc21e9d,
185
+ // 0xef087a76,
186
+ // 0x1d63f975,
187
+ // 0x0e330a81,
188
+ // 0xfc588982,
189
+ // 0xb21572c9,
190
+ // 0x407ef1ca,
191
+ // 0x532e023e,
192
+ // 0xa145813d,
193
+ // 0x758fe5d6,
194
+ // 0x87e466d5,
195
+ // 0x94b49521,
196
+ // 0x66df1622,
197
+ // 0x38cc2a06,
198
+ // 0xcaa7a905,
199
+ // 0xd9f75af1,
200
+ // 0x2b9cd9f2,
201
+ // 0xff56bd19,
202
+ // 0x0d3d3e1a,
203
+ // 0x1e6dcdee,
204
+ // 0xec064eed,
205
+ // 0xc38d26c4,
206
+ // 0x31e6a5c7,
207
+ // 0x22b65633,
208
+ // 0xd0ddd530,
209
+ // 0x0417b1db,
210
+ // 0xf67c32d8,
211
+ // 0xe52cc12c,
212
+ // 0x1747422f,
213
+ // 0x49547e0b,
214
+ // 0xbb3ffd08,
215
+ // 0xa86f0efc,
216
+ // 0x5a048dff,
217
+ // 0x8ecee914,
218
+ // 0x7ca56a17,
219
+ // 0x6ff599e3,
220
+ // 0x9d9e1ae0,
221
+ // 0xd3d3e1ab,
222
+ // 0x21b862a8,
223
+ // 0x32e8915c,
224
+ // 0xc083125f,
225
+ // 0x144976b4,
226
+ // 0xe622f5b7,
227
+ // 0xf5720643,
228
+ // 0x07198540,
229
+ // 0x590ab964,
230
+ // 0xab613a67,
231
+ // 0xb831c993,
232
+ // 0x4a5a4a90,
233
+ // 0x9e902e7b,
234
+ // 0x6cfbad78,
235
+ // 0x7fab5e8c,
236
+ // 0x8dc0dd8f,
237
+ // 0xe330a81a,
238
+ // 0x115b2b19,
239
+ // 0x020bd8ed,
240
+ // 0xf0605bee,
241
+ // 0x24aa3f05,
242
+ // 0xd6c1bc06,
243
+ // 0xc5914ff2,
244
+ // 0x37faccf1,
245
+ // 0x69e9f0d5,
246
+ // 0x9b8273d6,
247
+ // 0x88d28022,
248
+ // 0x7ab90321,
249
+ // 0xae7367ca,
250
+ // 0x5c18e4c9,
251
+ // 0x4f48173d,
252
+ // 0xbd23943e,
253
+ // 0xf36e6f75,
254
+ // 0x0105ec76,
255
+ // 0x12551f82,
256
+ // 0xe03e9c81,
257
+ // 0x34f4f86a,
258
+ // 0xc69f7b69,
259
+ // 0xd5cf889d,
260
+ // 0x27a40b9e,
261
+ // 0x79b737ba,
262
+ // 0x8bdcb4b9,
263
+ // 0x988c474d,
264
+ // 0x6ae7c44e,
265
+ // 0xbe2da0a5,
266
+ // 0x4c4623a6,
267
+ // 0x5f16d052,
268
+ // 0xad7d5351
269
+ // )
270
+ //
271
+ // export function crc32(buf: Buffer, initial: number): number {
272
+ // if (!Buffer.isBuffer(buf)) {
273
+ // buf = Buffer.from(buf)
274
+ // }
275
+ // let crc = (initial | 0) ^ -1
276
+ // for (let i = 0; i < buf.length; i++) {
277
+ // crc = kCRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8)
278
+ // }
279
+ // return (crc ^ -1) >>> 0
280
+ // }
281
+ //# sourceMappingURL=crc32.js.map
@@ -0,0 +1,58 @@
1
+ import { Schema, StrictSchema } from '@based/schema';
2
+ import { CreateObj } from './modify/create.js';
3
+ import { SchemaTypeDef } from '../server/schema/types.js';
4
+ import { ModifyCtx } from './operations.js';
5
+ import { SubscriptionMarkerMap, SubscriptionsMap, SubscriptionsToRun } from './query/subscription/index.js';
6
+ import { BasedDbQuery, QueryByAliasObj } from './query/BasedDbQuery.js';
7
+ import { ModifyRes } from './modify/ModifyRes.js';
8
+ import { DbServer } from '../server/index.js';
9
+ import { TransformFns } from '../server/migrate/index.js';
10
+ export type DbClientHooks = {
11
+ putSchema(schema: StrictSchema, fromStart?: boolean, transformFns?: TransformFns): Promise<DbServer['schema']>;
12
+ flushModify(buf: Buffer): Promise<{
13
+ offsets: Record<number, number>;
14
+ }>;
15
+ getQueryBuf(buf: Buffer): Promise<Uint8Array>;
16
+ };
17
+ type DbClientOpts = {
18
+ hooks: DbClientHooks;
19
+ maxModifySize?: number;
20
+ };
21
+ export declare class DbClient {
22
+ constructor({ hooks, maxModifySize }: DbClientOpts);
23
+ hooks: DbClientHooks;
24
+ schema: StrictSchema & {
25
+ lastId: number;
26
+ };
27
+ schemaTypesParsed: Record<string, SchemaTypeDef>;
28
+ schemaTypesParsedById: Record<number, SchemaTypeDef>;
29
+ writeTime: number;
30
+ isDraining: boolean;
31
+ modifyCtx: ModifyCtx;
32
+ maxModifySize: number;
33
+ upserting: Map<string, {
34
+ o: Record<string, any>;
35
+ p: Promise<number | ModifyRes>;
36
+ }>;
37
+ subscriptionsInProgress: boolean;
38
+ subscriptonThrottleMs: number;
39
+ subscriptions: SubscriptionsMap;
40
+ subscriptionMarkers: SubscriptionMarkerMap;
41
+ subscriptionsToRun: SubscriptionsToRun;
42
+ schemaChecksum: number;
43
+ putSchema(schema: Schema, fromStart?: boolean, transformFns?: TransformFns): Promise<StrictSchema>;
44
+ putLocalSchema(schema: any): StrictSchema & {
45
+ lastId: number;
46
+ };
47
+ create(type: string, obj: CreateObj, unsafe?: boolean): ModifyRes;
48
+ query(type: string, id?: number | ModifyRes | (number | ModifyRes)[] | QueryByAliasObj | QueryByAliasObj[]): BasedDbQuery;
49
+ query(): BasedDbQuery;
50
+ update(type: string, id: number | ModifyRes, value: any, overwrite?: boolean): ModifyRes;
51
+ update(value: any, overwrite?: boolean): ModifyRes;
52
+ upsert(type: string, obj: Record<string, any>): Promise<any>;
53
+ remove(type: string, id: number | ModifyRes): boolean;
54
+ destroy(): void;
55
+ stop(): void;
56
+ drain(): Promise<number>;
57
+ }
58
+ export {};
@@ -0,0 +1,120 @@
1
+ import { parse } from '@based/schema';
2
+ import { create } from './modify/create.js';
3
+ import { flushBuffer, ModifyCtx } from './operations.js';
4
+ import { BasedDbQuery } from './query/BasedDbQuery.js';
5
+ import { ModifyState } from './modify/ModifyRes.js';
6
+ import { upsert } from './modify/upsert.js';
7
+ import { update } from './modify/update.js';
8
+ import { remove } from './modify/remove.js';
9
+ import { updateTypeDefs } from '../server/schema/typeDef.js';
10
+ import { schemaToSelvaBuffer } from '../server/schema/selvaBuffer.js';
11
+ import { deepEqual } from '@saulx/utils';
12
+ import { hash } from '@saulx/hash';
13
+ export class DbClient {
14
+ constructor({ hooks, maxModifySize = 100 * 1e3 * 1e3 }) {
15
+ this.hooks = hooks;
16
+ this.maxModifySize = maxModifySize;
17
+ this.modifyCtx = new ModifyCtx(this);
18
+ }
19
+ hooks;
20
+ // schema
21
+ schema = {
22
+ lastId: 1, // we reserve one for root props
23
+ types: {},
24
+ };
25
+ schemaTypesParsed = {};
26
+ schemaTypesParsedById = {};
27
+ // modify
28
+ writeTime = 0;
29
+ isDraining = false;
30
+ modifyCtx;
31
+ maxModifySize;
32
+ upserting = new Map();
33
+ // subscriptions
34
+ subscriptionsInProgress = false;
35
+ subscriptonThrottleMs = 20;
36
+ subscriptions = new Map();
37
+ subscriptionMarkers = {};
38
+ subscriptionsToRun = [];
39
+ schemaChecksum;
40
+ async putSchema(schema, fromStart, transformFns) {
41
+ const checksum = hash(schema);
42
+ if (checksum === this.schemaChecksum) {
43
+ return this.schema;
44
+ }
45
+ const strictSchema = fromStart ? schema : parse(schema).schema;
46
+ const remoteSchema = await this.hooks.putSchema(strictSchema, fromStart, transformFns);
47
+ this.schemaChecksum = checksum;
48
+ return this.putLocalSchema(remoteSchema);
49
+ }
50
+ putLocalSchema(schema) {
51
+ if (deepEqual(this.schema, schema)) {
52
+ return this.schema;
53
+ }
54
+ this.schema = schema;
55
+ updateTypeDefs(this);
56
+ // TODO should not need this, but it modifies the schema
57
+ schemaToSelvaBuffer(this.schemaTypesParsed);
58
+ return this.schema;
59
+ }
60
+ create(type, obj, unsafe) {
61
+ return create(this, type, obj, unsafe);
62
+ }
63
+ query(type, id) {
64
+ if (type === undefined) {
65
+ return new BasedDbQuery(this, '_root', 1);
66
+ }
67
+ // this is now double resolve
68
+ if (Array.isArray(id)) {
69
+ let i = id.length;
70
+ while (i--) {
71
+ if (typeof id[i] === 'object') {
72
+ if (id[i] instanceof ModifyState) {
73
+ // @ts-ignore
74
+ id[i] = id[i].tmpId;
75
+ }
76
+ else {
77
+ // it's get by alias
78
+ }
79
+ }
80
+ }
81
+ }
82
+ else if (typeof id === 'object') {
83
+ if (id instanceof ModifyState) {
84
+ id = id.tmpId;
85
+ }
86
+ else {
87
+ // it's get by alias
88
+ }
89
+ }
90
+ return new BasedDbQuery(this, type, id);
91
+ }
92
+ update(typeOrValue, idOrOverwrite, value, overwrite) {
93
+ if (typeof typeOrValue === 'string') {
94
+ const id = typeof idOrOverwrite === 'object' ? idOrOverwrite.tmpId : idOrOverwrite;
95
+ return update(this, typeOrValue, id, value, overwrite);
96
+ }
97
+ // else it is rootProps
98
+ return update(this, '_root', 1, typeOrValue, idOrOverwrite);
99
+ }
100
+ upsert(type, obj) {
101
+ return upsert(this, type, obj);
102
+ }
103
+ remove(type, id) {
104
+ return remove(this, type, typeof id === 'number' ? id : id.tmpId);
105
+ }
106
+ destroy() {
107
+ this.modifyCtx.len = 0;
108
+ this.modifyCtx.db = null; // Make sure we don't have a circular ref and leak mem
109
+ }
110
+ stop() {
111
+ this.modifyCtx.len = 0;
112
+ }
113
+ async drain() {
114
+ await flushBuffer(this);
115
+ const t = this.writeTime;
116
+ this.writeTime = 0;
117
+ return t;
118
+ }
119
+ }
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,26 @@
1
+ import { PropDef, PropDefEdge, SchemaPropTree } from '../../server/schema/types.js';
2
+ import { inspect } from 'node:util';
3
+ import { SubscriptionMarkersCheck } from '../query/subscription/index.js';
4
+ import { DbClient } from '../index.js';
5
+ export type ModifyRes = {
6
+ tmpId: number;
7
+ error?: Error;
8
+ } & Promise<number>;
9
+ export declare class ModifyError {
10
+ #private;
11
+ constructor(prop: PropDef | PropDefEdge | SchemaPropTree, val: any, msg?: string);
12
+ toString(): string;
13
+ [inspect.custom](): string;
14
+ }
15
+ export declare class ModifyState {
16
+ #private;
17
+ constructor(typeId: number, tmpId: number, db: DbClient, subMarkers: SubscriptionMarkersCheck | false);
18
+ subMarkers: SubscriptionMarkersCheck | false;
19
+ tmpId: number;
20
+ error?: ModifyError;
21
+ promises?: Promise<any>[];
22
+ [Symbol.toPrimitive](): number;
23
+ getId(offsets: Record<number, number>): number;
24
+ then(resolve: any, reject: any): Promise<unknown>;
25
+ catch(handler: any): this | Promise<unknown>;
26
+ }
@@ -0,0 +1,98 @@
1
+ import { isPropDef, REVERSE_TYPE_INDEX_MAP, } from '../../server/schema/types.js';
2
+ import { inspect } from 'node:util';
3
+ const MAGIC_KEY = Math.random().toString(36).substring(2);
4
+ const MAGIC_REG = RegExp(`("${MAGIC_KEY}|${MAGIC_KEY}")`, 'g');
5
+ const walk = (val) => {
6
+ if (typeof val === 'object' && val !== null) {
7
+ if (Array.isArray(val)) {
8
+ return val.map(walk);
9
+ }
10
+ const obj = {};
11
+ for (const key in val) {
12
+ obj[MAGIC_KEY + key + MAGIC_KEY] = walk(val[key]);
13
+ }
14
+ return obj;
15
+ }
16
+ return val;
17
+ };
18
+ const parseVal = (val) => {
19
+ if (typeof val === 'object' && val !== null) {
20
+ return JSON.stringify(walk(val)).replace(MAGIC_REG, '');
21
+ }
22
+ return val;
23
+ };
24
+ export class ModifyError {
25
+ constructor(prop, val, msg) {
26
+ this.#prop = prop;
27
+ this.#val = val;
28
+ this.#msg = msg;
29
+ }
30
+ #msg;
31
+ #prop;
32
+ #val;
33
+ toString() {
34
+ if (isPropDef(this.#prop)) {
35
+ if (this.#msg) {
36
+ return `Invalid value at '${this.#prop.path.join('.')}'. Expected ${this.#msg} received '${parseVal(this.#val)}'`;
37
+ }
38
+ return `Invalid value at '${this.#prop.path.join('.')}'. Expected ${REVERSE_TYPE_INDEX_MAP[this.#prop.typeIndex]}, received '${parseVal(this.#val)}'`;
39
+ }
40
+ return `Unknown property '${this.#val}'. Expected one of: ${Object.keys(this.#prop).join(', ')}`;
41
+ }
42
+ [inspect.custom]() {
43
+ return this.toString();
44
+ }
45
+ }
46
+ export class ModifyState {
47
+ constructor(typeId, tmpId, db, subMarkers) {
48
+ this.tmpId = tmpId;
49
+ this.#typeId = typeId;
50
+ this.#buf = db.modifyCtx;
51
+ this.#ctx = db.modifyCtx.ctx;
52
+ this.subMarkers = subMarkers;
53
+ }
54
+ subMarkers;
55
+ #buf;
56
+ #ctx;
57
+ #typeId;
58
+ tmpId;
59
+ error;
60
+ promises;
61
+ [Symbol.toPrimitive]() {
62
+ return this.tmpId;
63
+ }
64
+ getId(offsets) {
65
+ const offset = offsets[this.#typeId] || 0;
66
+ return this.tmpId + offset;
67
+ }
68
+ then(resolve, reject) {
69
+ const promise = new Promise((resolve) => {
70
+ if (this.error) {
71
+ reject(new Error(this.error.toString()));
72
+ }
73
+ else if ('offsets' in this.#ctx) {
74
+ resolve(this.getId(this.#ctx.offsets));
75
+ }
76
+ else {
77
+ this.#buf.queue.set(resolve, this);
78
+ }
79
+ });
80
+ if (this.promises?.length) {
81
+ return Promise.allSettled(this.promises)
82
+ .then(() => promise)
83
+ .then(resolve, reject);
84
+ }
85
+ else {
86
+ return promise.then(resolve, reject);
87
+ }
88
+ }
89
+ catch(handler) {
90
+ if (this.error) {
91
+ return new Promise((resolve) => {
92
+ resolve(handler(new Error(this.error.toString())));
93
+ });
94
+ }
95
+ return this;
96
+ }
97
+ }
98
+ //# sourceMappingURL=ModifyRes.js.map
@@ -0,0 +1,4 @@
1
+ import { ModifyCtx } from '../../index.js';
2
+ import { SchemaTypeDef, PropDef } from '../../server/schema/types.js';
3
+ import { ModifyOp, ModifyErr } from './types.js';
4
+ export declare function writeAlias(value: string | null | Buffer, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
@@ -0,0 +1,47 @@
1
+ import { CREATE, UPDATE, RANGE_ERR, DELETE, } from './types.js';
2
+ import { ModifyError } from './ModifyRes.js';
3
+ import { setCursor } from './setCursor.js';
4
+ export function writeAlias(value, ctx, def, t, parentId, modifyOp) {
5
+ if (typeof value === 'string') {
6
+ if (value.length === 0) {
7
+ if (modifyOp === UPDATE) {
8
+ if (ctx.len + 11 > ctx.max) {
9
+ return RANGE_ERR;
10
+ }
11
+ setCursor(ctx, def, t.prop, parentId, modifyOp);
12
+ ctx.buf[ctx.len++] = DELETE;
13
+ }
14
+ }
15
+ else {
16
+ let size = Buffer.byteLength(value, 'utf8');
17
+ if (ctx.len + 15 + size > ctx.max) {
18
+ // 5 compression size
19
+ return RANGE_ERR;
20
+ }
21
+ if (modifyOp === CREATE) {
22
+ def.stringPropsCurrent[t.prop] = 2;
23
+ ctx.hasStringField++;
24
+ }
25
+ setCursor(ctx, def, t.prop, parentId, modifyOp);
26
+ ctx.buf[ctx.len++] = modifyOp;
27
+ ctx.buf[ctx.len++] = size;
28
+ ctx.buf[ctx.len++] = size >>>= 8;
29
+ ctx.buf[ctx.len++] = size >>>= 8;
30
+ ctx.buf[ctx.len++] = size >>>= 8;
31
+ ctx.len += ctx.buf.write(value, ctx.len, 'utf8');
32
+ }
33
+ }
34
+ else if (typeof value === null) {
35
+ if (modifyOp === UPDATE) {
36
+ if (ctx.len + 11 > ctx.max) {
37
+ return RANGE_ERR;
38
+ }
39
+ setCursor(ctx, def, t.prop, parentId, modifyOp);
40
+ ctx.buf[ctx.len++] = DELETE;
41
+ }
42
+ }
43
+ else {
44
+ return new ModifyError(t, value);
45
+ }
46
+ }
47
+ //# sourceMappingURL=alias.js.map
@@ -0,0 +1,6 @@
1
+ import { ModifyCtx } from '../../index.js';
2
+ import { PropDef, SchemaTypeDef } from '../../server/schema/types.js';
3
+ import { ModifyOp, ModifyErr } from './types.js';
4
+ export declare function getBuffer(value: any): Buffer;
5
+ export declare function writeBinaryRaw(value: Buffer, ctx: ModifyCtx): void;
6
+ export declare function writeBinary(value: any, ctx: ModifyCtx, schema: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;