@based/db 0.0.70 → 0.1.0

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 (263) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +105 -77
  3. package/dist/lib/darwin_aarch64/include/libdeflate.h +23 -0
  4. package/dist/lib/darwin_aarch64/include/selva/db.h +0 -41
  5. package/dist/lib/darwin_aarch64/include/selva/fast_linear_search.h +6 -2
  6. package/dist/lib/darwin_aarch64/include/selva/fields.h +52 -37
  7. package/dist/lib/darwin_aarch64/include/selva/gmtime.h +137 -0
  8. package/dist/lib/darwin_aarch64/include/selva/hll.h +1 -1
  9. package/dist/lib/darwin_aarch64/include/selva/mblen.h +40 -0
  10. package/dist/lib/darwin_aarch64/include/selva/selva_string.h +8 -5
  11. package/dist/lib/darwin_aarch64/include/selva/thread.h +37 -0
  12. package/dist/lib/darwin_aarch64/include/selva/types.h +18 -4
  13. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  14. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  15. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  16. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  17. package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
  18. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  19. package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
  20. package/dist/lib/linux_aarch64/include/libdeflate.h +23 -0
  21. package/dist/lib/linux_aarch64/include/selva/db.h +0 -41
  22. package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +6 -2
  23. package/dist/lib/linux_aarch64/include/selva/fields.h +52 -37
  24. package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
  25. package/dist/lib/linux_aarch64/include/selva/hll.h +1 -1
  26. package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
  27. package/dist/lib/linux_aarch64/include/selva/selva_string.h +8 -5
  28. package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
  29. package/dist/lib/linux_aarch64/include/selva/types.h +18 -4
  30. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  31. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  32. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  33. package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
  34. package/dist/lib/linux_aarch64/libselva.so +0 -0
  35. package/dist/lib/linux_x86_64/include/libdeflate.h +23 -0
  36. package/dist/lib/linux_x86_64/include/selva/db.h +0 -41
  37. package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +6 -2
  38. package/dist/lib/linux_x86_64/include/selva/fields.h +52 -37
  39. package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
  40. package/dist/lib/linux_x86_64/include/selva/hll.h +1 -1
  41. package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
  42. package/dist/lib/linux_x86_64/include/selva/selva_string.h +8 -5
  43. package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
  44. package/dist/lib/linux_x86_64/include/selva/types.h +18 -4
  45. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  46. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  47. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  48. package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
  49. package/dist/lib/linux_x86_64/libselva.so +0 -0
  50. package/dist/src/client/index.d.ts +16 -21
  51. package/dist/src/client/index.js +48 -59
  52. package/dist/src/client/modify/Ctx.d.ts +38 -0
  53. package/dist/src/client/modify/Ctx.js +30 -0
  54. package/dist/src/client/modify/Tmp.d.ts +19 -0
  55. package/dist/src/client/modify/Tmp.js +67 -0
  56. package/dist/src/client/modify/create/index.d.ts +6 -0
  57. package/dist/src/client/modify/create/index.js +191 -0
  58. package/dist/src/client/modify/create/mark.d.ts +7 -0
  59. package/dist/src/client/modify/create/mark.js +42 -0
  60. package/dist/src/client/modify/cursor.d.ts +10 -0
  61. package/dist/src/client/modify/cursor.js +48 -0
  62. package/dist/src/client/modify/delete/index.d.ts +2 -0
  63. package/dist/src/client/modify/delete/index.js +39 -0
  64. package/dist/src/client/modify/drain.d.ts +7 -0
  65. package/dist/src/client/modify/drain.js +77 -0
  66. package/dist/src/client/modify/edges/binary.d.ts +3 -0
  67. package/dist/src/client/modify/edges/binary.js +28 -0
  68. package/dist/src/client/modify/edges/cardinality.d.ts +3 -0
  69. package/dist/src/client/modify/edges/cardinality.js +15 -0
  70. package/dist/src/client/modify/edges/header.d.ts +5 -0
  71. package/dist/src/client/modify/edges/header.js +21 -0
  72. package/dist/src/client/modify/edges/index.d.ts +3 -0
  73. package/dist/src/client/modify/edges/index.js +128 -0
  74. package/dist/src/client/modify/edges/reference.d.ts +3 -0
  75. package/dist/src/client/modify/edges/reference.js +31 -0
  76. package/dist/src/client/modify/edges/references.d.ts +3 -0
  77. package/dist/src/client/modify/edges/references.js +38 -0
  78. package/dist/src/client/modify/edges/separate.d.ts +3 -0
  79. package/dist/src/client/modify/edges/separate.js +24 -0
  80. package/dist/src/client/modify/edges/string.d.ts +3 -0
  81. package/dist/src/client/modify/edges/string.js +30 -0
  82. package/dist/src/client/modify/error.d.ts +7 -0
  83. package/dist/src/client/modify/error.js +68 -0
  84. package/dist/src/client/modify/expire/index.d.ts +2 -0
  85. package/dist/src/client/modify/expire/index.js +31 -0
  86. package/dist/src/client/modify/props/alias.d.ts +3 -0
  87. package/dist/src/client/modify/props/alias.js +26 -0
  88. package/dist/src/client/modify/props/binary.d.ts +5 -0
  89. package/dist/src/client/modify/props/binary.js +52 -0
  90. package/dist/src/client/modify/props/cardinality.d.ts +4 -0
  91. package/dist/src/client/modify/props/cardinality.js +46 -0
  92. package/dist/src/client/modify/props/delete.d.ts +3 -0
  93. package/dist/src/client/modify/props/delete.js +13 -0
  94. package/dist/src/client/modify/props/fixed.d.ts +4 -0
  95. package/dist/src/client/modify/props/fixed.js +105 -0
  96. package/dist/src/client/modify/props/increment.d.ts +3 -0
  97. package/dist/src/client/modify/props/increment.js +28 -0
  98. package/dist/src/client/modify/props/json.d.ts +3 -0
  99. package/dist/src/client/modify/props/json.js +5 -0
  100. package/dist/src/client/modify/props/main.d.ts +4 -0
  101. package/dist/src/client/modify/props/main.js +22 -0
  102. package/dist/src/client/modify/props/object.d.ts +3 -0
  103. package/dist/src/client/modify/props/object.js +37 -0
  104. package/dist/src/client/modify/props/reference.d.ts +6 -0
  105. package/dist/src/client/modify/props/reference.js +92 -0
  106. package/dist/src/client/modify/props/references.d.ts +3 -0
  107. package/dist/src/client/modify/props/references.js +231 -0
  108. package/dist/src/client/modify/props/separate.d.ts +3 -0
  109. package/dist/src/client/modify/props/separate.js +43 -0
  110. package/dist/src/client/modify/props/string.d.ts +5 -0
  111. package/dist/src/client/modify/props/string.js +51 -0
  112. package/dist/src/client/modify/props/text.d.ts +3 -0
  113. package/dist/src/client/modify/props/text.js +35 -0
  114. package/dist/src/client/modify/props/vector.d.ts +3 -0
  115. package/dist/src/client/modify/props/vector.js +30 -0
  116. package/dist/src/client/modify/resize.d.ts +3 -0
  117. package/dist/src/client/modify/resize.js +20 -0
  118. package/dist/src/client/modify/types.d.ts +3 -4
  119. package/dist/src/client/modify/types.js +2 -1
  120. package/dist/src/client/modify/uint.d.ts +7 -0
  121. package/dist/src/client/modify/uint.js +27 -0
  122. package/dist/src/client/modify/update/index.d.ts +3 -0
  123. package/dist/src/client/modify/update/index.js +75 -0
  124. package/dist/src/client/modify/upsert/index.d.ts +3 -0
  125. package/dist/src/client/modify/{upsert.js → upsert/index.js} +4 -4
  126. package/dist/src/client/modify/validate.d.ts +6 -0
  127. package/dist/src/client/modify/validate.js +24 -0
  128. package/dist/src/client/query/BasedDbQuery.d.ts +18 -15
  129. package/dist/src/client/query/BasedDbQuery.js +93 -96
  130. package/dist/src/client/query/{BasedIterable.d.ts → BasedQueryResponse.d.ts} +5 -4
  131. package/dist/src/client/query/{BasedIterable.js → BasedQueryResponse.js} +15 -10
  132. package/dist/src/client/query/aggregates/aggregation.d.ts +5 -3
  133. package/dist/src/client/query/aggregates/aggregation.js +105 -48
  134. package/dist/src/client/query/aggregates/types.d.ts +34 -12
  135. package/dist/src/client/query/aggregates/types.js +30 -12
  136. package/dist/src/client/query/debug.js +1 -1
  137. package/dist/src/client/query/display.d.ts +1 -1
  138. package/dist/src/client/query/display.js +21 -4
  139. package/dist/src/client/query/filter/FilterBranch.js +2 -2
  140. package/dist/src/client/query/filter/convertFilter.d.ts +3 -2
  141. package/dist/src/client/query/filter/convertFilter.js +13 -1
  142. package/dist/src/client/query/filter/createFixedFilterBuffer.js +16 -30
  143. package/dist/src/client/query/filter/createReferenceFilter.js +6 -20
  144. package/dist/src/client/query/filter/createVariableFilterBuffer.js +15 -32
  145. package/dist/src/client/query/filter/parseFilterValue.js +3 -11
  146. package/dist/src/client/query/filter/primitiveFilter.js +1 -1
  147. package/dist/src/client/query/filter/toBuffer.js +9 -15
  148. package/dist/src/client/query/filter/types.d.ts +6 -6
  149. package/dist/src/client/query/filter/types.js +8 -8
  150. package/dist/src/client/query/include/include.d.ts +3 -0
  151. package/dist/src/client/query/include/include.js +58 -0
  152. package/dist/src/client/query/include/props.d.ts +7 -7
  153. package/dist/src/client/query/include/props.js +26 -21
  154. package/dist/src/client/query/include/toByteCode.js +188 -0
  155. package/dist/src/client/query/include/utils.d.ts +3 -1
  156. package/dist/src/client/query/include/utils.js +13 -0
  157. package/dist/src/client/query/include/walk.d.ts +2 -2
  158. package/dist/src/client/query/include/walk.js +38 -23
  159. package/dist/src/client/query/query.d.ts +2 -3
  160. package/dist/src/client/query/query.js +2 -3
  161. package/dist/src/client/query/queryDef.d.ts +4 -2
  162. package/dist/src/client/query/queryDef.js +3 -5
  163. package/dist/src/client/query/queryDefToReadSchema.d.ts +3 -0
  164. package/dist/src/client/query/queryDefToReadSchema.js +126 -0
  165. package/dist/src/client/query/registerQuery.js +15 -4
  166. package/dist/src/client/query/search/index.d.ts +2 -1
  167. package/dist/src/client/query/search/index.js +9 -2
  168. package/dist/src/client/query/sort.js +3 -0
  169. package/dist/src/client/query/subscription/index.d.ts +1 -1
  170. package/dist/src/client/query/subscription/index.js +2 -2
  171. package/dist/src/client/query/subscription/types.d.ts +1 -1
  172. package/dist/src/client/query/thresholds.d.ts +1 -1
  173. package/dist/src/client/query/thresholds.js +1 -1
  174. package/dist/src/client/query/toByteCode/{toBuffer.js → toByteCode.js} +8 -8
  175. package/dist/src/client/query/types.d.ts +40 -25
  176. package/dist/src/client/query/types.js +2 -6
  177. package/dist/src/client/query/validation.d.ts +6 -0
  178. package/dist/src/client/query/validation.js +32 -8
  179. package/dist/src/client/setLocalClientSchema.js +6 -10
  180. package/dist/src/client/string.d.ts +3 -7
  181. package/dist/src/client/string.js +18 -47
  182. package/dist/src/hooks.d.ts +2 -3
  183. package/dist/src/hooks.js +14 -9
  184. package/dist/src/index.d.ts +3 -5
  185. package/dist/src/index.js +4 -6
  186. package/dist/src/native.d.ts +3 -2
  187. package/dist/src/native.js +9 -8
  188. package/dist/src/server/IoWorker.js +2 -3
  189. package/dist/src/server/QueryWorker.js +1 -1
  190. package/dist/src/server/blocks.js +5 -4
  191. package/dist/src/server/dbHash.js +1 -1
  192. package/dist/src/server/index.d.ts +4 -6
  193. package/dist/src/server/index.js +63 -96
  194. package/dist/src/server/migrate/index.d.ts +2 -4
  195. package/dist/src/server/migrate/index.js +31 -16
  196. package/dist/src/server/migrate/worker.js +2 -27
  197. package/dist/src/server/save.js +10 -8
  198. package/dist/src/server/schema.js +17 -25
  199. package/dist/src/server/start.d.ts +1 -0
  200. package/dist/src/server/start.js +18 -10
  201. package/dist/src/server/tree.d.ts +20 -0
  202. package/dist/src/server/tree.js +17 -2
  203. package/dist/src/server/workers/DbWorker.d.ts +1 -0
  204. package/dist/src/server/workers/DbWorker.js +8 -1
  205. package/dist/src/server/workers/io_worker.js +1 -1
  206. package/dist/src/server/workers/worker.js +9 -4
  207. package/dist/src/table.d.ts +4 -0
  208. package/dist/src/table.js +97 -0
  209. package/dist/src/types.d.ts +1 -1
  210. package/package.json +18 -17
  211. package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +0 -29
  212. package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -29
  213. package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -29
  214. package/dist/src/client/flushModify.d.ts +0 -36
  215. package/dist/src/client/flushModify.js +0 -197
  216. package/dist/src/client/modify/ModifyRes.d.ts +0 -23
  217. package/dist/src/client/modify/ModifyRes.js +0 -101
  218. package/dist/src/client/modify/alias.d.ts +0 -4
  219. package/dist/src/client/modify/alias.js +0 -57
  220. package/dist/src/client/modify/binary.d.ts +0 -6
  221. package/dist/src/client/modify/binary.js +0 -80
  222. package/dist/src/client/modify/cardinality.d.ts +0 -6
  223. package/dist/src/client/modify/cardinality.js +0 -63
  224. package/dist/src/client/modify/create.d.ts +0 -5
  225. package/dist/src/client/modify/create.js +0 -228
  226. package/dist/src/client/modify/delete.d.ts +0 -4
  227. package/dist/src/client/modify/delete.js +0 -47
  228. package/dist/src/client/modify/expire.d.ts +0 -3
  229. package/dist/src/client/modify/expire.js +0 -25
  230. package/dist/src/client/modify/fixed.d.ts +0 -5
  231. package/dist/src/client/modify/fixed.js +0 -235
  232. package/dist/src/client/modify/index.d.ts +0 -4
  233. package/dist/src/client/modify/index.js +0 -4
  234. package/dist/src/client/modify/json.d.ts +0 -4
  235. package/dist/src/client/modify/json.js +0 -26
  236. package/dist/src/client/modify/modify.d.ts +0 -5
  237. package/dist/src/client/modify/modify.js +0 -134
  238. package/dist/src/client/modify/references/appendEdgeRefs.d.ts +0 -4
  239. package/dist/src/client/modify/references/appendEdgeRefs.js +0 -33
  240. package/dist/src/client/modify/references/edge.d.ts +0 -5
  241. package/dist/src/client/modify/references/edge.js +0 -322
  242. package/dist/src/client/modify/references/getEdgeSize.d.ts +0 -3
  243. package/dist/src/client/modify/references/getEdgeSize.js +0 -27
  244. package/dist/src/client/modify/references/reference.d.ts +0 -11
  245. package/dist/src/client/modify/references/reference.js +0 -112
  246. package/dist/src/client/modify/references/references.d.ts +0 -16
  247. package/dist/src/client/modify/references/references.js +0 -308
  248. package/dist/src/client/modify/setCursor.d.ts +0 -5
  249. package/dist/src/client/modify/setCursor.js +0 -33
  250. package/dist/src/client/modify/string.d.ts +0 -5
  251. package/dist/src/client/modify/string.js +0 -71
  252. package/dist/src/client/modify/text.d.ts +0 -8
  253. package/dist/src/client/modify/text.js +0 -69
  254. package/dist/src/client/modify/update.d.ts +0 -6
  255. package/dist/src/client/modify/update.js +0 -90
  256. package/dist/src/client/modify/upsert.d.ts +0 -3
  257. package/dist/src/client/modify/vector.d.ts +0 -4
  258. package/dist/src/client/modify/vector.js +0 -53
  259. package/dist/src/client/query/include/toBuffer.js +0 -123
  260. package/dist/src/client/query/read/read.d.ts +0 -9
  261. package/dist/src/client/query/read/read.js +0 -483
  262. /package/dist/src/client/query/include/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
  263. /package/dist/src/client/query/toByteCode/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
