@based/db 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/darwin_aarch64/include/cdefs.h +4 -0
- package/dist/lib/darwin_aarch64/include/selva/db.h +25 -5
- package/dist/lib/darwin_aarch64/include/selva/fields.h +34 -72
- package/dist/lib/darwin_aarch64/include/selva/selva_lang.h +7 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +9 -13
- package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
- package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v25.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/cdefs.h +4 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +25 -5
- package/dist/lib/linux_aarch64/include/selva/fields.h +34 -72
- package/dist/lib/linux_aarch64/include/selva/selva_lang.h +7 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +9 -13
- package/dist/lib/linux_aarch64/libdeflate.so +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v25.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/cdefs.h +4 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +25 -5
- package/dist/lib/linux_x86_64/include/selva/fields.h +34 -72
- package/dist/lib/linux_x86_64/include/selva/selva_lang.h +7 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +9 -13
- package/dist/lib/linux_x86_64/libdeflate.so +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v25.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/modify/Tmp.d.ts +0 -1
- package/dist/src/client/modify/Tmp.js +14 -9
- package/dist/src/client/modify/create/index.js +6 -5
- package/dist/src/client/modify/drain.js +6 -2
- package/dist/src/client/modify/edges/binary.js +3 -2
- package/dist/src/client/modify/edges/reference.js +2 -3
- package/dist/src/client/modify/edges/references.js +2 -3
- package/dist/src/client/modify/edges/separate.js +4 -1
- package/dist/src/client/modify/edges/string.js +2 -3
- package/dist/src/client/modify/error.d.ts +29 -0
- package/dist/src/client/modify/error.js +10 -0
- package/dist/src/client/modify/props/alias.js +1 -1
- package/dist/src/client/modify/props/binary.js +1 -1
- package/dist/src/client/modify/props/cardinality.js +1 -1
- package/dist/src/client/modify/props/fixed.js +13 -14
- package/dist/src/client/modify/props/reference.js +2 -2
- package/dist/src/client/modify/props/references.js +7 -7
- package/dist/src/client/modify/props/string.js +1 -1
- package/dist/src/client/modify/props/vector.js +1 -11
- package/dist/src/client/modify/types.d.ts +1 -0
- package/dist/src/client/modify/types.js +1 -0
- package/dist/src/client/modify/validate.d.ts +1 -1
- package/dist/src/client/modify/validate.js +4 -3
- package/dist/src/client/query/BasedDbQuery.d.ts +4 -4
- package/dist/src/client/query/BasedDbQuery.js +23 -12
- package/dist/src/client/query/BasedQueryResponse.d.ts +0 -1
- package/dist/src/client/query/BasedQueryResponse.js +0 -3
- package/dist/src/client/query/aggregates/aggregation.d.ts +1 -1
- package/dist/src/client/query/aggregates/aggregation.js +123 -51
- package/dist/src/client/query/display.js +14 -8
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +59 -22
- package/dist/src/client/query/filter/createReferenceFilter.js +13 -13
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +6 -3
- package/dist/src/client/query/filter/filter.js +8 -0
- package/dist/src/client/query/filter/primitiveFilter.js +4 -1
- package/dist/src/client/query/filter/{toBuffer.d.ts → toByteCode.d.ts} +3 -2
- package/dist/src/client/query/filter/{toBuffer.js → toByteCode.js} +46 -12
- package/dist/src/client/query/filter/types.d.ts +1 -0
- package/dist/src/client/query/filter/types.js +33 -5
- package/dist/src/client/query/include/toByteCode.d.ts +2 -2
- package/dist/src/client/query/include/toByteCode.js +1 -1
- package/dist/src/client/query/query.d.ts +1 -1
- package/dist/src/client/query/query.js +1 -1
- package/dist/src/client/query/queryDef.js +6 -2
- package/dist/src/client/query/registerQuery.js +5 -9
- package/dist/src/client/query/subscription/index.js +5 -0
- package/dist/src/client/query/subscription/toByteCode.d.ts +6 -0
- package/dist/src/client/query/subscription/toByteCode.js +139 -0
- package/dist/src/client/query/subscription/types.d.ts +6 -0
- package/dist/src/client/query/subscription/types.js +7 -9
- package/dist/src/client/query/toByteCode/aggregates.d.ts +2 -0
- package/dist/src/client/query/toByteCode/aggregates.js +60 -0
- package/dist/src/client/query/toByteCode/alias.d.ts +2 -0
- package/dist/src/client/query/toByteCode/alias.js +24 -0
- package/dist/src/client/query/toByteCode/default.d.ts +2 -2
- package/dist/src/client/query/toByteCode/default.js +21 -24
- package/dist/src/client/query/toByteCode/id.d.ts +2 -0
- package/dist/src/client/query/toByteCode/id.js +17 -0
- package/dist/src/client/query/toByteCode/ids.d.ts +2 -0
- package/dist/src/client/query/toByteCode/ids.js +52 -0
- package/dist/src/client/query/toByteCode/offsets.d.ts +35 -0
- package/dist/src/client/query/toByteCode/offsets.js +36 -0
- package/dist/src/client/query/toByteCode/reference.d.ts +2 -0
- package/dist/src/client/query/toByteCode/reference.js +12 -0
- package/dist/src/client/query/toByteCode/references.d.ts +2 -0
- package/dist/src/client/query/toByteCode/references.js +35 -0
- package/dist/src/client/query/toByteCode/toByteCode.d.ts +4 -2
- package/dist/src/client/query/toByteCode/toByteCode.js +62 -189
- package/dist/src/client/query/types.d.ts +24 -5
- package/dist/src/client/query/validation.d.ts +5 -1
- package/dist/src/client/query/validation.js +15 -3
- package/dist/src/client/string.js +1 -1
- package/dist/src/hooks.js +2 -29
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/native.d.ts +8 -1
- package/dist/src/native.js +23 -2
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/index.js +11 -2
- package/dist/src/server/migrate/worker.js +87 -84
- package/dist/src/server/schema.js +3 -2
- package/dist/src/server/schemaSelvaBuffer.d.ts +4 -0
- package/dist/src/server/schemaSelvaBuffer.js +182 -0
- package/dist/src/server/subscription.d.ts +32 -0
- package/dist/src/server/subscription.js +275 -0
- package/dist/src/utils.js +2 -3
- package/package.json +5 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import picocolors from 'picocolors';
|
|
2
|
-
import { BINARY, CARDINALITY, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, } from '@based/schema/def';
|
|
2
|
+
import { ALIAS, BINARY, CARDINALITY, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, } from '@based/schema/def';
|
|
3
3
|
import { ENCODER } from '@based/utils';
|
|
4
4
|
const decimals = (v) => ~~(v * 100) / 100;
|
|
5
5
|
const sizeCalc = (size) => {
|
|
@@ -53,7 +53,7 @@ export const prettyPrintVal = (v, type) => {
|
|
|
53
53
|
(isLarger ? picocolors.dim('... ') : '') +
|
|
54
54
|
picocolors.italic(picocolors.dim(`${~~((v.byteLength / 1e3) * 100) / 100}kb`)));
|
|
55
55
|
}
|
|
56
|
-
if (type === STRING || type === TEXT) {
|
|
56
|
+
if (type === STRING || type === TEXT || type === ALIAS) {
|
|
57
57
|
if (v.length > 50) {
|
|
58
58
|
const byteLength = ENCODER.encode(v).byteLength;
|
|
59
59
|
const chars = picocolors.italic(picocolors.dim(`${~~((byteLength / 1e3) * 100) / 100}kb`));
|
|
@@ -62,11 +62,11 @@ export const prettyPrintVal = (v, type) => {
|
|
|
62
62
|
picocolors.dim('...') +
|
|
63
63
|
'" ' +
|
|
64
64
|
chars;
|
|
65
|
-
return `"${v}`;
|
|
66
65
|
}
|
|
67
|
-
|
|
68
|
-
return `"${v}"`;
|
|
66
|
+
if (type === ALIAS) {
|
|
67
|
+
return `"${v}" ${picocolors.italic(picocolors.dim('alias'))}`;
|
|
69
68
|
}
|
|
69
|
+
return `"${v}"`;
|
|
70
70
|
}
|
|
71
71
|
if (type === CARDINALITY) {
|
|
72
72
|
return `${picocolors.blue(v)} ${picocolors.italic(picocolors.dim('unique'))}`;
|
|
@@ -216,14 +216,20 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
|
|
|
216
216
|
str += prettyPrintVal(v, def.typeIndex);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
else if (def.typeIndex === STRING) {
|
|
219
|
+
else if (def.typeIndex === STRING || def.typeIndex === ALIAS) {
|
|
220
220
|
if (v === undefined) {
|
|
221
221
|
return '';
|
|
222
222
|
}
|
|
223
223
|
str += prettyPrintVal(v, def.typeIndex);
|
|
224
224
|
}
|
|
225
225
|
else if (def.typeIndex === CARDINALITY) {
|
|
226
|
-
|
|
226
|
+
if (typeof v === 'object' && v !== null) {
|
|
227
|
+
str +=
|
|
228
|
+
inspectObject(v, q, key, level + 2, false, false, true, depth) + '';
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
str += prettyPrintVal(v, def.typeIndex);
|
|
232
|
+
}
|
|
227
233
|
}
|
|
228
234
|
else if (def.typeIndex === TIMESTAMP) {
|
|
229
235
|
str += prettyPrintVal(v, def.typeIndex);
|
|
@@ -336,7 +342,7 @@ export const inspectData = (q, def, level, top, depth, hasId = false) => {
|
|
|
336
342
|
str += '\n' + prefix + ']';
|
|
337
343
|
}
|
|
338
344
|
else {
|
|
339
|
-
str += ']';
|
|
345
|
+
str += ']' + '\n';
|
|
340
346
|
}
|
|
341
347
|
return str;
|
|
342
348
|
};
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { BINARY, STRING, REFERENCES, TIMESTAMP, } from '@based/schema/def';
|
|
2
|
-
import { ALIGNMENT_NOT_SET, EQUAL, MODE_AND_FIXED, MODE_DEFAULT, MODE_OR_FIXED, } from './types.js';
|
|
2
|
+
import { ALIGNMENT_NOT_SET, EQUAL, isNumerical, MODE_AND_FIXED, MODE_DEFAULT, MODE_OR_FIXED, } from './types.js';
|
|
3
3
|
import { parseFilterValue } from './parseFilterValue.js';
|
|
4
4
|
import { ENCODER, writeDoubleLE, writeInt64, writeUint16, writeUint32, } from '@based/utils';
|
|
5
|
+
const isNowQuery = (prop, value, ctx) => {
|
|
6
|
+
return (prop.typeIndex === TIMESTAMP &&
|
|
7
|
+
typeof value === 'string' &&
|
|
8
|
+
value.includes('now') &&
|
|
9
|
+
isNumerical(ctx.operation));
|
|
10
|
+
};
|
|
11
|
+
const createNowMeta = (prop, parsedValue, ctx) => {
|
|
12
|
+
return {
|
|
13
|
+
byteIndex: 8,
|
|
14
|
+
offset: parsedValue - Date.now(),
|
|
15
|
+
resolvedByteIndex: 0,
|
|
16
|
+
ctx,
|
|
17
|
+
prop,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
5
20
|
export const writeFixed = (prop, buf, value, size, offset) => {
|
|
6
21
|
if (prop.typeIndex === BINARY || prop.typeIndex === STRING) {
|
|
7
22
|
if (typeof value === 'string') {
|
|
@@ -43,42 +58,64 @@ export const createFixedFilterBuffer = (prop, size, ctx, value, sort) => {
|
|
|
43
58
|
if (Array.isArray(value)) {
|
|
44
59
|
const len = value.length;
|
|
45
60
|
// Add 8 extra bytes for alignment
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
const buffer = new Uint8Array(18 + len * size);
|
|
62
|
+
const result = { buffer };
|
|
63
|
+
buffer[0] = ctx.type;
|
|
64
|
+
buffer[1] =
|
|
49
65
|
prop.typeIndex === REFERENCES && ctx.operation === EQUAL
|
|
50
66
|
? MODE_AND_FIXED
|
|
51
67
|
: MODE_OR_FIXED;
|
|
52
|
-
|
|
53
|
-
writeUint16(
|
|
54
|
-
writeUint16(
|
|
55
|
-
|
|
56
|
-
writeUint16(
|
|
57
|
-
|
|
68
|
+
buffer[2] = prop.typeIndex;
|
|
69
|
+
writeUint16(buffer, size, 3);
|
|
70
|
+
writeUint16(buffer, start, 5);
|
|
71
|
+
buffer[7] = ctx.operation;
|
|
72
|
+
writeUint16(buffer, len, 8);
|
|
73
|
+
buffer[10] = ALIGNMENT_NOT_SET;
|
|
58
74
|
if (sort) {
|
|
59
75
|
value = new Uint32Array(value.map((v) => parseFilterValue(prop, v)));
|
|
60
76
|
value.sort();
|
|
61
77
|
for (let i = 0; i < len; i++) {
|
|
62
|
-
writeUint32(
|
|
78
|
+
writeUint32(buffer, value[i], 18 + i * size);
|
|
63
79
|
}
|
|
64
80
|
}
|
|
65
81
|
else {
|
|
66
82
|
for (let i = 0; i < len; i++) {
|
|
67
|
-
|
|
83
|
+
const parsedValue = parseFilterValue(prop, value[i]);
|
|
84
|
+
if (isNowQuery(prop, value, ctx)) {
|
|
85
|
+
if (!result.subscriptionMeta) {
|
|
86
|
+
result.subscriptionMeta = {};
|
|
87
|
+
}
|
|
88
|
+
if (!result.subscriptionMeta.now) {
|
|
89
|
+
result.subscriptionMeta = { now: [] };
|
|
90
|
+
}
|
|
91
|
+
result.subscriptionMeta.now.push(createNowMeta(prop, parsedValue, ctx));
|
|
92
|
+
}
|
|
93
|
+
writeFixed(prop, buffer, parsedValue, size, 18 + i * size);
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
|
-
return
|
|
96
|
+
return result;
|
|
71
97
|
}
|
|
72
98
|
else {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
writeUint16(
|
|
78
|
-
writeUint16(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
const buffer = new Uint8Array(8 + size);
|
|
100
|
+
buffer[0] = ctx.type;
|
|
101
|
+
buffer[1] = MODE_DEFAULT;
|
|
102
|
+
buffer[2] = prop.typeIndex;
|
|
103
|
+
writeUint16(buffer, size, 3);
|
|
104
|
+
writeUint16(buffer, start, 5);
|
|
105
|
+
buffer[7] = ctx.operation;
|
|
106
|
+
const parsedValue = parseFilterValue(prop, value);
|
|
107
|
+
writeFixed(prop, buffer, parsedValue, size, 8);
|
|
108
|
+
if (isNowQuery(prop, value, ctx)) {
|
|
109
|
+
return {
|
|
110
|
+
buffer,
|
|
111
|
+
subscriptionMeta: {
|
|
112
|
+
now: [createNowMeta(prop, parsedValue, ctx)],
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return { buffer };
|
|
118
|
+
}
|
|
82
119
|
}
|
|
83
120
|
};
|
|
84
121
|
//# sourceMappingURL=createFixedFilterBuffer.js.map
|
|
@@ -3,24 +3,24 @@ import { writeUint16, writeUint32 } from '@based/utils';
|
|
|
3
3
|
export const createReferenceFilter = (prop, ctx, value) => {
|
|
4
4
|
const isArray = Array.isArray(value);
|
|
5
5
|
const len = isArray ? value.length : 1;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
writeUint16(
|
|
11
|
-
writeUint16(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
writeUint16(
|
|
6
|
+
const buffer = new Uint8Array(11 + (isArray ? 8 : 0) + len * 4);
|
|
7
|
+
buffer[0] = ctx.type;
|
|
8
|
+
buffer[1] = MODE_REFERENCE;
|
|
9
|
+
buffer[2] = prop.typeIndex;
|
|
10
|
+
writeUint16(buffer, 4, 3); // size (4)
|
|
11
|
+
writeUint16(buffer, len, 5);
|
|
12
|
+
buffer[7] = ctx.operation;
|
|
13
|
+
buffer[8] = 0;
|
|
14
|
+
writeUint16(buffer, prop.inverseTypeId, 9);
|
|
15
15
|
if (isArray) {
|
|
16
|
-
|
|
16
|
+
buffer[11] = ALIGNMENT_NOT_SET;
|
|
17
17
|
for (let i = 0; i < len; i++) {
|
|
18
|
-
writeUint32(
|
|
18
|
+
writeUint32(buffer, value[i], 19 + i * 4);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
writeUint32(
|
|
22
|
+
writeUint32(buffer, value, 11);
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return { buffer };
|
|
25
25
|
};
|
|
26
26
|
//# sourceMappingURL=createReferenceFilter.js.map
|
|
@@ -103,13 +103,14 @@ export const createVariableFilterBuffer = (value, prop, ctx, lang) => {
|
|
|
103
103
|
for (let i = 0; i < fbLen; i++) {
|
|
104
104
|
v[v.byteLength - (i + 1)] = val[val.byteLength - (i + 1)];
|
|
105
105
|
}
|
|
106
|
-
parsedCondition = writeVarFilter(mode, v, ctx, prop, 0, 0);
|
|
106
|
+
parsedCondition = { buffer: writeVarFilter(mode, v, ctx, prop, 0, 0) };
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
109
|
parsedCondition = createFixedFilterBuffer(prop, 8, {
|
|
110
110
|
operation: EQUAL_CRC32,
|
|
111
111
|
type: ctx.type,
|
|
112
112
|
opts: ctx.opts,
|
|
113
|
+
typeId: ctx.typeId,
|
|
113
114
|
}, val, false);
|
|
114
115
|
}
|
|
115
116
|
}
|
|
@@ -117,11 +118,13 @@ export const createVariableFilterBuffer = (value, prop, ctx, lang) => {
|
|
|
117
118
|
if (val instanceof ArrayBuffer) {
|
|
118
119
|
val = new Uint8Array(val);
|
|
119
120
|
}
|
|
120
|
-
parsedCondition = writeVarFilter(mode, val, ctx, prop, 0, 0);
|
|
121
|
+
parsedCondition = { buffer: writeVarFilter(mode, val, ctx, prop, 0, 0) };
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
else {
|
|
124
|
-
parsedCondition =
|
|
125
|
+
parsedCondition = {
|
|
126
|
+
buffer: writeVarFilter(mode, val, ctx, prop, prop.start, prop.len),
|
|
127
|
+
};
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
130
|
return parsedCondition;
|
|
@@ -47,11 +47,15 @@ const referencesFilter = (db, filter, schema, conditions, def) => {
|
|
|
47
47
|
fromRef: t,
|
|
48
48
|
schema,
|
|
49
49
|
size: 0,
|
|
50
|
+
hasSubMeta: false,
|
|
50
51
|
};
|
|
51
52
|
conditions.references.set(t.prop, refConditions);
|
|
52
53
|
}
|
|
53
54
|
// more nested
|
|
54
55
|
size += filterRaw(db, [path.slice(i + 1).join('.'), ctx, value], refConditions.schema, refConditions, def);
|
|
56
|
+
if (refConditions.hasSubMeta) {
|
|
57
|
+
conditions.hasSubMeta = true;
|
|
58
|
+
}
|
|
55
59
|
return size;
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -108,6 +112,7 @@ export const filterOr = (db, def, filterAst, conditions) => {
|
|
|
108
112
|
conditions.or = {
|
|
109
113
|
size: 0,
|
|
110
114
|
conditions: new Map(),
|
|
115
|
+
hasSubMeta: false,
|
|
111
116
|
};
|
|
112
117
|
}
|
|
113
118
|
else {
|
|
@@ -117,6 +122,9 @@ export const filterOr = (db, def, filterAst, conditions) => {
|
|
|
117
122
|
}
|
|
118
123
|
filter(db, def, filterAst, conditions.or);
|
|
119
124
|
conditions.size += conditions.or.size;
|
|
125
|
+
if (conditions.or.hasSubMeta) {
|
|
126
|
+
conditions.hasSubMeta = true;
|
|
127
|
+
}
|
|
120
128
|
return conditions.or;
|
|
121
129
|
};
|
|
122
130
|
//# sourceMappingURL=filter.js.map
|
|
@@ -53,7 +53,10 @@ export const primitiveFilter = (def, prop, filter, conditions, lang) => {
|
|
|
53
53
|
arr = [];
|
|
54
54
|
bufferMap.set(fieldIndexChar, arr);
|
|
55
55
|
}
|
|
56
|
-
size += parsedCondition.byteLength;
|
|
56
|
+
size += parsedCondition.buffer.byteLength;
|
|
57
|
+
if ('subscriptionMeta' in parsedCondition) {
|
|
58
|
+
conditions.hasSubMeta = true;
|
|
59
|
+
}
|
|
57
60
|
arr.push(parsedCondition);
|
|
58
61
|
return size;
|
|
59
62
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { QueryDefFilter } from '../types.js';
|
|
2
|
-
export declare const fillConditionsBuffer: (result: Uint8Array, conditions: QueryDefFilter, offset: number) => number;
|
|
2
|
+
export declare const fillConditionsBuffer: (result: Uint8Array, conditions: QueryDefFilter, offset: number, metaOffset: number) => number;
|
|
3
3
|
export declare const isSimpleMainFilter: (conditions: QueryDefFilter) => boolean;
|
|
4
|
-
export declare const filterToBuffer: (conditions: QueryDefFilter) => Uint8Array;
|
|
4
|
+
export declare const filterToBuffer: (conditions: QueryDefFilter, metaOffset: number) => Uint8Array;
|
|
5
|
+
export declare const resolveMetaIndexes: (defFilter: QueryDefFilter, offset: number) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writeUint16, writeUint32 } from '@based/utils';
|
|
2
2
|
import { META_EDGE, META_EXISTS, META_OR_BRANCH, META_REFERENCE, TYPE_DEFAULT, TYPE_NEGATE, } from './types.js';
|
|
3
|
-
const writeConditions = (result, k, offset, conditions) => {
|
|
3
|
+
const writeConditions = (result, k, offset, conditions, metaOffset) => {
|
|
4
4
|
let lastWritten = offset;
|
|
5
5
|
result[lastWritten] = k;
|
|
6
6
|
lastWritten++;
|
|
@@ -8,14 +8,21 @@ const writeConditions = (result, k, offset, conditions) => {
|
|
|
8
8
|
lastWritten += 2;
|
|
9
9
|
let conditionSize = 0;
|
|
10
10
|
for (const condition of conditions) {
|
|
11
|
-
conditionSize += condition.byteLength;
|
|
12
|
-
result.set(condition, lastWritten);
|
|
13
|
-
|
|
11
|
+
conditionSize += condition.buffer.byteLength;
|
|
12
|
+
result.set(condition.buffer, lastWritten);
|
|
13
|
+
if ('subscriptionMeta' in condition) {
|
|
14
|
+
if ('now' in condition.subscriptionMeta) {
|
|
15
|
+
for (const n of condition.subscriptionMeta.now) {
|
|
16
|
+
n.resolvedByteIndex = n.byteIndex + lastWritten + metaOffset;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
lastWritten += condition.buffer.byteLength;
|
|
14
21
|
}
|
|
15
22
|
writeUint16(result, conditionSize, sizeIndex);
|
|
16
23
|
return lastWritten - offset;
|
|
17
24
|
};
|
|
18
|
-
export const fillConditionsBuffer = (result, conditions, offset) => {
|
|
25
|
+
export const fillConditionsBuffer = (result, conditions, offset, metaOffset) => {
|
|
19
26
|
let lastWritten = offset;
|
|
20
27
|
let orJumpIndex = 0;
|
|
21
28
|
if (conditions.or && conditions.or.size != 0) {
|
|
@@ -26,7 +33,7 @@ export const fillConditionsBuffer = (result, conditions, offset) => {
|
|
|
26
33
|
lastWritten += 4;
|
|
27
34
|
}
|
|
28
35
|
conditions.conditions.forEach((v, k) => {
|
|
29
|
-
lastWritten += writeConditions(result, k, lastWritten, v);
|
|
36
|
+
lastWritten += writeConditions(result, k, lastWritten, v, metaOffset);
|
|
30
37
|
});
|
|
31
38
|
if (conditions.references) {
|
|
32
39
|
for (const [refField, refConditions] of conditions.references) {
|
|
@@ -38,7 +45,7 @@ export const fillConditionsBuffer = (result, conditions, offset) => {
|
|
|
38
45
|
lastWritten += 2;
|
|
39
46
|
const sizeIndex = lastWritten;
|
|
40
47
|
lastWritten += 2;
|
|
41
|
-
const size = fillConditionsBuffer(result, refConditions, lastWritten);
|
|
48
|
+
const size = fillConditionsBuffer(result, refConditions, lastWritten, metaOffset);
|
|
42
49
|
writeUint16(result, size, sizeIndex);
|
|
43
50
|
lastWritten += size;
|
|
44
51
|
}
|
|
@@ -49,13 +56,13 @@ export const fillConditionsBuffer = (result, conditions, offset) => {
|
|
|
49
56
|
lastWritten++;
|
|
50
57
|
let sizeIndex = lastWritten;
|
|
51
58
|
lastWritten += 2;
|
|
52
|
-
const size = writeConditions(result, k, lastWritten, v);
|
|
59
|
+
const size = writeConditions(result, k, lastWritten, v, metaOffset);
|
|
53
60
|
lastWritten += size;
|
|
54
61
|
writeUint16(result, size, sizeIndex);
|
|
55
62
|
});
|
|
56
63
|
}
|
|
57
64
|
if (conditions.or && conditions.or.size != 0) {
|
|
58
|
-
const size = fillConditionsBuffer(result, conditions.or, lastWritten);
|
|
65
|
+
const size = fillConditionsBuffer(result, conditions.or, lastWritten, metaOffset);
|
|
59
66
|
writeUint16(result, size, orJumpIndex);
|
|
60
67
|
writeUint32(result, lastWritten, orJumpIndex + 2);
|
|
61
68
|
lastWritten += size;
|
|
@@ -85,16 +92,43 @@ export const isSimpleMainFilter = (conditions) => {
|
|
|
85
92
|
}
|
|
86
93
|
return false;
|
|
87
94
|
};
|
|
88
|
-
export const filterToBuffer = (conditions) => {
|
|
95
|
+
export const filterToBuffer = (conditions, metaOffset) => {
|
|
89
96
|
// add extra byte IS SINGLE CONDITION
|
|
90
97
|
let result;
|
|
91
98
|
if (conditions.size > 0) {
|
|
92
99
|
result = new Uint8Array(conditions.size);
|
|
93
|
-
fillConditionsBuffer(result, conditions, 0);
|
|
100
|
+
fillConditionsBuffer(result, conditions, 0, metaOffset);
|
|
94
101
|
}
|
|
95
102
|
else {
|
|
96
103
|
result = new Uint8Array(0);
|
|
97
104
|
}
|
|
98
105
|
return result;
|
|
99
106
|
};
|
|
100
|
-
|
|
107
|
+
export const resolveMetaIndexes = (defFilter, offset) => {
|
|
108
|
+
if (!defFilter.hasSubMeta) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for (const conditions of defFilter.conditions.values()) {
|
|
112
|
+
for (const condition of conditions) {
|
|
113
|
+
if (condition.subscriptionMeta) {
|
|
114
|
+
if (condition.subscriptionMeta.now) {
|
|
115
|
+
for (const now of condition.subscriptionMeta.now) {
|
|
116
|
+
now.resolvedByteIndex += offset;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (defFilter.and) {
|
|
123
|
+
resolveMetaIndexes(defFilter.and, offset);
|
|
124
|
+
}
|
|
125
|
+
if (defFilter.or) {
|
|
126
|
+
resolveMetaIndexes(defFilter.or, offset);
|
|
127
|
+
}
|
|
128
|
+
if (defFilter.references) {
|
|
129
|
+
for (const ref of defFilter.references.values()) {
|
|
130
|
+
resolveMetaIndexes(ref, offset);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=toByteCode.js.map
|
|
@@ -90,6 +90,7 @@ export const toFilterCtx = (def, op, opts = {}) => {
|
|
|
90
90
|
operation: EQUAL,
|
|
91
91
|
type: op === '!=' ? TYPE_NEGATE : TYPE_DEFAULT,
|
|
92
92
|
opts,
|
|
93
|
+
typeId: def.schema.id,
|
|
93
94
|
};
|
|
94
95
|
}
|
|
95
96
|
if (op === 'exists' || op === '!exists') {
|
|
@@ -97,6 +98,7 @@ export const toFilterCtx = (def, op, opts = {}) => {
|
|
|
97
98
|
operation: EXISTS,
|
|
98
99
|
type: op === '!exists' ? TYPE_NEGATE : TYPE_DEFAULT,
|
|
99
100
|
opts,
|
|
101
|
+
typeId: def.schema.id,
|
|
100
102
|
};
|
|
101
103
|
}
|
|
102
104
|
if (op === 'includes' || op === '!includes') {
|
|
@@ -104,22 +106,48 @@ export const toFilterCtx = (def, op, opts = {}) => {
|
|
|
104
106
|
operation: opts.lowerCase ? INCLUDES_TO_LOWER_CASE : INCLUDES,
|
|
105
107
|
type: op === '!includes' ? TYPE_NEGATE : TYPE_DEFAULT,
|
|
106
108
|
opts,
|
|
109
|
+
typeId: def.schema.id,
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
112
|
if (op === '>') {
|
|
110
|
-
return {
|
|
113
|
+
return {
|
|
114
|
+
operation: GREATER_THAN,
|
|
115
|
+
opts,
|
|
116
|
+
type: TYPE_DEFAULT,
|
|
117
|
+
typeId: def.schema.id,
|
|
118
|
+
};
|
|
111
119
|
}
|
|
112
120
|
if (op === '<') {
|
|
113
|
-
return {
|
|
121
|
+
return {
|
|
122
|
+
operation: SMALLER_THAN,
|
|
123
|
+
opts,
|
|
124
|
+
type: TYPE_DEFAULT,
|
|
125
|
+
typeId: def.schema.id,
|
|
126
|
+
};
|
|
114
127
|
}
|
|
115
128
|
if (op === '>=') {
|
|
116
|
-
return {
|
|
129
|
+
return {
|
|
130
|
+
operation: GREATER_THAN_INCLUSIVE,
|
|
131
|
+
opts,
|
|
132
|
+
type: TYPE_DEFAULT,
|
|
133
|
+
typeId: def.schema.id,
|
|
134
|
+
};
|
|
117
135
|
}
|
|
118
136
|
if (op === '<=') {
|
|
119
|
-
return {
|
|
137
|
+
return {
|
|
138
|
+
operation: SMALLER_THAN_INCLUSIVE,
|
|
139
|
+
opts,
|
|
140
|
+
type: TYPE_DEFAULT,
|
|
141
|
+
typeId: def.schema.id,
|
|
142
|
+
};
|
|
120
143
|
}
|
|
121
144
|
if (op === 'like') {
|
|
122
|
-
return {
|
|
145
|
+
return {
|
|
146
|
+
operation: LIKE,
|
|
147
|
+
opts,
|
|
148
|
+
type: TYPE_DEFAULT,
|
|
149
|
+
typeId: def.schema.id,
|
|
150
|
+
};
|
|
123
151
|
}
|
|
124
152
|
filterOperatorDoesNotExist(def, op);
|
|
125
153
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DbClient } from '../../index.js';
|
|
2
|
-
import { QueryDef } from '../types.js';
|
|
3
|
-
export declare const includeToBuffer: (db: DbClient, def: QueryDef) =>
|
|
2
|
+
import { IntermediateByteCode, QueryDef } from '../types.js';
|
|
3
|
+
export declare const includeToBuffer: (db: DbClient, def: QueryDef) => IntermediateByteCode[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MICRO_BUFFER, STRING, TEXT, JSON, BINARY } from '@based/schema/def';
|
|
2
|
-
import { QueryDefType } from '../types.js';
|
|
2
|
+
import { QueryDefType, } from '../types.js';
|
|
3
3
|
import { walkDefs } from './walk.js';
|
|
4
4
|
import { langCodesMap } from '@based/schema';
|
|
5
5
|
import { writeUint32 } from '@based/utils';
|
|
@@ -4,7 +4,7 @@ export * from './include/props.js';
|
|
|
4
4
|
export * from './include/toByteCode.js';
|
|
5
5
|
export * from './toByteCode/toByteCode.js';
|
|
6
6
|
export * from './filter/filter.js';
|
|
7
|
-
export * from './filter/
|
|
7
|
+
export * from './filter/toByteCode.js';
|
|
8
8
|
export * from './sort.js';
|
|
9
9
|
export * from './debug.js';
|
|
10
10
|
export * from './aggregates/aggregation.js';
|
|
@@ -4,7 +4,7 @@ export * from './include/props.js';
|
|
|
4
4
|
export * from './include/toByteCode.js';
|
|
5
5
|
export * from './toByteCode/toByteCode.js';
|
|
6
6
|
export * from './filter/filter.js';
|
|
7
|
-
export * from './filter/
|
|
7
|
+
export * from './filter/toByteCode.js';
|
|
8
8
|
export * from './sort.js';
|
|
9
9
|
export * from './debug.js';
|
|
10
10
|
export * from './aggregates/aggregation.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { langCodesMap } from '@based/schema';
|
|
2
2
|
import { DEF_RANGE_PROP_LIMIT, DEF_RANGE_REF_LIMIT } from './thresholds.js';
|
|
3
|
-
import { QueryDefType, } from './types.js';
|
|
3
|
+
import { QueryDefType, QueryType, } from './types.js';
|
|
4
4
|
import { validateAlias, validateId, validateIds, validateType, } from './validation.js';
|
|
5
5
|
const createEmptySharedDef = (skipValidation) => {
|
|
6
6
|
const q = {
|
|
7
7
|
errors: [],
|
|
8
8
|
skipValidation,
|
|
9
|
-
filter: { conditions: new Map(), size: 0 },
|
|
9
|
+
filter: { conditions: new Map(), size: 0, hasSubMeta: false },
|
|
10
10
|
range: { offset: 0, limit: 0 },
|
|
11
11
|
lang: {
|
|
12
12
|
lang: langCodesMap.get('none'),
|
|
@@ -46,15 +46,19 @@ export function createQueryDef(db, type, target, skipValidation) {
|
|
|
46
46
|
if (type === QueryDefType.Root) {
|
|
47
47
|
if (t.id) {
|
|
48
48
|
t.id = validateId(q, t.id);
|
|
49
|
+
q.queryType = QueryType.id;
|
|
49
50
|
}
|
|
50
51
|
else if (t.ids) {
|
|
52
|
+
q.queryType = QueryType.ids;
|
|
51
53
|
t.ids = validateIds(q, t.ids);
|
|
52
54
|
q.range.limit = t.ids.length;
|
|
53
55
|
}
|
|
54
56
|
else if (t.alias) {
|
|
57
|
+
q.queryType = QueryType.alias;
|
|
55
58
|
t.resolvedAlias = validateAlias(q, t.alias);
|
|
56
59
|
}
|
|
57
60
|
else {
|
|
61
|
+
q.queryType = QueryType.default;
|
|
58
62
|
q.range.limit = DEF_RANGE_PROP_LIMIT;
|
|
59
63
|
}
|
|
60
64
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { concatUint8Arr } from '@based/utils';
|
|
3
|
-
import { defToBuffer } from './toByteCode/toByteCode.js';
|
|
1
|
+
import { queryToBuffer } from './toByteCode/toByteCode.js';
|
|
4
2
|
import { handleErrors } from './validation.js';
|
|
5
3
|
import { createQueryDef } from './queryDef.js';
|
|
6
4
|
import { QueryDefType } from './types.js';
|
|
7
5
|
import { includeField } from './query.js';
|
|
8
6
|
import { convertToReaderSchema } from './queryDefToReadSchema.js';
|
|
9
7
|
export const registerQuery = (q) => {
|
|
10
|
-
if (!q.
|
|
8
|
+
if (!q.buffer) {
|
|
11
9
|
const commands = q.queryCommands;
|
|
12
10
|
q.queryCommands = null;
|
|
13
11
|
const def = createQueryDef(q.db, QueryDefType.Root,
|
|
@@ -22,16 +20,14 @@ export const registerQuery = (q) => {
|
|
|
22
20
|
includeField(q.def, { field: '*' });
|
|
23
21
|
}
|
|
24
22
|
q.queryCommands = commands;
|
|
25
|
-
const
|
|
26
|
-
const buf = concatUint8Arr(b);
|
|
27
|
-
let id = native.crc32(buf);
|
|
28
|
-
q.id = id;
|
|
29
|
-
def.queryId = q.id;
|
|
23
|
+
const buf = queryToBuffer(q);
|
|
30
24
|
q.buffer = buf;
|
|
25
|
+
// console.log(buf)
|
|
31
26
|
// console.log('--------------------------------------------------')
|
|
32
27
|
// console.dir(convertToReaderSchema(q.def), { depth: 100 })
|
|
33
28
|
// const c = convertToReaderSchema(q.def)
|
|
34
29
|
// const s = serialize(c)
|
|
30
|
+
// console.log('--------------------------------------------------')
|
|
35
31
|
// console.log(deSerializeSchema(s))
|
|
36
32
|
// q.def.readSchema = deSerializeSchema(
|
|
37
33
|
// serialize(convertToReaderSchema(q.def)),
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { BasedQueryResponse } from '../BasedQueryResponse.js';
|
|
2
2
|
import { registerQuery } from '../registerQuery.js';
|
|
3
|
+
import { registerSubscription } from './toByteCode.js';
|
|
4
|
+
// exec
|
|
5
|
+
// subscription thing
|
|
3
6
|
export class SubStore {
|
|
4
7
|
listeners;
|
|
5
8
|
onClose;
|
|
@@ -38,6 +41,7 @@ export class SubStore {
|
|
|
38
41
|
if (!killed) {
|
|
39
42
|
try {
|
|
40
43
|
registerQuery(q);
|
|
44
|
+
registerSubscription(q);
|
|
41
45
|
this.onClose = q.db.hooks.subscribe(q, onData, onError);
|
|
42
46
|
}
|
|
43
47
|
catch (err) {
|
|
@@ -55,6 +59,7 @@ export class SubStore {
|
|
|
55
59
|
else {
|
|
56
60
|
try {
|
|
57
61
|
registerQuery(q);
|
|
62
|
+
registerSubscription(q);
|
|
58
63
|
this.onClose = q.db.hooks.subscribe(q, onData, onError);
|
|
59
64
|
}
|
|
60
65
|
catch (err) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BasedDbQuery } from '../BasedDbQuery.js';
|
|
2
|
+
import { FilterMetaNow, QueryDef, QueryDefFilter } from '../types.js';
|
|
3
|
+
export declare const collectFilters: (filter: QueryDefFilter, fields?: Set<number>, nowQueries?: FilterMetaNow[]) => FilterMetaNow[];
|
|
4
|
+
export declare const collectFields: (def: QueryDef) => Set<number>;
|
|
5
|
+
export declare const collectTypes: (def: QueryDef | QueryDefFilter, types?: Set<number>) => Set<number>;
|
|
6
|
+
export declare const registerSubscription: (query: BasedDbQuery) => void;
|