@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
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ModifyCtx } from '../../../index.js';
|
|
2
|
-
import { PropDef, SchemaTypeDef } from '@based/schema/def';
|
|
3
|
-
import { ModifyState } from '../ModifyRes.js';
|
|
4
|
-
import { ModifyErr, ModifyOp } from '../types.js';
|
|
5
|
-
export type RefModifyOpts = {
|
|
6
|
-
id?: number | ModifyState;
|
|
7
|
-
$index?: number;
|
|
8
|
-
} & Record<`$${string}`, any>;
|
|
9
|
-
export type RefModify = ModifyState | RefModifyOpts | number;
|
|
10
|
-
export type Refs = RefModify[] | {
|
|
11
|
-
add?: RefModify[] | RefModify;
|
|
12
|
-
delete?: RefModify[] | RefModify;
|
|
13
|
-
upsert: RefModify[] | RefModify;
|
|
14
|
-
};
|
|
15
|
-
export declare function writeReferences(value: any, ctx: ModifyCtx, schema: SchemaTypeDef, def: PropDef, res: ModifyState, mod: ModifyOp): ModifyErr;
|
|
16
|
-
export declare const dbUpdateFromUpsert: (ctx: ModifyCtx, schema: SchemaTypeDef, def: PropDef, res: ModifyState, promise: Promise<any>) => void;
|
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { REFERENCES } from '@based/schema/def';
|
|
2
|
-
import { ModifyError, ModifyState } from '../ModifyRes.js';
|
|
3
|
-
import { setCursor } from '../setCursor.js';
|
|
4
|
-
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, RANGE_ERR, REF_OP_OVERWRITE, REF_OP_PUT_ADD, REF_OP_PUT_OVERWRITE, REF_OP_UPDATE, } 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 || (Array.isArray(value) && value.length === 0)) {
|
|
11
|
-
if (ctx.len + 11 > ctx.max) {
|
|
12
|
-
return RANGE_ERR;
|
|
13
|
-
}
|
|
14
|
-
setCursor(ctx, schema, def.prop, def.typeIndex, 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 === 'update') {
|
|
31
|
-
err = updateRefs(def, ctx, schema, mod, val, res.tmpId, 1);
|
|
32
|
-
}
|
|
33
|
-
else if (key === 'add') {
|
|
34
|
-
err = updateRefs(def, ctx, schema, mod, val, res.tmpId, 1);
|
|
35
|
-
}
|
|
36
|
-
else if (key === 'upsert') {
|
|
37
|
-
dbUpdateFromUpsert(ctx, schema, def, res, Promise.all(val.map((val) => ctx.db.upsert(def.inverseTypeName, val))));
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
err = new ModifyError(def, value);
|
|
41
|
-
}
|
|
42
|
-
if (err) {
|
|
43
|
-
return err;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export const dbUpdateFromUpsert = (ctx, schema, def, res, promise) => {
|
|
48
|
-
res.promises ??= [];
|
|
49
|
-
res.promises.push(promise.then((result) => {
|
|
50
|
-
let payload = {};
|
|
51
|
-
let i = 0;
|
|
52
|
-
for (; i < def.path.length - 1; i++) {
|
|
53
|
-
payload = payload[def.path[i]] = {};
|
|
54
|
-
}
|
|
55
|
-
payload[def.path[i]] = result;
|
|
56
|
-
return ctx.db.update(schema.type, res.getId(), payload);
|
|
57
|
-
}));
|
|
58
|
-
};
|
|
59
|
-
function deleteRefs(def, ctx, schema, modifyOp, refs, parentId) {
|
|
60
|
-
let size = 4 * refs.length + 1;
|
|
61
|
-
if (ctx.len + 10 + size > ctx.max) {
|
|
62
|
-
return RANGE_ERR;
|
|
63
|
-
}
|
|
64
|
-
setCursor(ctx, schema, def.prop, def.typeIndex, parentId, modifyOp);
|
|
65
|
-
ctx.buf[ctx.len++] = modifyOp;
|
|
66
|
-
ctx.buf[ctx.len++] = size;
|
|
67
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
68
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
69
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
70
|
-
ctx.buf[ctx.len++] = 2;
|
|
71
|
-
for (let ref of refs) {
|
|
72
|
-
if (typeof ref === 'number') {
|
|
73
|
-
ctx.buf[ctx.len++] = ref;
|
|
74
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
75
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
76
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
77
|
-
}
|
|
78
|
-
else if (ref instanceof ModifyState) {
|
|
79
|
-
if (ref.error) {
|
|
80
|
-
return ref.error;
|
|
81
|
-
}
|
|
82
|
-
ref = ref.tmpId;
|
|
83
|
-
ctx.buf[ctx.len++] = ref;
|
|
84
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
85
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
86
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return new ModifyError(def, refs);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function updateRefs(def, ctx, schema, mod, refs, parentId, op) {
|
|
94
|
-
if (ctx.len + 19 + refs.length * 4 > ctx.max) {
|
|
95
|
-
return RANGE_ERR;
|
|
96
|
-
}
|
|
97
|
-
setCursor(ctx, schema, def.prop, def.typeIndex, parentId, mod);
|
|
98
|
-
const initpos = ctx.len;
|
|
99
|
-
const nrOrErr = putRefs(def, ctx, mod, refs, op);
|
|
100
|
-
if (nrOrErr) {
|
|
101
|
-
if (typeof nrOrErr === 'number') {
|
|
102
|
-
if (nrOrErr === refs.length) {
|
|
103
|
-
ctx.len = initpos;
|
|
104
|
-
}
|
|
105
|
-
else if (ctx.len + 2 > ctx.max) {
|
|
106
|
-
return RANGE_ERR;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
ctx.buf[ctx.len++] = 0;
|
|
110
|
-
ctx.buf[ctx.len++] = REFERENCES;
|
|
111
|
-
}
|
|
112
|
-
return appendRefs(def, ctx, mod, refs, op, nrOrErr);
|
|
113
|
-
}
|
|
114
|
-
return nrOrErr;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
118
|
-
if (ctx.len + 10 > ctx.max) {
|
|
119
|
-
return RANGE_ERR;
|
|
120
|
-
}
|
|
121
|
-
const hasEdges = !!def.edges;
|
|
122
|
-
ctx.buf[ctx.len++] = modifyOp;
|
|
123
|
-
let i = refs.length - remaining;
|
|
124
|
-
let totalpos = ctx.len;
|
|
125
|
-
ctx.len += 4;
|
|
126
|
-
// if it just did a PUT, it should ADD not overwrite the remaining
|
|
127
|
-
ctx.buf[ctx.len++] = i === 0 ? op : REF_OP_UPDATE;
|
|
128
|
-
ctx.buf[ctx.len++] = remaining;
|
|
129
|
-
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
130
|
-
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
131
|
-
ctx.buf[ctx.len++] = remaining >>>= 8;
|
|
132
|
-
for (; i < refs.length; i++) {
|
|
133
|
-
let ref = refs[i];
|
|
134
|
-
let id;
|
|
135
|
-
let index;
|
|
136
|
-
let isTmpId;
|
|
137
|
-
if (def.hasDefaultEdges) {
|
|
138
|
-
if (typeof ref !== 'object') {
|
|
139
|
-
ref = { id: ref };
|
|
140
|
-
}
|
|
141
|
-
else if (ref instanceof ModifyState) {
|
|
142
|
-
ref = { id: ref };
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (typeof ref === 'object') {
|
|
146
|
-
if (ref instanceof ModifyState) {
|
|
147
|
-
if (ref.error) {
|
|
148
|
-
return ref.error;
|
|
149
|
-
}
|
|
150
|
-
const resolvedId = ref.getId();
|
|
151
|
-
if (resolvedId) {
|
|
152
|
-
id = resolvedId;
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
id = ref.tmpId;
|
|
156
|
-
isTmpId = true;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
else if (ref.id instanceof ModifyState) {
|
|
160
|
-
if (ref.id.error) {
|
|
161
|
-
return ref.id.error;
|
|
162
|
-
}
|
|
163
|
-
const resolvedId = ref.id.getId();
|
|
164
|
-
if (resolvedId) {
|
|
165
|
-
id = resolvedId;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
id = ref.id.tmpId;
|
|
169
|
-
isTmpId = true;
|
|
170
|
-
}
|
|
171
|
-
index = ref.$index;
|
|
172
|
-
}
|
|
173
|
-
else if (ref.id > 0) {
|
|
174
|
-
id = ref.id;
|
|
175
|
-
index = ref.$index;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
return new ModifyError(def, refs);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else if (ref > 0) {
|
|
182
|
-
id = ref;
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
return new ModifyError(def, refs);
|
|
186
|
-
}
|
|
187
|
-
if (!def.validation(id, def)) {
|
|
188
|
-
return new ModifyError(def, refs);
|
|
189
|
-
}
|
|
190
|
-
if (hasEdges && typeof ref === 'object' && !(ref instanceof ModifyState)) {
|
|
191
|
-
if (index === undefined) {
|
|
192
|
-
if (ctx.len + 9 > ctx.max) {
|
|
193
|
-
return RANGE_ERR;
|
|
194
|
-
}
|
|
195
|
-
ctx.buf[ctx.len++] = isTmpId ? EDGE_NOINDEX_TMPID : EDGE_NOINDEX_REALID;
|
|
196
|
-
ctx.buf[ctx.len++] = id;
|
|
197
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
198
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
199
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
200
|
-
}
|
|
201
|
-
else if (typeof index === 'number') {
|
|
202
|
-
if (ctx.len + 13 > ctx.max) {
|
|
203
|
-
return RANGE_ERR;
|
|
204
|
-
}
|
|
205
|
-
ctx.buf[ctx.len++] = isTmpId ? EDGE_INDEX_TMPID : EDGE_INDEX_REALID;
|
|
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
|
-
ctx.buf[ctx.len++] = index;
|
|
211
|
-
ctx.buf[ctx.len++] = index >>>= 8;
|
|
212
|
-
ctx.buf[ctx.len++] = index >>>= 8;
|
|
213
|
-
ctx.buf[ctx.len++] = index >>>= 8;
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
return new ModifyError(def, refs);
|
|
217
|
-
}
|
|
218
|
-
let sizepos = ctx.len;
|
|
219
|
-
ctx.len += 4;
|
|
220
|
-
const err = writeEdges(def, ref, ctx);
|
|
221
|
-
if (err) {
|
|
222
|
-
return err;
|
|
223
|
-
}
|
|
224
|
-
let size = ctx.len - sizepos - 4;
|
|
225
|
-
ctx.buf[sizepos++] = size;
|
|
226
|
-
ctx.buf[sizepos++] = size >>>= 8;
|
|
227
|
-
ctx.buf[sizepos++] = size >>>= 8;
|
|
228
|
-
ctx.buf[sizepos] = size >>>= 8;
|
|
229
|
-
}
|
|
230
|
-
else if (index === undefined) {
|
|
231
|
-
if (ctx.len + 5 > ctx.max) {
|
|
232
|
-
return RANGE_ERR;
|
|
233
|
-
}
|
|
234
|
-
ctx.buf[ctx.len++] = isTmpId
|
|
235
|
-
? NOEDGE_NOINDEX_TMPID
|
|
236
|
-
: NOEDGE_NOINDEX_REALID;
|
|
237
|
-
ctx.buf[ctx.len++] = id;
|
|
238
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
239
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
240
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
241
|
-
}
|
|
242
|
-
else if (typeof index === 'number') {
|
|
243
|
-
if (ctx.len + 9 > ctx.max) {
|
|
244
|
-
return RANGE_ERR;
|
|
245
|
-
}
|
|
246
|
-
ctx.buf[ctx.len++] = isTmpId ? NOEDGE_INDEX_TMPID : NOEDGE_INDEX_REALID;
|
|
247
|
-
ctx.buf[ctx.len++] = id;
|
|
248
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
249
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
250
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
251
|
-
ctx.buf[ctx.len++] = index;
|
|
252
|
-
ctx.buf[ctx.len++] = index >>>= 8;
|
|
253
|
-
ctx.buf[ctx.len++] = index >>>= 8;
|
|
254
|
-
ctx.buf[ctx.len++] = index >>>= 8;
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
return new ModifyError(def, refs);
|
|
258
|
-
}
|
|
259
|
-
ctx.markNodeDirty(ctx.db.schemaTypesParsed[def.inverseTypeName], id);
|
|
260
|
-
}
|
|
261
|
-
let size = ctx.len - totalpos - 4;
|
|
262
|
-
ctx.buf[totalpos++] = size;
|
|
263
|
-
ctx.buf[totalpos++] = size >>>= 8;
|
|
264
|
-
ctx.buf[totalpos++] = size >>>= 8;
|
|
265
|
-
ctx.buf[totalpos] = size >>>= 8;
|
|
266
|
-
}
|
|
267
|
-
function putRefs(def, ctx, modifyOp, refs, op) {
|
|
268
|
-
let size = refs.length * 4 + 1;
|
|
269
|
-
if (refs.length === 0) {
|
|
270
|
-
return 0;
|
|
271
|
-
}
|
|
272
|
-
ctx.buf[ctx.len++] = modifyOp;
|
|
273
|
-
ctx.buf[ctx.len++] = size;
|
|
274
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
275
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
276
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
277
|
-
ctx.buf[ctx.len++] =
|
|
278
|
-
op === REF_OP_OVERWRITE ? REF_OP_PUT_OVERWRITE : REF_OP_PUT_ADD;
|
|
279
|
-
let i = 0;
|
|
280
|
-
for (; i < refs.length; i++) {
|
|
281
|
-
let ref = refs[i];
|
|
282
|
-
if (typeof ref === 'number') {
|
|
283
|
-
if (!def.validation(ref, def)) {
|
|
284
|
-
return new ModifyError(def, ref);
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
ctx.buf[ctx.len++] = ref;
|
|
288
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
289
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
290
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
else if (ref instanceof ModifyState) {
|
|
294
|
-
if (ref.error) {
|
|
295
|
-
return ref.error;
|
|
296
|
-
}
|
|
297
|
-
ref = ref.getId();
|
|
298
|
-
if (!ref) {
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
if (!def.validation(ref, def)) {
|
|
302
|
-
return new ModifyError(def, ref);
|
|
303
|
-
}
|
|
304
|
-
ctx.buf[ctx.len++] = ref;
|
|
305
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
306
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
307
|
-
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
ctx.markNodeDirty(ctx.db.schemaTypesParsed[def.inverseTypeName], ref);
|
|
313
|
-
}
|
|
314
|
-
return refs.length - i;
|
|
315
|
-
}
|
|
316
|
-
//# sourceMappingURL=references.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ModifyCtx } from '../../index.js';
|
|
2
|
-
import { SchemaTypeDef } from '@based/schema/def';
|
|
3
|
-
import { ModifyOp } from './types.js';
|
|
4
|
-
export declare const setCursor: (ctx: ModifyCtx, schema: SchemaTypeDef, field: number, // TODO pass propdef better
|
|
5
|
-
typeIndex: number, id: number, modifyOp: ModifyOp, ignoreField?: boolean) => void;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { CREATE, SWITCH_FIELD, SWITCH_ID_CREATE, SWITCH_ID_UPDATE, SWITCH_TYPE, } from './types.js';
|
|
2
|
-
export const setCursor = (ctx, schema, field, // TODO pass propdef better
|
|
3
|
-
typeIndex, id, modifyOp, ignoreField) => {
|
|
4
|
-
const prefix0 = schema.idUint8[0];
|
|
5
|
-
const prefix1 = schema.idUint8[1];
|
|
6
|
-
if (ctx.prefix0 !== prefix0 || ctx.prefix1 !== prefix1) {
|
|
7
|
-
ctx.buf[ctx.len++] = SWITCH_TYPE; // switch node type
|
|
8
|
-
ctx.buf[ctx.len++] = prefix0; // type1
|
|
9
|
-
ctx.buf[ctx.len++] = prefix1; // type2
|
|
10
|
-
ctx.prefix0 = prefix0;
|
|
11
|
-
ctx.prefix1 = prefix1;
|
|
12
|
-
ctx.field = -1;
|
|
13
|
-
ctx.id = -1;
|
|
14
|
-
ctx.lastMain = -1;
|
|
15
|
-
}
|
|
16
|
-
if (!ignoreField && ctx.field !== field) {
|
|
17
|
-
ctx.buf[ctx.len++] = SWITCH_FIELD; // switch field
|
|
18
|
-
ctx.buf[ctx.len++] = field; // actual field
|
|
19
|
-
ctx.buf[ctx.len++] = typeIndex;
|
|
20
|
-
ctx.field = field;
|
|
21
|
-
}
|
|
22
|
-
if (ctx.id !== id) {
|
|
23
|
-
ctx.id = id;
|
|
24
|
-
ctx.lastMain = -1;
|
|
25
|
-
ctx.buf[ctx.len++] =
|
|
26
|
-
modifyOp === CREATE ? SWITCH_ID_CREATE : SWITCH_ID_UPDATE; // swtch id
|
|
27
|
-
ctx.buf[ctx.len++] = id;
|
|
28
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
29
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
30
|
-
ctx.buf[ctx.len++] = id >>>= 8;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=setCursor.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { LangCode } from '@based/schema';
|
|
2
|
-
import { ModifyCtx } from '../../index.js';
|
|
3
|
-
import { SchemaTypeDef, PropDef } from '@based/schema/def';
|
|
4
|
-
import { ModifyOp, ModifyErr } from './types.js';
|
|
5
|
-
export declare function writeString(lang: LangCode, value: string | null | Uint8Array, ctx: ModifyCtx, schema: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { ENCODER } from '../../index.js';
|
|
2
|
-
import { CREATE, UPDATE, RANGE_ERR, DELETE, DELETE_TEXT_FIELD, MOD_OPS_TO_STRING, } from './types.js';
|
|
3
|
-
import { ModifyError } from './ModifyRes.js';
|
|
4
|
-
import { setCursor } from './setCursor.js';
|
|
5
|
-
import { write } from '../string.js';
|
|
6
|
-
// allow setting buffer in modify create for strings
|
|
7
|
-
// add compression handling for main buffer
|
|
8
|
-
// add compression handling for edge fields
|
|
9
|
-
export function writeString(lang, value, ctx, schema, t, parentId, modifyOp) {
|
|
10
|
-
const isBuffer = value instanceof Uint8Array;
|
|
11
|
-
if (value === null || value === '') {
|
|
12
|
-
if (modifyOp === UPDATE) {
|
|
13
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 2 > ctx.max) {
|
|
14
|
-
return RANGE_ERR;
|
|
15
|
-
}
|
|
16
|
-
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
17
|
-
if (lang === 0) {
|
|
18
|
-
ctx.buf[ctx.len++] = DELETE;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
ctx.buf[ctx.len++] = DELETE_TEXT_FIELD;
|
|
22
|
-
ctx.buf[ctx.len++] = lang;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
if (!t.validation(value, t)) {
|
|
28
|
-
return new ModifyError(t, value);
|
|
29
|
-
}
|
|
30
|
-
if (t.transform) {
|
|
31
|
-
value = t.transform(MOD_OPS_TO_STRING[modifyOp], value);
|
|
32
|
-
}
|
|
33
|
-
let size = isBuffer
|
|
34
|
-
? // @ts-ignore
|
|
35
|
-
value.byteLength
|
|
36
|
-
: // @ts-ignore
|
|
37
|
-
ENCODER.encode(value).byteLength + 6;
|
|
38
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 11 + size > ctx.max) {
|
|
39
|
-
return RANGE_ERR;
|
|
40
|
-
}
|
|
41
|
-
if (modifyOp === CREATE) {
|
|
42
|
-
schema.seperateSort.bufferTmp[t.prop] = 2;
|
|
43
|
-
ctx.hasSortField++;
|
|
44
|
-
if (schema.hasSeperateDefaults) {
|
|
45
|
-
schema.seperateDefaults.bufferTmp[t.prop] = 1;
|
|
46
|
-
ctx.hasDefaults++;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
50
|
-
// TODO if buffer check if second byte is zero or one
|
|
51
|
-
// modOp | size u32 | stringprotocol | string
|
|
52
|
-
ctx.buf[ctx.len] = modifyOp;
|
|
53
|
-
ctx.len += 5;
|
|
54
|
-
if (isBuffer) {
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
ctx.buf.set(value, ctx.len);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
const isNoCompression = t.compression === 0;
|
|
60
|
-
// @ts-ignore stupid str
|
|
61
|
-
size = write(ctx.buf, value, ctx.len, isNoCompression, lang);
|
|
62
|
-
}
|
|
63
|
-
let sizepos = ctx.len + 1 - 5;
|
|
64
|
-
ctx.len += size;
|
|
65
|
-
ctx.buf[sizepos++] = size;
|
|
66
|
-
ctx.buf[sizepos++] = size >>>= 8;
|
|
67
|
-
ctx.buf[sizepos++] = size >>>= 8;
|
|
68
|
-
ctx.buf[sizepos] = size >>>= 8;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=string.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ModifyCtx } from '../../index.js';
|
|
2
|
-
import { ModifyOp, ModifyErr } from './types.js';
|
|
3
|
-
import { SchemaTypeDef, PropDef } from '@based/schema/def';
|
|
4
|
-
import { writeString } from './string.js';
|
|
5
|
-
import { ModifyState } from './ModifyRes.js';
|
|
6
|
-
export declare function writeText(value: {
|
|
7
|
-
[k: string]: Parameters<typeof writeString>[1];
|
|
8
|
-
} | Parameters<typeof writeString>[1], ctx: ModifyCtx, schema: SchemaTypeDef, t: PropDef, res: ModifyState, id: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { CREATE, UPDATE, RANGE_ERR, DELETE, } from './types.js';
|
|
2
|
-
import { writeString } from './string.js';
|
|
3
|
-
import { ModifyError } from './ModifyRes.js';
|
|
4
|
-
import { setCursor } from './setCursor.js';
|
|
5
|
-
export function writeText(value, ctx, schema, t, res, id, modifyOp) {
|
|
6
|
-
if (value === null && !res.locale) {
|
|
7
|
-
if (modifyOp === UPDATE) {
|
|
8
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 1 > ctx.max) {
|
|
9
|
-
return RANGE_ERR;
|
|
10
|
-
}
|
|
11
|
-
setCursor(ctx, schema, t.prop, t.typeIndex, id, modifyOp);
|
|
12
|
-
ctx.buf[ctx.len++] = DELETE;
|
|
13
|
-
}
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if ((value && typeof value !== 'object') || value === null || value === '') {
|
|
17
|
-
let locale = res.locale;
|
|
18
|
-
if (!locale) {
|
|
19
|
-
// TODO: Add def lang option...
|
|
20
|
-
for (const localeCode of schema.seperateTextSort.localeToIndex.keys()) {
|
|
21
|
-
locale = localeCode;
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (!schema.seperateTextSort.localeToIndex.has(locale)) {
|
|
26
|
-
return new ModifyError(t, locale, 'Invalid locale');
|
|
27
|
-
}
|
|
28
|
-
const err = writeString(locale, value, ctx, schema, t, res.tmpId, modifyOp);
|
|
29
|
-
if (modifyOp === CREATE) {
|
|
30
|
-
const index = t.prop * (schema.localeSize + 1);
|
|
31
|
-
const langIndex = schema.seperateTextSort.localeToIndex.get(locale);
|
|
32
|
-
schema.seperateTextSort.bufferTmp[index] -= 1;
|
|
33
|
-
schema.seperateTextSort.bufferTmp[index + langIndex] = 0;
|
|
34
|
-
ctx.hasSortText += 1;
|
|
35
|
-
if (schema.hasSeperateDefaults) {
|
|
36
|
-
schema.seperateDefaults.bufferTmp[t.prop] = 1;
|
|
37
|
-
ctx.hasDefaults++;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return err;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
if (modifyOp === CREATE && schema.hasSeperateDefaults) {
|
|
44
|
-
ctx.hasDefaults++;
|
|
45
|
-
}
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
for (const lang in value) {
|
|
48
|
-
const langC = schema.seperateTextSort.localeStringToIndex.get(lang);
|
|
49
|
-
if (!langC) {
|
|
50
|
-
return new ModifyError(t, lang, 'Invalid locale');
|
|
51
|
-
}
|
|
52
|
-
let s = value[lang];
|
|
53
|
-
const err = writeString(langC[1], s, ctx, schema, t, res.tmpId, modifyOp);
|
|
54
|
-
if (err) {
|
|
55
|
-
return err;
|
|
56
|
-
}
|
|
57
|
-
if (modifyOp === CREATE) {
|
|
58
|
-
const index = t.prop * (1 + schema.localeSize);
|
|
59
|
-
schema.seperateTextSort.bufferTmp[index] -= 1;
|
|
60
|
-
schema.seperateTextSort.bufferTmp[index + langC[0]] = 0;
|
|
61
|
-
ctx.hasSortText += 1;
|
|
62
|
-
if (schema.hasSeperateDefaults) {
|
|
63
|
-
schema.seperateDefaults.bufferTmp[t.prop]++;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=text.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ModifyRes } from './ModifyRes.js';
|
|
2
|
-
import { ModifyOpts } from './types.js';
|
|
3
|
-
import { DbClient } from '../index.js';
|
|
4
|
-
type Payload = Record<string, any>;
|
|
5
|
-
export declare const update: (db: DbClient, type: string, id: number, obj: Payload, opts?: ModifyOpts) => ModifyRes;
|
|
6
|
-
export {};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { MICRO_BUFFER, isValidId, } from '@based/schema/def';
|
|
2
|
-
import { startDrain, flushBuffer } from '../flushModify.js';
|
|
3
|
-
import { setCursor } from './setCursor.js';
|
|
4
|
-
import { modify } from './modify.js';
|
|
5
|
-
import { ModifyState } from './ModifyRes.js';
|
|
6
|
-
import { RANGE_ERR, UPDATE } from './types.js';
|
|
7
|
-
import { appendFixedValue } from './fixed.js';
|
|
8
|
-
import { getByPath } from '@saulx/utils';
|
|
9
|
-
const appendUpdate = (ctx, def, obj, res, overwrite) => {
|
|
10
|
-
const err = modify(ctx, res, obj, def, UPDATE, def.tree, overwrite);
|
|
11
|
-
if (err) {
|
|
12
|
-
return err;
|
|
13
|
-
}
|
|
14
|
-
if (def.updateTs) {
|
|
15
|
-
const updateTs = Date.now();
|
|
16
|
-
for (const prop of def.updateTs) {
|
|
17
|
-
if (getByPath(obj, prop.path) !== undefined) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
if (ctx.mergeMain) {
|
|
21
|
-
ctx.mergeMain.push(prop, updateTs);
|
|
22
|
-
ctx.mergeMainSize += prop.len + 4;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
ctx.mergeMain = [prop, updateTs];
|
|
26
|
-
ctx.mergeMainSize = prop.len + 4;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (ctx.mergeMain) {
|
|
31
|
-
let { mergeMain, mergeMainSize } = ctx;
|
|
32
|
-
ctx.mergeMainSize = 0;
|
|
33
|
-
ctx.mergeMain = null;
|
|
34
|
-
if (ctx.len + 15 + mergeMain.length * 4 > ctx.max) {
|
|
35
|
-
return RANGE_ERR;
|
|
36
|
-
}
|
|
37
|
-
setCursor(ctx, def, 0, MICRO_BUFFER, res.tmpId, UPDATE);
|
|
38
|
-
ctx.buf[ctx.len++] = 5;
|
|
39
|
-
ctx.buf[ctx.len++] = mergeMainSize;
|
|
40
|
-
ctx.buf[ctx.len++] = mergeMainSize >>>= 8;
|
|
41
|
-
ctx.buf[ctx.len++] = mergeMainSize >>>= 8;
|
|
42
|
-
ctx.buf[ctx.len++] = mergeMainSize >>>= 8;
|
|
43
|
-
for (let i = 0; i < mergeMain.length; i += 2) {
|
|
44
|
-
const t = mergeMain[i];
|
|
45
|
-
const v = mergeMain[i + 1];
|
|
46
|
-
let { start, len } = t;
|
|
47
|
-
ctx.buf[ctx.len++] = start;
|
|
48
|
-
ctx.buf[ctx.len++] = start >>>= 8;
|
|
49
|
-
ctx.buf[ctx.len++] = len;
|
|
50
|
-
ctx.buf[ctx.len++] = len >>>= 8;
|
|
51
|
-
const err = appendFixedValue(ctx, v, t, UPDATE);
|
|
52
|
-
if (err) {
|
|
53
|
-
return err;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
export const update = (db, type, id, obj, opts) => {
|
|
59
|
-
const def = db.schemaTypesParsed[type];
|
|
60
|
-
if (!def) {
|
|
61
|
-
throw new Error(`Unknown type: ${type}. Did you mean on of: ${Object.keys(db.schemaTypesParsed).join(', ')}`);
|
|
62
|
-
}
|
|
63
|
-
if (!isValidId(id)) {
|
|
64
|
-
throw new Error(`Update ${id} is not a valid id`);
|
|
65
|
-
}
|
|
66
|
-
const ctx = db.modifyCtx;
|
|
67
|
-
const pos = ctx.len;
|
|
68
|
-
const res = new ModifyState(def.id, id, db, opts, true);
|
|
69
|
-
const err = appendUpdate(ctx, def, obj, res, opts?.overwrite);
|
|
70
|
-
if (err) {
|
|
71
|
-
ctx.prefix0 = -1; // force a new cursor
|
|
72
|
-
ctx.len = pos;
|
|
73
|
-
if (err === RANGE_ERR) {
|
|
74
|
-
if (pos === 8) {
|
|
75
|
-
throw new Error('out of range');
|
|
76
|
-
}
|
|
77
|
-
void flushBuffer(db);
|
|
78
|
-
return update(db, type, id, obj, opts);
|
|
79
|
-
}
|
|
80
|
-
res.error = err;
|
|
81
|
-
throw err;
|
|
82
|
-
}
|
|
83
|
-
ctx.markNodeDirty(def, id);
|
|
84
|
-
if (!db.isDraining) {
|
|
85
|
-
startDrain(db);
|
|
86
|
-
}
|
|
87
|
-
// @ts-ignore
|
|
88
|
-
return res;
|
|
89
|
-
};
|
|
90
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ModifyCtx } from '../../index.js';
|
|
2
|
-
import { PropDef, SchemaTypeDef } from '@based/schema/def';
|
|
3
|
-
import { ModifyOp, ModifyErr } from './types.js';
|
|
4
|
-
export declare function writeVector(value: any, ctx: ModifyCtx, schema: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|