@based/db 0.0.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/README.md +43 -0
- package/dist/lib/darwin_aarch64/include/cdefs.h +317 -0
- package/dist/lib/darwin_aarch64/include/libdeflate.h +322 -0
- package/dist/lib/darwin_aarch64/include/libdeflate_strings.h +35 -0
- package/dist/lib/darwin_aarch64/include/linker_set.h +109 -0
- package/dist/lib/darwin_aarch64/include/queue.h +627 -0
- package/dist/lib/darwin_aarch64/include/selva/_export.h +7 -0
- package/dist/lib/darwin_aarch64/include/selva/align.h +9 -0
- package/dist/lib/darwin_aarch64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/darwin_aarch64/include/selva/base64.h +59 -0
- package/dist/lib/darwin_aarch64/include/selva/base64url.h +59 -0
- package/dist/lib/darwin_aarch64/include/selva/bitmap.h +95 -0
- package/dist/lib/darwin_aarch64/include/selva/crc32c.h +17 -0
- package/dist/lib/darwin_aarch64/include/selva/ctime.h +135 -0
- package/dist/lib/darwin_aarch64/include/selva/db.h +284 -0
- package/dist/lib/darwin_aarch64/include/selva/endian.h +301 -0
- package/dist/lib/darwin_aarch64/include/selva/fast_linear_search.h +23 -0
- package/dist/lib/darwin_aarch64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/darwin_aarch64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/darwin_aarch64/include/selva/fields.h +338 -0
- package/dist/lib/darwin_aarch64/include/selva/find.h +47 -0
- package/dist/lib/darwin_aarch64/include/selva/lpf.h +28 -0
- package/dist/lib/darwin_aarch64/include/selva/node_id_set.h +43 -0
- package/dist/lib/darwin_aarch64/include/selva/poptop.h +114 -0
- package/dist/lib/darwin_aarch64/include/selva/queue_r.h +190 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_hash128.h +39 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_lang.h +105 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_math.h +37 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_string.h +672 -0
- package/dist/lib/darwin_aarch64/include/selva/sort.h +119 -0
- package/dist/lib/darwin_aarch64/include/selva/strsearch.h +43 -0
- package/dist/lib/darwin_aarch64/include/selva/timestamp.h +25 -0
- package/dist/lib/darwin_aarch64/include/selva/traverse.h +65 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +110 -0
- package/dist/lib/darwin_aarch64/include/selva/vector.h +14 -0
- package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +13 -0
- package/dist/lib/darwin_aarch64/include/selva_error.h +137 -0
- package/dist/lib/darwin_aarch64/include/selva_lang_code.h +157 -0
- package/dist/lib/darwin_aarch64/include/tree.h +852 -0
- 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.11.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.8.0.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.0.8.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.0.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/lib/linux_aarch64/include/cdefs.h +317 -0
- package/dist/lib/linux_aarch64/include/libdeflate.h +322 -0
- package/dist/lib/linux_aarch64/include/libdeflate_strings.h +35 -0
- package/dist/lib/linux_aarch64/include/linker_set.h +109 -0
- package/dist/lib/linux_aarch64/include/queue.h +627 -0
- package/dist/lib/linux_aarch64/include/selva/_export.h +7 -0
- package/dist/lib/linux_aarch64/include/selva/align.h +9 -0
- package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/linux_aarch64/include/selva/base64.h +59 -0
- package/dist/lib/linux_aarch64/include/selva/base64url.h +59 -0
- package/dist/lib/linux_aarch64/include/selva/bitmap.h +95 -0
- package/dist/lib/linux_aarch64/include/selva/crc32c.h +17 -0
- package/dist/lib/linux_aarch64/include/selva/ctime.h +135 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +284 -0
- package/dist/lib/linux_aarch64/include/selva/endian.h +301 -0
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +23 -0
- package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/linux_aarch64/include/selva/fields.h +338 -0
- package/dist/lib/linux_aarch64/include/selva/find.h +47 -0
- package/dist/lib/linux_aarch64/include/selva/lpf.h +28 -0
- package/dist/lib/linux_aarch64/include/selva/node_id_set.h +43 -0
- package/dist/lib/linux_aarch64/include/selva/poptop.h +114 -0
- package/dist/lib/linux_aarch64/include/selva/queue_r.h +190 -0
- package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +39 -0
- package/dist/lib/linux_aarch64/include/selva/selva_lang.h +105 -0
- package/dist/lib/linux_aarch64/include/selva/selva_math.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +672 -0
- package/dist/lib/linux_aarch64/include/selva/sort.h +119 -0
- package/dist/lib/linux_aarch64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_aarch64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_aarch64/include/selva/traverse.h +65 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +110 -0
- package/dist/lib/linux_aarch64/include/selva/vector.h +14 -0
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +13 -0
- package/dist/lib/linux_aarch64/include/selva_error.h +137 -0
- package/dist/lib/linux_aarch64/include/selva_lang_code.h +157 -0
- package/dist/lib/linux_aarch64/include/tree.h +852 -0
- 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.11.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0.8.2 +0 -0
- package/dist/lib/linux_x86_64/include/cdefs.h +317 -0
- package/dist/lib/linux_x86_64/include/libdeflate.h +322 -0
- package/dist/lib/linux_x86_64/include/libdeflate_strings.h +35 -0
- package/dist/lib/linux_x86_64/include/linker_set.h +109 -0
- package/dist/lib/linux_x86_64/include/queue.h +627 -0
- package/dist/lib/linux_x86_64/include/selva/_export.h +7 -0
- package/dist/lib/linux_x86_64/include/selva/align.h +9 -0
- package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/linux_x86_64/include/selva/base64.h +59 -0
- package/dist/lib/linux_x86_64/include/selva/base64url.h +59 -0
- package/dist/lib/linux_x86_64/include/selva/bitmap.h +95 -0
- package/dist/lib/linux_x86_64/include/selva/crc32c.h +17 -0
- package/dist/lib/linux_x86_64/include/selva/ctime.h +135 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +284 -0
- package/dist/lib/linux_x86_64/include/selva/endian.h +301 -0
- package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +23 -0
- package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/linux_x86_64/include/selva/fields.h +338 -0
- package/dist/lib/linux_x86_64/include/selva/find.h +47 -0
- package/dist/lib/linux_x86_64/include/selva/lpf.h +28 -0
- package/dist/lib/linux_x86_64/include/selva/node_id_set.h +43 -0
- package/dist/lib/linux_x86_64/include/selva/poptop.h +114 -0
- package/dist/lib/linux_x86_64/include/selva/queue_r.h +190 -0
- package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +39 -0
- package/dist/lib/linux_x86_64/include/selva/selva_lang.h +105 -0
- package/dist/lib/linux_x86_64/include/selva/selva_math.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +672 -0
- package/dist/lib/linux_x86_64/include/selva/sort.h +119 -0
- package/dist/lib/linux_x86_64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_x86_64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_x86_64/include/selva/traverse.h +65 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +110 -0
- package/dist/lib/linux_x86_64/include/selva/vector.h +14 -0
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +13 -0
- package/dist/lib/linux_x86_64/include/selva_error.h +137 -0
- package/dist/lib/linux_x86_64/include/selva_lang_code.h +157 -0
- package/dist/lib/linux_x86_64/include/tree.h +852 -0
- package/dist/lib/linux_x86_64/libdeflate.so +0 -0
- package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.11.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0.8.2 +0 -0
- package/dist/src/client/crc32.d.ts +1 -0
- package/dist/src/client/crc32.js +281 -0
- package/dist/src/client/index.d.ts +58 -0
- package/dist/src/client/index.js +120 -0
- package/dist/src/client/modify/ModifyRes.d.ts +26 -0
- package/dist/src/client/modify/ModifyRes.js +98 -0
- package/dist/src/client/modify/alias.d.ts +4 -0
- package/dist/src/client/modify/alias.js +47 -0
- package/dist/src/client/modify/binary.d.ts +6 -0
- package/dist/src/client/modify/binary.js +61 -0
- package/dist/src/client/modify/create.d.ts +4 -0
- package/dist/src/client/modify/create.js +108 -0
- package/dist/src/client/modify/fixed.d.ts +5 -0
- package/dist/src/client/modify/fixed.js +118 -0
- package/dist/src/client/modify/hll.d.ts +4 -0
- package/dist/src/client/modify/hll.js +58 -0
- package/dist/src/client/modify/index.d.ts +4 -0
- package/dist/src/client/modify/index.js +4 -0
- package/dist/src/client/modify/modify.d.ts +5 -0
- package/dist/src/client/modify/modify.js +126 -0
- package/dist/src/client/modify/references/edge.d.ts +6 -0
- package/dist/src/client/modify/references/edge.js +158 -0
- package/dist/src/client/modify/references/reference.d.ts +11 -0
- package/dist/src/client/modify/references/reference.js +92 -0
- package/dist/src/client/modify/references/references.d.ts +17 -0
- package/dist/src/client/modify/references/references.js +271 -0
- package/dist/src/client/modify/remove.d.ts +2 -0
- package/dist/src/client/modify/remove.js +36 -0
- package/dist/src/client/modify/setCursor.d.ts +4 -0
- package/dist/src/client/modify/setCursor.js +36 -0
- package/dist/src/client/modify/string.d.ts +5 -0
- package/dist/src/client/modify/string.js +56 -0
- package/dist/src/client/modify/text.d.ts +5 -0
- package/dist/src/client/modify/text.js +14 -0
- package/dist/src/client/modify/types.d.ts +14 -0
- package/dist/src/client/modify/types.js +12 -0
- package/dist/src/client/modify/update.d.ts +5 -0
- package/dist/src/client/modify/update.js +80 -0
- package/dist/src/client/modify/upsert.d.ts +2 -0
- package/dist/src/client/modify/upsert.js +40 -0
- package/dist/src/client/operations.d.ts +31 -0
- package/dist/src/client/operations.js +110 -0
- package/dist/src/client/query/BasedDbQuery.d.ts +40 -0
- package/dist/src/client/query/BasedDbQuery.js +235 -0
- package/dist/src/client/query/BasedIterable.d.ts +26 -0
- package/dist/src/client/query/BasedIterable.js +113 -0
- package/dist/src/client/query/debug.d.ts +3 -0
- package/dist/src/client/query/debug.js +117 -0
- package/dist/src/client/query/display.d.ts +5 -0
- package/dist/src/client/query/display.js +233 -0
- package/dist/src/client/query/filter/FilterBranch.d.ts +13 -0
- package/dist/src/client/query/filter/FilterBranch.js +29 -0
- package/dist/src/client/query/filter/createFixedFilterBuffer.d.ts +3 -0
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +101 -0
- package/dist/src/client/query/filter/createReferenceFilter.d.ts +2 -0
- package/dist/src/client/query/filter/createReferenceFilter.js +24 -0
- package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -0
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +81 -0
- package/dist/src/client/query/filter/filter.d.ts +10 -0
- package/dist/src/client/query/filter/filter.js +134 -0
- package/dist/src/client/query/filter/operators.d.ts +6 -0
- package/dist/src/client/query/filter/operators.js +98 -0
- package/dist/src/client/query/filter/parseFilterValue.d.ts +2 -0
- package/dist/src/client/query/filter/parseFilterValue.js +99 -0
- package/dist/src/client/query/filter/primitiveFilter.d.ts +4 -0
- package/dist/src/client/query/filter/primitiveFilter.js +47 -0
- package/dist/src/client/query/filter/toBuffer.d.ts +3 -0
- package/dist/src/client/query/filter/toBuffer.js +100 -0
- package/dist/src/client/query/filter/types.d.ts +6 -0
- package/dist/src/client/query/filter/types.js +7 -0
- package/dist/src/client/query/include/props.d.ts +6 -0
- package/dist/src/client/query/include/props.js +44 -0
- package/dist/src/client/query/include/toBuffer.d.ts +3 -0
- package/dist/src/client/query/include/toBuffer.js +82 -0
- package/dist/src/client/query/include/utils.d.ts +6 -0
- package/dist/src/client/query/include/utils.js +41 -0
- package/dist/src/client/query/include/walk.d.ts +3 -0
- package/dist/src/client/query/include/walk.js +70 -0
- package/dist/src/client/query/query.d.ts +10 -0
- package/dist/src/client/query/query.js +11 -0
- package/dist/src/client/query/queryDef.d.ts +3 -0
- package/dist/src/client/query/queryDef.js +54 -0
- package/dist/src/client/query/read/read.d.ts +8 -0
- package/dist/src/client/query/read/read.js +303 -0
- package/dist/src/client/query/registerQuery.d.ts +2 -0
- package/dist/src/client/query/registerQuery.js +31 -0
- package/dist/src/client/query/search/index.d.ts +6 -0
- package/dist/src/client/query/search/index.js +82 -0
- package/dist/src/client/query/sort.d.ts +3 -0
- package/dist/src/client/query/sort.js +18 -0
- package/dist/src/client/query/subscription/index.d.ts +5 -0
- package/dist/src/client/query/subscription/index.js +52 -0
- package/dist/src/client/query/subscription/markers.d.ts +10 -0
- package/dist/src/client/query/subscription/markers.js +213 -0
- package/dist/src/client/query/subscription/run.d.ts +5 -0
- package/dist/src/client/query/subscription/run.js +69 -0
- package/dist/src/client/query/subscription/types.d.ts +33 -0
- package/dist/src/client/query/subscription/types.js +3 -0
- package/dist/src/client/query/thresholds.d.ts +6 -0
- package/dist/src/client/query/thresholds.js +16 -0
- package/dist/src/client/query/toBuffer.d.ts +3 -0
- package/dist/src/client/query/toBuffer.js +229 -0
- package/dist/src/client/query/types.d.ts +88 -0
- package/dist/src/client/query/types.js +15 -0
- package/dist/src/client/query/validation.d.ts +15 -0
- package/dist/src/client/query/validation.js +59 -0
- package/dist/src/client/string.d.ts +5 -0
- package/dist/src/client/string.js +73 -0
- package/dist/src/client/tree.d.ts +1 -0
- package/dist/src/client/tree.js +5 -0
- package/dist/src/index.d.ts +31 -0
- package/dist/src/index.js +85 -0
- package/dist/src/native.d.ts +28 -0
- package/dist/src/native.js +96 -0
- package/dist/src/server/csmt/draw-dot.d.ts +2 -0
- package/dist/src/server/csmt/draw-dot.js +32 -0
- package/dist/src/server/csmt/index.d.ts +4 -0
- package/dist/src/server/csmt/index.js +5 -0
- package/dist/src/server/csmt/match.d.ts +7 -0
- package/dist/src/server/csmt/match.js +10 -0
- package/dist/src/server/csmt/memebership-proof.d.ts +7 -0
- package/dist/src/server/csmt/memebership-proof.js +122 -0
- package/dist/src/server/csmt/tree-utils.d.ts +6 -0
- package/dist/src/server/csmt/tree-utils.js +33 -0
- package/dist/src/server/csmt/tree.d.ts +2 -0
- package/dist/src/server/csmt/tree.js +209 -0
- package/dist/src/server/csmt/types.d.ts +40 -0
- package/dist/src/server/csmt/types.js +2 -0
- package/dist/src/server/index.d.ts +85 -0
- package/dist/src/server/index.js +407 -0
- package/dist/src/server/migrate/index.d.ts +7 -0
- package/dist/src/server/migrate/index.js +108 -0
- package/dist/src/server/migrate/worker.d.ts +1 -0
- package/dist/src/server/migrate/worker.js +81 -0
- package/dist/src/server/save.d.ts +2 -0
- package/dist/src/server/save.js +66 -0
- package/dist/src/server/schema/schema.d.ts +3 -0
- package/dist/src/server/schema/schema.js +4 -0
- package/dist/src/server/schema/selvaBuffer.d.ts +4 -0
- package/dist/src/server/schema/selvaBuffer.js +102 -0
- package/dist/src/server/schema/typeDef.d.ts +6 -0
- package/dist/src/server/schema/typeDef.js +315 -0
- package/dist/src/server/schema/types.d.ts +127 -0
- package/dist/src/server/schema/types.js +113 -0
- package/dist/src/server/schema/utils.d.ts +6 -0
- package/dist/src/server/schema/utils.js +21 -0
- package/dist/src/server/start.d.ts +6 -0
- package/dist/src/server/start.js +86 -0
- package/dist/src/server/tree.d.ts +13 -0
- package/dist/src/server/tree.js +33 -0
- package/dist/src/server/worker.d.ts +1 -0
- package/dist/src/server/worker.js +35 -0
- package/package.json +48 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import picocolors from 'picocolors';
|
|
2
|
+
import { isPropDef, REVERSE_TYPE_INDEX_MAP } from '../../server/schema/types.js';
|
|
3
|
+
import { QueryDefType } from './types.js';
|
|
4
|
+
export const debugQueryDef = (q, returnIt) => {
|
|
5
|
+
const loggableObject = { type: 'bla', schema: null };
|
|
6
|
+
const f = (a) => {
|
|
7
|
+
if (a === null) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
// if (a instanceof BasedNode) {
|
|
11
|
+
// // will be changed
|
|
12
|
+
// return 'basedNode'
|
|
13
|
+
// }
|
|
14
|
+
if (a instanceof Buffer) {
|
|
15
|
+
return new Uint8Array(a);
|
|
16
|
+
}
|
|
17
|
+
if (a instanceof Uint8Array) {
|
|
18
|
+
return a;
|
|
19
|
+
}
|
|
20
|
+
if (a instanceof Set) {
|
|
21
|
+
return a;
|
|
22
|
+
}
|
|
23
|
+
if (a instanceof Map) {
|
|
24
|
+
const b = new Map();
|
|
25
|
+
walk(a, b);
|
|
26
|
+
return b;
|
|
27
|
+
}
|
|
28
|
+
else if (typeof a === 'object') {
|
|
29
|
+
if (a.type && a.include && a.filter && a.range) {
|
|
30
|
+
return debugQueryDef(a, true);
|
|
31
|
+
}
|
|
32
|
+
if (isPropDef(a)) {
|
|
33
|
+
return `${a.path.join('.')}: ${a.prop} ${REVERSE_TYPE_INDEX_MAP[a.typeIndex]}`;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const b = Array.isArray(a) ? [] : {};
|
|
37
|
+
walk(a, b);
|
|
38
|
+
return b;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return a;
|
|
42
|
+
};
|
|
43
|
+
const walk = (a, b) => {
|
|
44
|
+
if (a instanceof Map) {
|
|
45
|
+
a.forEach((v, k) => {
|
|
46
|
+
b.set(k, f(v));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
for (const key in a) {
|
|
51
|
+
if (key === 'schema') {
|
|
52
|
+
b[key] = `Schema [${a.schema?.type}]`;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
b[key] = f(a[key]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
walk(q, loggableObject);
|
|
61
|
+
loggableObject.type = QueryDefType[q.type];
|
|
62
|
+
if (!returnIt) {
|
|
63
|
+
console.dir(loggableObject, { depth: 10 });
|
|
64
|
+
}
|
|
65
|
+
return loggableObject;
|
|
66
|
+
};
|
|
67
|
+
export const debug = (x, start = 0, end = 0, label) => {
|
|
68
|
+
if (x === null || typeof x !== 'object') {
|
|
69
|
+
console.log(x);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (Array.isArray(x) && x[0] instanceof Buffer) {
|
|
73
|
+
debug(Buffer.concat(x), start, end, label);
|
|
74
|
+
}
|
|
75
|
+
else if (x instanceof Buffer) {
|
|
76
|
+
console.log(label || '');
|
|
77
|
+
if (!end) {
|
|
78
|
+
end = x.byteLength;
|
|
79
|
+
}
|
|
80
|
+
let len = Math.max(4, String(end - start).length + 1);
|
|
81
|
+
const w = Math.floor(process.stdout.columns / len) || 20;
|
|
82
|
+
const a = [...new Uint8Array(x.slice(start, end))];
|
|
83
|
+
for (let i = 0; i < Math.ceil((end - start) / w); i++) {
|
|
84
|
+
console.log(picocolors.gray(a
|
|
85
|
+
.slice(i * w, (i + 1) * w)
|
|
86
|
+
.map((v, j) => {
|
|
87
|
+
return String(j + i * w).padStart(len - 1, '0');
|
|
88
|
+
})
|
|
89
|
+
.join(' ')));
|
|
90
|
+
console.log(a
|
|
91
|
+
.slice(i * w, (i + 1) * w)
|
|
92
|
+
.map((v) => String(v).padStart(len - 1, '0'))
|
|
93
|
+
.map((v, j) => {
|
|
94
|
+
if (a[j + i * w] === 253) {
|
|
95
|
+
return picocolors.magenta(v);
|
|
96
|
+
}
|
|
97
|
+
if (a[j + i * w] === 255) {
|
|
98
|
+
return picocolors.blue(v);
|
|
99
|
+
}
|
|
100
|
+
if (a[j + i * w] === 254) {
|
|
101
|
+
return picocolors.green(v);
|
|
102
|
+
}
|
|
103
|
+
if (a[j + i * w] === 252) {
|
|
104
|
+
return picocolors.red(v);
|
|
105
|
+
}
|
|
106
|
+
return v;
|
|
107
|
+
})
|
|
108
|
+
.join(' '));
|
|
109
|
+
}
|
|
110
|
+
console.log('');
|
|
111
|
+
// -------------------------
|
|
112
|
+
}
|
|
113
|
+
else if ('type' in x && 'schema' in x && 'props' in x) {
|
|
114
|
+
debugQueryDef(x);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=debug.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { QueryDef } from './types.js';
|
|
2
|
+
import { BasedQueryResponse } from './BasedIterable.js';
|
|
3
|
+
export declare const size: (size: number) => string;
|
|
4
|
+
export declare const time: (time: number) => string;
|
|
5
|
+
export declare const inspectData: (q: BasedQueryResponse, def: QueryDef, level: number, top: boolean, depth: number, hasId?: boolean) => string;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import picocolors from 'picocolors';
|
|
2
|
+
import { BINARY, NUMBER, REFERENCE, REFERENCES, STRING, TIMESTAMP, } from '../../server/schema/types.js';
|
|
3
|
+
const decimals = (v) => ~~(v * 100) / 100;
|
|
4
|
+
const sizeCalc = (size) => {
|
|
5
|
+
if (size > 1e6) {
|
|
6
|
+
return `${decimals(size / 1e6)} mb`;
|
|
7
|
+
}
|
|
8
|
+
if (size > 1e3) {
|
|
9
|
+
return `${decimals(size / 1e3)} kb`;
|
|
10
|
+
}
|
|
11
|
+
return `${size} bytes`;
|
|
12
|
+
};
|
|
13
|
+
export const size = (size) => {
|
|
14
|
+
const str = sizeCalc(size);
|
|
15
|
+
if (size > 1e3 * 1e3 * 25) {
|
|
16
|
+
return picocolors.red(str);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return picocolors.green(str);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const timeCalc = (time) => {
|
|
23
|
+
if (time > 1e3) {
|
|
24
|
+
return `${decimals(time / 1e3)} s`;
|
|
25
|
+
}
|
|
26
|
+
return `${decimals(time)} ms`;
|
|
27
|
+
};
|
|
28
|
+
export const time = (time) => {
|
|
29
|
+
const str = timeCalc(time);
|
|
30
|
+
if (time > 1e3) {
|
|
31
|
+
return picocolors.red(str);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return picocolors.green(str);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const prettyPrintVal = (v, type) => {
|
|
38
|
+
if (type === BINARY) {
|
|
39
|
+
const nr = 12;
|
|
40
|
+
const isLarger = v.length > nr;
|
|
41
|
+
const x = [...v.slice(0, nr)].map((v) => {
|
|
42
|
+
return `${v}`.padStart(3, '0') + ' ';
|
|
43
|
+
});
|
|
44
|
+
return (picocolors.blue(x.join('')) +
|
|
45
|
+
(isLarger ? picocolors.dim('... ') : '') +
|
|
46
|
+
picocolors.italic(picocolors.dim(`${~~((Buffer.byteLength(v, 'utf8') / 1e3) * 100) / 100}kb`)));
|
|
47
|
+
}
|
|
48
|
+
if (type === STRING) {
|
|
49
|
+
if (v.length > 75) {
|
|
50
|
+
const chars = picocolors.italic(picocolors.dim(`${~~((Buffer.byteLength(v, 'utf8') / 1e3) * 100) / 100}kb`));
|
|
51
|
+
v =
|
|
52
|
+
v.slice(0, 75).replace(/\n/g, '\\n ') +
|
|
53
|
+
picocolors.dim('...') +
|
|
54
|
+
'" ' +
|
|
55
|
+
chars;
|
|
56
|
+
return `"${v}`;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return `"${v}"`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (type === TIMESTAMP) {
|
|
63
|
+
if (v === 0) {
|
|
64
|
+
return `0 ${picocolors.italic(picocolors.dim('No date'))}`;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return `${v} ${picocolors.italic(picocolors.dim(new Date(v).toString().replace(/\(.+\)/, '')))}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return v;
|
|
71
|
+
};
|
|
72
|
+
const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth) => {
|
|
73
|
+
const prefix = ''.padEnd(level, ' ');
|
|
74
|
+
let str = '';
|
|
75
|
+
if (isFirst || isObject) {
|
|
76
|
+
str = '{\n';
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
str = prefix + '{\n';
|
|
80
|
+
}
|
|
81
|
+
const prefixBody = ''.padEnd(level + 3, ' ');
|
|
82
|
+
let edges = [];
|
|
83
|
+
for (const k in object) {
|
|
84
|
+
const key = path ? path + '.' + k : k;
|
|
85
|
+
let def = q.props[key];
|
|
86
|
+
let v = object[k];
|
|
87
|
+
const isEdge = k[0] === '$';
|
|
88
|
+
if (k === '$searchScore') {
|
|
89
|
+
edges.push({ k, v, def: { typeIndex: NUMBER } });
|
|
90
|
+
}
|
|
91
|
+
else if (isEdge) {
|
|
92
|
+
if (q.edges?.props?.[k]) {
|
|
93
|
+
edges.push({ k, v, def: q.edges?.props?.[k] });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
str += prefixBody + `${k}: `;
|
|
98
|
+
}
|
|
99
|
+
if (isEdge) {
|
|
100
|
+
// skip
|
|
101
|
+
}
|
|
102
|
+
else if (key === 'id') {
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
str += v + picocolors.italic(picocolors.dim(` ${q.target.type}`));
|
|
105
|
+
str += ',\n';
|
|
106
|
+
}
|
|
107
|
+
else if (!def) {
|
|
108
|
+
str += inspectObject(v, q, key, level + 2, false, false, true, depth) + '';
|
|
109
|
+
}
|
|
110
|
+
else if ('__isPropDef' in def) {
|
|
111
|
+
if (def.typeIndex === REFERENCES) {
|
|
112
|
+
str += inspectData(v, q.references.get(def.prop), level + 2, false, depth);
|
|
113
|
+
}
|
|
114
|
+
else if (def.typeIndex === REFERENCE) {
|
|
115
|
+
if (!v || !v.id) {
|
|
116
|
+
str += 'null,\n';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
str += inspectObject(v, q.references.get(def.prop), '', level + 2, false, false, true, depth);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if (def.typeIndex === BINARY) {
|
|
123
|
+
if (v === undefined) {
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
126
|
+
str += prettyPrintVal(v, def.typeIndex);
|
|
127
|
+
}
|
|
128
|
+
else if (def.typeIndex === STRING) {
|
|
129
|
+
if (v === undefined) {
|
|
130
|
+
return '';
|
|
131
|
+
}
|
|
132
|
+
str += prettyPrintVal(v, def.typeIndex);
|
|
133
|
+
}
|
|
134
|
+
else if (def.typeIndex === TIMESTAMP) {
|
|
135
|
+
str += prettyPrintVal(v, def.typeIndex);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (typeof v === 'number') {
|
|
139
|
+
str += picocolors.blue(v);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
str += v;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (def?.typeIndex !== REFERENCE) {
|
|
146
|
+
str += ',\n';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
str += ',\n';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
for (const edge of edges) {
|
|
154
|
+
if (edge.def.typeIndex === REFERENCE) {
|
|
155
|
+
str += prefixBody + picocolors.bold(`${edge.k}: `);
|
|
156
|
+
str += inspectObject(edge.v, q.edges.references.get(edge.def.prop), '', level + 2, false, false, true, depth);
|
|
157
|
+
}
|
|
158
|
+
else if (edge.def.typeIndex === REFERENCES) {
|
|
159
|
+
str += prefixBody + picocolors.bold(`${edge.k}: `);
|
|
160
|
+
str +=
|
|
161
|
+
inspectData(edge.v, q.edges.references.get(edge.def.prop), level + 3, false, depth + 2) + '\n';
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
str +=
|
|
165
|
+
prefixBody +
|
|
166
|
+
picocolors.bold(`${edge.k}: `) +
|
|
167
|
+
prettyPrintVal(edge.v, edge.def.typeIndex) +
|
|
168
|
+
',\n';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (isObject) {
|
|
172
|
+
str += prefix + ' },\n';
|
|
173
|
+
}
|
|
174
|
+
else if (isLast) {
|
|
175
|
+
str += prefix + '}';
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
str += prefix + '},\n';
|
|
179
|
+
}
|
|
180
|
+
return str;
|
|
181
|
+
};
|
|
182
|
+
export const inspectData = (q, def, level, top, depth, hasId = false) => {
|
|
183
|
+
const length = q.length;
|
|
184
|
+
const max = Math.min(length, depth);
|
|
185
|
+
const prefix = top ? ' ' : '';
|
|
186
|
+
let str;
|
|
187
|
+
let i = 0;
|
|
188
|
+
if (hasId) {
|
|
189
|
+
str = prefix;
|
|
190
|
+
level = level + 1;
|
|
191
|
+
}
|
|
192
|
+
else if (top) {
|
|
193
|
+
level = level + 3;
|
|
194
|
+
str = prefix + '[\n' + prefix + ' ';
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
str = prefix + '[';
|
|
198
|
+
}
|
|
199
|
+
for (const x of q) {
|
|
200
|
+
str += inspectObject(x, def, '', level + 1, i === max - 1, i === 0, false, depth);
|
|
201
|
+
i++;
|
|
202
|
+
if (i >= max) {
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (length > max) {
|
|
207
|
+
const morePrefix = ''.padStart(top ? 2 : level + 3, ' ');
|
|
208
|
+
str +=
|
|
209
|
+
',\n' +
|
|
210
|
+
picocolors.dim(picocolors.italic(prefix +
|
|
211
|
+
morePrefix +
|
|
212
|
+
`...${length - max} More item${length - max !== 1 ? 's' : ''}\n`));
|
|
213
|
+
if (hasId) {
|
|
214
|
+
str += '';
|
|
215
|
+
}
|
|
216
|
+
else if (top) {
|
|
217
|
+
str += prefix + ']';
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
str += prefix + ']'.padStart(level + 2, ' ');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else if (hasId) {
|
|
224
|
+
}
|
|
225
|
+
else if (top) {
|
|
226
|
+
str += '\n' + prefix + ']';
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
str += ']';
|
|
230
|
+
}
|
|
231
|
+
return str;
|
|
232
|
+
};
|
|
233
|
+
//# sourceMappingURL=display.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DbClient } from '../../index.js';
|
|
2
|
+
import { QueryDefFilter, QueryDef } from '../types.js';
|
|
3
|
+
import { Operator } from './operators.js';
|
|
4
|
+
import { FilterBranchFn } from './types.js';
|
|
5
|
+
export declare class FilterBranch {
|
|
6
|
+
constructor(db: DbClient, filterBranch: QueryDefFilter, def: QueryDef);
|
|
7
|
+
db: DbClient;
|
|
8
|
+
filterBranch: QueryDefFilter;
|
|
9
|
+
def: QueryDef;
|
|
10
|
+
or(fn: FilterBranchFn): FilterBranch;
|
|
11
|
+
or(field: string, operator?: Operator | boolean, value?: any): FilterBranch;
|
|
12
|
+
filter(field: string, operator?: Operator | boolean, value?: any): this;
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { convertFilter, filter, filterOr } from './filter.js';
|
|
2
|
+
export class FilterBranch {
|
|
3
|
+
constructor(db, filterBranch, def) {
|
|
4
|
+
this.def = def;
|
|
5
|
+
this.filterBranch = filterBranch;
|
|
6
|
+
this.db = db;
|
|
7
|
+
}
|
|
8
|
+
db;
|
|
9
|
+
filterBranch;
|
|
10
|
+
def;
|
|
11
|
+
or(field, operator, value) {
|
|
12
|
+
if (typeof field === 'function') {
|
|
13
|
+
const f = new FilterBranch(this.db, filterOr(this.db, this.def, [], this.filterBranch), this.def);
|
|
14
|
+
field(f);
|
|
15
|
+
this.def.filter.size += f.filterBranch.size;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const f = convertFilter(field, operator, value);
|
|
19
|
+
filterOr(this.db, this.def, f, this.filterBranch);
|
|
20
|
+
}
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
filter(field, operator, value) {
|
|
24
|
+
const f = convertFilter(field, operator, value);
|
|
25
|
+
filter(this.db, this.def, f, this.filterBranch);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=FilterBranch.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { PropDef, PropDefEdge } from '../../../server/schema/types.js';
|
|
2
|
+
export declare const writeFixed: (prop: PropDef | PropDefEdge, buf: Buffer, value: any, size: number, offset: number, op: number) => void;
|
|
3
|
+
export declare const createFixedFilterBuffer: (prop: PropDef | PropDefEdge, size: number, op: number, value: any, sort: boolean) => Buffer;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { BINARY, STRING, REFERENCES, } from '../../../server/schema/types.js';
|
|
2
|
+
import { propIsSigned } from '../../../server/schema/utils.js';
|
|
3
|
+
import { negateType, stripNegation } from './operators.js';
|
|
4
|
+
import { parseFilterValue } from './parseFilterValue.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
|
+
export const writeFixed = (prop, buf, value, size, offset, op) => {
|
|
19
|
+
if (prop.typeIndex === BINARY || prop.typeIndex === STRING) {
|
|
20
|
+
if (typeof value === 'string') {
|
|
21
|
+
const size = buf.write(value, offset + 1, 'utf8');
|
|
22
|
+
buf[offset] = size;
|
|
23
|
+
}
|
|
24
|
+
else if (value instanceof Buffer) {
|
|
25
|
+
buf.set(value, offset);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error('Incorrect filter value for ' + prop.path);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (size === 1) {
|
|
32
|
+
buf[offset] = value;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (size === 8) {
|
|
36
|
+
buf.writeDoubleLE(value, offset);
|
|
37
|
+
}
|
|
38
|
+
else if (propIsSigned(prop)) {
|
|
39
|
+
if (size === 4) {
|
|
40
|
+
buf.writeInt32LE(value, offset);
|
|
41
|
+
}
|
|
42
|
+
else if (size === 2) {
|
|
43
|
+
buf.writeInt16LE(value, offset);
|
|
44
|
+
}
|
|
45
|
+
else if (size === 1) {
|
|
46
|
+
buf[offset] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (size === 4) {
|
|
50
|
+
buf.writeUInt32LE(value, offset);
|
|
51
|
+
}
|
|
52
|
+
else if (size === 2) {
|
|
53
|
+
buf.writeUInt16LE(value, offset);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
// Modes
|
|
58
|
+
// default = 0,
|
|
59
|
+
// orFixed = 1,
|
|
60
|
+
// orVar = 2,
|
|
61
|
+
export const createFixedFilterBuffer = (prop, size, op, value, sort) => {
|
|
62
|
+
let buf;
|
|
63
|
+
const start = prop.start;
|
|
64
|
+
if (Array.isArray(value)) {
|
|
65
|
+
// [or = 1] [size 2] [start 2] [op], [repeat 2], value[size] value[size] value[size]
|
|
66
|
+
const len = value.length;
|
|
67
|
+
buf = Buffer.allocUnsafe(10 + len * size);
|
|
68
|
+
buf[0] = negateType(op);
|
|
69
|
+
buf[1] = prop.typeIndex === REFERENCES && op === 1 ? 3 : 1;
|
|
70
|
+
buf.writeUInt16LE(size, 2);
|
|
71
|
+
buf.writeUInt16LE(start, 4);
|
|
72
|
+
buf[6] = stripNegation(op);
|
|
73
|
+
buf[7] = prop.typeIndex;
|
|
74
|
+
buf.writeUInt16LE(len, 8);
|
|
75
|
+
if (sort) {
|
|
76
|
+
value = new Uint32Array(value.map((v) => parseFilterValue(prop, v)));
|
|
77
|
+
value.sort();
|
|
78
|
+
for (let i = 0; i < len; i++) {
|
|
79
|
+
buf.writeUInt32LE(value[i], 10 + i * size);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
for (let i = 0; i < len; i++) {
|
|
84
|
+
writeFixed(prop, buf, parseFilterValue(prop, value[i]), size, 10 + i * size, op);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// [or = 0] [size 2] [start 2], [op], value[size]
|
|
90
|
+
buf = Buffer.allocUnsafe(8 + size);
|
|
91
|
+
buf[0] = negateType(op);
|
|
92
|
+
buf[1] = 0;
|
|
93
|
+
buf.writeUInt16LE(size, 2);
|
|
94
|
+
buf.writeUInt16LE(start, 4);
|
|
95
|
+
buf[6] = stripNegation(op);
|
|
96
|
+
buf[7] = prop.typeIndex;
|
|
97
|
+
writeFixed(prop, buf, parseFilterValue(prop, value), size, 8, op);
|
|
98
|
+
}
|
|
99
|
+
return buf;
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=createFixedFilterBuffer.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { negateType, stripNegation } from './operators.js';
|
|
2
|
+
export const createReferenceFilter = (prop, op, value) => {
|
|
3
|
+
let buf;
|
|
4
|
+
const len = Array.isArray(value) ? value.length : 1;
|
|
5
|
+
buf = Buffer.allocUnsafe(11 + len * 8);
|
|
6
|
+
buf[0] = negateType(op);
|
|
7
|
+
buf[1] = 5;
|
|
8
|
+
buf.writeUInt16LE(8, 2);
|
|
9
|
+
buf.writeUInt16LE(len, 4);
|
|
10
|
+
buf[6] = stripNegation(op);
|
|
11
|
+
buf[7] = prop.typeIndex;
|
|
12
|
+
buf[8] = 0;
|
|
13
|
+
buf.writeUInt16LE(prop.inverseTypeId, 9);
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
for (let i = 0; i < len; i++) {
|
|
16
|
+
buf.writeUInt32LE(value[i], 11 + i * 8);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
buf.writeUInt32LE(value, 11);
|
|
21
|
+
}
|
|
22
|
+
return buf;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=createReferenceFilter.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ALIAS } from '../../../server/schema/types.js';
|
|
2
|
+
import { negateType, stripNegation } from './operators.js';
|
|
3
|
+
import { createFixedFilterBuffer } from './createFixedFilterBuffer.js';
|
|
4
|
+
const parseValue = (value, prop, op) => {
|
|
5
|
+
let val = value;
|
|
6
|
+
if (op === 19 && typeof val === 'string') {
|
|
7
|
+
val = val.toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
if (val instanceof Uint8Array ||
|
|
10
|
+
typeof value === 'string' ||
|
|
11
|
+
!prop.separate ||
|
|
12
|
+
op !== 1) {
|
|
13
|
+
val = Buffer.from(val);
|
|
14
|
+
}
|
|
15
|
+
if (!(val instanceof Buffer)) {
|
|
16
|
+
throw new Error('Incorrect value for filter ' + prop.path);
|
|
17
|
+
}
|
|
18
|
+
return val;
|
|
19
|
+
};
|
|
20
|
+
export const createVariableFilterBuffer = (value, prop, op) => {
|
|
21
|
+
let isOr = 4;
|
|
22
|
+
let val;
|
|
23
|
+
let buf;
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
if (op !== 1 || !prop.separate) {
|
|
26
|
+
isOr = 2;
|
|
27
|
+
const x = [];
|
|
28
|
+
for (const v of value) {
|
|
29
|
+
const a = parseValue(v, prop, op);
|
|
30
|
+
const size = Buffer.allocUnsafe(2);
|
|
31
|
+
size.writeUint16LE(a.byteLength);
|
|
32
|
+
x.push(size, a);
|
|
33
|
+
}
|
|
34
|
+
val = Buffer.concat(x);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const x = [];
|
|
38
|
+
for (const v of value) {
|
|
39
|
+
x.push(parseValue(v, prop, op));
|
|
40
|
+
}
|
|
41
|
+
val = x;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
val = parseValue(value, prop, op);
|
|
46
|
+
}
|
|
47
|
+
// --------------------
|
|
48
|
+
if (op === 3 || op === 1 || op === 2 || op === 16 || op === 18 || op === 19) {
|
|
49
|
+
if (prop.separate) {
|
|
50
|
+
if (op === 1 && prop.typeIndex !== ALIAS) {
|
|
51
|
+
// 17 crc32 check
|
|
52
|
+
buf = createFixedFilterBuffer(prop, 8, 17, val, false);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
buf = writeVarFilter(isOr, val, buf, op, prop, 0, 0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// HANDLE EQUAL
|
|
60
|
+
buf = writeVarFilter(isOr, val, buf, op, prop, prop.start, prop.len);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.log('OP NOT SUPPORTED YET =>', op);
|
|
65
|
+
}
|
|
66
|
+
return buf;
|
|
67
|
+
};
|
|
68
|
+
function writeVarFilter(isOr, val, buf, op, prop, start, len) {
|
|
69
|
+
const size = val.byteLength;
|
|
70
|
+
buf = Buffer.allocUnsafe(12 + size);
|
|
71
|
+
buf[0] = negateType(op);
|
|
72
|
+
buf[1] = isOr;
|
|
73
|
+
buf.writeUInt16LE(start, 2);
|
|
74
|
+
buf.writeUint16LE(len, 4);
|
|
75
|
+
buf.writeUint32LE(size, 6);
|
|
76
|
+
buf[10] = stripNegation(op);
|
|
77
|
+
buf[11] = prop.typeIndex;
|
|
78
|
+
buf.set(val, 12);
|
|
79
|
+
return buf;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=createVariableFilterBuffer.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { QueryDef, QueryDefFilter } from '../types.js';
|
|
2
|
+
import { SchemaTypeDef } from '../../../server/schema/schema.js';
|
|
3
|
+
import { Operator } from './operators.js';
|
|
4
|
+
import { Filter, FilterAst } from './types.js';
|
|
5
|
+
import { DbClient } from '../../index.js';
|
|
6
|
+
export { Operator, Filter };
|
|
7
|
+
export declare const filterRaw: (db: DbClient, filter: Filter, schema: SchemaTypeDef, conditions: QueryDefFilter, def: QueryDef) => number;
|
|
8
|
+
export declare const filter: (db: DbClient, def: QueryDef, filterAst: FilterAst, conditions: QueryDefFilter) => void;
|
|
9
|
+
export declare const filterOr: (db: DbClient, def: QueryDef, filterAst: FilterAst[], conditions: QueryDefFilter) => QueryDefFilter;
|
|
10
|
+
export declare const convertFilter: (field: string, operator?: Operator | boolean, value?: any) => FilterAst;
|