@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,41 @@
|
|
|
1
|
+
import { REFERENCE, } from '../../../server/schema/types.js';
|
|
2
|
+
import { createQueryDef } from '../queryDef.js';
|
|
3
|
+
import { QueryDefType } from '../types.js';
|
|
4
|
+
export const getAllFieldFromObject = (tree, arr = []) => {
|
|
5
|
+
for (const key in tree) {
|
|
6
|
+
const leaf = tree[key];
|
|
7
|
+
if (!leaf.typeIndex && !leaf.__isPropDef) {
|
|
8
|
+
getAllFieldFromObject(leaf, arr);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
arr.push(leaf.path.join('.'));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return arr;
|
|
15
|
+
};
|
|
16
|
+
const createRefQueryDef = (db, def, t) => {
|
|
17
|
+
const defRef = createQueryDef(db, t.typeIndex === REFERENCE
|
|
18
|
+
? QueryDefType.Reference
|
|
19
|
+
: QueryDefType.References, {
|
|
20
|
+
type: t.inverseTypeName,
|
|
21
|
+
propDef: t,
|
|
22
|
+
});
|
|
23
|
+
def.references.set(t.prop, defRef);
|
|
24
|
+
return defRef;
|
|
25
|
+
};
|
|
26
|
+
export const createOrGetRefQueryDef = (db, def, t) => {
|
|
27
|
+
if (!def.references.has(t.prop)) {
|
|
28
|
+
return createRefQueryDef(db, def, t);
|
|
29
|
+
}
|
|
30
|
+
return def.references.get(t.prop);
|
|
31
|
+
};
|
|
32
|
+
export const createOrGetEdgeRefQueryDef = (db, def, t) => {
|
|
33
|
+
def.edges ??= createQueryDef(db, QueryDefType.Edge, {
|
|
34
|
+
ref: t,
|
|
35
|
+
});
|
|
36
|
+
def.edges.props ??= {};
|
|
37
|
+
def.edges.props[t.name] = t;
|
|
38
|
+
const refDef = createOrGetRefQueryDef(db, def.edges, t);
|
|
39
|
+
return refDef;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isPropDef, REFERENCE, REFERENCES, } from '../../../server/schema/types.js';
|
|
2
|
+
import { createQueryDef } from '../queryDef.js';
|
|
3
|
+
import { isRefDef, QueryDefType } from '../types.js';
|
|
4
|
+
import { getAllFieldFromObject, createOrGetRefQueryDef } from './utils.js';
|
|
5
|
+
import { includeFields, includeProp, includeAllProps } from './props.js';
|
|
6
|
+
export const walkDefs = (db, def, f) => {
|
|
7
|
+
const prop = def.props[f];
|
|
8
|
+
const path = f.split('.');
|
|
9
|
+
if (!prop) {
|
|
10
|
+
let t = def.schema.tree;
|
|
11
|
+
for (let i = 0; i < path.length; i++) {
|
|
12
|
+
const p = path[i];
|
|
13
|
+
if (isRefDef(def) && p[0] == '$') {
|
|
14
|
+
if (!def.edges) {
|
|
15
|
+
def.edges = createQueryDef(db, QueryDefType.Edge, {
|
|
16
|
+
ref: def.target.propDef,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const edgeProp = def.edges.props[p];
|
|
20
|
+
if (edgeProp.typeIndex === REFERENCE ||
|
|
21
|
+
edgeProp.typeIndex === REFERENCES) {
|
|
22
|
+
const refDef = createOrGetRefQueryDef(db, def.edges, edgeProp);
|
|
23
|
+
if (path.length - 1 === i) {
|
|
24
|
+
includeAllProps(refDef);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const f = path.slice(i + 1).join('.');
|
|
28
|
+
if (!includeProp(refDef, refDef.props[f])) {
|
|
29
|
+
includeFields(refDef, [f]);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
def.edges.include.props.add(edgeProp.prop);
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
t = t[p];
|
|
40
|
+
if (!t) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (isPropDef(t) &&
|
|
44
|
+
(t.typeIndex === REFERENCE || t.typeIndex === REFERENCES)) {
|
|
45
|
+
const refDef = createOrGetRefQueryDef(db, def, t);
|
|
46
|
+
const f = path.slice(i + 1).join('.');
|
|
47
|
+
if (!includeProp(refDef, refDef.props[f])) {
|
|
48
|
+
includeFields(refDef, [f]);
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const tree = def.schema.tree[path[0]];
|
|
54
|
+
if (tree) {
|
|
55
|
+
const endFields = getAllFieldFromObject(tree);
|
|
56
|
+
for (const field of endFields) {
|
|
57
|
+
walkDefs(db, def, field);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES) {
|
|
62
|
+
const refDef = createOrGetRefQueryDef(db, def, prop);
|
|
63
|
+
includeAllProps(refDef);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
includeProp(def, prop);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=walk.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './queryDef.js';
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export * from './include/props.js';
|
|
4
|
+
export * from './include/toBuffer.js';
|
|
5
|
+
export * from './toBuffer.js';
|
|
6
|
+
export * from './filter/filter.js';
|
|
7
|
+
export * from './filter/toBuffer.js';
|
|
8
|
+
export * from './sort.js';
|
|
9
|
+
export * from './debug.js';
|
|
10
|
+
export * from './read/read.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './queryDef.js';
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export * from './include/props.js';
|
|
4
|
+
export * from './include/toBuffer.js';
|
|
5
|
+
export * from './toBuffer.js';
|
|
6
|
+
export * from './filter/filter.js';
|
|
7
|
+
export * from './filter/toBuffer.js';
|
|
8
|
+
export * from './sort.js';
|
|
9
|
+
export * from './debug.js';
|
|
10
|
+
export * from './read/read.js';
|
|
11
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { MAX_RANGE_PROP_LIMIT, MAX_RANGE_REF_LIMIT } from './thresholds.js';
|
|
2
|
+
import { QueryDefType, } from './types.js';
|
|
3
|
+
const createEmptySharedDef = () => {
|
|
4
|
+
const q = {
|
|
5
|
+
filter: { conditions: new Map(), size: 0 },
|
|
6
|
+
range: { offset: 0, limit: 0 },
|
|
7
|
+
include: {
|
|
8
|
+
stringFields: new Set(),
|
|
9
|
+
props: new Set(),
|
|
10
|
+
propsRead: {},
|
|
11
|
+
main: {
|
|
12
|
+
len: 0,
|
|
13
|
+
include: {},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
sort: null,
|
|
17
|
+
references: new Map(),
|
|
18
|
+
};
|
|
19
|
+
return q;
|
|
20
|
+
};
|
|
21
|
+
export const createQueryDef = (db, type, target) => {
|
|
22
|
+
const queryDef = createEmptySharedDef();
|
|
23
|
+
if (type === QueryDefType.Edge) {
|
|
24
|
+
const t = target;
|
|
25
|
+
const q = queryDef;
|
|
26
|
+
q.props = t.ref.edges;
|
|
27
|
+
q.reverseProps = t.ref.reverseEdges;
|
|
28
|
+
q.type = type;
|
|
29
|
+
q.target = t;
|
|
30
|
+
return q;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const t = target;
|
|
34
|
+
const q = queryDef;
|
|
35
|
+
q.schema = db.schemaTypesParsed[t.type];
|
|
36
|
+
q.props = q.schema.props;
|
|
37
|
+
q.type = type;
|
|
38
|
+
q.target = t;
|
|
39
|
+
if (type === QueryDefType.Root) {
|
|
40
|
+
// IDS sort
|
|
41
|
+
if (t.ids) {
|
|
42
|
+
q.range.limit = t.ids.length; // 1k?
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
q.range.limit = MAX_RANGE_PROP_LIMIT;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (type === QueryDefType.References) {
|
|
49
|
+
q.range.limit = MAX_RANGE_REF_LIMIT;
|
|
50
|
+
}
|
|
51
|
+
return q;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=queryDef.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { QueryDef } from '../types.js';
|
|
2
|
+
export type Item = {
|
|
3
|
+
id: number;
|
|
4
|
+
} & {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export declare const readAllFields: (q: QueryDef, result: Buffer, offset: number, end: number, item: Item, id: number) => number;
|
|
8
|
+
export declare const resultToObject: (q: QueryDef, result: Buffer, end: number, offset?: number) => any;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, } from '../../../server/schema/types.js';
|
|
2
|
+
import { read } from '../../string.js';
|
|
3
|
+
const addField = (p, value, item, defaultOnly = false) => {
|
|
4
|
+
let i = p.__isEdge === true ? 1 : 0;
|
|
5
|
+
const len = p.path.length;
|
|
6
|
+
if (len - i === 1) {
|
|
7
|
+
const field = p.path[i];
|
|
8
|
+
if (!defaultOnly || !(field in item)) {
|
|
9
|
+
item[field] = value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
let select = item;
|
|
14
|
+
for (; i < len; i++) {
|
|
15
|
+
const field = p.path[i];
|
|
16
|
+
if (i === len - 1) {
|
|
17
|
+
if (!defaultOnly || !(field in select)) {
|
|
18
|
+
select[field] = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
select = select[field] ?? (select[field] = {});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const readMainValue = (prop, result, index, item) => {
|
|
28
|
+
// 1: timestamp, 4: number
|
|
29
|
+
if (prop.typeIndex === TIMESTAMP || prop.typeIndex === NUMBER) {
|
|
30
|
+
addField(prop, result.readDoubleLE(index), item);
|
|
31
|
+
}
|
|
32
|
+
// 5: uint32
|
|
33
|
+
else if (prop.typeIndex === UINT32) {
|
|
34
|
+
addField(prop, result.readUInt32LE(index), item);
|
|
35
|
+
}
|
|
36
|
+
// 9: boolean
|
|
37
|
+
else if (prop.typeIndex === BOOLEAN) {
|
|
38
|
+
addField(prop, Boolean(result[index]), item);
|
|
39
|
+
}
|
|
40
|
+
// 10: Enum
|
|
41
|
+
else if (prop.typeIndex === ENUM) {
|
|
42
|
+
if (result[index] === 0) {
|
|
43
|
+
addField(prop, undefined, item);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
addField(prop, prop.enum[result[index] - 1], item);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// 11: string
|
|
50
|
+
else if (prop.typeIndex === STRING) {
|
|
51
|
+
// Also remove this default then (same as other string)
|
|
52
|
+
const len = result[index];
|
|
53
|
+
if (len !== 0) {
|
|
54
|
+
const str = result.toString('utf-8', index + 1, index + len + 1);
|
|
55
|
+
addField(prop, str, item);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
addField(prop, '', item);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// 11: string
|
|
62
|
+
else if (prop.typeIndex === BINARY) {
|
|
63
|
+
addField(prop, new Uint8Array(result.buffer, index + 1, result[index]), item);
|
|
64
|
+
}
|
|
65
|
+
// 18: int8
|
|
66
|
+
else if (prop.typeIndex === INT8) {
|
|
67
|
+
addField(prop, result.readInt8(index), item);
|
|
68
|
+
}
|
|
69
|
+
// 19: uint8
|
|
70
|
+
else if (prop.typeIndex === UINT8) {
|
|
71
|
+
addField(prop, result.readUint8(index), item);
|
|
72
|
+
}
|
|
73
|
+
// 20: int16
|
|
74
|
+
else if (prop.typeIndex === INT16) {
|
|
75
|
+
addField(prop, result.readInt16LE(index), item);
|
|
76
|
+
}
|
|
77
|
+
// 21: uint16
|
|
78
|
+
else if (prop.typeIndex === UINT16) {
|
|
79
|
+
addField(prop, result.readUint16LE(index), item);
|
|
80
|
+
}
|
|
81
|
+
// 22: int32
|
|
82
|
+
else if (prop.typeIndex === INT32) {
|
|
83
|
+
addField(prop, result.readInt32LE(index), item);
|
|
84
|
+
}
|
|
85
|
+
// 5: uint32
|
|
86
|
+
else if (prop.typeIndex === UINT32) {
|
|
87
|
+
addField(prop, result.readUint32LE(index), item);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const readMain = (q, result, offset, item) => {
|
|
91
|
+
const mainInclude = q.include.main;
|
|
92
|
+
let i = offset;
|
|
93
|
+
if (mainInclude.len === q.schema.mainLen) {
|
|
94
|
+
for (const start in q.schema.main) {
|
|
95
|
+
readMainValue(q.schema.main[start], result, Number(start) + i, item);
|
|
96
|
+
}
|
|
97
|
+
i += q.schema.mainLen;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
for (const k in mainInclude.include) {
|
|
101
|
+
const [index, prop] = mainInclude.include[k];
|
|
102
|
+
readMainValue(prop, result, index + i, item);
|
|
103
|
+
}
|
|
104
|
+
i += mainInclude.len;
|
|
105
|
+
}
|
|
106
|
+
return i - offset;
|
|
107
|
+
};
|
|
108
|
+
const handleUndefinedProps = (id, q, item) => {
|
|
109
|
+
for (const k in q.include.propsRead) {
|
|
110
|
+
if (q.include.propsRead[k] !== id) {
|
|
111
|
+
addField(q.schema.reverseProps[k], '', item);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
export const readAllFields = (q, result, offset, end, item, id) => {
|
|
116
|
+
let i = offset;
|
|
117
|
+
while (i < end) {
|
|
118
|
+
const index = result[i];
|
|
119
|
+
i++;
|
|
120
|
+
if (index === 255) {
|
|
121
|
+
handleUndefinedProps(id, q, item);
|
|
122
|
+
return i - offset;
|
|
123
|
+
}
|
|
124
|
+
if (index === 252) {
|
|
125
|
+
let prop = result[i];
|
|
126
|
+
if (prop === 254) {
|
|
127
|
+
i++;
|
|
128
|
+
const field = result[i];
|
|
129
|
+
i++;
|
|
130
|
+
const size = result.readUint32LE(i);
|
|
131
|
+
i += 4;
|
|
132
|
+
const ref = q.edges.references.get(field);
|
|
133
|
+
if (size === 0) {
|
|
134
|
+
// @ts-ignore
|
|
135
|
+
addField(ref.target.propDef, null, item);
|
|
136
|
+
i += size;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
i++;
|
|
140
|
+
let id = result.readUInt32LE(i);
|
|
141
|
+
i += 4;
|
|
142
|
+
const refItem = {
|
|
143
|
+
id,
|
|
144
|
+
};
|
|
145
|
+
readAllFields(ref, result, i, size + i - 5, refItem, id);
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
addField(ref.target.propDef, refItem, item);
|
|
148
|
+
i += size - 5;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else if (prop === 253) {
|
|
152
|
+
i++;
|
|
153
|
+
const field = result[i];
|
|
154
|
+
i++;
|
|
155
|
+
const ref = q.edges.references.get(field);
|
|
156
|
+
const size = result.readUint32LE(i);
|
|
157
|
+
i += 4;
|
|
158
|
+
const refs = resultToObject(ref, result, size + i + 4, i);
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
addField(ref.target.propDef, refs, item);
|
|
161
|
+
i += size + 4;
|
|
162
|
+
// ----------------
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const edgeDef = q.edges.reverseProps[prop];
|
|
166
|
+
const t = edgeDef.typeIndex;
|
|
167
|
+
if (t === BINARY) {
|
|
168
|
+
i++;
|
|
169
|
+
const size = result.readUint32LE(i);
|
|
170
|
+
addField(edgeDef, new Uint8Array(result.buffer, i + 6, size - 6), item);
|
|
171
|
+
i += size + 4;
|
|
172
|
+
}
|
|
173
|
+
else if (t === STRING || t === ALIAS || t === ALIASES) {
|
|
174
|
+
i++;
|
|
175
|
+
const size = result.readUint32LE(i);
|
|
176
|
+
if (size === 0) {
|
|
177
|
+
addField(edgeDef, '', item);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
addField(edgeDef, read(result, i + 4, size), item);
|
|
181
|
+
}
|
|
182
|
+
i += size + 4;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
i++;
|
|
186
|
+
readMainValue(edgeDef, result, i, item);
|
|
187
|
+
i += edgeDef.len;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (index === 254) {
|
|
192
|
+
const field = result[i];
|
|
193
|
+
i++;
|
|
194
|
+
const size = result.readUint32LE(i);
|
|
195
|
+
i += 4;
|
|
196
|
+
const ref = q.references.get(field);
|
|
197
|
+
if (size === 0) {
|
|
198
|
+
// @ts-ignore
|
|
199
|
+
addField(ref.target.propDef, null, item);
|
|
200
|
+
i += size;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
i++;
|
|
204
|
+
let id = result.readUInt32LE(i);
|
|
205
|
+
i += 4;
|
|
206
|
+
const refItem = {
|
|
207
|
+
id,
|
|
208
|
+
};
|
|
209
|
+
readAllFields(ref, result, i, size + i - 5, refItem, id);
|
|
210
|
+
// @ts-ignore
|
|
211
|
+
addField(ref.target.propDef, refItem, item);
|
|
212
|
+
i += size - 5;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else if (index === 253) {
|
|
216
|
+
const field = result[i];
|
|
217
|
+
i++;
|
|
218
|
+
const ref = q.references.get(field);
|
|
219
|
+
const size = result.readUint32LE(i);
|
|
220
|
+
i += 4;
|
|
221
|
+
const refs = resultToObject(ref, result, size + i + 4, i);
|
|
222
|
+
// @ts-ignore
|
|
223
|
+
addField(ref.target.propDef, refs, item);
|
|
224
|
+
i += size + 4;
|
|
225
|
+
}
|
|
226
|
+
else if (index === 0) {
|
|
227
|
+
i += readMain(q, result, i, item);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
const prop = q.schema.reverseProps[index];
|
|
231
|
+
if (prop.typeIndex === BINARY) {
|
|
232
|
+
q.include.propsRead[index] = id;
|
|
233
|
+
const size = result.readUint32LE(i);
|
|
234
|
+
addField(prop, new Uint8Array(result.buffer, i + 4 + 2, size - 6), item);
|
|
235
|
+
i += size + 4;
|
|
236
|
+
}
|
|
237
|
+
else if (prop.typeIndex === STRING) {
|
|
238
|
+
q.include.propsRead[index] = id;
|
|
239
|
+
const size = result.readUint32LE(i);
|
|
240
|
+
if (size === 0) {
|
|
241
|
+
addField(prop, '', item);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
addField(prop, read(result, i + 4, size), item);
|
|
245
|
+
}
|
|
246
|
+
i += size + 4;
|
|
247
|
+
}
|
|
248
|
+
else if (prop.typeIndex == TEXT) {
|
|
249
|
+
q.include.propsRead[index] = id;
|
|
250
|
+
const size = result.readUint32LE(i);
|
|
251
|
+
// TODO Read text
|
|
252
|
+
//if (size === 0) {
|
|
253
|
+
// addField(prop, '', item)
|
|
254
|
+
//} else {
|
|
255
|
+
// addField(prop, read(result, i + 4, size), item)
|
|
256
|
+
//}
|
|
257
|
+
i += size + 4;
|
|
258
|
+
}
|
|
259
|
+
else if (prop.typeIndex === ALIAS) {
|
|
260
|
+
q.include.propsRead[index] = id;
|
|
261
|
+
const size = result.readUint32LE(i);
|
|
262
|
+
i += 4;
|
|
263
|
+
if (size === 0) {
|
|
264
|
+
addField(prop, '', item);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
const string = result.toString('utf8', i, (i += size));
|
|
268
|
+
addField(prop, string, item);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// to add defaults - may not optimal for performance
|
|
274
|
+
handleUndefinedProps(id, q, item);
|
|
275
|
+
return i - offset;
|
|
276
|
+
};
|
|
277
|
+
export const resultToObject = (q, result, end, offset = 0) => {
|
|
278
|
+
const len = result.readUint32LE(offset);
|
|
279
|
+
if (len === 0) {
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
let items = [];
|
|
283
|
+
let i = 5 + offset;
|
|
284
|
+
while (i < end) {
|
|
285
|
+
let id = result.readUInt32LE(i);
|
|
286
|
+
i += 4;
|
|
287
|
+
const item = {
|
|
288
|
+
id,
|
|
289
|
+
};
|
|
290
|
+
if (q.search) {
|
|
291
|
+
item.$searchScore = result[i];
|
|
292
|
+
i += 1;
|
|
293
|
+
}
|
|
294
|
+
const l = readAllFields(q, result, i, end, item, id);
|
|
295
|
+
i += l;
|
|
296
|
+
items.push(item);
|
|
297
|
+
}
|
|
298
|
+
if ('id' in q.target || 'alias' in q.target) {
|
|
299
|
+
return items[0];
|
|
300
|
+
}
|
|
301
|
+
return items;
|
|
302
|
+
};
|
|
303
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import native from '../../native.js';
|
|
2
|
+
import { defToBuffer } from './toBuffer.js';
|
|
3
|
+
import { checkMaxBufferSize } from './validation.js';
|
|
4
|
+
export const registerQuery = (q) => {
|
|
5
|
+
// just add crc32 in the buffer
|
|
6
|
+
if (!q.id) {
|
|
7
|
+
const b = defToBuffer(q.db, q.def);
|
|
8
|
+
const buf = Buffer.concat(b);
|
|
9
|
+
let id = native.crc32(buf);
|
|
10
|
+
q.id = id;
|
|
11
|
+
// id = (id ^ q.def.schema.id) >>> 0
|
|
12
|
+
// typeId, crc32, len
|
|
13
|
+
// but want it to fit in a js number...
|
|
14
|
+
// use 2 bytes for len and just continue counting
|
|
15
|
+
// const x = Buffer.allocUnsafe(8)
|
|
16
|
+
// // const number
|
|
17
|
+
// x.writeUint16LE(q.def.schema.id, 0)
|
|
18
|
+
// x.writeUint32LE(id, 2)
|
|
19
|
+
// x.writeUint16LE(buf.byteLength, 6)
|
|
20
|
+
// // ------------------------
|
|
21
|
+
// console.log('-> CRC32', { id, x: new Uint8Array(x), y: x.readFloatLE(0) })
|
|
22
|
+
// do a test for
|
|
23
|
+
// console.log(id)
|
|
24
|
+
// id, len, type as id?
|
|
25
|
+
q.buffer = buf;
|
|
26
|
+
checkMaxBufferSize(buf);
|
|
27
|
+
return buf;
|
|
28
|
+
}
|
|
29
|
+
return q.buffer;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=registerQuery.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { QueryDefSearch, QueryDef } from '../types.js';
|
|
2
|
+
export type Search = string[] | {
|
|
3
|
+
[field: string]: number;
|
|
4
|
+
} | string;
|
|
5
|
+
export declare const search: (def: QueryDef, q: string, s?: Search) => void;
|
|
6
|
+
export declare const searchToBuffer: (search: QueryDefSearch) => Buffer;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { STRING } from '../../../server/schema/types.js';
|
|
2
|
+
const makeSize = (nr, u8 = false) => {
|
|
3
|
+
if (u8) {
|
|
4
|
+
const size = Buffer.allocUnsafe(1);
|
|
5
|
+
size[0] = nr;
|
|
6
|
+
return size;
|
|
7
|
+
}
|
|
8
|
+
const size = Buffer.allocUnsafe(2);
|
|
9
|
+
size.writeUint16LE(nr);
|
|
10
|
+
return size;
|
|
11
|
+
};
|
|
12
|
+
export const search = (def, q, s) => {
|
|
13
|
+
let blocks = 0;
|
|
14
|
+
const x = q.toLowerCase().trim().split(' ');
|
|
15
|
+
const bufs = [];
|
|
16
|
+
for (const s of x) {
|
|
17
|
+
if (s) {
|
|
18
|
+
const b = Buffer.from(s);
|
|
19
|
+
bufs.push(makeSize(b.byteLength), b);
|
|
20
|
+
blocks++;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
bufs.unshift(makeSize(blocks, true));
|
|
24
|
+
const query = Buffer.concat(bufs);
|
|
25
|
+
def.search = {
|
|
26
|
+
size: query.byteLength + 2,
|
|
27
|
+
query,
|
|
28
|
+
fields: [],
|
|
29
|
+
};
|
|
30
|
+
if (typeof s === 'string') {
|
|
31
|
+
s = [s];
|
|
32
|
+
}
|
|
33
|
+
if (!s) {
|
|
34
|
+
s = {};
|
|
35
|
+
for (const k in def.props) {
|
|
36
|
+
const prop = def.props[k];
|
|
37
|
+
// if title / name / headline add ROLE:
|
|
38
|
+
if (prop.typeIndex === STRING) {
|
|
39
|
+
s[k] = k === 'title' || k === 'name' || k === 'headline' ? 0 : 2;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (Array.isArray(s)) {
|
|
44
|
+
const x = {};
|
|
45
|
+
for (const f of s) {
|
|
46
|
+
x[f] = 0;
|
|
47
|
+
}
|
|
48
|
+
s = x;
|
|
49
|
+
}
|
|
50
|
+
for (const key in s) {
|
|
51
|
+
const prop = def.props[key];
|
|
52
|
+
if (!prop) {
|
|
53
|
+
throw new Error('field ' + key + ' does not exist on type');
|
|
54
|
+
}
|
|
55
|
+
if (prop.typeIndex !== STRING) {
|
|
56
|
+
throw new Error('Can only search trough strings');
|
|
57
|
+
}
|
|
58
|
+
def.search.size += 4;
|
|
59
|
+
def.search.fields.push({
|
|
60
|
+
weight: s[key],
|
|
61
|
+
field: prop.prop,
|
|
62
|
+
start: prop.start ?? 0,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
export const searchToBuffer = (search) => {
|
|
67
|
+
const result = Buffer.allocUnsafe(search.size);
|
|
68
|
+
result.writeUint16LE(search.query.byteLength, 0);
|
|
69
|
+
result.set(search.query, 2);
|
|
70
|
+
const offset = search.query.byteLength + 2;
|
|
71
|
+
search.fields.sort((a, b) => {
|
|
72
|
+
return a.weight - b.weight;
|
|
73
|
+
});
|
|
74
|
+
for (let i = 0; i < search.fields.length * 4; i += 4) {
|
|
75
|
+
const f = search.fields[i / 4];
|
|
76
|
+
result[i + offset] = f.field;
|
|
77
|
+
result[i + 1 + offset] = f.weight;
|
|
78
|
+
result.writeUInt16LE(f.start, i + 2 + offset);
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const createSortBuffer = (sort) => {
|
|
2
|
+
const buf = Buffer.allocUnsafe(7);
|
|
3
|
+
// [order] [propType] [start] [start] [len] [len]
|
|
4
|
+
buf[0] = sort.order;
|
|
5
|
+
buf[1] = sort.prop.prop;
|
|
6
|
+
buf[2] = sort.prop.typeIndex;
|
|
7
|
+
buf.writeUint16LE(sort.prop.start, 3);
|
|
8
|
+
buf.writeUint16LE(sort.prop.len, 5);
|
|
9
|
+
return buf;
|
|
10
|
+
};
|
|
11
|
+
// NO REF / REFERENCES SUPPORT
|
|
12
|
+
export const sort = (def, field, order) => {
|
|
13
|
+
def.sort = {
|
|
14
|
+
prop: def.props[field],
|
|
15
|
+
order: order === 'asc' || order === undefined ? 0 : 1,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=sort.js.map
|