@based/db 0.0.71 → 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 (259) 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/mblen.h +40 -0
  9. package/dist/lib/darwin_aarch64/include/selva/selva_string.h +8 -5
  10. package/dist/lib/darwin_aarch64/include/selva/thread.h +37 -0
  11. package/dist/lib/darwin_aarch64/include/selva/types.h +18 -4
  12. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  13. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  14. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  15. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  16. package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
  17. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  18. package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
  19. package/dist/lib/linux_aarch64/include/libdeflate.h +23 -0
  20. package/dist/lib/linux_aarch64/include/selva/db.h +0 -41
  21. package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +6 -2
  22. package/dist/lib/linux_aarch64/include/selva/fields.h +52 -37
  23. package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
  24. package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
  25. package/dist/lib/linux_aarch64/include/selva/selva_string.h +8 -5
  26. package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
  27. package/dist/lib/linux_aarch64/include/selva/types.h +18 -4
  28. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  29. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  30. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  31. package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
  32. package/dist/lib/linux_aarch64/libselva.so +0 -0
  33. package/dist/lib/linux_x86_64/include/libdeflate.h +23 -0
  34. package/dist/lib/linux_x86_64/include/selva/db.h +0 -41
  35. package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +6 -2
  36. package/dist/lib/linux_x86_64/include/selva/fields.h +52 -37
  37. package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
  38. package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
  39. package/dist/lib/linux_x86_64/include/selva/selva_string.h +8 -5
  40. package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
  41. package/dist/lib/linux_x86_64/include/selva/types.h +18 -4
  42. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  43. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  44. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  45. package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
  46. package/dist/lib/linux_x86_64/libselva.so +0 -0
  47. package/dist/src/client/index.d.ts +16 -21
  48. package/dist/src/client/index.js +48 -59
  49. package/dist/src/client/modify/Ctx.d.ts +38 -0
  50. package/dist/src/client/modify/Ctx.js +30 -0
  51. package/dist/src/client/modify/Tmp.d.ts +19 -0
  52. package/dist/src/client/modify/Tmp.js +67 -0
  53. package/dist/src/client/modify/create/index.d.ts +6 -0
  54. package/dist/src/client/modify/create/index.js +191 -0
  55. package/dist/src/client/modify/create/mark.d.ts +7 -0
  56. package/dist/src/client/modify/create/mark.js +42 -0
  57. package/dist/src/client/modify/cursor.d.ts +10 -0
  58. package/dist/src/client/modify/cursor.js +48 -0
  59. package/dist/src/client/modify/delete/index.d.ts +2 -0
  60. package/dist/src/client/modify/delete/index.js +39 -0
  61. package/dist/src/client/modify/drain.d.ts +7 -0
  62. package/dist/src/client/modify/drain.js +77 -0
  63. package/dist/src/client/modify/edges/binary.d.ts +3 -0
  64. package/dist/src/client/modify/edges/binary.js +28 -0
  65. package/dist/src/client/modify/edges/cardinality.d.ts +3 -0
  66. package/dist/src/client/modify/edges/cardinality.js +15 -0
  67. package/dist/src/client/modify/edges/header.d.ts +5 -0
  68. package/dist/src/client/modify/edges/header.js +21 -0
  69. package/dist/src/client/modify/edges/index.d.ts +3 -0
  70. package/dist/src/client/modify/edges/index.js +128 -0
  71. package/dist/src/client/modify/edges/reference.d.ts +3 -0
  72. package/dist/src/client/modify/edges/reference.js +31 -0
  73. package/dist/src/client/modify/edges/references.d.ts +3 -0
  74. package/dist/src/client/modify/edges/references.js +38 -0
  75. package/dist/src/client/modify/edges/separate.d.ts +3 -0
  76. package/dist/src/client/modify/edges/separate.js +24 -0
  77. package/dist/src/client/modify/edges/string.d.ts +3 -0
  78. package/dist/src/client/modify/edges/string.js +30 -0
  79. package/dist/src/client/modify/error.d.ts +7 -0
  80. package/dist/src/client/modify/error.js +68 -0
  81. package/dist/src/client/modify/expire/index.d.ts +2 -0
  82. package/dist/src/client/modify/expire/index.js +31 -0
  83. package/dist/src/client/modify/props/alias.d.ts +3 -0
  84. package/dist/src/client/modify/props/alias.js +26 -0
  85. package/dist/src/client/modify/props/binary.d.ts +5 -0
  86. package/dist/src/client/modify/props/binary.js +52 -0
  87. package/dist/src/client/modify/props/cardinality.d.ts +4 -0
  88. package/dist/src/client/modify/props/cardinality.js +46 -0
  89. package/dist/src/client/modify/props/delete.d.ts +3 -0
  90. package/dist/src/client/modify/props/delete.js +13 -0
  91. package/dist/src/client/modify/props/fixed.d.ts +4 -0
  92. package/dist/src/client/modify/props/fixed.js +105 -0
  93. package/dist/src/client/modify/props/increment.d.ts +3 -0
  94. package/dist/src/client/modify/props/increment.js +28 -0
  95. package/dist/src/client/modify/props/json.d.ts +3 -0
  96. package/dist/src/client/modify/props/json.js +5 -0
  97. package/dist/src/client/modify/props/main.d.ts +4 -0
  98. package/dist/src/client/modify/props/main.js +22 -0
  99. package/dist/src/client/modify/props/object.d.ts +3 -0
  100. package/dist/src/client/modify/props/object.js +37 -0
  101. package/dist/src/client/modify/props/reference.d.ts +6 -0
  102. package/dist/src/client/modify/props/reference.js +92 -0
  103. package/dist/src/client/modify/props/references.d.ts +3 -0
  104. package/dist/src/client/modify/props/references.js +231 -0
  105. package/dist/src/client/modify/props/separate.d.ts +3 -0
  106. package/dist/src/client/modify/props/separate.js +43 -0
  107. package/dist/src/client/modify/props/string.d.ts +5 -0
  108. package/dist/src/client/modify/props/string.js +51 -0
  109. package/dist/src/client/modify/props/text.d.ts +3 -0
  110. package/dist/src/client/modify/props/text.js +35 -0
  111. package/dist/src/client/modify/props/vector.d.ts +3 -0
  112. package/dist/src/client/modify/props/vector.js +30 -0
  113. package/dist/src/client/modify/resize.d.ts +3 -0
  114. package/dist/src/client/modify/resize.js +20 -0
  115. package/dist/src/client/modify/types.d.ts +3 -4
  116. package/dist/src/client/modify/types.js +2 -1
  117. package/dist/src/client/modify/uint.d.ts +7 -0
  118. package/dist/src/client/modify/uint.js +27 -0
  119. package/dist/src/client/modify/update/index.d.ts +3 -0
  120. package/dist/src/client/modify/update/index.js +75 -0
  121. package/dist/src/client/modify/upsert/index.d.ts +3 -0
  122. package/dist/src/client/modify/{upsert.js → upsert/index.js} +4 -4
  123. package/dist/src/client/modify/validate.d.ts +6 -0
  124. package/dist/src/client/modify/validate.js +24 -0
  125. package/dist/src/client/query/BasedDbQuery.d.ts +17 -14
  126. package/dist/src/client/query/BasedDbQuery.js +90 -93
  127. package/dist/src/client/query/{BasedIterable.d.ts → BasedQueryResponse.d.ts} +5 -4
  128. package/dist/src/client/query/{BasedIterable.js → BasedQueryResponse.js} +15 -10
  129. package/dist/src/client/query/aggregates/aggregation.d.ts +5 -3
  130. package/dist/src/client/query/aggregates/aggregation.js +105 -48
  131. package/dist/src/client/query/aggregates/types.d.ts +33 -11
  132. package/dist/src/client/query/aggregates/types.js +29 -11
  133. package/dist/src/client/query/debug.js +1 -1
  134. package/dist/src/client/query/display.d.ts +1 -1
  135. package/dist/src/client/query/display.js +21 -4
  136. package/dist/src/client/query/filter/FilterBranch.js +2 -2
  137. package/dist/src/client/query/filter/convertFilter.d.ts +3 -2
  138. package/dist/src/client/query/filter/convertFilter.js +13 -1
  139. package/dist/src/client/query/filter/createFixedFilterBuffer.js +16 -30
  140. package/dist/src/client/query/filter/createReferenceFilter.js +6 -20
  141. package/dist/src/client/query/filter/createVariableFilterBuffer.js +15 -32
  142. package/dist/src/client/query/filter/parseFilterValue.js +3 -11
  143. package/dist/src/client/query/filter/primitiveFilter.js +1 -1
  144. package/dist/src/client/query/filter/toBuffer.js +9 -15
  145. package/dist/src/client/query/filter/types.d.ts +6 -6
  146. package/dist/src/client/query/filter/types.js +8 -8
  147. package/dist/src/client/query/include/include.d.ts +3 -0
  148. package/dist/src/client/query/include/include.js +58 -0
  149. package/dist/src/client/query/include/props.d.ts +7 -7
  150. package/dist/src/client/query/include/props.js +26 -21
  151. package/dist/src/client/query/include/toByteCode.js +188 -0
  152. package/dist/src/client/query/include/utils.d.ts +3 -1
  153. package/dist/src/client/query/include/utils.js +13 -0
  154. package/dist/src/client/query/include/walk.d.ts +2 -2
  155. package/dist/src/client/query/include/walk.js +38 -23
  156. package/dist/src/client/query/query.d.ts +2 -3
  157. package/dist/src/client/query/query.js +2 -3
  158. package/dist/src/client/query/queryDef.d.ts +4 -2
  159. package/dist/src/client/query/queryDef.js +3 -5
  160. package/dist/src/client/query/queryDefToReadSchema.d.ts +3 -0
  161. package/dist/src/client/query/queryDefToReadSchema.js +126 -0
  162. package/dist/src/client/query/registerQuery.js +15 -4
  163. package/dist/src/client/query/search/index.d.ts +2 -1
  164. package/dist/src/client/query/search/index.js +9 -2
  165. package/dist/src/client/query/sort.js +3 -0
  166. package/dist/src/client/query/subscription/index.d.ts +1 -1
  167. package/dist/src/client/query/subscription/index.js +2 -2
  168. package/dist/src/client/query/subscription/types.d.ts +1 -1
  169. package/dist/src/client/query/thresholds.d.ts +1 -1
  170. package/dist/src/client/query/thresholds.js +1 -1
  171. package/dist/src/client/query/toByteCode/{toBuffer.js → toByteCode.js} +8 -8
  172. package/dist/src/client/query/types.d.ts +40 -25
  173. package/dist/src/client/query/types.js +2 -6
  174. package/dist/src/client/query/validation.d.ts +6 -0
  175. package/dist/src/client/query/validation.js +31 -7
  176. package/dist/src/client/setLocalClientSchema.js +6 -10
  177. package/dist/src/client/string.d.ts +3 -7
  178. package/dist/src/client/string.js +18 -47
  179. package/dist/src/hooks.d.ts +2 -3
  180. package/dist/src/hooks.js +14 -9
  181. package/dist/src/index.d.ts +3 -5
  182. package/dist/src/index.js +4 -6
  183. package/dist/src/native.d.ts +3 -2
  184. package/dist/src/native.js +9 -8
  185. package/dist/src/server/IoWorker.js +2 -3
  186. package/dist/src/server/QueryWorker.js +1 -1
  187. package/dist/src/server/blocks.js +5 -4
  188. package/dist/src/server/dbHash.js +1 -1
  189. package/dist/src/server/index.d.ts +4 -6
  190. package/dist/src/server/index.js +63 -96
  191. package/dist/src/server/migrate/index.d.ts +2 -4
  192. package/dist/src/server/migrate/index.js +31 -16
  193. package/dist/src/server/migrate/worker.js +2 -27
  194. package/dist/src/server/save.js +3 -2
  195. package/dist/src/server/schema.js +9 -19
  196. package/dist/src/server/start.d.ts +1 -0
  197. package/dist/src/server/start.js +18 -10
  198. package/dist/src/server/tree.d.ts +20 -0
  199. package/dist/src/server/tree.js +17 -2
  200. package/dist/src/server/workers/DbWorker.d.ts +1 -0
  201. package/dist/src/server/workers/DbWorker.js +8 -1
  202. package/dist/src/server/workers/io_worker.js +1 -1
  203. package/dist/src/server/workers/worker.js +9 -4
  204. package/dist/src/table.d.ts +4 -0
  205. package/dist/src/table.js +97 -0
  206. package/package.json +18 -17
  207. package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +0 -29
  208. package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -29
  209. package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -29
  210. package/dist/src/client/flushModify.d.ts +0 -36
  211. package/dist/src/client/flushModify.js +0 -197
  212. package/dist/src/client/modify/ModifyRes.d.ts +0 -23
  213. package/dist/src/client/modify/ModifyRes.js +0 -101
  214. package/dist/src/client/modify/alias.d.ts +0 -4
  215. package/dist/src/client/modify/alias.js +0 -57
  216. package/dist/src/client/modify/binary.d.ts +0 -6
  217. package/dist/src/client/modify/binary.js +0 -80
  218. package/dist/src/client/modify/cardinality.d.ts +0 -6
  219. package/dist/src/client/modify/cardinality.js +0 -63
  220. package/dist/src/client/modify/create.d.ts +0 -5
  221. package/dist/src/client/modify/create.js +0 -228
  222. package/dist/src/client/modify/delete.d.ts +0 -4
  223. package/dist/src/client/modify/delete.js +0 -47
  224. package/dist/src/client/modify/expire.d.ts +0 -3
  225. package/dist/src/client/modify/expire.js +0 -25
  226. package/dist/src/client/modify/fixed.d.ts +0 -5
  227. package/dist/src/client/modify/fixed.js +0 -235
  228. package/dist/src/client/modify/index.d.ts +0 -4
  229. package/dist/src/client/modify/index.js +0 -4
  230. package/dist/src/client/modify/json.d.ts +0 -4
  231. package/dist/src/client/modify/json.js +0 -26
  232. package/dist/src/client/modify/modify.d.ts +0 -5
  233. package/dist/src/client/modify/modify.js +0 -134
  234. package/dist/src/client/modify/references/appendEdgeRefs.d.ts +0 -4
  235. package/dist/src/client/modify/references/appendEdgeRefs.js +0 -33
  236. package/dist/src/client/modify/references/edge.d.ts +0 -5
  237. package/dist/src/client/modify/references/edge.js +0 -336
  238. package/dist/src/client/modify/references/getEdgeSize.d.ts +0 -3
  239. package/dist/src/client/modify/references/getEdgeSize.js +0 -27
  240. package/dist/src/client/modify/references/reference.d.ts +0 -11
  241. package/dist/src/client/modify/references/reference.js +0 -124
  242. package/dist/src/client/modify/references/references.d.ts +0 -16
  243. package/dist/src/client/modify/references/references.js +0 -316
  244. package/dist/src/client/modify/setCursor.d.ts +0 -5
  245. package/dist/src/client/modify/setCursor.js +0 -33
  246. package/dist/src/client/modify/string.d.ts +0 -5
  247. package/dist/src/client/modify/string.js +0 -71
  248. package/dist/src/client/modify/text.d.ts +0 -8
  249. package/dist/src/client/modify/text.js +0 -69
  250. package/dist/src/client/modify/update.d.ts +0 -6
  251. package/dist/src/client/modify/update.js +0 -90
  252. package/dist/src/client/modify/upsert.d.ts +0 -3
  253. package/dist/src/client/modify/vector.d.ts +0 -4
  254. package/dist/src/client/modify/vector.js +0 -53
  255. package/dist/src/client/query/include/toBuffer.js +0 -123
  256. package/dist/src/client/query/read/read.d.ts +0 -9
  257. package/dist/src/client/query/read/read.js +0 -483
  258. /package/dist/src/client/query/include/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
  259. /package/dist/src/client/query/toByteCode/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
