@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,134 @@
1
+ import { isPropDef, ID_FIELD_DEF, } from '../../../server/schema/schema.js';
2
+ import { primitiveFilter } from './primitiveFilter.js';
3
+ import { IsFilter } from './types.js';
4
+ import { hasField, checkOperator, checkValue } from '../validation.js';
5
+ const referencesFilter = (db, filter, schema, conditions, def) => {
6
+ const [fieldStr, operator, value] = filter;
7
+ var size = 0;
8
+ const path = fieldStr.split('.');
9
+ let t = schema.tree;
10
+ hasField(fieldStr);
11
+ checkOperator(operator);
12
+ checkValue(value, operator);
13
+ for (let i = 0; i < path.length; i++) {
14
+ const p = path[i];
15
+ t = t[p];
16
+ if (!t) {
17
+ if (p[0] === '$') {
18
+ let edges = conditions.fromRef && conditions.fromRef.edges;
19
+ if (!edges && 'propDef' in def.target) {
20
+ edges = def.target.propDef.edges;
21
+ }
22
+ if (edges) {
23
+ const edgeDef = edges[p];
24
+ if (edgeDef) {
25
+ conditions.edges ??= new Map();
26
+ size += 3 + primitiveFilter(edgeDef, filter, conditions);
27
+ }
28
+ }
29
+ }
30
+ return size;
31
+ }
32
+ if (isPropDef(t) && t.typeIndex === 13) {
33
+ conditions.references ??= new Map();
34
+ let refConditions = conditions.references.get(t.prop);
35
+ if (!refConditions) {
36
+ const schema = db.schemaTypesParsed[t.inverseTypeName];
37
+ size += 6;
38
+ refConditions = {
39
+ conditions: new Map(),
40
+ fromRef: t,
41
+ schema,
42
+ size: 0,
43
+ };
44
+ conditions.references.set(t.prop, refConditions);
45
+ }
46
+ // more nested
47
+ size += filterRaw(db, [path.slice(i + 1).join('.'), operator, value], refConditions.schema, refConditions, def);
48
+ return size;
49
+ }
50
+ }
51
+ console.error(`Querty: field "${fieldStr}" does not exist on type ${schema.type}`);
52
+ return size;
53
+ };
54
+ export const filterRaw = (db, filter, schema, conditions, def) => {
55
+ const [field, operator, value] = filter;
56
+ hasField(field); // Validates if the field is a non-empty string
57
+ checkOperator(operator); // Validates if the operator is valid
58
+ checkValue(value, operator); // Validates the value based on the operator
59
+ let fieldDef = schema.props[field];
60
+ if (!fieldDef) {
61
+ if (field === 'id') {
62
+ fieldDef = ID_FIELD_DEF;
63
+ return primitiveFilter(fieldDef, filter, conditions);
64
+ }
65
+ return referencesFilter(db, filter, schema, conditions, def);
66
+ }
67
+ return primitiveFilter(fieldDef, filter, conditions);
68
+ };
69
+ export const filter = (db, def, filterAst, conditions) => {
70
+ for (const f of filterAst) {
71
+ if (IsFilter(f)) {
72
+ conditions.size += filterRaw(db, f, def.schema, conditions, def);
73
+ }
74
+ else {
75
+ filterOr(db, def, f, conditions);
76
+ }
77
+ }
78
+ };
79
+ export const filterOr = (db, def, filterAst, conditions) => {
80
+ if (!conditions.or) {
81
+ conditions.size += 7; // [0] [next 4]
82
+ conditions.or = {
83
+ size: 0,
84
+ conditions: new Map(),
85
+ };
86
+ }
87
+ filter(db, def, filterAst, conditions.or);
88
+ conditions.size += conditions.or.size;
89
+ return conditions.or;
90
+ };
91
+ function normalizeNeedle(s) {
92
+ return s
93
+ .normalize('NFKD')
94
+ .split('')
95
+ .filter((ch) => ch.charCodeAt(0) <= 127)
96
+ .join('');
97
+ }
98
+ export const convertFilter = (field, operator, value) => {
99
+ if (operator === undefined) {
100
+ operator = '=';
101
+ value = true;
102
+ }
103
+ else if (typeof operator === 'boolean') {
104
+ value = operator;
105
+ operator = '=';
106
+ }
107
+ hasField(field);
108
+ checkOperator(operator);
109
+ checkValue(value, operator);
110
+ if (operator === '!..') {
111
+ return [
112
+ [field, '>', value[1]],
113
+ [field, '<', value[0]],
114
+ ];
115
+ }
116
+ else if (operator === '..') {
117
+ return [
118
+ [field, '>', value[0]],
119
+ [field, '<', value[1]],
120
+ ];
121
+ }
122
+ else {
123
+ if (operator == 'like') {
124
+ if (value.normalize) {
125
+ value = normalizeNeedle(value);
126
+ }
127
+ else {
128
+ value = value.map(normalizeNeedle);
129
+ }
130
+ }
131
+ return [[field, operator, value]];
132
+ }
133
+ };
134
+ //# sourceMappingURL=filter.js.map
@@ -0,0 +1,6 @@
1
+ export declare const validOperators: readonly ["=", "has", "!has", "<", ">", "!=", "like", ">=", "<=", "..", "!..", "hasLoose"];
2
+ export type Operator = '=' | 'has' | '!has' | '<' | '>' | '!=' | 'like' | '>=' | '<=' | '..' | '!..' | 'like' | 'hasLoose';
3
+ export declare const operationToByte: (op: Operator) => number;
4
+ export declare const isNumerical: (op: number) => boolean;
5
+ export declare const stripNegation: (op: number) => number;
6
+ export declare const negateType: (op: number) => number;
@@ -0,0 +1,98 @@
1
+ export const validOperators = [
2
+ '=',
3
+ 'has',
4
+ '!has',
5
+ '<',
6
+ '>',
7
+ '!=',
8
+ 'like',
9
+ '>=',
10
+ '<=',
11
+ '..',
12
+ '!..',
13
+ 'hasLoose',
14
+ ];
15
+ // -------------------------------------------
16
+ // operations shared
17
+ // 1 = equality
18
+ // 2 = has (simd)
19
+ // 3 = not equal
20
+ // 4 = ends with
21
+ // 5 = starts with
22
+ // -------------------------------------------
23
+ // operations numbers
24
+ // 6 = larger then
25
+ // 7 = smaller then
26
+ // 8 = larger then inclusive
27
+ // 9 = smaller then inclusive
28
+ // 10 = range
29
+ // 11 = exclude range
30
+ // -------------------------------------------
31
+ // operations strings
32
+ // 12 = equality to lower case
33
+ // 13 = has to lower case (simd)
34
+ // 14 = starts with to lower case
35
+ // 15 = ends with to lower case
36
+ // 18 = search
37
+ // -------------------------------------------
38
+ export const operationToByte = (op) => {
39
+ if (op === '=') {
40
+ return 1;
41
+ }
42
+ if (op === 'has') {
43
+ return 2;
44
+ }
45
+ if (op === '!=') {
46
+ return 3;
47
+ }
48
+ if (op === '!has') {
49
+ return 16;
50
+ }
51
+ if (op === '>') {
52
+ return 6;
53
+ }
54
+ if (op === '<') {
55
+ return 7;
56
+ }
57
+ if (op === '>=') {
58
+ return 8;
59
+ }
60
+ if (op === '<=') {
61
+ return 9;
62
+ }
63
+ if (op === '..') {
64
+ return 10;
65
+ }
66
+ if (op === '!..') {
67
+ return 11;
68
+ }
69
+ if (op === 'like') {
70
+ return 18;
71
+ }
72
+ if (op === 'hasLoose') {
73
+ return 19;
74
+ }
75
+ return 0;
76
+ };
77
+ export const isNumerical = (op) => {
78
+ if (op === 6 || op === 7 || op === 8 || op === 9 || op === 10 || op === 11) {
79
+ return true;
80
+ }
81
+ return false;
82
+ };
83
+ export const stripNegation = (op) => {
84
+ if (op === 16) {
85
+ return 2;
86
+ }
87
+ if (op === 3) {
88
+ return 1;
89
+ }
90
+ return op;
91
+ };
92
+ export const negateType = (op) => {
93
+ if (op === 3) {
94
+ return 1;
95
+ }
96
+ return 2;
97
+ };
98
+ //# sourceMappingURL=operators.js.map
@@ -0,0 +1,2 @@
1
+ import { PropDef, PropDefEdge } from '../../../server/schema/types.js';
2
+ export declare const parseFilterValue: (prop: PropDef | PropDefEdge, value: any) => any;
@@ -0,0 +1,99 @@
1
+ import { TIMESTAMP, CREATED, UPDATED, ENUM, BOOLEAN, STRING, BINARY, } from '../../../server/schema/types.js';
2
+ import { crc32 } from '../../crc32.js';
3
+ // -------------------------------------------
4
+ // conditions normal
5
+ // field, [size 2]
6
+ // [or = 0] [size 2] [start 2], [op], value[size]
7
+ // -------------------------------------------
8
+ // conditions or fixed
9
+ // field, [size 2]
10
+ // [or = 1] [size 2] [start 2] [op], [repeat 2], value[size] value[size] value[size]
11
+ // -------------------------------------------
12
+ // conditions or variable
13
+ // field, [size 2]
14
+ // [or = 2] [size 2] [start 2], [op], [size 2], value[size], [size 2], value[size]
15
+ // -------------------------------------------
16
+ const timeToNumber = (ex) => {
17
+ if (ex === 's') {
18
+ return 1000;
19
+ }
20
+ if (ex === 'm') {
21
+ return 1000 * 60;
22
+ }
23
+ if (ex === 'h') {
24
+ return 1000 * 60 * 60;
25
+ }
26
+ if (ex === 'd') {
27
+ return 1000 * 60 * 60 * 24;
28
+ }
29
+ if (ex === 'y') {
30
+ return 31556952000;
31
+ }
32
+ return 1;
33
+ };
34
+ export const parseFilterValue = (prop, value) => {
35
+ if (prop.typeIndex === BINARY || prop.typeIndex === STRING) {
36
+ const b = value instanceof Buffer ? value : Buffer.from(value);
37
+ const buf = Buffer.allocUnsafe(8);
38
+ buf.writeUint32LE(crc32(b), 0);
39
+ buf.writeUint32LE(b.byteLength, 4);
40
+ return buf;
41
+ }
42
+ else if (prop.typeIndex === BOOLEAN) {
43
+ return value ? 1 : 0;
44
+ }
45
+ else if (prop.typeIndex === ENUM) {
46
+ return prop.reverseEnum[value] + 1;
47
+ }
48
+ else if (prop.typeIndex === TIMESTAMP ||
49
+ prop.typeIndex === CREATED ||
50
+ prop.typeIndex === UPDATED) {
51
+ if (value instanceof Date) {
52
+ return value.valueOf();
53
+ }
54
+ if (typeof value === 'string') {
55
+ if (value === 'now') {
56
+ return Date.now();
57
+ }
58
+ const y = value.replace(/([+-])/g, ' $1 ');
59
+ const arr = y.split(/ +/);
60
+ let newValue = 0;
61
+ let now;
62
+ let op = 1;
63
+ for (const seg of arr) {
64
+ if (seg === '-') {
65
+ op = -1;
66
+ }
67
+ else if (seg === '+') {
68
+ op = 1;
69
+ }
70
+ else {
71
+ var v = 0;
72
+ if (seg === 'now') {
73
+ if (!now) {
74
+ now = Date.now();
75
+ }
76
+ v = now;
77
+ }
78
+ else if (/[smhdy]$/.test(seg)) {
79
+ const ex = seg[seg.length - 1];
80
+ const number = parseInt(seg, 10);
81
+ v = number * timeToNumber(ex);
82
+ }
83
+ else if (seg) {
84
+ v = new Date(seg).valueOf();
85
+ }
86
+ if (op === -1) {
87
+ newValue -= v;
88
+ }
89
+ else {
90
+ newValue += v;
91
+ }
92
+ }
93
+ }
94
+ return newValue;
95
+ }
96
+ }
97
+ return value;
98
+ };
99
+ //# sourceMappingURL=parseFilterValue.js.map
@@ -0,0 +1,4 @@
1
+ import { PropDef, PropDefEdge } from '../../../server/schema/types.js';
2
+ import { QueryDefFilter } from '../types.js';
3
+ import { Filter } from './types.js';
4
+ export declare const primitiveFilter: (prop: PropDef | PropDefEdge, filter: Filter, conditions: QueryDefFilter) => number;
@@ -0,0 +1,47 @@
1
+ import { REFERENCE, REFERENCES, REVERSE_SIZE_MAP, } from '../../../server/schema/types.js';
2
+ import { isNumerical, operationToByte } from './operators.js';
3
+ import { createVariableFilterBuffer } from './createVariableFilterBuffer.js';
4
+ import { createFixedFilterBuffer } from './createFixedFilterBuffer.js';
5
+ import { createReferenceFilter } from './createReferenceFilter.js';
6
+ import { checkOperator, checkValue } from '../validation.js';
7
+ export const primitiveFilter = (prop, filter, conditions) => {
8
+ let [, operator, value] = filter;
9
+ checkOperator(operator);
10
+ checkValue(value, operator);
11
+ const fieldIndexChar = prop.prop;
12
+ let buf;
13
+ const op = operationToByte(operator);
14
+ let size = 0;
15
+ const bufferMap = prop.__isEdge ? conditions.edges : conditions.conditions;
16
+ const isArray = Array.isArray(value);
17
+ if (isArray && value.length === 1) {
18
+ value = value[0];
19
+ }
20
+ const propSize = REVERSE_SIZE_MAP[prop.typeIndex];
21
+ if (prop.typeIndex === REFERENCE) {
22
+ buf = createReferenceFilter(prop, op, value);
23
+ }
24
+ else if (prop.typeIndex === REFERENCES) {
25
+ if (op === 1 && !isArray) {
26
+ value = [value];
27
+ }
28
+ buf = createFixedFilterBuffer(prop, 4, op, value, !isNumerical(op));
29
+ }
30
+ else if (propSize) {
31
+ buf = createFixedFilterBuffer(prop, propSize, op, value, false);
32
+ }
33
+ else {
34
+ buf = createVariableFilterBuffer(value, prop, op);
35
+ }
36
+ // ADD OR if array for value
37
+ let arr = bufferMap.get(fieldIndexChar);
38
+ if (!arr) {
39
+ size += 3; // [field] [size 2]
40
+ arr = [];
41
+ bufferMap.set(fieldIndexChar, arr);
42
+ }
43
+ size += buf.byteLength;
44
+ arr.push(buf);
45
+ return size;
46
+ };
47
+ //# sourceMappingURL=primitiveFilter.js.map
@@ -0,0 +1,3 @@
1
+ import { QueryDefFilter } from '../types.js';
2
+ export declare const fillConditionsBuffer: (result: Buffer, conditions: QueryDefFilter, offset: number) => number;
3
+ export declare const filterToBuffer: (conditions: QueryDefFilter) => Buffer;
@@ -0,0 +1,100 @@
1
+ // -------------------------------------------
2
+ // and
3
+ // [meta = 255] [size 2]
4
+ // -------------------------------------------
5
+ // or
6
+ // [meta = 253] [size 2] [next 4]
7
+ // -------------------------------------------
8
+ // edge
9
+ // [meta = 252] [size 2]
10
+ // -------------------------------------------
11
+ // ref
12
+ // [meta = 254] [field] [typeId 2] [size 2]
13
+ // -------------------------------------------
14
+ // conditions normal
15
+ // field, [size 2]
16
+ // [or = 0] [size 2] [start 2], [op] [typeIndex], value[size]
17
+ // -------------------------------------------
18
+ // conditions or fixed
19
+ // field, [size 2]
20
+ // [or = 1] [size 2] [start 2] [op] [typeIndex], [repeat 2], value[size] value[size] value[size]
21
+ // -------------------------------------------
22
+ // conditions or variable
23
+ // field, [size 2]
24
+ // [or = 2] [size 2] [start 2], [op] [typeIndex], [size 2], value[size], [size 2], value[size]
25
+ // -------------------------------------------
26
+ const writeConditions = (result, k, offset, conditions) => {
27
+ let lastWritten = offset;
28
+ result[lastWritten] = k;
29
+ lastWritten++;
30
+ const sizeIndex = lastWritten;
31
+ lastWritten += 2;
32
+ let conditionSize = 0;
33
+ for (const condition of conditions) {
34
+ conditionSize += condition.byteLength;
35
+ result.set(condition, lastWritten);
36
+ lastWritten += condition.byteLength;
37
+ }
38
+ // make this u32
39
+ result.writeUint16LE(conditionSize, sizeIndex);
40
+ return lastWritten - offset;
41
+ };
42
+ export const fillConditionsBuffer = (result, conditions, offset) => {
43
+ let lastWritten = offset;
44
+ let orJumpIndex = 0;
45
+ if (conditions.or) {
46
+ result[lastWritten] = 253;
47
+ lastWritten++;
48
+ orJumpIndex = lastWritten;
49
+ lastWritten += 2;
50
+ lastWritten += 4;
51
+ }
52
+ conditions.conditions.forEach((v, k) => {
53
+ lastWritten += writeConditions(result, k, lastWritten, v);
54
+ });
55
+ if (conditions.references) {
56
+ for (const [refField, refConditions] of conditions.references) {
57
+ result[lastWritten] = 254;
58
+ lastWritten++;
59
+ result[lastWritten] = refField;
60
+ lastWritten++;
61
+ result.writeUint16LE(refConditions.schema.id, lastWritten);
62
+ lastWritten += 2;
63
+ const sizeIndex = lastWritten;
64
+ lastWritten += 2;
65
+ const size = fillConditionsBuffer(result, refConditions, lastWritten);
66
+ result.writeUint16LE(size, sizeIndex);
67
+ lastWritten += size;
68
+ }
69
+ }
70
+ if (conditions.edges) {
71
+ conditions.edges.forEach((v, k) => {
72
+ result[lastWritten] = 252;
73
+ lastWritten++;
74
+ let sizeIndex = lastWritten;
75
+ lastWritten += 2;
76
+ const size = writeConditions(result, k, lastWritten, v);
77
+ lastWritten += size;
78
+ result.writeUint16LE(size, sizeIndex);
79
+ });
80
+ }
81
+ if (conditions.or) {
82
+ const size = fillConditionsBuffer(result, conditions.or, lastWritten);
83
+ result.writeUint16LE(size, orJumpIndex);
84
+ result.writeUint32LE(lastWritten, orJumpIndex + 2);
85
+ lastWritten += size;
86
+ }
87
+ return lastWritten - offset;
88
+ };
89
+ export const filterToBuffer = (conditions) => {
90
+ let result;
91
+ if (conditions.size > 0) {
92
+ result = Buffer.allocUnsafe(conditions.size);
93
+ fillConditionsBuffer(result, conditions, 0);
94
+ }
95
+ else {
96
+ result = Buffer.alloc(0);
97
+ }
98
+ return result;
99
+ };
100
+ //# sourceMappingURL=toBuffer.js.map
@@ -0,0 +1,6 @@
1
+ import { Operator } from './operators.js';
2
+ import { FilterBranch } from './FilterBranch.js';
3
+ export type Filter = [fieldStr: string, operator: Operator, value: any];
4
+ export type FilterBranchFn = (filterBranch: FilterBranch) => void;
5
+ export type FilterAst = (Filter | FilterAst)[];
6
+ export declare const IsFilter: (f: FilterAst) => f is Filter;
@@ -0,0 +1,7 @@
1
+ export const IsFilter = (f) => {
2
+ if (typeof f[0] === 'string') {
3
+ return true;
4
+ }
5
+ return false;
6
+ };
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,6 @@
1
+ import { PropDef, PropDefEdge } from '../../../server/schema/types.js';
2
+ import { QueryDef } from '../types.js';
3
+ export declare const getAll: (props: QueryDef["props"]) => string[];
4
+ export declare const includeFields: (def: QueryDef, fields: string[]) => void;
5
+ export declare const includeAllProps: (def: QueryDef) => void;
6
+ export declare const includeProp: (def: QueryDef, prop: PropDef | PropDefEdge) => boolean;
@@ -0,0 +1,44 @@
1
+ import { REFERENCE, REFERENCES, } from '../../../server/schema/types.js';
2
+ export const getAll = (props) => {
3
+ const fields = [];
4
+ for (const key in props) {
5
+ const prop = props[key];
6
+ if (prop.typeIndex !== REFERENCE && prop.typeIndex !== REFERENCES) {
7
+ fields.push(prop.path.join('.'));
8
+ }
9
+ }
10
+ return fields;
11
+ };
12
+ export const includeFields = (def, fields) => {
13
+ for (const field of fields) {
14
+ if (field === '*') {
15
+ includeFields(def, getAll(def.props));
16
+ }
17
+ else {
18
+ def.include.stringFields.add(field);
19
+ }
20
+ }
21
+ };
22
+ export const includeAllProps = (def) => {
23
+ for (const key in def.props) {
24
+ const prop = def.props[key];
25
+ if (prop.typeIndex !== REFERENCE && prop.typeIndex !== REFERENCES) {
26
+ includeProp(def, prop);
27
+ }
28
+ }
29
+ };
30
+ export const includeProp = (def, prop) => {
31
+ if (!prop || prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES) {
32
+ return false;
33
+ }
34
+ if (prop.separate) {
35
+ def.include.props.add(prop.prop);
36
+ }
37
+ else {
38
+ def.include.main.len += prop.len;
39
+ def.include.main.include[prop.start] = [0, prop];
40
+ return true;
41
+ }
42
+ return false;
43
+ };
44
+ //# sourceMappingURL=props.js.map
@@ -0,0 +1,3 @@
1
+ import { DbClient } from '../../index.js';
2
+ import { QueryDef } from '../types.js';
3
+ export declare const includeToBuffer: (db: DbClient, def: QueryDef) => Buffer[];
@@ -0,0 +1,82 @@
1
+ import { walkDefs } from './walk.js';
2
+ const EMPTY_BUFFER = Buffer.alloc(0);
3
+ export const includeToBuffer = (db, def) => {
4
+ const result = [];
5
+ if (!def.include.stringFields.size &&
6
+ !def.include.props.size &&
7
+ !def.references.size &&
8
+ !def.include.main.len) {
9
+ return result;
10
+ }
11
+ let mainBuffer;
12
+ let len = 0;
13
+ let includeBuffer;
14
+ if (def.include.stringFields) {
15
+ for (const f of def.include.stringFields) {
16
+ walkDefs(db, def, f);
17
+ }
18
+ }
19
+ if (def.include.main.len > 0) {
20
+ if (def.include.main.len === def.schema.mainLen) {
21
+ // GET ALL MAIN FIELDS
22
+ let m = 0;
23
+ for (const key in def.include.main.include) {
24
+ const v = def.include.main.include[key];
25
+ const len = v[1].len;
26
+ v[0] = m;
27
+ m += len;
28
+ }
29
+ mainBuffer = EMPTY_BUFFER;
30
+ }
31
+ else {
32
+ // GET SOME MAIN FIELDS
33
+ const size = Object.keys(def.include.main.include).length;
34
+ mainBuffer = Buffer.allocUnsafe(size * 4 + 2);
35
+ mainBuffer.writeUint16LE(def.include.main.len, 0);
36
+ let i = 2;
37
+ let m = 0;
38
+ for (const key in def.include.main.include) {
39
+ const v = def.include.main.include[key];
40
+ mainBuffer.writeUint16LE(v[1].start, i);
41
+ const len = v[1].len;
42
+ v[0] = m;
43
+ mainBuffer.writeUint16LE(len, i + 2);
44
+ i += 4;
45
+ m += len;
46
+ }
47
+ }
48
+ }
49
+ const propSize = def.include.props.size ?? 0;
50
+ if (mainBuffer) {
51
+ len = mainBuffer.byteLength + 3 + propSize;
52
+ includeBuffer = Buffer.allocUnsafe(len);
53
+ includeBuffer[0] = 0;
54
+ includeBuffer.writeInt16LE(mainBuffer.byteLength, 1);
55
+ const offset = 3 + mainBuffer.byteLength;
56
+ mainBuffer.copy(includeBuffer, 3);
57
+ if (propSize) {
58
+ let i = 0;
59
+ for (const prop of def.include.props) {
60
+ includeBuffer[i + offset] = prop;
61
+ i++;
62
+ }
63
+ }
64
+ }
65
+ else if (propSize) {
66
+ const buf = Buffer.allocUnsafe(propSize);
67
+ let i = 0;
68
+ for (const prop of def.include.props) {
69
+ buf[i] = prop;
70
+ i++;
71
+ }
72
+ includeBuffer = buf;
73
+ }
74
+ if (includeBuffer) {
75
+ def.include.props.forEach((v) => {
76
+ def.include.propsRead[v] = 0;
77
+ });
78
+ result.push(includeBuffer);
79
+ }
80
+ return result;
81
+ };
82
+ //# sourceMappingURL=toBuffer.js.map
@@ -0,0 +1,6 @@
1
+ import { PropDef, PropDefEdge, SchemaPropTree } from '../../../server/schema/types.js';
2
+ import { DbClient } from '../../index.js';
3
+ import { QueryDef } from '../types.js';
4
+ export declare const getAllFieldFromObject: (tree: SchemaPropTree | PropDef, arr?: string[]) => string[];
5
+ export declare const createOrGetRefQueryDef: (db: DbClient, def: QueryDef, t: PropDef | PropDefEdge) => QueryDef;
6
+ export declare const createOrGetEdgeRefQueryDef: (db: DbClient, def: QueryDef, t: PropDefEdge) => QueryDef;