@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.
- package/README.md +43 -0
- package/dist/lib/darwin_aarch64/include/cdefs.h +317 -0
- package/dist/lib/darwin_aarch64/include/libdeflate.h +322 -0
- package/dist/lib/darwin_aarch64/include/libdeflate_strings.h +35 -0
- package/dist/lib/darwin_aarch64/include/linker_set.h +109 -0
- package/dist/lib/darwin_aarch64/include/queue.h +627 -0
- package/dist/lib/darwin_aarch64/include/selva/_export.h +7 -0
- package/dist/lib/darwin_aarch64/include/selva/align.h +9 -0
- package/dist/lib/darwin_aarch64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/darwin_aarch64/include/selva/base64.h +59 -0
- package/dist/lib/darwin_aarch64/include/selva/base64url.h +59 -0
- package/dist/lib/darwin_aarch64/include/selva/bitmap.h +95 -0
- package/dist/lib/darwin_aarch64/include/selva/crc32c.h +17 -0
- package/dist/lib/darwin_aarch64/include/selva/ctime.h +135 -0
- package/dist/lib/darwin_aarch64/include/selva/db.h +284 -0
- package/dist/lib/darwin_aarch64/include/selva/endian.h +301 -0
- package/dist/lib/darwin_aarch64/include/selva/fast_linear_search.h +23 -0
- package/dist/lib/darwin_aarch64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/darwin_aarch64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/darwin_aarch64/include/selva/fields.h +338 -0
- package/dist/lib/darwin_aarch64/include/selva/find.h +47 -0
- package/dist/lib/darwin_aarch64/include/selva/lpf.h +28 -0
- package/dist/lib/darwin_aarch64/include/selva/node_id_set.h +43 -0
- package/dist/lib/darwin_aarch64/include/selva/poptop.h +114 -0
- package/dist/lib/darwin_aarch64/include/selva/queue_r.h +190 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_hash128.h +39 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_lang.h +105 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_math.h +37 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_string.h +672 -0
- package/dist/lib/darwin_aarch64/include/selva/sort.h +119 -0
- package/dist/lib/darwin_aarch64/include/selva/strsearch.h +43 -0
- package/dist/lib/darwin_aarch64/include/selva/timestamp.h +25 -0
- package/dist/lib/darwin_aarch64/include/selva/traverse.h +65 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +110 -0
- package/dist/lib/darwin_aarch64/include/selva/vector.h +14 -0
- package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +13 -0
- package/dist/lib/darwin_aarch64/include/selva_error.h +137 -0
- package/dist/lib/darwin_aarch64/include/selva_lang_code.h +157 -0
- package/dist/lib/darwin_aarch64/include/tree.h +852 -0
- package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
- package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.11.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.8.0.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.0.8.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.0.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/lib/linux_aarch64/include/cdefs.h +317 -0
- package/dist/lib/linux_aarch64/include/libdeflate.h +322 -0
- package/dist/lib/linux_aarch64/include/libdeflate_strings.h +35 -0
- package/dist/lib/linux_aarch64/include/linker_set.h +109 -0
- package/dist/lib/linux_aarch64/include/queue.h +627 -0
- package/dist/lib/linux_aarch64/include/selva/_export.h +7 -0
- package/dist/lib/linux_aarch64/include/selva/align.h +9 -0
- package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/linux_aarch64/include/selva/base64.h +59 -0
- package/dist/lib/linux_aarch64/include/selva/base64url.h +59 -0
- package/dist/lib/linux_aarch64/include/selva/bitmap.h +95 -0
- package/dist/lib/linux_aarch64/include/selva/crc32c.h +17 -0
- package/dist/lib/linux_aarch64/include/selva/ctime.h +135 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +284 -0
- package/dist/lib/linux_aarch64/include/selva/endian.h +301 -0
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +23 -0
- package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/linux_aarch64/include/selva/fields.h +338 -0
- package/dist/lib/linux_aarch64/include/selva/find.h +47 -0
- package/dist/lib/linux_aarch64/include/selva/lpf.h +28 -0
- package/dist/lib/linux_aarch64/include/selva/node_id_set.h +43 -0
- package/dist/lib/linux_aarch64/include/selva/poptop.h +114 -0
- package/dist/lib/linux_aarch64/include/selva/queue_r.h +190 -0
- package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +39 -0
- package/dist/lib/linux_aarch64/include/selva/selva_lang.h +105 -0
- package/dist/lib/linux_aarch64/include/selva/selva_math.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +672 -0
- package/dist/lib/linux_aarch64/include/selva/sort.h +119 -0
- package/dist/lib/linux_aarch64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_aarch64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_aarch64/include/selva/traverse.h +65 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +110 -0
- package/dist/lib/linux_aarch64/include/selva/vector.h +14 -0
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +13 -0
- package/dist/lib/linux_aarch64/include/selva_error.h +137 -0
- package/dist/lib/linux_aarch64/include/selva_lang_code.h +157 -0
- package/dist/lib/linux_aarch64/include/tree.h +852 -0
- package/dist/lib/linux_aarch64/libdeflate.so +0 -0
- package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.11.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0.8.2 +0 -0
- package/dist/lib/linux_x86_64/include/cdefs.h +317 -0
- package/dist/lib/linux_x86_64/include/libdeflate.h +322 -0
- package/dist/lib/linux_x86_64/include/libdeflate_strings.h +35 -0
- package/dist/lib/linux_x86_64/include/linker_set.h +109 -0
- package/dist/lib/linux_x86_64/include/queue.h +627 -0
- package/dist/lib/linux_x86_64/include/selva/_export.h +7 -0
- package/dist/lib/linux_x86_64/include/selva/align.h +9 -0
- package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/linux_x86_64/include/selva/base64.h +59 -0
- package/dist/lib/linux_x86_64/include/selva/base64url.h +59 -0
- package/dist/lib/linux_x86_64/include/selva/bitmap.h +95 -0
- package/dist/lib/linux_x86_64/include/selva/crc32c.h +17 -0
- package/dist/lib/linux_x86_64/include/selva/ctime.h +135 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +284 -0
- package/dist/lib/linux_x86_64/include/selva/endian.h +301 -0
- package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +23 -0
- package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/linux_x86_64/include/selva/fields.h +338 -0
- package/dist/lib/linux_x86_64/include/selva/find.h +47 -0
- package/dist/lib/linux_x86_64/include/selva/lpf.h +28 -0
- package/dist/lib/linux_x86_64/include/selva/node_id_set.h +43 -0
- package/dist/lib/linux_x86_64/include/selva/poptop.h +114 -0
- package/dist/lib/linux_x86_64/include/selva/queue_r.h +190 -0
- package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +39 -0
- package/dist/lib/linux_x86_64/include/selva/selva_lang.h +105 -0
- package/dist/lib/linux_x86_64/include/selva/selva_math.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +672 -0
- package/dist/lib/linux_x86_64/include/selva/sort.h +119 -0
- package/dist/lib/linux_x86_64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_x86_64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_x86_64/include/selva/traverse.h +65 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +110 -0
- package/dist/lib/linux_x86_64/include/selva/vector.h +14 -0
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +13 -0
- package/dist/lib/linux_x86_64/include/selva_error.h +137 -0
- package/dist/lib/linux_x86_64/include/selva_lang_code.h +157 -0
- package/dist/lib/linux_x86_64/include/tree.h +852 -0
- package/dist/lib/linux_x86_64/libdeflate.so +0 -0
- package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.11.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0.8.2 +0 -0
- package/dist/src/client/crc32.d.ts +1 -0
- package/dist/src/client/crc32.js +281 -0
- package/dist/src/client/index.d.ts +58 -0
- package/dist/src/client/index.js +120 -0
- package/dist/src/client/modify/ModifyRes.d.ts +26 -0
- package/dist/src/client/modify/ModifyRes.js +98 -0
- package/dist/src/client/modify/alias.d.ts +4 -0
- package/dist/src/client/modify/alias.js +47 -0
- package/dist/src/client/modify/binary.d.ts +6 -0
- package/dist/src/client/modify/binary.js +61 -0
- package/dist/src/client/modify/create.d.ts +4 -0
- package/dist/src/client/modify/create.js +108 -0
- package/dist/src/client/modify/fixed.d.ts +5 -0
- package/dist/src/client/modify/fixed.js +118 -0
- package/dist/src/client/modify/hll.d.ts +4 -0
- package/dist/src/client/modify/hll.js +58 -0
- package/dist/src/client/modify/index.d.ts +4 -0
- package/dist/src/client/modify/index.js +4 -0
- package/dist/src/client/modify/modify.d.ts +5 -0
- package/dist/src/client/modify/modify.js +126 -0
- package/dist/src/client/modify/references/edge.d.ts +6 -0
- package/dist/src/client/modify/references/edge.js +158 -0
- package/dist/src/client/modify/references/reference.d.ts +11 -0
- package/dist/src/client/modify/references/reference.js +92 -0
- package/dist/src/client/modify/references/references.d.ts +17 -0
- package/dist/src/client/modify/references/references.js +271 -0
- package/dist/src/client/modify/remove.d.ts +2 -0
- package/dist/src/client/modify/remove.js +36 -0
- package/dist/src/client/modify/setCursor.d.ts +4 -0
- package/dist/src/client/modify/setCursor.js +36 -0
- package/dist/src/client/modify/string.d.ts +5 -0
- package/dist/src/client/modify/string.js +56 -0
- package/dist/src/client/modify/text.d.ts +5 -0
- package/dist/src/client/modify/text.js +14 -0
- package/dist/src/client/modify/types.d.ts +14 -0
- package/dist/src/client/modify/types.js +12 -0
- package/dist/src/client/modify/update.d.ts +5 -0
- package/dist/src/client/modify/update.js +80 -0
- package/dist/src/client/modify/upsert.d.ts +2 -0
- package/dist/src/client/modify/upsert.js +40 -0
- package/dist/src/client/operations.d.ts +31 -0
- package/dist/src/client/operations.js +110 -0
- package/dist/src/client/query/BasedDbQuery.d.ts +40 -0
- package/dist/src/client/query/BasedDbQuery.js +235 -0
- package/dist/src/client/query/BasedIterable.d.ts +26 -0
- package/dist/src/client/query/BasedIterable.js +113 -0
- package/dist/src/client/query/debug.d.ts +3 -0
- package/dist/src/client/query/debug.js +117 -0
- package/dist/src/client/query/display.d.ts +5 -0
- package/dist/src/client/query/display.js +233 -0
- package/dist/src/client/query/filter/FilterBranch.d.ts +13 -0
- package/dist/src/client/query/filter/FilterBranch.js +29 -0
- package/dist/src/client/query/filter/createFixedFilterBuffer.d.ts +3 -0
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +101 -0
- package/dist/src/client/query/filter/createReferenceFilter.d.ts +2 -0
- package/dist/src/client/query/filter/createReferenceFilter.js +24 -0
- package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -0
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +81 -0
- package/dist/src/client/query/filter/filter.d.ts +10 -0
- package/dist/src/client/query/filter/filter.js +134 -0
- package/dist/src/client/query/filter/operators.d.ts +6 -0
- package/dist/src/client/query/filter/operators.js +98 -0
- package/dist/src/client/query/filter/parseFilterValue.d.ts +2 -0
- package/dist/src/client/query/filter/parseFilterValue.js +99 -0
- package/dist/src/client/query/filter/primitiveFilter.d.ts +4 -0
- package/dist/src/client/query/filter/primitiveFilter.js +47 -0
- package/dist/src/client/query/filter/toBuffer.d.ts +3 -0
- package/dist/src/client/query/filter/toBuffer.js +100 -0
- package/dist/src/client/query/filter/types.d.ts +6 -0
- package/dist/src/client/query/filter/types.js +7 -0
- package/dist/src/client/query/include/props.d.ts +6 -0
- package/dist/src/client/query/include/props.js +44 -0
- package/dist/src/client/query/include/toBuffer.d.ts +3 -0
- package/dist/src/client/query/include/toBuffer.js +82 -0
- package/dist/src/client/query/include/utils.d.ts +6 -0
- package/dist/src/client/query/include/utils.js +41 -0
- package/dist/src/client/query/include/walk.d.ts +3 -0
- package/dist/src/client/query/include/walk.js +70 -0
- package/dist/src/client/query/query.d.ts +10 -0
- package/dist/src/client/query/query.js +11 -0
- package/dist/src/client/query/queryDef.d.ts +3 -0
- package/dist/src/client/query/queryDef.js +54 -0
- package/dist/src/client/query/read/read.d.ts +8 -0
- package/dist/src/client/query/read/read.js +303 -0
- package/dist/src/client/query/registerQuery.d.ts +2 -0
- package/dist/src/client/query/registerQuery.js +31 -0
- package/dist/src/client/query/search/index.d.ts +6 -0
- package/dist/src/client/query/search/index.js +82 -0
- package/dist/src/client/query/sort.d.ts +3 -0
- package/dist/src/client/query/sort.js +18 -0
- package/dist/src/client/query/subscription/index.d.ts +5 -0
- package/dist/src/client/query/subscription/index.js +52 -0
- package/dist/src/client/query/subscription/markers.d.ts +10 -0
- package/dist/src/client/query/subscription/markers.js +213 -0
- package/dist/src/client/query/subscription/run.d.ts +5 -0
- package/dist/src/client/query/subscription/run.js +69 -0
- package/dist/src/client/query/subscription/types.d.ts +33 -0
- package/dist/src/client/query/subscription/types.js +3 -0
- package/dist/src/client/query/thresholds.d.ts +6 -0
- package/dist/src/client/query/thresholds.js +16 -0
- package/dist/src/client/query/toBuffer.d.ts +3 -0
- package/dist/src/client/query/toBuffer.js +229 -0
- package/dist/src/client/query/types.d.ts +88 -0
- package/dist/src/client/query/types.js +15 -0
- package/dist/src/client/query/validation.d.ts +15 -0
- package/dist/src/client/query/validation.js +59 -0
- package/dist/src/client/string.d.ts +5 -0
- package/dist/src/client/string.js +73 -0
- package/dist/src/client/tree.d.ts +1 -0
- package/dist/src/client/tree.js +5 -0
- package/dist/src/index.d.ts +31 -0
- package/dist/src/index.js +85 -0
- package/dist/src/native.d.ts +28 -0
- package/dist/src/native.js +96 -0
- package/dist/src/server/csmt/draw-dot.d.ts +2 -0
- package/dist/src/server/csmt/draw-dot.js +32 -0
- package/dist/src/server/csmt/index.d.ts +4 -0
- package/dist/src/server/csmt/index.js +5 -0
- package/dist/src/server/csmt/match.d.ts +7 -0
- package/dist/src/server/csmt/match.js +10 -0
- package/dist/src/server/csmt/memebership-proof.d.ts +7 -0
- package/dist/src/server/csmt/memebership-proof.js +122 -0
- package/dist/src/server/csmt/tree-utils.d.ts +6 -0
- package/dist/src/server/csmt/tree-utils.js +33 -0
- package/dist/src/server/csmt/tree.d.ts +2 -0
- package/dist/src/server/csmt/tree.js +209 -0
- package/dist/src/server/csmt/types.d.ts +40 -0
- package/dist/src/server/csmt/types.js +2 -0
- package/dist/src/server/index.d.ts +85 -0
- package/dist/src/server/index.js +407 -0
- package/dist/src/server/migrate/index.d.ts +7 -0
- package/dist/src/server/migrate/index.js +108 -0
- package/dist/src/server/migrate/worker.d.ts +1 -0
- package/dist/src/server/migrate/worker.js +81 -0
- package/dist/src/server/save.d.ts +2 -0
- package/dist/src/server/save.js +66 -0
- package/dist/src/server/schema/schema.d.ts +3 -0
- package/dist/src/server/schema/schema.js +4 -0
- package/dist/src/server/schema/selvaBuffer.d.ts +4 -0
- package/dist/src/server/schema/selvaBuffer.js +102 -0
- package/dist/src/server/schema/typeDef.d.ts +6 -0
- package/dist/src/server/schema/typeDef.js +315 -0
- package/dist/src/server/schema/types.d.ts +127 -0
- package/dist/src/server/schema/types.js +113 -0
- package/dist/src/server/schema/utils.d.ts +6 -0
- package/dist/src/server/schema/utils.js +21 -0
- package/dist/src/server/start.d.ts +6 -0
- package/dist/src/server/start.js +86 -0
- package/dist/src/server/tree.d.ts +13 -0
- package/dist/src/server/tree.js +33 -0
- package/dist/src/server/worker.d.ts +1 -0
- package/dist/src/server/worker.js +35 -0
- package/package.json +48 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ModifyError, ModifyState } from '../ModifyRes.js';
|
|
2
|
+
import { setCursor } from '../setCursor.js';
|
|
3
|
+
import { DELETE, RANGE_ERR } from '../types.js';
|
|
4
|
+
import { getEdgeSize, writeEdges } from './edge.js';
|
|
5
|
+
import { dbUpdateFromUpsert } from './references.js';
|
|
6
|
+
function writeRef(id, ctx, schema, def, parentId, modifyOp, hasEdges) {
|
|
7
|
+
if (ctx.len + 16 > ctx.max) {
|
|
8
|
+
return RANGE_ERR;
|
|
9
|
+
}
|
|
10
|
+
ctx.markNodeDirty(ctx.db.schemaTypesParsed[def.inverseTypeName], id);
|
|
11
|
+
setCursor(ctx, schema, def.prop, parentId, modifyOp);
|
|
12
|
+
ctx.buf[ctx.len++] = modifyOp;
|
|
13
|
+
ctx.buf[ctx.len++] = hasEdges ? 1 : 0;
|
|
14
|
+
ctx.buf[ctx.len++] = id;
|
|
15
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
16
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
17
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
18
|
+
}
|
|
19
|
+
function singleReferenceEdges(ref, ctx, schema, def, parentId, modifyOp) {
|
|
20
|
+
let id = ref.id;
|
|
21
|
+
if (typeof id !== 'number') {
|
|
22
|
+
if (id instanceof ModifyState) {
|
|
23
|
+
if (id.error) {
|
|
24
|
+
return id.error;
|
|
25
|
+
}
|
|
26
|
+
id = id.tmpId;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (id > 0) {
|
|
30
|
+
const edgesLen = def.edgesTotalLen || getEdgeSize(def, ref);
|
|
31
|
+
if (edgesLen === 0) {
|
|
32
|
+
return writeRef(id, ctx, schema, def, parentId, modifyOp, false);
|
|
33
|
+
}
|
|
34
|
+
let err = writeRef(id, ctx, schema, def, parentId, modifyOp, true);
|
|
35
|
+
if (err) {
|
|
36
|
+
return err;
|
|
37
|
+
}
|
|
38
|
+
if (ctx.len + 4 + edgesLen > ctx.max) {
|
|
39
|
+
return RANGE_ERR;
|
|
40
|
+
}
|
|
41
|
+
let sizepos = ctx.len;
|
|
42
|
+
ctx.len += 4;
|
|
43
|
+
err = writeEdges(def, ref, ctx);
|
|
44
|
+
if (err) {
|
|
45
|
+
return err;
|
|
46
|
+
}
|
|
47
|
+
let size = ctx.len - sizepos;
|
|
48
|
+
ctx.buf[sizepos++] = size;
|
|
49
|
+
ctx.buf[sizepos++] = size >>>= 8;
|
|
50
|
+
ctx.buf[sizepos++] = size >>>= 8;
|
|
51
|
+
ctx.buf[sizepos] = size >>>= 8;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return new ModifyError(def, ref);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function writeReference(value, ctx, schema, def, res, modifyOp) {
|
|
58
|
+
if (value === null) {
|
|
59
|
+
if (ctx.len + 11 > ctx.max) {
|
|
60
|
+
return RANGE_ERR;
|
|
61
|
+
}
|
|
62
|
+
setCursor(ctx, schema, def.prop, res.tmpId, modifyOp);
|
|
63
|
+
ctx.buf[ctx.len++] = DELETE;
|
|
64
|
+
}
|
|
65
|
+
else if (typeof value === 'number') {
|
|
66
|
+
return writeRef(value, ctx, schema, def, res.tmpId, modifyOp, false);
|
|
67
|
+
}
|
|
68
|
+
else if (value instanceof ModifyState) {
|
|
69
|
+
if (value.error) {
|
|
70
|
+
return value.error;
|
|
71
|
+
}
|
|
72
|
+
return writeRef(value.tmpId, ctx, schema, def, res.tmpId, modifyOp, false);
|
|
73
|
+
}
|
|
74
|
+
else if (typeof value === 'object' && value !== null) {
|
|
75
|
+
if (def.edges) {
|
|
76
|
+
return singleReferenceEdges(value, ctx, schema, def, res.tmpId, modifyOp);
|
|
77
|
+
}
|
|
78
|
+
else if (typeof value.id === 'number') {
|
|
79
|
+
return writeRef(value.id, ctx, schema, def, res.tmpId, modifyOp, false);
|
|
80
|
+
}
|
|
81
|
+
else if (typeof value.upsert === 'object' && value.upsert !== null) {
|
|
82
|
+
dbUpdateFromUpsert(ctx, schema, def, res, ctx.db.upsert(def.inverseTypeName, value.upsert));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return new ModifyError(def, value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return new ModifyError(def, value);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=reference.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
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 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
|
+
update?: RefModify[] | RefModify;
|
|
13
|
+
delete?: RefModify[] | RefModify;
|
|
14
|
+
upsert: RefModify[] | RefModify;
|
|
15
|
+
};
|
|
16
|
+
export declare function writeReferences(value: any, ctx: ModifyCtx, schema: SchemaTypeDef, def: PropDef, res: ModifyState, mod: ModifyOp): ModifyErr;
|
|
17
|
+
export declare const dbUpdateFromUpsert: (ctx: ModifyCtx, schema: SchemaTypeDef, def: PropDef, res: ModifyState, promise: Promise<any>) => void;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { REFERENCES, } from '../../../server/schema/types.js';
|
|
2
|
+
import { ModifyError, ModifyState } from '../ModifyRes.js';
|
|
3
|
+
import { setCursor } from '../setCursor.js';
|
|
4
|
+
import { DELETE, RANGE_ERR } from '../types.js';
|
|
5
|
+
import { writeEdges } from './edge.js';
|
|
6
|
+
export function writeReferences(value, ctx, schema, def, res, mod) {
|
|
7
|
+
if (typeof value !== 'object') {
|
|
8
|
+
return new ModifyError(def, value);
|
|
9
|
+
}
|
|
10
|
+
if (value === null) {
|
|
11
|
+
if (ctx.len + 11 > ctx.max) {
|
|
12
|
+
return RANGE_ERR;
|
|
13
|
+
}
|
|
14
|
+
setCursor(ctx, schema, def.prop, res.tmpId, mod);
|
|
15
|
+
ctx.buf[ctx.len++] = DELETE;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
return updateRefs(def, ctx, schema, mod, value, res.tmpId, 0);
|
|
20
|
+
}
|
|
21
|
+
for (const key in value) {
|
|
22
|
+
const val = value[key];
|
|
23
|
+
let err;
|
|
24
|
+
if (!Array.isArray(val)) {
|
|
25
|
+
err = new ModifyError(def, value);
|
|
26
|
+
}
|
|
27
|
+
else if (key === 'delete') {
|
|
28
|
+
err = deleteRefs(def, ctx, schema, mod, val, res.tmpId);
|
|
29
|
+
}
|
|
30
|
+
else if (key === 'add') {
|
|
31
|
+
err = updateRefs(def, ctx, schema, mod, val, res.tmpId, 1);
|
|
32
|
+
}
|
|
33
|
+
else if (key === 'upsert') {
|
|
34
|
+
dbUpdateFromUpsert(ctx, schema, def, res, Promise.all(val.map((val) => ctx.db.upsert(def.inverseTypeName, val))));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
err = new ModifyError(def, value);
|
|
38
|
+
}
|
|
39
|
+
if (err) {
|
|
40
|
+
return err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export const dbUpdateFromUpsert = (ctx, schema, def, res, promise) => {
|
|
45
|
+
res.promises ??= [];
|
|
46
|
+
res.promises.push(promise.then((result) => {
|
|
47
|
+
let payload = {};
|
|
48
|
+
let i = 0;
|
|
49
|
+
for (; i < def.path.length - 1; i++) {
|
|
50
|
+
payload = payload[def.path[i]] = {};
|
|
51
|
+
}
|
|
52
|
+
payload[def.path[i]] = result;
|
|
53
|
+
return ctx.db.update(schema.type, res.tmpId, payload);
|
|
54
|
+
}));
|
|
55
|
+
};
|
|
56
|
+
function deleteRefs(def, ctx, schema, modifyOp, refs, parentId) {
|
|
57
|
+
let size = 4 * refs.length + 1;
|
|
58
|
+
if (ctx.len + 10 + size > ctx.max) {
|
|
59
|
+
return RANGE_ERR;
|
|
60
|
+
}
|
|
61
|
+
setCursor(ctx, schema, def.prop, parentId, modifyOp);
|
|
62
|
+
ctx.buf[ctx.len++] = modifyOp;
|
|
63
|
+
ctx.buf[ctx.len++] = size;
|
|
64
|
+
ctx.buf[ctx.len++] = size >>>= 8;
|
|
65
|
+
ctx.buf[ctx.len++] = size >>>= 8;
|
|
66
|
+
ctx.buf[ctx.len++] = size >>>= 8;
|
|
67
|
+
ctx.buf[ctx.len++] = 2;
|
|
68
|
+
for (let ref of refs) {
|
|
69
|
+
if (typeof ref === 'number') {
|
|
70
|
+
ctx.buf[ctx.len++] = ref;
|
|
71
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
72
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
73
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
74
|
+
}
|
|
75
|
+
else if (ref instanceof ModifyState) {
|
|
76
|
+
if (ref.error) {
|
|
77
|
+
return ref.error;
|
|
78
|
+
}
|
|
79
|
+
ref = ref.tmpId;
|
|
80
|
+
ctx.buf[ctx.len++] = ref;
|
|
81
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
82
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
83
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return new ModifyError(def, refs);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function updateRefs(def, ctx, schema, mod, refs, parentId, op) {
|
|
91
|
+
if (ctx.len + 19 + refs.length * 4 > ctx.max) {
|
|
92
|
+
return RANGE_ERR;
|
|
93
|
+
}
|
|
94
|
+
setCursor(ctx, schema, def.prop, parentId, mod);
|
|
95
|
+
const initpos = ctx.len;
|
|
96
|
+
const nrOrErr = putRefs(def, ctx, mod, refs, op);
|
|
97
|
+
if (nrOrErr) {
|
|
98
|
+
if (typeof nrOrErr === 'number') {
|
|
99
|
+
if (nrOrErr === refs.length) {
|
|
100
|
+
// reset
|
|
101
|
+
ctx.len = initpos;
|
|
102
|
+
}
|
|
103
|
+
else if (ctx.len + 2 > ctx.max) {
|
|
104
|
+
return RANGE_ERR;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
ctx.buf[ctx.len++] = 0;
|
|
108
|
+
ctx.buf[ctx.len++] = REFERENCES;
|
|
109
|
+
}
|
|
110
|
+
return appendRefs(def, ctx, mod, refs, op, nrOrErr);
|
|
111
|
+
}
|
|
112
|
+
return nrOrErr;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
116
|
+
if (ctx.len + 10 > ctx.max) {
|
|
117
|
+
return RANGE_ERR;
|
|
118
|
+
}
|
|
119
|
+
const hasEdges = !!def.edges;
|
|
120
|
+
ctx.buf[ctx.len++] = modifyOp;
|
|
121
|
+
let i = refs.length - remaining;
|
|
122
|
+
let totalpos = ctx.len;
|
|
123
|
+
ctx.len += 4;
|
|
124
|
+
ctx.buf[ctx.len++] = i === 0 ? op : 1; // if it just did a PUT, it should ADD not overwrite the remaining
|
|
125
|
+
ctx.buf[ctx.len++] = remaining;
|
|
126
|
+
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
127
|
+
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
128
|
+
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
129
|
+
for (; i < refs.length; i++) {
|
|
130
|
+
const ref = refs[i];
|
|
131
|
+
let id;
|
|
132
|
+
let index;
|
|
133
|
+
if (typeof ref === 'object') {
|
|
134
|
+
if (ref instanceof ModifyState) {
|
|
135
|
+
if (ref.error) {
|
|
136
|
+
return ref.error;
|
|
137
|
+
}
|
|
138
|
+
id = ref.tmpId;
|
|
139
|
+
}
|
|
140
|
+
else if (ref.id instanceof ModifyState) {
|
|
141
|
+
if (ref.id.error) {
|
|
142
|
+
return ref.id.error;
|
|
143
|
+
}
|
|
144
|
+
id = ref.id.tmpId;
|
|
145
|
+
index = ref.$index;
|
|
146
|
+
}
|
|
147
|
+
else if (ref.id > 0) {
|
|
148
|
+
id = ref.id;
|
|
149
|
+
index = ref.$index;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
return new ModifyError(def, refs);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else if (ref > 0) {
|
|
156
|
+
id = ref;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return new ModifyError(def, refs);
|
|
160
|
+
}
|
|
161
|
+
if (hasEdges) {
|
|
162
|
+
if (index === undefined) {
|
|
163
|
+
if (ctx.len + 9 > ctx.max) {
|
|
164
|
+
return RANGE_ERR;
|
|
165
|
+
}
|
|
166
|
+
ctx.buf[ctx.len++] = 1;
|
|
167
|
+
ctx.buf[ctx.len++] = id;
|
|
168
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
169
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
170
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
171
|
+
}
|
|
172
|
+
else if (typeof index === 'number') {
|
|
173
|
+
if (ctx.len + 13 > ctx.max) {
|
|
174
|
+
return RANGE_ERR;
|
|
175
|
+
}
|
|
176
|
+
ctx.buf[ctx.len++] = 2;
|
|
177
|
+
ctx.buf[ctx.len++] = id;
|
|
178
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
179
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
180
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
181
|
+
ctx.buf[ctx.len++] = index;
|
|
182
|
+
ctx.buf[ctx.len++] = index >>>= 8;
|
|
183
|
+
ctx.buf[ctx.len++] = index >>>= 8;
|
|
184
|
+
ctx.buf[ctx.len++] = index >>>= 8;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
return new ModifyError(def, refs);
|
|
188
|
+
}
|
|
189
|
+
let sizepos = ctx.len;
|
|
190
|
+
ctx.len += 4;
|
|
191
|
+
const err = writeEdges(def, ref, ctx);
|
|
192
|
+
if (err) {
|
|
193
|
+
return err;
|
|
194
|
+
}
|
|
195
|
+
let size = ctx.len - sizepos - 4;
|
|
196
|
+
ctx.buf[sizepos++] = size;
|
|
197
|
+
ctx.buf[sizepos++] = size >>>= 8;
|
|
198
|
+
ctx.buf[sizepos++] = size >>>= 8;
|
|
199
|
+
ctx.buf[sizepos] = size >>>= 8;
|
|
200
|
+
}
|
|
201
|
+
else if (index === undefined) {
|
|
202
|
+
if (ctx.len + 5 > ctx.max) {
|
|
203
|
+
return RANGE_ERR;
|
|
204
|
+
}
|
|
205
|
+
ctx.buf[ctx.len++] = 0;
|
|
206
|
+
ctx.buf[ctx.len++] = id;
|
|
207
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
208
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
209
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
210
|
+
}
|
|
211
|
+
else if (typeof index === 'number') {
|
|
212
|
+
if (ctx.len + 9 > ctx.max) {
|
|
213
|
+
return RANGE_ERR;
|
|
214
|
+
}
|
|
215
|
+
ctx.buf[ctx.len++] = 3;
|
|
216
|
+
ctx.buf[ctx.len++] = id;
|
|
217
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
218
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
219
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
220
|
+
ctx.buf[ctx.len++] = index;
|
|
221
|
+
ctx.buf[ctx.len++] = index >>>= 8;
|
|
222
|
+
ctx.buf[ctx.len++] = index >>>= 8;
|
|
223
|
+
ctx.buf[ctx.len++] = index >>>= 8;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
return new ModifyError(def, refs);
|
|
227
|
+
}
|
|
228
|
+
ctx.markNodeDirty(ctx.db.schemaTypesParsed[def.inverseTypeName], id);
|
|
229
|
+
}
|
|
230
|
+
let size = ctx.len - totalpos - 4;
|
|
231
|
+
ctx.buf[totalpos++] = size;
|
|
232
|
+
ctx.buf[totalpos++] = size >>>= 8;
|
|
233
|
+
ctx.buf[totalpos++] = size >>>= 8;
|
|
234
|
+
ctx.buf[totalpos] = size >>>= 8;
|
|
235
|
+
}
|
|
236
|
+
function putRefs(def, ctx, modifyOp, refs, op) {
|
|
237
|
+
let size = refs.length * 4 + 1;
|
|
238
|
+
ctx.buf[ctx.len++] = modifyOp;
|
|
239
|
+
ctx.buf[ctx.len++] = size;
|
|
240
|
+
ctx.buf[ctx.len++] = size >>>= 8;
|
|
241
|
+
ctx.buf[ctx.len++] = size >>>= 8;
|
|
242
|
+
ctx.buf[ctx.len++] = size >>>= 8;
|
|
243
|
+
ctx.buf[ctx.len++] = op === 0 ? 3 : 4;
|
|
244
|
+
ctx.len = (ctx.len + 3) & ~3;
|
|
245
|
+
let i = 0;
|
|
246
|
+
for (; i < refs.length; i++) {
|
|
247
|
+
let ref = refs[i];
|
|
248
|
+
if (typeof ref === 'number') {
|
|
249
|
+
ctx.buf[ctx.len++] = ref;
|
|
250
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
251
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
252
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
253
|
+
}
|
|
254
|
+
else if (ref instanceof ModifyState) {
|
|
255
|
+
if (ref.error) {
|
|
256
|
+
return ref.error;
|
|
257
|
+
}
|
|
258
|
+
ref = ref.tmpId;
|
|
259
|
+
ctx.buf[ctx.len++] = ref;
|
|
260
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
261
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
262
|
+
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
ctx.markNodeDirty(ctx.db.schemaTypesParsed[def.inverseTypeName], ref);
|
|
268
|
+
}
|
|
269
|
+
return refs.length - i;
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=references.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { flushBuffer, startDrain } from '../operations.js';
|
|
2
|
+
import { setCursor } from './setCursor.js';
|
|
3
|
+
import { UPDATE } from './types.js';
|
|
4
|
+
export const remove = (db, type, id) => {
|
|
5
|
+
const ctx = db.modifyCtx;
|
|
6
|
+
const schema = db.schemaTypesParsed[type];
|
|
7
|
+
const separate = schema.separate;
|
|
8
|
+
if (separate) {
|
|
9
|
+
const size = 12 + separate.length * 12;
|
|
10
|
+
if (ctx.len + size > ctx.max) {
|
|
11
|
+
flushBuffer(db);
|
|
12
|
+
return remove(db, type, id);
|
|
13
|
+
}
|
|
14
|
+
setCursor(ctx, schema, 0, id, UPDATE);
|
|
15
|
+
ctx.buf[ctx.len++] = 4;
|
|
16
|
+
for (const s of separate) {
|
|
17
|
+
setCursor(ctx, schema, s.prop, id, UPDATE);
|
|
18
|
+
ctx.buf[ctx.len++] = 4;
|
|
19
|
+
}
|
|
20
|
+
ctx.buf[ctx.len++] = 10;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
if (ctx.len + 12 > ctx.max) {
|
|
24
|
+
flushBuffer(db);
|
|
25
|
+
return remove(db, type, id);
|
|
26
|
+
}
|
|
27
|
+
setCursor(ctx, schema, 0, id, UPDATE);
|
|
28
|
+
ctx.buf[ctx.len++] = 4;
|
|
29
|
+
ctx.buf[ctx.len++] = 10;
|
|
30
|
+
}
|
|
31
|
+
if (!db.isDraining) {
|
|
32
|
+
startDrain(db);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=remove.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModifyCtx } from '../../index.js';
|
|
2
|
+
import { SchemaTypeDef } from '../../server/schema/types.js';
|
|
3
|
+
import { ModifyOp } from './types.js';
|
|
4
|
+
export declare const setCursor: (ctx: ModifyCtx, schema: SchemaTypeDef, field: number, id: number, modifyOp: ModifyOp, ignoreField?: boolean) => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CREATE, SWITCH_FIELD, SWITCH_ID_CREATE, SWITCH_ID_UPDATE, SWITCH_TYPE, } from './types.js';
|
|
2
|
+
export const setCursor = (ctx, schema, field, id, modifyOp, ignoreField) => {
|
|
3
|
+
const prefix0 = schema.idUint8[0];
|
|
4
|
+
const prefix1 = schema.idUint8[1];
|
|
5
|
+
if (ctx.prefix0 !== prefix0 || ctx.prefix1 !== prefix1) {
|
|
6
|
+
ctx.buf[ctx.len++] = SWITCH_TYPE; // switch node type
|
|
7
|
+
ctx.buf[ctx.len++] = prefix0; // type1
|
|
8
|
+
ctx.buf[ctx.len++] = prefix1; // type2
|
|
9
|
+
ctx.prefix0 = prefix0;
|
|
10
|
+
ctx.prefix1 = prefix1;
|
|
11
|
+
ctx.field = -1;
|
|
12
|
+
ctx.id = -1;
|
|
13
|
+
ctx.lastMain = -1;
|
|
14
|
+
if (modifyOp === CREATE) {
|
|
15
|
+
ctx.markTypeDirty(schema);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (!ignoreField && ctx.field !== field) {
|
|
19
|
+
ctx.buf[ctx.len++] = SWITCH_FIELD; // switch field
|
|
20
|
+
ctx.buf[ctx.len++] = field; // actual field
|
|
21
|
+
// add start and len if its main
|
|
22
|
+
ctx.field = field;
|
|
23
|
+
}
|
|
24
|
+
if (ctx.id !== id) {
|
|
25
|
+
ctx.markNodeDirty(schema, id);
|
|
26
|
+
ctx.id = id;
|
|
27
|
+
ctx.lastMain = -1;
|
|
28
|
+
ctx.buf[ctx.len++] =
|
|
29
|
+
modifyOp === CREATE ? SWITCH_ID_CREATE : SWITCH_ID_UPDATE; // swtch id
|
|
30
|
+
ctx.buf[ctx.len++] = id;
|
|
31
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
32
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
33
|
+
ctx.buf[ctx.len++] = id >>>= 8;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=setCursor.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { LangCode } from '@based/schema';
|
|
2
|
+
import { ModifyCtx } from '../../index.js';
|
|
3
|
+
import { SchemaTypeDef, PropDef } from '../../server/schema/types.js';
|
|
4
|
+
import { ModifyOp, ModifyErr } from './types.js';
|
|
5
|
+
export declare function writeString(lang: LangCode, value: string | null | Buffer, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CREATE, UPDATE, RANGE_ERR, DELETE, } from './types.js';
|
|
2
|
+
import { ModifyError } from './ModifyRes.js';
|
|
3
|
+
import { setCursor } from './setCursor.js';
|
|
4
|
+
import { write } from '../string.js';
|
|
5
|
+
// allow setting buffer in modify create for strings
|
|
6
|
+
// add compression handling for main buffer
|
|
7
|
+
// add compression handling for edge fields
|
|
8
|
+
export function writeString(lang, value, ctx, def, t, parentId, modifyOp) {
|
|
9
|
+
const isBuffer = value instanceof Buffer;
|
|
10
|
+
if (typeof value !== 'string' && value !== null && !isBuffer) {
|
|
11
|
+
return new ModifyError(t, value);
|
|
12
|
+
}
|
|
13
|
+
const len = value?.length;
|
|
14
|
+
if (!len) {
|
|
15
|
+
if (modifyOp === UPDATE) {
|
|
16
|
+
if (ctx.len + 11 > ctx.max) {
|
|
17
|
+
return RANGE_ERR;
|
|
18
|
+
}
|
|
19
|
+
setCursor(ctx, def, t.prop, parentId, modifyOp);
|
|
20
|
+
ctx.buf[ctx.len++] = DELETE;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
let size = isBuffer
|
|
25
|
+
? value.byteLength
|
|
26
|
+
: Buffer.byteLength(value, 'utf8') + 6;
|
|
27
|
+
if (ctx.len + 20 + size > ctx.max) {
|
|
28
|
+
// 5 compression size
|
|
29
|
+
return RANGE_ERR;
|
|
30
|
+
}
|
|
31
|
+
if (modifyOp === CREATE) {
|
|
32
|
+
def.stringPropsCurrent[t.prop] = 2;
|
|
33
|
+
ctx.hasStringField++;
|
|
34
|
+
}
|
|
35
|
+
setCursor(ctx, def, t.prop, parentId, modifyOp);
|
|
36
|
+
// TODO if buffer check if second byte is zero or one
|
|
37
|
+
// modOp | size u32 | stringprotocol | string
|
|
38
|
+
ctx.buf[ctx.len] = modifyOp;
|
|
39
|
+
ctx.len += 5;
|
|
40
|
+
if (isBuffer) {
|
|
41
|
+
ctx.buf.set(value, ctx.len);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const isNoCompression = t.compression === 0;
|
|
45
|
+
// @ts-ignore stupid str
|
|
46
|
+
size = write(ctx.buf, value, ctx.len, isNoCompression, lang);
|
|
47
|
+
}
|
|
48
|
+
let sizepos = ctx.len + 1 - 5;
|
|
49
|
+
ctx.len += size;
|
|
50
|
+
ctx.buf[sizepos++] = size;
|
|
51
|
+
ctx.buf[sizepos++] = size >>>= 8;
|
|
52
|
+
ctx.buf[sizepos++] = size >>>= 8;
|
|
53
|
+
ctx.buf[sizepos] = size >>>= 8;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ModifyCtx } from '../../index.js';
|
|
2
|
+
import { ModifyOp, ModifyErr } from './types.js';
|
|
3
|
+
import { SchemaTypeDef, PropDef } from '../../server/schema/types.js';
|
|
4
|
+
export declare function writeText(value: any, // TODO YOLO
|
|
5
|
+
ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { langCodesMap } from '@based/schema';
|
|
2
|
+
import { writeString } from './string.js';
|
|
3
|
+
export function writeText(value, // TODO YOLO
|
|
4
|
+
ctx, def, t, parentId, modifyOp) {
|
|
5
|
+
for (const lang in value) {
|
|
6
|
+
const langCode = langCodesMap.get(lang) || langCodesMap.get('en'); // TODO use proper fallback
|
|
7
|
+
const s = value[lang];
|
|
8
|
+
const err = writeString(langCode, s, ctx, def, t, parentId, modifyOp);
|
|
9
|
+
if (err) {
|
|
10
|
+
return err;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ModifyError } from './ModifyRes.js';
|
|
2
|
+
export declare const CREATE = 3;
|
|
3
|
+
export declare const UPDATE = 6;
|
|
4
|
+
export declare const DELETE = 11;
|
|
5
|
+
export declare const MERGE_MAIN = 4;
|
|
6
|
+
export declare const RANGE_ERR = 1;
|
|
7
|
+
export declare const INCREMENT = 12;
|
|
8
|
+
export declare const DECREMENT = 13;
|
|
9
|
+
export declare const SWITCH_TYPE = 2;
|
|
10
|
+
export declare const SWITCH_FIELD = 0;
|
|
11
|
+
export declare const SWITCH_ID_CREATE = 9;
|
|
12
|
+
export declare const SWITCH_ID_UPDATE = 1;
|
|
13
|
+
export type ModifyErr = typeof RANGE_ERR | ModifyError | void;
|
|
14
|
+
export type ModifyOp = typeof CREATE | typeof UPDATE | typeof INCREMENT;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const CREATE = 3;
|
|
2
|
+
export const UPDATE = 6;
|
|
3
|
+
export const DELETE = 11;
|
|
4
|
+
export const MERGE_MAIN = 4;
|
|
5
|
+
export const RANGE_ERR = 1;
|
|
6
|
+
export const INCREMENT = 12;
|
|
7
|
+
export const DECREMENT = 13;
|
|
8
|
+
export const SWITCH_TYPE = 2;
|
|
9
|
+
export const SWITCH_FIELD = 0;
|
|
10
|
+
export const SWITCH_ID_CREATE = 9;
|
|
11
|
+
export const SWITCH_ID_UPDATE = 1;
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,80 @@
|
|
|
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 { RANGE_ERR, UPDATE } from './types.js';
|
|
6
|
+
import { appendFixedValue } from './fixed.js';
|
|
7
|
+
import { getSubscriptionMarkers } from '../query/subscription/index.js';
|
|
8
|
+
const appendUpdate = (ctx, def, obj, res, overwrite) => {
|
|
9
|
+
const err = modify(ctx, res, obj, def, UPDATE, def.tree, overwrite);
|
|
10
|
+
if (err) {
|
|
11
|
+
return err;
|
|
12
|
+
}
|
|
13
|
+
if (def.updateTs) {
|
|
14
|
+
const updateTs = Date.now();
|
|
15
|
+
for (const prop of def.updateTs) {
|
|
16
|
+
if (ctx.mergeMain) {
|
|
17
|
+
ctx.mergeMain.push(prop, updateTs);
|
|
18
|
+
ctx.mergeMainSize += prop.len + 4;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
ctx.mergeMain = [prop, updateTs];
|
|
22
|
+
ctx.mergeMainSize = prop.len + 4;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (ctx.mergeMain) {
|
|
27
|
+
let { mergeMain, mergeMainSize } = ctx;
|
|
28
|
+
ctx.mergeMainSize = 0;
|
|
29
|
+
ctx.mergeMain = null;
|
|
30
|
+
if (ctx.len + 15 + mergeMain.length * 4 > ctx.max) {
|
|
31
|
+
return RANGE_ERR;
|
|
32
|
+
}
|
|
33
|
+
setCursor(ctx, def, 0, res.tmpId, UPDATE);
|
|
34
|
+
ctx.buf[ctx.len++] = 5;
|
|
35
|
+
ctx.buf[ctx.len++] = mergeMainSize;
|
|
36
|
+
ctx.buf[ctx.len++] = mergeMainSize >>>= 8;
|
|
37
|
+
ctx.buf[ctx.len++] = mergeMainSize >>>= 8;
|
|
38
|
+
ctx.buf[ctx.len++] = mergeMainSize >>>= 8;
|
|
39
|
+
for (let i = 0; i < mergeMain.length; i += 2) {
|
|
40
|
+
const t = mergeMain[i];
|
|
41
|
+
const v = mergeMain[i + 1];
|
|
42
|
+
let { start, len } = t;
|
|
43
|
+
ctx.buf[ctx.len++] = start;
|
|
44
|
+
ctx.buf[ctx.len++] = start >>>= 8;
|
|
45
|
+
ctx.buf[ctx.len++] = len;
|
|
46
|
+
ctx.buf[ctx.len++] = len >>>= 8;
|
|
47
|
+
const err = appendFixedValue(ctx, v, t);
|
|
48
|
+
if (err) {
|
|
49
|
+
return err;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export const update = (db, type, id, obj, overwrite) => {
|
|
55
|
+
const def = db.schemaTypesParsed[type];
|
|
56
|
+
const ctx = db.modifyCtx;
|
|
57
|
+
const pos = ctx.len;
|
|
58
|
+
const res = new ModifyState(def.id, id, db, getSubscriptionMarkers(db, def.id, id, false));
|
|
59
|
+
const err = appendUpdate(ctx, def, obj, res, overwrite);
|
|
60
|
+
if (err) {
|
|
61
|
+
ctx.prefix0 = -1; // force a new cursor
|
|
62
|
+
ctx.len = pos;
|
|
63
|
+
if (err === RANGE_ERR) {
|
|
64
|
+
if (pos === 0) {
|
|
65
|
+
throw new Error('out of range');
|
|
66
|
+
}
|
|
67
|
+
flushBuffer(db);
|
|
68
|
+
return update(db, type, id, obj, overwrite);
|
|
69
|
+
}
|
|
70
|
+
res.error = err;
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
if (!db.isDraining) {
|
|
75
|
+
startDrain(db);
|
|
76
|
+
}
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
return res;
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=update.js.map
|