@based/db 0.0.70 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/hll.h +1 -1
- 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/hll.h +1 -1
- 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/hll.h +1 -1
- 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 +30 -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 +18 -15
- package/dist/src/client/query/BasedDbQuery.js +93 -96
- 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 +34 -12
- package/dist/src/client/query/aggregates/types.js +30 -12
- 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 +32 -8
- 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 +31 -16
- package/dist/src/server/migrate/worker.js +2 -27
- package/dist/src/server/save.js +10 -8
- package/dist/src/server/schema.js +17 -25
- 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/dist/src/types.d.ts +1 -1
- 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 -322
- 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 -112
- package/dist/src/client/modify/references/references.d.ts +0 -16
- package/dist/src/client/modify/references/references.js +0 -308
- 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,63 +0,0 @@
|
|
|
1
|
-
import { RANGE_ERR, CREATE } from './types.js';
|
|
2
|
-
import { ModifyError } from './ModifyRes.js';
|
|
3
|
-
import { setCursor } from './setCursor.js';
|
|
4
|
-
import { xxHash64 } from '../xxHash64.js';
|
|
5
|
-
import { ENCODER } from '@saulx/utils';
|
|
6
|
-
export function writeHll(value, ctx, def, t, parentId, modifyOp) {
|
|
7
|
-
if (!value) {
|
|
8
|
-
return new ModifyError(t, value);
|
|
9
|
-
}
|
|
10
|
-
if (value === null) {
|
|
11
|
-
// Future hll_reset function
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
else if (!Array.isArray(value)) {
|
|
15
|
-
value = [value];
|
|
16
|
-
}
|
|
17
|
-
const err = addHll(value, ctx, def, t, parentId, modifyOp);
|
|
18
|
-
if (!err && modifyOp === CREATE) {
|
|
19
|
-
def.seperateSort.bufferTmp[t.prop] = 2;
|
|
20
|
-
ctx.hasSortField++;
|
|
21
|
-
}
|
|
22
|
-
return err;
|
|
23
|
-
}
|
|
24
|
-
function addHll(value, ctx, def, t, parentId, modifyOp) {
|
|
25
|
-
const len = value.length;
|
|
26
|
-
let size = 4 + len * 8;
|
|
27
|
-
if (ctx.len + size + 11 /* SIZE.DEFAULT_CURSOR */ > ctx.max) {
|
|
28
|
-
return RANGE_ERR;
|
|
29
|
-
}
|
|
30
|
-
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
31
|
-
ctx.buf[ctx.len++] = modifyOp;
|
|
32
|
-
return writeHllBuf(value, ctx, t, len);
|
|
33
|
-
}
|
|
34
|
-
export function writeHllBuf(value, ctx, t, len) {
|
|
35
|
-
let startLen = ctx.len;
|
|
36
|
-
ctx.buf[ctx.len++] = len;
|
|
37
|
-
ctx.buf[ctx.len++] = len >>> 8;
|
|
38
|
-
ctx.buf[ctx.len++] = len >>> 16;
|
|
39
|
-
ctx.buf[ctx.len++] = len >>> 24;
|
|
40
|
-
for (let val of value) {
|
|
41
|
-
if (val === undefined) {
|
|
42
|
-
// not sure if this makes sense....
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
else if (!t.validation(val, t)) {
|
|
46
|
-
ctx.len = startLen;
|
|
47
|
-
len = 0;
|
|
48
|
-
ctx.buf[ctx.len++] = len;
|
|
49
|
-
ctx.buf[ctx.len++] = len >>> 8;
|
|
50
|
-
ctx.buf[ctx.len++] = len >>> 16;
|
|
51
|
-
ctx.buf[ctx.len++] = len >>> 24;
|
|
52
|
-
return new ModifyError(t, val);
|
|
53
|
-
}
|
|
54
|
-
else if (typeof val === 'string') {
|
|
55
|
-
xxHash64(ENCODER.encode(val), ctx.buf, ctx.len);
|
|
56
|
-
}
|
|
57
|
-
else if (val instanceof Uint8Array && val.byteLength === 8) {
|
|
58
|
-
ctx.buf.set(val, ctx.len);
|
|
59
|
-
}
|
|
60
|
-
ctx.len += 8;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=cardinality.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ModifyRes } from './ModifyRes.js';
|
|
2
|
-
import { ModifyOpts } from './types.js';
|
|
3
|
-
import { DbClient } from '../index.js';
|
|
4
|
-
export type CreateObj = Record<string, any>;
|
|
5
|
-
export declare function create(db: DbClient, type: string, obj: CreateObj, opts?: ModifyOpts): ModifyRes;
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import { BINARY, MICRO_BUFFER, STRING, JSON, TEXT, ALIAS, } from '@based/schema/def';
|
|
2
|
-
import { inverseLangMap } from '@based/schema';
|
|
3
|
-
import { startDrain, flushBuffer } from '../flushModify.js';
|
|
4
|
-
import { setCursor } from './setCursor.js';
|
|
5
|
-
import { modify } from './modify.js';
|
|
6
|
-
import { ModifyState } from './ModifyRes.js';
|
|
7
|
-
import { CREATE, RANGE_ERR, ADD_EMPTY_SORT, ADD_EMPTY_SORT_TEXT, } from './types.js';
|
|
8
|
-
import { writeFixedValue } from './fixed.js';
|
|
9
|
-
import { writeBinary } from './binary.js';
|
|
10
|
-
import { writeString } from './string.js';
|
|
11
|
-
import { writeText } from './text.js';
|
|
12
|
-
import { writeJson } from './json.js';
|
|
13
|
-
import { writeAlias } from './alias.js';
|
|
14
|
-
import { getByPath } from '@saulx/utils';
|
|
15
|
-
const appendCreate = (ctx, schema, obj, res, unsafe) => {
|
|
16
|
-
const len = ctx.len;
|
|
17
|
-
let err = modify(ctx, res, obj, schema, CREATE, schema.tree, true, unsafe);
|
|
18
|
-
if (err) {
|
|
19
|
-
return err;
|
|
20
|
-
}
|
|
21
|
-
if (ctx.len === len || schema.mainLen === 0) {
|
|
22
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ > ctx.max) {
|
|
23
|
-
return RANGE_ERR;
|
|
24
|
-
}
|
|
25
|
-
setCursor(ctx, schema, 0, MICRO_BUFFER, res.tmpId, CREATE);
|
|
26
|
-
}
|
|
27
|
-
if (schema.createTs) {
|
|
28
|
-
const createTs = Date.now();
|
|
29
|
-
for (const prop of schema.createTs) {
|
|
30
|
-
if (getByPath(obj, prop.path) !== undefined) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (ctx.lastMain === -1) {
|
|
34
|
-
let mainLenU32 = schema.mainLen;
|
|
35
|
-
setCursor(ctx, schema, prop.prop, MICRO_BUFFER, res.tmpId, CREATE);
|
|
36
|
-
ctx.buf[ctx.len++] = CREATE;
|
|
37
|
-
ctx.buf[ctx.len++] = mainLenU32;
|
|
38
|
-
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
39
|
-
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
40
|
-
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
41
|
-
ctx.lastMain = ctx.len;
|
|
42
|
-
ctx.buf.set(schema.mainEmpty, ctx.len);
|
|
43
|
-
ctx.len += schema.mainLen;
|
|
44
|
-
}
|
|
45
|
-
err = writeFixedValue(ctx, createTs, prop, ctx.lastMain + prop.start, CREATE);
|
|
46
|
-
if (err) {
|
|
47
|
-
return err;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else if (ctx.lastMain === -1 && !schema.mainEmptyAllZeroes) {
|
|
52
|
-
// this is there to handle different defaults
|
|
53
|
-
if (ctx.lastMain === -1) {
|
|
54
|
-
let mainLenU32 = schema.mainLen;
|
|
55
|
-
setCursor(ctx, schema, 0, MICRO_BUFFER, res.tmpId, CREATE);
|
|
56
|
-
ctx.buf[ctx.len++] = CREATE;
|
|
57
|
-
ctx.buf[ctx.len++] = mainLenU32;
|
|
58
|
-
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
59
|
-
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
60
|
-
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
61
|
-
ctx.lastMain = ctx.len;
|
|
62
|
-
ctx.buf.set(schema.mainEmpty, ctx.len);
|
|
63
|
-
ctx.len += schema.mainLen;
|
|
64
|
-
}
|
|
65
|
-
// add text & string here
|
|
66
|
-
}
|
|
67
|
-
if (schema.hasSeperateDefaults) {
|
|
68
|
-
const buf = schema.seperateDefaults.bufferTmp;
|
|
69
|
-
// if ctx.hasDefault === -1 means it needs defaults
|
|
70
|
-
if (ctx.hasDefaults !== schema.seperateDefaults.props.size - 1) {
|
|
71
|
-
const id = res.tmpId;
|
|
72
|
-
for (const propDef of schema.seperateDefaults.props.values()) {
|
|
73
|
-
const prop = propDef.prop;
|
|
74
|
-
const type = propDef.typeIndex;
|
|
75
|
-
if (schema.seperateDefaults.bufferTmp[prop] === 0) {
|
|
76
|
-
if (type === BINARY) {
|
|
77
|
-
writeBinary(propDef.default, ctx, schema, propDef, id, CREATE);
|
|
78
|
-
}
|
|
79
|
-
else if (type === STRING) {
|
|
80
|
-
writeString(0, propDef.default, ctx, schema, propDef, id, CREATE);
|
|
81
|
-
}
|
|
82
|
-
else if (type === TEXT) {
|
|
83
|
-
writeText(propDef.default, ctx, schema, propDef, res, id, CREATE);
|
|
84
|
-
}
|
|
85
|
-
else if (type === JSON) {
|
|
86
|
-
writeJson(propDef.default, ctx, schema, propDef, id, CREATE);
|
|
87
|
-
}
|
|
88
|
-
else if (type === ALIAS) {
|
|
89
|
-
writeAlias(propDef.default, ctx, schema, propDef, id, CREATE);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else if (type === TEXT) {
|
|
93
|
-
const buf = schema.seperateTextSort.bufferTmp;
|
|
94
|
-
const amount = schema.localeSize + 1;
|
|
95
|
-
const len = amount * schema.seperateTextSort.props.length;
|
|
96
|
-
for (const { prop } of schema.seperateTextSort.props) {
|
|
97
|
-
const index = prop * amount;
|
|
98
|
-
if (buf[index] !== 0) {
|
|
99
|
-
for (let i = index + 1; i < len + index; i++) {
|
|
100
|
-
const lang = buf[i];
|
|
101
|
-
if (lang !== 0) {
|
|
102
|
-
const val = propDef.default[inverseLangMap.get(lang)];
|
|
103
|
-
if (val !== undefined) {
|
|
104
|
-
writeString(lang, val, ctx, schema, propDef, res.tmpId, CREATE);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (ctx.hasDefaults !== -1) {
|
|
114
|
-
buf.fill(0);
|
|
115
|
-
}
|
|
116
|
-
ctx.hasDefaults = -1;
|
|
117
|
-
}
|
|
118
|
-
if (schema.hasSeperateSort) {
|
|
119
|
-
// just do it here!
|
|
120
|
-
if (ctx.hasSortField !== schema.seperateSort.size - 1) {
|
|
121
|
-
if (ctx.len + 3 > ctx.max) {
|
|
122
|
-
return RANGE_ERR;
|
|
123
|
-
}
|
|
124
|
-
ctx.buf[ctx.len++] = ADD_EMPTY_SORT;
|
|
125
|
-
let sizepos = ctx.len;
|
|
126
|
-
ctx.len += 2;
|
|
127
|
-
for (const { prop } of schema.seperateSort.props) {
|
|
128
|
-
if (schema.seperateSort.bufferTmp[prop] === 0) {
|
|
129
|
-
if (ctx.len + 1 > ctx.max) {
|
|
130
|
-
return RANGE_ERR;
|
|
131
|
-
}
|
|
132
|
-
ctx.buf[ctx.len++] = prop;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
let size = ctx.len - sizepos - 2;
|
|
136
|
-
ctx.buf[sizepos++] = size;
|
|
137
|
-
ctx.buf[sizepos] = size >>>= 8;
|
|
138
|
-
}
|
|
139
|
-
if (ctx.hasSortField !== -1) {
|
|
140
|
-
schema.seperateSort.bufferTmp.set(schema.seperateSort.buffer, 0);
|
|
141
|
-
}
|
|
142
|
-
// add test for this
|
|
143
|
-
ctx.hasSortField = -1;
|
|
144
|
-
}
|
|
145
|
-
if (schema.hasSeperateTextSort) {
|
|
146
|
-
const buf = schema.seperateTextSort.bufferTmp;
|
|
147
|
-
if (ctx.hasSortText !== schema.seperateTextSort.size - 1) {
|
|
148
|
-
if (ctx.len + 3 > ctx.max) {
|
|
149
|
-
return RANGE_ERR;
|
|
150
|
-
}
|
|
151
|
-
ctx.buf[ctx.len++] = ADD_EMPTY_SORT_TEXT;
|
|
152
|
-
let sizepos = ctx.len;
|
|
153
|
-
ctx.len += 2;
|
|
154
|
-
const amount = schema.localeSize + 1;
|
|
155
|
-
const len = amount * schema.seperateTextSort.props.length;
|
|
156
|
-
for (const { prop } of schema.seperateTextSort.props) {
|
|
157
|
-
const index = prop * amount;
|
|
158
|
-
if (buf[index] !== 0) {
|
|
159
|
-
ctx.buf[ctx.len++] = prop;
|
|
160
|
-
ctx.buf[ctx.len++] = buf[index];
|
|
161
|
-
for (let i = index + 1; i < len + index; i++) {
|
|
162
|
-
const lang = buf[i];
|
|
163
|
-
if (lang !== 0) {
|
|
164
|
-
ctx.buf[ctx.len++] = lang;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
let size = ctx.len - sizepos - 2;
|
|
170
|
-
ctx.buf[sizepos++] = size;
|
|
171
|
-
ctx.buf[sizepos] = size >>>= 8;
|
|
172
|
-
// [size][size] [prop][len][lang][lang]
|
|
173
|
-
}
|
|
174
|
-
if (ctx.hasSortText !== -1) {
|
|
175
|
-
buf.set(schema.seperateTextSort.buffer, 0);
|
|
176
|
-
}
|
|
177
|
-
ctx.hasSortText = -1;
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
export function create(db, type, obj, opts) {
|
|
181
|
-
const def = db.schemaTypesParsed[type];
|
|
182
|
-
if (!def) {
|
|
183
|
-
throw new Error(
|
|
184
|
-
// fix this with promise
|
|
185
|
-
`Unknown type: ${type}. Did you mean on of: ${Object.keys(db.schemaTypesParsed).join(', ')}`);
|
|
186
|
-
}
|
|
187
|
-
let id;
|
|
188
|
-
if ('id' in obj) {
|
|
189
|
-
if (opts?.unsafe) {
|
|
190
|
-
id = obj.id;
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
// fix this with promise
|
|
194
|
-
throw Error('create with "id" is not allowed');
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
id = def.lastId + 1;
|
|
199
|
-
}
|
|
200
|
-
const ctx = db.modifyCtx;
|
|
201
|
-
const res = new ModifyState(def.id, id, db, opts);
|
|
202
|
-
const pos = ctx.len;
|
|
203
|
-
const err = appendCreate(ctx, def, obj, res, opts?.unsafe);
|
|
204
|
-
if (err) {
|
|
205
|
-
ctx.prefix0 = -1; // Force a new cursor
|
|
206
|
-
ctx.len = pos;
|
|
207
|
-
if (err === RANGE_ERR) {
|
|
208
|
-
if (pos === 8) {
|
|
209
|
-
throw new Error('!No range available');
|
|
210
|
-
}
|
|
211
|
-
void flushBuffer(db);
|
|
212
|
-
return db.create(type, obj, opts);
|
|
213
|
-
}
|
|
214
|
-
res.error = err;
|
|
215
|
-
throw err;
|
|
216
|
-
}
|
|
217
|
-
ctx.markTypeDirty(def);
|
|
218
|
-
ctx.markNodeDirty(def, id);
|
|
219
|
-
if (!db.isDraining) {
|
|
220
|
-
startDrain(db);
|
|
221
|
-
}
|
|
222
|
-
if (id > def.lastId) {
|
|
223
|
-
def.lastId = id;
|
|
224
|
-
}
|
|
225
|
-
// @ts-ignore
|
|
226
|
-
return res;
|
|
227
|
-
}
|
|
228
|
-
//# sourceMappingURL=create.js.map
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { flushBuffer, startDrain } from '../flushModify.js';
|
|
2
|
-
import { ModifyState } from './ModifyRes.js';
|
|
3
|
-
import { setCursor } from './setCursor.js';
|
|
4
|
-
import { UPDATE, DELETE_SORT_INDEX, DELETE_NODE, } from './types.js';
|
|
5
|
-
import { MICRO_BUFFER } from '@based/schema/def';
|
|
6
|
-
export const deleteFn = (db, type, id, opts) => {
|
|
7
|
-
const def = db.schemaTypesParsed[type];
|
|
8
|
-
if (!def) {
|
|
9
|
-
throw new Error(`Unknown type: ${type}. Did you mean on of: ${Object.keys(db.schemaTypesParsed).join(', ')}`);
|
|
10
|
-
}
|
|
11
|
-
if (def.insertOnly) {
|
|
12
|
-
throw new Error(`This type is insertOnly`);
|
|
13
|
-
}
|
|
14
|
-
const ctx = db.modifyCtx;
|
|
15
|
-
const res = new ModifyState(def.id, id, db, opts);
|
|
16
|
-
const schema = db.schemaTypesParsed[type];
|
|
17
|
-
const separate = schema.separate;
|
|
18
|
-
if (separate) {
|
|
19
|
-
const size = 11 /* SIZE.DEFAULT_CURSOR */ + 2 + separate.length * 12;
|
|
20
|
-
if (ctx.len + size > ctx.max) {
|
|
21
|
-
void flushBuffer(db);
|
|
22
|
-
return deleteFn(db, type, id);
|
|
23
|
-
}
|
|
24
|
-
setCursor(ctx, schema, 0, MICRO_BUFFER, id, UPDATE);
|
|
25
|
-
ctx.buf[ctx.len++] = DELETE_SORT_INDEX;
|
|
26
|
-
for (const s of separate) {
|
|
27
|
-
setCursor(ctx, schema, s.prop, s.typeIndex, id, UPDATE);
|
|
28
|
-
ctx.buf[ctx.len++] = DELETE_SORT_INDEX;
|
|
29
|
-
}
|
|
30
|
-
ctx.buf[ctx.len++] = DELETE_NODE;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 2 > ctx.max) {
|
|
34
|
-
void flushBuffer(db);
|
|
35
|
-
return deleteFn(db, type, id);
|
|
36
|
-
}
|
|
37
|
-
setCursor(ctx, schema, 0, MICRO_BUFFER, id, UPDATE);
|
|
38
|
-
ctx.buf[ctx.len++] = DELETE_SORT_INDEX;
|
|
39
|
-
ctx.buf[ctx.len++] = DELETE_NODE;
|
|
40
|
-
}
|
|
41
|
-
if (!db.isDraining) {
|
|
42
|
-
startDrain(db);
|
|
43
|
-
}
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
return res;
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=delete.js.map
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { MICRO_BUFFER } from '@based/schema/def';
|
|
2
|
-
import { startDrain, flushBuffer } from '../flushModify.js';
|
|
3
|
-
import { setCursor } from './setCursor.js';
|
|
4
|
-
import { EXPIRE } from './types.js';
|
|
5
|
-
export function expire(db, type, id, seconds) {
|
|
6
|
-
const def = db.schemaTypesParsed[type];
|
|
7
|
-
if (!def) {
|
|
8
|
-
throw new Error(`Unknown type: ${type}. Did you mean on of: ${Object.keys(db.schemaTypesParsed).join(', ')}`);
|
|
9
|
-
}
|
|
10
|
-
const ctx = db.modifyCtx;
|
|
11
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 > ctx.max) {
|
|
12
|
-
void flushBuffer(db);
|
|
13
|
-
return expire(db, type, id, seconds);
|
|
14
|
-
}
|
|
15
|
-
setCursor(ctx, def, 0, MICRO_BUFFER, id, EXPIRE);
|
|
16
|
-
ctx.buf[ctx.len++] = EXPIRE;
|
|
17
|
-
ctx.buf[ctx.len++] = seconds;
|
|
18
|
-
ctx.buf[ctx.len++] = seconds >>>= 8;
|
|
19
|
-
ctx.buf[ctx.len++] = seconds >>>= 8;
|
|
20
|
-
ctx.buf[ctx.len++] = seconds >>>= 8;
|
|
21
|
-
if (!db.isDraining) {
|
|
22
|
-
startDrain(db);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=expire.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ModifyCtx } from '../../index.js';
|
|
2
|
-
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
3
|
-
import { ModifyErr, ModifyOp } from './types.js';
|
|
4
|
-
export declare const writeFixedValue: (ctx: ModifyCtx, value: any, def: PropDef | PropDefEdge, pos: number, mod: ModifyOp) => ModifyErr;
|
|
5
|
-
export declare const appendFixedValue: (ctx: ModifyCtx, val: any, def: PropDef | PropDefEdge, mod: ModifyOp) => ModifyErr;
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { ENCODER } from '../../index.js';
|
|
2
|
-
import { BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, UINT16, UINT32, UINT8, } from '@based/schema/def';
|
|
3
|
-
import { convertToTimestamp } from '@saulx/utils';
|
|
4
|
-
import { getBuffer } from './binary.js';
|
|
5
|
-
import { ModifyError } from './ModifyRes.js';
|
|
6
|
-
import { MOD_OPS_TO_STRING, RANGE_ERR } from './types.js';
|
|
7
|
-
const map = {};
|
|
8
|
-
map[BINARY] = (ctx, val, def, mod) => {
|
|
9
|
-
const buf = getBuffer(val);
|
|
10
|
-
if (buf === undefined) {
|
|
11
|
-
return new ModifyError(def, val);
|
|
12
|
-
}
|
|
13
|
-
if (!def.validation(val, def)) {
|
|
14
|
-
return new ModifyError(def, val);
|
|
15
|
-
}
|
|
16
|
-
if (def.transform) {
|
|
17
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
18
|
-
}
|
|
19
|
-
const size = buf.byteLength;
|
|
20
|
-
if (ctx.len + size + 1 > ctx.max) {
|
|
21
|
-
return RANGE_ERR;
|
|
22
|
-
}
|
|
23
|
-
ctx.buf[ctx.len++] = size;
|
|
24
|
-
ctx.buf.set(buf, ctx.len);
|
|
25
|
-
ctx.len += buf.byteLength;
|
|
26
|
-
};
|
|
27
|
-
map[STRING] = (ctx, val, def, mod) => {
|
|
28
|
-
const valBuf = ENCODER.encode(val);
|
|
29
|
-
const size = valBuf.byteLength;
|
|
30
|
-
if (size + 1 > def.len) {
|
|
31
|
-
return new ModifyError(def, val, `max length of ${def.len - 1},`);
|
|
32
|
-
}
|
|
33
|
-
if (!def.validation(val, def)) {
|
|
34
|
-
return new ModifyError(def, val);
|
|
35
|
-
}
|
|
36
|
-
if (def.transform) {
|
|
37
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
38
|
-
}
|
|
39
|
-
if (ctx.len + size + 1 > ctx.max) {
|
|
40
|
-
return RANGE_ERR;
|
|
41
|
-
}
|
|
42
|
-
ctx.buf[ctx.len++] = size;
|
|
43
|
-
ctx.buf.set(valBuf, ctx.len);
|
|
44
|
-
const fullSize = def.len - 1;
|
|
45
|
-
ctx.len += fullSize;
|
|
46
|
-
if (fullSize !== size) {
|
|
47
|
-
ctx.buf.fill(0, ctx.len - (fullSize - size), ctx.len);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
map[BOOLEAN] = (ctx, val, def, mod) => {
|
|
51
|
-
if (ctx.len + 1 > ctx.max) {
|
|
52
|
-
return RANGE_ERR;
|
|
53
|
-
}
|
|
54
|
-
if (val === null) {
|
|
55
|
-
val = def.default;
|
|
56
|
-
}
|
|
57
|
-
if (!def.validation(val, def)) {
|
|
58
|
-
return new ModifyError(def, val);
|
|
59
|
-
}
|
|
60
|
-
if (def.transform) {
|
|
61
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
62
|
-
}
|
|
63
|
-
if (typeof val === 'boolean') {
|
|
64
|
-
ctx.buf[ctx.len++] = val ? 1 : 0;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return new ModifyError(def, val);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
map[ENUM] = (ctx, val, def, mod) => {
|
|
71
|
-
if (ctx.len + 1 > ctx.max) {
|
|
72
|
-
return RANGE_ERR;
|
|
73
|
-
}
|
|
74
|
-
if (!def.validation(val, def)) {
|
|
75
|
-
return new ModifyError(def, val);
|
|
76
|
-
}
|
|
77
|
-
if (def.transform) {
|
|
78
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
79
|
-
}
|
|
80
|
-
if (val === null) {
|
|
81
|
-
ctx.buf[ctx.len++] = 0;
|
|
82
|
-
}
|
|
83
|
-
else if (val in def.reverseEnum) {
|
|
84
|
-
ctx.buf[ctx.len++] = def.reverseEnum[val] + 1;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
return new ModifyError(def, val);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
map[NUMBER] = (ctx, val, def, mod) => {
|
|
91
|
-
if (ctx.len + 8 > ctx.max) {
|
|
92
|
-
return RANGE_ERR;
|
|
93
|
-
}
|
|
94
|
-
if (val === null) {
|
|
95
|
-
val = def.default;
|
|
96
|
-
}
|
|
97
|
-
if (!def.validation(val, def)) {
|
|
98
|
-
return new ModifyError(def, val);
|
|
99
|
-
}
|
|
100
|
-
if (def.transform) {
|
|
101
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
102
|
-
}
|
|
103
|
-
const view = new DataView(ctx.buf.buffer, ctx.buf.byteOffset + ctx.len, 8);
|
|
104
|
-
ctx.len += 8;
|
|
105
|
-
view.setFloat64(0, val, true);
|
|
106
|
-
};
|
|
107
|
-
map[TIMESTAMP] = (ctx, val, def, mod) => {
|
|
108
|
-
const parsedValue = convertToTimestamp(val);
|
|
109
|
-
if (ctx.len + 8 > ctx.max) {
|
|
110
|
-
return RANGE_ERR;
|
|
111
|
-
}
|
|
112
|
-
if (val === null) {
|
|
113
|
-
val = def.default;
|
|
114
|
-
}
|
|
115
|
-
if (!def.validation(parsedValue, def)) {
|
|
116
|
-
return new ModifyError(def, val);
|
|
117
|
-
}
|
|
118
|
-
if (def.transform) {
|
|
119
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
120
|
-
}
|
|
121
|
-
const view = new DataView(ctx.buf.buffer, ctx.buf.byteOffset + ctx.len, 8);
|
|
122
|
-
ctx.len += 8;
|
|
123
|
-
// Todo use new utils and store as uint64
|
|
124
|
-
view.setFloat64(0, parsedValue, true);
|
|
125
|
-
// const ts = view.getFloat64(0)
|
|
126
|
-
};
|
|
127
|
-
map[UINT32] = (ctx, val, def, mod) => {
|
|
128
|
-
if (ctx.len + 4 > ctx.max) {
|
|
129
|
-
return RANGE_ERR;
|
|
130
|
-
}
|
|
131
|
-
if (val === null) {
|
|
132
|
-
val = def.default;
|
|
133
|
-
}
|
|
134
|
-
if (!def.validation(val, def)) {
|
|
135
|
-
return new ModifyError(def, val);
|
|
136
|
-
}
|
|
137
|
-
if (def.transform) {
|
|
138
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
139
|
-
}
|
|
140
|
-
ctx.buf[ctx.len++] = val;
|
|
141
|
-
ctx.buf[ctx.len++] = val >>>= 8;
|
|
142
|
-
ctx.buf[ctx.len++] = val >>>= 8;
|
|
143
|
-
ctx.buf[ctx.len++] = val >>>= 8;
|
|
144
|
-
};
|
|
145
|
-
map[UINT16] = (ctx, val, def, mod) => {
|
|
146
|
-
if (ctx.len + 2 > ctx.max) {
|
|
147
|
-
return RANGE_ERR;
|
|
148
|
-
}
|
|
149
|
-
if (val === null) {
|
|
150
|
-
val = def.default;
|
|
151
|
-
}
|
|
152
|
-
if (!def.validation(val, def)) {
|
|
153
|
-
return new ModifyError(def, val);
|
|
154
|
-
}
|
|
155
|
-
if (def.transform) {
|
|
156
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
157
|
-
}
|
|
158
|
-
ctx.buf[ctx.len++] = val;
|
|
159
|
-
ctx.buf[ctx.len++] = val >>>= 8;
|
|
160
|
-
};
|
|
161
|
-
map[UINT8] = (ctx, val, def, mod) => {
|
|
162
|
-
if (ctx.len + 1 > ctx.max) {
|
|
163
|
-
return RANGE_ERR;
|
|
164
|
-
}
|
|
165
|
-
if (val === null) {
|
|
166
|
-
val = def.default;
|
|
167
|
-
}
|
|
168
|
-
if (!def.validation(val, def)) {
|
|
169
|
-
return new ModifyError(def, val);
|
|
170
|
-
}
|
|
171
|
-
if (def.transform) {
|
|
172
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
173
|
-
}
|
|
174
|
-
ctx.buf[ctx.len++] = val;
|
|
175
|
-
};
|
|
176
|
-
map[INT32] = (ctx, val, def, mod) => {
|
|
177
|
-
if (ctx.len + 4 > ctx.max) {
|
|
178
|
-
return RANGE_ERR;
|
|
179
|
-
}
|
|
180
|
-
if (val === null) {
|
|
181
|
-
val = def.default;
|
|
182
|
-
}
|
|
183
|
-
if (!def.validation(val, def)) {
|
|
184
|
-
return new ModifyError(def, val);
|
|
185
|
-
}
|
|
186
|
-
if (def.transform) {
|
|
187
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
188
|
-
}
|
|
189
|
-
ctx.buf[ctx.len++] = val;
|
|
190
|
-
ctx.buf[ctx.len++] = val >>>= 8;
|
|
191
|
-
ctx.buf[ctx.len++] = val >>>= 8;
|
|
192
|
-
ctx.buf[ctx.len++] = val >>>= 8;
|
|
193
|
-
};
|
|
194
|
-
map[INT16] = (ctx, val, def, mod) => {
|
|
195
|
-
if (ctx.len + 2 > ctx.max) {
|
|
196
|
-
return RANGE_ERR;
|
|
197
|
-
}
|
|
198
|
-
if (val === null) {
|
|
199
|
-
val = def.default;
|
|
200
|
-
}
|
|
201
|
-
if (!def.validation(val, def)) {
|
|
202
|
-
return new ModifyError(def, val);
|
|
203
|
-
}
|
|
204
|
-
if (def.transform) {
|
|
205
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
206
|
-
}
|
|
207
|
-
ctx.buf[ctx.len++] = val;
|
|
208
|
-
ctx.buf[ctx.len++] = val >>>= 8;
|
|
209
|
-
};
|
|
210
|
-
map[INT8] = (ctx, val, def, mod) => {
|
|
211
|
-
if (ctx.len + 1 > ctx.max) {
|
|
212
|
-
return RANGE_ERR;
|
|
213
|
-
}
|
|
214
|
-
if (val === null) {
|
|
215
|
-
val = def.default;
|
|
216
|
-
}
|
|
217
|
-
if (!def.validation(val, def)) {
|
|
218
|
-
return new ModifyError(def, val);
|
|
219
|
-
}
|
|
220
|
-
if (def.transform) {
|
|
221
|
-
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
222
|
-
}
|
|
223
|
-
ctx.buf[ctx.len++] = val;
|
|
224
|
-
};
|
|
225
|
-
export const writeFixedValue = (ctx, value, def, pos, mod) => {
|
|
226
|
-
const len = ctx.len;
|
|
227
|
-
ctx.len = pos;
|
|
228
|
-
const res = map[def.typeIndex](ctx, value, def, mod);
|
|
229
|
-
ctx.len = len;
|
|
230
|
-
return res;
|
|
231
|
-
};
|
|
232
|
-
export const appendFixedValue = (ctx, val, def, mod) => {
|
|
233
|
-
return map[def.typeIndex](ctx, val, def, mod);
|
|
234
|
-
};
|
|
235
|
-
//# sourceMappingURL=fixed.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 writeJson(value: any, ctx: ModifyCtx, schema: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { CREATE } from './types.js';
|
|
2
|
-
import { writeBinary } from './binary.js';
|
|
3
|
-
import { ModifyError } from './ModifyRes.js';
|
|
4
|
-
export function writeJson(value, ctx, schema, t, parentId, modifyOp) {
|
|
5
|
-
try {
|
|
6
|
-
if (value === null) {
|
|
7
|
-
return writeBinary(null, ctx, schema, t, parentId, modifyOp);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
if (!t.validation(value, t)) {
|
|
11
|
-
return new ModifyError(t, value);
|
|
12
|
-
}
|
|
13
|
-
if (modifyOp === CREATE) {
|
|
14
|
-
if (schema.hasSeperateDefaults) {
|
|
15
|
-
schema.seperateDefaults.bufferTmp[t.prop] = 1;
|
|
16
|
-
ctx.hasDefaults++;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return writeBinary(JSON.stringify(value), ctx, schema, t, parentId, modifyOp);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
return new ModifyError(t, value);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=json.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ModifyCtx } from '../../index.js';
|
|
2
|
-
import { SchemaTypeDef } from '@based/schema/def';
|
|
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;
|