@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,61 @@
1
+ import { UPDATE, RANGE_ERR, DELETE } from './types.js';
2
+ import { ModifyError } from './ModifyRes.js';
3
+ import { setCursor } from './setCursor.js';
4
+ import native from '../../native.js';
5
+ export function getBuffer(value) {
6
+ if (typeof value === 'object') {
7
+ if (value instanceof Buffer) {
8
+ return value;
9
+ }
10
+ if (value.buffer instanceof ArrayBuffer) {
11
+ return Buffer.from(value.buffer);
12
+ }
13
+ }
14
+ }
15
+ export function writeBinaryRaw(value, ctx) {
16
+ let size = value.byteLength + 6;
17
+ let crc = native.crc32(value);
18
+ ctx.buf[ctx.len++] = size;
19
+ ctx.buf[ctx.len++] = size >>>= 8;
20
+ ctx.buf[ctx.len++] = size >>>= 8;
21
+ ctx.buf[ctx.len++] = size >>>= 8;
22
+ ctx.buf[ctx.len++] = 0;
23
+ ctx.buf[ctx.len++] = 0;
24
+ ctx.buf.set(value, ctx.len);
25
+ ctx.len += value.byteLength;
26
+ ctx.buf[ctx.len++] = crc;
27
+ ctx.buf[ctx.len++] = crc >>>= 8;
28
+ ctx.buf[ctx.len++] = crc >>>= 8;
29
+ ctx.buf[ctx.len++] = crc >>>= 8;
30
+ }
31
+ export function writeBinary(value, ctx, schema, t, parentId, modifyOp) {
32
+ let size;
33
+ if (value === null) {
34
+ size = 0;
35
+ }
36
+ else {
37
+ value = getBuffer(value);
38
+ if (!value) {
39
+ return new ModifyError(t, value);
40
+ }
41
+ size = value.byteLength + 6;
42
+ }
43
+ if (size === 0) {
44
+ if (modifyOp === UPDATE) {
45
+ if (ctx.len + 11 > ctx.max) {
46
+ return RANGE_ERR;
47
+ }
48
+ setCursor(ctx, schema, t.prop, parentId, modifyOp);
49
+ ctx.buf[ctx.len++] = DELETE;
50
+ }
51
+ }
52
+ else {
53
+ if (ctx.len + 15 + size > ctx.max) {
54
+ return RANGE_ERR;
55
+ }
56
+ setCursor(ctx, schema, t.prop, parentId, modifyOp);
57
+ ctx.buf[ctx.len++] = modifyOp;
58
+ writeBinaryRaw(value, ctx);
59
+ }
60
+ }
61
+ //# sourceMappingURL=binary.js.map
@@ -0,0 +1,4 @@
1
+ import { ModifyRes } from './ModifyRes.js';
2
+ import { DbClient } from '../index.js';
3
+ export type CreateObj = Record<string, any>;
4
+ export declare function create(db: DbClient, type: string, obj: CreateObj, unsafe?: boolean): ModifyRes;
@@ -0,0 +1,108 @@
1
+ import { startDrain, flushBuffer } from '../operations.js';
2
+ import { setCursor } from './setCursor.js';
3
+ import { modify } from './modify.js';
4
+ import { ModifyState } from './ModifyRes.js';
5
+ import { CREATE, RANGE_ERR } from './types.js';
6
+ import { writeFixedValue } from './fixed.js';
7
+ import { getSubscriptionMarkers } from '../query/subscription/index.js';
8
+ const appendCreate = (ctx, def, obj, res, unsafe) => {
9
+ const len = ctx.len;
10
+ let err = modify(ctx, res, obj, def, CREATE, def.tree, true, unsafe);
11
+ if (err) {
12
+ return err;
13
+ }
14
+ if (ctx.len === len || def.mainLen === 0) {
15
+ if (ctx.len + 10 > ctx.max) {
16
+ return RANGE_ERR;
17
+ }
18
+ setCursor(ctx, def, 0, res.tmpId, CREATE);
19
+ }
20
+ if (def.createTs) {
21
+ const createTs = Date.now();
22
+ for (const prop of def.createTs) {
23
+ if (ctx.lastMain === -1) {
24
+ let mainLenU32 = def.mainLen;
25
+ setCursor(ctx, def, prop.prop, res.tmpId, CREATE);
26
+ ctx.buf[ctx.len++] = CREATE;
27
+ ctx.buf[ctx.len++] = mainLenU32;
28
+ ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
29
+ ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
30
+ ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
31
+ ctx.lastMain = ctx.len;
32
+ ctx.buf.fill(0, ctx.len, (ctx.len += def.mainLen));
33
+ }
34
+ err = writeFixedValue(ctx, createTs, prop, ctx.lastMain + prop.start);
35
+ if (err) {
36
+ return err;
37
+ }
38
+ }
39
+ }
40
+ // if touched lets see perf impact here
41
+ if (def.hasStringProp) {
42
+ if (ctx.hasStringField !== def.stringPropsSize - 1) {
43
+ if (ctx.len + 3 > ctx.max) {
44
+ return RANGE_ERR;
45
+ }
46
+ ctx.buf[ctx.len++] = 7;
47
+ let sizepos = ctx.len;
48
+ ctx.len += 2;
49
+ for (const { prop } of def.stringPropsLoop) {
50
+ if (def.stringPropsCurrent[prop] === 1) {
51
+ if (ctx.len + 1 > ctx.max) {
52
+ return RANGE_ERR;
53
+ }
54
+ ctx.buf[ctx.len++] = prop;
55
+ }
56
+ }
57
+ let size = ctx.len - sizepos - 2;
58
+ ctx.buf[sizepos++] = size;
59
+ ctx.buf[sizepos] = size >>>= 8;
60
+ }
61
+ if (ctx.hasStringField !== -1) {
62
+ def.stringProps.copy(def.stringPropsCurrent);
63
+ }
64
+ }
65
+ };
66
+ export function create(db, type, obj, unsafe) {
67
+ const def = db.schemaTypesParsed[type];
68
+ let id;
69
+ if ('id' in obj) {
70
+ if (unsafe) {
71
+ id = obj.id;
72
+ }
73
+ else {
74
+ throw Error('create with "id" is not allowed');
75
+ }
76
+ }
77
+ else {
78
+ id = def.lastId + 1;
79
+ }
80
+ const ctx = db.modifyCtx;
81
+ const res = new ModifyState(def.id, id, db, getSubscriptionMarkers(db, def.id, id, true));
82
+ const pos = ctx.len;
83
+ const err = appendCreate(ctx, def, obj, res, unsafe);
84
+ if (err) {
85
+ ctx.prefix0 = -1; // force a new cursor
86
+ ctx.len = pos;
87
+ if (err === RANGE_ERR) {
88
+ if (pos === 0) {
89
+ throw new Error('out of range');
90
+ }
91
+ flushBuffer(db);
92
+ return db.create(type, obj, unsafe);
93
+ }
94
+ res.error = err;
95
+ // @ts-ignore
96
+ return res;
97
+ }
98
+ if (!db.isDraining) {
99
+ startDrain(db);
100
+ }
101
+ if (id > def.lastId) {
102
+ def.lastId = id;
103
+ def.total++;
104
+ }
105
+ // @ts-ignore
106
+ return res;
107
+ }
108
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1,5 @@
1
+ import { ModifyCtx } from '../../index.js';
2
+ import { PropDef, PropDefEdge } from '../../server/schema/types.js';
3
+ import { ModifyErr } from './types.js';
4
+ export declare const writeFixedValue: (ctx: ModifyCtx, val: any, def: PropDef | PropDefEdge, pos: number) => ModifyErr;
5
+ export declare const appendFixedValue: (ctx: ModifyCtx, val: any, def: PropDef | PropDefEdge) => ModifyErr;
@@ -0,0 +1,118 @@
1
+ import { BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, UINT16, UINT32, UINT8, } from '../../server/schema/types.js';
2
+ import { getBuffer } from './binary.js';
3
+ import { ModifyError } from './ModifyRes.js';
4
+ import { RANGE_ERR } from './types.js';
5
+ const map = {};
6
+ map[BINARY] = (ctx, val, def) => {
7
+ const buf = getBuffer(val);
8
+ if (buf === undefined) {
9
+ return new ModifyError(def, val);
10
+ }
11
+ const size = buf.byteLength;
12
+ if (ctx.len + size + 1 > ctx.max) {
13
+ return RANGE_ERR;
14
+ }
15
+ ctx.buf[ctx.len++] = size;
16
+ ctx.buf.set(buf, ctx.len);
17
+ ctx.len += buf.byteLength;
18
+ };
19
+ map[STRING] = (ctx, val, def) => {
20
+ if (typeof val !== 'string') {
21
+ if (val !== null) {
22
+ return new ModifyError(def, val);
23
+ }
24
+ val = '';
25
+ }
26
+ const size = Buffer.byteLength(val, 'utf8');
27
+ if (size + 1 > def.len) {
28
+ return new ModifyError(def, val, `max length of ${def.len - 1},`);
29
+ }
30
+ if (ctx.len + size + 1 > ctx.max) {
31
+ return RANGE_ERR;
32
+ }
33
+ ctx.buf[ctx.len++] = size;
34
+ ctx.len += ctx.buf.write(val, ctx.len, 'utf8');
35
+ };
36
+ map[BOOLEAN] = (ctx, val, def) => {
37
+ if (ctx.len + 1 > ctx.max) {
38
+ return RANGE_ERR;
39
+ }
40
+ if (val === null) {
41
+ ctx.buf[ctx.len++] = 0;
42
+ }
43
+ else if (typeof val === 'boolean') {
44
+ ctx.buf[ctx.len++] = val ? 1 : 0;
45
+ }
46
+ else {
47
+ return new ModifyError(def, val);
48
+ }
49
+ };
50
+ map[ENUM] = (ctx, val, def) => {
51
+ if (ctx.len + 1 > ctx.max) {
52
+ return RANGE_ERR;
53
+ }
54
+ if (val === null) {
55
+ ctx.buf[ctx.len++] = 1;
56
+ }
57
+ else if (val in def.reverseEnum) {
58
+ ctx.buf[ctx.len++] = def.reverseEnum[val] + 1;
59
+ }
60
+ else {
61
+ return new ModifyError(def, val);
62
+ }
63
+ };
64
+ map[NUMBER] = (ctx, val, def) => {
65
+ if (typeof val !== 'number') {
66
+ return new ModifyError(def, val);
67
+ }
68
+ if (ctx.len + 8 > ctx.max) {
69
+ return RANGE_ERR;
70
+ }
71
+ ctx.len = ctx.buf.writeDoubleLE(val, ctx.len);
72
+ };
73
+ map[UINT32] = (ctx, val, def) => {
74
+ if (typeof val !== 'number') {
75
+ return new ModifyError(def, val);
76
+ }
77
+ if (ctx.len + 4 > ctx.max) {
78
+ return RANGE_ERR;
79
+ }
80
+ ctx.buf[ctx.len++] = val;
81
+ ctx.buf[ctx.len++] = val >>>= 8;
82
+ ctx.buf[ctx.len++] = val >>>= 8;
83
+ ctx.buf[ctx.len++] = val >>>= 8;
84
+ };
85
+ map[UINT16] = (ctx, val, def) => {
86
+ if (typeof val !== 'number') {
87
+ return new ModifyError(def, val);
88
+ }
89
+ if (ctx.len + 2 > ctx.max) {
90
+ return RANGE_ERR;
91
+ }
92
+ ctx.buf[ctx.len++] = val;
93
+ ctx.buf[ctx.len++] = val >>>= 8;
94
+ };
95
+ map[UINT8] = (ctx, val, def) => {
96
+ if (typeof val !== 'number') {
97
+ return new ModifyError(def, val);
98
+ }
99
+ if (ctx.len + 1 > ctx.max) {
100
+ return RANGE_ERR;
101
+ }
102
+ ctx.buf[ctx.len++] = val;
103
+ };
104
+ map[TIMESTAMP] = map[NUMBER];
105
+ map[INT32] = map[UINT32];
106
+ map[INT16] = map[UINT16];
107
+ map[INT8] = map[UINT8];
108
+ export const writeFixedValue = (ctx, val, def, pos) => {
109
+ const len = ctx.len;
110
+ ctx.len = pos;
111
+ const res = map[def.typeIndex](ctx, val, def);
112
+ ctx.len = len;
113
+ return res;
114
+ };
115
+ export const appendFixedValue = (ctx, val, def) => {
116
+ return map[def.typeIndex](ctx, val, def);
117
+ };
118
+ //# sourceMappingURL=fixed.js.map
@@ -0,0 +1,4 @@
1
+ import { ModifyCtx } from '../../index.js';
2
+ import { SchemaTypeDef, PropDef } from '../../server/schema/types.js';
3
+ import { ModifyOp, ModifyErr } from './types.js';
4
+ export declare function writeHll(value: string | null | Buffer, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
@@ -0,0 +1,58 @@
1
+ import { UPDATE, RANGE_ERR, DELETE } from './types.js';
2
+ import { ModifyError } from './ModifyRes.js';
3
+ import { setCursor } from './setCursor.js';
4
+ import { crc32 } from '../crc32.js';
5
+ export function writeHll(value, ctx, def, t, parentId, modifyOp) {
6
+ if (typeof value !== 'object') {
7
+ return new ModifyError(t, value);
8
+ }
9
+ if (value === null) {
10
+ if (modifyOp === UPDATE) {
11
+ if (ctx.len + 11 > ctx.max) {
12
+ return RANGE_ERR;
13
+ }
14
+ setCursor(ctx, def, t.prop, parentId, modifyOp);
15
+ ctx.buf[ctx.len++] = DELETE;
16
+ }
17
+ }
18
+ else if (Array.isArray(value)) {
19
+ return addHll(value, ctx, def, t, parentId, modifyOp, 0);
20
+ }
21
+ else {
22
+ for (const key in value) {
23
+ if (key === 'add') {
24
+ const err = addHll(value, ctx, def, t, parentId, modifyOp, 1);
25
+ if (err) {
26
+ return err;
27
+ }
28
+ }
29
+ else {
30
+ return new ModifyError(t, value);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ function addHll(value, ctx, def, t, parentId, modifyOp, addOrPut) {
36
+ let size = value.length * 4 + 1;
37
+ if (ctx.len + size + 11 > ctx.max) {
38
+ return RANGE_ERR;
39
+ }
40
+ setCursor(ctx, def, t.prop, parentId, modifyOp);
41
+ ctx.buf[ctx.len++] = modifyOp;
42
+ ctx.buf[ctx.len++] = size;
43
+ ctx.buf[ctx.len++] = size >>>= 8;
44
+ ctx.buf[ctx.len++] = size >>>= 8;
45
+ ctx.buf[ctx.len++] = size >>>= 8;
46
+ ctx.buf[ctx.len++] = addOrPut;
47
+ for (const str of value) {
48
+ if (typeof str !== 'string') {
49
+ return new ModifyError(t, value);
50
+ }
51
+ let hash = crc32(Buffer.from(str));
52
+ ctx.buf[ctx.len++] = hash;
53
+ ctx.buf[ctx.len++] = hash >>>= 8;
54
+ ctx.buf[ctx.len++] = hash >>>= 8;
55
+ ctx.buf[ctx.len++] = hash >>>= 8;
56
+ }
57
+ }
58
+ //# sourceMappingURL=hll.js.map
@@ -0,0 +1,4 @@
1
+ export { ModifyRes } from './ModifyRes.js';
2
+ export { create } from './create.js';
3
+ export { update } from './update.js';
4
+ export { remove } from './remove.js';
@@ -0,0 +1,4 @@
1
+ export { create } from './create.js';
2
+ export { update } from './update.js';
3
+ export { remove } from './remove.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ import { ModifyCtx } from '../../index.js';
2
+ import { SchemaTypeDef } from '../../server/schema/types.js';
3
+ import { ModifyState } from './ModifyRes.js';
4
+ import { ModifyErr, ModifyOp } from './types.js';
5
+ export declare function modify(ctx: ModifyCtx, res: ModifyState, obj: Record<string, any>, schema: SchemaTypeDef, mod: ModifyOp, tree: SchemaTypeDef['tree'], overwrite: boolean, unsafe?: boolean): ModifyErr;
@@ -0,0 +1,126 @@
1
+ import { isPropDef, REFERENCE, REFERENCES, STRING, TEXT, ALIAS, BINARY, HLL, } from '../../server/schema/types.js';
2
+ import { ModifyError } from './ModifyRes.js';
3
+ import { writeReference } from './references/reference.js';
4
+ import { writeReferences } from './references/references.js';
5
+ import { writeString } from './string.js';
6
+ import { writeText } from './text.js';
7
+ import { DECREMENT, INCREMENT, RANGE_ERR, } from './types.js';
8
+ import { writeBinary } from './binary.js';
9
+ import { setCursor } from './setCursor.js';
10
+ import { appendFixedValue, writeFixedValue } from './fixed.js';
11
+ import { writeAlias } from './alias.js';
12
+ import { writeHll } from './hll.js';
13
+ import { checkSubscriptionMarkers } from '../query/subscription/index.js';
14
+ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
15
+ for (const key in obj) {
16
+ const def = tree[key];
17
+ if (def === undefined) {
18
+ if (unsafe) {
19
+ continue;
20
+ }
21
+ return new ModifyError(tree, key);
22
+ }
23
+ let err;
24
+ if (isPropDef(def)) {
25
+ if (res.subMarkers) {
26
+ checkSubscriptionMarkers(ctx.db, res.subMarkers, def);
27
+ }
28
+ const val = obj[key];
29
+ const type = def.typeIndex;
30
+ if (def.separate) {
31
+ if (type === STRING) {
32
+ err = writeString(0, val, ctx, schema, def, res.tmpId, mod);
33
+ }
34
+ else if (type === TEXT) {
35
+ err = writeText(val, ctx, schema, def, res.tmpId, mod);
36
+ }
37
+ else if (type === REFERENCE) {
38
+ err = writeReference(val, ctx, schema, def, res, mod);
39
+ }
40
+ else if (type === REFERENCES) {
41
+ err = writeReferences(val, ctx, schema, def, res, mod);
42
+ }
43
+ else if (type === BINARY) {
44
+ err = writeBinary(val, ctx, schema, def, res.tmpId, mod);
45
+ }
46
+ else if (type === ALIAS) {
47
+ err = writeAlias(val, ctx, schema, def, res.tmpId, mod);
48
+ }
49
+ else if (type === HLL) {
50
+ err = writeHll(val, ctx, schema, def, res.tmpId, mod);
51
+ }
52
+ }
53
+ else if (overwrite) {
54
+ if (ctx.len + 15 + schema.mainLen > ctx.max) {
55
+ return RANGE_ERR;
56
+ }
57
+ setCursor(ctx, schema, def.prop, res.tmpId, mod, true);
58
+ if (ctx.lastMain === -1) {
59
+ let mainLenU32 = schema.mainLen;
60
+ setCursor(ctx, schema, def.prop, res.tmpId, mod);
61
+ ctx.buf[ctx.len++] = mod;
62
+ ctx.buf[ctx.len++] = mainLenU32;
63
+ ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
64
+ ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
65
+ ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
66
+ ctx.lastMain = ctx.len;
67
+ ctx.buf.fill(0, ctx.len, (ctx.len += schema.mainLen));
68
+ }
69
+ if (typeof val === 'object' && val !== null && 'increment' in val) {
70
+ err = writeFixedValue(ctx, val.increment, def, ctx.lastMain + def.start);
71
+ }
72
+ else {
73
+ err = writeFixedValue(ctx, val, def, ctx.lastMain + def.start);
74
+ }
75
+ }
76
+ else if (typeof val === 'object') {
77
+ if (val !== null && 'increment' in val) {
78
+ let increment = val.increment;
79
+ if (increment === 0) {
80
+ continue;
81
+ }
82
+ if (ctx.len + 10 > ctx.max) {
83
+ return RANGE_ERR;
84
+ }
85
+ setCursor(ctx, schema, def.prop, res.tmpId, mod);
86
+ let start = def.start;
87
+ if (increment < 0) {
88
+ ctx.buf[ctx.len++] = DECREMENT;
89
+ increment = -increment;
90
+ }
91
+ else {
92
+ ctx.buf[ctx.len++] = INCREMENT;
93
+ }
94
+ ctx.buf[ctx.len++] = def.typeIndex;
95
+ ctx.buf[ctx.len++] = start;
96
+ ctx.buf[ctx.len++] = start >>>= 8;
97
+ appendFixedValue(ctx, increment, def);
98
+ }
99
+ else {
100
+ return new ModifyError(def, val);
101
+ }
102
+ }
103
+ else if (ctx.mergeMain) {
104
+ ctx.mergeMain.push(def, val);
105
+ ctx.mergeMainSize += def.len + 4;
106
+ }
107
+ else {
108
+ ctx.mergeMain = [def, val];
109
+ ctx.mergeMainSize = def.len + 4;
110
+ }
111
+ }
112
+ else {
113
+ err = _modify(ctx, res, obj[key], schema, mod, def, overwrite, unsafe);
114
+ }
115
+ if (err) {
116
+ if (unsafe && err !== RANGE_ERR) {
117
+ continue;
118
+ }
119
+ return err;
120
+ }
121
+ }
122
+ }
123
+ export function modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe = false) {
124
+ return _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe);
125
+ }
126
+ //# sourceMappingURL=modify.js.map
@@ -0,0 +1,6 @@
1
+ import { ModifyCtx } from '../../../index.js';
2
+ import { PropDef } from '../../../server/schema/types.js';
3
+ import { ModifyErr } from '../types.js';
4
+ import { RefModifyOpts } from './references.js';
5
+ export declare function getEdgeSize(t: PropDef, ref: RefModifyOpts): number;
6
+ export declare function writeEdges(t: PropDef, ref: RefModifyOpts, ctx: ModifyCtx): ModifyErr;
@@ -0,0 +1,158 @@
1
+ import { BINARY, REFERENCE, REFERENCES, STRING, } from '../../../server/schema/types.js';
2
+ import { write } from '../../string.js';
3
+ import { getBuffer, writeBinaryRaw } from '../binary.js';
4
+ import { ModifyError, ModifyState } from '../ModifyRes.js';
5
+ import { RANGE_ERR } from '../types.js';
6
+ import { appendFixedValue } from '../fixed.js';
7
+ export function getEdgeSize(t, ref) {
8
+ let size = 0;
9
+ for (const key in t.edges) {
10
+ if (key in ref) {
11
+ const edge = t.edges[key];
12
+ const value = ref[key];
13
+ if (edge.len === 0) {
14
+ if (edge.typeIndex === STRING) {
15
+ size += Buffer.byteLength(value) + 4;
16
+ }
17
+ else if (edge.typeIndex === REFERENCE) {
18
+ size += 4;
19
+ }
20
+ else if (edge.typeIndex === REFERENCES) {
21
+ size += value.length * 4 + 4;
22
+ }
23
+ }
24
+ else {
25
+ size += edge.len;
26
+ }
27
+ }
28
+ }
29
+ return size;
30
+ }
31
+ function appendRefs(t, ctx, value) {
32
+ for (let i = 0; i < value.length; i++) {
33
+ let id = value[i];
34
+ if (typeof id !== 'number') {
35
+ if (id instanceof ModifyState) {
36
+ if (id.error) {
37
+ return id.error;
38
+ }
39
+ id = id.tmpId;
40
+ }
41
+ else {
42
+ return new ModifyError(t, value);
43
+ }
44
+ }
45
+ if (id > 0) {
46
+ ctx.buf[ctx.len++] = id;
47
+ ctx.buf[ctx.len++] = id >>>= 8;
48
+ ctx.buf[ctx.len++] = id >>>= 8;
49
+ ctx.buf[ctx.len++] = id >>>= 8;
50
+ }
51
+ else {
52
+ return new ModifyError(t, value);
53
+ }
54
+ }
55
+ }
56
+ export function writeEdges(t, ref, ctx) {
57
+ for (const key in t.edges) {
58
+ if (key in ref) {
59
+ const edge = t.edges[key];
60
+ let value = ref[key];
61
+ if (edge.len === 0) {
62
+ if (edge.typeIndex === BINARY) {
63
+ let size = 0;
64
+ if (value === null) {
65
+ size = 0;
66
+ }
67
+ else {
68
+ const buf = getBuffer(value);
69
+ if (!buf) {
70
+ return new ModifyError(t, ref);
71
+ }
72
+ size = buf.byteLength;
73
+ }
74
+ if (ctx.len + 6 + size > ctx.max) {
75
+ return RANGE_ERR;
76
+ }
77
+ ctx.buf[ctx.len++] = edge.prop;
78
+ ctx.buf[ctx.len++] = STRING;
79
+ if (size) {
80
+ writeBinaryRaw(value, ctx);
81
+ }
82
+ else {
83
+ ctx.buf[ctx.len++] = 0;
84
+ ctx.buf[ctx.len++] = 0;
85
+ ctx.buf[ctx.len++] = 0;
86
+ ctx.buf[ctx.len++] = 0;
87
+ }
88
+ }
89
+ else if (edge.typeIndex === STRING) {
90
+ if (typeof value !== 'string') {
91
+ return new ModifyError(t, ref);
92
+ }
93
+ if (ctx.len + 6 + Buffer.byteLength(value) > ctx.max) {
94
+ return RANGE_ERR;
95
+ }
96
+ ctx.buf[ctx.len++] = edge.prop;
97
+ ctx.buf[ctx.len++] = STRING;
98
+ let size = write(ctx.buf, value, ctx.len + 4, edge.compression === 0);
99
+ let sizeU32 = size;
100
+ ctx.buf[ctx.len++] = sizeU32;
101
+ ctx.buf[ctx.len++] = sizeU32 >>>= 8;
102
+ ctx.buf[ctx.len++] = sizeU32 >>>= 8;
103
+ ctx.buf[ctx.len++] = sizeU32 >>>= 8;
104
+ ctx.len += size;
105
+ }
106
+ else if (edge.typeIndex === REFERENCE) {
107
+ if (typeof value !== 'number') {
108
+ if (value instanceof ModifyState) {
109
+ value = value.tmpId;
110
+ }
111
+ else {
112
+ return new ModifyError(t, ref);
113
+ }
114
+ }
115
+ if (value > 0) {
116
+ ctx.buf[ctx.len++] = edge.prop;
117
+ ctx.buf[ctx.len++] = REFERENCE;
118
+ ctx.buf[ctx.len++] = value;
119
+ ctx.buf[ctx.len++] = value >>>= 8;
120
+ ctx.buf[ctx.len++] = value >>>= 8;
121
+ ctx.buf[ctx.len++] = value >>>= 8;
122
+ }
123
+ else {
124
+ return new ModifyError(t, ref);
125
+ }
126
+ }
127
+ else if (edge.typeIndex === REFERENCES) {
128
+ if (!Array.isArray(value)) {
129
+ return new ModifyError(t, ref);
130
+ }
131
+ let size = value.length * 4;
132
+ if (ctx.len + 6 + size > ctx.max) {
133
+ return RANGE_ERR;
134
+ }
135
+ ctx.buf[ctx.len++] = edge.prop;
136
+ ctx.buf[ctx.len++] = REFERENCES;
137
+ ctx.buf[ctx.len++] = size;
138
+ ctx.buf[ctx.len++] = size >>>= 8;
139
+ ctx.buf[ctx.len++] = size >>>= 8;
140
+ ctx.buf[ctx.len++] = size >>>= 8;
141
+ appendRefs(edge, ctx, value);
142
+ }
143
+ }
144
+ else {
145
+ if (ctx.len + 2 > ctx.max) {
146
+ return RANGE_ERR;
147
+ }
148
+ ctx.buf[ctx.len++] = edge.prop;
149
+ ctx.buf[ctx.len++] = edge.typeIndex;
150
+ const err = appendFixedValue(ctx, value, edge);
151
+ if (err) {
152
+ return err;
153
+ }
154
+ }
155
+ }
156
+ }
157
+ }
158
+ //# sourceMappingURL=edge.js.map
@@ -0,0 +1,11 @@
1
+ import { ModifyCtx } from '../../../index.js';
2
+ import { PropDef, SchemaTypeDef } from '../../../server/schema/types.js';
3
+ import { ModifyState } from '../ModifyRes.js';
4
+ import { ModifyErr, ModifyOp } from '../types.js';
5
+ export declare function writeReference(value: number | ModifyState | {
6
+ id: number;
7
+ upsert?: Record<string, any>;
8
+ } | {
9
+ id?: number;
10
+ upsert: Record<string, any>;
11
+ }, ctx: ModifyCtx, schema: SchemaTypeDef, def: PropDef, res: ModifyState, modifyOp: ModifyOp): ModifyErr;