@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,88 @@
1
+ import { PropDef, PropDefEdge, SchemaTypeDef } from '../../server/schema/schema.js';
2
+ export type MainIncludes = {
3
+ [start: string]: [number, PropDef];
4
+ };
5
+ export type IncludeTreeArr = (string | PropDef | IncludeTreeArr)[];
6
+ declare enum QueryDefType {
7
+ Edge = 1,
8
+ Reference = 2,
9
+ References = 3,
10
+ Root = 4
11
+ }
12
+ export type EdgeTarget = {
13
+ ref: PropDef | PropDefEdge | null;
14
+ };
15
+ export type Target = {
16
+ type: string;
17
+ id?: number | void;
18
+ ids?: Uint32Array | void;
19
+ propDef?: PropDef | PropDefEdge;
20
+ alias?: QueryByAliasObj;
21
+ };
22
+ export declare const isRefDef: (def: QueryDef) => def is QueryDefRest;
23
+ export type QueryDefFilter = {
24
+ size: number;
25
+ conditions: Map<number, Buffer[]>;
26
+ references?: Map<number, QueryDefFilter>;
27
+ fromRef?: PropDef;
28
+ schema?: SchemaTypeDef;
29
+ edges?: Map<number, Buffer[]>;
30
+ or?: QueryDefFilter;
31
+ and?: QueryDefFilter;
32
+ };
33
+ export type QueryDefSearch = {
34
+ size: number;
35
+ query: Buffer;
36
+ fields: {
37
+ weight: number;
38
+ field: number;
39
+ start: number;
40
+ }[];
41
+ };
42
+ export type QueryDefSort = {
43
+ prop: PropDefEdge | PropDef;
44
+ order: 0 | 1;
45
+ };
46
+ export type QueryDefShared = {
47
+ filter: QueryDefFilter;
48
+ search: null | QueryDefSearch;
49
+ sort: null | QueryDefSort;
50
+ reverseProps: any;
51
+ range: {
52
+ offset: number;
53
+ limit: number;
54
+ };
55
+ include: {
56
+ stringFields: Set<string>;
57
+ props: Set<number>;
58
+ propsRead: {
59
+ [propName: number]: number;
60
+ };
61
+ main: {
62
+ include: MainIncludes;
63
+ len: number;
64
+ };
65
+ };
66
+ references: Map<number, QueryDef>;
67
+ edges?: QueryDef;
68
+ };
69
+ export type QueryDefEdges = {
70
+ type: QueryDefType.Edge;
71
+ target: EdgeTarget;
72
+ schema: null;
73
+ props: PropDef['edges'];
74
+ reverseProps: PropDef['edges'];
75
+ } & QueryDefShared;
76
+ export type QueryDefRest = {
77
+ type: QueryDefType.References | QueryDefType.Reference | QueryDefType.Root;
78
+ target: Target;
79
+ schema: SchemaTypeDef | null;
80
+ props: SchemaTypeDef['props'] | PropDef['edges'];
81
+ } & QueryDefShared;
82
+ export type QueryDef = QueryDefEdges | QueryDefRest;
83
+ export type QueryTarget = EdgeTarget | Target;
84
+ export { QueryDefType };
85
+ export type QueryByAliasObj = {
86
+ [key: string]: string | QueryByAliasObj;
87
+ };
88
+ export declare const isAlias: (id: QueryByAliasObj | number | (QueryByAliasObj | number)[]) => id is QueryByAliasObj;
@@ -0,0 +1,15 @@
1
+ var QueryDefType;
2
+ (function (QueryDefType) {
3
+ QueryDefType[QueryDefType["Edge"] = 1] = "Edge";
4
+ QueryDefType[QueryDefType["Reference"] = 2] = "Reference";
5
+ QueryDefType[QueryDefType["References"] = 3] = "References";
6
+ QueryDefType[QueryDefType["Root"] = 4] = "Root";
7
+ })(QueryDefType || (QueryDefType = {}));
8
+ export const isRefDef = (def) => {
9
+ return (def.type === QueryDefType.Reference || def.type === QueryDefType.References);
10
+ };
11
+ export { QueryDefType };
12
+ export const isAlias = (id) => {
13
+ return typeof id === 'object' && id !== null && !Array.isArray(id);
14
+ };
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,15 @@
1
+ import { PropDef, PropDefEdge } from '../../server/schema/types.js';
2
+ import { Operator } from './filter/operators.js';
3
+ import { QueryByAliasObj } from './types.js';
4
+ export declare const isValidId: (id: number) => void;
5
+ export declare const checkMaxIdsPerQuery: (ids: (number | QueryByAliasObj)[]) => void;
6
+ export declare const checkMaxBufferSize: (buf: Buffer) => void;
7
+ export declare const checkTotalBufferSize: (bufers: Buffer[]) => void;
8
+ export declare const hasFields: (fields: {
9
+ [key: string]: PropDefEdge;
10
+ } | {
11
+ [path: string]: PropDef;
12
+ }) => void;
13
+ export declare const hasField: (field: string) => void;
14
+ export declare const checkOperator: (operator: Operator | boolean) => void;
15
+ export declare const checkValue: (value: any, operator: Operator) => void;
@@ -0,0 +1,59 @@
1
+ import { MAX_IDS_PER_QUERY, MIN_ID_VALUE, MAX_ID_VALUE, MAX_BUFFER_SIZE, } from './thresholds.js';
2
+ import { validOperators } from './filter/operators.js';
3
+ export const isValidId = (id) => {
4
+ if (typeof id != 'number') {
5
+ throw new Error('Id has to be a number');
6
+ }
7
+ else if (id < MIN_ID_VALUE || id > MAX_ID_VALUE) {
8
+ throw new Error(`Invalid Id: The Id should range between ${MIN_ID_VALUE} and ${MAX_ID_VALUE}.)`);
9
+ }
10
+ };
11
+ export const checkMaxIdsPerQuery = (ids) => {
12
+ if (ids.length > MAX_IDS_PER_QUERY) {
13
+ throw new Error(`The number of IDs cannot exceed ${MAX_IDS_PER_QUERY}.`);
14
+ }
15
+ };
16
+ export const checkMaxBufferSize = (buf) => {
17
+ if (buf.byteLength > MAX_BUFFER_SIZE) {
18
+ throw new Error(`The buffer size exceeds the maximum threshold of ${MAX_BUFFER_SIZE} bytes.` +
19
+ `Crrent size is ${buf.byteLength} bytes.`);
20
+ }
21
+ };
22
+ export const checkTotalBufferSize = (bufers) => {
23
+ let totalSize = 0;
24
+ for (const buffer of bufers) {
25
+ totalSize += buffer.byteLength;
26
+ if (totalSize > MAX_BUFFER_SIZE) {
27
+ throw new Error(`The total buffer size exceeds the maximum threshold of ${MAX_BUFFER_SIZE} bytes.` +
28
+ `Crrent size is ${totalSize} bytes.`);
29
+ }
30
+ }
31
+ };
32
+ export const hasFields = (fields) => {
33
+ if (Object.keys(fields).length === 0) {
34
+ throw new Error('No fields available to include');
35
+ }
36
+ };
37
+ export const hasField = (field) => {
38
+ if (!field) {
39
+ throw new Error(`Invalid field: ${field}`);
40
+ }
41
+ else if (typeof field !== 'string' || field.trim() === '') {
42
+ throw new Error('Field must be a non-empty string');
43
+ }
44
+ };
45
+ export const checkOperator = (operator) => {
46
+ if (operator !== undefined &&
47
+ typeof operator !== 'boolean' &&
48
+ !validOperators.includes(operator)) {
49
+ throw new Error(`Invalid operator: ${operator}`);
50
+ }
51
+ };
52
+ export const checkValue = (value, operator) => {
53
+ if (operator === '..' || operator === '!..') {
54
+ if (!Array.isArray(value) || value.length !== 2) {
55
+ throw new Error(`Invalid value for operator ${operator}: expected an array with two elements`);
56
+ }
57
+ }
58
+ };
59
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1,5 @@
1
+ import { LangCode } from '@based/schema';
2
+ export declare const write: (buf: Buffer, value: string, offset: number, noCompression: boolean, lang?: LangCode) => number;
3
+ export declare const compress: (str: string) => Buffer;
4
+ export declare const decompress: (buf: Buffer) => string;
5
+ export declare const read: (buf: Buffer, offset: number, len: number) => string;
@@ -0,0 +1,73 @@
1
+ import native from '../native.js';
2
+ // type 0 = no compression; 1 = deflate
3
+ // [lang] [type] [uncompressed size 4] [compressed string] [crc32]
4
+ // var cnt = 0
5
+ // var bytesSaved = 0
6
+ // make this into a package
7
+ // write the type Byte
8
+ export const write = (buf, value, offset, noCompression, lang) => {
9
+ value = value.normalize('NFKD');
10
+ buf[offset] = lang || 0;
11
+ // 50 maybe if lvl 1
12
+ if (value.length > 200 && !noCompression) {
13
+ const s = Buffer.byteLength(value, 'utf8');
14
+ buf.write(value, offset + 6 + s, 'utf8');
15
+ let crc = native.crc32(buf.subarray(offset + 6 + s, offset + 6 + 2 * s));
16
+ const size = native.compress(buf, offset + 6, s);
17
+ if (size === 0) {
18
+ buf[offset + 1] = 0; // not compressed
19
+ const len = buf.write(value, offset + 2, 'utf8');
20
+ buf[offset + len + 2] = crc;
21
+ buf[offset + len + 3] = crc >>>= 8;
22
+ buf[offset + len + 4] = crc >>>= 8;
23
+ buf[offset + len + 5] = crc >>>= 8;
24
+ return len + 6;
25
+ }
26
+ else {
27
+ buf[offset + 1] = 1; // compressed
28
+ buf.writeUInt32LE(s, offset + 2);
29
+ buf[offset + size + 6] = crc;
30
+ buf[offset + size + 7] = crc >>>= 8;
31
+ buf[offset + size + 8] = crc >>>= 8;
32
+ buf[offset + size + 9] = crc >>>= 8;
33
+ return size + 10; // 0 C 4 4
34
+ }
35
+ }
36
+ else {
37
+ buf[offset + 1] = 0; // not compressed
38
+ const len = buf.write(value, offset + 2, 'utf8');
39
+ let crc = native.crc32(buf.subarray(offset + 2, offset + len + 2));
40
+ buf[offset + len + 2] = crc;
41
+ buf[offset + len + 3] = crc >>>= 8;
42
+ buf[offset + len + 4] = crc >>>= 8;
43
+ buf[offset + len + 5] = crc >>>= 8;
44
+ return len + 6;
45
+ }
46
+ };
47
+ let tmpCompressBlock;
48
+ export const compress = (str) => {
49
+ if (!tmpCompressBlock || tmpCompressBlock.byteLength < str.length * 3) {
50
+ tmpCompressBlock = Buffer.allocUnsafe(str.length * 3);
51
+ }
52
+ const s = write(tmpCompressBlock, str, 0, false);
53
+ const nBuffer = Buffer.allocUnsafe(s);
54
+ tmpCompressBlock.copy(nBuffer, 0, 0, s);
55
+ return nBuffer;
56
+ };
57
+ export const decompress = (buf) => {
58
+ return read(buf, 0, buf.byteLength);
59
+ };
60
+ export const read = (buf, offset, len) => {
61
+ const type = buf[offset + 1];
62
+ if (type == 1) {
63
+ const origSize = buf.readUint32LE(offset + 2);
64
+ const newBuffer = Buffer.allocUnsafe(origSize);
65
+ native.decompress(buf, newBuffer, offset + 6, len - 6);
66
+ return newBuffer.toString('utf8');
67
+ }
68
+ else if (type == 0) {
69
+ return buf.toString('utf8', offset + 2, len + offset - 4);
70
+ }
71
+ return '';
72
+ };
73
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ export declare const makeCsmtKeyFromNodeId: (typeId: number, blockCapacity: number, nodeId: number) => number;
@@ -0,0 +1,5 @@
1
+ export const makeCsmtKeyFromNodeId = (typeId, blockCapacity, nodeId) => {
2
+ const tmp = nodeId - +!(nodeId % blockCapacity);
3
+ return typeId * 4294967296 + ((tmp / blockCapacity) | 0) * blockCapacity + 1;
4
+ };
5
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1,31 @@
1
+ import { compress, decompress } from './client/string.js';
2
+ import { ModifyCtx } from './client/operations.js';
3
+ import { DbServer } from './server/index.js';
4
+ import { DbClient } from './client/index.js';
5
+ export * from './server/schema/typeDef.js';
6
+ export * from './client/modify/modify.js';
7
+ export { compress, decompress };
8
+ export { ModifyCtx };
9
+ export { DbClient, DbServer };
10
+ export declare class BasedDb {
11
+ client: DbClient;
12
+ server: DbServer;
13
+ fileSystemPath: string;
14
+ maxModifySize: number;
15
+ constructor({ path, maxModifySize, }: {
16
+ path: string;
17
+ maxModifySize?: number;
18
+ });
19
+ create: DbClient['create'];
20
+ update: DbClient['update'];
21
+ upsert: DbClient['upsert'];
22
+ remove: DbClient['remove'];
23
+ query: DbClient['query'];
24
+ putSchema: DbClient['putSchema'];
25
+ drain: DbClient['drain'];
26
+ start: DbServer['start'];
27
+ stop: DbServer['stop'];
28
+ save: DbServer['save'];
29
+ migrateSchema: DbServer['migrateSchema'];
30
+ destroy(): Promise<void>;
31
+ }
@@ -0,0 +1,85 @@
1
+ import { compress, decompress } from './client/string.js';
2
+ import { ModifyCtx } from './client/operations.js';
3
+ import { DbServer } from './server/index.js';
4
+ import { DbClient } from './client/index.js';
5
+ export * from './server/schema/typeDef.js';
6
+ export * from './client/modify/modify.js';
7
+ export { compress, decompress };
8
+ export { ModifyCtx }; // TODO move this somewhere
9
+ export { DbClient, DbServer };
10
+ export class BasedDb {
11
+ client;
12
+ server;
13
+ fileSystemPath;
14
+ maxModifySize;
15
+ constructor({ path, maxModifySize, }) {
16
+ const server = new DbServer({
17
+ path,
18
+ maxModifySize,
19
+ onSchemaChange(schema) {
20
+ client.putLocalSchema(schema);
21
+ },
22
+ });
23
+ const client = new DbClient({
24
+ maxModifySize,
25
+ hooks: {
26
+ putSchema(schema, fromStart) {
27
+ return Promise.resolve(server.putSchema(schema, fromStart));
28
+ },
29
+ flushModify(buf) {
30
+ server.modify(buf);
31
+ return Promise.resolve({
32
+ offsets: {},
33
+ });
34
+ },
35
+ getQueryBuf(buf) {
36
+ return Promise.resolve(server.getQueryBuf(buf));
37
+ },
38
+ },
39
+ });
40
+ this.server = server;
41
+ this.client = client;
42
+ }
43
+ // client
44
+ create = function () {
45
+ return this.client.create.apply(this.client, arguments);
46
+ };
47
+ update = function () {
48
+ return this.client.update.apply(this.client, arguments);
49
+ };
50
+ upsert = function () {
51
+ return this.client.upsert.apply(this.client, arguments);
52
+ };
53
+ remove = function () {
54
+ return this.client.remove.apply(this.client, arguments);
55
+ };
56
+ query = function () {
57
+ return this.client.query.apply(this.client, arguments);
58
+ };
59
+ putSchema = function () {
60
+ return this.client.putSchema.apply(this.client, arguments);
61
+ };
62
+ drain = function () {
63
+ return this.client.drain.apply(this.client, arguments);
64
+ };
65
+ // server
66
+ start = function () {
67
+ return this.server.start.apply(this.server, arguments);
68
+ };
69
+ stop = function () {
70
+ this.client.stop();
71
+ return this.server.stop.apply(this.server, arguments);
72
+ };
73
+ save = function () {
74
+ return this.server.save.apply(this.server, arguments);
75
+ };
76
+ migrateSchema = function () {
77
+ return this.server.migrateSchema.apply(this.server, arguments);
78
+ };
79
+ // both
80
+ destroy() {
81
+ this.client.destroy();
82
+ return this.server.destroy();
83
+ }
84
+ }
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,28 @@
1
+ declare const _default: {
2
+ workerCtxInit: () => void;
3
+ markMerkleBlock: (buf: Buffer) => any;
4
+ externalFromInt(address: BigInt): any;
5
+ intFromExternal(external: any): BigInt;
6
+ modify: (data: Buffer, types: Buffer, dbCtx: any) => any;
7
+ getQueryBuf: (q: Buffer, dbCtx: any) => Buffer | null;
8
+ start: (id: number) => any;
9
+ stop: (dbCtx: any) => any;
10
+ saveCommon: (path: string, dbCtx: any) => number;
11
+ saveRange: (path: string, typeCode: number, start: number, end: number, dbCtx: any, hashOut: Buffer) => number;
12
+ loadCommon: (path: string, dbCtx: any) => number;
13
+ loadRange: (path: string, dbCtx: any) => number;
14
+ updateSchemaType: (prefix: number, buf: Buffer, dbCtx: any) => any;
15
+ getTypeInfo: (typeId: number, dbCtx: any) => any;
16
+ getNodeRangeHash: (typeId: number, start: number, end: number, bufOut: Buffer, dbCtx: any) => any;
17
+ createHash: () => {
18
+ update: (buf: Buffer) => any;
19
+ digest: (encoding?: BufferEncoding) => Buffer | string;
20
+ reset: () => void;
21
+ };
22
+ compress: (buf: Buffer, offset: number, stringSize: number) => any;
23
+ decompress: (input: Buffer, output: Buffer, offset: number, len: number) => any;
24
+ crc32: (buf: Buffer) => any;
25
+ createSortIndex: (buf: Buffer, dbCtx: any) => any;
26
+ destroySortIndex: (buf: Buffer, dbCtx: any) => any;
27
+ };
28
+ export default _default;
@@ -0,0 +1,96 @@
1
+ // @ts-ignore
2
+ import db from '../../basedDbNative.cjs';
3
+ var compressor = null;
4
+ var decompressor = null;
5
+ export default {
6
+ workerCtxInit: () => {
7
+ return db.workerCtxInit();
8
+ },
9
+ markMerkleBlock: (buf) => {
10
+ // pstart,
11
+ },
12
+ externalFromInt(address) {
13
+ return db.externalFromInt(address);
14
+ },
15
+ intFromExternal(external) {
16
+ return db.intFromExternal(external);
17
+ },
18
+ modify: (data, types, dbCtx) => {
19
+ db.modify(data, types, dbCtx);
20
+ },
21
+ getQueryBuf: (q, dbCtx) => {
22
+ return db.getQueryBuf(dbCtx, q);
23
+ },
24
+ start: (id) => {
25
+ return db.start(id);
26
+ },
27
+ stop: (dbCtx) => {
28
+ return db.stop(dbCtx);
29
+ },
30
+ saveCommon: (path, dbCtx) => {
31
+ const buf = Buffer.concat([Buffer.from(path), Buffer.from([0])]);
32
+ return db.saveCommon(buf, dbCtx);
33
+ },
34
+ saveRange: (path, typeCode, start, end, dbCtx, hashOut) => {
35
+ const buf = Buffer.concat([Buffer.from(path), Buffer.from([0])]);
36
+ return db.saveRange(buf, typeCode, start, end, dbCtx, hashOut);
37
+ },
38
+ loadCommon: (path, dbCtx) => {
39
+ const buf = Buffer.concat([Buffer.from(path), Buffer.from([0])]);
40
+ return db.loadCommon(buf, dbCtx);
41
+ },
42
+ loadRange: (path, dbCtx) => {
43
+ const buf = Buffer.concat([Buffer.from(path), Buffer.from([0])]);
44
+ return db.loadRange(buf, dbCtx);
45
+ },
46
+ updateSchemaType: (prefix, buf, dbCtx) => {
47
+ return db.updateSchema(prefix, buf, dbCtx);
48
+ },
49
+ getTypeInfo: (typeId, dbCtx) => {
50
+ return db.getTypeInfo(typeId, dbCtx);
51
+ },
52
+ getNodeRangeHash: (typeId, start, end, bufOut, dbCtx) => {
53
+ return db.getNodeRangeHash(typeId, start, end, bufOut, dbCtx);
54
+ },
55
+ createHash: () => {
56
+ const state = db.hashCreate();
57
+ const hash = {
58
+ update: (buf) => {
59
+ db.hashUpdate(state, buf);
60
+ return hash;
61
+ },
62
+ digest: (encoding) => {
63
+ const buf = Buffer.allocUnsafe(16);
64
+ db.hashDigest(state, buf);
65
+ return encoding ? buf.toString(encoding) : buf;
66
+ },
67
+ reset: () => {
68
+ db.hashReset(state);
69
+ },
70
+ };
71
+ return hash;
72
+ },
73
+ // needs to pass dbCtx: any
74
+ compress: (buf, offset, stringSize) => {
75
+ if (compressor === null) {
76
+ compressor = db.createCompressor();
77
+ }
78
+ return db.compress(compressor, buf, offset, stringSize);
79
+ },
80
+ decompress: (input, output, offset, len) => {
81
+ if (decompressor === null) {
82
+ decompressor = db.createDecompressor();
83
+ }
84
+ return db.decompress(decompressor, input, output, offset, len);
85
+ },
86
+ crc32: (buf) => {
87
+ return db.crc32(buf);
88
+ },
89
+ createSortIndex: (buf, dbCtx) => {
90
+ return db.createSortIndex(dbCtx, buf);
91
+ },
92
+ destroySortIndex: (buf, dbCtx) => {
93
+ return db.destroySortIndex(dbCtx, buf);
94
+ }
95
+ };
96
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1,2 @@
1
+ import { Csmt } from './index.js';
2
+ export default function draw(csmt: Csmt): string;
@@ -0,0 +1,32 @@
1
+ function makeLabel(node) {
2
+ return `${node.key}\n${node.hash.toString('base64').substring(0, 5)}`;
3
+ }
4
+ export default function draw(csmt) {
5
+ const root = csmt.getRoot();
6
+ const lines = [];
7
+ const nodes = [];
8
+ let i = 0;
9
+ const walk = (node, prev) => {
10
+ const cur = i;
11
+ const left = node.left;
12
+ const right = node.right;
13
+ const isLeaf = !left && !right;
14
+ nodes.push(`n${cur} [label="${makeLabel(node)}"${isLeaf ? ' shape=box' : ''}];`);
15
+ if (cur > 0) {
16
+ lines.push(`n${prev} -- n${cur}`);
17
+ }
18
+ if (left) {
19
+ i++;
20
+ walk(left, cur);
21
+ }
22
+ if (right) {
23
+ i++;
24
+ walk(right, cur);
25
+ }
26
+ };
27
+ if (root) {
28
+ walk(root, i);
29
+ }
30
+ return `graph ethane {\n${nodes.join('\n')}\n${lines.join('\n')}\n}`;
31
+ }
32
+ //# sourceMappingURL=draw-dot.js.map
@@ -0,0 +1,4 @@
1
+ import drawDot from './draw-dot.js';
2
+ export * from './types.js';
3
+ export * from './tree.js';
4
+ export { drawDot };
@@ -0,0 +1,5 @@
1
+ import drawDot from './draw-dot.js';
2
+ export * from './types.js';
3
+ export * from './tree.js';
4
+ export { drawDot };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ type Predicate = (x: any) => boolean;
2
+ type Func = (x: any) => any;
3
+ declare const match: (x: any) => {
4
+ on: (pred: Predicate, fn: Func) => any;
5
+ otherwise: (fn: Func) => any;
6
+ };
7
+ export default match;
@@ -0,0 +1,10 @@
1
+ const matched = (x) => ({
2
+ on: () => matched(x),
3
+ otherwise: () => x,
4
+ });
5
+ const match = (x) => ({
6
+ on: (pred, fn) => (pred(x) ? matched(fn(x)) : match(x)),
7
+ otherwise: (fn) => fn(x),
8
+ });
9
+ export default match;
10
+ //# sourceMappingURL=match.js.map
@@ -0,0 +1,7 @@
1
+ import { TreeKey, TreeNode } from './types.js';
2
+ export declare enum Direction {
3
+ Left = "L",
4
+ Right = "R"
5
+ }
6
+ export type Proof = [TreeKey | null, TreeKey | null] | [TreeKey | Buffer, TreeKey | Direction][];
7
+ export default function membershipProof(root: TreeNode | null, k: TreeKey): Proof;