@@ -0,0 +1,126 @@
1
+ // import type { IncludeOpts, QueryDef, Target } from '@based/db'
2
+ import { inverseLangMap, langCodesMap } from '@based/schema';
3
+ import { COLVEC, ENUM, TEXT, VECTOR, } from '@based/schema/def';
4
+ import { ReaderMeta, ReaderSchemaEnum, } from '@based/protocol/db-read';
5
+ const createReaderPropDef = (p, locales, opts) => {
6
+ const readerPropDef = {
7
+ path: p.__isEdge ? p.path.slice(1) : p.path,
8
+ typeIndex: p.typeIndex,
9
+ readBy: 0,
10
+ };
11
+ if (opts?.meta) {
12
+ readerPropDef.meta =
13
+ opts?.meta === 'only' ? ReaderMeta.only : ReaderMeta.combined;
14
+ }
15
+ if (p.typeIndex === ENUM) {
16
+ readerPropDef.enum = p.enum;
17
+ }
18
+ if (p.typeIndex === VECTOR || p.typeIndex === COLVEC) {
19
+ readerPropDef.vectorBaseType = p.vectorBaseType;
20
+ readerPropDef.len = p.len;
21
+ }
22
+ if (p.typeIndex === TEXT) {
23
+ if (opts.codes.has(0)) {
24
+ readerPropDef.locales = locales;
25
+ }
26
+ else {
27
+ if (opts.codes.size === 1 && opts.codes.has(opts.localeFromDef)) {
28
+ // dont add locales - interpets it as a normal prop
29
+ }
30
+ else {
31
+ readerPropDef.locales = {};
32
+ for (const code of opts.codes) {
33
+ readerPropDef.locales[code] = inverseLangMap.get(code);
34
+ }
35
+ }
36
+ }
37
+ }
38
+ return readerPropDef;
39
+ };
40
+ export const convertToReaderSchema = (q, locales) => {
41
+ if (!locales) {
42
+ locales = {};
43
+ for (const lang in q.schema.locales) {
44
+ locales[langCodesMap.get(lang)] = lang;
45
+ }
46
+ }
47
+ const t = q.type;
48
+ const isRoot = t === 4; // QueryDefType.Root (cant import type enum ofc)
49
+ const isSingle = isRoot && ('id' in q.target || 'alias' in q.target);
50
+ const isEdge = t === 1; // QueryDefType.Edge (cant import type enum ofc)
51
+ const readerSchema = {
52
+ readId: 0,
53
+ props: {},
54
+ main: { len: 0, props: {} },
55
+ refs: {},
56
+ type: isEdge
57
+ ? ReaderSchemaEnum.edge
58
+ : isSingle
59
+ ? q.target.type === '_root'
60
+ ? ReaderSchemaEnum.rootProps
61
+ : ReaderSchemaEnum.single
62
+ : ReaderSchemaEnum.default,
63
+ };
64
+ if (q.aggregate) {
65
+ readerSchema.aggregate = {
66
+ aggregates: [],
67
+ totalResultsSize: q.aggregate.totalResultsSize,
68
+ };
69
+ const a = readerSchema.aggregate;
70
+ for (const aggArray of q.aggregate.aggregates.values()) {
71
+ for (const agg of aggArray) {
72
+ a.aggregates.push({
73
+ path: agg.propDef.path,
74
+ type: agg.type,
75
+ resultPos: agg.resultPos,
76
+ });
77
+ }
78
+ }
79
+ if (q.aggregate.groupBy) {
80
+ a.groupBy = {
81
+ typeIndex: q.aggregate.groupBy.typeIndex,
82
+ };
83
+ if (q.aggregate.groupBy.stepRange) {
84
+ a.groupBy.stepRange = q.aggregate.groupBy.stepRange;
85
+ }
86
+ if (q.aggregate.groupBy.display) {
87
+ a.groupBy.display = q.aggregate.groupBy.display;
88
+ }
89
+ if (q.aggregate.groupBy.enum) {
90
+ a.groupBy.enum = q.aggregate.groupBy.enum;
91
+ }
92
+ if (q.aggregate.groupBy.stepType) {
93
+ a.groupBy.stepType = true;
94
+ }
95
+ }
96
+ }
97
+ else {
98
+ if (q.schema?.hooks?.read) {
99
+ readerSchema.hook = q.schema.hooks.read;
100
+ }
101
+ if (isRoot && q.search) {
102
+ readerSchema.search = true;
103
+ }
104
+ for (const [k, v] of q.include.props) {
105
+ readerSchema.props[k] = createReaderPropDef(v.def, locales, v.opts);
106
+ }
107
+ readerSchema.main.len = q.include.main.len;
108
+ for (const k in q.include.main.include) {
109
+ const [start, p, opts] = q.include.main.include[k];
110
+ readerSchema.main.props[start] = createReaderPropDef(p, locales, opts);
111
+ }
112
+ for (const [k, v] of q.references.entries()) {
113
+ const target = v.target;
114
+ const propDef = target.propDef;
115
+ readerSchema.refs[k] = {
116
+ schema: convertToReaderSchema(v, locales),
117
+ prop: createReaderPropDef(propDef, locales),
118
+ };
119
+ }
120
+ if (q.edges) {
121
+ readerSchema.edges = convertToReaderSchema(q.edges, locales);
122
+ }
123
+ }
124
+ return readerSchema;
125
+ };
126
+ //# sourceMappingURL=queryDefToReadSchema.js.map
@@ -1,15 +1,18 @@
1
1
  import native from '../../native.js';
