@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,41 @@
1
+ import { REFERENCE, } from '../../../server/schema/types.js';
2
+ import { createQueryDef } from '../queryDef.js';
3
+ import { QueryDefType } from '../types.js';
4
+ export const getAllFieldFromObject = (tree, arr = []) => {
5
+ for (const key in tree) {
6
+ const leaf = tree[key];
7
+ if (!leaf.typeIndex && !leaf.__isPropDef) {
8
+ getAllFieldFromObject(leaf, arr);
9
+ }
10
+ else {
11
+ arr.push(leaf.path.join('.'));
12
+ }
13
+ }
14
+ return arr;
15
+ };
16
+ const createRefQueryDef = (db, def, t) => {
17
+ const defRef = createQueryDef(db, t.typeIndex === REFERENCE
18
+ ? QueryDefType.Reference
19
+ : QueryDefType.References, {
20
+ type: t.inverseTypeName,
21
+ propDef: t,
22
+ });
23
+ def.references.set(t.prop, defRef);
24
+ return defRef;
25
+ };
26
+ export const createOrGetRefQueryDef = (db, def, t) => {
27
+ if (!def.references.has(t.prop)) {
28
+ return createRefQueryDef(db, def, t);
29
+ }
30
+ return def.references.get(t.prop);
31
+ };
32
+ export const createOrGetEdgeRefQueryDef = (db, def, t) => {
33
+ def.edges ??= createQueryDef(db, QueryDefType.Edge, {
34
+ ref: t,
35
+ });
36
+ def.edges.props ??= {};
37
+ def.edges.props[t.name] = t;
38
+ const refDef = createOrGetRefQueryDef(db, def.edges, t);
39
+ return refDef;
40
+ };
41
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,3 @@
1
+ import { QueryDef } from '../types.js';
2
+ import { DbClient } from '../../index.js';
3
+ export declare const walkDefs: (db: DbClient, def: QueryDef, f: string) => void;
@@ -0,0 +1,70 @@
1
+ import { isPropDef, REFERENCE, REFERENCES, } from '../../../server/schema/types.js';
2
+ import { createQueryDef } from '../queryDef.js';
3
+ import { isRefDef, QueryDefType } from '../types.js';
4
+ import { getAllFieldFromObject, createOrGetRefQueryDef } from './utils.js';
5
+ import { includeFields, includeProp, includeAllProps } from './props.js';
6
+ export const walkDefs = (db, def, f) => {
7
+ const prop = def.props[f];
8
+ const path = f.split('.');
9
+ if (!prop) {
10
+ let t = def.schema.tree;
11
+ for (let i = 0; i < path.length; i++) {
12
+ const p = path[i];
13
+ if (isRefDef(def) && p[0] == '$') {
14
+ if (!def.edges) {
15
+ def.edges = createQueryDef(db, QueryDefType.Edge, {
16
+ ref: def.target.propDef,
17
+ });
18
+ }
19
+ const edgeProp = def.edges.props[p];
20
+ if (edgeProp.typeIndex === REFERENCE ||
21
+ edgeProp.typeIndex === REFERENCES) {
22
+ const refDef = createOrGetRefQueryDef(db, def.edges, edgeProp);
23
+ if (path.length - 1 === i) {
24
+ includeAllProps(refDef);
25
+ }
26
+ else {
27
+ const f = path.slice(i + 1).join('.');
28
+ if (!includeProp(refDef, refDef.props[f])) {
29
+ includeFields(refDef, [f]);
30
+ }
31
+ return;
32
+ }
33
+ }
34
+ else {
35
+ def.edges.include.props.add(edgeProp.prop);
36
+ }
37
+ return;
38
+ }
39
+ t = t[p];
40
+ if (!t) {
41
+ return;
42
+ }
43
+ if (isPropDef(t) &&
44
+ (t.typeIndex === REFERENCE || t.typeIndex === REFERENCES)) {
45
+ const refDef = createOrGetRefQueryDef(db, def, t);
46
+ const f = path.slice(i + 1).join('.');
47
+ if (!includeProp(refDef, refDef.props[f])) {
48
+ includeFields(refDef, [f]);
49
+ }
50
+ return;
51
+ }
52
+ }
53
+ const tree = def.schema.tree[path[0]];
54
+ if (tree) {
55
+ const endFields = getAllFieldFromObject(tree);
56
+ for (const field of endFields) {
57
+ walkDefs(db, def, field);
58
+ }
59
+ }
60
+ }
61
+ else if (prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES) {
62
+ const refDef = createOrGetRefQueryDef(db, def, prop);
63
+ includeAllProps(refDef);
64
+ return;
65
+ }
66
+ else {
67
+ includeProp(def, prop);
68
+ }
69
+ };
70
+ //# sourceMappingURL=walk.js.map
@@ -0,0 +1,10 @@
1
+ export * from './queryDef.js';
2
+ export * from './types.js';
3
+ export * from './include/props.js';
4
+ export * from './include/toBuffer.js';
5
+ export * from './toBuffer.js';
6
+ export * from './filter/filter.js';
7
+ export * from './filter/toBuffer.js';
8
+ export * from './sort.js';
9
+ export * from './debug.js';
10
+ export * from './read/read.js';
@@ -0,0 +1,11 @@
1
+ export * from './queryDef.js';
2
+ export * from './types.js';
3
+ export * from './include/props.js';
4
+ export * from './include/toBuffer.js';
5
+ export * from './toBuffer.js';
6
+ export * from './filter/filter.js';
7
+ export * from './filter/toBuffer.js';
8
+ export * from './sort.js';
9
+ export * from './debug.js';
10
+ export * from './read/read.js';
11
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1,3 @@
1
+ import { DbClient } from '../index.js';
2
+ import { QueryDef, QueryDefType, QueryTarget } from './types.js';
3
+ export declare const createQueryDef: (db: DbClient, type: QueryDefType, target: QueryTarget) => QueryDef;
@@ -0,0 +1,54 @@
1
+ import { MAX_RANGE_PROP_LIMIT, MAX_RANGE_REF_LIMIT } from './thresholds.js';
2
+ import { QueryDefType, } from './types.js';
3
+ const createEmptySharedDef = () => {
4
+ const q = {
5
+ filter: { conditions: new Map(), size: 0 },
6
+ range: { offset: 0, limit: 0 },
7
+ include: {
8
+ stringFields: new Set(),
9
+ props: new Set(),
10
+ propsRead: {},
11
+ main: {
12
+ len: 0,
13
+ include: {},
14
+ },
15
+ },
16
+ sort: null,
17
+ references: new Map(),
18
+ };
19
+ return q;
20
+ };
21
+ export const createQueryDef = (db, type, target) => {
22
+ const queryDef = createEmptySharedDef();
23
+ if (type === QueryDefType.Edge) {
24
+ const t = target;
25
+ const q = queryDef;
26
+ q.props = t.ref.edges;
27
+ q.reverseProps = t.ref.reverseEdges;
28
+ q.type = type;
29
+ q.target = t;
30
+ return q;
31
+ }
32
+ else {
33
+ const t = target;
34
+ const q = queryDef;
35
+ q.schema = db.schemaTypesParsed[t.type];
36
+ q.props = q.schema.props;
37
+ q.type = type;
38
+ q.target = t;
39
+ if (type === QueryDefType.Root) {
40
+ // IDS sort
41
+ if (t.ids) {
42
+ q.range.limit = t.ids.length; // 1k?
43
+ }
44
+ else {
45
+ q.range.limit = MAX_RANGE_PROP_LIMIT;
46
+ }
47
+ }
48
+ else if (type === QueryDefType.References) {
49
+ q.range.limit = MAX_RANGE_REF_LIMIT;
50
+ }
51
+ return q;
52
+ }
53
+ };
54
+ //# sourceMappingURL=queryDef.js.map
@@ -0,0 +1,8 @@
1
+ import { QueryDef } from '../types.js';
2
+ export type Item = {
3
+ id: number;
4
+ } & {
5
+ [key: string]: any;
6
+ };
7
+ export declare const readAllFields: (q: QueryDef, result: Buffer, offset: number, end: number, item: Item, id: number) => number;
8
+ export declare const resultToObject: (q: QueryDef, result: Buffer, end: number, offset?: number) => any;
@@ -0,0 +1,303 @@
1
+ import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, } from '../../../server/schema/types.js';
2
+ import { read } from '../../string.js';
3
+ const addField = (p, value, item, defaultOnly = false) => {
4
+ let i = p.__isEdge === true ? 1 : 0;
5
+ const len = p.path.length;
6
+ if (len - i === 1) {
7
+ const field = p.path[i];
8
+ if (!defaultOnly || !(field in item)) {
9
+ item[field] = value;
10
+ }
11
+ }
12
+ else {
13
+ let select = item;
14
+ for (; i < len; i++) {
15
+ const field = p.path[i];
16
+ if (i === len - 1) {
17
+ if (!defaultOnly || !(field in select)) {
18
+ select[field] = value;
19
+ }
20
+ }
21
+ else {
22
+ select = select[field] ?? (select[field] = {});
23
+ }
24
+ }
25
+ }
26
+ };
27
+ const readMainValue = (prop, result, index, item) => {
28
+ // 1: timestamp, 4: number
29
+ if (prop.typeIndex === TIMESTAMP || prop.typeIndex === NUMBER) {
30
+ addField(prop, result.readDoubleLE(index), item);
31
+ }
32
+ // 5: uint32
33
+ else if (prop.typeIndex === UINT32) {
34
+ addField(prop, result.readUInt32LE(index), item);
35
+ }
36
+ // 9: boolean
37
+ else if (prop.typeIndex === BOOLEAN) {
38
+ addField(prop, Boolean(result[index]), item);
39
+ }
40
+ // 10: Enum
41
+ else if (prop.typeIndex === ENUM) {
42
+ if (result[index] === 0) {
43
+ addField(prop, undefined, item);
44
+ }
45
+ else {
46
+ addField(prop, prop.enum[result[index] - 1], item);
47
+ }
48
+ }
49
+ // 11: string
50
+ else if (prop.typeIndex === STRING) {
51
+ // Also remove this default then (same as other string)
52
+ const len = result[index];
53
+ if (len !== 0) {
54
+ const str = result.toString('utf-8', index + 1, index + len + 1);
55
+ addField(prop, str, item);
56
+ }
57
+ else {
58
+ addField(prop, '', item);
59
+ }
60
+ }
61
+ // 11: string
62
+ else if (prop.typeIndex === BINARY) {
63
+ addField(prop, new Uint8Array(result.buffer, index + 1, result[index]), item);
64
+ }
65
+ // 18: int8
66
+ else if (prop.typeIndex === INT8) {
67
+ addField(prop, result.readInt8(index), item);
68
+ }
69
+ // 19: uint8
70
+ else if (prop.typeIndex === UINT8) {
71
+ addField(prop, result.readUint8(index), item);
72
+ }
73
+ // 20: int16
74
+ else if (prop.typeIndex === INT16) {
75
+ addField(prop, result.readInt16LE(index), item);
76
+ }
77
+ // 21: uint16
78
+ else if (prop.typeIndex === UINT16) {
79
+ addField(prop, result.readUint16LE(index), item);
80
+ }
81
+ // 22: int32
82
+ else if (prop.typeIndex === INT32) {
83
+ addField(prop, result.readInt32LE(index), item);
84
+ }
85
+ // 5: uint32
86
+ else if (prop.typeIndex === UINT32) {
87
+ addField(prop, result.readUint32LE(index), item);
88
+ }
89
+ };
90
+ const readMain = (q, result, offset, item) => {
91
+ const mainInclude = q.include.main;
92
+ let i = offset;
93
+ if (mainInclude.len === q.schema.mainLen) {
94
+ for (const start in q.schema.main) {
95
+ readMainValue(q.schema.main[start], result, Number(start) + i, item);
96
+ }
97
+ i += q.schema.mainLen;
98
+ }
99
+ else {
100
+ for (const k in mainInclude.include) {
101
+ const [index, prop] = mainInclude.include[k];
102
+ readMainValue(prop, result, index + i, item);
103
+ }
104
+ i += mainInclude.len;
105
+ }
106
+ return i - offset;
107
+ };
108
+ const handleUndefinedProps = (id, q, item) => {
109
+ for (const k in q.include.propsRead) {
110
+ if (q.include.propsRead[k] !== id) {
111
+ addField(q.schema.reverseProps[k], '', item);
112
+ }
113
+ }
114
+ };
115
+ export const readAllFields = (q, result, offset, end, item, id) => {
116
+ let i = offset;
117
+ while (i < end) {
118
+ const index = result[i];
119
+ i++;
120
+ if (index === 255) {
121
+ handleUndefinedProps(id, q, item);
122
+ return i - offset;
123
+ }
124
+ if (index === 252) {
125
+ let prop = result[i];
126
+ if (prop === 254) {
127
+ i++;
128
+ const field = result[i];
129
+ i++;
130
+ const size = result.readUint32LE(i);
131
+ i += 4;
132
+ const ref = q.edges.references.get(field);
133
+ if (size === 0) {
134
+ // @ts-ignore
135
+ addField(ref.target.propDef, null, item);
136
+ i += size;
137
+ }
138
+ else {
139
+ i++;
140
+ let id = result.readUInt32LE(i);
141
+ i += 4;
142
+ const refItem = {
143
+ id,
144
+ };
145
+ readAllFields(ref, result, i, size + i - 5, refItem, id);
146
+ // @ts-ignore
147
+ addField(ref.target.propDef, refItem, item);
148
+ i += size - 5;
149
+ }
150
+ }
151
+ else if (prop === 253) {
152
+ i++;
153
+ const field = result[i];
154
+ i++;
155
+ const ref = q.edges.references.get(field);
156
+ const size = result.readUint32LE(i);
157
+ i += 4;
158
+ const refs = resultToObject(ref, result, size + i + 4, i);
159
+ // @ts-ignore
160
+ addField(ref.target.propDef, refs, item);
161
+ i += size + 4;
162
+ // ----------------
163
+ }
164
+ else {
165
+ const edgeDef = q.edges.reverseProps[prop];
166
+ const t = edgeDef.typeIndex;
167
+ if (t === BINARY) {
168
+ i++;
169
+ const size = result.readUint32LE(i);
170
+ addField(edgeDef, new Uint8Array(result.buffer, i + 6, size - 6), item);
171
+ i += size + 4;
172
+ }
173
+ else if (t === STRING || t === ALIAS || t === ALIASES) {
174
+ i++;
175
+ const size = result.readUint32LE(i);
176
+ if (size === 0) {
177
+ addField(edgeDef, '', item);
178
+ }
179
+ else {
180
+ addField(edgeDef, read(result, i + 4, size), item);
181
+ }
182
+ i += size + 4;
183
+ }
184
+ else {
185
+ i++;
186
+ readMainValue(edgeDef, result, i, item);
187
+ i += edgeDef.len;
188
+ }
189
+ }
190
+ }
191
+ else if (index === 254) {
192
+ const field = result[i];
193
+ i++;
194
+ const size = result.readUint32LE(i);
195
+ i += 4;
196
+ const ref = q.references.get(field);
197
+ if (size === 0) {
198
+ // @ts-ignore
199
+ addField(ref.target.propDef, null, item);
200
+ i += size;
201
+ }
202
+ else {
203
+ i++;
204
+ let id = result.readUInt32LE(i);
205
+ i += 4;
206
+ const refItem = {
207
+ id,
208
+ };
209
+ readAllFields(ref, result, i, size + i - 5, refItem, id);
210
+ // @ts-ignore
211
+ addField(ref.target.propDef, refItem, item);
212
+ i += size - 5;
213
+ }
214
+ }
215
+ else if (index === 253) {
216
+ const field = result[i];
217
+ i++;
218
+ const ref = q.references.get(field);
219
+ const size = result.readUint32LE(i);
220
+ i += 4;
221
+ const refs = resultToObject(ref, result, size + i + 4, i);
222
+ // @ts-ignore
223
+ addField(ref.target.propDef, refs, item);
224
+ i += size + 4;
225
+ }
226
+ else if (index === 0) {
227
+ i += readMain(q, result, i, item);
228
+ }
229
+ else {
230
+ const prop = q.schema.reverseProps[index];
231
+ if (prop.typeIndex === BINARY) {
232
+ q.include.propsRead[index] = id;
233
+ const size = result.readUint32LE(i);
234
+ addField(prop, new Uint8Array(result.buffer, i + 4 + 2, size - 6), item);
235
+ i += size + 4;
236
+ }
237
+ else if (prop.typeIndex === STRING) {
238
+ q.include.propsRead[index] = id;
239
+ const size = result.readUint32LE(i);
240
+ if (size === 0) {
241
+ addField(prop, '', item);
242
+ }
243
+ else {
244
+ addField(prop, read(result, i + 4, size), item);
245
+ }
246
+ i += size + 4;
247
+ }
248
+ else if (prop.typeIndex == TEXT) {
249
+ q.include.propsRead[index] = id;
250
+ const size = result.readUint32LE(i);
251
+ // TODO Read text
252
+ //if (size === 0) {
253
+ // addField(prop, '', item)
254
+ //} else {
255
+ // addField(prop, read(result, i + 4, size), item)
256
+ //}
257
+ i += size + 4;
258
+ }
259
+ else if (prop.typeIndex === ALIAS) {
260
+ q.include.propsRead[index] = id;
261
+ const size = result.readUint32LE(i);
262
+ i += 4;
263
+ if (size === 0) {
264
+ addField(prop, '', item);
265
+ }
266
+ else {
267
+ const string = result.toString('utf8', i, (i += size));
268
+ addField(prop, string, item);
269
+ }
270
+ }
271
+ }
272
+ }
273
+ // to add defaults - may not optimal for performance
274
+ handleUndefinedProps(id, q, item);
275
+ return i - offset;
276
+ };
277
+ export const resultToObject = (q, result, end, offset = 0) => {
278
+ const len = result.readUint32LE(offset);
279
+ if (len === 0) {
280
+ return [];
281
+ }
282
+ let items = [];
283
+ let i = 5 + offset;
284
+ while (i < end) {
285
+ let id = result.readUInt32LE(i);
286
+ i += 4;
287
+ const item = {
288
+ id,
289
+ };
290
+ if (q.search) {
291
+ item.$searchScore = result[i];
292
+ i += 1;
293
+ }
294
+ const l = readAllFields(q, result, i, end, item, id);
295
+ i += l;
296
+ items.push(item);
297
+ }
298
+ if ('id' in q.target || 'alias' in q.target) {
299
+ return items[0];
300
+ }
301
+ return items;
302
+ };
303
+ //# sourceMappingURL=read.js.map
@@ -0,0 +1,2 @@
1
+ import { BasedDbQuery } from './BasedDbQuery.js';
2
+ export declare const registerQuery: (q: BasedDbQuery) => Buffer;
@@ -0,0 +1,31 @@
1
+ import native from '../../native.js';
2
+ import { defToBuffer } from './toBuffer.js';
3
+ import { checkMaxBufferSize } from './validation.js';
4
+ export const registerQuery = (q) => {
5
+ // just add crc32 in the buffer
6
+ if (!q.id) {
7
+ const b = defToBuffer(q.db, q.def);
8
+ const buf = Buffer.concat(b);
9
+ let id = native.crc32(buf);
10
+ q.id = id;
11
+ // id = (id ^ q.def.schema.id) >>> 0
12
+ // typeId, crc32, len
13
+ // but want it to fit in a js number...
14
+ // use 2 bytes for len and just continue counting
15
+ // const x = Buffer.allocUnsafe(8)
16
+ // // const number
17
+ // x.writeUint16LE(q.def.schema.id, 0)
18
+ // x.writeUint32LE(id, 2)
19
+ // x.writeUint16LE(buf.byteLength, 6)
20
+ // // ------------------------
21
+ // console.log('-> CRC32', { id, x: new Uint8Array(x), y: x.readFloatLE(0) })
22
+ // do a test for
23
+ // console.log(id)
24
+ // id, len, type as id?
25
+ q.buffer = buf;
26
+ checkMaxBufferSize(buf);
27
+ return buf;
28
+ }
29
+ return q.buffer;
30
+ };
31
+ //# sourceMappingURL=registerQuery.js.map
@@ -0,0 +1,6 @@
1
+ import { QueryDefSearch, QueryDef } from '../types.js';
2
+ export type Search = string[] | {
3
+ [field: string]: number;
4
+ } | string;
5
+ export declare const search: (def: QueryDef, q: string, s?: Search) => void;
6
+ export declare const searchToBuffer: (search: QueryDefSearch) => Buffer;
@@ -0,0 +1,82 @@
1
+ import { STRING } from '../../../server/schema/types.js';
2
+ const makeSize = (nr, u8 = false) => {
3
+ if (u8) {
4
+ const size = Buffer.allocUnsafe(1);
5
+ size[0] = nr;
6
+ return size;
7
+ }
8
+ const size = Buffer.allocUnsafe(2);
9
+ size.writeUint16LE(nr);
10
+ return size;
11
+ };
12
+ export const search = (def, q, s) => {
13
+ let blocks = 0;
14
+ const x = q.toLowerCase().trim().split(' ');
15
+ const bufs = [];
16
+ for (const s of x) {
17
+ if (s) {
18
+ const b = Buffer.from(s);
19
+ bufs.push(makeSize(b.byteLength), b);
20
+ blocks++;
21
+ }
22
+ }
23
+ bufs.unshift(makeSize(blocks, true));
24
+ const query = Buffer.concat(bufs);
25
+ def.search = {
26
+ size: query.byteLength + 2,
27
+ query,
28
+ fields: [],
29
+ };
30
+ if (typeof s === 'string') {
31
+ s = [s];
32
+ }
33
+ if (!s) {
34
+ s = {};
35
+ for (const k in def.props) {
36
+ const prop = def.props[k];
37
+ // if title / name / headline add ROLE:
38
+ if (prop.typeIndex === STRING) {
39
+ s[k] = k === 'title' || k === 'name' || k === 'headline' ? 0 : 2;
40
+ }
41
+ }
42
+ }
43
+ else if (Array.isArray(s)) {
44
+ const x = {};
45
+ for (const f of s) {
46
+ x[f] = 0;
47
+ }
48
+ s = x;
49
+ }
50
+ for (const key in s) {
51
+ const prop = def.props[key];
52
+ if (!prop) {
53
+ throw new Error('field ' + key + ' does not exist on type');
54
+ }
55
+ if (prop.typeIndex !== STRING) {
56
+ throw new Error('Can only search trough strings');
57
+ }
58
+ def.search.size += 4;
59
+ def.search.fields.push({
60
+ weight: s[key],
61
+ field: prop.prop,
62
+ start: prop.start ?? 0,
63
+ });
64
+ }
65
+ };
66
+ export const searchToBuffer = (search) => {
67
+ const result = Buffer.allocUnsafe(search.size);
68
+ result.writeUint16LE(search.query.byteLength, 0);
69
+ result.set(search.query, 2);
70
+ const offset = search.query.byteLength + 2;
71
+ search.fields.sort((a, b) => {
72
+ return a.weight - b.weight;
73
+ });
74
+ for (let i = 0; i < search.fields.length * 4; i += 4) {
75
+ const f = search.fields[i / 4];
76
+ result[i + offset] = f.field;
77
+ result[i + 1 + offset] = f.weight;
78
+ result.writeUInt16LE(f.start, i + 2 + offset);
79
+ }
80
+ return result;
81
+ };
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import { QueryDef, QueryDefSort } from './types.js';
2
+ export declare const createSortBuffer: (sort: QueryDefSort) => Buffer;
3
+ export declare const sort: (def: QueryDef, field: string, order?: "asc" | "desc") => void;
@@ -0,0 +1,18 @@
1
+ export const createSortBuffer = (sort) => {
2
+ const buf = Buffer.allocUnsafe(7);
3
+ // [order] [propType] [start] [start] [len] [len]
4
+ buf[0] = sort.order;
5
+ buf[1] = sort.prop.prop;
6
+ buf[2] = sort.prop.typeIndex;
7
+ buf.writeUint16LE(sort.prop.start, 3);
8
+ buf.writeUint16LE(sort.prop.len, 5);
9
+ return buf;
10
+ };
11
+ // NO REF / REFERENCES SUPPORT
12
+ export const sort = (def, field, order) => {
13
+ def.sort = {
14
+ prop: def.props[field],
15
+ order: order === 'asc' || order === undefined ? 0 : 1,
16
+ };
17
+ };
18
+ //# sourceMappingURL=sort.js.map
@@ -0,0 +1,5 @@
1
+ import { BasedDbQuery } from '../BasedDbQuery.js';
2
+ import { OnData, OnError, OnClose } from './types.js';
3
+ export * from './types.js';
4
+ export * from './markers.js';
5
+ export declare const subscribe: (q: BasedDbQuery, onData: OnData, onError: OnError) => OnClose;