@@ -1,134 +0,0 @@
1
- import { isPropDef, REFERENCE, REFERENCES, STRING, TEXT, ALIAS, BINARY, CARDINALITY, VECTOR, MICRO_BUFFER, JSON, COLVEC, } from '@based/schema/def';
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 './cardinality.js';
13
- import { writeVector } from './vector.js';
14
- import { writeJson } from './json.js';
15
- function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
16
- for (const key in obj) {
17
- const def = tree[key];
18
- if (def === undefined) {
19
- if (unsafe) {
20
- continue;
21
- }
22
- return new ModifyError(tree, key);
23
- }
24
- let err;
25
- if (isPropDef(def)) {
26
- const val = obj[key];
27
- if (val === undefined) {
28
- continue;
29
- }
30
- const type = def.typeIndex;
31
- if (def.separate) {
32
- if (type === STRING) {
33
- err = writeString(0, val, ctx, schema, def, res.tmpId, mod);
34
- }
35
- else if (type === TEXT) {
36
- err = writeText(val, ctx, schema, def, res, res.tmpId, mod);
37
- }
38
- else if (type === REFERENCE) {
39
- err = writeReference(val, ctx, schema, def, res, mod);
40
- }
41
- else if (type === REFERENCES) {
42
- err = writeReferences(val, ctx, schema, def, res, mod);
43
- }
44
- else if (type === BINARY) {
45
- err = writeBinary(val, ctx, schema, def, res.tmpId, mod);
46
- }
47
- else if (type === ALIAS) {
48
- err = writeAlias(val, ctx, schema, def, res.tmpId, mod);
49
- }
50
- else if (type === CARDINALITY) {
51
- err = writeHll(val, ctx, schema, def, res.tmpId, mod);
52
- }
53
- else if (type === VECTOR || type === COLVEC) {
54
- err = writeVector(val, ctx, schema, def, res.tmpId, mod);
55
- }
56
- else if (type === JSON) {
57
- err = writeJson(val, ctx, schema, def, res.tmpId, mod);
58
- }
59
- }
60
- else if (overwrite) {
61
- if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 + schema.mainLen > ctx.max) {
62
- return RANGE_ERR;
63
- }
64
- setCursor(ctx, schema, def.prop, MICRO_BUFFER, res.tmpId, mod, true);
65
- if (ctx.lastMain === -1) {
66
- let mainLenU32 = schema.mainLen;
67
- setCursor(ctx, schema, def.prop, MICRO_BUFFER, res.tmpId, mod);
68
- ctx.buf[ctx.len++] = mod;
69
- ctx.buf[ctx.len++] = mainLenU32;
70
- ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
71
- ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
72
- ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
73
- ctx.lastMain = ctx.len;
74
- ctx.buf.set(schema.mainEmpty, ctx.len);
75
- ctx.len += schema.mainLen;
76
- }
77
- if (typeof val === 'object' && val !== null && 'increment' in val) {
78
- err = writeFixedValue(ctx, val.increment, def, ctx.lastMain + def.start, mod);
79
- }
80
- else {
81
- err = writeFixedValue(ctx, val, def, ctx.lastMain + def.start, mod);
82
- }
83
- }
84
- else if (typeof val === 'object' && val !== null) {
85
- if ('increment' in val) {
86
- let increment = val.increment;
87
- if (increment === 0) {
88
- continue;
89
- }
90
- if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ > ctx.max) {
91
- return RANGE_ERR;
92
- }
93
- setCursor(ctx, schema, def.prop, MICRO_BUFFER, res.tmpId, mod);
94
- let start = def.start;
95
- if (increment < 0) {
96
- ctx.buf[ctx.len++] = DECREMENT;
97
- increment = -increment;
98
- }
99
- else {
100
- ctx.buf[ctx.len++] = INCREMENT;
101
- }
102
- ctx.buf[ctx.len++] = def.typeIndex;
103
- ctx.buf[ctx.len++] = start;
104
- ctx.buf[ctx.len++] = start >>>= 8;
105
- appendFixedValue(ctx, increment, def, mod);
106
- }
107
- else {
108
- return new ModifyError(def, val);
109
- }
110
- }
111
- else if (ctx.mergeMain) {
112
- ctx.mergeMain.push(def, val);
113
- ctx.mergeMainSize += def.len + 4;
114
- }
115
- else {
116
- ctx.mergeMain = [def, val];
117
- ctx.mergeMainSize = def.len + 4;
118
- }
119
- }
120
- else {
121
- err = _modify(ctx, res, obj[key], schema, mod, def, overwrite, unsafe);
122
- }
123
- if (err) {
124
- if (unsafe && err !== RANGE_ERR) {
125
- continue;
126
- }
127
- return err;
128
- }
129
- }
130
- }
131
- export function modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe = false) {
132
- return _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe);
133
- }
134
- //# sourceMappingURL=modify.js.map
@@ -1,4 +0,0 @@
1
- import type { PropDefEdge } from '@based/schema/def';
2
- import type { ModifyCtx } from '../../flushModify.js';
3
- import type { ModifyErr } from '../types.js';
4
- export declare function appendEdgeRefs(t: PropDefEdge, ctx: ModifyCtx, value: any[]): ModifyErr;
@@ -1,33 +0,0 @@
1
- import { ModifyError, ModifyState } from '../ModifyRes.js';
2
- export function appendEdgeRefs(t, ctx, value) {
3
- for (let i = 0; i < value.length; i++) {
4
- let id = value[i];
5
- if (typeof id !== 'number') {
6
- if (id instanceof ModifyState) {
7
- if (id.error) {
8
- return id.error;
9
- }
10
- id = id.tmpId;
11
- }
12
- else if (typeof id === 'object' && id !== null && id.id) {
13
- id = id.id;
14
- }
15
- else {
16
- return new ModifyError(t, value);
17
- }
18
- }
19
- if (!t.validation(id, t)) {
20
- return new ModifyError(t, value);
21
- }
22
- if (id > 0) {
23
- ctx.buf[ctx.len++] = id;
24
- ctx.buf[ctx.len++] = id >>>= 8;
25
- ctx.buf[ctx.len++] = id >>>= 8;
26
- ctx.buf[ctx.len++] = id >>>= 8;
27
- }
28
- else {
29
- return new ModifyError(t, value);
30
- }
31
- }
32
- }
33
- //# sourceMappingURL=appendEdgeRefs.js.map
@@ -1,5 +0,0 @@
1
- import { ModifyCtx } from '../../../index.js';
2
- import { PropDef } from '@based/schema/def';
3
- import { ModifyErr } from '../types.js';
4
- import { RefModifyOpts } from './references.js';
5
- export declare function writeEdges(t: PropDef, ref: RefModifyOpts, ctx: ModifyCtx): ModifyErr;
@@ -1,322 +0,0 @@
1
- import { ENCODER } from '../../../index.js';
2
- import { BINARY, MICRO_BUFFER, CARDINALITY, REFERENCE, REFERENCES, STRING, } from '@based/schema/def';
3
- import { write } from '../../string.js';
4
- import { writeHllBuf } from '../cardinality.js';
5
- import { getBuffer, writeBinaryRaw } from '../binary.js';
6
- import { ModifyError, ModifyState } from '../ModifyRes.js';
7
- import { DECREMENT, INCREMENT, RANGE_ERR, UPDATE, UPDATE_PARTIAL, } from '../types.js';
8
- import { appendFixedValue } from '../fixed.js';
9
- import { appendEdgeRefs } from './appendEdgeRefs.js';
10
- function valueOperation(value) {
11
- if (typeof value === 'object' && value !== null) {
12
- if (value.increment > 0) {
13
- return INCREMENT;
14
- }
15
- else if (value.increment < 0) {
16
- return DECREMENT;
17
- }
18
- return 0;
19
- }
20
- return UPDATE;
21
- }
22
- const EDGE_HEADER_SIZE = 5;
23
- export function writeEdges(t, ref, ctx) {
24
- let mainFields;
25
- let mainSize = 0;
26
- let hasIncr = false;
27
- for (const key in ref) {
28
- if (key === 'id' || key === '$index') {
29
- continue;
30
- }
31
- const edge = t.edges?.[key];
32
- if (!edge) {
33
- return new ModifyError(t, key, `Does not exist`);
34
- }
35
- let value = ref[key];
36
- if (edge.separate === true) {
37
- if (ctx.len + 2 > ctx.max) {
38
- return RANGE_ERR;
39
- }
40
- ctx.buf[ctx.len++] = UPDATE;
41
- ctx.buf[ctx.len++] = edge.prop;
42
- /*
43
- Seperate fields:
44
-
45
- | Offset | Field | Size (bytes)| Description |
46
- |---------|-------------|-------------|---------------------------------------|
47
- | 0 | modify op | 1 | Modify operation identifier |
48
- | 1 | prop | 1 | Field identifier |
49
- | 2 | type | 1 | Indicates MICRO_BUFFER type |
50
- | 3 | size | 4 | Size of the data in bytes |
51
- | 7 | data | Variable | Content |
52
- */
53
- if (edge.typeIndex === BINARY) {
54
- let size = 0;
55
- // add null
56
- if (value === null) {
57
- size = 0;
58
- }
59
- else {
60
- const buf = getBuffer(value);
61
- if (!buf || !edge.validation(buf, edge)) {
62
- return new ModifyError(edge, value);
63
- }
64
- size = buf.byteLength;
65
- value = buf;
66
- }
67
- if (ctx.len + EDGE_HEADER_SIZE + size > ctx.max) {
68
- return RANGE_ERR;
69
- }
70
- ctx.buf[ctx.len++] = STRING;
71
- if (size) {
72
- writeBinaryRaw(value, ctx);
73
- }
74
- else {
75
- ctx.buf[ctx.len++] = 0;
76
- ctx.buf[ctx.len++] = 0;
77
- ctx.buf[ctx.len++] = 0;
78
- ctx.buf[ctx.len++] = 0;
79
- }
80
- }
81
- else if (edge.typeIndex === STRING) {
82
- let size = 0;
83
- // add null
84
- if (value !== null) {
85
- if (!edge.validation(value, edge)) {
86
- return new ModifyError(edge, value);
87
- }
88
- const isBuffer = value instanceof Uint8Array;
89
- size = isBuffer
90
- ? value.byteLength
91
- : ENCODER.encode(value).byteLength + 6;
92
- if (ctx.len + EDGE_HEADER_SIZE + size > ctx.max) {
93
- return RANGE_ERR;
94
- }
95
- ctx.buf[ctx.len++] = STRING;
96
- size = write(ctx.buf, value, ctx.len + 4, edge.compression === 0);
97
- }
98
- let sizeU32 = size;
99
- ctx.buf[ctx.len++] = sizeU32;
100
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
101
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
102
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
103
- ctx.len += size;
104
- }
105
- else if (edge.typeIndex === REFERENCE) {
106
- // add null
107
- if (typeof value !== 'number') {
108
- if (value instanceof ModifyState) {
109
- if (value.error) {
110
- return value.error;
111
- }
112
- value = value.tmpId;
113
- }
114
- else if (typeof value === 'object' && value !== null && value.id) {
115
- value = value.id;
116
- }
117
- else {
118
- return new ModifyError(edge, value);
119
- }
120
- }
121
- if (!edge.validation(value, edge)) {
122
- return new ModifyError(edge, value);
123
- }
124
- if (value > 0) {
125
- ctx.buf[ctx.len++] = REFERENCE;
126
- ctx.buf[ctx.len++] = value;
127
- ctx.buf[ctx.len++] = value >>>= 8;
128
- ctx.buf[ctx.len++] = value >>>= 8;
129
- ctx.buf[ctx.len++] = value >>>= 8;
130
- }
131
- else {
132
- return new ModifyError(edge, value);
133
- }
134
- }
135
- else if (edge.typeIndex === REFERENCES) {
136
- // add null
137
- if (!Array.isArray(value)) {
138
- return new ModifyError(edge, value);
139
- }
140
- let size = value.length * 4;
141
- if (ctx.len + EDGE_HEADER_SIZE + size > ctx.max) {
142
- return RANGE_ERR;
143
- }
144
- ctx.buf[ctx.len++] = REFERENCES;
145
- ctx.buf[ctx.len++] = size;
146
- ctx.buf[ctx.len++] = size >>>= 8;
147
- ctx.buf[ctx.len++] = size >>>= 8;
148
- ctx.buf[ctx.len++] = size >>>= 8;
149
- const err = appendEdgeRefs(edge, ctx, value);
150
- if (err) {
151
- return err;
152
- }
153
- }
154
- else if (edge.typeIndex === CARDINALITY) {
155
- // add null
156
- if (!Array.isArray(value)) {
157
- value = [value];
158
- }
159
- const len = value.length;
160
- let size = 4 + len * 8;
161
- if (ctx.len + size + EDGE_HEADER_SIZE > ctx.max) {
162
- return RANGE_ERR;
163
- }
164
- ctx.buf[ctx.len++] = CARDINALITY;
165
- writeHllBuf(value, ctx, edge, size);
166
- }
167
- }
168
- else {
169
- const op = valueOperation(value);
170
- if (op === 0) {
171
- return new ModifyError(edge, value);
172
- }
173
- if (op != UPDATE) {
174
- hasIncr = true;
175
- value = value.increment;
176
- }
177
- if (!hasIncr && t.edgeMainLen == edge.len) {
178
- /*
179
- Full main update:
180
-
181
- | Offset | Field | Size (bytes)| Description |
182
- |---------|-------------|-------------|---------------------------------------|
183
- | 0 | modify op | 1 | Modify operation identifier |
184
- | 1 | prop | 1 | Field identifier (0) |
185
- | 2 | type | 1 | Indicates MICRO_BUFFER type |
186
- | 3 | mainSize | 4 | Size of the main data in bytes |
187
- | 7 | main buffer | Variable | Main data content |
188
- */
189
- if (ctx.len + 7 + edge.len > ctx.max) {
190
- return RANGE_ERR;
191
- }
192
- ctx.buf[ctx.len++] = UPDATE;
193
- ctx.buf[ctx.len++] = 0;
194
- ctx.buf[ctx.len++] = MICRO_BUFFER;
195
- const size = edge.len;
196
- let sizeU32 = size;
197
- ctx.buf[ctx.len++] = sizeU32;
198
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
199
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
200
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
201
- const err = appendFixedValue(ctx, value, edge, UPDATE);
202
- if (err) {
203
- return err;
204
- }
205
- }
206
- else {
207
- mainSize += edge.len;
208
- if (!mainFields) {
209
- mainFields = [edge, value, op];
210
- }
211
- else {
212
- const len = mainFields.length;
213
- for (let i = 0; i < len; i += 3) {
214
- if (edge.start < mainFields[i].start) {
215
- mainFields.splice(i, 0, edge, value, op);
216
- break;
217
- }
218
- else if (mainFields[len - i - 3].start < edge.start) {
219
- mainFields.splice(len - i, 0, edge, value, op);
220
- break;
221
- }
222
- }
223
- }
224
- }
225
- }
226
- }
227
- if (mainFields) {
228
- // Single field in main buffer can immediately setup the main buffer
229
- if (!hasIncr && mainSize === t.edgeMainLen) {
230
- /*
231
- Full main update:
232
-
233
- | Offset | Field | Size (bytes)| Description |
234
- |---------|-------------|-------------|---------------------------------------|
235
- | 0 | modify op | 1 | Modify operation identifier |
236
- | 1 | prop | 1 | Field identifier (0) |
237
- | 2 | type | 1 | Indicates MICRO_BUFFER type |
238
- | 3 | mainSize | 4 | Size of the main data in bytes |
239
- | 7 | main buffer | Variable | Main data content |
240
- */
241
- if (ctx.len + 7 + mainSize > ctx.max) {
242
- return RANGE_ERR;
243
- }
244
- ctx.buf[ctx.len++] = UPDATE;
245
- ctx.buf[ctx.len++] = 0;
246
- ctx.buf[ctx.len++] = MICRO_BUFFER;
247
- let sizeU32 = mainSize;
248
- ctx.buf[ctx.len++] = sizeU32;
249
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
250
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
251
- ctx.buf[ctx.len++] = sizeU32 >>>= 8;
252
- for (let i = 0; i < mainFields.length; i += 3) {
253
- const edge = mainFields[i];
254
- const err = appendFixedValue(ctx, mainFields[i + 1], edge, UPDATE);
255
- if (err) {
256
- return err;
257
- }
258
- }
259
- }
260
- else {
261
- /*
262
- Partial main update:
263
-
264
- | Offset | Field | Size (bytes)| Description |
265
- |---------|-------------|-------------|--------------------------------------|
266
- | 0 | modify op | 1 | Modify operation identifier |
267
- | 1 | prop | 1 | Field identifier (0 in this case) |
268
- | 2 | type | 1 | Indicates MICRO_BUFFER type |
269
- | 3 | size | 4 | Total size of the payload |
270
- | 7 | mainSize | 2 | Length of the main data block |
271
- | 9 | start | 2 | Start position of first section |
272
- | 11 | len | 2 | Length of first section |
273
- | 12 | field op | 1 | Field operation type e.g. INCREMENT |
274
- | 13 | propType | 1 | Prop typeIndex |
275
- | ... | ... | ... | Additional (start, len) pairs |
276
- | X | main | len | Actual main content |
277
- */
278
- const mainFieldsStartSize = mainFields.length * 2;
279
- if (ctx.len + 7 + mainSize + mainFieldsStartSize > ctx.max) {
280
- return RANGE_ERR;
281
- }
282
- ctx.buf[ctx.len++] = UPDATE_PARTIAL;
283
- ctx.buf[ctx.len++] = 0;
284
- ctx.buf[ctx.len++] = MICRO_BUFFER;
285
- const size = mainFieldsStartSize + t.edgeMainLen;
286
- ctx.buf[ctx.len++] = size;
287
- ctx.buf[ctx.len++] = size >>> 8;
288
- ctx.buf[ctx.len++] = size >>> 16;
289
- ctx.buf[ctx.len++] = size >>> 24;
290
- ctx.buf[ctx.len++] = t.edgeMainLen;
291
- ctx.buf[ctx.len++] = t.edgeMainLen >>> 8;
292
- // Index of start of fields
293
- const sIndex = ctx.len;
294
- ctx.len += mainFieldsStartSize;
295
- // Add zeroes
296
- ctx.buf.fill(0, ctx.len, ctx.len + t.edgeMainLen);
297
- // Keep track of written bytes from append fixed
298
- let startMain = ctx.len;
299
- for (let i = 0; i < mainFields.length; i += 3) {
300
- const edge = mainFields[i];
301
- const value = mainFields[i + 1];
302
- const op = mainFields[i + 2];
303
- const sIndexI = i * 2 + sIndex;
304
- ctx.buf[sIndexI] = edge.start;
305
- ctx.buf[sIndexI + 1] = edge.start >>> 8;
306
- ctx.buf[sIndexI + 2] = edge.len;
307
- ctx.buf[sIndexI + 3] = edge.len >>> 8;
308
- ctx.buf[sIndexI + 4] = op;
309
- ctx.buf[sIndexI + 5] = edge.typeIndex;
310
- ctx.len = startMain + edge.start;
311
- // Add null support (defaults)
312
- const err = appendFixedValue(ctx, value, edge, op);
313
- if (err) {
314
- return err;
315
- }
316
- }
317
- // Correction append fixed value writes the len
318
- ctx.len = startMain + t.edgeMainLen;
319
- }
320
- }
321
- }
322
- //# sourceMappingURL=edge.js.map
@@ -1,3 +0,0 @@
1
- import { PropDef } from '@based/schema/def';
2
- import { RefModifyOpts } from './references.js';
3
- export declare function getEdgeSize(t: PropDef, ref: RefModifyOpts): number;
@@ -1,27 +0,0 @@
1
- import { STRING, REFERENCE, REFERENCES } from '@based/schema/def';
2
- import { ENCODER } from '@saulx/utils';
3
- export function getEdgeSize(t, ref) {
4
- let size = 0;
5
- for (const key in t.edges) {
6
- if (key in ref) {
7
- const edge = t.edges[key];
8
- const value = ref[key];
9
- if (edge.len === 0) {
10
- if (edge.typeIndex === STRING) {
11
- size += ENCODER.encode(value).byteLength + 4;
12
- }
13
- else if (edge.typeIndex === REFERENCE) {
14
- size += 4;
15
- }
16
- else if (edge.typeIndex === REFERENCES) {
17
- size += value.length * 4 + 4;
18
- }
19
- }
20
- else {
21
- size += edge.len;
22
- }
23
- }
24
- }
25
- return size;
26
- }
27
- //# sourceMappingURL=getEdgeSize.js.map
@@ -1,11 +0,0 @@
1
- import { ModifyCtx } from '../../../index.js';
2
- import { PropDef, SchemaTypeDef } from '@based/schema/def';
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;
@@ -1,112 +0,0 @@
1
- import { ModifyError, ModifyState } from '../ModifyRes.js';
2
- import { setCursor } from '../setCursor.js';
3
- import { DELETE, RANGE_ERR, EDGE_NOINDEX_TMPID, NOEDGE_NOINDEX_TMPID, EDGE_NOINDEX_REALID, NOEDGE_INDEX_REALID, } from '../types.js';
4
- import { writeEdges } from './edge.js';
5
- import { dbUpdateFromUpsert } from './references.js';
6
- function writeRef(id, ctx, schema, def, parentId, modifyOp, hasEdges, isTmpId) {
7
- if (!def.validation(id, def)) {
8
- return new ModifyError(def, id);
9
- }
10
- if (ctx.len + 16 > ctx.max) {
11
- return RANGE_ERR;
12
- }
13
- ctx.markNodeDirty(ctx.db.schemaTypesParsed[def.inverseTypeName], id);
14
- setCursor(ctx, schema, def.prop, def.typeIndex, parentId, modifyOp);
15
- ctx.buf[ctx.len++] = modifyOp;
16
- if (isTmpId) {
17
- ctx.buf[ctx.len++] = hasEdges ? EDGE_NOINDEX_TMPID : NOEDGE_NOINDEX_TMPID;
18
- }
19
- else {
20
- ctx.buf[ctx.len++] = hasEdges ? EDGE_NOINDEX_REALID : NOEDGE_INDEX_REALID;
21
- }
22
- ctx.buf[ctx.len++] = id;
23
- ctx.buf[ctx.len++] = id >>>= 8;
24
- ctx.buf[ctx.len++] = id >>>= 8;
25
- ctx.buf[ctx.len++] = id >>>= 8;
26
- }
27
- function singleReferenceEdges(ref, ctx, schema, def, parentId, modifyOp) {
28
- let id = ref.id;
29
- let isTmpId;
30
- if (typeof id !== 'number') {
31
- if (id instanceof ModifyState) {
32
- if (id.error) {
33
- return id.error;
34
- }
35
- const resolvedId = id.getId();
36
- if (resolvedId) {
37
- id = resolvedId;
38
- }
39
- else {
40
- isTmpId = !true;
41
- id = id.tmpId;
42
- }
43
- }
44
- }
45
- // TODO SINGLE REF
46
- if (id > 0) {
47
- if (def.edgesSeperateCnt === 0 && def.edgeMainLen === 0) {
48
- return writeRef(id, ctx, schema, def, parentId, modifyOp, false, isTmpId);
49
- }
50
- else {
51
- let err = writeRef(id, ctx, schema, def, parentId, modifyOp, true, isTmpId);
52
- if (err) {
53
- return err;
54
- }
55
- // TODO REMOVE - SEEMS REDUNDANT
56
- if (ctx.len + 4 > ctx.max) {
57
- return RANGE_ERR;
58
- }
59
- let sizepos = ctx.len;
60
- ctx.len += 4;
61
- err = writeEdges(def, ref, ctx);
62
- if (err) {
63
- return err;
64
- }
65
- let size = ctx.len - sizepos;
66
- ctx.buf[sizepos++] = size;
67
- ctx.buf[sizepos++] = size >>>= 8;
68
- ctx.buf[sizepos++] = size >>>= 8;
69
- ctx.buf[sizepos] = size >>>= 8;
70
- }
71
- }
72
- }
73
- export function writeReference(value, ctx, schema, def, res, modifyOp) {
74
- if (value === null) {
75
- if (ctx.len + 11 > ctx.max) {
76
- return RANGE_ERR;
77
- }
78
- setCursor(ctx, schema, def.prop, def.typeIndex, res.tmpId, modifyOp);
79
- ctx.buf[ctx.len++] = DELETE;
80
- }
81
- else if (typeof value === 'number') {
82
- return writeRef(value, ctx, schema, def, res.tmpId, modifyOp, false, false);
83
- }
84
- else if (value instanceof ModifyState) {
85
- if (value.error) {
86
- return value.error;
87
- }
88
- const id = value.getId();
89
- if (id) {
90
- return writeRef(id, ctx, schema, def, res.tmpId, modifyOp, false, false);
91
- }
92
- return writeRef(value.tmpId, ctx, schema, def, res.tmpId, modifyOp, false, true);
93
- }
94
- else if (typeof value === 'object' && value !== null) {
95
- if (def.edges) {
96
- return singleReferenceEdges(value, ctx, schema, def, res.tmpId, modifyOp);
97
- }
98
- else if (typeof value.id === 'number') {
99
- return writeRef(value.id, ctx, schema, def, res.tmpId, modifyOp, false, false);
100
- }
101
- else if (typeof value.upsert === 'object' && value.upsert !== null) {
102
- dbUpdateFromUpsert(ctx, schema, def, res, ctx.db.upsert(def.inverseTypeName, value.upsert));
103
- }
104
- else {
105
- return new ModifyError(def, value);
106
- }
107
- }
108
- else {
109
- return new ModifyError(def, value);
110
- }
111
- }
112
- //# sourceMappingURL=reference.js.map
@@ -1,16 +0,0 @@
1
- import { ModifyCtx } from '../../../index.js';
2
- import { PropDef, SchemaTypeDef } from '@based/schema/def';
3
- import { ModifyState } from '../ModifyRes.js';
4
- import { ModifyErr, ModifyOp } from '../types.js';
5
- export type RefModifyOpts = {
6
- id?: number | ModifyState;
7
- $index?: number;
8
- } & Record<`$${string}`, any>;
9
- export type RefModify = ModifyState | RefModifyOpts | number;
10
- export type Refs = RefModify[] | {
11
- add?: RefModify[] | RefModify;
12
- delete?: RefModify[] | RefModify;
13
- upsert: RefModify[] | RefModify;
14
- };
15
- export declare function writeReferences(value: any, ctx: ModifyCtx, schema: SchemaTypeDef, def: PropDef, res: ModifyState, mod: ModifyOp): ModifyErr;
16
- export declare const dbUpdateFromUpsert: (ctx: ModifyCtx, schema: SchemaTypeDef, def: PropDef, res: ModifyState, promise: Promise<any>) => void;