2
- import { concatUint8Arr } from '@saulx/utils';
3
- import { defToBuffer } from './toByteCode/toBuffer.js';
2
+ import { concatUint8Arr } from '@based/utils';
3
+ import { defToBuffer } from './toByteCode/toByteCode.js';
4
4
  import { handleErrors } from './validation.js';
5
5
  import { createQueryDef } from './queryDef.js';
6
6
  import { QueryDefType } from './types.js';
7
7
  import { includeField } from './query.js';
8
+ import { convertToReaderSchema } from './queryDefToReadSchema.js';
8
9
  export const registerQuery = (q) => {
9
10
  if (!q.id) {
10
11
  const commands = q.queryCommands;
11
12
  q.queryCommands = null;
12
- const def = createQueryDef(q.db, QueryDefType.Root, q.target, q.skipValidation);
13
+ const def = createQueryDef(q.db, QueryDefType.Root,
14
+ // @ts-ignore
15
+ q.target, q.skipValidation);
13
16
  def.schemaChecksum = q.db.schema?.hash || 0;
14
17
  q.def = def;
15
18
  // proposal:
@@ -18,14 +21,22 @@ export const registerQuery = (q) => {
18
21
  }
19
22
  // locale first...
20
23
  if (!q.def.include.stringFields.size && !q.def.references.size) {
21
- includeField(q.def, '*');
24
+ includeField(q.def, { field: '*' });
22
25
  }
23
26
  q.queryCommands = commands;
24
27
  const b = defToBuffer(q.db, q.def);
25
28
  const buf = concatUint8Arr(b);
26
29
  let id = native.crc32(buf);
27
30
  q.id = id;
31
+ def.queryId = q.id;
28
32
  q.buffer = buf;
33
+ // console.log('--------------------------------------------------')
34
+ // console.dir(convertToReaderSchema(q.def), { depth: 100 })
35
+ // console.log(deSerializeSchema(serialize(convertToReaderSchema(q.def))))
36
+ // q.def.readSchema = deSerializeSchema(
37
+ // serialize(convertToReaderSchema(q.def)),
38
+ // )
39
+ q.def.readSchema = convertToReaderSchema(q.def);
29
40
  handleErrors(q.def);
30
41
  return buf;
31
42
  }
@@ -1,8 +1,9 @@
1
1
  import { QueryDefSearch, QueryDef } from '../types.js';
2
2
  import { FilterOpts } from '../filter/types.js';
3
+ import { QueryBranch } from '../BasedDbQuery.js';
3
4
  export type Search = string[] | {
4
5
  [field: string]: number;
5
6
  } | string;
6
7
  export declare const vectorSearch: (def: QueryDef, q: ArrayBufferView, field: string, opts: Omit<FilterOpts, "lowerCase">) => void;
7
- export declare const search: (def: QueryDef, q: string, s?: Search) => void;
8
+ export declare const search: (queryBranch: QueryBranch<any>, q: string, s?: Search) => void;
8
9
  export declare const searchToBuffer: (search: QueryDefSearch) => Uint8Array<ArrayBuffer>;
@@ -2,7 +2,7 @@ import { langCodesMap } from '@based/schema';
2
2
  import { STRING, TEXT, VECTOR } from '@based/schema/def';
3
3
  import { getVectorFn } from '../filter/types.js';
4
4
  import { searchDoesNotExist, searchIncorrecQueryValue, searchIncorrectType, } from '../validation.js';
5
- import { ENCODER, concatUint8Arr } from '@saulx/utils';
5
+ import { ENCODER, concatUint8Arr } from '@based/utils';
6
6
  // vector
7
7
  export const vectorSearch = (def, q, field, opts) => {
8
8
  let prop = def.props[field];
@@ -23,7 +23,8 @@ export const vectorSearch = (def, q, field, opts) => {
23
23
  opts,
24
24
  };
25
25
  };
26
- export const search = (def, q, s) => {
26
+ export const search = (queryBranch, q, s) => {
27
+ const def = queryBranch.def;
27
28
  const bufs = [];
28
29
  let nrBlocks = 0;
29
30
  let totalByteLength = 1;
@@ -110,6 +111,12 @@ export const search = (def, q, s) => {
110
111
  start: prop.start ?? 0, // also need lang ofc if you have start
111
112
  });
112
113
  }
114
+ const searchHook = def.schema.hooks?.search;
115
+ if (searchHook) {
116
+ def.schema.hooks.search = null;
117
+ searchHook(queryBranch, new Set(Object.keys(s)));
118
+ def.schema.hooks.search = searchHook;
119
+ }
113
120
  };
