@based/db 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +425 -8
- package/dist/lib/darwin_aarch64/include/selva/db.h +12 -3
- package/dist/lib/darwin_aarch64/include/selva/fields.h +22 -11
- package/dist/lib/darwin_aarch64/include/selva/history.h +49 -0
- package/dist/lib/darwin_aarch64/include/selva/hll.h +21 -0
- package/dist/lib/darwin_aarch64/include/selva/sort.h +14 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +9 -2
- package/dist/lib/darwin_aarch64/include/selva/vector.h +22 -1
- package/dist/lib/darwin_aarch64/include/selva/xxhash64.h +23 -0
- package/dist/lib/darwin_aarch64/libnode-v20.11.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.8.0.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +12 -3
- package/dist/lib/linux_aarch64/include/selva/fields.h +22 -11
- package/dist/lib/linux_aarch64/include/selva/history.h +49 -0
- package/dist/lib/linux_aarch64/include/selva/hll.h +21 -0
- package/dist/lib/linux_aarch64/include/selva/sort.h +14 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +9 -2
- package/dist/lib/linux_aarch64/include/selva/vector.h +22 -1
- package/dist/lib/linux_aarch64/include/selva/xxhash64.h +23 -0
- package/dist/lib/linux_aarch64/libnode-v20.11.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +12 -3
- package/dist/lib/linux_x86_64/include/selva/fields.h +22 -11
- package/dist/lib/linux_x86_64/include/selva/history.h +49 -0
- package/dist/lib/linux_x86_64/include/selva/hll.h +21 -0
- package/dist/lib/linux_x86_64/include/selva/sort.h +14 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +9 -2
- package/dist/lib/linux_x86_64/include/selva/vector.h +22 -1
- package/dist/lib/linux_x86_64/include/selva/xxhash64.h +23 -0
- package/dist/lib/linux_x86_64/libnode-v20.11.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/bitWise.js +21 -1
- package/dist/src/client/index.d.ts +11 -5
- package/dist/src/client/index.js +57 -11
- package/dist/src/client/modify/ModifyRes.d.ts +4 -1
- package/dist/src/client/modify/ModifyRes.js +8 -1
- package/dist/src/client/modify/alias.js +3 -3
- package/dist/src/client/modify/binary.js +5 -2
- package/dist/src/client/modify/cardinality.d.ts +4 -0
- package/dist/src/client/modify/cardinality.js +50 -0
- package/dist/src/client/modify/create copy.d.ts +5 -0
- package/dist/src/client/modify/create copy.js +112 -0
- package/dist/src/client/modify/create.d.ts +2 -1
- package/dist/src/client/modify/create.js +11 -7
- package/dist/src/client/modify/delete.d.ts +2 -0
- package/dist/src/client/modify/delete.js +37 -0
- package/dist/src/client/modify/expire.d.ts +3 -0
- package/dist/src/client/modify/expire.js +25 -0
- package/dist/src/client/modify/fixed.js +11 -1
- package/dist/src/client/modify/index.d.ts +1 -1
- package/dist/src/client/modify/index.js +1 -1
- package/dist/src/client/modify/json.d.ts +4 -0
- package/dist/src/client/modify/json.js +5 -0
- package/dist/src/client/modify/modify.js +11 -7
- package/dist/src/client/modify/references/edge.js +21 -6
- package/dist/src/client/modify/references/reference.js +2 -2
- package/dist/src/client/modify/references/references.d.ts +0 -1
- package/dist/src/client/modify/references/references.js +4 -4
- package/dist/src/client/modify/remove.d.ts +1 -2
- package/dist/src/client/modify/remove.js +9 -6
- package/dist/src/client/modify/setCursor.d.ts +1 -1
- package/dist/src/client/modify/setCursor.js +4 -1
- package/dist/src/client/modify/string.js +2 -2
- package/dist/src/client/modify/text.d.ts +2 -1
- package/dist/src/client/modify/text.js +13 -7
- package/dist/src/client/modify/types.d.ts +8 -1
- package/dist/src/client/modify/types.js +1 -0
- package/dist/src/client/modify/update.d.ts +2 -1
- package/dist/src/client/modify/update.js +9 -5
- package/dist/src/client/modify/upsert.d.ts +2 -1
- package/dist/src/client/modify/upsert.js +3 -3
- package/dist/src/client/modify/vector copy.d.ts +4 -0
- package/dist/src/client/modify/vector copy.js +46 -0
- package/dist/src/client/modify/vector.js +6 -4
- package/dist/src/client/query/BasedDbQuery.d.ts +4 -3
- package/dist/src/client/query/BasedDbQuery.js +39 -16
- package/dist/src/client/query/BasedIterable.js +3 -3
- package/dist/src/client/query/filter/FilterBranch.d.ts +2 -2
- package/dist/src/client/query/filter/FilterBranch.js +2 -2
- package/dist/src/client/query/filter/createFixedFilterBuffer.d.ts +3 -2
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +14 -11
- package/dist/src/client/query/filter/createReferenceFilter.d.ts +2 -1
- package/dist/src/client/query/filter/createReferenceFilter.js +6 -5
- package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +61 -30
- package/dist/src/client/query/filter/filter.d.ts +2 -2
- package/dist/src/client/query/filter/filter.js +23 -21
- package/dist/src/client/query/filter/parseFilterValue.js +9 -64
- package/dist/src/client/query/filter/primitiveFilter.js +7 -11
- package/dist/src/client/query/filter/toBuffer.js +5 -7
- package/dist/src/client/query/filter/types.d.ts +51 -2
- package/dist/src/client/query/filter/types.js +114 -0
- package/dist/src/client/query/include/props.d.ts +2 -0
- package/dist/src/client/query/include/props.js +25 -6
- package/dist/src/client/query/include/toBuffer.js +21 -1
- package/dist/src/client/query/include/walk.js +17 -2
- package/dist/src/client/query/queryDef.js +1 -0
- package/dist/src/client/query/read/read.js +85 -21
- package/dist/src/client/query/search/index.d.ts +2 -0
- package/dist/src/client/query/search/index.js +79 -23
- package/dist/src/client/query/subscription/index.js +2 -2
- package/dist/src/client/query/subscription/markers.d.ts +1 -1
- package/dist/src/client/query/subscription/markers.js +2 -2
- package/dist/src/client/query/toBuffer.js +0 -4
- package/dist/src/client/query/types.d.ts +10 -0
- package/dist/src/client/query/validation.d.ts +3 -2
- package/dist/src/client/query/validation.js +17 -2
- package/dist/src/client/timestamp.d.ts +1 -0
- package/dist/src/client/timestamp.js +68 -0
- package/dist/src/client/xxHash64.d.ts +1 -0
- package/dist/src/client/xxHash64.js +5 -0
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.js +13 -3
- package/dist/src/native.d.ts +1 -0
- package/dist/src/native.js +4 -1
- package/dist/src/server/csmt/tree.js +12 -2
- package/dist/src/server/index.d.ts +12 -4
- package/dist/src/server/index.js +63 -17
- package/dist/src/server/migrate/worker.js +3 -3
- package/dist/src/server/schema/selvaBuffer.js +20 -11
- package/dist/src/server/schema/typeDef.d.ts +2 -2
- package/dist/src/server/schema/typeDef.js +14 -5
- package/dist/src/server/schema/types.d.ts +7 -2
- package/dist/src/server/schema/types.js +6 -3
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, UINT16, UINT32, UINT8, } from '../../server/schema/types.js';
|
|
2
|
+
import { convertToTimestamp } from '../timestamp.js';
|
|
2
3
|
import { getBuffer } from './binary.js';
|
|
3
4
|
import { ModifyError } from './ModifyRes.js';
|
|
4
5
|
import { RANGE_ERR } from './types.js';
|
|
@@ -70,6 +71,16 @@ map[NUMBER] = (ctx, val, def) => {
|
|
|
70
71
|
}
|
|
71
72
|
ctx.len = ctx.buf.writeDoubleLE(val, ctx.len);
|
|
72
73
|
};
|
|
74
|
+
map[TIMESTAMP] = (ctx, val, def) => {
|
|
75
|
+
const parsedValue = convertToTimestamp(val);
|
|
76
|
+
if (typeof parsedValue !== 'number') {
|
|
77
|
+
return new ModifyError(def, val);
|
|
78
|
+
}
|
|
79
|
+
if (ctx.len + 8 > ctx.max) {
|
|
80
|
+
return RANGE_ERR;
|
|
81
|
+
}
|
|
82
|
+
ctx.len = ctx.buf.writeDoubleLE(parsedValue, ctx.len);
|
|
83
|
+
};
|
|
73
84
|
map[UINT32] = (ctx, val, def) => {
|
|
74
85
|
if (typeof val !== 'number') {
|
|
75
86
|
return new ModifyError(def, val);
|
|
@@ -101,7 +112,6 @@ map[UINT8] = (ctx, val, def) => {
|
|
|
101
112
|
}
|
|
102
113
|
ctx.buf[ctx.len++] = val;
|
|
103
114
|
};
|
|
104
|
-
map[TIMESTAMP] = map[NUMBER];
|
|
105
115
|
map[INT32] = map[UINT32];
|
|
106
116
|
map[INT16] = map[UINT16];
|
|
107
117
|
map[INT8] = map[UINT8];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModifyCtx } from '../../index.js';
|
|
2
|
+
import { PropDef, SchemaTypeDef } from '../../server/schema/types.js';
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { isPropDef, REFERENCE, REFERENCES, STRING, TEXT, ALIAS, BINARY,
|
|
1
|
+
import { isPropDef, REFERENCE, REFERENCES, STRING, TEXT, ALIAS, BINARY, CARDINALITY, VECTOR, MICRO_BUFFER, JSON, } from '../../server/schema/types.js';
|
|
2
2
|
import { ModifyError } from './ModifyRes.js';
|
|
3
3
|
import { writeReference } from './references/reference.js';
|
|
4
4
|
import { writeReferences } from './references/references.js';
|
|
@@ -9,9 +9,10 @@ import { writeBinary } from './binary.js';
|
|
|
9
9
|
import { setCursor } from './setCursor.js';
|
|
10
10
|
import { appendFixedValue, writeFixedValue } from './fixed.js';
|
|
11
11
|
import { writeAlias } from './alias.js';
|
|
12
|
-
import { writeHll } from './
|
|
12
|
+
import { writeHll } from './cardinality.js';
|
|
13
13
|
import { writeVector } from './vector.js';
|
|
14
14
|
import { checkSubscriptionMarkers } from '../query/subscription/index.js';
|
|
15
|
+
import { writeJson } from './json.js';
|
|
15
16
|
function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
16
17
|
for (const key in obj) {
|
|
17
18
|
const def = tree[key];
|
|
@@ -33,7 +34,7 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
33
34
|
err = writeString(0, val, ctx, schema, def, res.tmpId, mod);
|
|
34
35
|
}
|
|
35
36
|
else if (type === TEXT) {
|
|
36
|
-
err = writeText(val, ctx, schema, def, res
|
|
37
|
+
err = writeText(val, ctx, schema, def, res, mod);
|
|
37
38
|
}
|
|
38
39
|
else if (type === REFERENCE) {
|
|
39
40
|
err = writeReference(val, ctx, schema, def, res, mod);
|
|
@@ -47,21 +48,24 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
47
48
|
else if (type === ALIAS) {
|
|
48
49
|
err = writeAlias(val, ctx, schema, def, res.tmpId, mod);
|
|
49
50
|
}
|
|
50
|
-
else if (type ===
|
|
51
|
+
else if (type === CARDINALITY) {
|
|
51
52
|
err = writeHll(val, ctx, schema, def, res.tmpId, mod);
|
|
52
53
|
}
|
|
53
54
|
else if (type === VECTOR) {
|
|
54
55
|
err = writeVector(val, ctx, schema, def, res.tmpId, mod);
|
|
55
56
|
}
|
|
57
|
+
else if (type === JSON) {
|
|
58
|
+
err = writeJson(val, ctx, schema, def, res.tmpId, mod);
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
else if (overwrite) {
|
|
58
62
|
if (ctx.len + 15 + schema.mainLen > ctx.max) {
|
|
59
63
|
return RANGE_ERR;
|
|
60
64
|
}
|
|
61
|
-
setCursor(ctx, schema, def.prop, res.tmpId, mod, true);
|
|
65
|
+
setCursor(ctx, schema, def.prop, MICRO_BUFFER, res.tmpId, mod, true);
|
|
62
66
|
if (ctx.lastMain === -1) {
|
|
63
67
|
let mainLenU32 = schema.mainLen;
|
|
64
|
-
setCursor(ctx, schema, def.prop, res.tmpId, mod);
|
|
68
|
+
setCursor(ctx, schema, def.prop, MICRO_BUFFER, res.tmpId, mod);
|
|
65
69
|
ctx.buf[ctx.len++] = mod;
|
|
66
70
|
ctx.buf[ctx.len++] = mainLenU32;
|
|
67
71
|
ctx.buf[ctx.len++] = mainLenU32 >>>= 8;
|
|
@@ -86,7 +90,7 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
86
90
|
if (ctx.len + 10 > ctx.max) {
|
|
87
91
|
return RANGE_ERR;
|
|
88
92
|
}
|
|
89
|
-
setCursor(ctx, schema, def.prop, res.tmpId, mod);
|
|
93
|
+
setCursor(ctx, schema, def.prop, MICRO_BUFFER, res.tmpId, mod);
|
|
90
94
|
let start = def.start;
|
|
91
95
|
if (increment < 0) {
|
|
92
96
|
ctx.buf[ctx.len++] = DECREMENT;
|
|
@@ -2,7 +2,7 @@ import { BINARY, REFERENCE, REFERENCES, STRING, } from '../../../server/schema/t
|
|
|
2
2
|
import { write } from '../../string.js';
|
|
3
3
|
import { getBuffer, writeBinaryRaw } from '../binary.js';
|
|
4
4
|
import { ModifyError, ModifyState } from '../ModifyRes.js';
|
|
5
|
-
import { RANGE_ERR } from '../types.js';
|
|
5
|
+
import { DECREMENT, INCREMENT, RANGE_ERR } from '../types.js';
|
|
6
6
|
import { appendFixedValue } from '../fixed.js';
|
|
7
7
|
export function getEdgeSize(t, ref) {
|
|
8
8
|
let size = 0;
|
|
@@ -67,7 +67,7 @@ export function writeEdges(t, ref, ctx) {
|
|
|
67
67
|
else {
|
|
68
68
|
const buf = getBuffer(value);
|
|
69
69
|
if (!buf) {
|
|
70
|
-
return new ModifyError(
|
|
70
|
+
return new ModifyError(edge, value);
|
|
71
71
|
}
|
|
72
72
|
size = buf.byteLength;
|
|
73
73
|
}
|
|
@@ -88,7 +88,7 @@ export function writeEdges(t, ref, ctx) {
|
|
|
88
88
|
}
|
|
89
89
|
else if (edge.typeIndex === STRING) {
|
|
90
90
|
if (typeof value !== 'string') {
|
|
91
|
-
return new ModifyError(
|
|
91
|
+
return new ModifyError(edge, value);
|
|
92
92
|
}
|
|
93
93
|
if (ctx.len + 6 + Buffer.byteLength(value) > ctx.max) {
|
|
94
94
|
return RANGE_ERR;
|
|
@@ -109,7 +109,7 @@ export function writeEdges(t, ref, ctx) {
|
|
|
109
109
|
value = value.tmpId;
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
|
-
return new ModifyError(
|
|
112
|
+
return new ModifyError(edge, value);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
if (value > 0) {
|
|
@@ -121,12 +121,12 @@ export function writeEdges(t, ref, ctx) {
|
|
|
121
121
|
ctx.buf[ctx.len++] = value >>>= 8;
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
124
|
-
return new ModifyError(
|
|
124
|
+
return new ModifyError(edge, value);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
else if (edge.typeIndex === REFERENCES) {
|
|
128
128
|
if (!Array.isArray(value)) {
|
|
129
|
-
return new ModifyError(
|
|
129
|
+
return new ModifyError(edge, value);
|
|
130
130
|
}
|
|
131
131
|
let size = value.length * 4;
|
|
132
132
|
if (ctx.len + 6 + size > ctx.max) {
|
|
@@ -145,6 +145,21 @@ export function writeEdges(t, ref, ctx) {
|
|
|
145
145
|
if (ctx.len + 2 > ctx.max) {
|
|
146
146
|
return RANGE_ERR;
|
|
147
147
|
}
|
|
148
|
+
if (typeof value === 'object' && value !== null) {
|
|
149
|
+
if (value.increment > 0) {
|
|
150
|
+
ctx.buf[ctx.len++] = 0;
|
|
151
|
+
ctx.buf[ctx.len++] = INCREMENT;
|
|
152
|
+
value = value.increment;
|
|
153
|
+
}
|
|
154
|
+
else if (value.increment < 0) {
|
|
155
|
+
ctx.buf[ctx.len++] = 0;
|
|
156
|
+
ctx.buf[ctx.len++] = DECREMENT;
|
|
157
|
+
value = -value.increment;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return new ModifyError(edge, value);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
148
163
|
ctx.buf[ctx.len++] = edge.prop;
|
|
149
164
|
ctx.buf[ctx.len++] = edge.typeIndex;
|
|
150
165
|
const err = appendFixedValue(ctx, value, edge);
|
|
@@ -8,7 +8,7 @@ function writeRef(id, ctx, schema, def, parentId, modifyOp, hasEdges) {
|
|
|
8
8
|
return RANGE_ERR;
|
|
9
9
|
}
|
|
10
10
|
ctx.markNodeDirty(ctx.db.schemaTypesParsed[def.inverseTypeName], id);
|
|
11
|
-
setCursor(ctx, schema, def.prop, parentId, modifyOp);
|
|
11
|
+
setCursor(ctx, schema, def.prop, def.typeIndex, parentId, modifyOp);
|
|
12
12
|
ctx.buf[ctx.len++] = modifyOp;
|
|
13
13
|
ctx.buf[ctx.len++] = hasEdges ? 1 : 0;
|
|
14
14
|
ctx.buf[ctx.len++] = id;
|
|
@@ -59,7 +59,7 @@ export function writeReference(value, ctx, schema, def, res, modifyOp) {
|
|
|
59
59
|
if (ctx.len + 11 > ctx.max) {
|
|
60
60
|
return RANGE_ERR;
|
|
61
61
|
}
|
|
62
|
-
setCursor(ctx, schema, def.prop, res.tmpId, modifyOp);
|
|
62
|
+
setCursor(ctx, schema, def.prop, def.typeIndex, res.tmpId, modifyOp);
|
|
63
63
|
ctx.buf[ctx.len++] = DELETE;
|
|
64
64
|
}
|
|
65
65
|
else if (typeof value === 'number') {
|
|
@@ -9,7 +9,6 @@ export type RefModifyOpts = {
|
|
|
9
9
|
export type RefModify = ModifyState | RefModifyOpts | number;
|
|
10
10
|
export type Refs = RefModify[] | {
|
|
11
11
|
add?: RefModify[] | RefModify;
|
|
12
|
-
update?: RefModify[] | RefModify;
|
|
13
12
|
delete?: RefModify[] | RefModify;
|
|
14
13
|
upsert: RefModify[] | RefModify;
|
|
15
14
|
};
|
|
@@ -11,7 +11,7 @@ export function writeReferences(value, ctx, schema, def, res, mod) {
|
|
|
11
11
|
if (ctx.len + 11 > ctx.max) {
|
|
12
12
|
return RANGE_ERR;
|
|
13
13
|
}
|
|
14
|
-
setCursor(ctx, schema, def.prop, res.tmpId, mod);
|
|
14
|
+
setCursor(ctx, schema, def.prop, def.typeIndex, res.tmpId, mod);
|
|
15
15
|
ctx.buf[ctx.len++] = DELETE;
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
@@ -27,7 +27,7 @@ export function writeReferences(value, ctx, schema, def, res, mod) {
|
|
|
27
27
|
else if (key === 'delete') {
|
|
28
28
|
err = deleteRefs(def, ctx, schema, mod, val, res.tmpId);
|
|
29
29
|
}
|
|
30
|
-
else if (key === '
|
|
30
|
+
else if (key === 'set') {
|
|
31
31
|
err = updateRefs(def, ctx, schema, mod, val, res.tmpId, 1);
|
|
32
32
|
}
|
|
33
33
|
else if (key === 'upsert') {
|
|
@@ -58,7 +58,7 @@ function deleteRefs(def, ctx, schema, modifyOp, refs, parentId) {
|
|
|
58
58
|
if (ctx.len + 10 + size > ctx.max) {
|
|
59
59
|
return RANGE_ERR;
|
|
60
60
|
}
|
|
61
|
-
setCursor(ctx, schema, def.prop, parentId, modifyOp);
|
|
61
|
+
setCursor(ctx, schema, def.prop, def.typeIndex, parentId, modifyOp);
|
|
62
62
|
ctx.buf[ctx.len++] = modifyOp;
|
|
63
63
|
ctx.buf[ctx.len++] = size;
|
|
64
64
|
ctx.buf[ctx.len++] = size >>>= 8;
|
|
@@ -91,7 +91,7 @@ function updateRefs(def, ctx, schema, mod, refs, parentId, op) {
|
|
|
91
91
|
if (ctx.len + 19 + refs.length * 4 > ctx.max) {
|
|
92
92
|
return RANGE_ERR;
|
|
93
93
|
}
|
|
94
|
-
setCursor(ctx, schema, def.prop, parentId, mod);
|
|
94
|
+
setCursor(ctx, schema, def.prop, def.typeIndex, parentId, mod);
|
|
95
95
|
const initpos = ctx.len;
|
|
96
96
|
const nrOrErr = putRefs(def, ctx, mod, refs, op);
|
|
97
97
|
if (nrOrErr) {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const remove: (db: DbClient, type: string, id: number) => boolean;
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { flushBuffer, startDrain } from '../operations.js';
|
|
2
2
|
import { setCursor } from './setCursor.js';
|
|
3
3
|
import { UPDATE } from './types.js';
|
|
4
|
-
|
|
4
|
+
import { MICRO_BUFFER } from '../../server/schema/schema.js';
|
|
5
|
+
export const ;
|
|
6
|
+
delete ;
|
|
7
|
+
(db, type, id) => {
|
|
5
8
|
const ctx = db.modifyCtx;
|
|
6
9
|
const schema = db.schemaTypesParsed[type];
|
|
7
10
|
const separate = schema.separate;
|
|
@@ -9,12 +12,12 @@ export const remove = (db, type, id) => {
|
|
|
9
12
|
const size = 12 + separate.length * 12;
|
|
10
13
|
if (ctx.len + size > ctx.max) {
|
|
11
14
|
flushBuffer(db);
|
|
12
|
-
return
|
|
15
|
+
return delete (db, type, id);
|
|
13
16
|
}
|
|
14
|
-
setCursor(ctx, schema, 0, id, UPDATE);
|
|
17
|
+
setCursor(ctx, schema, 0, MICRO_BUFFER, id, UPDATE);
|
|
15
18
|
ctx.buf[ctx.len++] = 4;
|
|
16
19
|
for (const s of separate) {
|
|
17
|
-
setCursor(ctx, schema, s.prop, id, UPDATE);
|
|
20
|
+
setCursor(ctx, schema, s.prop, s.typeIndex, id, UPDATE);
|
|
18
21
|
ctx.buf[ctx.len++] = 4;
|
|
19
22
|
}
|
|
20
23
|
ctx.buf[ctx.len++] = 10;
|
|
@@ -22,9 +25,9 @@ export const remove = (db, type, id) => {
|
|
|
22
25
|
else {
|
|
23
26
|
if (ctx.len + 12 > ctx.max) {
|
|
24
27
|
flushBuffer(db);
|
|
25
|
-
return
|
|
28
|
+
return delete (db, type, id);
|
|
26
29
|
}
|
|
27
|
-
setCursor(ctx, schema, 0, id, UPDATE);
|
|
30
|
+
setCursor(ctx, schema, 0, MICRO_BUFFER, id, UPDATE);
|
|
28
31
|
ctx.buf[ctx.len++] = 4;
|
|
29
32
|
ctx.buf[ctx.len++] = 10;
|
|
30
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ModifyCtx } from '../../index.js';
|
|
2
2
|
import { SchemaTypeDef } from '../../server/schema/types.js';
|
|
3
3
|
import { ModifyOp } from './types.js';
|
|
4
|
-
export declare const setCursor: (ctx: ModifyCtx, schema: SchemaTypeDef, field: number, id: number, modifyOp: ModifyOp, ignoreField?: boolean) => void;
|
|
4
|
+
export declare const setCursor: (ctx: ModifyCtx, schema: SchemaTypeDef, field: number, typeIndex: number, id: number, modifyOp: ModifyOp, ignoreField?: boolean) => void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CREATE, SWITCH_FIELD, SWITCH_ID_CREATE, SWITCH_ID_UPDATE, SWITCH_TYPE, } from './types.js';
|
|
2
|
-
export const setCursor = (ctx, schema, field,
|
|
2
|
+
export const setCursor = (ctx, schema, field, // PROPDEF
|
|
3
|
+
typeIndex, id, modifyOp, ignoreField) => {
|
|
3
4
|
const prefix0 = schema.idUint8[0];
|
|
4
5
|
const prefix1 = schema.idUint8[1];
|
|
5
6
|
if (ctx.prefix0 !== prefix0 || ctx.prefix1 !== prefix1) {
|
|
@@ -18,6 +19,8 @@ export const setCursor = (ctx, schema, field, id, modifyOp, ignoreField) => {
|
|
|
18
19
|
if (!ignoreField && ctx.field !== field) {
|
|
19
20
|
ctx.buf[ctx.len++] = SWITCH_FIELD; // switch field
|
|
20
21
|
ctx.buf[ctx.len++] = field; // actual field
|
|
22
|
+
ctx.buf[ctx.len++] = typeIndex;
|
|
23
|
+
// field === 0 ? MICRO_BUFFER : schema.reverseProps[field].typeIndex
|
|
21
24
|
// add start and len if its main
|
|
22
25
|
ctx.field = field;
|
|
23
26
|
}
|
|
@@ -16,7 +16,7 @@ export function writeString(lang, value, ctx, def, t, parentId, modifyOp) {
|
|
|
16
16
|
if (ctx.len + 11 > ctx.max) {
|
|
17
17
|
return RANGE_ERR;
|
|
18
18
|
}
|
|
19
|
-
setCursor(ctx, def, t.prop, parentId, modifyOp);
|
|
19
|
+
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
20
20
|
ctx.buf[ctx.len++] = DELETE;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -32,7 +32,7 @@ export function writeString(lang, value, ctx, def, t, parentId, modifyOp) {
|
|
|
32
32
|
def.stringPropsCurrent[t.prop] = 2;
|
|
33
33
|
ctx.hasStringField++;
|
|
34
34
|
}
|
|
35
|
-
setCursor(ctx, def, t.prop, parentId, modifyOp);
|
|
35
|
+
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
36
36
|
// TODO if buffer check if second byte is zero or one
|
|
37
37
|
// modOp | size u32 | stringprotocol | string
|
|
38
38
|
ctx.buf[ctx.len] = modifyOp;
|
|
@@ -2,6 +2,7 @@ import { ModifyCtx } from '../../index.js';
|
|
|
2
2
|
import { ModifyOp, ModifyErr } from './types.js';
|
|
3
3
|
import { SchemaTypeDef, PropDef } from '../../server/schema/types.js';
|
|
4
4
|
import { writeString } from './string.js';
|
|
5
|
+
import { ModifyState } from './ModifyRes.js';
|
|
5
6
|
export declare function writeText(value: {
|
|
6
7
|
[k: string]: Parameters<typeof writeString>[1];
|
|
7
|
-
}, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef,
|
|
8
|
+
}, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, res: ModifyState, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { langCodesMap } from '@based/schema';
|
|
2
2
|
import { writeString } from './string.js';
|
|
3
|
-
export function writeText(value, ctx, def, t,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
export function writeText(value, ctx, def, t, res, modifyOp) {
|
|
4
|
+
// todo proper fallback as well
|
|
5
|
+
if (value && typeof value !== 'object') {
|
|
6
|
+
const err = writeString(res.i18n ?? langCodesMap.get('en'), value, ctx, def, t, res.tmpId, modifyOp);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
for (const lang in value) {
|
|
10
|
+
const langCode = langCodesMap.get(lang) || langCodesMap.get('en'); // TODO use proper fallback
|
|
11
|
+
const s = value[lang];
|
|
12
|
+
const err = writeString(langCode, s, ctx, def, t, res.tmpId, modifyOp);
|
|
13
|
+
if (err) {
|
|
14
|
+
return err;
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
}
|
|
12
18
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LangName } from '@based/schema';
|
|
1
2
|
import { ModifyError } from './ModifyRes.js';
|
|
2
3
|
export declare const CREATE = 3;
|
|
3
4
|
export declare const UPDATE = 6;
|
|
@@ -6,9 +7,15 @@ export declare const MERGE_MAIN = 4;
|
|
|
6
7
|
export declare const RANGE_ERR = 1;
|
|
7
8
|
export declare const INCREMENT = 12;
|
|
8
9
|
export declare const DECREMENT = 13;
|
|
10
|
+
export declare const EXPIRE = 14;
|
|
9
11
|
export declare const SWITCH_TYPE = 2;
|
|
10
12
|
export declare const SWITCH_FIELD = 0;
|
|
11
13
|
export declare const SWITCH_ID_CREATE = 9;
|
|
12
14
|
export declare const SWITCH_ID_UPDATE = 1;
|
|
13
15
|
export type ModifyErr = typeof RANGE_ERR | ModifyError | void;
|
|
14
|
-
export type ModifyOp = typeof CREATE | typeof UPDATE | typeof INCREMENT;
|
|
16
|
+
export type ModifyOp = typeof CREATE | typeof UPDATE | typeof INCREMENT | typeof EXPIRE;
|
|
17
|
+
export type ModifyOpts = {
|
|
18
|
+
unsafe?: boolean;
|
|
19
|
+
i18n?: LangName;
|
|
20
|
+
overwrite?: boolean;
|
|
21
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ModifyRes } from './ModifyRes.js';
|
|
2
|
+
import { ModifyOpts } from './types.js';
|
|
2
3
|
import { DbClient } from '../index.js';
|
|
3
4
|
type Payload = Record<string, any>;
|
|
4
|
-
export declare const update: (db: DbClient, type: string, id: number, obj: Payload,
|
|
5
|
+
export declare const update: (db: DbClient, type: string, id: number, obj: Payload, opts?: ModifyOpts) => ModifyRes;
|
|
5
6
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MICRO_BUFFER, } from '../../server/schema/schema.js';
|
|
1
2
|
import { startDrain, flushBuffer } from '../operations.js';
|
|
2
3
|
import { setCursor } from './setCursor.js';
|
|
3
4
|
import { modify } from './modify.js';
|
|
@@ -30,7 +31,7 @@ const appendUpdate = (ctx, def, obj, res, overwrite) => {
|
|
|
30
31
|
if (ctx.len + 15 + mergeMain.length * 4 > ctx.max) {
|
|
31
32
|
return RANGE_ERR;
|
|
32
33
|
}
|
|
33
|
-
setCursor(ctx, def, 0, res.tmpId, UPDATE);
|
|
34
|
+
setCursor(ctx, def, 0, MICRO_BUFFER, res.tmpId, UPDATE);
|
|
34
35
|
ctx.buf[ctx.len++] = 5;
|
|
35
36
|
ctx.buf[ctx.len++] = mergeMainSize;
|
|
36
37
|
ctx.buf[ctx.len++] = mergeMainSize >>>= 8;
|
|
@@ -51,12 +52,15 @@ const appendUpdate = (ctx, def, obj, res, overwrite) => {
|
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
|
-
export const update = (db, type, id, obj,
|
|
55
|
+
export const update = (db, type, id, obj, opts) => {
|
|
55
56
|
const def = db.schemaTypesParsed[type];
|
|
57
|
+
if (!def) {
|
|
58
|
+
throw new Error(`Unknown type: ${type}. Did you mean on of: ${Object.keys(db.schemaTypesParsed).join(', ')}`);
|
|
59
|
+
}
|
|
56
60
|
const ctx = db.modifyCtx;
|
|
57
61
|
const pos = ctx.len;
|
|
58
|
-
const res = new ModifyState(def.id, id, db, getSubscriptionMarkers(db, def.id, id, false));
|
|
59
|
-
const err = appendUpdate(ctx, def, obj, res, overwrite);
|
|
62
|
+
const res = new ModifyState(def.id, id, db, getSubscriptionMarkers(db, def.id, id, false), opts);
|
|
63
|
+
const err = appendUpdate(ctx, def, obj, res, opts?.overwrite);
|
|
60
64
|
if (err) {
|
|
61
65
|
ctx.prefix0 = -1; // force a new cursor
|
|
62
66
|
ctx.len = pos;
|
|
@@ -65,7 +69,7 @@ export const update = (db, type, id, obj, overwrite) => {
|
|
|
65
69
|
throw new Error('out of range');
|
|
66
70
|
}
|
|
67
71
|
flushBuffer(db);
|
|
68
|
-
return update(db, type, id, obj,
|
|
72
|
+
return update(db, type, id, obj, opts);
|
|
69
73
|
}
|
|
70
74
|
res.error = err;
|
|
71
75
|
// @ts-ignore
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DbClient } from '../index.js';
|
|
2
|
-
|
|
2
|
+
import { ModifyOpts } from './types.js';
|
|
3
|
+
export declare function upsert(db: DbClient, type: string, obj: Record<string, any>, opts?: ModifyOpts): Promise<any>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ALIAS } from '../../server/schema/types.js';
|
|
2
|
-
export async function upsert(db, type, obj) {
|
|
2
|
+
export async function upsert(db, type, obj, opts) {
|
|
3
3
|
const tree = db.schemaTypesParsed[type].tree;
|
|
4
4
|
let q;
|
|
5
5
|
let id = '';
|
|
@@ -27,10 +27,10 @@ export async function upsert(db, type, obj) {
|
|
|
27
27
|
p: q.get().then((res) => {
|
|
28
28
|
db.upserting.delete(id);
|
|
29
29
|
if (res.length === 0) {
|
|
30
|
-
return db.create(type, store.o);
|
|
30
|
+
return db.create(type, store.o, opts);
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
return db.update(type, res.toObject()[0].id, store.o);
|
|
33
|
+
return db.update(type, res.toObject()[0].id, store.o, opts);
|
|
34
34
|
}
|
|
35
35
|
}),
|
|
36
36
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModifyCtx } from '../../index.js';
|
|
2
|
+
import { PropDef, SchemaTypeDef } from '../../server/schema/types.js';
|
|
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;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { UPDATE, RANGE_ERR, DELETE } from './types.js';
|
|
2
|
+
import { ModifyError } from './ModifyRes.js';
|
|
3
|
+
import { setCursor } from './setCursor.js';
|
|
4
|
+
function write(value, ctx, fieldSize) {
|
|
5
|
+
const size = Math.min(value.byteLength, fieldSize);
|
|
6
|
+
let tmp = size;
|
|
7
|
+
// 16-bits would be enough but the zig code now expects 32-bits
|
|
8
|
+
ctx.buf[ctx.len++] = tmp;
|
|
9
|
+
ctx.buf[ctx.len++] = tmp >>>= 8;
|
|
10
|
+
ctx.buf[ctx.len++] = tmp >>>= 8;
|
|
11
|
+
ctx.buf[ctx.len++] = tmp >>>= 8;
|
|
12
|
+
Buffer.from(value.buffer).copy(ctx.buf, ctx.len, 0, size);
|
|
13
|
+
ctx.len += size;
|
|
14
|
+
}
|
|
15
|
+
export function writeVector(value, ctx, schema, t, parentId, modifyOp) {
|
|
16
|
+
let size;
|
|
17
|
+
if (value === null) {
|
|
18
|
+
size = 0;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
if (!value) {
|
|
22
|
+
return new ModifyError(t, value);
|
|
23
|
+
}
|
|
24
|
+
size = value.byteLength + 4;
|
|
25
|
+
}
|
|
26
|
+
if (size === 0) {
|
|
27
|
+
if (modifyOp === UPDATE) {
|
|
28
|
+
if (ctx.len + 11 > ctx.max) {
|
|
29
|
+
// TODO ???
|
|
30
|
+
return RANGE_ERR;
|
|
31
|
+
}
|
|
32
|
+
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
33
|
+
ctx.buf[ctx.len++] = DELETE;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (ctx.len + 15 + size > ctx.max) {
|
|
38
|
+
// TODO ???
|
|
39
|
+
return RANGE_ERR;
|
|
40
|
+
}
|
|
41
|
+
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
42
|
+
ctx.buf[ctx.len++] = modifyOp;
|
|
43
|
+
write(value, ctx, t.len);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=vector%20copy.js.map
|
|
@@ -25,18 +25,20 @@ export function writeVector(value, ctx, schema, t, parentId, modifyOp) {
|
|
|
25
25
|
}
|
|
26
26
|
if (size === 0) {
|
|
27
27
|
if (modifyOp === UPDATE) {
|
|
28
|
-
if (ctx.len + 11 > ctx.max) {
|
|
28
|
+
if (ctx.len + 11 > ctx.max) {
|
|
29
|
+
// TODO ???
|
|
29
30
|
return RANGE_ERR;
|
|
30
31
|
}
|
|
31
|
-
setCursor(ctx, schema, t.prop, parentId, modifyOp);
|
|
32
|
+
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
32
33
|
ctx.buf[ctx.len++] = DELETE;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
else {
|
|
36
|
-
if (ctx.len + 15 + size > ctx.max) {
|
|
37
|
+
if (ctx.len + 15 + size > ctx.max) {
|
|
38
|
+
// TODO ???
|
|
37
39
|
return RANGE_ERR;
|
|
38
40
|
}
|
|
39
|
-
setCursor(ctx, schema, t.prop, parentId, modifyOp);
|
|
41
|
+
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
40
42
|
ctx.buf[ctx.len++] = modifyOp;
|
|
41
43
|
write(value, ctx, t.len);
|
|
42
44
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { QueryDef, Operator, QueryByAliasObj } from './query.js';
|
|
2
2
|
import { BasedQueryResponse } from './BasedIterable.js';
|
|
3
|
-
import { FilterAst, FilterBranchFn } from './filter/types.js';
|
|
4
3
|
import { Search } from './search/index.js';
|
|
5
4
|
import { OnData, OnError } from './subscription/index.js';
|
|
6
5
|
import { DbClient } from '../index.js';
|
|
7
6
|
import { LangName } from '@based/schema';
|
|
7
|
+
import { FilterAst, FilterBranchFn, FilterOpts } from './filter/types.js';
|
|
8
8
|
export { QueryByAliasObj };
|
|
9
9
|
export type SelectFn = (field: string) => BasedDbReferenceQuery;
|
|
10
10
|
export type BranchInclude = (select: SelectFn) => any;
|
|
@@ -13,11 +13,12 @@ export declare class QueryBranch<T> {
|
|
|
13
13
|
def: QueryDef;
|
|
14
14
|
constructor(db: DbClient, def: QueryDef);
|
|
15
15
|
sort(field: string, order?: 'asc' | 'desc'): T;
|
|
16
|
-
filter(field: string, operator?:
|
|
16
|
+
filter<O extends Operator>(field: string, operator?: O | boolean, value?: any, opts?: FilterOpts<O>): T;
|
|
17
17
|
search(query: string, ...fields: Search[]): T;
|
|
18
|
+
search(query: ArrayBufferView, field: string, opts?: Omit<FilterOpts, 'lowerCase'>): T;
|
|
18
19
|
filterBatch(f: FilterAst): this;
|
|
19
20
|
or(fn: FilterBranchFn): T;
|
|
20
|
-
or(field: string, operator?: Operator | boolean, value?: any): T;
|
|
21
|
+
or(field: string, operator?: Operator | boolean, value?: any, opts?: FilterOpts): T;
|
|
21
22
|
range(offset: number, limit: number): T;
|
|
22
23
|
include(...fields: (string | BranchInclude | string[])[]): T;
|
|
23
24
|
}
|