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