@based/db 0.0.71 → 0.1.1
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/LICENSE +201 -0
- package/README.md +105 -77
- package/dist/lib/darwin_aarch64/include/libdeflate.h +23 -0
- package/dist/lib/darwin_aarch64/include/selva/db.h +0 -41
- package/dist/lib/darwin_aarch64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/darwin_aarch64/include/selva/fields.h +52 -37
- package/dist/lib/darwin_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/darwin_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_string.h +8 -5
- package/dist/lib/darwin_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +18 -4
- 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/libselva.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/lib/linux_aarch64/include/libdeflate.h +23 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +0 -41
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/linux_aarch64/include/selva/fields.h +52 -37
- package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +8 -5
- package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +18 -4
- 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/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/libdeflate.h +23 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +0 -41
- package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/linux_x86_64/include/selva/fields.h +52 -37
- package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +8 -5
- package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +18 -4
- 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/libselva.so +0 -0
- package/dist/src/client/index.d.ts +16 -21
- package/dist/src/client/index.js +48 -59
- package/dist/src/client/modify/Ctx.d.ts +38 -0
- package/dist/src/client/modify/Ctx.js +30 -0
- package/dist/src/client/modify/Tmp.d.ts +19 -0
- package/dist/src/client/modify/Tmp.js +67 -0
- package/dist/src/client/modify/create/index.d.ts +6 -0
- package/dist/src/client/modify/create/index.js +191 -0
- package/dist/src/client/modify/create/mark.d.ts +7 -0
- package/dist/src/client/modify/create/mark.js +42 -0
- package/dist/src/client/modify/cursor.d.ts +10 -0
- package/dist/src/client/modify/cursor.js +48 -0
- package/dist/src/client/modify/delete/index.d.ts +2 -0
- package/dist/src/client/modify/delete/index.js +39 -0
- package/dist/src/client/modify/drain.d.ts +7 -0
- package/dist/src/client/modify/drain.js +77 -0
- package/dist/src/client/modify/edges/binary.d.ts +3 -0
- package/dist/src/client/modify/edges/binary.js +28 -0
- package/dist/src/client/modify/edges/cardinality.d.ts +3 -0
- package/dist/src/client/modify/edges/cardinality.js +15 -0
- package/dist/src/client/modify/edges/header.d.ts +5 -0
- package/dist/src/client/modify/edges/header.js +21 -0
- package/dist/src/client/modify/edges/index.d.ts +3 -0
- package/dist/src/client/modify/edges/index.js +128 -0
- package/dist/src/client/modify/edges/reference.d.ts +3 -0
- package/dist/src/client/modify/edges/reference.js +31 -0
- package/dist/src/client/modify/edges/references.d.ts +3 -0
- package/dist/src/client/modify/edges/references.js +38 -0
- package/dist/src/client/modify/edges/separate.d.ts +3 -0
- package/dist/src/client/modify/edges/separate.js +24 -0
- package/dist/src/client/modify/edges/string.d.ts +3 -0
- package/dist/src/client/modify/edges/string.js +30 -0
- package/dist/src/client/modify/error.d.ts +7 -0
- package/dist/src/client/modify/error.js +68 -0
- package/dist/src/client/modify/expire/index.d.ts +2 -0
- package/dist/src/client/modify/expire/index.js +31 -0
- package/dist/src/client/modify/props/alias.d.ts +3 -0
- package/dist/src/client/modify/props/alias.js +26 -0
- package/dist/src/client/modify/props/binary.d.ts +5 -0
- package/dist/src/client/modify/props/binary.js +52 -0
- package/dist/src/client/modify/props/cardinality.d.ts +4 -0
- package/dist/src/client/modify/props/cardinality.js +46 -0
- package/dist/src/client/modify/props/delete.d.ts +3 -0
- package/dist/src/client/modify/props/delete.js +13 -0
- package/dist/src/client/modify/props/fixed.d.ts +4 -0
- package/dist/src/client/modify/props/fixed.js +105 -0
- package/dist/src/client/modify/props/increment.d.ts +3 -0
- package/dist/src/client/modify/props/increment.js +28 -0
- package/dist/src/client/modify/props/json.d.ts +3 -0
- package/dist/src/client/modify/props/json.js +5 -0
- package/dist/src/client/modify/props/main.d.ts +4 -0
- package/dist/src/client/modify/props/main.js +22 -0
- package/dist/src/client/modify/props/object.d.ts +3 -0
- package/dist/src/client/modify/props/object.js +37 -0
- package/dist/src/client/modify/props/reference.d.ts +6 -0
- package/dist/src/client/modify/props/reference.js +92 -0
- package/dist/src/client/modify/props/references.d.ts +3 -0
- package/dist/src/client/modify/props/references.js +231 -0
- package/dist/src/client/modify/props/separate.d.ts +3 -0
- package/dist/src/client/modify/props/separate.js +43 -0
- package/dist/src/client/modify/props/string.d.ts +5 -0
- package/dist/src/client/modify/props/string.js +51 -0
- package/dist/src/client/modify/props/text.d.ts +3 -0
- package/dist/src/client/modify/props/text.js +35 -0
- package/dist/src/client/modify/props/vector.d.ts +3 -0
- package/dist/src/client/modify/props/vector.js +48 -0
- package/dist/src/client/modify/resize.d.ts +3 -0
- package/dist/src/client/modify/resize.js +20 -0
- package/dist/src/client/modify/types.d.ts +3 -4
- package/dist/src/client/modify/types.js +2 -1
- package/dist/src/client/modify/uint.d.ts +7 -0
- package/dist/src/client/modify/uint.js +27 -0
- package/dist/src/client/modify/update/index.d.ts +3 -0
- package/dist/src/client/modify/update/index.js +75 -0
- package/dist/src/client/modify/upsert/index.d.ts +3 -0
- package/dist/src/client/modify/{upsert.js → upsert/index.js} +4 -4
- package/dist/src/client/modify/validate.d.ts +6 -0
- package/dist/src/client/modify/validate.js +24 -0
- package/dist/src/client/query/BasedDbQuery.d.ts +17 -14
- package/dist/src/client/query/BasedDbQuery.js +90 -93
- package/dist/src/client/query/{BasedIterable.d.ts → BasedQueryResponse.d.ts} +5 -4
- package/dist/src/client/query/{BasedIterable.js → BasedQueryResponse.js} +15 -10
- package/dist/src/client/query/aggregates/aggregation.d.ts +5 -3
- package/dist/src/client/query/aggregates/aggregation.js +105 -48
- package/dist/src/client/query/aggregates/types.d.ts +33 -11
- package/dist/src/client/query/aggregates/types.js +29 -11
- package/dist/src/client/query/debug.js +1 -1
- package/dist/src/client/query/display.d.ts +1 -1
- package/dist/src/client/query/display.js +21 -4
- package/dist/src/client/query/filter/FilterBranch.js +2 -2
- package/dist/src/client/query/filter/convertFilter.d.ts +3 -2
- package/dist/src/client/query/filter/convertFilter.js +13 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +16 -30
- package/dist/src/client/query/filter/createReferenceFilter.js +6 -20
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +15 -32
- package/dist/src/client/query/filter/parseFilterValue.js +3 -11
- package/dist/src/client/query/filter/primitiveFilter.js +1 -1
- package/dist/src/client/query/filter/toBuffer.js +9 -15
- package/dist/src/client/query/filter/types.d.ts +6 -6
- package/dist/src/client/query/filter/types.js +8 -8
- package/dist/src/client/query/include/include.d.ts +3 -0
- package/dist/src/client/query/include/include.js +58 -0
- package/dist/src/client/query/include/props.d.ts +7 -7
- package/dist/src/client/query/include/props.js +26 -21
- package/dist/src/client/query/include/toByteCode.js +188 -0
- package/dist/src/client/query/include/utils.d.ts +3 -1
- package/dist/src/client/query/include/utils.js +13 -0
- package/dist/src/client/query/include/walk.d.ts +2 -2
- package/dist/src/client/query/include/walk.js +38 -23
- package/dist/src/client/query/query.d.ts +2 -3
- package/dist/src/client/query/query.js +2 -3
- package/dist/src/client/query/queryDef.d.ts +4 -2
- package/dist/src/client/query/queryDef.js +3 -5
- package/dist/src/client/query/queryDefToReadSchema.d.ts +3 -0
- package/dist/src/client/query/queryDefToReadSchema.js +126 -0
- package/dist/src/client/query/registerQuery.js +15 -4
- package/dist/src/client/query/search/index.d.ts +2 -1
- package/dist/src/client/query/search/index.js +9 -2
- package/dist/src/client/query/sort.js +3 -0
- package/dist/src/client/query/subscription/index.d.ts +1 -1
- package/dist/src/client/query/subscription/index.js +2 -2
- package/dist/src/client/query/subscription/types.d.ts +1 -1
- package/dist/src/client/query/thresholds.d.ts +1 -1
- package/dist/src/client/query/thresholds.js +1 -1
- package/dist/src/client/query/toByteCode/{toBuffer.js → toByteCode.js} +8 -8
- package/dist/src/client/query/types.d.ts +40 -25
- package/dist/src/client/query/types.js +2 -6
- package/dist/src/client/query/validation.d.ts +6 -0
- package/dist/src/client/query/validation.js +31 -7
- package/dist/src/client/setLocalClientSchema.js +6 -10
- package/dist/src/client/string.d.ts +3 -7
- package/dist/src/client/string.js +18 -47
- package/dist/src/hooks.d.ts +2 -3
- package/dist/src/hooks.js +14 -9
- package/dist/src/index.d.ts +3 -5
- package/dist/src/index.js +4 -6
- package/dist/src/native.d.ts +3 -2
- package/dist/src/native.js +9 -8
- package/dist/src/server/IoWorker.js +2 -3
- package/dist/src/server/QueryWorker.js +1 -1
- package/dist/src/server/blocks.js +5 -4
- package/dist/src/server/dbHash.js +1 -1
- package/dist/src/server/index.d.ts +4 -6
- package/dist/src/server/index.js +63 -96
- package/dist/src/server/migrate/index.d.ts +2 -4
- package/dist/src/server/migrate/index.js +32 -16
- package/dist/src/server/migrate/worker.js +2 -27
- package/dist/src/server/save.js +3 -2
- package/dist/src/server/schema.js +9 -19
- package/dist/src/server/start.d.ts +1 -0
- package/dist/src/server/start.js +18 -10
- package/dist/src/server/tree.d.ts +20 -0
- package/dist/src/server/tree.js +17 -2
- package/dist/src/server/workers/DbWorker.d.ts +1 -0
- package/dist/src/server/workers/DbWorker.js +8 -1
- package/dist/src/server/workers/io_worker.js +1 -1
- package/dist/src/server/workers/worker.js +9 -4
- package/dist/src/table.d.ts +4 -0
- package/dist/src/table.js +97 -0
- package/package.json +18 -17
- package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +0 -29
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -29
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -29
- package/dist/src/client/flushModify.d.ts +0 -36
- package/dist/src/client/flushModify.js +0 -197
- package/dist/src/client/modify/ModifyRes.d.ts +0 -23
- package/dist/src/client/modify/ModifyRes.js +0 -101
- package/dist/src/client/modify/alias.d.ts +0 -4
- package/dist/src/client/modify/alias.js +0 -57
- package/dist/src/client/modify/binary.d.ts +0 -6
- package/dist/src/client/modify/binary.js +0 -80
- package/dist/src/client/modify/cardinality.d.ts +0 -6
- package/dist/src/client/modify/cardinality.js +0 -63
- package/dist/src/client/modify/create.d.ts +0 -5
- package/dist/src/client/modify/create.js +0 -228
- package/dist/src/client/modify/delete.d.ts +0 -4
- package/dist/src/client/modify/delete.js +0 -47
- package/dist/src/client/modify/expire.d.ts +0 -3
- package/dist/src/client/modify/expire.js +0 -25
- package/dist/src/client/modify/fixed.d.ts +0 -5
- package/dist/src/client/modify/fixed.js +0 -235
- package/dist/src/client/modify/index.d.ts +0 -4
- package/dist/src/client/modify/index.js +0 -4
- package/dist/src/client/modify/json.d.ts +0 -4
- package/dist/src/client/modify/json.js +0 -26
- package/dist/src/client/modify/modify.d.ts +0 -5
- package/dist/src/client/modify/modify.js +0 -134
- package/dist/src/client/modify/references/appendEdgeRefs.d.ts +0 -4
- package/dist/src/client/modify/references/appendEdgeRefs.js +0 -33
- package/dist/src/client/modify/references/edge.d.ts +0 -5
- package/dist/src/client/modify/references/edge.js +0 -336
- package/dist/src/client/modify/references/getEdgeSize.d.ts +0 -3
- package/dist/src/client/modify/references/getEdgeSize.js +0 -27
- package/dist/src/client/modify/references/reference.d.ts +0 -11
- package/dist/src/client/modify/references/reference.js +0 -124
- package/dist/src/client/modify/references/references.d.ts +0 -16
- package/dist/src/client/modify/references/references.js +0 -316
- package/dist/src/client/modify/setCursor.d.ts +0 -5
- package/dist/src/client/modify/setCursor.js +0 -33
- package/dist/src/client/modify/string.d.ts +0 -5
- package/dist/src/client/modify/string.js +0 -71
- package/dist/src/client/modify/text.d.ts +0 -8
- package/dist/src/client/modify/text.js +0 -69
- package/dist/src/client/modify/update.d.ts +0 -6
- package/dist/src/client/modify/update.js +0 -90
- package/dist/src/client/modify/upsert.d.ts +0 -3
- package/dist/src/client/modify/vector.d.ts +0 -4
- package/dist/src/client/modify/vector.js +0 -53
- package/dist/src/client/query/include/toBuffer.js +0 -123
- package/dist/src/client/query/read/read.d.ts +0 -9
- package/dist/src/client/query/read/read.js +0 -483
- /package/dist/src/client/query/include/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
- /package/dist/src/client/query/toByteCode/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
SUM = 1,
|
|
3
|
-
COUNT = 2,
|
|
4
|
-
CARDINALITY = 3,
|
|
5
|
-
STDDEV = 4,
|
|
6
|
-
AVERAGE = 5,
|
|
7
|
-
VARIANCE = 6,
|
|
8
|
-
MAX = 7,
|
|
9
|
-
MIN = 8
|
|
10
|
-
}
|
|
1
|
+
import { AggregateType } from '@based/protocol/db-read';
|
|
11
2
|
export declare const enum AccumulatorSize {
|
|
12
3
|
SUM = 8,
|
|
13
4
|
COUNT = 4,
|
|
@@ -16,7 +7,8 @@ export declare const enum AccumulatorSize {
|
|
|
16
7
|
AVERAGE = 16,// count (u64) + sum (f64) = 16
|
|
17
8
|
VARIANCE = 24,// count (u64) + sum (f64) + sum_sq (f64) = 8 + 8 + 8 = 24
|
|
18
9
|
MAX = 8,
|
|
19
|
-
MIN = 8
|
|
10
|
+
MIN = 8,
|
|
11
|
+
HMEAN = 16
|
|
20
12
|
}
|
|
21
13
|
export declare const aggregateTypeMap: Map<AggregateType, {
|
|
22
14
|
resultsSize: number;
|
|
@@ -26,3 +18,33 @@ export declare const enum GroupBy {
|
|
|
26
18
|
NONE = 0,
|
|
27
19
|
HAS_GROUP = 255
|
|
28
20
|
}
|
|
21
|
+
export declare enum Interval {
|
|
22
|
+
none = 0,
|
|
23
|
+
epoch = 1,
|
|
24
|
+
hour = 2,
|
|
25
|
+
day = 6,// The day of the month (1–31); for interval values, the number of days
|
|
26
|
+
doy = 7,// The day of the year (0–365)
|
|
27
|
+
dow = 8,// The day of the week as Sunday (0) to Saturday (6)
|
|
28
|
+
isoDOW = 9,// The day of the week as Monday (1) to Sunday (7). This matches the ISO 8601 day of the week numbering.
|
|
29
|
+
month = 11,// The number of the month within the year (0–11);
|
|
30
|
+
year = 14
|
|
31
|
+
}
|
|
32
|
+
export type IntervalString = keyof typeof Interval;
|
|
33
|
+
export type StepObject = {
|
|
34
|
+
step?: number | IntervalString;
|
|
35
|
+
timeZone?: string;
|
|
36
|
+
display?: Intl.DateTimeFormat;
|
|
37
|
+
};
|
|
38
|
+
export type StepShorthand = number | IntervalString;
|
|
39
|
+
export type StepInput = StepObject | StepShorthand;
|
|
40
|
+
export type NormalizedStepObject = {
|
|
41
|
+
step: number | Interval;
|
|
42
|
+
};
|
|
43
|
+
export declare enum setMode {
|
|
44
|
+
'sample' = 0,
|
|
45
|
+
'population' = 1
|
|
46
|
+
}
|
|
47
|
+
export type setModeString = 'sample' | 'population';
|
|
48
|
+
export type aggFnOptions = {
|
|
49
|
+
mode?: setModeString;
|
|
50
|
+
};
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
(function (AggregateType) {
|
|
3
|
-
AggregateType[AggregateType["SUM"] = 1] = "SUM";
|
|
4
|
-
AggregateType[AggregateType["COUNT"] = 2] = "COUNT";
|
|
5
|
-
AggregateType[AggregateType["CARDINALITY"] = 3] = "CARDINALITY";
|
|
6
|
-
AggregateType[AggregateType["STDDEV"] = 4] = "STDDEV";
|
|
7
|
-
AggregateType[AggregateType["AVERAGE"] = 5] = "AVERAGE";
|
|
8
|
-
AggregateType[AggregateType["VARIANCE"] = 6] = "VARIANCE";
|
|
9
|
-
AggregateType[AggregateType["MAX"] = 7] = "MAX";
|
|
10
|
-
AggregateType[AggregateType["MIN"] = 8] = "MIN";
|
|
11
|
-
})(AggregateType || (AggregateType = {}));
|
|
1
|
+
import { AggregateType } from '@based/protocol/db-read';
|
|
12
2
|
export const aggregateTypeMap = new Map([
|
|
13
3
|
[
|
|
14
4
|
AggregateType.CARDINALITY,
|
|
@@ -26,10 +16,38 @@ export const aggregateTypeMap = new Map([
|
|
|
26
16
|
AggregateType.AVERAGE,
|
|
27
17
|
{ resultsSize: 8, accumulatorSize: 16 /* AccumulatorSize.AVERAGE */ },
|
|
28
18
|
],
|
|
19
|
+
[
|
|
20
|
+
AggregateType.HMEAN,
|
|
21
|
+
{ resultsSize: 8, accumulatorSize: 16 /* AccumulatorSize.HMEAN */ },
|
|
22
|
+
],
|
|
29
23
|
[
|
|
30
24
|
AggregateType.VARIANCE,
|
|
31
25
|
{ resultsSize: 8, accumulatorSize: 24 /* AccumulatorSize.VARIANCE */ },
|
|
32
26
|
],
|
|
33
27
|
// Othe types like MAX, MIN, SUM fall in the else case in aggregation.ts 8/8
|
|
34
28
|
]);
|
|
29
|
+
export var Interval;
|
|
30
|
+
(function (Interval) {
|
|
31
|
+
Interval[Interval["none"] = 0] = "none";
|
|
32
|
+
Interval[Interval["epoch"] = 1] = "epoch";
|
|
33
|
+
Interval[Interval["hour"] = 2] = "hour";
|
|
34
|
+
// minute = 3,
|
|
35
|
+
// second = 4,
|
|
36
|
+
// microseconds = 5,
|
|
37
|
+
Interval[Interval["day"] = 6] = "day";
|
|
38
|
+
Interval[Interval["doy"] = 7] = "doy";
|
|
39
|
+
Interval[Interval["dow"] = 8] = "dow";
|
|
40
|
+
Interval[Interval["isoDOW"] = 9] = "isoDOW";
|
|
41
|
+
// week = 10, // The number of the ISO 8601 week-numbering week of the year
|
|
42
|
+
Interval[Interval["month"] = 11] = "month";
|
|
43
|
+
// isoMonth = 12, // The number of the month within the year (1–12);
|
|
44
|
+
// quarter = 13, // The quarter of the year (1–4) that the date is in
|
|
45
|
+
Interval[Interval["year"] = 14] = "year";
|
|
46
|
+
// timeZone = 15, // ? seconds? or string?
|
|
47
|
+
})(Interval || (Interval = {}));
|
|
48
|
+
export var setMode;
|
|
49
|
+
(function (setMode) {
|
|
50
|
+
setMode[setMode["sample"] = 0] = "sample";
|
|
51
|
+
setMode[setMode["population"] = 1] = "population";
|
|
52
|
+
})(setMode || (setMode = {}));
|
|
35
53
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import picocolors from 'picocolors';
|
|
2
2
|
import { isPropDef, REVERSE_TYPE_INDEX_MAP } from '@based/schema/def';
|
|
3
3
|
import { QueryDefType } from './types.js';
|
|
4
|
-
import { concatUint8Arr } from '@
|
|
4
|
+
import { concatUint8Arr } from '@based/utils';
|
|
5
5
|
export const debugQueryDef = (q, returnIt) => {
|
|
6
6
|
const loggableObject = { type: 'bla', schema: null };
|
|
7
7
|
const f = (a) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QueryDef } from './types.js';
|
|
2
2
|
import { TypeIndex } from '@based/schema/def';
|
|
3
|
-
import { BasedQueryResponse } from './
|
|
3
|
+
import { BasedQueryResponse } from './BasedQueryResponse.js';
|
|
4
4
|
export declare const size: (size: number) => string;
|
|
5
5
|
export declare const time: (time: number) => string;
|
|
6
6
|
export declare const printNumber: (nr: number) => string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import picocolors from 'picocolors';
|
|
2
2
|
import { BINARY, CARDINALITY, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, } from '@based/schema/def';
|
|
3
|
-
import { ENCODER } from '@
|
|
4
|
-
import { AggregateType } from '
|
|
3
|
+
import { ENCODER } from '@based/utils';
|
|
4
|
+
import { AggregateType } from '@based/protocol/db-read';
|
|
5
5
|
const decimals = (v) => ~~(v * 100) / 100;
|
|
6
6
|
const sizeCalc = (size) => {
|
|
7
7
|
if (size > 1e6) {
|
|
@@ -124,6 +124,7 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
|
|
|
124
124
|
}
|
|
125
125
|
const prefixBody = ''.padEnd(level + 3, ' ');
|
|
126
126
|
let edges = [];
|
|
127
|
+
// use reader schema
|
|
127
128
|
for (const k in object) {
|
|
128
129
|
const key = path ? path + '.' + k : k;
|
|
129
130
|
let def;
|
|
@@ -176,14 +177,30 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
|
|
|
176
177
|
}
|
|
177
178
|
else if ('__isPropDef' in def) {
|
|
178
179
|
if (def.typeIndex === REFERENCES) {
|
|
179
|
-
|
|
180
|
+
if (q.aggregate) {
|
|
181
|
+
str += printNumber(v);
|
|
182
|
+
const [[__, akv], _] = q.aggregate.aggregates;
|
|
183
|
+
const aggType = akv[0].type;
|
|
184
|
+
str += picocolors.italic(picocolors.dim(` ${AggregateType[aggType].toLowerCase()}`));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
str += inspectData(v, q.references.get(def.prop), level + 2, false, depth);
|
|
188
|
+
}
|
|
180
189
|
}
|
|
181
190
|
else if (def.typeIndex === REFERENCE) {
|
|
182
191
|
if (!v || !v.id) {
|
|
183
192
|
str += 'null,\n';
|
|
184
193
|
}
|
|
185
194
|
else {
|
|
186
|
-
|
|
195
|
+
if (q.aggregate) {
|
|
196
|
+
str += printNumber(v);
|
|
197
|
+
const [[__, akv], _] = q.aggregate.aggregates;
|
|
198
|
+
const aggType = akv[0].type;
|
|
199
|
+
str += picocolors.italic(picocolors.dim(` ${AggregateType[aggType].toLowerCase()}`));
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
str += inspectObject(v, q.references.get(def.prop), '', level + 2, false, false, true, depth);
|
|
203
|
+
}
|
|
187
204
|
}
|
|
188
205
|
}
|
|
189
206
|
else if (def.typeIndex === BINARY) {
|
|
@@ -16,7 +16,7 @@ export class FilterBranch {
|
|
|
16
16
|
this.def.filter.size += f.filterBranch.size;
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
|
-
const f = convertFilter(this
|
|
19
|
+
const f = convertFilter(this, field, operator, value, opts);
|
|
20
20
|
if (f) {
|
|
21
21
|
filterOr(this.db, this.def, f, this.filterBranch);
|
|
22
22
|
}
|
|
@@ -24,7 +24,7 @@ export class FilterBranch {
|
|
|
24
24
|
return this;
|
|
25
25
|
}
|
|
26
26
|
filter(field, operator, value) {
|
|
27
|
-
const f = convertFilter(this
|
|
27
|
+
const f = convertFilter(this, field, operator, value);
|
|
28
28
|
if (f) {
|
|
29
29
|
filter(this.db, this.def, f, this.filterBranch);
|
|
30
30
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QueryBranch } from '../BasedDbQuery.js';
|
|
2
2
|
import { Operator } from './filter.js';
|
|
3
|
+
import { FilterBranch } from './FilterBranch.js';
|
|
3
4
|
import { FilterOpts, FilterAst } from './types.js';
|
|
4
|
-
export declare const convertFilter: (
|
|
5
|
+
export declare const convertFilter: (query: QueryBranch<any> | FilterBranch, field: string, operator?: Operator | boolean, value?: any, opts?: FilterOpts | undefined) => FilterAst;
|
|
@@ -6,7 +6,19 @@ const normalizeNeedle = (s) => {
|
|
|
6
6
|
.filter((ch) => ch.charCodeAt(0) <= 127)
|
|
7
7
|
.join('');
|
|
8
8
|
};
|
|
9
|
-
export const convertFilter = (
|
|
9
|
+
export const convertFilter = (query, field, operator, value, opts) => {
|
|
10
|
+
const def = query.def;
|
|
11
|
+
const filterHook = def.schema.hooks?.filter;
|
|
12
|
+
if (filterHook) {
|
|
13
|
+
def.schema.hooks.filter = null;
|
|
14
|
+
if (typeof operator === 'boolean') {
|
|
15
|
+
filterHook(query, field, '=', operator);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
filterHook(query, field, operator, value);
|
|
19
|
+
}
|
|
20
|
+
def.schema.hooks.filter = filterHook;
|
|
21
|
+
}
|
|
10
22
|
if (operator === undefined) {
|
|
11
23
|
operator = '=';
|
|
12
24
|
value = true;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { BINARY, STRING, REFERENCES, } from '@based/schema/def';
|
|
1
|
+
import { BINARY, STRING, REFERENCES, TIMESTAMP, } from '@based/schema/def';
|
|
2
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
|
-
import { ENCODER } from '@
|
|
4
|
+
import { ENCODER, writeDoubleLE, writeInt64, writeUint16, writeUint32, } from '@based/utils';
|
|
5
5
|
export const writeFixed = (prop, buf, value, size, offset) => {
|
|
6
|
-
if (prop.transform) {
|
|
7
|
-
value = prop.transform('filter', value);
|
|
8
|
-
}
|
|
9
6
|
if (prop.typeIndex === BINARY || prop.typeIndex === STRING) {
|
|
10
7
|
if (typeof value === 'string') {
|
|
11
8
|
const { written } = ENCODER.encodeInto(value, buf.subarray(offset + 1));
|
|
@@ -23,19 +20,18 @@ export const writeFixed = (prop, buf, value, size, offset) => {
|
|
|
23
20
|
}
|
|
24
21
|
else {
|
|
25
22
|
if (size === 8) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
if (prop.typeIndex === TIMESTAMP) {
|
|
24
|
+
writeInt64(buf, value, offset);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
writeDoubleLE(buf, value, offset);
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
else if (size === 4) {
|
|
31
|
-
buf
|
|
32
|
-
buf[offset + 1] = value >>> 8;
|
|
33
|
-
buf[offset + 2] = value >>> 16;
|
|
34
|
-
buf[offset + 3] = value >>> 24;
|
|
31
|
+
writeUint32(buf, value, offset);
|
|
35
32
|
}
|
|
36
33
|
else if (size === 2) {
|
|
37
|
-
buf
|
|
38
|
-
buf[offset + 1] = value >>> 8;
|
|
34
|
+
writeUint16(buf, value, offset);
|
|
39
35
|
}
|
|
40
36
|
else if (size === 1) {
|
|
41
37
|
buf[offset] = value;
|
|
@@ -54,24 +50,16 @@ export const createFixedFilterBuffer = (prop, size, ctx, value, sort) => {
|
|
|
54
50
|
? MODE_AND_FIXED
|
|
55
51
|
: MODE_OR_FIXED;
|
|
56
52
|
buf[2] = prop.typeIndex;
|
|
57
|
-
buf
|
|
58
|
-
buf
|
|
59
|
-
buf[5] = start;
|
|
60
|
-
buf[6] = start >>> 8;
|
|
53
|
+
writeUint16(buf, size, 3);
|
|
54
|
+
writeUint16(buf, start, 5);
|
|
61
55
|
buf[7] = ctx.operation;
|
|
62
|
-
buf
|
|
63
|
-
buf[9] = len >>> 8;
|
|
56
|
+
writeUint16(buf, len, 8);
|
|
64
57
|
buf[10] = ALIGNMENT_NOT_SET;
|
|
65
58
|
if (sort) {
|
|
66
59
|
value = new Uint32Array(value.map((v) => parseFilterValue(prop, v)));
|
|
67
60
|
value.sort();
|
|
68
61
|
for (let i = 0; i < len; i++) {
|
|
69
|
-
|
|
70
|
-
const val = value[i];
|
|
71
|
-
buf[off] = val;
|
|
72
|
-
buf[off + 1] = val >>> 8;
|
|
73
|
-
buf[off + 2] = val >>> 16;
|
|
74
|
-
buf[off + 3] = val >>> 24;
|
|
62
|
+
writeUint32(buf, value[i], 18 + i * size);
|
|
75
63
|
}
|
|
76
64
|
}
|
|
77
65
|
else {
|
|
@@ -86,10 +74,8 @@ export const createFixedFilterBuffer = (prop, size, ctx, value, sort) => {
|
|
|
86
74
|
buf[0] = ctx.type;
|
|
87
75
|
buf[1] = MODE_DEFAULT;
|
|
88
76
|
buf[2] = prop.typeIndex;
|
|
89
|
-
buf
|
|
90
|
-
buf
|
|
91
|
-
buf[5] = start;
|
|
92
|
-
buf[6] = start >>> 8;
|
|
77
|
+
writeUint16(buf, size, 3);
|
|
78
|
+
writeUint16(buf, start, 5);
|
|
93
79
|
buf[7] = ctx.operation;
|
|
94
80
|
writeFixed(prop, buf, parseFilterValue(prop, value), size, 8);
|
|
95
81
|
return buf;
|
|
@@ -1,39 +1,25 @@
|
|
|
1
1
|
import { ALIGNMENT_NOT_SET, MODE_REFERENCE } from './types.js';
|
|
2
|
+
import { writeUint16, writeUint32 } from '@based/utils';
|
|
2
3
|
export const createReferenceFilter = (prop, ctx, value) => {
|
|
3
|
-
if (prop.transform) {
|
|
4
|
-
value = prop.transform('filter', value);
|
|
5
|
-
}
|
|
6
4
|
const isArray = Array.isArray(value);
|
|
7
5
|
const len = isArray ? value.length : 1;
|
|
8
6
|
const buf = new Uint8Array(11 + (isArray ? 8 : 0) + len * 4);
|
|
9
7
|
buf[0] = ctx.type;
|
|
10
8
|
buf[1] = MODE_REFERENCE;
|
|
11
9
|
buf[2] = prop.typeIndex;
|
|
12
|
-
// size (4)
|
|
13
|
-
buf
|
|
14
|
-
buf[4] = 0;
|
|
15
|
-
buf[5] = len;
|
|
16
|
-
buf[6] = len >>> 8;
|
|
10
|
+
writeUint16(buf, 4, 3); // size (4)
|
|
11
|
+
writeUint16(buf, len, 5);
|
|
17
12
|
buf[7] = ctx.operation;
|
|
18
13
|
buf[8] = 0;
|
|
19
|
-
buf
|
|
20
|
-
buf[10] = prop.inverseTypeId >>> 8;
|
|
14
|
+
writeUint16(buf, prop.inverseTypeId, 9);
|
|
21
15
|
if (isArray) {
|
|
22
16
|
buf[11] = ALIGNMENT_NOT_SET;
|
|
23
17
|
for (let i = 0; i < len; i++) {
|
|
24
|
-
|
|
25
|
-
const v = value[i];
|
|
26
|
-
buf[off++] = v;
|
|
27
|
-
buf[off++] = v >>> 8;
|
|
28
|
-
buf[off++] = v >>> 16;
|
|
29
|
-
buf[off++] = v >>> 24;
|
|
18
|
+
writeUint32(buf, value[i], 19 + i * 4);
|
|
30
19
|
}
|
|
31
20
|
}
|
|
32
21
|
else {
|
|
33
|
-
buf
|
|
34
|
-
buf[12] = value >>> 8;
|
|
35
|
-
buf[13] = value >>> 16;
|
|
36
|
-
buf[14] = value >>> 24;
|
|
22
|
+
writeUint32(buf, value, 11);
|
|
37
23
|
}
|
|
38
24
|
return buf;
|
|
39
25
|
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { ALIAS, TEXT, VECTOR } from '@based/schema/def';
|
|
2
|
-
import { EQUAL, EQUAL_CRC32,
|
|
2
|
+
import { EQUAL, EQUAL_CRC32, INCLUDES, INCLUDES_TO_LOWER_CASE, LIKE, MODE_DEFAULT_VAR, MODE_OR_VAR, getVectorFn, } from './types.js';
|
|
3
3
|
import { createFixedFilterBuffer } from './createFixedFilterBuffer.js';
|
|
4
4
|
import { crc32 } from '../../crc32.js';
|
|
5
|
-
import { ENCODER, concatUint8Arr } from '@
|
|
5
|
+
import { ENCODER, concatUint8Arr, writeUint16, writeUint32 } from '@based/utils';
|
|
6
6
|
const DEFAULT_SCORE = new Uint8Array(new Float32Array([0.5]).buffer);
|
|
7
7
|
const parseValue = (value, prop, ctx, lang) => {
|
|
8
|
-
if (
|
|
9
|
-
value = prop.transform('filter', value);
|
|
10
|
-
}
|
|
11
|
-
if (ctx.operation === HAS_TO_LOWER_CASE && typeof value === 'string') {
|
|
8
|
+
if (ctx.operation === INCLUDES_TO_LOWER_CASE && typeof value === 'string') {
|
|
12
9
|
value = value.toLowerCase();
|
|
13
10
|
}
|
|
14
11
|
if (ctx.operation === LIKE && prop.typeIndex === VECTOR) {
|
|
@@ -68,15 +65,14 @@ export const createVariableFilterBuffer = (value, prop, ctx, lang) => {
|
|
|
68
65
|
if (Array.isArray(value)) {
|
|
69
66
|
if (ctx.operation !== EQUAL || !prop.separate) {
|
|
70
67
|
mode = MODE_OR_VAR;
|
|
71
|
-
const
|
|
68
|
+
const values = [];
|
|
72
69
|
for (const v of value) {
|
|
73
|
-
const
|
|
70
|
+
const parsedValue = parseValue(v, prop, ctx, lang);
|
|
74
71
|
const size = new Uint8Array(2);
|
|
75
|
-
size
|
|
76
|
-
size
|
|
77
|
-
x.push(size, a);
|
|
72
|
+
writeUint16(size, parsedValue.byteLength, 0);
|
|
73
|
+
values.push(size, parsedValue);
|
|
78
74
|
}
|
|
79
|
-
val = concatUint8Arr(
|
|
75
|
+
val = concatUint8Arr(values);
|
|
80
76
|
}
|
|
81
77
|
else {
|
|
82
78
|
const x = [];
|
|
@@ -90,9 +86,9 @@ export const createVariableFilterBuffer = (value, prop, ctx, lang) => {
|
|
|
90
86
|
val = parseValue(value, prop, ctx, lang);
|
|
91
87
|
}
|
|
92
88
|
if (ctx.operation === EQUAL ||
|
|
93
|
-
ctx.operation ===
|
|
89
|
+
ctx.operation === INCLUDES ||
|
|
94
90
|
ctx.operation === LIKE ||
|
|
95
|
-
ctx.operation ===
|
|
91
|
+
ctx.operation === INCLUDES_TO_LOWER_CASE) {
|
|
96
92
|
if (prop.separate) {
|
|
97
93
|
if (ctx.operation === EQUAL &&
|
|
98
94
|
prop.typeIndex !== ALIAS &&
|
|
@@ -102,14 +98,8 @@ export const createVariableFilterBuffer = (value, prop, ctx, lang) => {
|
|
|
102
98
|
const crc = crc32(val.slice(0, -fbLen));
|
|
103
99
|
const len = val.byteLength - fbLen;
|
|
104
100
|
const v = new Uint8Array(8 + fbLen);
|
|
105
|
-
v
|
|
106
|
-
v
|
|
107
|
-
v[2] = crc >>> 16;
|
|
108
|
-
v[3] = crc >>> 24;
|
|
109
|
-
v[4] = len;
|
|
110
|
-
v[5] = len >>> 8;
|
|
111
|
-
v[6] = len >>> 16;
|
|
112
|
-
v[7] = len >>> 24;
|
|
101
|
+
writeUint32(v, crc, 0);
|
|
102
|
+
writeUint32(v, len, 4);
|
|
113
103
|
for (let i = 0; i < fbLen; i++) {
|
|
114
104
|
v[v.byteLength - (i + 1)] = val[val.byteLength - (i + 1)];
|
|
115
105
|
}
|
|
@@ -142,17 +132,10 @@ function writeVarFilter(mode, val, ctx, prop, start, len) {
|
|
|
142
132
|
buf[0] = ctx.type;
|
|
143
133
|
buf[1] = mode;
|
|
144
134
|
buf[2] = prop.typeIndex;
|
|
145
|
-
buf
|
|
146
|
-
buf
|
|
147
|
-
buf
|
|
148
|
-
buf[6] = len >>> 8;
|
|
149
|
-
buf[7] = size;
|
|
150
|
-
buf[8] = size >>> 8;
|
|
151
|
-
buf[9] = size >>> 16;
|
|
152
|
-
buf[10] = size >>> 24;
|
|
135
|
+
writeUint16(buf, start, 3);
|
|
136
|
+
writeUint16(buf, len, 5);
|
|
137
|
+
writeUint32(buf, size, 7);
|
|
153
138
|
buf[11] = ctx.operation;
|
|
154
|
-
// need to pas LANG FROM QUERY
|
|
155
|
-
// need to set on 12 if TEXT
|
|
156
139
|
buf.set(val, 12);
|
|
157
140
|
return buf;
|
|
158
141
|
}
|
|
@@ -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, ENCODER } from '@
|
|
3
|
+
import { convertToTimestamp, ENCODER, writeUint32 } from '@based/utils';
|
|
4
4
|
// -------------------------------------------
|
|
5
5
|
// conditions normal
|
|
6
6
|
// field, [size 2]
|
|
@@ -20,16 +20,8 @@ export const parseFilterValue = (prop, value) => {
|
|
|
20
20
|
prop.typeIndex === TEXT) {
|
|
21
21
|
const b = value instanceof Uint8Array ? value : ENCODER.encode(value);
|
|
22
22
|
const buf = new Uint8Array(8);
|
|
23
|
-
|
|
24
|
-
buf
|
|
25
|
-
buf[1] = crc >>>= 8;
|
|
26
|
-
buf[2] = crc >>>= 8;
|
|
27
|
-
buf[3] = crc >>>= 8;
|
|
28
|
-
let len = b.byteLength;
|
|
29
|
-
buf[4] = len;
|
|
30
|
-
buf[5] = len >>>= 8;
|
|
31
|
-
buf[6] = len >>>= 8;
|
|
32
|
-
buf[7] = len >>>= 8;
|
|
23
|
+
writeUint32(buf, crc32(b), 0);
|
|
24
|
+
writeUint32(buf, b.byteLength, 4);
|
|
33
25
|
return buf;
|
|
34
26
|
}
|
|
35
27
|
else if (prop.typeIndex === BOOLEAN) {
|
|
@@ -38,7 +38,7 @@ export const primitiveFilter = (def, prop, filter, conditions, lang) => {
|
|
|
38
38
|
parsedCondition = createFixedFilterBuffer(prop, 4, ctx, value, !isNumerical(ctx.operation));
|
|
39
39
|
}
|
|
40
40
|
else if (prop.typeIndex === CARDINALITY) {
|
|
41
|
-
parsedCondition = createFixedFilterBuffer(prop,
|
|
41
|
+
parsedCondition = createFixedFilterBuffer(prop, 4, ctx, value, false);
|
|
42
42
|
}
|
|
43
43
|
else if (propSize) {
|
|
44
44
|
parsedCondition = createFixedFilterBuffer(prop, propSize, ctx, value, false);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { writeUint16, writeUint32 } from '@based/utils';
|
|
1
2
|
import { META_EDGE, META_EXISTS, META_OR_BRANCH, META_REFERENCE, TYPE_DEFAULT, TYPE_NEGATE, } from './types.js';
|
|
2
3
|
const writeConditions = (result, k, offset, conditions) => {
|
|
3
4
|
let lastWritten = offset;
|
|
@@ -11,8 +12,7 @@ const writeConditions = (result, k, offset, conditions) => {
|
|
|
11
12
|
result.set(condition, lastWritten);
|
|
12
13
|
lastWritten += condition.byteLength;
|
|
13
14
|
}
|
|
14
|
-
result
|
|
15
|
-
result[sizeIndex + 1] = conditionSize >>> 8;
|
|
15
|
+
writeUint16(result, conditionSize, sizeIndex);
|
|
16
16
|
return lastWritten - offset;
|
|
17
17
|
};
|
|
18
18
|
export const fillConditionsBuffer = (result, conditions, offset) => {
|
|
@@ -34,14 +34,12 @@ export const fillConditionsBuffer = (result, conditions, offset) => {
|
|
|
34
34
|
lastWritten++;
|
|
35
35
|
result[lastWritten] = refField;
|
|
36
36
|
lastWritten++;
|
|
37
|
-
result
|
|
38
|
-
result[lastWritten + 1] = refConditions.schema.id >>> 8;
|
|
37
|
+
writeUint16(result, refConditions.schema.id, lastWritten);
|
|
39
38
|
lastWritten += 2;
|
|
40
39
|
const sizeIndex = lastWritten;
|
|
41
40
|
lastWritten += 2;
|
|
42
41
|
const size = fillConditionsBuffer(result, refConditions, lastWritten);
|
|
43
|
-
result
|
|
44
|
-
result[sizeIndex + 1] = size >>> 8;
|
|
42
|
+
writeUint16(result, size, sizeIndex);
|
|
45
43
|
lastWritten += size;
|
|
46
44
|
}
|
|
47
45
|
}
|
|
@@ -53,18 +51,13 @@ export const fillConditionsBuffer = (result, conditions, offset) => {
|
|
|
53
51
|
lastWritten += 2;
|
|
54
52
|
const size = writeConditions(result, k, lastWritten, v);
|
|
55
53
|
lastWritten += size;
|
|
56
|
-
result
|
|
57
|
-
result[sizeIndex + 1] = size >>> 8;
|
|
54
|
+
writeUint16(result, size, sizeIndex);
|
|
58
55
|
});
|
|
59
56
|
}
|
|
60
57
|
if (conditions.or && conditions.or.size != 0) {
|
|
61
58
|
const size = fillConditionsBuffer(result, conditions.or, lastWritten);
|
|
62
|
-
result
|
|
63
|
-
result
|
|
64
|
-
result[orJumpIndex + 2] = lastWritten;
|
|
65
|
-
result[orJumpIndex + 3] = lastWritten >>> 8;
|
|
66
|
-
result[orJumpIndex + 4] = lastWritten >>> 16;
|
|
67
|
-
result[orJumpIndex + 5] = lastWritten >>> 24;
|
|
59
|
+
writeUint16(result, size, orJumpIndex);
|
|
60
|
+
writeUint32(result, lastWritten, orJumpIndex + 2);
|
|
68
61
|
lastWritten += size;
|
|
69
62
|
}
|
|
70
63
|
if (conditions.exists) {
|
|
@@ -86,7 +79,8 @@ export const isSimpleMainFilter = (conditions) => {
|
|
|
86
79
|
!conditions.edges &&
|
|
87
80
|
conditions.conditions.size === 1 &&
|
|
88
81
|
conditions.conditions.has(0) &&
|
|
89
|
-
!conditions.or
|
|
82
|
+
!conditions.or &&
|
|
83
|
+
!conditions.exists) {
|
|
90
84
|
return true;
|
|
91
85
|
}
|
|
92
86
|
return false;
|
|
@@ -4,15 +4,15 @@ export type Filter = [fieldStr: string, ctx: FilterCtx, value: any];
|
|
|
4
4
|
export type FilterBranchFn = (filterBranch: FilterBranch) => void;
|
|
5
5
|
export type FilterAst = (Filter | FilterAst)[];
|
|
6
6
|
export declare const IsFilter: (f: FilterAst) => f is Filter;
|
|
7
|
-
export type Operator = '=' | '
|
|
8
|
-
export declare const VECTOR_FNS: string[];
|
|
7
|
+
export type Operator = '=' | 'includes' | '!includes' | '<' | '>' | '!=' | 'like' | '>=' | '<=' | '..' | '!..' | 'like' | 'exists' | '!exists';
|
|
9
8
|
export type FilterOpts<O = Operator> = {
|
|
10
9
|
lowerCase?: boolean;
|
|
11
10
|
fn?: 'dotProduct' | 'manhattanDistance' | 'cosineSimilarity' | 'euclideanDistance';
|
|
12
11
|
score?: number;
|
|
13
12
|
};
|
|
13
|
+
export declare const VECTOR_FNS: string[];
|
|
14
14
|
export declare const EQUAL = 1;
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const INCLUDES = 2;
|
|
16
16
|
export declare const ENDS_WITH = 4;
|
|
17
17
|
export declare const STARTS_WITH = 5;
|
|
18
18
|
export declare const EQUAL_CRC32 = 17;
|
|
@@ -23,12 +23,12 @@ export declare const SMALLER_THAN_INCLUSIVE = 9;
|
|
|
23
23
|
export declare const RANGE = 10;
|
|
24
24
|
export declare const RANGE_EXCLUDE = 11;
|
|
25
25
|
export declare const EQUAL_LOWER_CASE = 12;
|
|
26
|
-
export declare const
|
|
26
|
+
export declare const INCLUDES_TO_LOWER_CASE = 13;
|
|
27
27
|
export declare const STARTS_WITH_LOWER_CASE = 14;
|
|
28
28
|
export declare const ENDS_WITH_LOWER_CASE = 15;
|
|
29
29
|
export declare const LIKE = 18;
|
|
30
30
|
export declare const EXISTS = 19;
|
|
31
|
-
export type OPERATOR = typeof EQUAL | typeof
|
|
31
|
+
export type OPERATOR = typeof EQUAL | typeof INCLUDES | typeof ENDS_WITH | typeof STARTS_WITH | typeof GREATER_THAN | typeof SMALLER_THAN | typeof GREATER_THAN_INCLUSIVE | typeof SMALLER_THAN_INCLUSIVE | typeof RANGE | typeof RANGE_EXCLUDE | typeof EQUAL_LOWER_CASE | typeof INCLUDES_TO_LOWER_CASE | typeof STARTS_WITH_LOWER_CASE | typeof ENDS_WITH_LOWER_CASE | typeof LIKE | typeof EQUAL_CRC32 | typeof EXISTS;
|
|
32
32
|
export declare const isNumerical: (op: OPERATOR) => boolean;
|
|
33
33
|
export declare const TYPE_NEGATE = 1;
|
|
34
34
|
export declare const TYPE_DEFAULT = 2;
|
|
@@ -54,7 +54,7 @@ export declare const VECTOR_DOT_PRODUCT = 0;
|
|
|
54
54
|
export declare const VECTOR_MANHATTAN_DIST = 1;
|
|
55
55
|
export declare const VECTOR_COSTINE_SIMILARITY = 2;
|
|
56
56
|
export declare const VECTOR_EUCLIDEAN_DIST = 3;
|
|
57
|
-
export declare const getVectorFn: (optsFn?: FilterOpts["fn"]) => 0 | 1 |
|
|
57
|
+
export declare const getVectorFn: (optsFn?: FilterOpts["fn"]) => 0 | 1 | 3 | 2;
|
|
58
58
|
export declare const toFilterCtx: (def: QueryDef, op: Operator, opts?: FilterOpts) => FilterCtx;
|
|
59
59
|
export declare const operatorReverseMap: Record<OPERATOR, string>;
|
|
60
60
|
export declare const ALIGNMENT_NOT_SET = 255;
|
|
@@ -14,7 +14,7 @@ export const VECTOR_FNS = [
|
|
|
14
14
|
// -------------------------------------------
|
|
15
15
|
// operations shared
|
|
16
16
|
export const EQUAL = 1;
|
|
17
|
-
export const
|
|
17
|
+
export const INCLUDES = 2;
|
|
18
18
|
export const ENDS_WITH = 4;
|
|
19
19
|
export const STARTS_WITH = 5;
|
|
20
20
|
export const EQUAL_CRC32 = 17;
|
|
@@ -29,12 +29,12 @@ export const RANGE_EXCLUDE = 11;
|
|
|
29
29
|
// -------------------------------------------
|
|
30
30
|
// operations strings
|
|
31
31
|
export const EQUAL_LOWER_CASE = 12;
|
|
32
|
-
export const
|
|
32
|
+
export const INCLUDES_TO_LOWER_CASE = 13;
|
|
33
33
|
export const STARTS_WITH_LOWER_CASE = 14;
|
|
34
34
|
export const ENDS_WITH_LOWER_CASE = 15;
|
|
35
35
|
export const LIKE = 18;
|
|
36
36
|
// -------------------------------------------
|
|
37
|
-
// only valid for
|
|
37
|
+
// only valid for separate fields
|
|
38
38
|
export const EXISTS = 19;
|
|
39
39
|
// -------------------------------------------
|
|
40
40
|
export const isNumerical = (op) => {
|
|
@@ -99,10 +99,10 @@ export const toFilterCtx = (def, op, opts = {}) => {
|
|
|
99
99
|
opts,
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
if (op === '
|
|
102
|
+
if (op === 'includes' || op === '!includes') {
|
|
103
103
|
return {
|
|
104
|
-
operation: opts.lowerCase ?
|
|
105
|
-
type: op === '!
|
|
104
|
+
operation: opts.lowerCase ? INCLUDES_TO_LOWER_CASE : INCLUDES,
|
|
105
|
+
type: op === '!includes' ? TYPE_NEGATE : TYPE_DEFAULT,
|
|
106
106
|
opts,
|
|
107
107
|
};
|
|
108
108
|
}
|
|
@@ -125,7 +125,7 @@ export const toFilterCtx = (def, op, opts = {}) => {
|
|
|
125
125
|
};
|
|
126
126
|
export const operatorReverseMap = {
|
|
127
127
|
[EQUAL]: '=',
|
|
128
|
-
[
|
|
128
|
+
[INCLUDES]: 'includes',
|
|
129
129
|
[ENDS_WITH]: 'endsWith',
|
|
130
130
|
[STARTS_WITH]: 'startsWith',
|
|
131
131
|
[GREATER_THAN]: '>',
|
|
@@ -135,7 +135,7 @@ export const operatorReverseMap = {
|
|
|
135
135
|
[RANGE]: '..',
|
|
136
136
|
[RANGE_EXCLUDE]: '!..',
|
|
137
137
|
[EQUAL_LOWER_CASE]: '= (lowerCase)',
|
|
138
|
-
[
|
|
138
|
+
[INCLUDES_TO_LOWER_CASE]: 'includes (lowerCase)',
|
|
139
139
|
[STARTS_WITH_LOWER_CASE]: 'startsWith (lowerCase)',
|
|
140
140
|
[ENDS_WITH_LOWER_CASE]: 'endsWith (lowerCase)',
|
|
141
141
|
[LIKE]: 'like',
|