@based/db 0.0.71 → 0.1.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/LICENSE +201 -0
- package/README.md +105 -77
- package/dist/lib/darwin_aarch64/include/libdeflate.h +23 -0
- package/dist/lib/darwin_aarch64/include/selva/db.h +0 -41
- package/dist/lib/darwin_aarch64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/darwin_aarch64/include/selva/fields.h +52 -37
- package/dist/lib/darwin_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/darwin_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_string.h +8 -5
- package/dist/lib/darwin_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +18 -4
- 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-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/lib/linux_aarch64/include/libdeflate.h +23 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +0 -41
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/linux_aarch64/include/selva/fields.h +52 -37
- package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +8 -5
- package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +18 -4
- package/dist/lib/linux_aarch64/libdeflate.so +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/libdeflate.h +23 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +0 -41
- package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/linux_x86_64/include/selva/fields.h +52 -37
- package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +8 -5
- package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +18 -4
- package/dist/lib/linux_x86_64/libdeflate.so +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/index.d.ts +16 -21
- package/dist/src/client/index.js +48 -59
- package/dist/src/client/modify/Ctx.d.ts +38 -0
- package/dist/src/client/modify/Ctx.js +30 -0
- package/dist/src/client/modify/Tmp.d.ts +19 -0
- package/dist/src/client/modify/Tmp.js +67 -0
- package/dist/src/client/modify/create/index.d.ts +6 -0
- package/dist/src/client/modify/create/index.js +191 -0
- package/dist/src/client/modify/create/mark.d.ts +7 -0
- package/dist/src/client/modify/create/mark.js +42 -0
- package/dist/src/client/modify/cursor.d.ts +10 -0
- package/dist/src/client/modify/cursor.js +48 -0
- package/dist/src/client/modify/delete/index.d.ts +2 -0
- package/dist/src/client/modify/delete/index.js +39 -0
- package/dist/src/client/modify/drain.d.ts +7 -0
- package/dist/src/client/modify/drain.js +77 -0
- package/dist/src/client/modify/edges/binary.d.ts +3 -0
- package/dist/src/client/modify/edges/binary.js +28 -0
- package/dist/src/client/modify/edges/cardinality.d.ts +3 -0
- package/dist/src/client/modify/edges/cardinality.js +15 -0
- package/dist/src/client/modify/edges/header.d.ts +5 -0
- package/dist/src/client/modify/edges/header.js +21 -0
- package/dist/src/client/modify/edges/index.d.ts +3 -0
- package/dist/src/client/modify/edges/index.js +128 -0
- package/dist/src/client/modify/edges/reference.d.ts +3 -0
- package/dist/src/client/modify/edges/reference.js +31 -0
- package/dist/src/client/modify/edges/references.d.ts +3 -0
- package/dist/src/client/modify/edges/references.js +38 -0
- package/dist/src/client/modify/edges/separate.d.ts +3 -0
- package/dist/src/client/modify/edges/separate.js +24 -0
- package/dist/src/client/modify/edges/string.d.ts +3 -0
- package/dist/src/client/modify/edges/string.js +30 -0
- package/dist/src/client/modify/error.d.ts +7 -0
- package/dist/src/client/modify/error.js +68 -0
- package/dist/src/client/modify/expire/index.d.ts +2 -0
- package/dist/src/client/modify/expire/index.js +31 -0
- package/dist/src/client/modify/props/alias.d.ts +3 -0
- package/dist/src/client/modify/props/alias.js +26 -0
- package/dist/src/client/modify/props/binary.d.ts +5 -0
- package/dist/src/client/modify/props/binary.js +52 -0
- package/dist/src/client/modify/props/cardinality.d.ts +4 -0
- package/dist/src/client/modify/props/cardinality.js +46 -0
- package/dist/src/client/modify/props/delete.d.ts +3 -0
- package/dist/src/client/modify/props/delete.js +13 -0
- package/dist/src/client/modify/props/fixed.d.ts +4 -0
- package/dist/src/client/modify/props/fixed.js +105 -0
- package/dist/src/client/modify/props/increment.d.ts +3 -0
- package/dist/src/client/modify/props/increment.js +28 -0
- package/dist/src/client/modify/props/json.d.ts +3 -0
- package/dist/src/client/modify/props/json.js +5 -0
- package/dist/src/client/modify/props/main.d.ts +4 -0
- package/dist/src/client/modify/props/main.js +22 -0
- package/dist/src/client/modify/props/object.d.ts +3 -0
- package/dist/src/client/modify/props/object.js +37 -0
- package/dist/src/client/modify/props/reference.d.ts +6 -0
- package/dist/src/client/modify/props/reference.js +92 -0
- package/dist/src/client/modify/props/references.d.ts +3 -0
- package/dist/src/client/modify/props/references.js +231 -0
- package/dist/src/client/modify/props/separate.d.ts +3 -0
- package/dist/src/client/modify/props/separate.js +43 -0
- package/dist/src/client/modify/props/string.d.ts +5 -0
- package/dist/src/client/modify/props/string.js +51 -0
- package/dist/src/client/modify/props/text.d.ts +3 -0
- package/dist/src/client/modify/props/text.js +35 -0
- package/dist/src/client/modify/props/vector.d.ts +3 -0
- package/dist/src/client/modify/props/vector.js +48 -0
- package/dist/src/client/modify/resize.d.ts +3 -0
- package/dist/src/client/modify/resize.js +20 -0
- package/dist/src/client/modify/types.d.ts +3 -4
- package/dist/src/client/modify/types.js +2 -1
- package/dist/src/client/modify/uint.d.ts +7 -0
- package/dist/src/client/modify/uint.js +27 -0
- package/dist/src/client/modify/update/index.d.ts +3 -0
- package/dist/src/client/modify/update/index.js +75 -0
- package/dist/src/client/modify/upsert/index.d.ts +3 -0
- package/dist/src/client/modify/{upsert.js → upsert/index.js} +4 -4
- package/dist/src/client/modify/validate.d.ts +6 -0
- package/dist/src/client/modify/validate.js +24 -0
- package/dist/src/client/query/BasedDbQuery.d.ts +17 -14
- package/dist/src/client/query/BasedDbQuery.js +90 -93
- package/dist/src/client/query/{BasedIterable.d.ts → BasedQueryResponse.d.ts} +5 -4
- package/dist/src/client/query/{BasedIterable.js → BasedQueryResponse.js} +15 -10
- package/dist/src/client/query/aggregates/aggregation.d.ts +5 -3
- package/dist/src/client/query/aggregates/aggregation.js +105 -48
- package/dist/src/client/query/aggregates/types.d.ts +33 -11
- package/dist/src/client/query/aggregates/types.js +29 -11
- package/dist/src/client/query/debug.js +1 -1
- package/dist/src/client/query/display.d.ts +1 -1
- package/dist/src/client/query/display.js +21 -4
- package/dist/src/client/query/filter/FilterBranch.js +2 -2
- package/dist/src/client/query/filter/convertFilter.d.ts +3 -2
- package/dist/src/client/query/filter/convertFilter.js +13 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +16 -30
- package/dist/src/client/query/filter/createReferenceFilter.js +6 -20
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +15 -32
- package/dist/src/client/query/filter/parseFilterValue.js +3 -11
- package/dist/src/client/query/filter/primitiveFilter.js +1 -1
- package/dist/src/client/query/filter/toBuffer.js +9 -15
- package/dist/src/client/query/filter/types.d.ts +6 -6
- package/dist/src/client/query/filter/types.js +8 -8
- package/dist/src/client/query/include/include.d.ts +3 -0
- package/dist/src/client/query/include/include.js +58 -0
- package/dist/src/client/query/include/props.d.ts +7 -7
- package/dist/src/client/query/include/props.js +26 -21
- package/dist/src/client/query/include/toByteCode.js +188 -0
- package/dist/src/client/query/include/utils.d.ts +3 -1
- package/dist/src/client/query/include/utils.js +13 -0
- package/dist/src/client/query/include/walk.d.ts +2 -2
- package/dist/src/client/query/include/walk.js +38 -23
- package/dist/src/client/query/query.d.ts +2 -3
- package/dist/src/client/query/query.js +2 -3
- package/dist/src/client/query/queryDef.d.ts +4 -2
- package/dist/src/client/query/queryDef.js +3 -5
- package/dist/src/client/query/queryDefToReadSchema.d.ts +3 -0
- package/dist/src/client/query/queryDefToReadSchema.js +126 -0
- package/dist/src/client/query/registerQuery.js +15 -4
- package/dist/src/client/query/search/index.d.ts +2 -1
- package/dist/src/client/query/search/index.js +9 -2
- package/dist/src/client/query/sort.js +3 -0
- package/dist/src/client/query/subscription/index.d.ts +1 -1
- package/dist/src/client/query/subscription/index.js +2 -2
- package/dist/src/client/query/subscription/types.d.ts +1 -1
- package/dist/src/client/query/thresholds.d.ts +1 -1
- package/dist/src/client/query/thresholds.js +1 -1
- package/dist/src/client/query/toByteCode/{toBuffer.js → toByteCode.js} +8 -8
- package/dist/src/client/query/types.d.ts +40 -25
- package/dist/src/client/query/types.js +2 -6
- package/dist/src/client/query/validation.d.ts +6 -0
- package/dist/src/client/query/validation.js +31 -7
- package/dist/src/client/setLocalClientSchema.js +6 -10
- package/dist/src/client/string.d.ts +3 -7
- package/dist/src/client/string.js +18 -47
- package/dist/src/hooks.d.ts +2 -3
- package/dist/src/hooks.js +14 -9
- package/dist/src/index.d.ts +3 -5
- package/dist/src/index.js +4 -6
- package/dist/src/native.d.ts +3 -2
- package/dist/src/native.js +9 -8
- package/dist/src/server/IoWorker.js +2 -3
- package/dist/src/server/QueryWorker.js +1 -1
- package/dist/src/server/blocks.js +5 -4
- package/dist/src/server/dbHash.js +1 -1
- package/dist/src/server/index.d.ts +4 -6
- package/dist/src/server/index.js +63 -96
- package/dist/src/server/migrate/index.d.ts +2 -4
- package/dist/src/server/migrate/index.js +32 -16
- package/dist/src/server/migrate/worker.js +2 -27
- package/dist/src/server/save.js +3 -2
- package/dist/src/server/schema.js +9 -19
- package/dist/src/server/start.d.ts +1 -0
- package/dist/src/server/start.js +18 -10
- package/dist/src/server/tree.d.ts +20 -0
- package/dist/src/server/tree.js +17 -2
- package/dist/src/server/workers/DbWorker.d.ts +1 -0
- package/dist/src/server/workers/DbWorker.js +8 -1
- package/dist/src/server/workers/io_worker.js +1 -1
- package/dist/src/server/workers/worker.js +9 -4
- package/dist/src/table.d.ts +4 -0
- package/dist/src/table.js +97 -0
- package/package.json +18 -17
- package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +0 -29
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -29
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -29
- package/dist/src/client/flushModify.d.ts +0 -36
- package/dist/src/client/flushModify.js +0 -197
- package/dist/src/client/modify/ModifyRes.d.ts +0 -23
- package/dist/src/client/modify/ModifyRes.js +0 -101
- package/dist/src/client/modify/alias.d.ts +0 -4
- package/dist/src/client/modify/alias.js +0 -57
- package/dist/src/client/modify/binary.d.ts +0 -6
- package/dist/src/client/modify/binary.js +0 -80
- package/dist/src/client/modify/cardinality.d.ts +0 -6
- package/dist/src/client/modify/cardinality.js +0 -63
- package/dist/src/client/modify/create.d.ts +0 -5
- package/dist/src/client/modify/create.js +0 -228
- package/dist/src/client/modify/delete.d.ts +0 -4
- package/dist/src/client/modify/delete.js +0 -47
- package/dist/src/client/modify/expire.d.ts +0 -3
- package/dist/src/client/modify/expire.js +0 -25
- package/dist/src/client/modify/fixed.d.ts +0 -5
- package/dist/src/client/modify/fixed.js +0 -235
- package/dist/src/client/modify/index.d.ts +0 -4
- package/dist/src/client/modify/index.js +0 -4
- package/dist/src/client/modify/json.d.ts +0 -4
- package/dist/src/client/modify/json.js +0 -26
- package/dist/src/client/modify/modify.d.ts +0 -5
- package/dist/src/client/modify/modify.js +0 -134
- package/dist/src/client/modify/references/appendEdgeRefs.d.ts +0 -4
- package/dist/src/client/modify/references/appendEdgeRefs.js +0 -33
- package/dist/src/client/modify/references/edge.d.ts +0 -5
- package/dist/src/client/modify/references/edge.js +0 -336
- package/dist/src/client/modify/references/getEdgeSize.d.ts +0 -3
- package/dist/src/client/modify/references/getEdgeSize.js +0 -27
- package/dist/src/client/modify/references/reference.d.ts +0 -11
- package/dist/src/client/modify/references/reference.js +0 -124
- package/dist/src/client/modify/references/references.d.ts +0 -16
- package/dist/src/client/modify/references/references.js +0 -316
- package/dist/src/client/modify/setCursor.d.ts +0 -5
- package/dist/src/client/modify/setCursor.js +0 -33
- package/dist/src/client/modify/string.d.ts +0 -5
- package/dist/src/client/modify/string.js +0 -71
- package/dist/src/client/modify/text.d.ts +0 -8
- package/dist/src/client/modify/text.js +0 -69
- package/dist/src/client/modify/update.d.ts +0 -6
- package/dist/src/client/modify/update.js +0 -90
- package/dist/src/client/modify/upsert.d.ts +0 -3
- package/dist/src/client/modify/vector.d.ts +0 -4
- package/dist/src/client/modify/vector.js +0 -53
- package/dist/src/client/query/include/toBuffer.js +0 -123
- package/dist/src/client/query/read/read.d.ts +0 -9
- package/dist/src/client/query/read/read.js +0 -483
- /package/dist/src/client/query/include/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
- /package/dist/src/client/query/toByteCode/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { deleteProp } from './delete.js';
|
|
2
|
+
import { writeU32, writeU8, writeU8Array } from '../uint.js';
|
|
3
|
+
import { validate } from '../validate.js';
|
|
4
|
+
import { xxHash64 } from '../../xxHash64.js';
|
|
5
|
+
import { ENCODER } from '@based/utils';
|
|
6
|
+
import { reserve } from '../resize.js';
|
|
7
|
+
import { PROP_CURSOR_SIZE, writePropCursor } from '../cursor.js';
|
|
8
|
+
import { CREATE } from '../types.js';
|
|
9
|
+
export const writeCardinalityRaw = (ctx, def, val, sizeFixBecauseEdgeIsDifferent = val.length) => {
|
|
10
|
+
writeU32(ctx, sizeFixBecauseEdgeIsDifferent);
|
|
11
|
+
for (const item of val) {
|
|
12
|
+
validate(def, item);
|
|
13
|
+
if (typeof item === 'string') {
|
|
14
|
+
xxHash64(ENCODER.encode(item), ctx.array, ctx.index);
|
|
15
|
+
ctx.index += 8;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (item instanceof Uint8Array && item.byteLength === 8) {
|
|
19
|
+
writeU8Array(ctx, item);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
throw [def, val];
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const writeCardinality = (ctx, def, val) => {
|
|
26
|
+
if (val === null) {
|
|
27
|
+
deleteProp(ctx, def);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!Array.isArray(val)) {
|
|
31
|
+
val = [val];
|
|
32
|
+
}
|
|
33
|
+
if (val.length === 0) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const size = PROP_CURSOR_SIZE + 1 + 4 + val.length * 8;
|
|
37
|
+
reserve(ctx, PROP_CURSOR_SIZE + size + 1);
|
|
38
|
+
writePropCursor(ctx, def);
|
|
39
|
+
writeU8(ctx, ctx.operation);
|
|
40
|
+
writeCardinalityRaw(ctx, def, val);
|
|
41
|
+
if (ctx.operation === CREATE) {
|
|
42
|
+
ctx.schema.separateSort.bufferTmp[def.prop] = 2;
|
|
43
|
+
ctx.sort++;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=cardinality.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DELETE, UPDATE } from '../types.js';
|
|
2
|
+
import { reserve } from '../resize.js';
|
|
3
|
+
import { PROP_CURSOR_SIZE, writePropCursor } from '../cursor.js';
|
|
4
|
+
import { writeU8 } from '../uint.js';
|
|
5
|
+
export const deleteProp = (ctx, def) => {
|
|
6
|
+
if (ctx.operation !== UPDATE) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
reserve(ctx, PROP_CURSOR_SIZE + 1);
|
|
10
|
+
writePropCursor(ctx, def);
|
|
11
|
+
writeU8(ctx, DELETE);
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Ctx } from '../Ctx.js';
|
|
2
|
+
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
3
|
+
export declare const writeFixed: (ctx: Ctx, def: PropDef | PropDefEdge, val: string | boolean | number) => void;
|
|
4
|
+
export declare const writeFixedAtOffset: (ctx: Ctx, def: PropDef, val: string | boolean | number, offset: number) => void;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, UINT16, UINT32, UINT8, } from '@based/schema/def';
|
|
2
|
+
import { convertToTimestamp, ENCODER } from '@based/utils';
|
|
3
|
+
import { getBuffer } from './binary.js';
|
|
4
|
+
import { reserve } from '../resize.js';
|
|
5
|
+
import { writeU16, writeU32, writeU64, writeU8, writeU8Array } from '../uint.js';
|
|
6
|
+
import { validate } from '../validate.js';
|
|
7
|
+
const map = {};
|
|
8
|
+
map[BINARY] = (ctx, val, def) => {
|
|
9
|
+
val = getBuffer(val);
|
|
10
|
+
validate(def, val);
|
|
11
|
+
reserve(ctx, val.byteLength + 1);
|
|
12
|
+
writeU8(ctx, val.byteLength);
|
|
13
|
+
writeU8Array(ctx, val);
|
|
14
|
+
};
|
|
15
|
+
map[STRING] = (ctx, val, def) => {
|
|
16
|
+
const valBuf = ENCODER.encode(val);
|
|
17
|
+
const size = valBuf.byteLength;
|
|
18
|
+
if (size + 1 > def.len) {
|
|
19
|
+
throw [def, val, `max length of ${def.len - 1},`];
|
|
20
|
+
}
|
|
21
|
+
validate(def, val);
|
|
22
|
+
reserve(ctx, size + 1);
|
|
23
|
+
const fullSize = def.len - 1;
|
|
24
|
+
ctx.array[ctx.index] = size;
|
|
25
|
+
ctx.array.set(valBuf, ctx.index + 1);
|
|
26
|
+
ctx.index += fullSize + 1;
|
|
27
|
+
if (fullSize !== size) {
|
|
28
|
+
ctx.array.fill(0, ctx.index - (fullSize - size), ctx.index);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
map[BOOLEAN] = (ctx, val, def) => {
|
|
32
|
+
val ??= def.default;
|
|
33
|
+
validate(def, val);
|
|
34
|
+
reserve(ctx, 1);
|
|
35
|
+
writeU8(ctx, val ? 1 : 0);
|
|
36
|
+
};
|
|
37
|
+
map[ENUM] = (ctx, val, def) => {
|
|
38
|
+
validate(def, val);
|
|
39
|
+
if (val === null) {
|
|
40
|
+
reserve(ctx, 1);
|
|
41
|
+
writeU8(ctx, def.default);
|
|
42
|
+
}
|
|
43
|
+
else if (val in def.reverseEnum) {
|
|
44
|
+
reserve(ctx, 1);
|
|
45
|
+
writeU8(ctx, def.reverseEnum[val] + 1);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw [def, val];
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
map[NUMBER] = (ctx, val, def) => {
|
|
52
|
+
val ??= def.default;
|
|
53
|
+
validate(def, val);
|
|
54
|
+
const view = new DataView(ctx.array.buffer, ctx.array.byteOffset + ctx.index, 8);
|
|
55
|
+
reserve(ctx, 8);
|
|
56
|
+
view.setFloat64(0, val, true);
|
|
57
|
+
ctx.index += 8;
|
|
58
|
+
};
|
|
59
|
+
map[TIMESTAMP] = (ctx, val, def) => {
|
|
60
|
+
val ??= def.default;
|
|
61
|
+
const parsedValue = convertToTimestamp(val);
|
|
62
|
+
validate(def, parsedValue);
|
|
63
|
+
reserve(ctx, 8);
|
|
64
|
+
writeU64(ctx, parsedValue);
|
|
65
|
+
};
|
|
66
|
+
map[UINT32] = (ctx, val, def) => {
|
|
67
|
+
val ??= def.default;
|
|
68
|
+
validate(def, val);
|
|
69
|
+
reserve(ctx, 4);
|
|
70
|
+
writeU32(ctx, val);
|
|
71
|
+
};
|
|
72
|
+
map[UINT16] = (ctx, val, def) => {
|
|
73
|
+
val ??= def.default;
|
|
74
|
+
validate(def, val);
|
|
75
|
+
reserve(ctx, 2);
|
|
76
|
+
writeU16(ctx, val);
|
|
77
|
+
};
|
|
78
|
+
map[UINT8] = map[INT8] = (ctx, val, def) => {
|
|
79
|
+
val ??= def.default;
|
|
80
|
+
validate(def, val);
|
|
81
|
+
reserve(ctx, 1);
|
|
82
|
+
writeU8(ctx, val);
|
|
83
|
+
};
|
|
84
|
+
map[INT32] = (ctx, val, def) => {
|
|
85
|
+
val ??= def.default;
|
|
86
|
+
validate(def, val);
|
|
87
|
+
reserve(ctx, 4);
|
|
88
|
+
writeU32(ctx, val);
|
|
89
|
+
};
|
|
90
|
+
map[INT16] = (ctx, val, def) => {
|
|
91
|
+
val ??= def.default;
|
|
92
|
+
validate(def, val);
|
|
93
|
+
reserve(ctx, 2);
|
|
94
|
+
writeU16(ctx, val);
|
|
95
|
+
};
|
|
96
|
+
export const writeFixed = (ctx, def, val) => {
|
|
97
|
+
return map[def.typeIndex](ctx, val, def);
|
|
98
|
+
};
|
|
99
|
+
export const writeFixedAtOffset = (ctx, def, val, offset) => {
|
|
100
|
+
const index = ctx.index;
|
|
101
|
+
ctx.index = offset;
|
|
102
|
+
map[def.typeIndex](ctx, val, def);
|
|
103
|
+
ctx.index = index;
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=fixed.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PROP_CURSOR_SIZE, writeMainCursor } from '../cursor.js';
|
|
2
|
+
import { writeU16, writeU8 } from '../uint.js';
|
|
3
|
+
import { reserve } from '../resize.js';
|
|
4
|
+
import { writeFixed } from './fixed.js';
|
|
5
|
+
import { DECREMENT, INCREMENT } from '../types.js';
|
|
6
|
+
export const writeIncrement = (ctx, def, val) => {
|
|
7
|
+
if (typeof val.increment !== 'number') {
|
|
8
|
+
throw [def, val];
|
|
9
|
+
}
|
|
10
|
+
if (val.increment === 0) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
reserve(ctx, PROP_CURSOR_SIZE + 4 + def.len);
|
|
14
|
+
writeMainCursor(ctx);
|
|
15
|
+
if (val.increment > 0) {
|
|
16
|
+
writeU8(ctx, INCREMENT);
|
|
17
|
+
writeU8(ctx, def.typeIndex);
|
|
18
|
+
writeU16(ctx, def.start);
|
|
19
|
+
writeFixed(ctx, def, val.increment);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
writeU8(ctx, DECREMENT);
|
|
23
|
+
writeU8(ctx, def.typeIndex);
|
|
24
|
+
writeU16(ctx, def.start);
|
|
25
|
+
writeFixed(ctx, def, -val.increment);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=increment.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { writeFixedAtOffset } from './fixed.js';
|
|
2
|
+
import { reserve } from '../resize.js';
|
|
3
|
+
import { PROP_CURSOR_SIZE, writeMainCursor } from '../cursor.js';
|
|
4
|
+
import { writeU32, writeU8, writeU8Array } from '../uint.js';
|
|
5
|
+
export const writeMainBuffer = (ctx) => {
|
|
6
|
+
if (ctx.cursor.main === null) {
|
|
7
|
+
reserve(ctx, PROP_CURSOR_SIZE + 5 + ctx.schema.mainLen);
|
|
8
|
+
writeMainCursor(ctx);
|
|
9
|
+
writeU8(ctx, ctx.operation);
|
|
10
|
+
writeU32(ctx, ctx.schema.mainLen);
|
|
11
|
+
ctx.cursor.main = ctx.index;
|
|
12
|
+
writeU8Array(ctx, ctx.schema.mainEmpty);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export const writeMainValue = (ctx, def, val) => {
|
|
16
|
+
reserve(ctx, PROP_CURSOR_SIZE + 5 + ctx.schema.mainLen);
|
|
17
|
+
writeMainBuffer(ctx);
|
|
18
|
+
writeFixedAtOffset(ctx, def, typeof val === 'object' && val !== null && 'increment' in val
|
|
19
|
+
? val.increment
|
|
20
|
+
: val, ctx.cursor.main + def.start);
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isPropDef } from '@based/schema/def';
|
|
2
|
+
import { writeSeparate } from './separate.js';
|
|
3
|
+
import { writeMainValue } from './main.js';
|
|
4
|
+
import { writeIncrement } from './increment.js';
|
|
5
|
+
export const writeObject = (ctx, tree, obj) => {
|
|
6
|
+
for (const key in obj) {
|
|
7
|
+
const val = obj[key];
|
|
8
|
+
if (val === undefined) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
const def = tree[key];
|
|
12
|
+
if (def === undefined) {
|
|
13
|
+
if (ctx.unsafe) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
throw [tree, key];
|
|
17
|
+
}
|
|
18
|
+
if (!isPropDef(def)) {
|
|
19
|
+
writeObject(ctx, def, val);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (def.separate) {
|
|
23
|
+
writeSeparate(ctx, def, val);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (ctx.overwrite) {
|
|
27
|
+
writeMainValue(ctx, def, val);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (typeof val === 'object' && val !== null) {
|
|
31
|
+
writeIncrement(ctx, def, val);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
ctx.main.set(def, val);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Tmp } from '../Tmp.js';
|
|
2
|
+
import { reserve } from '../resize.js';
|
|
3
|
+
import { PROP_CURSOR_SIZE, writePropCursor } from '../cursor.js';
|
|
4
|
+
import { EDGE_NOINDEX_REALID, EDGE_NOINDEX_TMPID, NOEDGE_NOINDEX_REALID, NOEDGE_NOINDEX_TMPID, } from '../types.js';
|
|
5
|
+
import { writeEdges } from '../edges/index.js';
|
|
6
|
+
import { deleteProp } from './delete.js';
|
|
7
|
+
import { writeU32, writeU8 } from '../uint.js';
|
|
8
|
+
const writeReferenceId = (ctx, def, val, refOp) => {
|
|
9
|
+
if (!def.validation(val, def)) {
|
|
10
|
+
throw [def, val];
|
|
11
|
+
}
|
|
12
|
+
reserve(ctx, PROP_CURSOR_SIZE + 6);
|
|
13
|
+
writePropCursor(ctx, def);
|
|
14
|
+
writeU8(ctx, ctx.operation);
|
|
15
|
+
writeU8(ctx, refOp);
|
|
16
|
+
writeU32(ctx, val);
|
|
17
|
+
};
|
|
18
|
+
export const writeReference = (ctx, def, val) => {
|
|
19
|
+
if (val === null) {
|
|
20
|
+
deleteProp(ctx, def);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (typeof val === 'number') {
|
|
24
|
+
if (def.hasDefaultEdges) {
|
|
25
|
+
writeReferenceId(ctx, def, val, EDGE_NOINDEX_REALID);
|
|
26
|
+
writeEdges(ctx, def, {}, true);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
writeReferenceId(ctx, def, val, NOEDGE_NOINDEX_REALID);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (typeof val === 'object') {
|
|
34
|
+
if (typeof val.id === 'object') {
|
|
35
|
+
if (val.id === null) {
|
|
36
|
+
throw [def, val];
|
|
37
|
+
}
|
|
38
|
+
if ('then' in val.id && typeof val.id.then === 'function') {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
const resolvedId = val.id.id;
|
|
41
|
+
if (resolvedId) {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
val.id = resolvedId;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (typeof val.id === 'number') {
|
|
48
|
+
if (!def.edges || val instanceof Tmp || val instanceof Promise) {
|
|
49
|
+
writeReferenceId(ctx, def, val.id, NOEDGE_NOINDEX_REALID);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
writeReferenceId(ctx, def, val.id, EDGE_NOINDEX_REALID);
|
|
53
|
+
writeEdges(ctx, def, val, true);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (val.id instanceof Tmp) {
|
|
58
|
+
if (val.id.batch !== ctx.batch) {
|
|
59
|
+
throw val.id;
|
|
60
|
+
}
|
|
61
|
+
if (!def.edges) {
|
|
62
|
+
writeReferenceId(ctx, def, val.id.tmpId, NOEDGE_NOINDEX_TMPID);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
writeReferenceId(ctx, def, val.id.tmpId, EDGE_NOINDEX_TMPID);
|
|
66
|
+
writeEdges(ctx, def, val, true);
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (val instanceof Tmp) {
|
|
71
|
+
if (val.batch !== ctx.batch) {
|
|
72
|
+
throw val;
|
|
73
|
+
}
|
|
74
|
+
if (def.hasDefaultEdges) {
|
|
75
|
+
writeReferenceId(ctx, def, val.tmpId, EDGE_NOINDEX_TMPID);
|
|
76
|
+
writeEdges(ctx, def, {}, true);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
writeReferenceId(ctx, def, val.tmpId, NOEDGE_NOINDEX_TMPID);
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (val.id instanceof Promise) {
|
|
84
|
+
throw val.id;
|
|
85
|
+
}
|
|
86
|
+
if (val instanceof Promise) {
|
|
87
|
+
throw val;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
throw [def, val];
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=reference.js.map
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { reserve } from '../resize.js';
|
|
2
|
+
import { PROP_CURSOR_SIZE, writePropCursor } from '../cursor.js';
|
|
3
|
+
import { writeU32, writeU8 } from '../uint.js';
|
|
4
|
+
import { Tmp } from '../Tmp.js';
|
|
5
|
+
import { validate } from '../validate.js';
|
|
6
|
+
import { writeEdges } from '../edges/index.js';
|
|
7
|
+
import { writeUint32 } from '@based/utils';
|
|
8
|
+
import { DELETE, EDGE_INDEX_REALID, EDGE_INDEX_TMPID, EDGE_NOINDEX_REALID, EDGE_NOINDEX_TMPID, NOEDGE_INDEX_REALID, NOEDGE_INDEX_TMPID, NOEDGE_NOINDEX_REALID, NOEDGE_NOINDEX_TMPID, REF_OP_DELETE, REF_OP_OVERWRITE, REF_OP_PUT_ADD, REF_OP_PUT_OVERWRITE, REF_OP_UPDATE, } from '../types.js';
|
|
9
|
+
const clearReferences = (ctx, def) => {
|
|
10
|
+
reserve(ctx, PROP_CURSOR_SIZE + 1);
|
|
11
|
+
writePropCursor(ctx, def);
|
|
12
|
+
writeU8(ctx, DELETE);
|
|
13
|
+
};
|
|
14
|
+
const hasEdgeOrIndex = (def, obj) => {
|
|
15
|
+
if (def.edges) {
|
|
16
|
+
for (const key in obj) {
|
|
17
|
+
if (key[0] === '$') {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const hasAnEdge = (def, obj) => {
|
|
24
|
+
if (def.hasDefaultEdges) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (def.edges) {
|
|
28
|
+
for (const key in obj) {
|
|
29
|
+
if (key[0] === '$' && key !== '$index') {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const putReferences = (ctx, def, val, refOp) => {
|
|
36
|
+
reserve(ctx, PROP_CURSOR_SIZE + 6 + val.length * 4);
|
|
37
|
+
writePropCursor(ctx, def);
|
|
38
|
+
writeU8(ctx, ctx.operation);
|
|
39
|
+
writeU32(ctx, val.length * 4 + 1);
|
|
40
|
+
writeU8(ctx, refOp === REF_OP_OVERWRITE ? REF_OP_PUT_OVERWRITE : REF_OP_PUT_ADD);
|
|
41
|
+
let index = 0;
|
|
42
|
+
for (const id of val) {
|
|
43
|
+
if (typeof id === 'number') {
|
|
44
|
+
validate(def, id);
|
|
45
|
+
writeU32(ctx, id);
|
|
46
|
+
index++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (typeof id === 'object' && id !== null && typeof id.id === 'number') {
|
|
50
|
+
if (hasEdgeOrIndex(def, id)) {
|
|
51
|
+
return index;
|
|
52
|
+
}
|
|
53
|
+
validate(def, id.id);
|
|
54
|
+
writeU32(ctx, id.id);
|
|
55
|
+
index++;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
return index;
|
|
59
|
+
}
|
|
60
|
+
return index;
|
|
61
|
+
};
|
|
62
|
+
const updateReferences = (ctx, def, val, index, length, refOp) => {
|
|
63
|
+
reserve(ctx, PROP_CURSOR_SIZE + 6 + val.length * 9);
|
|
64
|
+
writePropCursor(ctx, def);
|
|
65
|
+
writeU8(ctx, ctx.operation);
|
|
66
|
+
const sizeIndex = ctx.index;
|
|
67
|
+
ctx.index += 4;
|
|
68
|
+
const start = ctx.index;
|
|
69
|
+
writeU8(ctx, index > 0 ? REF_OP_UPDATE : refOp);
|
|
70
|
+
writeU32(ctx, length);
|
|
71
|
+
while (length--) {
|
|
72
|
+
let id = val[index++];
|
|
73
|
+
if (def.hasDefaultEdges) {
|
|
74
|
+
if (typeof id === 'number' ||
|
|
75
|
+
id instanceof Tmp ||
|
|
76
|
+
id instanceof Promise) {
|
|
77
|
+
id = { id: id };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (typeof id === 'number') {
|
|
81
|
+
validate(def, id);
|
|
82
|
+
writeU8(ctx, NOEDGE_NOINDEX_REALID);
|
|
83
|
+
writeU32(ctx, id);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (typeof id !== 'object' || id === null) {
|
|
87
|
+
throw [def, val];
|
|
88
|
+
}
|
|
89
|
+
if (typeof id.then === 'function') {
|
|
90
|
+
if (id.id) {
|
|
91
|
+
validate(def, id.id);
|
|
92
|
+
writeU8(ctx, NOEDGE_NOINDEX_REALID);
|
|
93
|
+
writeU32(ctx, id.id);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (id instanceof Tmp && id.batch === ctx.batch) {
|
|
97
|
+
writeU8(ctx, NOEDGE_NOINDEX_TMPID);
|
|
98
|
+
writeU32(ctx, id.tmpId);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
throw id;
|
|
102
|
+
}
|
|
103
|
+
if (typeof id.id === 'number') {
|
|
104
|
+
writeReferenceObj(ctx, def, id.id, id, false);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (typeof id.id !== 'object' || id.id === null) {
|
|
108
|
+
throw [def, val];
|
|
109
|
+
}
|
|
110
|
+
if (typeof id.id.then === 'function') {
|
|
111
|
+
if (id.id.id) {
|
|
112
|
+
writeReferenceObj(ctx, def, id.id.id, id, false);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (id.id instanceof Tmp && id.id.batch === ctx.batch) {
|
|
116
|
+
writeReferenceObj(ctx, def, id.id.tmpId, id, true);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
throw id.id;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
writeUint32(ctx.array, ctx.index - start, sizeIndex);
|
|
123
|
+
};
|
|
124
|
+
const putOrUpdateReferences = (ctx, def, val, refOp) => {
|
|
125
|
+
if (!val.length) {
|
|
126
|
+
clearReferences(ctx, def);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (def.hasDefaultEdges) {
|
|
130
|
+
updateReferences(ctx, def, val, 0, val.length, refOp);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const start = ctx.index;
|
|
134
|
+
const index = putReferences(ctx, def, val, refOp);
|
|
135
|
+
if (index === val.length) {
|
|
136
|
+
// did all
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (index === 0) {
|
|
140
|
+
// did nothing
|
|
141
|
+
ctx.index = start;
|
|
142
|
+
ctx.cursor.prop = null;
|
|
143
|
+
updateReferences(ctx, def, val, 0, val.length, refOp);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// did partial
|
|
147
|
+
ctx.cursor.prop = null;
|
|
148
|
+
updateReferences(ctx, def, val, index, val.length - index, refOp);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const writeReferenceObj = (ctx, def, id, obj, isTmp) => {
|
|
152
|
+
const hasIndex = typeof obj.$index === 'number';
|
|
153
|
+
const hasEdges = hasAnEdge(def, obj);
|
|
154
|
+
validate(def, id);
|
|
155
|
+
if (hasIndex) {
|
|
156
|
+
if (hasEdges) {
|
|
157
|
+
writeU8(ctx, isTmp ? EDGE_INDEX_TMPID : EDGE_INDEX_REALID);
|
|
158
|
+
writeU32(ctx, id);
|
|
159
|
+
writeU32(ctx, obj.$index);
|
|
160
|
+
writeEdges(ctx, def, obj, false);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
writeU8(ctx, isTmp ? NOEDGE_INDEX_TMPID : NOEDGE_INDEX_REALID);
|
|
164
|
+
writeU32(ctx, id);
|
|
165
|
+
writeU32(ctx, obj.$index);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else if (hasEdges) {
|
|
169
|
+
writeU8(ctx, isTmp ? EDGE_NOINDEX_TMPID : EDGE_NOINDEX_REALID);
|
|
170
|
+
writeU32(ctx, id);
|
|
171
|
+
writeEdges(ctx, def, obj, false);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
writeU8(ctx, isTmp ? NOEDGE_NOINDEX_TMPID : NOEDGE_NOINDEX_REALID);
|
|
175
|
+
writeU32(ctx, id);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const deleteReferences = (ctx, def, val) => {
|
|
179
|
+
const size = 4 * val.length + 1;
|
|
180
|
+
reserve(ctx, PROP_CURSOR_SIZE + 6 + size);
|
|
181
|
+
writePropCursor(ctx, def);
|
|
182
|
+
writeU8(ctx, ctx.operation);
|
|
183
|
+
writeU32(ctx, size);
|
|
184
|
+
writeU8(ctx, REF_OP_DELETE);
|
|
185
|
+
for (const id of val) {
|
|
186
|
+
if (typeof id === 'number') {
|
|
187
|
+
validate(def, id);
|
|
188
|
+
writeU32(ctx, id);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (id === null ||
|
|
192
|
+
typeof id !== 'object' ||
|
|
193
|
+
typeof id.then !== 'function') {
|
|
194
|
+
throw [def, val];
|
|
195
|
+
}
|
|
196
|
+
if (typeof id.id === 'number') {
|
|
197
|
+
writeU32(ctx, id.id);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
throw id.id || id;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
export const writeReferences = (ctx, def, val) => {
|
|
204
|
+
if (typeof val !== 'object') {
|
|
205
|
+
throw [def, val];
|
|
206
|
+
}
|
|
207
|
+
if (val === null) {
|
|
208
|
+
clearReferences(ctx, def);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (Array.isArray(val)) {
|
|
212
|
+
putOrUpdateReferences(ctx, def, val, REF_OP_OVERWRITE);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
for (const key in val) {
|
|
216
|
+
const arr = val[key];
|
|
217
|
+
if (!Array.isArray(arr)) {
|
|
218
|
+
throw [def, val];
|
|
219
|
+
}
|
|
220
|
+
if (key === 'update' || key === 'add') {
|
|
221
|
+
putOrUpdateReferences(ctx, def, arr, REF_OP_UPDATE);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (key === 'delete') {
|
|
225
|
+
deleteReferences(ctx, def, arr);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
throw [def, val];
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
//# sourceMappingURL=references.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { STRING, TEXT, REFERENCE, REFERENCES, BINARY, ALIAS, CARDINALITY, VECTOR, COLVEC, JSON, } from '@based/schema/def';
|
|
2
|
+
import { writeReference } from './reference.js';
|
|
3
|
+
import { writeString } from './string.js';
|
|
4
|
+
import { writeText } from './text.js';
|
|
5
|
+
import { writeReferences } from './references.js';
|
|
6
|
+
import { writeBinary } from './binary.js';
|
|
7
|
+
import { writeAlias } from './alias.js';
|
|
8
|
+
import { writeCardinality } from './cardinality.js';
|
|
9
|
+
import { writeVector } from './vector.js';
|
|
10
|
+
import { writeJson } from './json.js';
|
|
11
|
+
import { markDefaults } from '../create/mark.js';
|
|
12
|
+
export const writeSeparate = (ctx, def, val) => {
|
|
13
|
+
const type = def.typeIndex;
|
|
14
|
+
if (type === STRING) {
|
|
15
|
+
writeString(ctx, def, val, 0);
|
|
16
|
+
}
|
|
17
|
+
else if (type === TEXT) {
|
|
18
|
+
writeText(ctx, def, val);
|
|
19
|
+
}
|
|
20
|
+
else if (type === REFERENCE) {
|
|
21
|
+
writeReference(ctx, def, val);
|
|
22
|
+
}
|
|
23
|
+
else if (type === REFERENCES) {
|
|
24
|
+
writeReferences(ctx, def, val);
|
|
25
|
+
}
|
|
26
|
+
else if (type === BINARY) {
|
|
27
|
+
writeBinary(ctx, def, val);
|
|
28
|
+
}
|
|
29
|
+
else if (type === ALIAS) {
|
|
30
|
+
writeAlias(ctx, def, val);
|
|
31
|
+
}
|
|
32
|
+
else if (type === CARDINALITY) {
|
|
33
|
+
writeCardinality(ctx, def, val);
|
|
34
|
+
}
|
|
35
|
+
else if (type === VECTOR || type === COLVEC) {
|
|
36
|
+
writeVector(ctx, def, val);
|
|
37
|
+
}
|
|
38
|
+
else if (type === JSON) {
|
|
39
|
+
writeJson(ctx, def, val);
|
|
40
|
+
}
|
|
41
|
+
markDefaults(ctx, def, val);
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=separate.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PropDef } from '@based/schema/def';
|
|
2
|
+
import { Ctx } from '../Ctx.js';
|
|
3
|
+
import { LangCode } from '@based/schema';
|
|
4
|
+
export declare const deleteString: (ctx: Ctx, def: PropDef, lang: LangCode) => void;
|
|
5
|
+
export declare const writeString: (ctx: Ctx, def: PropDef, val: any, lang: LangCode) => void;
|