@based/db 0.0.45 → 0.0.46
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/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/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/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/query/debug.js +3 -0
- package/dist/src/client/query/display.js +1 -1
- package/dist/src/client/query/include/toBuffer.js +0 -1
- package/dist/src/client/query/read/read.js +51 -40
- package/dist/src/client/query/toBuffer.js +54 -26
- package/dist/src/client/query/types.d.ts +7 -0
- package/dist/src/client/query/types.js +1 -0
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -281,7 +281,7 @@ export const inspectData = (q, def, level, top, depth, hasId = false) => {
|
|
|
281
281
|
str = prefix + '[';
|
|
282
282
|
}
|
|
283
283
|
if (def.aggregate) {
|
|
284
|
-
str += inspectObject(q.toObject(), def, '', level + 1, i === max - 1, i === 0, false, depth);
|
|
284
|
+
str += inspectObject('toObject' in q ? q.toObject() : q, def, '', level + 1, i === max - 1, i === 0, false, depth);
|
|
285
285
|
return str;
|
|
286
286
|
}
|
|
287
287
|
for (const x of q) {
|
|
@@ -3,7 +3,43 @@ 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
|
-
import { READ_EDGE, READ_ID, READ_REFERENCE, READ_REFERENCES, } from '../types.js';
|
|
6
|
+
import { READ_EDGE, READ_ID, READ_REFERENCE, READ_REFERENCES, READ_AGGREGATION, } from '../types.js';
|
|
7
|
+
const readAggregate = (q, result, offset, len) => {
|
|
8
|
+
const results = {};
|
|
9
|
+
if (q.aggregate.groupBy) {
|
|
10
|
+
let i = offset;
|
|
11
|
+
while (i < len) {
|
|
12
|
+
let key = '';
|
|
13
|
+
if (result[i] == 0) {
|
|
14
|
+
if (q.aggregate.groupBy.default) {
|
|
15
|
+
key = q.aggregate.groupBy.default;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
key = `$undefined`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
key = DECODER.decode(result.subarray(i, i + 2));
|
|
23
|
+
}
|
|
24
|
+
i += 2;
|
|
25
|
+
const resultKey = (results[key] = {});
|
|
26
|
+
for (const aggregatesArray of q.aggregate.aggregates.values()) {
|
|
27
|
+
for (const agg of aggregatesArray) {
|
|
28
|
+
setByPath(resultKey, agg.propDef.path, readUint32(result, agg.resultPos + i));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
i += q.aggregate.totalResultsPos;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
for (const aggregatesArray of q.aggregate.aggregates.values()) {
|
|
36
|
+
for (const agg of aggregatesArray) {
|
|
37
|
+
setByPath(results, agg.propDef.path, readUint32(result, agg.resultPos + offset));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return results;
|
|
42
|
+
};
|
|
7
43
|
const addField = (p, value, item, defaultOnly = false, lang = 0) => {
|
|
8
44
|
let i = p.__isEdge === true ? 1 : 0;
|
|
9
45
|
// TODO OPTMIZE
|
|
@@ -175,7 +211,19 @@ export const readAllFields = (q, result, offset, end, item, id) => {
|
|
|
175
211
|
handleUndefinedProps(id, q, item);
|
|
176
212
|
return i - offset;
|
|
177
213
|
}
|
|
178
|
-
if (index ===
|
|
214
|
+
if (index === READ_AGGREGATION) {
|
|
215
|
+
// also for edges at some point!
|
|
216
|
+
let field = result[i];
|
|
217
|
+
i++;
|
|
218
|
+
const size = readUint32(result, i);
|
|
219
|
+
i += 4;
|
|
220
|
+
const ref = q.references.get(field);
|
|
221
|
+
addField(
|
|
222
|
+
// @ts-ignore
|
|
223
|
+
ref.target.propDef, readAggregate(ref, result, i, i + size), item);
|
|
224
|
+
i += size;
|
|
225
|
+
}
|
|
226
|
+
else if (index === READ_EDGE) {
|
|
179
227
|
let prop = result[i];
|
|
180
228
|
if (prop === READ_REFERENCE) {
|
|
181
229
|
i++;
|
|
@@ -369,44 +417,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
|
|
|
369
417
|
let cnt = 0;
|
|
370
418
|
export const resultToObject = (q, result, end, offset = 0) => {
|
|
371
419
|
if (q.aggregate) {
|
|
372
|
-
|
|
373
|
-
// range for numbers
|
|
374
|
-
if (q.aggregate.groupBy) {
|
|
375
|
-
// key size = 2 for now... not perfect...
|
|
376
|
-
let i = 0;
|
|
377
|
-
while (i < result.byteLength - 4) {
|
|
378
|
-
// if group = 0
|
|
379
|
-
// add extra thing for the keys maybe?
|
|
380
|
-
let key = '';
|
|
381
|
-
if (result[i] == 0) {
|
|
382
|
-
if (q.aggregate.groupBy.default) {
|
|
383
|
-
key = q.aggregate.groupBy.default;
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
key = `$undefined`;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
key = DECODER.decode(result.subarray(i, i + 2));
|
|
391
|
-
}
|
|
392
|
-
i += 2;
|
|
393
|
-
const resultKey = (results[key] = {});
|
|
394
|
-
for (const aggregatesArray of q.aggregate.aggregates.values()) {
|
|
395
|
-
for (const agg of aggregatesArray) {
|
|
396
|
-
setByPath(resultKey, agg.propDef.path, readUint32(result, agg.resultPos + i));
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
i += q.aggregate.totalResultsPos;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
for (const aggregatesArray of q.aggregate.aggregates.values()) {
|
|
404
|
-
for (const agg of aggregatesArray) {
|
|
405
|
-
setByPath(results, agg.propDef.path, readUint32(result, agg.resultPos));
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
return results;
|
|
420
|
+
return readAggregate(q, result, 0, result.byteLength - 4);
|
|
410
421
|
}
|
|
411
422
|
const len = readUint32(result, offset);
|
|
412
423
|
if (len === 0) {
|
|
@@ -39,30 +39,58 @@ export function defToBuffer(db, def) {
|
|
|
39
39
|
throw new Error('Wrong aggregate size (0)');
|
|
40
40
|
}
|
|
41
41
|
const filterSize = def.filter.size || 0;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
buf
|
|
42
|
+
if (def.type === QueryDefType.References) {
|
|
43
|
+
const buf = new Uint8Array(13 + filterSize + aggregateSize);
|
|
44
|
+
const sz = 10 + filterSize + aggregateSize;
|
|
45
|
+
buf[0] = 251 /* includeOp.REFERENCES_AGGREGATION */;
|
|
46
|
+
buf[1] = sz;
|
|
47
|
+
buf[2] = sz >>> 8;
|
|
48
|
+
// ---
|
|
49
|
+
buf[3] = filterSize;
|
|
50
|
+
buf[4] = filterSize >>> 8;
|
|
51
|
+
buf[5] = def.range.offset;
|
|
52
|
+
buf[6] = def.range.offset >>> 8;
|
|
53
|
+
buf[7] = def.range.offset >>> 16;
|
|
54
|
+
buf[8] = def.range.offset >>> 24;
|
|
55
|
+
if (filterSize) {
|
|
56
|
+
buf.set(filterToBuffer(def.filter), 9);
|
|
57
|
+
}
|
|
58
|
+
// required to get typeEntry and fieldSchema
|
|
59
|
+
buf[9 + filterSize] = def.schema.idUint8[0]; // typeId
|
|
60
|
+
buf[9 + 1 + filterSize] = def.schema.idUint8[1]; // typeId
|
|
61
|
+
buf[9 + 2 + filterSize] = def.target.propDef.prop; // refField
|
|
62
|
+
const aggregateBuffer = aggregateToBuffer(def.aggregate);
|
|
63
|
+
buf.set(aggregateBuffer, 9 + 3 + filterSize);
|
|
64
|
+
// buf[12 + filterSize] = aggregateSize
|
|
65
|
+
// buf[12 + 1 + filterSize] = aggregateSize >>> 8
|
|
66
|
+
result.push(buf);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const buf = new Uint8Array(16 + filterSize + aggregateSize);
|
|
70
|
+
buf[0] = isRootCountOnly(def, filterSize)
|
|
71
|
+
? QueryType.aggregatesCountType
|
|
72
|
+
: QueryType.aggregates;
|
|
73
|
+
buf[1] = def.schema.idUint8[0];
|
|
74
|
+
buf[2] = def.schema.idUint8[1];
|
|
75
|
+
buf[3] = def.range.offset;
|
|
76
|
+
buf[4] = def.range.offset >>> 8;
|
|
77
|
+
buf[5] = def.range.offset >>> 16;
|
|
78
|
+
buf[6] = def.range.offset >>> 24;
|
|
79
|
+
buf[7] = def.range.limit;
|
|
80
|
+
buf[8] = def.range.limit >>> 8;
|
|
81
|
+
buf[9] = def.range.limit >>> 16;
|
|
82
|
+
buf[10] = def.range.limit >>> 24;
|
|
83
|
+
buf[11] = filterSize;
|
|
84
|
+
buf[12] = filterSize >>> 8;
|
|
85
|
+
if (filterSize) {
|
|
86
|
+
buf.set(filterToBuffer(def.filter), 13);
|
|
87
|
+
}
|
|
88
|
+
const aggregateBuffer = aggregateToBuffer(def.aggregate);
|
|
89
|
+
buf[14 + filterSize] = aggregateSize;
|
|
90
|
+
buf[15 + filterSize] = aggregateSize >>> 8;
|
|
91
|
+
buf.set(aggregateBuffer, 16 + filterSize);
|
|
92
|
+
result.push(buf);
|
|
60
93
|
}
|
|
61
|
-
const aggregateBuffer = aggregateToBuffer(def.aggregate);
|
|
62
|
-
buf[14 + filterSize] = aggregateSize;
|
|
63
|
-
buf[15 + filterSize] = aggregateSize >>> 8;
|
|
64
|
-
buf.set(aggregateBuffer, 16 + filterSize);
|
|
65
|
-
result.push(buf);
|
|
66
94
|
// ignore this for now...
|
|
67
95
|
// result.push(...include)
|
|
68
96
|
if (def.type === QueryDefType.Root) {
|
|
@@ -206,7 +234,7 @@ export function defToBuffer(db, def) {
|
|
|
206
234
|
const modsSize = filterSize + sortSize;
|
|
207
235
|
const meta = new Uint8Array(modsSize + 10 + 8);
|
|
208
236
|
const sz = size + 7 + modsSize + 8;
|
|
209
|
-
meta[0] = 254
|
|
237
|
+
meta[0] = 254 /* includeOp.REFERENCES */;
|
|
210
238
|
meta[1] = sz;
|
|
211
239
|
meta[2] = sz >>> 8;
|
|
212
240
|
meta[3] = filterSize;
|
|
@@ -235,7 +263,7 @@ export function defToBuffer(db, def) {
|
|
|
235
263
|
else if (def.type === QueryDefType.Reference) {
|
|
236
264
|
const meta = new Uint8Array(6);
|
|
237
265
|
const sz = size + 3;
|
|
238
|
-
meta[0] = 255
|
|
266
|
+
meta[0] = 255 /* includeOp.REFERENCE */;
|
|
239
267
|
meta[1] = sz;
|
|
240
268
|
meta[2] = sz >>> 8;
|
|
241
269
|
meta[3] = def.schema.idUint8[0];
|
|
@@ -246,7 +274,7 @@ export function defToBuffer(db, def) {
|
|
|
246
274
|
result.push(...include);
|
|
247
275
|
if (edges) {
|
|
248
276
|
const metaEdgeBuffer = new Uint8Array(3);
|
|
249
|
-
metaEdgeBuffer[0] = 252
|
|
277
|
+
metaEdgeBuffer[0] = 252 /* includeOp.EDGE */;
|
|
250
278
|
metaEdgeBuffer[1] = edgesSize;
|
|
251
279
|
metaEdgeBuffer[2] = edgesSize >>> 8;
|
|
252
280
|
result.push(metaEdgeBuffer, ...edges);
|
|
@@ -140,3 +140,10 @@ export declare const READ_ID = 255;
|
|
|
140
140
|
export declare const READ_EDGE = 252;
|
|
141
141
|
export declare const READ_REFERENCES = 253;
|
|
142
142
|
export declare const READ_REFERENCE = 254;
|
|
143
|
+
export declare const READ_AGGREGATION = 250;
|
|
144
|
+
export declare const enum includeOp {
|
|
145
|
+
REFERENCES_AGGREGATION = 251,
|
|
146
|
+
EDGE = 252,
|
|
147
|
+
REFERENCES = 254,
|
|
148
|
+
REFERENCE = 255
|
|
149
|
+
}
|