@based/db 0.0.64 → 0.0.67
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 +2 -2
- package/dist/lib/darwin_aarch64/include/selva/colvec.h +71 -0
- package/dist/lib/darwin_aarch64/include/selva/db.h +33 -4
- package/dist/lib/darwin_aarch64/include/selva/fields.h +37 -25
- package/dist/lib/darwin_aarch64/include/selva/hll.h +5 -3
- package/dist/lib/darwin_aarch64/include/selva/membar.h +23 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +8 -1
- package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +19 -3
- 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-v20.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v21.node +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/selva/colvec.h +71 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +33 -4
- package/dist/lib/linux_aarch64/include/selva/fields.h +37 -25
- package/dist/lib/linux_aarch64/include/selva/hll.h +5 -3
- package/dist/lib/linux_aarch64/include/selva/membar.h +23 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +8 -1
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +19 -3
- package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +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_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/colvec.h +71 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +33 -4
- package/dist/lib/linux_x86_64/include/selva/fields.h +37 -25
- package/dist/lib/linux_x86_64/include/selva/hll.h +5 -3
- package/dist/lib/linux_x86_64/include/selva/membar.h +23 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +8 -1
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +19 -3
- package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v21.node +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/flushModify.d.ts +2 -1
- package/dist/src/client/flushModify.js +12 -4
- package/dist/src/client/modify/create.js +11 -0
- package/dist/src/client/modify/delete.js +3 -0
- package/dist/src/client/modify/fixed.js +1 -1
- package/dist/src/client/modify/modify.js +2 -2
- package/dist/src/client/modify/setCursor.d.ts +2 -1
- package/dist/src/client/query/BasedDbQuery.d.ts +10 -4
- package/dist/src/client/query/BasedDbQuery.js +114 -6
- package/dist/src/client/query/aggregates/aggregation.js +24 -11
- package/dist/src/client/query/aggregates/types.d.ts +22 -2
- package/dist/src/client/query/aggregates/types.js +34 -1
- package/dist/src/client/query/display.js +8 -2
- package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -3
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +20 -7
- package/dist/src/client/query/filter/filter.js +13 -3
- package/dist/src/client/query/filter/primitiveFilter.d.ts +1 -2
- package/dist/src/client/query/include/props.js +18 -2
- package/dist/src/client/query/include/toBuffer.js +11 -3
- package/dist/src/client/query/include/walk.js +5 -1
- package/dist/src/client/query/queryDef.js +4 -1
- package/dist/src/client/query/read/read.js +52 -22
- package/dist/src/client/query/registerQuery.js +1 -0
- package/dist/src/client/query/search/index.d.ts +1 -1
- package/dist/src/client/query/search/index.js +21 -7
- package/dist/src/client/query/sort.d.ts +1 -1
- package/dist/src/client/query/toByteCode/default.d.ts +1 -1
- package/dist/src/client/query/toByteCode/default.js +0 -2
- package/dist/src/client/query/toByteCode/toBuffer.js +0 -7
- package/dist/src/client/query/types.d.ts +16 -5
- package/dist/src/client/query/validation.d.ts +3 -0
- package/dist/src/client/query/validation.js +34 -2
- package/dist/src/client/xxHash64.d.ts +1 -1
- package/dist/src/index.d.ts +1 -2
- package/dist/src/index.js +0 -1
- package/dist/src/native.d.ts +7 -4
- package/dist/src/native.js +23 -13
- package/dist/src/server/IoWorker.d.ts +8 -0
- package/dist/src/server/IoWorker.js +39 -0
- package/dist/src/server/QueryWorker.d.ts +8 -0
- package/dist/src/server/QueryWorker.js +26 -0
- package/dist/src/server/blocks.d.ts +24 -0
- package/dist/src/server/blocks.js +112 -0
- package/dist/src/server/dbHash.d.ts +1 -1
- package/dist/src/server/index.d.ts +10 -16
- package/dist/src/server/index.js +39 -15
- package/dist/src/server/migrate/index.d.ts +5 -0
- package/dist/src/server/migrate/index.js +11 -7
- package/dist/src/server/migrate/worker.js +3 -0
- package/dist/src/server/save.d.ts +8 -6
- package/dist/src/server/save.js +34 -78
- package/dist/src/server/schema.js +6 -5
- package/dist/src/server/start.js +57 -60
- package/dist/src/server/tree.d.ts +24 -13
- package/dist/src/server/tree.js +95 -66
- package/dist/src/server/workers/DbWorker.d.ts +17 -0
- package/dist/src/server/{DbWorker.js → workers/DbWorker.js} +15 -17
- package/dist/src/server/workers/io_worker.js +39 -0
- package/dist/src/server/workers/io_worker_types.d.ts +12 -0
- package/dist/src/server/workers/io_worker_types.js +2 -0
- package/dist/src/server/workers/query_worker.d.ts +1 -0
- package/dist/src/server/workers/query_worker.js +4 -0
- package/dist/src/server/workers/worker.d.ts +1 -0
- package/dist/src/server/workers/worker.js +41 -0
- package/dist/src/shared/Emitter.d.ts +1 -0
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.js +1 -1
- package/package.json +3 -3
- package/dist/lib/darwin_aarch64/include/selva/find.h +0 -47
- package/dist/lib/darwin_aarch64/include/selva/history.h +0 -64
- package/dist/lib/darwin_aarch64/include/selva/queue_r.h +0 -190
- package/dist/lib/darwin_aarch64/include/selva/traverse.h +0 -65
- package/dist/lib/linux_aarch64/include/selva/find.h +0 -47
- package/dist/lib/linux_aarch64/include/selva/history.h +0 -64
- package/dist/lib/linux_aarch64/include/selva/queue_r.h +0 -190
- package/dist/lib/linux_aarch64/include/selva/traverse.h +0 -65
- package/dist/lib/linux_x86_64/include/selva/find.h +0 -47
- package/dist/lib/linux_x86_64/include/selva/history.h +0 -64
- package/dist/lib/linux_x86_64/include/selva/queue_r.h +0 -190
- package/dist/lib/linux_x86_64/include/selva/traverse.h +0 -65
- package/dist/src/client/query/serialize.d.ts +0 -4
- package/dist/src/client/query/serialize.js +0 -26
- package/dist/src/server/DbWorker.d.ts +0 -13
- package/dist/src/server/csmt/draw-dot.d.ts +0 -4
- package/dist/src/server/csmt/draw-dot.js +0 -38
- package/dist/src/server/csmt/index.d.ts +0 -4
- package/dist/src/server/csmt/index.js +0 -5
- package/dist/src/server/csmt/match.d.ts +0 -7
- package/dist/src/server/csmt/match.js +0 -10
- package/dist/src/server/csmt/memebership-proof.d.ts +0 -7
- package/dist/src/server/csmt/memebership-proof.js +0 -122
- package/dist/src/server/csmt/tree-utils.d.ts +0 -6
- package/dist/src/server/csmt/tree-utils.js +0 -33
- package/dist/src/server/csmt/tree.d.ts +0 -3
- package/dist/src/server/csmt/tree.js +0 -270
- package/dist/src/server/csmt/types.d.ts +0 -46
- package/dist/src/server/csmt/types.js +0 -2
- package/dist/src/server/worker.js +0 -33
- /package/dist/src/server/{worker.d.ts → workers/io_worker.d.ts} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { QueryDef, QueryDefFilter } from '../types.js';
|
|
3
3
|
import { Filter } from './types.js';
|
|
4
|
-
|
|
5
|
-
export declare const primitiveFilter: (def: QueryDef, prop: PropDef | PropDefEdge, filter: Filter, conditions: QueryDefFilter, lang: LangCode) => number;
|
|
4
|
+
export declare const primitiveFilter: (def: QueryDef, prop: PropDef | PropDefEdge, filter: Filter, conditions: QueryDefFilter, lang: QueryDef["lang"]) => number;
|
|
@@ -69,9 +69,25 @@ export const includeProp = (def, prop) => {
|
|
|
69
69
|
}
|
|
70
70
|
if (prop.typeIndex === TEXT) {
|
|
71
71
|
if (!def.include.langTextFields.has(prop.prop)) {
|
|
72
|
-
def.include.langTextFields.set(prop.prop, {
|
|
72
|
+
def.include.langTextFields.set(prop.prop, {
|
|
73
|
+
def: prop,
|
|
74
|
+
codes: new Set(),
|
|
75
|
+
fallBacks: [],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const langs = def.include.langTextFields.get(prop.prop);
|
|
79
|
+
if (def.lang.fallback.length > 0) {
|
|
80
|
+
for (const fallback of def.lang.fallback) {
|
|
81
|
+
if (!langs.fallBacks.includes(fallback)) {
|
|
82
|
+
langs.fallBacks.push(fallback);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const langCode = def.lang.lang ?? 0;
|
|
87
|
+
langs.codes.add(langCode);
|
|
88
|
+
if (langCode === 0 || langs.codes.size > 1) {
|
|
89
|
+
langs.fallBacks = [];
|
|
73
90
|
}
|
|
74
|
-
def.include.langTextFields.get(prop.prop).codes.add(def.lang ?? 0);
|
|
75
91
|
}
|
|
76
92
|
else {
|
|
77
93
|
if (prop.separate) {
|
|
@@ -56,21 +56,29 @@ export const includeToBuffer = (db, def) => {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
if (def.include.langTextFields.size) {
|
|
59
|
-
for (const [prop, { codes, def: propDef },] of def.include.langTextFields.entries()) {
|
|
59
|
+
for (const [prop, { codes, def: propDef, fallBacks },] of def.include.langTextFields.entries()) {
|
|
60
60
|
def.include.propsRead[prop] = 0;
|
|
61
61
|
if (codes.has(0)) {
|
|
62
|
-
const b = new Uint8Array(
|
|
62
|
+
const b = new Uint8Array(4);
|
|
63
63
|
b[0] = prop;
|
|
64
64
|
b[1] = propDef.typeIndex;
|
|
65
65
|
b[2] = 0;
|
|
66
|
+
b[3] = 0;
|
|
66
67
|
result.push(b);
|
|
67
68
|
}
|
|
68
69
|
else {
|
|
69
70
|
for (const code of codes) {
|
|
70
|
-
const
|
|
71
|
+
const fallBackSize = fallBacks.length;
|
|
72
|
+
const b = new Uint8Array(4 + fallBackSize);
|
|
71
73
|
b[0] = prop;
|
|
72
74
|
b[1] = propDef.typeIndex;
|
|
73
75
|
b[2] = code;
|
|
76
|
+
b[3] = fallBackSize;
|
|
77
|
+
let i = 0;
|
|
78
|
+
for (const fallback of fallBacks) {
|
|
79
|
+
b[i + 4] = fallback;
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
74
82
|
result.push(b);
|
|
75
83
|
}
|
|
76
84
|
}
|
|
@@ -55,7 +55,11 @@ export const walkDefs = (db, def, f) => {
|
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
if (!def.include.langTextFields.has(t.prop)) {
|
|
58
|
-
def.include.langTextFields.set(t.prop, {
|
|
58
|
+
def.include.langTextFields.set(t.prop, {
|
|
59
|
+
def: t,
|
|
60
|
+
codes: new Set(),
|
|
61
|
+
fallBacks: [],
|
|
62
|
+
});
|
|
59
63
|
}
|
|
60
64
|
def.include.langTextFields.get(t.prop).codes.add(langCode);
|
|
61
65
|
return;
|
|
@@ -8,7 +8,10 @@ const createEmptySharedDef = (skipValidation) => {
|
|
|
8
8
|
skipValidation,
|
|
9
9
|
filter: { conditions: new Map(), size: 0 },
|
|
10
10
|
range: { offset: 0, limit: 0 },
|
|
11
|
-
lang:
|
|
11
|
+
lang: {
|
|
12
|
+
lang: langCodesMap.get('none'),
|
|
13
|
+
fallback: [],
|
|
14
|
+
},
|
|
12
15
|
include: {
|
|
13
16
|
langTextFields: new Map(),
|
|
14
17
|
stringFields: new Set(),
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, JSON, CARDINALITY, } from '@based/schema/def';
|
|
1
|
+
import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, JSON, CARDINALITY, COLVEC, } from '@based/schema/def';
|
|
2
2
|
import { QueryDefType } from '../types.js';
|
|
3
3
|
import { read, readUtf8 } from '../../string.js';
|
|
4
4
|
import { DECODER, readDoubleLE, readFloatLE, readInt16, readInt32, readUint16, readUint32, setByPath, } from '@saulx/utils';
|
|
5
5
|
import { inverseLangMap } from '@based/schema';
|
|
6
6
|
import { READ_EDGE, READ_ID, READ_REFERENCE, READ_REFERENCES, READ_AGGREGATION, } from '../types.js';
|
|
7
|
+
import { AggregateType } from '../aggregates/types.js';
|
|
7
8
|
const readAggregate = (q, result, offset, len) => {
|
|
8
9
|
const results = {};
|
|
9
10
|
if (q.aggregate.groupBy) {
|
|
10
11
|
let i = offset;
|
|
11
12
|
while (i < len) {
|
|
12
13
|
let key = '';
|
|
14
|
+
let keyLen = 0;
|
|
13
15
|
if (result[i] == 0) {
|
|
14
16
|
if (q.aggregate.groupBy.default) {
|
|
15
17
|
key = q.aggregate.groupBy.default;
|
|
@@ -17,24 +19,50 @@ const readAggregate = (q, result, offset, len) => {
|
|
|
17
19
|
else {
|
|
18
20
|
key = `$undefined`;
|
|
19
21
|
}
|
|
22
|
+
i += 2;
|
|
20
23
|
}
|
|
21
24
|
else {
|
|
22
|
-
|
|
25
|
+
if (q.aggregate.groupBy.typeIndex == ENUM) {
|
|
26
|
+
i += 2;
|
|
27
|
+
key = q.aggregate.groupBy.enum[result[i] - 1];
|
|
28
|
+
i++;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
keyLen = readUint16(result, i);
|
|
32
|
+
i += 2;
|
|
33
|
+
key = DECODER.decode(result.subarray(i, i + keyLen));
|
|
34
|
+
i += keyLen;
|
|
35
|
+
}
|
|
23
36
|
}
|
|
24
|
-
i += 2;
|
|
25
37
|
const resultKey = (results[key] = {});
|
|
26
38
|
for (const aggregatesArray of q.aggregate.aggregates.values()) {
|
|
27
39
|
for (const agg of aggregatesArray) {
|
|
28
|
-
|
|
40
|
+
var val = undefined;
|
|
41
|
+
if (agg.type === AggregateType.CARDINALITY ||
|
|
42
|
+
agg.type === AggregateType.COUNT) {
|
|
43
|
+
val = readUint32(result, agg.resultPos + i);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
val = readDoubleLE(result, agg.resultPos + i);
|
|
47
|
+
}
|
|
48
|
+
setByPath(resultKey, agg.propDef.path, val);
|
|
29
49
|
}
|
|
30
50
|
}
|
|
31
|
-
i += q.aggregate.
|
|
51
|
+
i += q.aggregate.totalResultsSize;
|
|
32
52
|
}
|
|
33
53
|
}
|
|
34
54
|
else {
|
|
35
55
|
for (const aggregatesArray of q.aggregate.aggregates.values()) {
|
|
36
56
|
for (const agg of aggregatesArray) {
|
|
37
|
-
|
|
57
|
+
var val = undefined;
|
|
58
|
+
if (agg.type === AggregateType.CARDINALITY ||
|
|
59
|
+
agg.type === AggregateType.COUNT) {
|
|
60
|
+
val = readUint32(result, agg.resultPos + offset);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
val = readDoubleLE(result, agg.resultPos + offset);
|
|
64
|
+
}
|
|
65
|
+
setByPath(results, agg.propDef.path, val);
|
|
38
66
|
}
|
|
39
67
|
}
|
|
40
68
|
}
|
|
@@ -168,13 +196,13 @@ const handleUndefinedProps = (id, q, item) => {
|
|
|
168
196
|
if (prop.typeIndex === CARDINALITY) {
|
|
169
197
|
addField(prop, 0, item);
|
|
170
198
|
}
|
|
171
|
-
else if (prop.typeIndex === TEXT && q.lang == 0) {
|
|
199
|
+
else if (prop.typeIndex === TEXT && q.lang.lang == 0) {
|
|
172
200
|
const lan = getEmptyField(prop, item);
|
|
173
201
|
const lang = q.include.langTextFields.get(prop.prop).codes;
|
|
174
202
|
if (lang.has(0)) {
|
|
175
203
|
for (const locale in q.schema.locales) {
|
|
176
204
|
if (lan[locale] == undefined) {
|
|
177
|
-
lan[locale] =
|
|
205
|
+
lan[locale] = '';
|
|
178
206
|
}
|
|
179
207
|
}
|
|
180
208
|
}
|
|
@@ -182,23 +210,26 @@ const handleUndefinedProps = (id, q, item) => {
|
|
|
182
210
|
for (const code of lang) {
|
|
183
211
|
const locale = inverseLangMap.get(code);
|
|
184
212
|
if (!lan[locale]) {
|
|
185
|
-
lan[locale] =
|
|
213
|
+
lan[locale] = '';
|
|
186
214
|
}
|
|
187
215
|
}
|
|
188
216
|
}
|
|
189
217
|
}
|
|
190
|
-
else if (prop.typeIndex === BINARY) {
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
else if (prop.typeIndex === TEXT
|
|
218
|
+
// else if (prop.typeIndex === BINARY) {
|
|
219
|
+
// addField(prop, prop.default, item)
|
|
220
|
+
// }
|
|
221
|
+
else if (prop.typeIndex === TEXT ||
|
|
222
|
+
prop.typeIndex === STRING ||
|
|
223
|
+
prop.typeIndex === ALIAS) {
|
|
194
224
|
addField(prop, '', item);
|
|
195
225
|
}
|
|
196
|
-
else {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
226
|
+
// else if (prop.typeIndex === JSON) {
|
|
227
|
+
// // addField(prop, null, item)
|
|
228
|
+
// } else {
|
|
229
|
+
// // if (prop.default !== undefined) {
|
|
230
|
+
// // addField(prop, '', item)
|
|
231
|
+
// // }
|
|
232
|
+
// }
|
|
202
233
|
}
|
|
203
234
|
}
|
|
204
235
|
};
|
|
@@ -376,7 +407,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
|
|
|
376
407
|
// do nothing
|
|
377
408
|
}
|
|
378
409
|
else {
|
|
379
|
-
if (q.lang != 0) {
|
|
410
|
+
if (q.lang.lang != 0) {
|
|
380
411
|
q.include.propsRead[index] = id;
|
|
381
412
|
addField(prop, read(result, i + 4, size, true), item);
|
|
382
413
|
}
|
|
@@ -399,7 +430,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
|
|
|
399
430
|
addField(prop, string, item);
|
|
400
431
|
}
|
|
401
432
|
}
|
|
402
|
-
else if (prop.typeIndex == VECTOR) {
|
|
433
|
+
else if (prop.typeIndex == VECTOR || prop.typeIndex == COLVEC) {
|
|
403
434
|
q.include.propsRead[index] = id;
|
|
404
435
|
const size = readUint32(result, i);
|
|
405
436
|
const arr = new Float32Array(size / 4);
|
|
@@ -414,7 +445,6 @@ export const readAllFields = (q, result, offset, end, item, id) => {
|
|
|
414
445
|
handleUndefinedProps(id, q, item);
|
|
415
446
|
return i - offset;
|
|
416
447
|
};
|
|
417
|
-
let cnt = 0;
|
|
418
448
|
export const resultToObject = (q, result, end, offset = 0) => {
|
|
419
449
|
if (q.aggregate) {
|
|
420
450
|
return readAggregate(q, result, 0, result.byteLength - 4);
|
|
@@ -5,4 +5,4 @@ export type Search = string[] | {
|
|
|
5
5
|
} | string;
|
|
6
6
|
export declare const vectorSearch: (def: QueryDef, q: ArrayBufferView, field: string, opts: Omit<FilterOpts, "lowerCase">) => void;
|
|
7
7
|
export declare const search: (def: QueryDef, q: string, s?: Search) => void;
|
|
8
|
-
export declare const searchToBuffer: (search: QueryDefSearch) => Uint8Array
|
|
8
|
+
export declare const searchToBuffer: (search: QueryDefSearch) => Uint8Array<ArrayBuffer>;
|
|
@@ -74,14 +74,16 @@ export const search = (def, q, s) => {
|
|
|
74
74
|
}
|
|
75
75
|
for (const key in s) {
|
|
76
76
|
let prop = def.props[key];
|
|
77
|
-
let lang = def.lang;
|
|
77
|
+
let lang = def.lang.lang;
|
|
78
|
+
let fallback = def.lang.fallback;
|
|
78
79
|
if (!prop) {
|
|
79
80
|
if (key.includes('.')) {
|
|
80
81
|
const k = key.split('.');
|
|
81
82
|
prop = def.props[k.slice(0, -1).join('.')];
|
|
82
83
|
if (prop && prop.typeIndex === TEXT) {
|
|
83
84
|
lang = langCodesMap.get(k[k.length - 1]);
|
|
84
|
-
|
|
85
|
+
fallback = [];
|
|
86
|
+
// handle incorrect LANG
|
|
85
87
|
}
|
|
86
88
|
else {
|
|
87
89
|
prop = searchDoesNotExist(def, key, false);
|
|
@@ -94,11 +96,16 @@ export const search = (def, q, s) => {
|
|
|
94
96
|
if (prop.typeIndex !== STRING && prop.typeIndex !== TEXT) {
|
|
95
97
|
searchIncorrectType(def, prop);
|
|
96
98
|
}
|
|
97
|
-
def.search.size +=
|
|
99
|
+
def.search.size += 10;
|
|
100
|
+
if (fallback.length > 3) {
|
|
101
|
+
// Max 4 lang fallback size (tmp)
|
|
102
|
+
console.warn('Search has a max of 4 lang fallbacks!');
|
|
103
|
+
fallback = fallback.slice(0, 3);
|
|
104
|
+
}
|
|
98
105
|
def.search.fields.push({
|
|
99
106
|
typeIndex: prop.typeIndex,
|
|
100
107
|
weight: s[key],
|
|
101
|
-
lang,
|
|
108
|
+
lang: { lang, fallback },
|
|
102
109
|
field: prop.prop,
|
|
103
110
|
start: prop.start ?? 0, // also need lang ofc if you have start
|
|
104
111
|
});
|
|
@@ -147,6 +154,8 @@ export const searchToBuffer = (search) => {
|
|
|
147
154
|
| 2 | weight | 1 | Field weight value |
|
|
148
155
|
| 3 | start | 2 | Start position in the query (u16) |
|
|
149
156
|
| 5 | lang | 1 | Language identifier |
|
|
157
|
+
| 6 | fallbackL | 1 | Language fallback size |
|
|
158
|
+
| 7 | fallback | 3 | Language fallback |
|
|
150
159
|
|
|
151
160
|
### Notes:
|
|
152
161
|
- The number of field entries is inferred from the total packet size.
|
|
@@ -162,15 +171,20 @@ export const searchToBuffer = (search) => {
|
|
|
162
171
|
return a.weight - b.weight;
|
|
163
172
|
});
|
|
164
173
|
// @ts-ignore
|
|
165
|
-
for (let i = 0; i < search.fields.length *
|
|
174
|
+
for (let i = 0; i < search.fields.length * 10; i += 10) {
|
|
166
175
|
// @ts-ignore
|
|
167
|
-
const f = search.fields[Math.floor(i /
|
|
176
|
+
const f = search.fields[Math.floor(i / 10)];
|
|
168
177
|
result[i + offset] = f.field;
|
|
169
178
|
result[i + offset + 1] = f.typeIndex;
|
|
170
179
|
result[i + offset + 2] = f.weight;
|
|
171
180
|
result[i + offset + 3] = f.start;
|
|
172
181
|
result[i + offset + 4] = f.start >>> 8;
|
|
173
|
-
|
|
182
|
+
// fallback
|
|
183
|
+
result[i + offset + 5] = f.lang.lang;
|
|
184
|
+
result[i + offset + 6] = f.lang.fallback.length;
|
|
185
|
+
for (let j = 0; j < f.lang.fallback.length; j++) {
|
|
186
|
+
result[i + j + offset + 7] = f.lang.fallback[j];
|
|
187
|
+
}
|
|
174
188
|
}
|
|
175
189
|
return result;
|
|
176
190
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { QueryDef, QueryDefSort } from './types.js';
|
|
2
|
-
export declare const createSortBuffer: (sort: QueryDefSort) => Uint8Array
|
|
2
|
+
export declare const createSortBuffer: (sort: QueryDefSort) => Uint8Array<ArrayBuffer>;
|
|
3
3
|
export declare const sort: (def: QueryDef, field: string, order?: "asc" | "desc") => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { QueryDef } from '../types.js';
|
|
2
|
-
export declare const defaultQuery: (def: QueryDef, filterSize: number, sortSize: number, searchSize: number, sort: Uint8Array, search: Uint8Array) => Uint8Array
|
|
2
|
+
export declare const defaultQuery: (def: QueryDef, filterSize: number, sortSize: number, searchSize: number, sort: Uint8Array, search: Uint8Array) => Uint8Array<ArrayBuffer>;
|
|
@@ -17,8 +17,6 @@ export const defaultQuery = (def, filterSize, sortSize, searchSize, sort, search
|
|
|
17
17
|
buf[index++] = filterSize;
|
|
18
18
|
buf[index++] = filterSize >>> 8;
|
|
19
19
|
buf[index++] = filterSize && isSimpleMainFilter(def.filter) ? 1 : 0;
|
|
20
|
-
// if (filterSize && isSimpleMainFilter(def.filter)) {
|
|
21
|
-
// console.log('SIMPLE FILTER!')
|
|
22
20
|
if (filterSize) {
|
|
23
21
|
buf.set(filterToBuffer(def.filter), index);
|
|
24
22
|
index += filterSize;
|
|
@@ -14,7 +14,6 @@ const byteSize = (arr) => {
|
|
|
14
14
|
export function defToBuffer(db, def) {
|
|
15
15
|
const result = [];
|
|
16
16
|
const include = includeToBuffer(db, def);
|
|
17
|
-
// ---------------------------------------
|
|
18
17
|
def.references.forEach((ref) => {
|
|
19
18
|
include.push(...defToBuffer(db, ref));
|
|
20
19
|
if (ref.errors) {
|
|
@@ -46,7 +45,6 @@ export function defToBuffer(db, def) {
|
|
|
46
45
|
buf[0] = 251 /* includeOp.REFERENCES_AGGREGATION */;
|
|
47
46
|
buf[1] = sz;
|
|
48
47
|
buf[2] = sz >>> 8;
|
|
49
|
-
// ---
|
|
50
48
|
buf[3] = filterSize;
|
|
51
49
|
buf[4] = filterSize >>> 8;
|
|
52
50
|
buf[5] = def.range.offset;
|
|
@@ -62,8 +60,6 @@ export function defToBuffer(db, def) {
|
|
|
62
60
|
buf[9 + 2 + filterSize] = def.target.propDef.prop; // refField
|
|
63
61
|
const aggregateBuffer = aggregateToBuffer(def.aggregate);
|
|
64
62
|
buf.set(aggregateBuffer, 9 + 3 + filterSize);
|
|
65
|
-
// buf[12 + filterSize] = aggregateSize
|
|
66
|
-
// buf[12 + 1 + filterSize] = aggregateSize >>> 8
|
|
67
63
|
result.push(buf);
|
|
68
64
|
}
|
|
69
65
|
else {
|
|
@@ -92,8 +88,6 @@ export function defToBuffer(db, def) {
|
|
|
92
88
|
buf.set(aggregateBuffer, 16 + filterSize);
|
|
93
89
|
result.push(buf);
|
|
94
90
|
}
|
|
95
|
-
// ignore this for now...
|
|
96
|
-
// result.push(...include)
|
|
97
91
|
if (def.type === QueryDefType.Root) {
|
|
98
92
|
const checksum = new Uint8Array(8);
|
|
99
93
|
writeUint64(checksum, def.schemaChecksum ?? 0, 0);
|
|
@@ -175,7 +169,6 @@ export function defToBuffer(db, def) {
|
|
|
175
169
|
buf[idsSize + 13] = def.range.limit >>> 16;
|
|
176
170
|
buf[idsSize + 14] = def.range.limit >>> 24;
|
|
177
171
|
// if (filterSize && isSimpleMainFilter(def.filter)) {
|
|
178
|
-
// console.log('SIMPLE FILTER!')
|
|
179
172
|
buf[idsSize + 15] = filterSize;
|
|
180
173
|
buf[idsSize + 16] = filterSize >>> 8;
|
|
181
174
|
if (filterSize) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LangCode } from '@based/schema';
|
|
1
|
+
import { LangCode, LangName } from '@based/schema';
|
|
2
2
|
import { PropDef, PropDefEdge, SchemaTypeDef } from '@based/schema/def';
|
|
3
3
|
import { FilterOpts } from './filter/types.js';
|
|
4
4
|
import { QueryError } from './validation.js';
|
|
@@ -59,7 +59,10 @@ export type QueryDefSearch = {
|
|
|
59
59
|
weight: number;
|
|
60
60
|
field: number;
|
|
61
61
|
start: number;
|
|
62
|
-
lang:
|
|
62
|
+
lang: {
|
|
63
|
+
lang: LangCode;
|
|
64
|
+
fallback: LangCode[];
|
|
65
|
+
};
|
|
63
66
|
typeIndex: number;
|
|
64
67
|
}[];
|
|
65
68
|
} | {
|
|
@@ -78,17 +81,23 @@ export type Aggregation = {
|
|
|
78
81
|
type: AggregateType;
|
|
79
82
|
propDef: PropDef;
|
|
80
83
|
resultPos: number;
|
|
84
|
+
accumulatorPos: number;
|
|
81
85
|
};
|
|
82
86
|
export type QueryDefAggregation = {
|
|
83
87
|
size: number;
|
|
84
88
|
groupBy?: PropDef;
|
|
85
89
|
aggregates: Map<number, Aggregation[]>;
|
|
86
|
-
|
|
90
|
+
totalResultsSize: number;
|
|
91
|
+
totalAccumulatorSize: number;
|
|
87
92
|
};
|
|
93
|
+
export type LangFallback = LangName | false;
|
|
88
94
|
export type QueryDefShared = {
|
|
89
95
|
schemaChecksum?: number;
|
|
90
96
|
errors: QueryError[];
|
|
91
|
-
lang:
|
|
97
|
+
lang: {
|
|
98
|
+
lang: LangCode;
|
|
99
|
+
fallback: LangCode[];
|
|
100
|
+
};
|
|
92
101
|
filter: QueryDefFilter;
|
|
93
102
|
aggregate: null | QueryDefAggregation;
|
|
94
103
|
search: null | QueryDefSearch;
|
|
@@ -99,9 +108,11 @@ export type QueryDefShared = {
|
|
|
99
108
|
limit: number;
|
|
100
109
|
};
|
|
101
110
|
include: {
|
|
102
|
-
langTextFields: Map<number,
|
|
111
|
+
langTextFields: Map<number, // prop name
|
|
112
|
+
{
|
|
103
113
|
def: PropDef | PropDefEdge;
|
|
104
114
|
codes: Set<LangCode>;
|
|
115
|
+
fallBacks: LangCode[];
|
|
105
116
|
}>;
|
|
106
117
|
stringFields: Set<string>;
|
|
107
118
|
props: Map<number, PropDef | PropDefEdge>;
|
|
@@ -31,6 +31,7 @@ export declare const ERR_SEARCH_TYPE = 22;
|
|
|
31
31
|
export declare const ERR_SEARCH_INCORRECT_VALUE = 23;
|
|
32
32
|
export declare const ERR_SORT_LANG = 24;
|
|
33
33
|
export declare const ERR_AGG_ENOENT = 25;
|
|
34
|
+
export declare const ERR_AGG_TYPE = 26;
|
|
34
35
|
declare const messages: {
|
|
35
36
|
1: (p: any) => string;
|
|
36
37
|
2: (p: any) => string;
|
|
@@ -57,6 +58,7 @@ declare const messages: {
|
|
|
57
58
|
23: (p: any) => string;
|
|
58
59
|
24: (p: any) => string;
|
|
59
60
|
25: (p: any) => string;
|
|
61
|
+
26: (p: any) => string;
|
|
60
62
|
};
|
|
61
63
|
export type ErrorCode = keyof typeof messages;
|
|
62
64
|
export declare const searchIncorrecQueryValue: (def: QueryDef, payload: any) => void;
|
|
@@ -85,4 +87,5 @@ export declare const ERROR_STRING: PropDef;
|
|
|
85
87
|
export declare const ERROR_VECTOR: PropDef;
|
|
86
88
|
export declare const EMPTY_SCHEMA_DEF: SchemaTypeDef;
|
|
87
89
|
export declare const aggregationFieldDoesNotExist: (def: QueryDef, field: string) => void;
|
|
90
|
+
export declare const aggregationFieldNotNumber: (def: QueryDef, field: string) => void;
|
|
88
91
|
export {};
|
|
@@ -29,6 +29,7 @@ export const ERR_SEARCH_TYPE = 22;
|
|
|
29
29
|
export const ERR_SEARCH_INCORRECT_VALUE = 23;
|
|
30
30
|
export const ERR_SORT_LANG = 24;
|
|
31
31
|
export const ERR_AGG_ENOENT = 25;
|
|
32
|
+
export const ERR_AGG_TYPE = 26;
|
|
32
33
|
const messages = {
|
|
33
34
|
[ERR_TARGET_INVAL_TYPE]: (p) => `Type "${p}" does not exist`,
|
|
34
35
|
[ERR_TARGET_INVAL_ALIAS]: (p) => {
|
|
@@ -61,6 +62,7 @@ const messages = {
|
|
|
61
62
|
[ERR_SEARCH_INCORRECT_VALUE]: (p) => `Search: incorrect query on field "${safeStringify(p)}"`,
|
|
62
63
|
[ERR_SORT_LANG]: (p) => `Sort: invalid lang`,
|
|
63
64
|
[ERR_AGG_ENOENT]: (p) => `Field \"${p}\" in the aggregate function is invalid or unreacheable.`,
|
|
65
|
+
[ERR_AGG_TYPE]: (p) => `Aggregate: incorrect type "${p.path.join('.')}"`,
|
|
64
66
|
};
|
|
65
67
|
export const searchIncorrecQueryValue = (def, payload) => {
|
|
66
68
|
def.errors.push({ code: ERR_SEARCH_INCORRECT_VALUE, payload });
|
|
@@ -137,6 +139,28 @@ export const validateFilter = (def, prop, f) => {
|
|
|
137
139
|
});
|
|
138
140
|
return true;
|
|
139
141
|
}
|
|
142
|
+
// map { id: } format for filter
|
|
143
|
+
const values = f[2];
|
|
144
|
+
if (Array.isArray(values)) {
|
|
145
|
+
let hasObject = false;
|
|
146
|
+
for (const v of values) {
|
|
147
|
+
if (typeof v === 'object' && 'id' in v) {
|
|
148
|
+
hasObject = true;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (hasObject) {
|
|
153
|
+
f[2] = values.map((v) => {
|
|
154
|
+
if (typeof v === 'object' && 'id' in v) {
|
|
155
|
+
return v.id;
|
|
156
|
+
}
|
|
157
|
+
return v;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (typeof values === 'object' && 'id' in values) {
|
|
162
|
+
f[2] = values.id;
|
|
163
|
+
}
|
|
140
164
|
if (validateVal(def, f, prop.validation)) {
|
|
141
165
|
return true;
|
|
142
166
|
}
|
|
@@ -272,7 +296,7 @@ export const validateSort = (def, field, orderInput) => {
|
|
|
272
296
|
return {
|
|
273
297
|
prop: EMPTY_ALIAS_PROP_DEF,
|
|
274
298
|
order,
|
|
275
|
-
lang: def.lang,
|
|
299
|
+
lang: def.lang?.lang,
|
|
276
300
|
};
|
|
277
301
|
}
|
|
278
302
|
}
|
|
@@ -285,7 +309,7 @@ export const validateSort = (def, field, orderInput) => {
|
|
|
285
309
|
}
|
|
286
310
|
else if (type === TEXT) {
|
|
287
311
|
if (lang === 0) {
|
|
288
|
-
lang = def.lang ?? 0;
|
|
312
|
+
lang = def.lang?.lang ?? 0;
|
|
289
313
|
if (lang === 0) {
|
|
290
314
|
def.errors.push({
|
|
291
315
|
code: ERR_SORT_LANG,
|
|
@@ -443,6 +467,7 @@ export const EMPTY_SCHEMA_DEF = {
|
|
|
443
467
|
propNames: new Uint8Array([]),
|
|
444
468
|
idUint8: new Uint8Array([0, 0]),
|
|
445
469
|
mainEmptyAllZeroes: true,
|
|
470
|
+
hasSeperateDefaults: false,
|
|
446
471
|
};
|
|
447
472
|
export const aggregationFieldDoesNotExist = (def, field) => {
|
|
448
473
|
def.errors.push({
|
|
@@ -451,4 +476,11 @@ export const aggregationFieldDoesNotExist = (def, field) => {
|
|
|
451
476
|
});
|
|
452
477
|
handleErrors(def);
|
|
453
478
|
};
|
|
479
|
+
export const aggregationFieldNotNumber = (def, field) => {
|
|
480
|
+
def.errors.push({
|
|
481
|
+
code: ERR_AGG_TYPE,
|
|
482
|
+
payload: field,
|
|
483
|
+
});
|
|
484
|
+
handleErrors(def);
|
|
485
|
+
};
|
|
454
486
|
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const xxHash64: (buf: Uint8Array, target?: Uint8Array, index?: number) => Uint8Array
|
|
1
|
+
export declare const xxHash64: (buf: Uint8Array, target?: Uint8Array, index?: number) => Uint8Array<ArrayBufferLike>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -12,14 +12,13 @@ export { DbClient, DbServer };
|
|
|
12
12
|
export { xxHash64 } from './client/xxHash64.js';
|
|
13
13
|
export { crc32 } from './client/crc32.js';
|
|
14
14
|
export { default as createHash } from './server/dbHash.js';
|
|
15
|
-
export * from './client/query/serialize.js';
|
|
16
15
|
export * from './utils.js';
|
|
17
16
|
export * from './client/query/query.js';
|
|
18
17
|
export * from './client/query/BasedDbQuery.js';
|
|
19
18
|
export * from './client/query/BasedIterable.js';
|
|
20
19
|
export * from './server/save.js';
|
|
21
20
|
export * from './hooks.js';
|
|
22
|
-
export { getDefaultHooks };
|
|
21
|
+
export { getDefaultHooks, BasedDbOpts };
|
|
23
22
|
export declare class BasedDb extends Emitter {
|
|
24
23
|
client: DbClient;
|
|
25
24
|
server: DbServer;
|
package/dist/src/index.js
CHANGED
|
@@ -13,7 +13,6 @@ export { DbClient, DbServer };
|
|
|
13
13
|
export { xxHash64 } from './client/xxHash64.js';
|
|
14
14
|
export { crc32 } from './client/crc32.js';
|
|
15
15
|
export { default as createHash } from './server/dbHash.js';
|
|
16
|
-
export * from './client/query/serialize.js';
|
|
17
16
|
export * from './utils.js';
|
|
18
17
|
export * from './client/query/query.js';
|
|
19
18
|
export * from './client/query/BasedDbQuery.js';
|
package/dist/src/native.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
declare const native: {
|
|
2
|
-
|
|
3
|
-
historyCreate(pathname: string, mainLen: number): any;
|
|
2
|
+
threadCtx: any;
|
|
4
3
|
workerCtxInit: () => void;
|
|
5
4
|
externalFromInt(address: BigInt): any;
|
|
6
5
|
intFromExternal(external: any): BigInt;
|
|
@@ -9,9 +8,10 @@ declare const native: {
|
|
|
9
8
|
start: () => any;
|
|
10
9
|
stop: (dbCtx: any) => any;
|
|
11
10
|
saveCommon: (path: string, dbCtx: any) => number;
|
|
12
|
-
|
|
11
|
+
saveBlock: (path: string, typeCode: number, start: number, dbCtx: any, hashOut: Uint8Array) => number;
|
|
13
12
|
loadCommon: (path: string, dbCtx: any) => void;
|
|
14
|
-
|
|
13
|
+
loadBlock: (path: string, dbCtx: any) => void;
|
|
14
|
+
delBlock: (dbCtx: any, typeId: number, block: number) => void;
|
|
15
15
|
updateSchemaType: (prefix: number, buf: Uint8Array, dbCtx: any) => any;
|
|
16
16
|
getTypeInfo: (typeId: number, dbCtx: any) => any;
|
|
17
17
|
getNodeRangeHash: (typeId: number, start: number, end: number, bufOut: Uint8Array, dbCtx: any) => any;
|
|
@@ -22,5 +22,8 @@ declare const native: {
|
|
|
22
22
|
destroySortIndex: (buf: Uint8Array, dbCtx: any) => any;
|
|
23
23
|
xxHash64: (buf: Uint8Array, target: Uint8Array, index: number) => any;
|
|
24
24
|
equals: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
25
|
+
membarSyncRead: () => void;
|
|
26
|
+
membarSyncWrite: () => void;
|
|
27
|
+
colvecTest: (dbCtx: any, typeId: number, field: number, nodeId: number, len: number) => any;
|
|
25
28
|
};
|
|
26
29
|
export default native;
|