@based/db 0.0.68 → 0.0.70
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 +6 -1
- package/dist/lib/darwin_aarch64/include/selva/fields.h +0 -9
- package/dist/lib/darwin_aarch64/include/selva_error.h +4 -1
- 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/linux_aarch64/include/selva/fields.h +0 -9
- package/dist/lib/linux_aarch64/include/selva_error.h +4 -1
- 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/selva/fields.h +0 -9
- package/dist/lib/linux_x86_64/include/selva_error.h +4 -1
- 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/modify/alias.js +4 -0
- package/dist/src/client/modify/binary.d.ts +1 -1
- package/dist/src/client/modify/binary.js +22 -7
- package/dist/src/client/modify/create.js +91 -39
- package/dist/src/client/modify/fixed.d.ts +3 -3
- package/dist/src/client/modify/fixed.js +80 -20
- package/dist/src/client/modify/json.js +7 -0
- package/dist/src/client/modify/modify.js +3 -3
- package/dist/src/client/modify/references/edge.js +3 -3
- package/dist/src/client/modify/string.d.ts +1 -1
- package/dist/src/client/modify/string.js +17 -7
- package/dist/src/client/modify/text.d.ts +1 -1
- package/dist/src/client/modify/text.js +27 -15
- package/dist/src/client/modify/types.d.ts +2 -1
- package/dist/src/client/modify/types.js +6 -0
- package/dist/src/client/modify/update.js +5 -1
- package/dist/src/client/query/display.js +1 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +3 -0
- package/dist/src/client/query/filter/createReferenceFilter.js +3 -0
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +21 -19
- package/dist/src/client/query/read/read.js +9 -10
- package/dist/src/native.d.ts +1 -0
- package/dist/src/native.js +3 -0
- package/dist/src/server/IoWorker.d.ts +16 -0
- package/dist/src/server/IoWorker.js +32 -3
- package/dist/src/server/QueryWorker.js +2 -2
- package/dist/src/server/blocks.d.ts +3 -1
- package/dist/src/server/blocks.js +31 -7
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/server/index.js +8 -11
- package/dist/src/server/migrate/index.js +25 -11
- package/dist/src/server/migrate/worker.js +70 -62
- package/dist/src/server/save.d.ts +7 -1
- package/dist/src/server/save.js +107 -50
- package/dist/src/server/schema.d.ts +1 -1
- package/dist/src/server/schema.js +6 -2
- package/dist/src/server/start.js +11 -5
- package/dist/src/server/tree.d.ts +11 -0
- package/dist/src/server/tree.js +0 -1
- package/dist/src/server/workers/DbWorker.d.ts +3 -2
- package/dist/src/server/workers/DbWorker.js +2 -1
- package/dist/src/server/workers/io_worker.js +22 -17
- package/dist/src/server/workers/io_worker_types.d.ts +9 -1
- package/dist/src/server/workers/worker.js +11 -3
- package/dist/src/types.d.ts +1 -0
- package/dist/src/types.js +1 -0
- package/dist/src/utils.js +1 -1
- package/package.json +5 -3
- package/dist/lib/darwin_aarch64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
|
@@ -3,9 +3,9 @@ import { BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TIMESTAMP, U
|
|
|
3
3
|
import { convertToTimestamp } from '@saulx/utils';
|
|
4
4
|
import { getBuffer } from './binary.js';
|
|
5
5
|
import { ModifyError } from './ModifyRes.js';
|
|
6
|
-
import { RANGE_ERR } from './types.js';
|
|
6
|
+
import { MOD_OPS_TO_STRING, RANGE_ERR } from './types.js';
|
|
7
7
|
const map = {};
|
|
8
|
-
map[BINARY] = (ctx, val, def) => {
|
|
8
|
+
map[BINARY] = (ctx, val, def, mod) => {
|
|
9
9
|
const buf = getBuffer(val);
|
|
10
10
|
if (buf === undefined) {
|
|
11
11
|
return new ModifyError(def, val);
|
|
@@ -13,6 +13,9 @@ map[BINARY] = (ctx, val, def) => {
|
|
|
13
13
|
if (!def.validation(val, def)) {
|
|
14
14
|
return new ModifyError(def, val);
|
|
15
15
|
}
|
|
16
|
+
if (def.transform) {
|
|
17
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
18
|
+
}
|
|
16
19
|
const size = buf.byteLength;
|
|
17
20
|
if (ctx.len + size + 1 > ctx.max) {
|
|
18
21
|
return RANGE_ERR;
|
|
@@ -21,7 +24,7 @@ map[BINARY] = (ctx, val, def) => {
|
|
|
21
24
|
ctx.buf.set(buf, ctx.len);
|
|
22
25
|
ctx.len += buf.byteLength;
|
|
23
26
|
};
|
|
24
|
-
map[STRING] = (ctx, val, def) => {
|
|
27
|
+
map[STRING] = (ctx, val, def, mod) => {
|
|
25
28
|
const valBuf = ENCODER.encode(val);
|
|
26
29
|
const size = valBuf.byteLength;
|
|
27
30
|
if (size + 1 > def.len) {
|
|
@@ -30,6 +33,9 @@ map[STRING] = (ctx, val, def) => {
|
|
|
30
33
|
if (!def.validation(val, def)) {
|
|
31
34
|
return new ModifyError(def, val);
|
|
32
35
|
}
|
|
36
|
+
if (def.transform) {
|
|
37
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
38
|
+
}
|
|
33
39
|
if (ctx.len + size + 1 > ctx.max) {
|
|
34
40
|
return RANGE_ERR;
|
|
35
41
|
}
|
|
@@ -41,30 +47,36 @@ map[STRING] = (ctx, val, def) => {
|
|
|
41
47
|
ctx.buf.fill(0, ctx.len - (fullSize - size), ctx.len);
|
|
42
48
|
}
|
|
43
49
|
};
|
|
44
|
-
map[BOOLEAN] = (ctx, val, def) => {
|
|
50
|
+
map[BOOLEAN] = (ctx, val, def, mod) => {
|
|
45
51
|
if (ctx.len + 1 > ctx.max) {
|
|
46
52
|
return RANGE_ERR;
|
|
47
53
|
}
|
|
54
|
+
if (val === null) {
|
|
55
|
+
val = def.default;
|
|
56
|
+
}
|
|
48
57
|
if (!def.validation(val, def)) {
|
|
49
58
|
return new ModifyError(def, val);
|
|
50
59
|
}
|
|
51
|
-
if (
|
|
52
|
-
|
|
60
|
+
if (def.transform) {
|
|
61
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
53
62
|
}
|
|
54
|
-
|
|
63
|
+
if (typeof val === 'boolean') {
|
|
55
64
|
ctx.buf[ctx.len++] = val ? 1 : 0;
|
|
56
65
|
}
|
|
57
66
|
else {
|
|
58
67
|
return new ModifyError(def, val);
|
|
59
68
|
}
|
|
60
69
|
};
|
|
61
|
-
map[ENUM] = (ctx, val, def) => {
|
|
70
|
+
map[ENUM] = (ctx, val, def, mod) => {
|
|
62
71
|
if (ctx.len + 1 > ctx.max) {
|
|
63
72
|
return RANGE_ERR;
|
|
64
73
|
}
|
|
65
74
|
if (!def.validation(val, def)) {
|
|
66
75
|
return new ModifyError(def, val);
|
|
67
76
|
}
|
|
77
|
+
if (def.transform) {
|
|
78
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
79
|
+
}
|
|
68
80
|
if (val === null) {
|
|
69
81
|
ctx.buf[ctx.len++] = 0;
|
|
70
82
|
}
|
|
@@ -75,101 +87,149 @@ map[ENUM] = (ctx, val, def) => {
|
|
|
75
87
|
return new ModifyError(def, val);
|
|
76
88
|
}
|
|
77
89
|
};
|
|
78
|
-
map[NUMBER] = (ctx, val, def) => {
|
|
90
|
+
map[NUMBER] = (ctx, val, def, mod) => {
|
|
79
91
|
if (ctx.len + 8 > ctx.max) {
|
|
80
92
|
return RANGE_ERR;
|
|
81
93
|
}
|
|
94
|
+
if (val === null) {
|
|
95
|
+
val = def.default;
|
|
96
|
+
}
|
|
82
97
|
if (!def.validation(val, def)) {
|
|
83
98
|
return new ModifyError(def, val);
|
|
84
99
|
}
|
|
100
|
+
if (def.transform) {
|
|
101
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
102
|
+
}
|
|
85
103
|
const view = new DataView(ctx.buf.buffer, ctx.buf.byteOffset + ctx.len, 8);
|
|
86
104
|
ctx.len += 8;
|
|
87
105
|
view.setFloat64(0, val, true);
|
|
88
106
|
};
|
|
89
|
-
map[TIMESTAMP] = (ctx, val, def) => {
|
|
107
|
+
map[TIMESTAMP] = (ctx, val, def, mod) => {
|
|
90
108
|
const parsedValue = convertToTimestamp(val);
|
|
91
109
|
if (ctx.len + 8 > ctx.max) {
|
|
92
110
|
return RANGE_ERR;
|
|
93
111
|
}
|
|
112
|
+
if (val === null) {
|
|
113
|
+
val = def.default;
|
|
114
|
+
}
|
|
94
115
|
if (!def.validation(parsedValue, def)) {
|
|
95
116
|
return new ModifyError(def, val);
|
|
96
117
|
}
|
|
118
|
+
if (def.transform) {
|
|
119
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
120
|
+
}
|
|
97
121
|
const view = new DataView(ctx.buf.buffer, ctx.buf.byteOffset + ctx.len, 8);
|
|
98
122
|
ctx.len += 8;
|
|
99
123
|
// Todo use new utils and store as uint64
|
|
100
124
|
view.setFloat64(0, parsedValue, true);
|
|
101
125
|
// const ts = view.getFloat64(0)
|
|
102
126
|
};
|
|
103
|
-
map[UINT32] = (ctx, val, def) => {
|
|
127
|
+
map[UINT32] = (ctx, val, def, mod) => {
|
|
104
128
|
if (ctx.len + 4 > ctx.max) {
|
|
105
129
|
return RANGE_ERR;
|
|
106
130
|
}
|
|
131
|
+
if (val === null) {
|
|
132
|
+
val = def.default;
|
|
133
|
+
}
|
|
107
134
|
if (!def.validation(val, def)) {
|
|
108
135
|
return new ModifyError(def, val);
|
|
109
136
|
}
|
|
137
|
+
if (def.transform) {
|
|
138
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
139
|
+
}
|
|
110
140
|
ctx.buf[ctx.len++] = val;
|
|
111
141
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
112
142
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
113
143
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
114
144
|
};
|
|
115
|
-
map[UINT16] = (ctx, val, def) => {
|
|
145
|
+
map[UINT16] = (ctx, val, def, mod) => {
|
|
116
146
|
if (ctx.len + 2 > ctx.max) {
|
|
117
147
|
return RANGE_ERR;
|
|
118
148
|
}
|
|
149
|
+
if (val === null) {
|
|
150
|
+
val = def.default;
|
|
151
|
+
}
|
|
119
152
|
if (!def.validation(val, def)) {
|
|
120
153
|
return new ModifyError(def, val);
|
|
121
154
|
}
|
|
155
|
+
if (def.transform) {
|
|
156
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
157
|
+
}
|
|
122
158
|
ctx.buf[ctx.len++] = val;
|
|
123
159
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
124
160
|
};
|
|
125
|
-
map[UINT8] = (ctx, val, def) => {
|
|
161
|
+
map[UINT8] = (ctx, val, def, mod) => {
|
|
126
162
|
if (ctx.len + 1 > ctx.max) {
|
|
127
163
|
return RANGE_ERR;
|
|
128
164
|
}
|
|
165
|
+
if (val === null) {
|
|
166
|
+
val = def.default;
|
|
167
|
+
}
|
|
129
168
|
if (!def.validation(val, def)) {
|
|
130
169
|
return new ModifyError(def, val);
|
|
131
170
|
}
|
|
171
|
+
if (def.transform) {
|
|
172
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
173
|
+
}
|
|
132
174
|
ctx.buf[ctx.len++] = val;
|
|
133
175
|
};
|
|
134
|
-
map[INT32] = (ctx, val, def) => {
|
|
176
|
+
map[INT32] = (ctx, val, def, mod) => {
|
|
135
177
|
if (ctx.len + 4 > ctx.max) {
|
|
136
178
|
return RANGE_ERR;
|
|
137
179
|
}
|
|
180
|
+
if (val === null) {
|
|
181
|
+
val = def.default;
|
|
182
|
+
}
|
|
138
183
|
if (!def.validation(val, def)) {
|
|
139
184
|
return new ModifyError(def, val);
|
|
140
185
|
}
|
|
186
|
+
if (def.transform) {
|
|
187
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
188
|
+
}
|
|
141
189
|
ctx.buf[ctx.len++] = val;
|
|
142
190
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
143
191
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
144
192
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
145
193
|
};
|
|
146
|
-
map[INT16] = (ctx, val, def) => {
|
|
194
|
+
map[INT16] = (ctx, val, def, mod) => {
|
|
147
195
|
if (ctx.len + 2 > ctx.max) {
|
|
148
196
|
return RANGE_ERR;
|
|
149
197
|
}
|
|
198
|
+
if (val === null) {
|
|
199
|
+
val = def.default;
|
|
200
|
+
}
|
|
150
201
|
if (!def.validation(val, def)) {
|
|
151
202
|
return new ModifyError(def, val);
|
|
152
203
|
}
|
|
204
|
+
if (def.transform) {
|
|
205
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
206
|
+
}
|
|
153
207
|
ctx.buf[ctx.len++] = val;
|
|
154
208
|
ctx.buf[ctx.len++] = val >>>= 8;
|
|
155
209
|
};
|
|
156
|
-
map[INT8] = (ctx, val, def) => {
|
|
210
|
+
map[INT8] = (ctx, val, def, mod) => {
|
|
157
211
|
if (ctx.len + 1 > ctx.max) {
|
|
158
212
|
return RANGE_ERR;
|
|
159
213
|
}
|
|
214
|
+
if (val === null) {
|
|
215
|
+
val = def.default;
|
|
216
|
+
}
|
|
160
217
|
if (!def.validation(val, def)) {
|
|
161
218
|
return new ModifyError(def, val);
|
|
162
219
|
}
|
|
220
|
+
if (def.transform) {
|
|
221
|
+
val = def.transform(MOD_OPS_TO_STRING[mod], val);
|
|
222
|
+
}
|
|
163
223
|
ctx.buf[ctx.len++] = val;
|
|
164
224
|
};
|
|
165
|
-
export const writeFixedValue = (ctx,
|
|
225
|
+
export const writeFixedValue = (ctx, value, def, pos, mod) => {
|
|
166
226
|
const len = ctx.len;
|
|
167
227
|
ctx.len = pos;
|
|
168
|
-
const res = map[def.typeIndex](ctx,
|
|
228
|
+
const res = map[def.typeIndex](ctx, value, def, mod);
|
|
169
229
|
ctx.len = len;
|
|
170
230
|
return res;
|
|
171
231
|
};
|
|
172
|
-
export const appendFixedValue = (ctx, val, def) => {
|
|
173
|
-
return map[def.typeIndex](ctx, val, def);
|
|
232
|
+
export const appendFixedValue = (ctx, val, def, mod) => {
|
|
233
|
+
return map[def.typeIndex](ctx, val, def, mod);
|
|
174
234
|
};
|
|
175
235
|
//# sourceMappingURL=fixed.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CREATE } from './types.js';
|
|
1
2
|
import { writeBinary } from './binary.js';
|
|
2
3
|
import { ModifyError } from './ModifyRes.js';
|
|
3
4
|
export function writeJson(value, ctx, schema, t, parentId, modifyOp) {
|
|
@@ -9,6 +10,12 @@ export function writeJson(value, ctx, schema, t, parentId, modifyOp) {
|
|
|
9
10
|
if (!t.validation(value, t)) {
|
|
10
11
|
return new ModifyError(t, value);
|
|
11
12
|
}
|
|
13
|
+
if (modifyOp === CREATE) {
|
|
14
|
+
if (schema.hasSeperateDefaults) {
|
|
15
|
+
schema.seperateDefaults.bufferTmp[t.prop] = 1;
|
|
16
|
+
ctx.hasDefaults++;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
12
19
|
return writeBinary(JSON.stringify(value), ctx, schema, t, parentId, modifyOp);
|
|
13
20
|
}
|
|
14
21
|
}
|
|
@@ -75,10 +75,10 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
75
75
|
ctx.len += schema.mainLen;
|
|
76
76
|
}
|
|
77
77
|
if (typeof val === 'object' && val !== null && 'increment' in val) {
|
|
78
|
-
err = writeFixedValue(ctx, val.increment, def, ctx.lastMain + def.start);
|
|
78
|
+
err = writeFixedValue(ctx, val.increment, def, ctx.lastMain + def.start, mod);
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
-
err = writeFixedValue(ctx, val, def, ctx.lastMain + def.start);
|
|
81
|
+
err = writeFixedValue(ctx, val, def, ctx.lastMain + def.start, mod);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
else if (typeof val === 'object' && val !== null) {
|
|
@@ -102,7 +102,7 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
102
102
|
ctx.buf[ctx.len++] = def.typeIndex;
|
|
103
103
|
ctx.buf[ctx.len++] = start;
|
|
104
104
|
ctx.buf[ctx.len++] = start >>>= 8;
|
|
105
|
-
appendFixedValue(ctx, increment, def);
|
|
105
|
+
appendFixedValue(ctx, increment, def, mod);
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
108
108
|
return new ModifyError(def, val);
|
|
@@ -198,7 +198,7 @@ export function writeEdges(t, ref, ctx) {
|
|
|
198
198
|
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
199
199
|
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
200
200
|
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
201
|
-
const err = appendFixedValue(ctx, value, edge);
|
|
201
|
+
const err = appendFixedValue(ctx, value, edge, UPDATE);
|
|
202
202
|
if (err) {
|
|
203
203
|
return err;
|
|
204
204
|
}
|
|
@@ -251,7 +251,7 @@ export function writeEdges(t, ref, ctx) {
|
|
|
251
251
|
ctx.buf[ctx.len++] = sizeU32 >>>= 8;
|
|
252
252
|
for (let i = 0; i < mainFields.length; i += 3) {
|
|
253
253
|
const edge = mainFields[i];
|
|
254
|
-
const err = appendFixedValue(ctx, mainFields[i + 1], edge);
|
|
254
|
+
const err = appendFixedValue(ctx, mainFields[i + 1], edge, UPDATE);
|
|
255
255
|
if (err) {
|
|
256
256
|
return err;
|
|
257
257
|
}
|
|
@@ -309,7 +309,7 @@ export function writeEdges(t, ref, ctx) {
|
|
|
309
309
|
ctx.buf[sIndexI + 5] = edge.typeIndex;
|
|
310
310
|
ctx.len = startMain + edge.start;
|
|
311
311
|
// Add null support (defaults)
|
|
312
|
-
const err = appendFixedValue(ctx, value, edge);
|
|
312
|
+
const err = appendFixedValue(ctx, value, edge, op);
|
|
313
313
|
if (err) {
|
|
314
314
|
return err;
|
|
315
315
|
}
|
|
@@ -2,4 +2,4 @@ import { LangCode } from '@based/schema';
|
|
|
2
2
|
import { ModifyCtx } from '../../index.js';
|
|
3
3
|
import { SchemaTypeDef, PropDef } from '@based/schema/def';
|
|
4
4
|
import { ModifyOp, ModifyErr } from './types.js';
|
|
5
|
-
export declare function writeString(lang: LangCode, value: string | null | Uint8Array, ctx: ModifyCtx,
|
|
5
|
+
export declare function writeString(lang: LangCode, value: string | null | Uint8Array, ctx: ModifyCtx, schema: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { ENCODER } from '../../index.js';
|
|
2
|
-
import { CREATE, UPDATE, RANGE_ERR, DELETE, DELETE_TEXT_FIELD, } from './types.js';
|
|
2
|
+
import { CREATE, UPDATE, RANGE_ERR, DELETE, DELETE_TEXT_FIELD, MOD_OPS_TO_STRING, } from './types.js';
|
|
3
3
|
import { ModifyError } from './ModifyRes.js';
|
|
4
4
|
import { setCursor } from './setCursor.js';
|
|
5
5
|
import { write } from '../string.js';
|
|
6
6
|
// allow setting buffer in modify create for strings
|
|
7
7
|
// add compression handling for main buffer
|
|
8
8
|
// add compression handling for edge fields
|
|
9
|
-
export function writeString(lang, value, ctx,
|
|
9
|
+
export function writeString(lang, value, ctx, schema, t, parentId, modifyOp) {
|
|
10
10
|
const isBuffer = value instanceof Uint8Array;
|
|
11
11
|
if (value === null || value === '') {
|
|
12
12
|
if (modifyOp === UPDATE) {
|
|
13
13
|
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 2 > ctx.max) {
|
|
14
14
|
return RANGE_ERR;
|
|
15
15
|
}
|
|
16
|
-
setCursor(ctx,
|
|
16
|
+
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
17
17
|
if (lang === 0) {
|
|
18
18
|
ctx.buf[ctx.len++] = DELETE;
|
|
19
19
|
}
|
|
@@ -27,22 +27,32 @@ export function writeString(lang, value, ctx, def, t, parentId, modifyOp) {
|
|
|
27
27
|
if (!t.validation(value, t)) {
|
|
28
28
|
return new ModifyError(t, value);
|
|
29
29
|
}
|
|
30
|
+
if (t.transform) {
|
|
31
|
+
value = t.transform(MOD_OPS_TO_STRING[modifyOp], value);
|
|
32
|
+
}
|
|
30
33
|
let size = isBuffer
|
|
31
|
-
?
|
|
32
|
-
|
|
34
|
+
? // @ts-ignore
|
|
35
|
+
value.byteLength
|
|
36
|
+
: // @ts-ignore
|
|
37
|
+
ENCODER.encode(value).byteLength + 6;
|
|
33
38
|
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 11 + size > ctx.max) {
|
|
34
39
|
return RANGE_ERR;
|
|
35
40
|
}
|
|
36
41
|
if (modifyOp === CREATE) {
|
|
37
|
-
|
|
42
|
+
schema.seperateSort.bufferTmp[t.prop] = 2;
|
|
38
43
|
ctx.hasSortField++;
|
|
44
|
+
if (schema.hasSeperateDefaults) {
|
|
45
|
+
schema.seperateDefaults.bufferTmp[t.prop] = 1;
|
|
46
|
+
ctx.hasDefaults++;
|
|
47
|
+
}
|
|
39
48
|
}
|
|
40
|
-
setCursor(ctx,
|
|
49
|
+
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
41
50
|
// TODO if buffer check if second byte is zero or one
|
|
42
51
|
// modOp | size u32 | stringprotocol | string
|
|
43
52
|
ctx.buf[ctx.len] = modifyOp;
|
|
44
53
|
ctx.len += 5;
|
|
45
54
|
if (isBuffer) {
|
|
55
|
+
// @ts-ignore
|
|
46
56
|
ctx.buf.set(value, ctx.len);
|
|
47
57
|
}
|
|
48
58
|
else {
|
|
@@ -5,4 +5,4 @@ import { writeString } from './string.js';
|
|
|
5
5
|
import { ModifyState } from './ModifyRes.js';
|
|
6
6
|
export declare function writeText(value: {
|
|
7
7
|
[k: string]: Parameters<typeof writeString>[1];
|
|
8
|
-
} | Parameters<typeof writeString>[1], ctx: ModifyCtx,
|
|
8
|
+
} | Parameters<typeof writeString>[1], ctx: ModifyCtx, schema: SchemaTypeDef, t: PropDef, res: ModifyState, id: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -2,13 +2,13 @@ import { CREATE, UPDATE, RANGE_ERR, DELETE, } from './types.js';
|
|
|
2
2
|
import { writeString } from './string.js';
|
|
3
3
|
import { ModifyError } from './ModifyRes.js';
|
|
4
4
|
import { setCursor } from './setCursor.js';
|
|
5
|
-
export function writeText(value, ctx,
|
|
5
|
+
export function writeText(value, ctx, schema, t, res, id, modifyOp) {
|
|
6
6
|
if (value === null && !res.locale) {
|
|
7
7
|
if (modifyOp === UPDATE) {
|
|
8
8
|
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 1 > ctx.max) {
|
|
9
9
|
return RANGE_ERR;
|
|
10
10
|
}
|
|
11
|
-
setCursor(ctx,
|
|
11
|
+
setCursor(ctx, schema, t.prop, t.typeIndex, id, modifyOp);
|
|
12
12
|
ctx.buf[ctx.len++] = DELETE;
|
|
13
13
|
}
|
|
14
14
|
return;
|
|
@@ -17,40 +17,52 @@ export function writeText(value, ctx, def, t, res, parentId, modifyOp) {
|
|
|
17
17
|
let locale = res.locale;
|
|
18
18
|
if (!locale) {
|
|
19
19
|
// TODO: Add def lang option...
|
|
20
|
-
for (const localeCode of
|
|
20
|
+
for (const localeCode of schema.seperateTextSort.localeToIndex.keys()) {
|
|
21
21
|
locale = localeCode;
|
|
22
22
|
break;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
if (!
|
|
25
|
+
if (!schema.seperateTextSort.localeToIndex.has(locale)) {
|
|
26
26
|
return new ModifyError(t, locale, 'Invalid locale');
|
|
27
27
|
}
|
|
28
|
-
const err = writeString(locale, value, ctx,
|
|
28
|
+
const err = writeString(locale, value, ctx, schema, t, res.tmpId, modifyOp);
|
|
29
29
|
if (modifyOp === CREATE) {
|
|
30
|
-
const index = t.prop * (
|
|
31
|
-
const langIndex =
|
|
32
|
-
|
|
33
|
-
|
|
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
34
|
ctx.hasSortText += 1;
|
|
35
|
+
if (schema.hasSeperateDefaults) {
|
|
36
|
+
schema.seperateDefaults.bufferTmp[t.prop] = 1;
|
|
37
|
+
ctx.hasDefaults++;
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
return err;
|
|
37
41
|
}
|
|
38
42
|
else {
|
|
43
|
+
if (modifyOp === CREATE && schema.hasSeperateDefaults) {
|
|
44
|
+
ctx.hasDefaults++;
|
|
45
|
+
}
|
|
39
46
|
// @ts-ignore
|
|
40
47
|
for (const lang in value) {
|
|
41
|
-
const langC =
|
|
48
|
+
const langC = schema.seperateTextSort.localeStringToIndex.get(lang);
|
|
42
49
|
if (!langC) {
|
|
43
50
|
return new ModifyError(t, lang, 'Invalid locale');
|
|
44
51
|
}
|
|
45
52
|
let s = value[lang];
|
|
46
|
-
const err = writeString(langC[1], s, ctx,
|
|
53
|
+
const err = writeString(langC[1], s, ctx, schema, t, res.tmpId, modifyOp);
|
|
47
54
|
if (err) {
|
|
48
55
|
return err;
|
|
49
56
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
+
}
|
|
54
66
|
}
|
|
55
67
|
}
|
|
56
68
|
}
|
|
@@ -17,11 +17,12 @@ export declare const SWITCH_TYPE = 2;
|
|
|
17
17
|
export declare const SWITCH_FIELD = 0;
|
|
18
18
|
export declare const SWITCH_ID_CREATE = 9;
|
|
19
19
|
export declare const SWITCH_ID_UPDATE = 1;
|
|
20
|
+
export type ModifyOp = typeof CREATE | typeof UPDATE | typeof INCREMENT | typeof EXPIRE;
|
|
21
|
+
export declare const MOD_OPS_TO_STRING: Record<ModifyOp, 'create' | 'update'>;
|
|
20
22
|
export declare const enum SIZE {
|
|
21
23
|
DEFAULT_CURSOR = 11
|
|
22
24
|
}
|
|
23
25
|
export type ModifyErr = typeof RANGE_ERR | ModifyError | void;
|
|
24
|
-
export type ModifyOp = typeof CREATE | typeof UPDATE | typeof INCREMENT | typeof EXPIRE;
|
|
25
26
|
export type ModifyOpts = {
|
|
26
27
|
unsafe?: boolean;
|
|
27
28
|
locale?: LangName;
|
|
@@ -15,6 +15,12 @@ export const SWITCH_TYPE = 2;
|
|
|
15
15
|
export const SWITCH_FIELD = 0;
|
|
16
16
|
export const SWITCH_ID_CREATE = 9;
|
|
17
17
|
export const SWITCH_ID_UPDATE = 1;
|
|
18
|
+
export const MOD_OPS_TO_STRING = {
|
|
19
|
+
[CREATE]: 'create',
|
|
20
|
+
[UPDATE]: 'update',
|
|
21
|
+
[INCREMENT]: 'update',
|
|
22
|
+
[EXPIRE]: 'update',
|
|
23
|
+
};
|
|
18
24
|
export const NOEDGE_NOINDEX_REALID = 0;
|
|
19
25
|
export const EDGE_NOINDEX_REALID = 1;
|
|
20
26
|
export const EDGE_INDEX_REALID = 2;
|
|
@@ -5,6 +5,7 @@ import { modify } from './modify.js';
|
|
|
5
5
|
import { ModifyState } from './ModifyRes.js';
|
|
6
6
|
import { RANGE_ERR, UPDATE } from './types.js';
|
|
7
7
|
import { appendFixedValue } from './fixed.js';
|
|
8
|
+
import { getByPath } from '@saulx/utils';
|
|
8
9
|
const appendUpdate = (ctx, def, obj, res, overwrite) => {
|
|
9
10
|
const err = modify(ctx, res, obj, def, UPDATE, def.tree, overwrite);
|
|
10
11
|
if (err) {
|
|
@@ -13,6 +14,9 @@ const appendUpdate = (ctx, def, obj, res, overwrite) => {
|
|
|
13
14
|
if (def.updateTs) {
|
|
14
15
|
const updateTs = Date.now();
|
|
15
16
|
for (const prop of def.updateTs) {
|
|
17
|
+
if (getByPath(obj, prop.path) !== undefined) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
16
20
|
if (ctx.mergeMain) {
|
|
17
21
|
ctx.mergeMain.push(prop, updateTs);
|
|
18
22
|
ctx.mergeMainSize += prop.len + 4;
|
|
@@ -44,7 +48,7 @@ const appendUpdate = (ctx, def, obj, res, overwrite) => {
|
|
|
44
48
|
ctx.buf[ctx.len++] = start >>>= 8;
|
|
45
49
|
ctx.buf[ctx.len++] = len;
|
|
46
50
|
ctx.buf[ctx.len++] = len >>>= 8;
|
|
47
|
-
const err = appendFixedValue(ctx, v, t);
|
|
51
|
+
const err = appendFixedValue(ctx, v, t, UPDATE);
|
|
48
52
|
if (err) {
|
|
49
53
|
return err;
|
|
50
54
|
}
|
|
@@ -3,6 +3,9 @@ import { ALIGNMENT_NOT_SET, EQUAL, MODE_AND_FIXED, MODE_DEFAULT, MODE_OR_FIXED,
|
|
|
3
3
|
import { parseFilterValue } from './parseFilterValue.js';
|
|
4
4
|
import { ENCODER } from '@saulx/utils';
|
|
5
5
|
export const writeFixed = (prop, buf, value, size, offset) => {
|
|
6
|
+
if (prop.transform) {
|
|
7
|
+
value = prop.transform('filter', value);
|
|
8
|
+
}
|
|
6
9
|
if (prop.typeIndex === BINARY || prop.typeIndex === STRING) {
|
|
7
10
|
if (typeof value === 'string') {
|
|
8
11
|
const { written } = ENCODER.encodeInto(value, buf.subarray(offset + 1));
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ALIGNMENT_NOT_SET, MODE_REFERENCE } from './types.js';
|
|
2
2
|
export const createReferenceFilter = (prop, ctx, value) => {
|
|
3
|
+
if (prop.transform) {
|
|
4
|
+
value = prop.transform('filter', value);
|
|
5
|
+
}
|
|
3
6
|
const isArray = Array.isArray(value);
|
|
4
7
|
const len = isArray ? value.length : 1;
|
|
5
8
|
const buf = new Uint8Array(11 + (isArray ? 8 : 0) + len * 4);
|
|
@@ -5,15 +5,17 @@ import { crc32 } from '../../crc32.js';
|
|
|
5
5
|
import { ENCODER, concatUint8Arr } from '@saulx/utils';
|
|
6
6
|
const DEFAULT_SCORE = new Uint8Array(new Float32Array([0.5]).buffer);
|
|
7
7
|
const parseValue = (value, prop, ctx, lang) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
if (prop.transform) {
|
|
9
|
+
value = prop.transform('filter', value);
|
|
10
|
+
}
|
|
11
|
+
if (ctx.operation === HAS_TO_LOWER_CASE && typeof value === 'string') {
|
|
12
|
+
value = value.toLowerCase();
|
|
11
13
|
}
|
|
12
14
|
if (ctx.operation === LIKE && prop.typeIndex === VECTOR) {
|
|
13
|
-
if (!(
|
|
15
|
+
if (!(value instanceof ArrayBuffer)) {
|
|
14
16
|
throw new Error('Vector should be an arrayBuffer');
|
|
15
17
|
}
|
|
16
|
-
const vector = new Uint8Array(
|
|
18
|
+
const vector = new Uint8Array(value);
|
|
17
19
|
let fn = new Uint8Array([getVectorFn(ctx.opts.fn)]);
|
|
18
20
|
const score = ctx.opts.score
|
|
19
21
|
? new Uint8Array(new Float32Array([ctx.opts.score]).buffer)
|
|
@@ -23,41 +25,41 @@ const parseValue = (value, prop, ctx, lang) => {
|
|
|
23
25
|
off += (buf.set(new Uint8Array(vector), off), vector.byteLength);
|
|
24
26
|
off += (buf.set(fn, off), fn.byteLength);
|
|
25
27
|
buf.set(score, off);
|
|
26
|
-
|
|
28
|
+
value = buf;
|
|
27
29
|
}
|
|
28
|
-
if (
|
|
30
|
+
if (value instanceof Uint8Array ||
|
|
29
31
|
typeof value === 'string' ||
|
|
30
32
|
!prop.separate ||
|
|
31
33
|
ctx.operation !== EQUAL) {
|
|
32
|
-
if (typeof
|
|
33
|
-
|
|
34
|
+
if (typeof value === 'string') {
|
|
35
|
+
value = ENCODER.encode(value.normalize('NFKD'));
|
|
34
36
|
}
|
|
35
37
|
if (prop.typeIndex === TEXT) {
|
|
36
38
|
// 1 + size
|
|
37
39
|
const fallbacksSize = lang.lang === 0 ? 0 : lang.fallback.length;
|
|
38
|
-
const tmp = new Uint8Array(
|
|
39
|
-
tmp.set(
|
|
40
|
+
const tmp = new Uint8Array(value.byteLength + 2 + fallbacksSize);
|
|
41
|
+
tmp.set(value);
|
|
40
42
|
tmp[tmp.byteLength - 1] = fallbacksSize;
|
|
41
43
|
tmp[tmp.byteLength - 2] = lang.lang;
|
|
42
44
|
for (let i = 0; i < fallbacksSize; i++) {
|
|
43
45
|
tmp[tmp.byteLength - 2 - fallbacksSize + i] = lang.fallback[i];
|
|
44
46
|
}
|
|
45
|
-
|
|
47
|
+
value = tmp;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
+
if (value?.BYTES_PER_ELEMENT > 1) {
|
|
51
|
+
value = value.buffer;
|
|
50
52
|
}
|
|
51
|
-
if (!(
|
|
53
|
+
if (!(value instanceof Uint8Array || value instanceof ArrayBuffer)) {
|
|
52
54
|
throw new Error(`Incorrect value for filter: ${prop.path}`);
|
|
53
55
|
}
|
|
54
56
|
if (ctx.operation === LIKE && prop.typeIndex !== VECTOR) {
|
|
55
|
-
const tmp = new Uint8Array(
|
|
56
|
-
tmp.set(
|
|
57
|
+
const tmp = new Uint8Array(value.byteLength + 1);
|
|
58
|
+
tmp.set(value instanceof ArrayBuffer ? new Uint8Array(value) : value);
|
|
57
59
|
tmp[tmp.byteLength - 1] = ctx.opts.score ?? 2;
|
|
58
|
-
|
|
60
|
+
value = tmp;
|
|
59
61
|
}
|
|
60
|
-
return
|
|
62
|
+
return value;
|
|
61
63
|
};
|
|
62
64
|
export const createVariableFilterBuffer = (value, prop, ctx, lang) => {
|
|
63
65
|
let mode = MODE_DEFAULT_VAR;
|