@based/db 0.0.28 → 0.0.29
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 +1 -399
- package/dist/lib/darwin_aarch64/include/selva/db.h +8 -4
- package/dist/lib/darwin_aarch64/include/selva/selva_hash128.h +17 -7
- package/dist/lib/darwin_aarch64/include/selva/sort.h +21 -14
- 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/libselva.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +8 -4
- package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +17 -7
- package/dist/lib/linux_aarch64/include/selva/sort.h +21 -14
- package/dist/lib/linux_aarch64/libdeflate.so +0 -0
- 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/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +8 -4
- package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +17 -7
- package/dist/lib/linux_x86_64/include/selva/sort.h +21 -14
- 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/libselva.so +0 -0
- package/dist/src/client/flushModify.d.ts +1 -1
- package/dist/src/client/flushModify.js +12 -17
- package/dist/src/client/index.d.ts +6 -4
- package/dist/src/client/index.js +19 -2
- package/dist/src/client/modify/ModifyRes.d.ts +1 -1
- package/dist/src/client/modify/ModifyRes.js +14 -18
- package/dist/src/client/modify/fixed.js +43 -8
- package/dist/src/client/modify/modify.js +0 -1
- package/dist/src/client/modify/references/{appendRefs.d.ts → appendEdgeRefs.d.ts} +1 -1
- package/dist/src/client/modify/references/{appendRefs.js → appendEdgeRefs.js} +5 -2
- package/dist/src/client/modify/references/edge.js +182 -175
- package/dist/src/client/modify/references/reference.js +4 -8
- package/dist/src/client/modify/references/references.js +18 -14
- package/dist/src/client/modify/string.js +0 -3
- package/dist/src/client/modify/text.js +11 -3
- package/dist/src/client/modify/types.d.ts +11 -0
- package/dist/src/client/modify/types.js +10 -0
- package/dist/src/client/modify/update.js +4 -1
- package/dist/src/client/modify/vector.js +13 -4
- package/dist/src/client/query/BasedDbQuery.d.ts +1 -1
- package/dist/src/client/query/BasedDbQuery.js +2 -2
- package/dist/src/client/query/BasedIterable.d.ts +1 -1
- package/dist/src/client/query/BasedIterable.js +7 -2
- package/dist/src/client/query/filter/createFixedFilterBuffer.d.ts +2 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +11 -28
- package/dist/src/client/query/filter/createReferenceFilter.d.ts +2 -1
- package/dist/src/client/query/filter/createReferenceFilter.js +10 -9
- package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +8 -10
- package/dist/src/client/query/filter/parseFilterValue.js +1 -1
- package/dist/src/client/query/filter/primitiveFilter.js +9 -9
- package/dist/src/client/query/filter/toBuffer.js +0 -15
- package/dist/src/client/query/filter/types.d.ts +1 -0
- package/dist/src/client/query/filter/types.js +1 -0
- package/dist/src/client/query/include/walk.js +0 -1
- package/dist/src/client/query/read/read.js +4 -4
- package/dist/src/client/query/search/index.js +11 -15
- package/dist/src/client/query/subscription/markers.js +1 -2
- package/dist/src/client/query/subscription/run.js +0 -2
- package/dist/src/client/query/thresholds.d.ts +0 -2
- package/dist/src/client/query/thresholds.js +0 -2
- package/dist/src/client/query/toBuffer.js +16 -42
- package/dist/src/client/query/types.d.ts +3 -2
- package/dist/src/client/query/validation.d.ts +1 -3
- package/dist/src/client/query/validation.js +6 -18
- package/dist/src/client/string.d.ts +2 -0
- package/dist/src/client/string.js +9 -13
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +7 -15
- package/dist/src/native.d.ts +1 -1
- package/dist/src/native.js +3 -3
- package/dist/src/server/csmt/draw-dot.js +2 -2
- package/dist/src/server/csmt/tree.js +57 -6
- package/dist/src/server/csmt/types.d.ts +5 -0
- package/dist/src/server/index.d.ts +4 -3
- package/dist/src/server/index.js +44 -44
- package/dist/src/server/migrate/index.js +47 -29
- package/dist/src/server/migrate/worker.js +2 -2
- package/dist/src/server/save.js +40 -28
- package/dist/src/server/start.js +7 -19
- package/dist/src/server/tree.d.ts +2 -0
- package/dist/src/server/tree.js +34 -2
- package/dist/src/server/worker.js +3 -3
- package/dist/src/utils.d.ts +3 -1
- package/dist/src/utils.js +43 -19
- package/package.json +9 -3
- package/dist/lib/darwin_aarch64/include/selva/base64.h +0 -59
- package/dist/lib/darwin_aarch64/include/selva/base64url.h +0 -59
- package/dist/lib/linux_aarch64/include/selva/base64.h +0 -59
- package/dist/lib/linux_aarch64/include/selva/base64url.h +0 -59
- package/dist/lib/linux_x86_64/include/selva/base64.h +0 -59
- package/dist/lib/linux_x86_64/include/selva/base64url.h +0 -59
- package/dist/src/client/timestamp.d.ts +0 -1
- package/dist/src/client/timestamp.js +0 -68
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MICRO_BUFFER } from '@based/schema/def';
|
|
1
|
+
import { MICRO_BUFFER, isValidId, } from '@based/schema/def';
|
|
2
2
|
import { startDrain, flushBuffer } from '../flushModify.js';
|
|
3
3
|
import { setCursor } from './setCursor.js';
|
|
4
4
|
import { modify } from './modify.js';
|
|
@@ -57,6 +57,9 @@ export const update = (db, type, id, obj, opts) => {
|
|
|
57
57
|
if (!def) {
|
|
58
58
|
throw new Error(`Unknown type: ${type}. Did you mean on of: ${Object.keys(db.schemaTypesParsed).join(', ')}`);
|
|
59
59
|
}
|
|
60
|
+
if (!isValidId(id)) {
|
|
61
|
+
throw new Error(`Update ${id} is not a valid id`);
|
|
62
|
+
}
|
|
60
63
|
const ctx = db.modifyCtx;
|
|
61
64
|
const pos = ctx.len;
|
|
62
65
|
const res = new ModifyState(def.id, id, db, getSubscriptionMarkers(db, def.id, id, false), opts, true);
|
|
@@ -2,14 +2,23 @@ import { UPDATE, RANGE_ERR, DELETE, } from './types.js';
|
|
|
2
2
|
import { ModifyError } from './ModifyRes.js';
|
|
3
3
|
import { setCursor } from './setCursor.js';
|
|
4
4
|
function write(value, ctx, fieldSize) {
|
|
5
|
-
|
|
6
|
-
let
|
|
7
|
-
|
|
5
|
+
let size = Math.min(value.byteLength, fieldSize);
|
|
6
|
+
let padding = 0;
|
|
7
|
+
if (ctx.len % 4 != 0) {
|
|
8
|
+
padding = ctx.len % 4;
|
|
9
|
+
}
|
|
10
|
+
size -= padding;
|
|
11
|
+
let tmp = size + 4;
|
|
12
|
+
// 16-bits would be enough but the zig expects 32-bits
|
|
8
13
|
ctx.buf[ctx.len++] = tmp;
|
|
9
14
|
ctx.buf[ctx.len++] = tmp >>>= 8;
|
|
10
15
|
ctx.buf[ctx.len++] = tmp >>>= 8;
|
|
11
16
|
ctx.buf[ctx.len++] = tmp >>>= 8;
|
|
12
|
-
ctx.buf.
|
|
17
|
+
ctx.buf[ctx.len++] = padding;
|
|
18
|
+
ctx.buf[ctx.len++] = 0;
|
|
19
|
+
ctx.buf[ctx.len++] = 0;
|
|
20
|
+
ctx.buf[ctx.len++] = 0;
|
|
21
|
+
ctx.buf.set(new Uint8Array(value.buffer).subarray(0, size), ctx.len - padding);
|
|
13
22
|
ctx.len += size;
|
|
14
23
|
}
|
|
15
24
|
export function writeVector(value, ctx, schema, t, parentId, modifyOp) {
|
|
@@ -28,7 +28,7 @@ export declare class BasedDbReferenceQuery extends QueryBranch<BasedDbReferenceQ
|
|
|
28
28
|
declare class GetPromise extends Promise<BasedQueryResponse> {
|
|
29
29
|
toObject(): Promise<any>;
|
|
30
30
|
toJSON(): Promise<string>;
|
|
31
|
-
inspect(depth?: number): GetPromise;
|
|
31
|
+
inspect(depth?: number, raw?: boolean): GetPromise;
|
|
32
32
|
}
|
|
33
33
|
export declare class BasedDbQuery extends QueryBranch<BasedDbQuery> {
|
|
34
34
|
#private;
|
|
@@ -188,8 +188,8 @@ class GetPromise extends Promise {
|
|
|
188
188
|
toJSON() {
|
|
189
189
|
return this.then(resToJSON);
|
|
190
190
|
}
|
|
191
|
-
inspect(depth) {
|
|
192
|
-
return this.then((res) => new GetPromise((resolve) => resolve(res.inspect(depth))));
|
|
191
|
+
inspect(depth, raw) {
|
|
192
|
+
return this.then((res) => new GetPromise((resolve) => resolve(res.inspect(depth, raw))));
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
export class BasedDbQuery extends QueryBranch {
|
|
@@ -15,7 +15,7 @@ export declare class BasedQueryResponse {
|
|
|
15
15
|
debug(): this;
|
|
16
16
|
node(index?: number): any;
|
|
17
17
|
[Symbol.iterator](): Generator<Partial<Item>, void, unknown>;
|
|
18
|
-
inspect(depth?: number): this;
|
|
18
|
+
inspect(depth?: number, raw?: boolean): this;
|
|
19
19
|
forEach(fn: (item: any, key: number) => void): void;
|
|
20
20
|
map(fn: (item: any, key: number) => any): any[];
|
|
21
21
|
get checksum(): number;
|
|
@@ -78,8 +78,13 @@ export class BasedQueryResponse {
|
|
|
78
78
|
yield item;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
inspect(depth = 2) {
|
|
82
|
-
|
|
81
|
+
inspect(depth = 2, raw) {
|
|
82
|
+
if (raw) {
|
|
83
|
+
console.dir(this.toObject(), { depth });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.log(this[inspect.custom](depth));
|
|
87
|
+
}
|
|
83
88
|
return this;
|
|
84
89
|
}
|
|
85
90
|
forEach(fn) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { FilterCtx } from './types.js';
|
|
3
|
+
import { FilterCondition } from '../types.js';
|
|
3
4
|
export declare const writeFixed: (prop: PropDef | PropDefEdge, buf: Uint8Array, value: any, size: number, offset: number) => void;
|
|
4
|
-
export declare const createFixedFilterBuffer: (prop: PropDef | PropDefEdge, size: number, ctx: FilterCtx, value: any, sort: boolean) =>
|
|
5
|
+
export declare const createFixedFilterBuffer: (prop: PropDef | PropDefEdge, size: number, ctx: FilterCtx, value: any, sort: boolean) => FilterCondition;
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { BINARY, STRING, REFERENCES, } from '@based/schema/def';
|
|
2
|
-
import { EQUAL, MODE_AND_FIXED, MODE_DEFAULT, MODE_OR_FIXED, } from './types.js';
|
|
2
|
+
import { ALIGNMENT_NOT_SET, EQUAL, MODE_AND_FIXED, MODE_DEFAULT, MODE_OR_FIXED, } from './types.js';
|
|
3
3
|
import { parseFilterValue } from './parseFilterValue.js';
|
|
4
4
|
import { ENCODER } from '../../../utils.js';
|
|
5
|
-
// -------------------------------------------
|
|
6
|
-
// conditions normal
|
|
7
|
-
// field, [size 2]
|
|
8
|
-
// [or = 0] [size 2] [start 2], [op], value[size]
|
|
9
|
-
// -------------------------------------------
|
|
10
|
-
// conditions or fixed
|
|
11
|
-
// field, [size 2]
|
|
12
|
-
// [or = 1] [size 2] [start 2] [op], [repeat 2], value[size] value[size] value[size]
|
|
13
|
-
// -------------------------------------------
|
|
14
|
-
// conditions or variable
|
|
15
|
-
// field, [size 2]
|
|
16
|
-
// [or = 2] [size 2] [start 2], [op], [size 2], value[size], [size 2], value[size]
|
|
17
|
-
// -------------------------------------------
|
|
18
5
|
export const writeFixed = (prop, buf, value, size, offset) => {
|
|
19
6
|
if (prop.typeIndex === BINARY || prop.typeIndex === STRING) {
|
|
20
7
|
if (typeof value === 'string') {
|
|
@@ -32,7 +19,8 @@ export const writeFixed = (prop, buf, value, size, offset) => {
|
|
|
32
19
|
buf[offset] = value;
|
|
33
20
|
}
|
|
34
21
|
else {
|
|
35
|
-
if (size === 8) {
|
|
22
|
+
if (size === 8) {
|
|
23
|
+
// RFE no int64 for u? prob important to add...
|
|
36
24
|
const view = new DataView(buf.buffer, buf.byteOffset);
|
|
37
25
|
view.setFloat64(offset, value, true);
|
|
38
26
|
}
|
|
@@ -51,17 +39,12 @@ export const writeFixed = (prop, buf, value, size, offset) => {
|
|
|
51
39
|
}
|
|
52
40
|
}
|
|
53
41
|
};
|
|
54
|
-
// Modes
|
|
55
|
-
// default = 0,
|
|
56
|
-
// orFixed = 1,
|
|
57
|
-
// orVar = 2,
|
|
58
42
|
export const createFixedFilterBuffer = (prop, size, ctx, value, sort) => {
|
|
59
|
-
let buf;
|
|
60
43
|
const start = prop.start;
|
|
61
44
|
if (Array.isArray(value)) {
|
|
62
|
-
// [or = 1] [size 2] [start 2] [op], [repeat 2], value[size] value[size] value[size]
|
|
63
45
|
const len = value.length;
|
|
64
|
-
|
|
46
|
+
// Add 8 extra bytes for alignment
|
|
47
|
+
const buf = new Uint8Array(18 + len * size);
|
|
65
48
|
buf[0] = ctx.type;
|
|
66
49
|
buf[1] =
|
|
67
50
|
prop.typeIndex === REFERENCES && ctx.operation === EQUAL
|
|
@@ -73,14 +56,14 @@ export const createFixedFilterBuffer = (prop, size, ctx, value, sort) => {
|
|
|
73
56
|
buf[5] = start;
|
|
74
57
|
buf[6] = start >>> 8;
|
|
75
58
|
buf[7] = ctx.operation;
|
|
76
|
-
// buf[7] = prop.typeIndex
|
|
77
59
|
buf[8] = len;
|
|
78
60
|
buf[9] = len >>> 8;
|
|
61
|
+
buf[10] = ALIGNMENT_NOT_SET;
|
|
79
62
|
if (sort) {
|
|
80
63
|
value = new Uint32Array(value.map((v) => parseFilterValue(prop, v)));
|
|
81
64
|
value.sort();
|
|
82
65
|
for (let i = 0; i < len; i++) {
|
|
83
|
-
const off =
|
|
66
|
+
const off = 18 + i * size;
|
|
84
67
|
const val = value[i];
|
|
85
68
|
buf[off] = val;
|
|
86
69
|
buf[off + 1] = val >>> 8;
|
|
@@ -90,13 +73,13 @@ export const createFixedFilterBuffer = (prop, size, ctx, value, sort) => {
|
|
|
90
73
|
}
|
|
91
74
|
else {
|
|
92
75
|
for (let i = 0; i < len; i++) {
|
|
93
|
-
writeFixed(prop, buf, parseFilterValue(prop, value[i]), size,
|
|
76
|
+
writeFixed(prop, buf, parseFilterValue(prop, value[i]), size, 18 + i * size);
|
|
94
77
|
}
|
|
95
78
|
}
|
|
79
|
+
return buf;
|
|
96
80
|
}
|
|
97
81
|
else {
|
|
98
|
-
|
|
99
|
-
buf = new Uint8Array(8 + size);
|
|
82
|
+
const buf = new Uint8Array(8 + size);
|
|
100
83
|
buf[0] = ctx.type;
|
|
101
84
|
buf[1] = MODE_DEFAULT;
|
|
102
85
|
buf[2] = prop.typeIndex;
|
|
@@ -106,7 +89,7 @@ export const createFixedFilterBuffer = (prop, size, ctx, value, sort) => {
|
|
|
106
89
|
buf[6] = start >>> 8;
|
|
107
90
|
buf[7] = ctx.operation;
|
|
108
91
|
writeFixed(prop, buf, parseFilterValue(prop, value), size, 8);
|
|
92
|
+
return buf;
|
|
109
93
|
}
|
|
110
|
-
return buf;
|
|
111
94
|
};
|
|
112
95
|
//# sourceMappingURL=createFixedFilterBuffer.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { FilterCtx } from './types.js';
|
|
3
|
-
|
|
3
|
+
import { FilterCondition } from '../types.js';
|
|
4
|
+
export declare const createReferenceFilter: (prop: PropDef | PropDefEdge, ctx: FilterCtx, value: any) => FilterCondition;
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { MODE_REFERENCE } from './types.js';
|
|
1
|
+
import { ALIGNMENT_NOT_SET, MODE_REFERENCE } from './types.js';
|
|
2
2
|
export const createReferenceFilter = (prop, ctx, value) => {
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const isArray = Array.isArray(value);
|
|
4
|
+
const len = isArray ? value.length : 1;
|
|
5
|
+
const buf = new Uint8Array(11 + (isArray ? 8 : 0) + len * 4);
|
|
5
6
|
buf[0] = ctx.type;
|
|
6
7
|
buf[1] = MODE_REFERENCE;
|
|
7
8
|
buf[2] = prop.typeIndex;
|
|
8
|
-
|
|
9
|
-
buf[
|
|
9
|
+
// size (4)
|
|
10
|
+
buf[3] = 4;
|
|
11
|
+
buf[4] = 0;
|
|
10
12
|
buf[5] = len;
|
|
11
13
|
buf[6] = len >>> 8;
|
|
12
14
|
buf[7] = ctx.operation;
|
|
13
|
-
// buf[7] = prop.typeIndex
|
|
14
|
-
// REF TYPE (only 1 exists now...)
|
|
15
15
|
buf[8] = 0;
|
|
16
16
|
buf[9] = prop.inverseTypeId;
|
|
17
17
|
buf[10] = prop.inverseTypeId >>> 8;
|
|
18
|
-
if (
|
|
18
|
+
if (isArray) {
|
|
19
|
+
buf[11] = ALIGNMENT_NOT_SET;
|
|
19
20
|
for (let i = 0; i < len; i++) {
|
|
20
|
-
let off =
|
|
21
|
+
let off = 19 + i * 4;
|
|
21
22
|
const v = value[i];
|
|
22
23
|
buf[off++] = v;
|
|
23
24
|
buf[off++] = v >>> 8;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { FilterCtx } from './types.js';
|
|
3
3
|
import { LangCode } from '@based/schema';
|
|
4
|
-
|
|
4
|
+
import { FilterCondition } from '../types.js';
|
|
5
|
+
export declare const createVariableFilterBuffer: (value: any, prop: PropDef | PropDefEdge, ctx: FilterCtx, lang: LangCode) => FilterCondition;
|
|
@@ -6,7 +6,6 @@ import { ENCODER, concatUint8Arr } from '../../../utils.js';
|
|
|
6
6
|
const DEFAULT_SCORE = new Uint8Array(new Float32Array([0.5]).buffer);
|
|
7
7
|
const parseValue = (value, prop, ctx, lang) => {
|
|
8
8
|
let val = value;
|
|
9
|
-
// TODO should we do .normalize('NFKD') for all strings?
|
|
10
9
|
if (ctx.operation === HAS_TO_LOWER_CASE && typeof val === 'string') {
|
|
11
10
|
val = val.toLowerCase();
|
|
12
11
|
}
|
|
@@ -31,7 +30,7 @@ const parseValue = (value, prop, ctx, lang) => {
|
|
|
31
30
|
!prop.separate ||
|
|
32
31
|
ctx.operation !== EQUAL) {
|
|
33
32
|
if (typeof val === 'string') {
|
|
34
|
-
val = ENCODER.encode(val);
|
|
33
|
+
val = ENCODER.encode(val.normalize('NFKD'));
|
|
35
34
|
}
|
|
36
35
|
if (prop.typeIndex === TEXT) {
|
|
37
36
|
const tmp = new Uint8Array(val.byteLength + 1);
|
|
@@ -48,7 +47,7 @@ const parseValue = (value, prop, ctx, lang) => {
|
|
|
48
47
|
}
|
|
49
48
|
if (ctx.operation === LIKE && prop.typeIndex !== VECTOR) {
|
|
50
49
|
const tmp = new Uint8Array(val.byteLength + 1);
|
|
51
|
-
tmp.set(
|
|
50
|
+
tmp.set(val instanceof ArrayBuffer ? new Uint8Array(val) : val);
|
|
52
51
|
tmp[tmp.byteLength - 1] = ctx.opts.score ?? 2;
|
|
53
52
|
val = tmp;
|
|
54
53
|
}
|
|
@@ -57,7 +56,7 @@ const parseValue = (value, prop, ctx, lang) => {
|
|
|
57
56
|
export const createVariableFilterBuffer = (value, prop, ctx, lang) => {
|
|
58
57
|
let mode = MODE_DEFAULT_VAR;
|
|
59
58
|
let val;
|
|
60
|
-
let
|
|
59
|
+
let parsedCondition;
|
|
61
60
|
if (Array.isArray(value)) {
|
|
62
61
|
if (ctx.operation !== EQUAL || !prop.separate) {
|
|
63
62
|
mode = MODE_OR_VAR;
|
|
@@ -103,25 +102,24 @@ export const createVariableFilterBuffer = (value, prop, ctx, lang) => {
|
|
|
103
102
|
v[6] = len >>> 16;
|
|
104
103
|
v[7] = len >>> 24;
|
|
105
104
|
v[8] = val[val.length - 1];
|
|
106
|
-
|
|
105
|
+
parsedCondition = writeVarFilter(mode, v, ctx, prop, 0, 0);
|
|
107
106
|
}
|
|
108
107
|
else {
|
|
109
|
-
|
|
108
|
+
parsedCondition = createFixedFilterBuffer(prop, 8, { operation: EQUAL_CRC32, type: ctx.type, opts: ctx.opts }, val, false);
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
else {
|
|
113
112
|
if (val instanceof ArrayBuffer) {
|
|
114
113
|
val = new Uint8Array(val);
|
|
115
114
|
}
|
|
116
|
-
|
|
115
|
+
parsedCondition = writeVarFilter(mode, val, ctx, prop, 0, 0);
|
|
117
116
|
}
|
|
118
117
|
}
|
|
119
118
|
else {
|
|
120
|
-
|
|
121
|
-
buf = writeVarFilter(mode, val, ctx, prop, prop.start, prop.len);
|
|
119
|
+
parsedCondition = writeVarFilter(mode, val, ctx, prop, prop.start, prop.len);
|
|
122
120
|
}
|
|
123
121
|
}
|
|
124
|
-
return
|
|
122
|
+
return parsedCondition;
|
|
125
123
|
};
|
|
126
124
|
function writeVarFilter(mode, val, ctx, prop, start, len) {
|
|
127
125
|
const size = val.byteLength;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TIMESTAMP, ENUM, BOOLEAN, STRING, BINARY, TEXT, } from '@based/schema/def';
|
|
2
2
|
import { crc32 } from '../../crc32.js';
|
|
3
|
-
import { convertToTimestamp } from '
|
|
3
|
+
import { convertToTimestamp } from '@saulx/utils';
|
|
4
4
|
import { ENCODER } from '../../../utils.js';
|
|
5
5
|
// -------------------------------------------
|
|
6
6
|
// conditions normal
|
|
@@ -6,10 +6,10 @@ import { createReferenceFilter } from './createReferenceFilter.js';
|
|
|
6
6
|
import { validateFilter } from '../validation.js';
|
|
7
7
|
export const primitiveFilter = (def, prop, filter, conditions, lang) => {
|
|
8
8
|
if (validateFilter(def, prop, filter)) {
|
|
9
|
-
return;
|
|
9
|
+
return 0;
|
|
10
10
|
}
|
|
11
11
|
let [, ctx, value] = filter;
|
|
12
|
-
let
|
|
12
|
+
let parsedCondition;
|
|
13
13
|
const fieldIndexChar = prop.prop;
|
|
14
14
|
const bufferMap = prop.__isEdge ? conditions.edges : conditions.conditions;
|
|
15
15
|
if (ctx.operation === EXISTS) {
|
|
@@ -29,22 +29,22 @@ export const primitiveFilter = (def, prop, filter, conditions, lang) => {
|
|
|
29
29
|
}
|
|
30
30
|
const propSize = REVERSE_SIZE_MAP[prop.typeIndex];
|
|
31
31
|
if (prop.typeIndex === REFERENCE) {
|
|
32
|
-
|
|
32
|
+
parsedCondition = createReferenceFilter(prop, ctx, value);
|
|
33
33
|
}
|
|
34
34
|
else if (prop.typeIndex === REFERENCES) {
|
|
35
35
|
if (ctx.operation === EQUAL && !isArray) {
|
|
36
36
|
value = [value];
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
parsedCondition = createFixedFilterBuffer(prop, 4, ctx, value, !isNumerical(ctx.operation));
|
|
39
39
|
}
|
|
40
40
|
else if (prop.typeIndex === CARDINALITY) {
|
|
41
|
-
|
|
41
|
+
parsedCondition = createFixedFilterBuffer(prop, 2, ctx, value, false);
|
|
42
42
|
}
|
|
43
43
|
else if (propSize) {
|
|
44
|
-
|
|
44
|
+
parsedCondition = createFixedFilterBuffer(prop, propSize, ctx, value, false);
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
|
-
|
|
47
|
+
parsedCondition = createVariableFilterBuffer(value, prop, ctx, lang);
|
|
48
48
|
}
|
|
49
49
|
// ADD OR if array for value
|
|
50
50
|
let arr = bufferMap.get(fieldIndexChar);
|
|
@@ -53,8 +53,8 @@ export const primitiveFilter = (def, prop, filter, conditions, lang) => {
|
|
|
53
53
|
arr = [];
|
|
54
54
|
bufferMap.set(fieldIndexChar, arr);
|
|
55
55
|
}
|
|
56
|
-
size +=
|
|
57
|
-
arr.push(
|
|
56
|
+
size += parsedCondition.byteLength;
|
|
57
|
+
arr.push(parsedCondition);
|
|
58
58
|
return size;
|
|
59
59
|
};
|
|
60
60
|
//# sourceMappingURL=primitiveFilter.js.map
|
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
import { META_EDGE, META_EXISTS, META_OR_BRANCH, META_REFERENCE, TYPE_DEFAULT, TYPE_NEGATE, } from './types.js';
|
|
2
|
-
// or
|
|
3
|
-
// [meta = 253] [size 2] [next 4]
|
|
4
|
-
// -------------------------------------------
|
|
5
|
-
// edge
|
|
6
|
-
// [meta = 252] [size 2]
|
|
7
|
-
// -------------------------------------------
|
|
8
|
-
// ref
|
|
9
|
-
// [meta = 254] [field] [typeId 2] [size 2]
|
|
10
|
-
// -------------------------------------------
|
|
11
|
-
// conditions normal
|
|
12
|
-
// -------------------------------------------
|
|
13
|
-
// conditions or fixed
|
|
14
|
-
// -------------------------------------------
|
|
15
|
-
// conditions or variable
|
|
16
|
-
// -------------------------------------------
|
|
17
2
|
const writeConditions = (result, k, offset, conditions) => {
|
|
18
3
|
let lastWritten = offset;
|
|
19
4
|
result[lastWritten] = k;
|
|
@@ -57,3 +57,4 @@ export declare const VECTOR_EUCLIDEAN_DIST = 3;
|
|
|
57
57
|
export declare const getVectorFn: (optsFn?: FilterOpts["fn"]) => 0 | 1 | 2 | 3;
|
|
58
58
|
export declare const toFilterCtx: (def: QueryDef, op: Operator, opts?: FilterOpts) => FilterCtx;
|
|
59
59
|
export declare const operatorReverseMap: Record<OPERATOR, string>;
|
|
60
|
+
export declare const ALIGNMENT_NOT_SET = 255;
|
|
@@ -20,7 +20,6 @@ export const walkDefs = (db, def, f) => {
|
|
|
20
20
|
def.edges.lang = def.lang;
|
|
21
21
|
}
|
|
22
22
|
const edgeProp = def.edges.props[p];
|
|
23
|
-
// console.log(p, !!edgeProp, Object.keys(def.edges.props), def.target)
|
|
24
23
|
if (edgeProp.typeIndex === REFERENCE ||
|
|
25
24
|
edgeProp.typeIndex === REFERENCES) {
|
|
26
25
|
const refDef = createOrGetRefQueryDef(db, def.edges, edgeProp);
|
|
@@ -135,7 +135,7 @@ const handleUndefinedProps = (id, q, item) => {
|
|
|
135
135
|
if (q.aggregation == 0 /* AggFlag.NONE */ || q.aggregation == null) {
|
|
136
136
|
for (const k in q.include.propsRead) {
|
|
137
137
|
if (q.include.propsRead[k] !== id) {
|
|
138
|
-
// Only
|
|
138
|
+
// Only relevant for seperate props
|
|
139
139
|
const prop = q.schema.reverseProps[k];
|
|
140
140
|
if (prop.typeIndex === CARDINALITY) {
|
|
141
141
|
addField(prop, 0, item);
|
|
@@ -159,6 +159,9 @@ const handleUndefinedProps = (id, q, item) => {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
+
else if (prop.typeIndex === BINARY) {
|
|
163
|
+
addField(prop, new Uint8Array(0), item);
|
|
164
|
+
}
|
|
162
165
|
else {
|
|
163
166
|
addField(prop, prop.typeIndex === JSON ? null : '', item);
|
|
164
167
|
}
|
|
@@ -314,9 +317,6 @@ export const readAllFields = (q, result, offset, end, item, id) => {
|
|
|
314
317
|
}
|
|
315
318
|
else {
|
|
316
319
|
const prop = q.schema.reverseProps[index];
|
|
317
|
-
if (!prop) {
|
|
318
|
-
console.log({ prop: !!prop }, index);
|
|
319
|
-
}
|
|
320
320
|
if (prop.typeIndex === CARDINALITY) {
|
|
321
321
|
q.include.propsRead[index] = id;
|
|
322
322
|
const size = readUint32(result, i);
|
|
@@ -12,8 +12,7 @@ export const vectorSearch = (def, q, field, opts) => {
|
|
|
12
12
|
if (prop.typeIndex !== VECTOR) {
|
|
13
13
|
searchIncorrectType(def, prop);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
let size = 9;
|
|
15
|
+
let size = 17;
|
|
17
16
|
const vec = new Uint8Array(q.buffer, 0, q.byteLength);
|
|
18
17
|
size += vec.byteLength;
|
|
19
18
|
def.search = {
|
|
@@ -32,21 +31,17 @@ export const search = (def, q, s) => {
|
|
|
32
31
|
searchIncorrecQueryValue(def, q);
|
|
33
32
|
q = '';
|
|
34
33
|
}
|
|
35
|
-
const x = q
|
|
36
|
-
.toLowerCase()
|
|
37
|
-
.normalize('NFKD')
|
|
38
|
-
.trim()
|
|
39
|
-
.split(' ')
|
|
40
|
-
.map((s) => ` ${s}`);
|
|
34
|
+
const x = q.toLowerCase().normalize('NFKD').trim().split(' ');
|
|
41
35
|
for (const s of x) {
|
|
42
36
|
if (s) {
|
|
43
37
|
const buf = ENCODER.encode(s);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
const lenBuf = new Uint8Array(2);
|
|
39
|
+
let len = buf.byteLength;
|
|
40
|
+
lenBuf[0] = len;
|
|
41
|
+
lenBuf[1] = len >>> 8;
|
|
42
|
+
bufs.push(lenBuf, buf);
|
|
48
43
|
nrBlocks++;
|
|
49
|
-
totalByteLength +=
|
|
44
|
+
totalByteLength += buf.byteLength + 2;
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
47
|
bufs.unshift(Uint8Array.from([nrBlocks]));
|
|
@@ -119,7 +114,8 @@ export const searchToBuffer = (search) => {
|
|
|
119
114
|
| 3 | field | 1 | Field identifier |
|
|
120
115
|
| 4 | func | 1 | Function identifier (enum) |
|
|
121
116
|
| 5 | score | 4 | Score value (f32) |
|
|
122
|
-
| 9 |
|
|
117
|
+
| 9 | align | 8 | Space for alignment |
|
|
118
|
+
| 17 | query | queryLen | Query data (array of f32 values) |
|
|
123
119
|
*/
|
|
124
120
|
const result = new Uint8Array(search.size);
|
|
125
121
|
result[0] = 1; // search.isVector 1
|
|
@@ -128,7 +124,7 @@ export const searchToBuffer = (search) => {
|
|
|
128
124
|
result[3] = search.prop;
|
|
129
125
|
result[4] = getVectorFn(search.opts.fn);
|
|
130
126
|
result.set(new Uint8Array(new Float32Array([search.opts.score ?? 0.5]).buffer), 5);
|
|
131
|
-
result.set(search.query,
|
|
127
|
+
result.set(search.query, 17);
|
|
132
128
|
return result;
|
|
133
129
|
}
|
|
134
130
|
else {
|
|
@@ -95,7 +95,7 @@ const getFilterFields = (filter, results = {
|
|
|
95
95
|
conditions.forEach((v, k) => {
|
|
96
96
|
if (k === 0) {
|
|
97
97
|
for (const buf of v) {
|
|
98
|
-
const x = buf[4] | buf[5] << 8;
|
|
98
|
+
const x = buf[4] | (buf[5] << 8);
|
|
99
99
|
results.main.add(x);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -209,6 +209,5 @@ export const resetSubscriptionMarkers = (db) => {
|
|
|
209
209
|
};
|
|
210
210
|
export const deleteSubscriptionMarkers = (q) => {
|
|
211
211
|
// derp
|
|
212
|
-
console.log('delete markers!');
|
|
213
212
|
};
|
|
214
213
|
//# sourceMappingURL=markers.js.map
|
|
@@ -61,11 +61,9 @@ export const runSubscription = (subscription) => {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
export const startSubscription = (db) => {
|
|
64
|
-
console.log('start subscription');
|
|
65
64
|
if (!db.subscriptionsInProgress) {
|
|
66
65
|
db.subscriptionsInProgress = true;
|
|
67
66
|
setTimeout(() => {
|
|
68
|
-
console.log('run it');
|
|
69
67
|
db.subscriptionsToRun.forEach((s) => {
|
|
70
68
|
runSubscription(s);
|
|
71
69
|
});
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export declare const MAX_IDS_PER_QUERY = 1000000;
|
|
2
2
|
export declare const DEF_RANGE_PROP_LIMIT = 1000;
|
|
3
3
|
export declare const DEF_RANGE_REF_LIMIT = 10000;
|
|
4
|
-
export declare const MAX_ID = 4294967295;
|
|
5
4
|
export declare const MIN_ID_VALUE = 1;
|
|
6
|
-
export declare const MAX_ID_VALUE: number;
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
export const MAX_IDS_PER_QUERY = 1e6; // Max number of IDs that can be queried at once
|
|
3
3
|
export const DEF_RANGE_PROP_LIMIT = 1e3;
|
|
4
4
|
export const DEF_RANGE_REF_LIMIT = 1e4;
|
|
5
|
-
export const MAX_ID = 4294967295;
|
|
6
5
|
// Data validation thresholds
|
|
7
6
|
export const MIN_ID_VALUE = 1; // Minimum allowed value for an ID (id array stared)
|
|
8
|
-
export const MAX_ID_VALUE = 2 ** 32 - 1; /// Maximum allowed value for an ID (Uint32)
|
|
9
7
|
//# sourceMappingURL=thresholds.js.map
|