114
121
  export const searchToBuffer = (search) => {
115
122
  if (search.isVector) {
@@ -14,6 +14,9 @@ export const createSortBuffer = (sort) => {
14
14
  };
15
15
  // NO REF / REFERENCES SUPPORT
16
16
  export const sort = (def, field, order) => {
17
+ if (field === 'id' && order === 'asc') {
18
+ return;
19
+ }
17
20
  def.sort = validateSort(def, field, order);
18
21
  };
19
22
  //# sourceMappingURL=sort.js.map
@@ -1,5 +1,5 @@
1
1
  import { BasedDbQuery } from '../BasedDbQuery.js';
2
- import { BasedQueryResponse } from '../BasedIterable.js';
2
+ import { BasedQueryResponse } from '../BasedQueryResponse.js';
3
3
  import { OnData, OnError, OnClose } from './types.js';
4
4
  export declare class SubStore {
5
5
  listeners: Map<OnData, OnError>;
@@ -1,4 +1,4 @@
1
- import { BasedQueryResponse } from '../BasedIterable.js';
1
+ import { BasedQueryResponse } from '../BasedQueryResponse.js';
2
2
  import { registerQuery } from '../registerQuery.js';
3
3
  export class SubStore {
4
4
  listeners;
@@ -9,7 +9,7 @@ export class SubStore {
9
9
  subscribe(q) {
10
10
  const onData = (res) => {
11
11
  if (!this.response) {
12
- this.response = new BasedQueryResponse(q.id, q.def, res, 0);
12
+ this.response = new BasedQueryResponse(q.def, res, 0);
13
13
  }
14
14
  else {
15
15
  this.response.result = res;
@@ -1,4 +1,4 @@
1
- import { BasedQueryResponse } from '../BasedIterable.js';
1
+ import { BasedQueryResponse } from '../BasedQueryResponse.js';
2
2
  export type OnData = (res: BasedQueryResponse) => any;
3
3
  export type OnError = (err: Error) => any;
4
4
  export type OnClose = () => any;
@@ -1,4 +1,4 @@
1
1
  export declare const MAX_IDS_PER_QUERY = 1000000;
2
2
  export declare const DEF_RANGE_PROP_LIMIT = 1000;
3
- export declare const DEF_RANGE_REF_LIMIT = 10000;
3
+ export declare const DEF_RANGE_REF_LIMIT = 1000;
4
4
  export declare const MIN_ID_VALUE = 1;
@@ -1,7 +1,7 @@
1
1
  // Query thresholds
2
2
  export const MAX_IDS_PER_QUERY = 1e6; // Max number of IDs that can be queried at once
3
3
  export const DEF_RANGE_PROP_LIMIT = 1e3;
4
- export const DEF_RANGE_REF_LIMIT = 1e4;
4
+ export const DEF_RANGE_REF_LIMIT = 1e3;
5
5
  // Data validation thresholds
6
6
  export const MIN_ID_VALUE = 1; // Minimum allowed value for an ID (id array stared)
7
7
  //# sourceMappingURL=thresholds.js.map
@@ -1,9 +1,9 @@
1
1
  import { createSortBuffer } from '../sort.js';
2
2
  import { QueryDefType, QueryType } from '../types.js';
3
- import { includeToBuffer } from '../include/toBuffer.js';
3
+ import { includeToBuffer } from '../include/toByteCode.js';
4
4
  import { filterToBuffer } from '../query.js';
5
5
  import { searchToBuffer } from '../search/index.js';
6
- import { ENCODER, writeUint64 } from '@saulx/utils';
6
+ import { ENCODER, writeUint64 } from '@based/utils';
7
7
  import { aggregateToBuffer, isRootCountOnly, } from '../aggregates/aggregation.js';
8
8
  import { defaultQuery } from './default.js';
9
9
  const byteSize = (arr) => {
@@ -42,7 +42,7 @@ export function defToBuffer(db, def) {
42
42
  if (def.type === QueryDefType.References) {
43
43
  const buf = new Uint8Array(13 + filterSize + aggregateSize);
44
44
  const sz = 10 + filterSize + aggregateSize;
45
- buf[0] = 251 /* includeOp.REFERENCES_AGGREGATION */;
45
+ buf[0] = 2 /* includeOp.REFERENCES_AGGREGATION */;
46
46
  buf[1] = sz;
47
47
  buf[2] = sz >>> 8;
48
48
  buf[3] = filterSize;
@@ -122,7 +122,7 @@ export function defToBuffer(db, def) {
122
122
  }
123
123
  result.push(buf);
124
124
  }
125
- else if (def.target.id) {
125
+ else if (typeof def.target.id === 'number') {
126
126
  const buf = new Uint8Array(9 + filterSize);
127
127
  buf[0] = QueryType.id;
128
128
  buf[1] = def.schema.idUint8[0];
@@ -203,7 +203,7 @@ export function defToBuffer(db, def) {
203
203
  const modsSize = filterSize + sortSize;
204
204
  const meta = new Uint8Array(modsSize + 10 + 8);
205
205
  const sz = size + 7 + modsSize + 8;
206
- meta[0] = 254 /* includeOp.REFERENCES */;
206
+ meta[0] = 4 /* includeOp.REFERENCES */;
207
207
  meta[1] = sz;
208
208
  meta[2] = sz >>> 8;
209
209
  meta[3] = filterSize;
@@ -232,7 +232,7 @@ export function defToBuffer(db, def) {
232
232
  else if (def.type === QueryDefType.Reference) {
233
233
  const meta = new Uint8Array(6);
234
234
  const sz = size + 3;
235
- meta[0] = 255 /* includeOp.REFERENCE */;
235
+ meta[0] = 5 /* includeOp.REFERENCE */;
236
236
  meta[1] = sz;
237
237
  meta[2] = sz >>> 8;
238
238
  meta[3] = def.schema.idUint8[0];
@@ -243,7 +243,7 @@ export function defToBuffer(db, def) {
243
243
  result.push(...include);
244
244
  if (edges) {
245
245
  const metaEdgeBuffer = new Uint8Array(3);
246
- metaEdgeBuffer[0] = 252 /* includeOp.EDGE */;
246
+ metaEdgeBuffer[0] = 3 /* includeOp.EDGE */;
247
247
  metaEdgeBuffer[1] = edgesSize;
248
248
  metaEdgeBuffer[2] = edgesSize >>> 8;
249
249
  result.push(metaEdgeBuffer, ...edges);
@@ -255,4 +255,4 @@ export function defToBuffer(db, def) {
255
255
  }
256
256
  return result;
257
257
  }
258
- //# sourceMappingURL=toBuffer.js.map
258
+ //# sourceMappingURL=toByteCode.js.map
@@ -2,9 +2,24 @@ import { LangCode, LangName } from '@based/schema';
2
2
  import { PropDef, PropDefEdge, SchemaTypeDef } from '@based/schema/def';
3
3
  import { FilterOpts } from './filter/types.js';
4
4
  import { QueryError } from './validation.js';
5
- import { AggregateType } from './aggregates/types.js';
5
+ import { Interval, aggFnOptions } from './aggregates/types.js';
6
+ import { AggregateType, ReaderSchema } from '@based/protocol/db-read';
7
+ export type IncludeOpts = {
8
+ end?: {
9
+ [langCode: string]: number;
10
+ } | number;
11
+ bytes?: boolean;
12
+ meta?: 'only' | true | false;
13
+ codes?: Set<LangCode>;
14
+ fallBacks?: LangCode[];
15
+ localeFromDef?: LangCode;
16
+ };
17
+ export type IncludeField = {
18
+ field: string;
19
+ opts?: IncludeOpts;
20
+ };
6
21
  export type MainIncludes = {
7
- [start: string]: [number, PropDef];
22
+ [start: string]: [number, PropDef, IncludeOpts];
8
23
  };
9
24
  export type IncludeTreeArr = (string | PropDef | IncludeTreeArr)[];
10
25
  export declare enum QueryType {
@@ -26,7 +41,7 @@ export type EdgeTarget = {
26
41
  };
27
42
  export type Target = {
28
43
  type: string;
29
- id?: number | void;
44
+ id?: number | void | Promise<number>;
30
45
  ids?: Uint32Array | void;
31
46
  propDef?: PropDef | PropDefEdge;
32
47
  alias?: QueryByAliasObj;
@@ -85,13 +100,21 @@ export type Aggregation = {
85
100
  };
86
101
  export type QueryDefAggregation = {
87
102
  size: number;
88
- groupBy?: PropDef;
103
+ groupBy?: aggPropDef;
89
104
  aggregates: Map<number, Aggregation[]>;
105
+ option?: aggFnOptions;
90
106
  totalResultsSize: number;
91
107
  totalAccumulatorSize: number;
92
108
  };
109
+ export interface aggPropDef extends PropDef {
110
+ stepType?: Interval;
111
+ stepRange?: number;
112
+ tz?: number;
113
+ display?: Intl.DateTimeFormat;
114
+ }
93
115
  export type LangFallback = LangName | false;
94
116
  export type QueryDefShared = {
117
+ queryId?: number;
95
118
  schemaChecksum?: number;
96
119
  errors: QueryError[];
97
120
  lang: {
@@ -108,31 +131,25 @@ export type QueryDefShared = {
108
131
  limit: number;
109
132
  };
110
133
  include: {
111
- langTextFields: Map<number, // prop name
112
- {
134
+ stringFields: Map<string, IncludeField>;
135
+ props: Map<number, {
113
136
  def: PropDef | PropDefEdge;
114
- codes: Set<LangCode>;
115
- fallBacks: LangCode[];
137
+ opts?: IncludeOpts;
116
138
  }>;
117
- stringFields: Set<string>;
118
- props: Map<number, PropDef | PropDefEdge>;
119
- propsRead: {
120
- [propName: number]: number;
121
- };
122
139
  main: {
123
140
  include: MainIncludes;
124
141
  len: number;
125
142
  };
126
143
  };
127
144
  references: Map<number, QueryDef>;
128
- edges?: QueryDef;
145
+ edges?: QueryDefEdges;
146
+ readSchema?: ReaderSchema;
129
147
  };
130
148
  export type QueryDefEdges = {
131
149
  type: QueryDefType.Edge;
132
150
  target: EdgeTarget;
133
151
  schema: null;
134
152
  props: PropDef['edges'];
135
- reverseProps: PropDef['edges'];
136
153
  } & QueryDefShared;
137
154
  export type QueryDefRest = {
138
155
  type: QueryDefType.References | QueryDefType.Reference | QueryDefType.Root;
@@ -146,15 +163,13 @@ export { QueryDefType };
146
163
  export type QueryByAliasObj = {
147
164
  [key: string]: string | QueryByAliasObj;
148
165
  };
149
- export declare const isAlias: (id: QueryByAliasObj | number | Uint32Array | (QueryByAliasObj | number)[]) => id is QueryByAliasObj;
150
- export declare const READ_ID = 255;
151
- export declare const READ_EDGE = 252;
152
- export declare const READ_REFERENCES = 253;
153
- export declare const READ_REFERENCE = 254;
154
- export declare const READ_AGGREGATION = 250;
166
+ export declare const isAlias: (id: Promise<number> | QueryByAliasObj | number | Uint32Array | (QueryByAliasObj | number | Promise<number>)[]) => id is QueryByAliasObj;
155
167
  export declare const enum includeOp {
156
- REFERENCES_AGGREGATION = 251,
157
- EDGE = 252,
158
- REFERENCES = 254,
159
- REFERENCE = 255
168
+ DEFAULT = 1,
169
+ REFERENCES_AGGREGATION = 2,
170
+ EDGE = 3,
171
+ REFERENCES = 4,
172
+ REFERENCE = 5,
173
+ META = 6,// this can be a small buffer as well
174
+ PARTIAL = 7
160
175
  }
@@ -25,11 +25,7 @@ export const isAlias = (id) => {
25
25
  return (typeof id === 'object' &&
26
26
  id !== null &&
27
27
  !Array.isArray(id) &&
28
- !ArrayBuffer.isView(id));
28
+ !ArrayBuffer.isView(id) &&
29
+ typeof id.then !== 'function');
29
30
  };
30
- export const READ_ID = 255;
31
- export const READ_EDGE = 252;
32
- export const READ_REFERENCES = 253;
33
- export const READ_REFERENCE = 254;
34
- export const READ_AGGREGATION = 250;
35
31
  //# sourceMappingURL=types.js.map
@@ -2,6 +2,7 @@ import { PropDef, PropDefEdge, SchemaTypeDef } from '@based/schema/def';
2
2
  import { DbClient } from '../index.js';
3
3
  import { Filter } from './query.js';
4
4
  import { QueryByAliasObj, QueryDef } from './types.js';
5
+ import { StepInput } from './aggregates/types.js';
5
6
  export type QueryError = {
6
7
  code: number;
7
8
  payload: any;
@@ -32,6 +33,8 @@ export declare const ERR_SEARCH_INCORRECT_VALUE = 23;
32
33
  export declare const ERR_SORT_LANG = 24;
33
34
  export declare const ERR_AGG_ENOENT = 25;
34
35
  export declare const ERR_AGG_TYPE = 26;
36
+ export declare const ERR_AGG_INVALID_STEP_TYPE = 27;
37
+ export declare const ERR_AGG_INVALID_STEP_RANGE = 28;
35
38
  declare const messages: {
36
39
  1: (p: any) => string;
37
40
  2: (p: any) => string;
@@ -59,6 +62,8 @@ declare const messages: {
59
62
  24: (p: any) => string;
60
63
  25: (p: any) => string;
61
64
  26: (p: any) => string;
65
+ 27: (p: any) => string;
66
+ 28: (p: any) => string;
62
67
  };
63
68
  export type ErrorCode = keyof typeof messages;
64
69
  export declare const searchIncorrecQueryValue: (def: QueryDef, payload: any) => void;
@@ -88,4 +93,5 @@ export declare const ERROR_VECTOR: PropDef;
88
93
  export declare const EMPTY_SCHEMA_DEF: SchemaTypeDef;
89
94
  export declare const aggregationFieldDoesNotExist: (def: QueryDef, field: string) => void;
90
95
  export declare const aggregationFieldNotNumber: (def: QueryDef, field: string) => void;
96
+ export declare const validateStepRange: (def: QueryDef, step: StepInput) => void;
91
97
  export {};
@@ -1,6 +1,6 @@
1
1
  import picocolors from 'picocolors';
2
- import { ALIAS, BINARY, BOOLEAN, REFERENCE, REFERENCES, REVERSE_TYPE_INDEX_MAP, STRING, TEXT, TIMESTAMP, VECTOR, propIsNumerical, createEmptyDef, DEFAULT_MAP, } from '@based/schema/def';
3
- import { EQUAL, EXISTS, HAS, isNumerical, LIKE, operatorReverseMap, VECTOR_FNS, } from './filter/types.js';
2
+ import { ALIAS, BINARY, BOOLEAN, REFERENCE, REFERENCES, REVERSE_TYPE_INDEX_MAP, STRING, TEXT, TIMESTAMP, VECTOR, propIsNumerical, createEmptyDef, DEFAULT_MAP, ID_FIELD_DEF, } from '@based/schema/def';
3
+ import { EQUAL, EXISTS, INCLUDES, isNumerical, LIKE, operatorReverseMap, VECTOR_FNS, } from './filter/types.js';
4
4
  import { MAX_IDS_PER_QUERY } from './thresholds.js';
5
5
  import { displayTarget, safeStringify } from './display.js';
6
6
  import { isValidId, isValidString, langCodesMap, MAX_ID, } from '@based/schema';
@@ -30,6 +30,8 @@ export const ERR_SEARCH_INCORRECT_VALUE = 23;
30
30
  export const ERR_SORT_LANG = 24;
31
31
  export const ERR_AGG_ENOENT = 25;
32
32
  export const ERR_AGG_TYPE = 26;
33
+ export const ERR_AGG_INVALID_STEP_TYPE = 27;
34
+ export const ERR_AGG_INVALID_STEP_RANGE = 28;
33
35
  const messages = {
34
36
  [ERR_TARGET_INVAL_TYPE]: (p) => `Type "${p}" does not exist`,
35
37
  [ERR_TARGET_INVAL_ALIAS]: (p) => {
@@ -54,8 +56,8 @@ const messages = {
54
56
  [ERR_SORT_WRONG_TARGET]: (p) => `Sort: incorrect qeury target "${displayTarget(p)}"`,
55
57
  [ERR_SORT_ORDER]: (p) => `Sort: incorrect order option "${safeStringify(p.order)}" passed to sort "${p.field}"`,
56
58
  [ERR_SORT_TYPE]: (p) => `Sort: cannot sort on type "${REVERSE_TYPE_INDEX_MAP[p.typeIndex]}" on field "${p.path.join('.')}"`,
57
- [ERR_RANGE_INVALID_OFFSET]: (p) => `Range: incorrect offset "${safeStringify(p)}"`,
58
- [ERR_RANGE_INVALID_LIMIT]: (p) => `Range: incorrect limit "${safeStringify(p)}"`,
59
+ [ERR_RANGE_INVALID_OFFSET]: (p) => `Range: incorrect start "${safeStringify(p)}"`,
60
+ [ERR_RANGE_INVALID_LIMIT]: (p) => `Range: incorrect end "${safeStringify(p)}"`,
59
61
  [ERR_INVALID_LANG]: (p) => `Invalid locale "${p}"`,
60
62
  [ERR_SEARCH_ENOENT]: (p) => `Search: field does not exist "${p}"`,
61
63
  [ERR_SEARCH_TYPE]: (p) => `Search: incorrect type "${p.path.join('.')}"`,
@@ -63,6 +65,8 @@ const messages = {
63
65
  [ERR_SORT_LANG]: (p) => `Sort: invalid lang`,
64
66
  [ERR_AGG_ENOENT]: (p) => `Field \"${p}\" in the aggregate function is invalid or unreacheable.`,
65
67
  [ERR_AGG_TYPE]: (p) => `Aggregate: incorrect type "${p.path.join('.')}"`,
68
+ [ERR_AGG_INVALID_STEP_TYPE]: (p) => `Aggregate: Incorrect step type "${p}"`,
69
+ [ERR_AGG_INVALID_STEP_RANGE]: (p) => `Aggregate: Incorrect step range "${p}". Step ranges are limited to uint32 max value in seconds => group by ~136 years.`,
66
70
  };
67
71
  export const searchIncorrecQueryValue = (def, payload) => {
68
72
  def.errors.push({ code: ERR_SEARCH_INCORRECT_VALUE, payload });
@@ -87,6 +91,18 @@ export const validateRange = (def, offset, limit) => {
87
91
  def.errors.push({ code: ERR_RANGE_INVALID_LIMIT, payload: limit });
88
92
  r = true;
89
93
  }
94
+ if (limit === 0) {
95
+ def.errors.push({ code: ERR_RANGE_INVALID_OFFSET, payload: offset });
96
+ r = true;
97
+ }
98
+ if (limit % 1 !== 0) {
99
+ def.errors.push({ code: ERR_RANGE_INVALID_LIMIT, payload: limit });
100
+ r = true;
101
+ }
102
+ if (offset % 1 !== 0) {
103
+ def.errors.push({ code: ERR_RANGE_INVALID_OFFSET, payload: offset });
104
+ r = true;
105
+ }
90
106
  return r;
91
107
  };
92
108
  export const validateVal = (def, f, validate) => {
@@ -166,7 +182,7 @@ export const validateFilter = (def, prop, f) => {
166
182
  }
167
183
  }
168
184
  else if (t === VECTOR) {
169
- if (isNumerical(op) || op === HAS) {
185
+ if (isNumerical(op) || op === INCLUDES) {
170
186
  def.errors.push({ code: ERR_FILTER_OP_FIELD, payload: f });
171
187
  return true;
172
188
  }
@@ -266,7 +282,7 @@ export const validateLocale = (def, lang) => {
266
282
  }
267
283
  };
268
284
  export const validateSort = (def, field, orderInput) => {
269
- let propDef = def.props[field];
285
+ let propDef = field === 'id' ? ID_FIELD_DEF : def.props[field];
270
286
  if (orderInput && orderInput !== 'asc' && orderInput !== 'desc') {
271
287
  def.errors.push({
272
288
  code: ERR_SORT_ORDER,
@@ -274,7 +290,6 @@ export const validateSort = (def, field, orderInput) => {
274
290
  });
275
291
  }
276
292
  const order = orderInput === 'asc' || orderInput === undefined ? 0 : 1;
277
- // IF ! FIX
278
293
  let lang = 0;
279
294
  if (!propDef) {
280
295
  let isText = false;
@@ -483,4 +498,13 @@ export const aggregationFieldNotNumber = (def, field) => {
483
498
  });
484
499
  handleErrors(def);
485
500
  };
501
+ export const validateStepRange = (def, step) => {
502
+ if (typeof step !== 'number' || step >= 4294967296) {
503
+ def.errors.push({
504
+ code: ERR_AGG_INVALID_STEP_RANGE,
505
+ payload: step,
506
+ });
507
+ handleErrors(def);
508
+ }
509
+ };
486
510
  //# sourceMappingURL=validation.js.map
@@ -1,5 +1,6 @@
1
- import { schemaToSelvaBuffer, updateTypeDefs } from '@based/schema/def';
2
- import { execCtxQueue } from './flushModify.js';
1
+ import { updateTypeDefs } from '@based/schema/def';
2
+ import { cancel } from './modify/drain.js';
3
+ import { Ctx } from './modify/Ctx.js';
3
4
  export const setLocalClientSchema = (client, schema) => {
4
5
  if (client.schema && client.schema.hash === schema.hash) {
5
6
  return client.schema;
@@ -8,16 +9,11 @@ export const setLocalClientSchema = (client, schema) => {
8
9
  client.schema = schema;
9
10
  client.schemaTypesParsed = schemaTypesParsed;
10
11
  client.schemaTypesParsedById = schemaTypesParsedById;
11
- // Adds bidrectional refs on defs
12
- schemaToSelvaBuffer(client.schemaTypesParsed);
13
- // this has to happen before the listeners
14
- if (client.modifyCtx.len > 8) {
12
+ if (client.modifyCtx.index > 8) {
15
13
  console.info('Modify cancelled - schema updated');
16
14
  }
17
- // cancel modify queue
18
- const resCtx = client.modifyCtx.ctx;
19
- client.modifyCtx.reset();
20
- execCtxQueue(resCtx, true);
15
+ cancel(client.modifyCtx, Error('Schema changed - in-flight modify cancelled'));
16
+ client.modifyCtx = new Ctx(schema.hash, client.modifyCtx.array);
21
17
  // resubscribe
22
18
  for (const [q, store] of client.subs) {
23
19
  store.resubscribe(q);
@@ -1,8 +1,4 @@
1
- import { LangCode } from '@based/schema';
2
- export declare const COMPRESSED = 1;
3
- export declare const NOT_COMPRESSED = 0;
4
- export declare const write: (buf: Uint8Array, value: string, offset: number, noCompression: boolean, lang?: LangCode) => number;
1
+ import type { LangCode } from '@based/schema';
2
+ import { Ctx } from './modify/Ctx.js';
3
+ export declare const write: (ctx: Ctx, value: string, offset: number, noCompression: boolean, lang?: LangCode) => number | null;
5
4
  export declare const compress: (str: string) => Uint8Array;
6
- export declare const decompress: (val: Uint8Array) => string;
7
- export declare const read: (val: Uint8Array, offset: number, len: number, stripCrc32: boolean) => string;
8
- export declare const readUtf8: (val: Uint8Array, offset: number, len: number) => string;