@based/db 0.0.71 → 0.1.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/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 +30 -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 +31 -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,19 +1,18 @@
|
|
|
1
|
-
import { filter, sort, filterOr, isAlias,
|
|
2
|
-
import { BasedQueryResponse } from './
|
|
3
|
-
import { createOrGetEdgeRefQueryDef, createOrGetRefQueryDef, } from './include/utils.js';
|
|
1
|
+
import { filter, sort, filterOr, isAlias, addAggregate, groupBy, } from './query.js';
|
|
2
|
+
import { BasedQueryResponse } from './BasedQueryResponse.js';
|
|
4
3
|
import { FilterBranch } from './filter/FilterBranch.js';
|
|
5
4
|
import { search, vectorSearch } from './search/index.js';
|
|
6
5
|
import native from '../../native.js';
|
|
7
|
-
import { REFERENCE, REFERENCES } from '@based/schema/def';
|
|
8
6
|
import { subscribe } from './subscription/index.js';
|
|
9
7
|
import { registerQuery } from './registerQuery.js';
|
|
10
8
|
import { langCodesMap } from '@based/schema';
|
|
11
9
|
import { convertFilter } from './filter/convertFilter.js';
|
|
12
10
|
import { validateLocale, validateRange } from './validation.js';
|
|
13
11
|
import { DEF_RANGE_PROP_LIMIT } from './thresholds.js';
|
|
14
|
-
import { AggregateType } from './aggregates/types.js';
|
|
15
12
|
import { displayTarget } from './display.js';
|
|
16
13
|
import picocolors from 'picocolors';
|
|
14
|
+
import { include } from './include/include.js';
|
|
15
|
+
import { AggregateType } from '@based/protocol/db-read';
|
|
17
16
|
export class QueryBranch {
|
|
18
17
|
db;
|
|
19
18
|
def;
|
|
@@ -43,7 +42,7 @@ export class QueryBranch {
|
|
|
43
42
|
});
|
|
44
43
|
}
|
|
45
44
|
else {
|
|
46
|
-
const f = convertFilter(this
|
|
45
|
+
const f = convertFilter(this, field, operator, value, opts);
|
|
47
46
|
if (!f) {
|
|
48
47
|
// @ts-ignore
|
|
49
48
|
return this;
|
|
@@ -53,19 +52,6 @@ export class QueryBranch {
|
|
|
53
52
|
// @ts-ignore
|
|
54
53
|
return this;
|
|
55
54
|
}
|
|
56
|
-
filterBatch(f) {
|
|
57
|
-
if (this.queryCommands) {
|
|
58
|
-
this.queryCommands.push({
|
|
59
|
-
method: 'filterBatch',
|
|
60
|
-
args: [f],
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
filter(this.db, this.def, f, this.def.filter);
|
|
65
|
-
}
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
55
|
search(query, field, opts, ...fields) {
|
|
70
56
|
if (this.queryCommands) {
|
|
71
57
|
this.queryCommands.push({
|
|
@@ -102,7 +88,7 @@ export class QueryBranch {
|
|
|
102
88
|
}
|
|
103
89
|
if (fields.length) {
|
|
104
90
|
if (fields.length === 1) {
|
|
105
|
-
search(this
|
|
91
|
+
search(this, query, fields[0]);
|
|
106
92
|
}
|
|
107
93
|
else {
|
|
108
94
|
const s = {};
|
|
@@ -119,31 +105,37 @@ export class QueryBranch {
|
|
|
119
105
|
Object.assign(s, f);
|
|
120
106
|
}
|
|
121
107
|
}
|
|
122
|
-
search(this
|
|
108
|
+
search(this, query, s);
|
|
123
109
|
}
|
|
124
110
|
}
|
|
125
111
|
else {
|
|
126
|
-
search(this
|
|
112
|
+
search(this, query);
|
|
127
113
|
}
|
|
128
114
|
}
|
|
129
115
|
// @ts-ignore
|
|
130
116
|
return this;
|
|
131
117
|
}
|
|
132
|
-
groupBy(field) {
|
|
118
|
+
groupBy(field, step) {
|
|
133
119
|
if (this.queryCommands) {
|
|
134
120
|
this.queryCommands.push({
|
|
135
121
|
method: 'groupBy',
|
|
136
|
-
args: [field],
|
|
122
|
+
args: [field, step],
|
|
137
123
|
});
|
|
138
124
|
}
|
|
139
125
|
else {
|
|
140
|
-
|
|
126
|
+
const groupByHook = this.def.schema.hooks?.groupBy;
|
|
127
|
+
if (groupByHook) {
|
|
128
|
+
this.def.schema.hooks.groupBy = null;
|
|
129
|
+
groupByHook(this, field);
|
|
130
|
+
this.def.schema.hooks.groupBy = groupByHook;
|
|
131
|
+
}
|
|
132
|
+
groupBy(this.def, field, step);
|
|
141
133
|
}
|
|
142
134
|
// only works with aggregates for now
|
|
143
135
|
// @ts-ignore
|
|
144
136
|
return this;
|
|
145
137
|
}
|
|
146
|
-
count(field = '
|
|
138
|
+
count(field = 'count') {
|
|
147
139
|
if (this.queryCommands) {
|
|
148
140
|
this.queryCommands.push({
|
|
149
141
|
method: 'count',
|
|
@@ -152,7 +144,7 @@ export class QueryBranch {
|
|
|
152
144
|
}
|
|
153
145
|
else {
|
|
154
146
|
const p = field.split('.');
|
|
155
|
-
addAggregate(AggregateType.COUNT,
|
|
147
|
+
addAggregate(this, AggregateType.COUNT, p);
|
|
156
148
|
}
|
|
157
149
|
// @ts-ignore
|
|
158
150
|
return this;
|
|
@@ -168,7 +160,7 @@ export class QueryBranch {
|
|
|
168
160
|
});
|
|
169
161
|
}
|
|
170
162
|
else {
|
|
171
|
-
addAggregate(AggregateType.SUM,
|
|
163
|
+
addAggregate(this, AggregateType.SUM, fields);
|
|
172
164
|
}
|
|
173
165
|
// @ts-ignore
|
|
174
166
|
return this;
|
|
@@ -184,39 +176,61 @@ export class QueryBranch {
|
|
|
184
176
|
});
|
|
185
177
|
}
|
|
186
178
|
else {
|
|
187
|
-
addAggregate(AggregateType.CARDINALITY,
|
|
179
|
+
addAggregate(this, AggregateType.CARDINALITY, [field]);
|
|
188
180
|
}
|
|
189
181
|
// @ts-ignore
|
|
190
182
|
return this;
|
|
191
183
|
}
|
|
192
|
-
stddev(...
|
|
193
|
-
if (fields.length === 0) {
|
|
194
|
-
throw new Error('Empty standard deviation function called');
|
|
195
|
-
}
|
|
184
|
+
stddev(...args) {
|
|
196
185
|
if (this.queryCommands) {
|
|
197
186
|
this.queryCommands.push({
|
|
198
187
|
method: 'stddev',
|
|
199
|
-
args
|
|
188
|
+
args,
|
|
200
189
|
});
|
|
201
190
|
}
|
|
202
191
|
else {
|
|
203
|
-
|
|
192
|
+
let option = {};
|
|
193
|
+
let fields;
|
|
194
|
+
const lastArg = args[args.length - 1];
|
|
195
|
+
const lastArgIsOptions = typeof lastArg === 'object' && lastArg !== null;
|
|
196
|
+
if (lastArgIsOptions) {
|
|
197
|
+
option = lastArg;
|
|
198
|
+
fields = args.slice(0, -1);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
fields = args;
|
|
202
|
+
}
|
|
203
|
+
if (fields.length === 0) {
|
|
204
|
+
throw new Error('Empty standard deviation function called');
|
|
205
|
+
}
|
|
206
|
+
addAggregate(this, AggregateType.STDDEV, fields, option);
|
|
204
207
|
}
|
|
205
208
|
// @ts-ignore
|
|
206
209
|
return this;
|
|
207
210
|
}
|
|
208
|
-
var(...
|
|
209
|
-
if (fields.length === 0) {
|
|
210
|
-
throw new Error('Empty variance function called');
|
|
211
|
-
}
|
|
211
|
+
var(...args) {
|
|
212
212
|
if (this.queryCommands) {
|
|
213
213
|
this.queryCommands.push({
|
|
214
214
|
method: 'var',
|
|
215
|
-
args
|
|
215
|
+
args,
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
218
|
else {
|
|
219
|
-
|
|
219
|
+
let option = {};
|
|
220
|
+
let fields = [];
|
|
221
|
+
const lastArg = args[args.length - 1];
|
|
222
|
+
const lastArgIsOptions = typeof lastArg === 'object' && lastArg !== null;
|
|
223
|
+
if (lastArgIsOptions) {
|
|
224
|
+
option = lastArg;
|
|
225
|
+
fields = args.slice(0, -1);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
fields = args;
|
|
229
|
+
}
|
|
230
|
+
if (fields.length === 0) {
|
|
231
|
+
throw new Error('Empty variance called');
|
|
232
|
+
}
|
|
233
|
+
addAggregate(this, AggregateType.VARIANCE, fields, option);
|
|
220
234
|
}
|
|
221
235
|
// @ts-ignore
|
|
222
236
|
return this;
|
|
@@ -232,7 +246,23 @@ export class QueryBranch {
|
|
|
232
246
|
});
|
|
233
247
|
}
|
|
234
248
|
else {
|
|
235
|
-
addAggregate(AggregateType.AVERAGE,
|
|
249
|
+
addAggregate(this, AggregateType.AVERAGE, fields);
|
|
250
|
+
}
|
|
251
|
+
// @ts-ignore
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
harmonicMean(...fields) {
|
|
255
|
+
if (fields.length === 0) {
|
|
256
|
+
throw new Error('Empty harmonic mean function called');
|
|
257
|
+
}
|
|
258
|
+
if (this.queryCommands) {
|
|
259
|
+
this.queryCommands.push({
|
|
260
|
+
method: 'harmonicMean',
|
|
261
|
+
args: fields,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
addAggregate(this, AggregateType.HMEAN, fields);
|
|
236
266
|
}
|
|
237
267
|
// @ts-ignore
|
|
238
268
|
return this;
|
|
@@ -248,7 +278,7 @@ export class QueryBranch {
|
|
|
248
278
|
});
|
|
249
279
|
}
|
|
250
280
|
else {
|
|
251
|
-
addAggregate(AggregateType.MAX,
|
|
281
|
+
addAggregate(this, AggregateType.MAX, fields);
|
|
252
282
|
}
|
|
253
283
|
// @ts-ignore
|
|
254
284
|
return this;
|
|
@@ -264,7 +294,7 @@ export class QueryBranch {
|
|
|
264
294
|
});
|
|
265
295
|
}
|
|
266
296
|
else {
|
|
267
|
-
addAggregate(AggregateType.MIN,
|
|
297
|
+
addAggregate(this, AggregateType.MIN, fields);
|
|
268
298
|
}
|
|
269
299
|
// @ts-ignore
|
|
270
300
|
return this;
|
|
@@ -283,7 +313,7 @@ export class QueryBranch {
|
|
|
283
313
|
this.def.filter.size += f.filterBranch.size;
|
|
284
314
|
}
|
|
285
315
|
else {
|
|
286
|
-
const f = convertFilter(this
|
|
316
|
+
const f = convertFilter(this, field, operator, value, opts);
|
|
287
317
|
if (f) {
|
|
288
318
|
filterOr(this.db, this.def, f, this.def.filter);
|
|
289
319
|
}
|
|
@@ -316,49 +346,12 @@ export class QueryBranch {
|
|
|
316
346
|
this.queryCommands.push({ method: 'include', args: fields });
|
|
317
347
|
}
|
|
318
348
|
else {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (field[0] == '$') {
|
|
326
|
-
// @ts-ignore
|
|
327
|
-
const prop = this.def.target?.propDef?.edges[field];
|
|
328
|
-
if (prop &&
|
|
329
|
-
(prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES)) {
|
|
330
|
-
const refDef = createOrGetEdgeRefQueryDef(this.db, this.def, prop);
|
|
331
|
-
// @ts-ignore
|
|
332
|
-
return new QueryBranch(this.db, refDef);
|
|
333
|
-
}
|
|
334
|
-
throw new Error(`No edge reference or edge references field named "${field}"`);
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
const prop = field[0] == '$'
|
|
338
|
-
? // @ts-ignore
|
|
339
|
-
this.def.target?.propDef?.edges[field]
|
|
340
|
-
: this.def.props[field];
|
|
341
|
-
if (prop &&
|
|
342
|
-
(prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES)) {
|
|
343
|
-
const refDef = createOrGetRefQueryDef(this.db, this.def, prop);
|
|
344
|
-
// @ts-ignore
|
|
345
|
-
return new QueryBranch(this.db, refDef);
|
|
346
|
-
}
|
|
347
|
-
throw new Error(`No reference or references field named "${field}"`);
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
else if (Array.isArray(f)) {
|
|
352
|
-
if (f.length === 0) {
|
|
353
|
-
includeFields(this.def, ['id']);
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
includeFields(this.def, f);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else if (f !== undefined) {
|
|
360
|
-
throw new Error('Invalid include statement: expected props, refs and edges (string or array) or function');
|
|
361
|
-
}
|
|
349
|
+
include(this, fields);
|
|
350
|
+
const includeHook = this.def.schema.hooks?.include;
|
|
351
|
+
if (includeHook) {
|
|
352
|
+
this.def.schema.hooks.include = null;
|
|
353
|
+
includeHook(this, this.def.include.stringFields);
|
|
354
|
+
this.def.schema.hooks.include = includeHook;
|
|
362
355
|
}
|
|
363
356
|
}
|
|
364
357
|
// @ts-ignore
|
|
@@ -367,14 +360,14 @@ export class QueryBranch {
|
|
|
367
360
|
}
|
|
368
361
|
export class BasedDbReferenceQuery extends QueryBranch {
|
|
369
362
|
}
|
|
370
|
-
const resToJSON = (res) => res.toJSON();
|
|
363
|
+
const resToJSON = (res, replacer, space) => res.toJSON(replacer, space);
|
|
371
364
|
const resToObject = (res) => res.toObject();
|
|
372
365
|
class GetPromise extends Promise {
|
|
373
366
|
toObject() {
|
|
374
367
|
return this.then(resToObject);
|
|
375
368
|
}
|
|
376
|
-
toJSON() {
|
|
377
|
-
return this.then(resToJSON);
|
|
369
|
+
toJSON(replacer, space) {
|
|
370
|
+
return this.then((res) => resToJSON(res, replacer, space));
|
|
378
371
|
}
|
|
379
372
|
inspect(depth, raw) {
|
|
380
373
|
return this.then((res) => new GetPromise((resolve) => resolve(res.inspect(depth, raw))));
|
|
@@ -383,6 +376,7 @@ class GetPromise extends Promise {
|
|
|
383
376
|
export class BasedDbQuery extends QueryBranch {
|
|
384
377
|
skipValidation = false;
|
|
385
378
|
target;
|
|
379
|
+
readSchema;
|
|
386
380
|
constructor(db, type, rawTarget, skipValidation) {
|
|
387
381
|
const target = {
|
|
388
382
|
type,
|
|
@@ -419,6 +413,9 @@ export class BasedDbQuery extends QueryBranch {
|
|
|
419
413
|
if (!this.db.schema) {
|
|
420
414
|
await this.db.once('schema');
|
|
421
415
|
}
|
|
416
|
+
if ('id' in this.target) {
|
|
417
|
+
this.target.id = await this.target.id;
|
|
418
|
+
}
|
|
422
419
|
buf = registerQuery(this);
|
|
423
420
|
}
|
|
424
421
|
catch (err) {
|
|
@@ -456,7 +453,7 @@ export class BasedDbQuery extends QueryBranch {
|
|
|
456
453
|
reject(res);
|
|
457
454
|
}
|
|
458
455
|
else {
|
|
459
|
-
resolve(new BasedQueryResponse(this.
|
|
456
|
+
resolve(new BasedQueryResponse(this.def, res, performance.now() - d));
|
|
460
457
|
}
|
|
461
458
|
};
|
|
462
459
|
// if !id not initialized yet
|
|
@@ -514,7 +511,7 @@ export class BasedDbQuery extends QueryBranch {
|
|
|
514
511
|
const buf = registerQuery(this);
|
|
515
512
|
const d = performance.now();
|
|
516
513
|
const res = native.getQueryBuf(buf, dbCtxExternal);
|
|
517
|
-
return new BasedQueryResponse(this.
|
|
514
|
+
return new BasedQueryResponse(this.def, new Uint8Array(res), performance.now() - d);
|
|
518
515
|
}
|
|
519
516
|
}
|
|
520
517
|
//# sourceMappingURL=BasedDbQuery.js.map
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
2
|
import { QueryDef } from './types.js';
|
|
3
|
-
import { Item } from './query.js';
|
|
4
3
|
import { size, time, inspectData } from './display.js';
|
|
4
|
+
import { Item } from '@based/protocol/db-read';
|
|
5
5
|
export { time, size, inspectData };
|
|
6
6
|
export declare class BasedQueryResponse {
|
|
7
7
|
result: Uint8Array;
|
|
8
8
|
def: QueryDef;
|
|
9
9
|
execTime: number;
|
|
10
10
|
end: number;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
constructor(def: QueryDef, result: Uint8Array, execTime: number, end?: number);
|
|
12
|
+
get id(): number;
|
|
13
|
+
get queryId(): number;
|
|
13
14
|
get version(): number;
|
|
14
15
|
get size(): number;
|
|
15
16
|
[inspect.custom](depth: number): string;
|
|
@@ -22,6 +23,6 @@ export declare class BasedQueryResponse {
|
|
|
22
23
|
get checksum(): number;
|
|
23
24
|
get length(): number;
|
|
24
25
|
toObject(): any;
|
|
25
|
-
toJSON(): string;
|
|
26
|
+
toJSON(replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
|
|
26
27
|
toString(): string;
|
|
27
28
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
2
|
import picocolors from 'picocolors';
|
|
3
|
-
import { debug
|
|
3
|
+
import { debug } from './query.js';
|
|
4
4
|
import { size, time, inspectData, defHasId, displayTarget } from './display.js';
|
|
5
|
-
import { readFloatLE, readUint32 } from '@
|
|
5
|
+
import { readFloatLE, readUint32 } from '@based/utils';
|
|
6
|
+
import { resultToObject, readProps, readId, } from '@based/protocol/db-read';
|
|
6
7
|
export { time, size, inspectData };
|
|
7
8
|
const BITS_FOR_BYTE_LEN = 21;
|
|
8
9
|
const FACTOR = 2 ** BITS_FOR_BYTE_LEN;
|
|
@@ -12,14 +13,18 @@ export class BasedQueryResponse {
|
|
|
12
13
|
def;
|
|
13
14
|
execTime;
|
|
14
15
|
end;
|
|
15
|
-
|
|
16
|
-
constructor(id, def, result, execTime, end = result.length) {
|
|
17
|
-
this.id = id;
|
|
16
|
+
constructor(def, result, execTime, end = result.length) {
|
|
18
17
|
this.def = def;
|
|
19
18
|
this.result = result;
|
|
20
19
|
this.execTime = execTime;
|
|
21
20
|
this.end = end;
|
|
22
21
|
}
|
|
22
|
+
get id() {
|
|
23
|
+
return readId(this.def.readSchema, this.result);
|
|
24
|
+
}
|
|
25
|
+
get queryId() {
|
|
26
|
+
return this.def.queryId;
|
|
27
|
+
}
|
|
23
28
|
get version() {
|
|
24
29
|
return (this.checksum >>> 0) * FACTOR + (this.result.byteLength & MASK_B);
|
|
25
30
|
}
|
|
@@ -72,7 +77,7 @@ export class BasedQueryResponse {
|
|
|
72
77
|
item.$searchScore = readFloatLE(result, i);
|
|
73
78
|
i += 4;
|
|
74
79
|
}
|
|
75
|
-
const l =
|
|
80
|
+
const l = readProps(this.def.readSchema, result, i, result.byteLength - 4, item);
|
|
76
81
|
i += l;
|
|
77
82
|
yield item;
|
|
78
83
|
}
|
|
@@ -110,14 +115,14 @@ export class BasedQueryResponse {
|
|
|
110
115
|
return l;
|
|
111
116
|
}
|
|
112
117
|
toObject() {
|
|
113
|
-
return resultToObject(this.def, this.result, this.end - 4, 0);
|
|
118
|
+
return resultToObject(this.def.readSchema, this.result, this.end - 4, 0);
|
|
114
119
|
}
|
|
115
|
-
toJSON() {
|
|
120
|
+
toJSON(replacer, space) {
|
|
116
121
|
// TODO: optimize
|
|
117
|
-
return JSON.stringify(this.toObject());
|
|
122
|
+
return JSON.stringify(this.toObject(), replacer, space);
|
|
118
123
|
}
|
|
119
124
|
toString() {
|
|
120
125
|
return this.toJSON();
|
|
121
126
|
}
|
|
122
127
|
}
|
|
123
|
-
//# sourceMappingURL=
|
|
128
|
+
//# sourceMappingURL=BasedQueryResponse.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { QueryDef, QueryDefAggregation } from '../types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { StepInput, aggFnOptions } from './types.js';
|
|
3
|
+
import { QueryBranch } from '../BasedDbQuery.js';
|
|
4
|
+
import { AggregateType } from '@based/protocol/db-read';
|
|
3
5
|
export declare const aggregateToBuffer: (aggregates: QueryDefAggregation) => Uint8Array;
|
|
4
|
-
export declare const groupBy: (def: QueryDef, field: string) => void;
|
|
5
|
-
export declare const addAggregate: (
|
|
6
|
+
export declare const groupBy: (def: QueryDef, field: string, StepInput: StepInput) => void;
|
|
7
|
+
export declare const addAggregate: (query: QueryBranch<any>, type: AggregateType, fields: string[], option?: aggFnOptions) => void;
|
|
6
8
|
export declare const isRootCountOnly: (def: QueryDef, filterSize: number) => boolean;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { writeUint16 } from '@
|
|
1
|
+
import { writeUint16, writeInt16, writeUint32 } from '@based/utils';
|
|
2
2
|
import { QueryDefType } from '../types.js';
|
|
3
|
-
import {
|
|
3
|
+
import { setMode } from './types.js';
|
|
4
4
|
import { UINT32 } from '@based/schema/def';
|
|
5
|
-
import { aggregationFieldDoesNotExist } from '../validation.js';
|
|
6
|
-
import { aggregateTypeMap } from '../aggregates/types.js';
|
|
5
|
+
import { aggregationFieldDoesNotExist, validateStepRange, } from '../validation.js';
|
|
6
|
+
import { aggregateTypeMap, Interval, } from '../aggregates/types.js';
|
|
7
|
+
import { AggregateType } from '@based/protocol/db-read';
|
|
7
8
|
export const aggregateToBuffer = (aggregates) => {
|
|
8
9
|
const aggBuffer = new Uint8Array(aggregates.size);
|
|
9
10
|
let i = 0;
|
|
@@ -18,6 +19,12 @@ export const aggregateToBuffer = (aggregates) => {
|
|
|
18
19
|
i += 2;
|
|
19
20
|
writeUint16(aggBuffer, aggregates.groupBy.len, i);
|
|
20
21
|
i += 2;
|
|
22
|
+
aggBuffer[i] = aggregates.groupBy.stepType || 0;
|
|
23
|
+
i += 1;
|
|
24
|
+
writeUint32(aggBuffer, aggregates.groupBy.stepRange || 0, i);
|
|
25
|
+
i += 4;
|
|
26
|
+
writeInt16(aggBuffer, aggregates.groupBy.tz || 0, i);
|
|
27
|
+
i += 2;
|
|
21
28
|
}
|
|
22
29
|
else {
|
|
23
30
|
aggBuffer[i] = 0 /* GroupBy.NONE */;
|
|
@@ -27,6 +34,8 @@ export const aggregateToBuffer = (aggregates) => {
|
|
|
27
34
|
i += 2;
|
|
28
35
|
writeUint16(aggBuffer, aggregates.totalAccumulatorSize, i);
|
|
29
36
|
i += 2;
|
|
37
|
+
aggBuffer[i] = setMode[aggregates?.option?.mode] || 0;
|
|
38
|
+
i += 1;
|
|
30
39
|
for (const [prop, aggregatesArray] of aggregates.aggregates.entries()) {
|
|
31
40
|
aggBuffer[i] = prop;
|
|
32
41
|
i += 1;
|
|
@@ -54,71 +63,100 @@ export const aggregateToBuffer = (aggregates) => {
|
|
|
54
63
|
const ensureAggregate = (def) => {
|
|
55
64
|
if (!def.aggregate) {
|
|
56
65
|
def.aggregate = {
|
|
57
|
-
size:
|
|
66
|
+
size: 7,
|
|
58
67
|
aggregates: new Map(),
|
|
59
68
|
totalResultsSize: 0,
|
|
60
69
|
totalAccumulatorSize: 0,
|
|
61
70
|
};
|
|
62
71
|
}
|
|
63
72
|
};
|
|
64
|
-
export const groupBy = (def, field) => {
|
|
73
|
+
export const groupBy = (def, field, StepInput) => {
|
|
65
74
|
const fieldDef = def.schema.props[field];
|
|
66
75
|
if (!fieldDef) {
|
|
67
76
|
aggregationFieldDoesNotExist(def, field);
|
|
68
77
|
}
|
|
69
78
|
ensureAggregate(def);
|
|
70
79
|
if (!def.aggregate.groupBy) {
|
|
71
|
-
def.aggregate.size +=
|
|
80
|
+
def.aggregate.size += 12;
|
|
72
81
|
}
|
|
73
82
|
def.aggregate.groupBy = fieldDef;
|
|
83
|
+
def.aggregate.groupBy.stepRange = undefined;
|
|
84
|
+
def.aggregate.groupBy.stepType = undefined;
|
|
85
|
+
def.aggregate.groupBy.tz = undefined;
|
|
86
|
+
def.aggregate.groupBy.display = undefined;
|
|
87
|
+
if (typeof StepInput === 'object' &&
|
|
88
|
+
StepInput !== null &&
|
|
89
|
+
'step' in StepInput) {
|
|
90
|
+
if (typeof StepInput.timeZone == 'string') {
|
|
91
|
+
def.aggregate.groupBy.tz = getTimeZoneOffsetInMinutes(StepInput.timeZone);
|
|
92
|
+
}
|
|
93
|
+
if (typeof StepInput?.step == 'string') {
|
|
94
|
+
const intervalEnumKey = StepInput.step;
|
|
95
|
+
def.aggregate.groupBy.stepType = Interval[intervalEnumKey];
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
validateStepRange(def, StepInput?.step);
|
|
99
|
+
def.aggregate.groupBy.stepRange = StepInput.step;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (typeof StepInput == 'number') {
|
|
103
|
+
validateStepRange(def, StepInput);
|
|
104
|
+
def.aggregate.groupBy.stepRange = StepInput;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const intervalEnumKey = StepInput;
|
|
108
|
+
def.aggregate.groupBy.stepType = Interval[intervalEnumKey];
|
|
109
|
+
}
|
|
110
|
+
if (typeof StepInput === 'object' && StepInput?.display) {
|
|
111
|
+
def.aggregate.groupBy.display = StepInput?.display;
|
|
112
|
+
}
|
|
74
113
|
};
|
|
75
|
-
export const addAggregate = (type,
|
|
114
|
+
export const addAggregate = (query, type, fields, option) => {
|
|
115
|
+
const def = query.def;
|
|
116
|
+
def.schema.hooks?.aggregate?.(def, new Set(fields));
|
|
76
117
|
ensureAggregate(def);
|
|
118
|
+
if (option?.mode)
|
|
119
|
+
def.aggregate.option = option;
|
|
77
120
|
const aggregates = def.aggregate.aggregates;
|
|
78
121
|
for (const field of fields) {
|
|
79
|
-
|
|
80
|
-
|
|
122
|
+
const fieldDef = type === AggregateType.COUNT
|
|
123
|
+
? {
|
|
124
|
+
prop: 255,
|
|
125
|
+
path: [field],
|
|
126
|
+
__isPropDef: true,
|
|
127
|
+
len: 4,
|
|
128
|
+
start: 0,
|
|
129
|
+
typeIndex: UINT32,
|
|
130
|
+
separate: true,
|
|
131
|
+
validation: () => true,
|
|
132
|
+
default: 0,
|
|
133
|
+
}
|
|
134
|
+
: def.schema.props[field];
|
|
135
|
+
if (!fieldDef) {
|
|
136
|
+
aggregationFieldDoesNotExist(def, field);
|
|
137
|
+
}
|
|
138
|
+
if (!aggregates.get(fieldDef.prop)) {
|
|
139
|
+
aggregates.set(fieldDef.prop, []);
|
|
140
|
+
def.aggregate.size += 3;
|
|
141
|
+
}
|
|
142
|
+
const aggregateField = aggregates.get(fieldDef.prop);
|
|
143
|
+
aggregateField.push({
|
|
144
|
+
propDef: fieldDef,
|
|
145
|
+
type,
|
|
146
|
+
resultPos: def.aggregate.totalResultsSize,
|
|
147
|
+
accumulatorPos: def.aggregate.totalAccumulatorSize,
|
|
148
|
+
});
|
|
149
|
+
const specificSizes = aggregateTypeMap.get(type);
|
|
150
|
+
if (specificSizes) {
|
|
151
|
+
def.aggregate.totalResultsSize += specificSizes.resultsSize;
|
|
152
|
+
def.aggregate.totalAccumulatorSize += specificSizes.accumulatorSize;
|
|
81
153
|
}
|
|
82
154
|
else {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
prop: 255,
|
|
86
|
-
path: [field],
|
|
87
|
-
__isPropDef: true,
|
|
88
|
-
len: 4,
|
|
89
|
-
start: 0,
|
|
90
|
-
typeIndex: UINT32,
|
|
91
|
-
separate: true,
|
|
92
|
-
validation: () => true,
|
|
93
|
-
default: 0,
|
|
94
|
-
}
|
|
95
|
-
: def.schema.props[field];
|
|
96
|
-
if (!fieldDef) {
|
|
97
|
-
aggregationFieldDoesNotExist(def, field);
|
|
98
|
-
}
|
|
99
|
-
if (!aggregates.get(fieldDef.prop)) {
|
|
100
|
-
aggregates.set(fieldDef.prop, []);
|
|
101
|
-
def.aggregate.size += 3;
|
|
102
|
-
}
|
|
103
|
-
const aggregateField = aggregates.get(fieldDef.prop);
|
|
104
|
-
aggregateField.push({
|
|
105
|
-
propDef: fieldDef,
|
|
106
|
-
type,
|
|
107
|
-
resultPos: def.aggregate.totalResultsSize,
|
|
108
|
-
accumulatorPos: def.aggregate.totalAccumulatorSize,
|
|
109
|
-
});
|
|
110
|
-
const specificSizes = aggregateTypeMap.get(type);
|
|
111
|
-
if (specificSizes) {
|
|
112
|
-
def.aggregate.totalResultsSize += specificSizes.resultsSize;
|
|
113
|
-
def.aggregate.totalAccumulatorSize += specificSizes.accumulatorSize;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
def.aggregate.totalResultsSize += 8;
|
|
117
|
-
def.aggregate.totalAccumulatorSize += 8;
|
|
118
|
-
}
|
|
119
|
-
// needs to add an extra field WRITE TO
|
|
120
|
-
def.aggregate.size += 8;
|
|
155
|
+
def.aggregate.totalResultsSize += 8;
|
|
156
|
+
def.aggregate.totalAccumulatorSize += 8;
|
|
121
157
|
}
|
|
158
|
+
// needs to add an extra field WRITE TO
|
|
159
|
+
def.aggregate.size += 8;
|
|
122
160
|
}
|
|
123
161
|
};
|
|
124
162
|
export const isRootCountOnly = (def, filterSize) => {
|
|
@@ -149,4 +187,23 @@ export const isRootCountOnly = (def, filterSize) => {
|
|
|
149
187
|
}
|
|
150
188
|
return true;
|
|
151
189
|
};
|
|
190
|
+
function getTimeZoneOffsetInMinutes(timeZone, date = new Date()) {
|
|
191
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
192
|
+
timeZone,
|
|
193
|
+
year: 'numeric',
|
|
194
|
+
month: 'numeric',
|
|
195
|
+
day: 'numeric',
|
|
196
|
+
hour: 'numeric',
|
|
197
|
+
minute: 'numeric',
|
|
198
|
+
second: 'numeric',
|
|
199
|
+
hour12: false,
|
|
200
|
+
});
|
|
201
|
+
const parts = formatter.formatToParts(date);
|
|
202
|
+
const getPart = (partName) => parseInt(parts.find((p) => p.type === partName)?.value || '0', 10);
|
|
203
|
+
const targetTimeAsUTC = Date.UTC(getPart('year'), getPart('month') - 1, getPart('day'), getPart('hour'), getPart('minute'), getPart('second'));
|
|
204
|
+
const originalUTCTime = date.getTime();
|
|
205
|
+
const offsetInMilliseconds = targetTimeAsUTC - originalUTCTime;
|
|
206
|
+
const offsetInMinutes = offsetInMilliseconds / (1000 * 60);
|
|
207
|
+
return Math.round(offsetInMinutes);
|
|
208
|
+
}
|
|
152
209
|
//# sourceMappingURL=aggregation.js.map
|