@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,40 @@
|
|
|
1
|
+
import { ALIAS } from '../../server/schema/types.js';
|
|
2
|
+
export async function upsert(db, type, obj) {
|
|
3
|
+
const tree = db.schemaTypesParsed[type].tree;
|
|
4
|
+
let q;
|
|
5
|
+
let id = '';
|
|
6
|
+
for (const key in obj) {
|
|
7
|
+
if (tree[key].typeIndex === ALIAS) {
|
|
8
|
+
id += `${key}:${obj[key]};`;
|
|
9
|
+
if (q) {
|
|
10
|
+
q = q.or(key, '=', obj[key]);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
q = db.query(type).include('id').filter(key, '=', obj[key]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (!q) {
|
|
18
|
+
throw new Error('no alias found for upsert operation');
|
|
19
|
+
}
|
|
20
|
+
if (db.upserting.has(id)) {
|
|
21
|
+
const store = db.upserting.get(id);
|
|
22
|
+
store.o = { ...store.o, ...obj };
|
|
23
|
+
return store.p;
|
|
24
|
+
}
|
|
25
|
+
const store = {
|
|
26
|
+
o: obj,
|
|
27
|
+
p: q.get().then((res) => {
|
|
28
|
+
db.upserting.delete(id);
|
|
29
|
+
if (res.length === 0) {
|
|
30
|
+
return db.create(type, store.o);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return db.update(type, res.toObject()[0].id, store.o);
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
db.upserting.set(id, store);
|
|
38
|
+
return store.p;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=upsert.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PropDef, SchemaTypeDef } from '../server/schema/types.js';
|
|
2
|
+
import { DbClient } from './index.js';
|
|
3
|
+
import { ModifyState } from './modify/ModifyRes.js';
|
|
4
|
+
export declare class ModifyCtx {
|
|
5
|
+
constructor(db: DbClient);
|
|
6
|
+
len: number;
|
|
7
|
+
id: number;
|
|
8
|
+
lastMain: number;
|
|
9
|
+
hasStringField: number;
|
|
10
|
+
queue: Map<(payload: any) => void, ModifyState>;
|
|
11
|
+
ctx: {
|
|
12
|
+
offsets?: Record<number, number>;
|
|
13
|
+
};
|
|
14
|
+
payload: Buffer;
|
|
15
|
+
max: number;
|
|
16
|
+
buf: Buffer;
|
|
17
|
+
field: number;
|
|
18
|
+
prefix0: number;
|
|
19
|
+
prefix1: number;
|
|
20
|
+
mergeMain: (PropDef | any)[] | null;
|
|
21
|
+
mergeMainSize: number;
|
|
22
|
+
db: DbClient;
|
|
23
|
+
dirtyRanges: Set<number>;
|
|
24
|
+
dirtyTypes: Map<number, number>;
|
|
25
|
+
markNodeDirty(schema: SchemaTypeDef, nodeId: number): void;
|
|
26
|
+
markTypeDirty(schema: SchemaTypeDef): void;
|
|
27
|
+
updateMax(): void;
|
|
28
|
+
getData(): Buffer;
|
|
29
|
+
}
|
|
30
|
+
export declare const flushBuffer: (db: DbClient) => Promise<void>;
|
|
31
|
+
export declare const startDrain: (db: DbClient) => void;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { makeCsmtKeyFromNodeId } from './tree.js';
|
|
2
|
+
export class ModifyCtx {
|
|
3
|
+
constructor(db) {
|
|
4
|
+
this.max = db.maxModifySize;
|
|
5
|
+
this.db = db;
|
|
6
|
+
this.buf = Buffer.allocUnsafe(db.maxModifySize);
|
|
7
|
+
}
|
|
8
|
+
// default values
|
|
9
|
+
len = 0;
|
|
10
|
+
id = -1;
|
|
11
|
+
lastMain = -1;
|
|
12
|
+
hasStringField = -1;
|
|
13
|
+
queue = new Map();
|
|
14
|
+
ctx = {}; // maybe make this different?
|
|
15
|
+
payload;
|
|
16
|
+
max;
|
|
17
|
+
buf;
|
|
18
|
+
field;
|
|
19
|
+
prefix0 = -1;
|
|
20
|
+
prefix1 = -1;
|
|
21
|
+
mergeMain;
|
|
22
|
+
mergeMainSize;
|
|
23
|
+
db;
|
|
24
|
+
dirtyRanges = new Set();
|
|
25
|
+
dirtyTypes = new Map();
|
|
26
|
+
markNodeDirty(schema, nodeId) {
|
|
27
|
+
const key = makeCsmtKeyFromNodeId(schema.id, schema.blockCapacity, nodeId);
|
|
28
|
+
if (this.dirtyRanges.has(key)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.dirtyRanges.add(key);
|
|
32
|
+
this.updateMax();
|
|
33
|
+
}
|
|
34
|
+
markTypeDirty(schema) {
|
|
35
|
+
if (this.dirtyTypes.has(schema.id)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.dirtyTypes.set(schema.id, schema.lastId);
|
|
39
|
+
this.updateMax();
|
|
40
|
+
}
|
|
41
|
+
updateMax() {
|
|
42
|
+
// reserve space in the end of the buf [...data, type (16), lastId (32), typesSize (16), ...ranges (64)[], dataLen (32)]
|
|
43
|
+
this.max =
|
|
44
|
+
this.db.maxModifySize -
|
|
45
|
+
4 -
|
|
46
|
+
2 -
|
|
47
|
+
this.dirtyTypes.size * 10 -
|
|
48
|
+
this.dirtyRanges.size * 8;
|
|
49
|
+
}
|
|
50
|
+
getData() {
|
|
51
|
+
const rangesSize = this.dirtyRanges.size;
|
|
52
|
+
const typesSize = this.dirtyTypes.size;
|
|
53
|
+
const data = this.buf.subarray(0, this.len + 4 + 2 + typesSize * 10 + rangesSize * 8);
|
|
54
|
+
let i = this.len;
|
|
55
|
+
data.writeUint16LE(typesSize, i);
|
|
56
|
+
i += 2;
|
|
57
|
+
for (const [id, startId] of this.dirtyTypes) {
|
|
58
|
+
const lastId = this.db.schemaTypesParsedById[id].lastId;
|
|
59
|
+
data.writeUint16LE(id, i);
|
|
60
|
+
i += 2;
|
|
61
|
+
data.writeUint32LE(startId, i);
|
|
62
|
+
i += 4;
|
|
63
|
+
data.writeUint32LE(lastId, i);
|
|
64
|
+
i += 4;
|
|
65
|
+
}
|
|
66
|
+
for (let key of this.dirtyRanges) {
|
|
67
|
+
data.writeDoubleLE(key, i);
|
|
68
|
+
i += 8;
|
|
69
|
+
}
|
|
70
|
+
data.writeUint32LE(this.len, i);
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export const flushBuffer = (db) => {
|
|
75
|
+
const ctx = db.modifyCtx;
|
|
76
|
+
let flushPromise;
|
|
77
|
+
if (ctx.len) {
|
|
78
|
+
const d = Date.now();
|
|
79
|
+
const data = ctx.getData();
|
|
80
|
+
const resCtx = ctx.ctx;
|
|
81
|
+
const queue = ctx.queue;
|
|
82
|
+
flushPromise = db.hooks.flushModify(data).then(({ offsets }) => {
|
|
83
|
+
resCtx.offsets = offsets;
|
|
84
|
+
db.writeTime += Date.now() - d;
|
|
85
|
+
if (queue.size) {
|
|
86
|
+
flushPromise.then(() => {
|
|
87
|
+
for (const [resolve, res] of queue) {
|
|
88
|
+
resolve(res.getId(offsets));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
ctx.dirtyTypes.clear();
|
|
94
|
+
ctx.dirtyRanges.clear();
|
|
95
|
+
ctx.len = 0;
|
|
96
|
+
ctx.prefix0 = -1;
|
|
97
|
+
ctx.prefix1 = -1;
|
|
98
|
+
ctx.max = db.maxModifySize;
|
|
99
|
+
ctx.ctx = {};
|
|
100
|
+
}
|
|
101
|
+
db.isDraining = false;
|
|
102
|
+
return flushPromise;
|
|
103
|
+
};
|
|
104
|
+
export const startDrain = (db) => {
|
|
105
|
+
db.isDraining = true;
|
|
106
|
+
process.nextTick(() => {
|
|
107
|
+
flushBuffer(db);
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { QueryDef, Operator, QueryByAliasObj } from './query.js';
|
|
2
|
+
import { BasedQueryResponse } from './BasedIterable.js';
|
|
3
|
+
import { FilterAst, FilterBranchFn } from './filter/types.js';
|
|
4
|
+
import { Search } from './search/index.js';
|
|
5
|
+
import { OnData, OnError } from './subscription/index.js';
|
|
6
|
+
import { DbClient } from '../index.js';
|
|
7
|
+
export { QueryByAliasObj };
|
|
8
|
+
export type SelectFn = (field: string) => BasedDbReferenceQuery;
|
|
9
|
+
export type BranchInclude = (select: SelectFn) => any;
|
|
10
|
+
export declare class QueryBranch<T> {
|
|
11
|
+
db: DbClient;
|
|
12
|
+
def: QueryDef;
|
|
13
|
+
constructor(db: DbClient, def: QueryDef);
|
|
14
|
+
sort(field: string, order?: 'asc' | 'desc'): T;
|
|
15
|
+
filter(field: string, operator?: Operator | boolean, value?: any): T;
|
|
16
|
+
search(query: string, ...fields: Search[]): T;
|
|
17
|
+
filterBatch(f: FilterAst): this;
|
|
18
|
+
or(fn: FilterBranchFn): T;
|
|
19
|
+
or(field: string, operator?: Operator | boolean, value?: any): T;
|
|
20
|
+
range(offset: number, limit: number): T;
|
|
21
|
+
include(...fields: (string | BranchInclude | string[])[]): T;
|
|
22
|
+
}
|
|
23
|
+
export declare class BasedDbReferenceQuery extends QueryBranch<BasedDbReferenceQuery> {
|
|
24
|
+
}
|
|
25
|
+
declare class GetPromise extends Promise<BasedQueryResponse> {
|
|
26
|
+
toObject(): Promise<any>;
|
|
27
|
+
toJSON(): Promise<string>;
|
|
28
|
+
inspect(): GetPromise;
|
|
29
|
+
}
|
|
30
|
+
export declare class BasedDbQuery extends QueryBranch<BasedDbQuery> {
|
|
31
|
+
#private;
|
|
32
|
+
constructor(db: DbClient, type: string, id?: QueryByAliasObj | number | (QueryByAliasObj | number)[]);
|
|
33
|
+
id: number;
|
|
34
|
+
get(): GetPromise;
|
|
35
|
+
buffer: Buffer;
|
|
36
|
+
register(): Buffer;
|
|
37
|
+
subscribe(onData: OnData, onError?: OnError): import("./subscription/types.js").OnClose;
|
|
38
|
+
_getSync(dbCtxExternal: any): BasedQueryResponse;
|
|
39
|
+
toBuffer(): Buffer;
|
|
40
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { createQueryDef, QueryDefType, includeFields, filter, sort, defToBuffer, getAll, filterOr, convertFilter, isAlias, } from './query.js';
|
|
2
|
+
import { BasedQueryResponse } from './BasedIterable.js';
|
|
3
|
+
import { createOrGetEdgeRefQueryDef, createOrGetRefQueryDef, } from './include/utils.js';
|
|
4
|
+
import { FilterBranch } from './filter/FilterBranch.js';
|
|
5
|
+
import { search } from './search/index.js';
|
|
6
|
+
import { isValidId, checkMaxIdsPerQuery, checkTotalBufferSize, hasField, hasFields, } from './validation.js';
|
|
7
|
+
import native from '../../native.js';
|
|
8
|
+
import { REFERENCE, REFERENCES } from '../../server/schema/types.js';
|
|
9
|
+
import { subscribe } from './subscription/index.js';
|
|
10
|
+
import { registerQuery } from './registerQuery.js';
|
|
11
|
+
export class QueryBranch {
|
|
12
|
+
db;
|
|
13
|
+
def;
|
|
14
|
+
constructor(db, def) {
|
|
15
|
+
this.db = db;
|
|
16
|
+
this.def = def;
|
|
17
|
+
}
|
|
18
|
+
sort(field, order = 'asc') {
|
|
19
|
+
sort(this.def, field, order);
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
filter(field, operator, value) {
|
|
24
|
+
const f = convertFilter(field, operator, value);
|
|
25
|
+
filter(this.db, this.def, f, this.def.filter);
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
search(query, ...fields) {
|
|
30
|
+
if (fields.length) {
|
|
31
|
+
if (fields.length === 1) {
|
|
32
|
+
search(this.def, query, fields[0]);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const s = {};
|
|
36
|
+
for (const f of fields) {
|
|
37
|
+
if (typeof f === 'string') {
|
|
38
|
+
s[f] = 0;
|
|
39
|
+
}
|
|
40
|
+
else if (Array.isArray(f)) {
|
|
41
|
+
for (const ff of f) {
|
|
42
|
+
s[ff] = 0;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (typeof f === 'object') {
|
|
46
|
+
Object.assign(s, f);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
search(this.def, query, s);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
search(this.def, query);
|
|
54
|
+
}
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
filterBatch(f) {
|
|
59
|
+
filter(this.db, this.def, f, this.def.filter);
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
or(field, operator, value) {
|
|
64
|
+
if (typeof field === 'function') {
|
|
65
|
+
const f = new FilterBranch(this.db, filterOr(this.db, this.def, [], this.def.filter), this.def);
|
|
66
|
+
field(f);
|
|
67
|
+
this.def.filter.size += f.filterBranch.size;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const f = convertFilter(field, operator, value);
|
|
71
|
+
filterOr(this.db, this.def, f, this.def.filter);
|
|
72
|
+
}
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
range(offset, limit) {
|
|
77
|
+
this.def.range.offset = offset;
|
|
78
|
+
this.def.range.limit = limit;
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
include(...fields) {
|
|
83
|
+
for (const f of fields) {
|
|
84
|
+
if (typeof f === 'string') {
|
|
85
|
+
if (f === '*') {
|
|
86
|
+
hasFields(this.def.props);
|
|
87
|
+
includeFields(this.def, getAll(this.def.props));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.def.include.stringFields.add(f);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (typeof f === 'function') {
|
|
94
|
+
f((field) => {
|
|
95
|
+
if (field[0] == '$') {
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
const prop = this.def.target?.propDef?.edges[field];
|
|
98
|
+
if (prop &&
|
|
99
|
+
(prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES)) {
|
|
100
|
+
const refDef = createOrGetEdgeRefQueryDef(this.db, this.def, prop);
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
return new QueryBranch(this.db, refDef);
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`No edge reference or edge references field named "${field}"`);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const prop = field[0] == '$'
|
|
108
|
+
? // @ts-ignore
|
|
109
|
+
this.def.target?.propDef?.edges[field]
|
|
110
|
+
: this.def.props[field];
|
|
111
|
+
if (prop &&
|
|
112
|
+
(prop.typeIndex === REFERENCE || prop.typeIndex === REFERENCES)) {
|
|
113
|
+
const refDef = createOrGetRefQueryDef(this.db, this.def, prop);
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
return new QueryBranch(this.db, refDef);
|
|
116
|
+
}
|
|
117
|
+
throw new Error(`No reference or references field named "${field}"`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else if (Array.isArray(f)) {
|
|
122
|
+
for (const field of f) {
|
|
123
|
+
hasField(field);
|
|
124
|
+
}
|
|
125
|
+
includeFields(this.def, f);
|
|
126
|
+
}
|
|
127
|
+
else if (f !== undefined) {
|
|
128
|
+
throw new Error('Invalid include statement: expected props, refs and edges (string or array) or function');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export class BasedDbReferenceQuery extends QueryBranch {
|
|
136
|
+
}
|
|
137
|
+
const resToJSON = (res) => res.toJSON();
|
|
138
|
+
const resToObject = (res) => res.toObject();
|
|
139
|
+
const resInspect = (res) => new GetPromise((resolve) => resolve(res.inspect()));
|
|
140
|
+
class GetPromise extends Promise {
|
|
141
|
+
toObject() {
|
|
142
|
+
return this.then(resToObject);
|
|
143
|
+
}
|
|
144
|
+
toJSON() {
|
|
145
|
+
return this.then(resToJSON);
|
|
146
|
+
}
|
|
147
|
+
inspect() {
|
|
148
|
+
return this.then(resInspect);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export class BasedDbQuery extends QueryBranch {
|
|
152
|
+
constructor(db, type, id) {
|
|
153
|
+
const target = {
|
|
154
|
+
type,
|
|
155
|
+
};
|
|
156
|
+
if (id) {
|
|
157
|
+
if (isAlias(id)) {
|
|
158
|
+
target.alias = id;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
if (Array.isArray(id)) {
|
|
162
|
+
checkMaxIdsPerQuery(id);
|
|
163
|
+
// const ids = id.filter((id) => typeof id === 'number')
|
|
164
|
+
// if (ids.length < id.length) {
|
|
165
|
+
// throw new Error(
|
|
166
|
+
// 'Seems that aliases are part of ids in qeury not supported yet...',
|
|
167
|
+
// )
|
|
168
|
+
// }
|
|
169
|
+
// TODO ADD MULTI ALIAS
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
target.ids = new Uint32Array(id);
|
|
172
|
+
for (const id of target.ids) {
|
|
173
|
+
isValidId(id);
|
|
174
|
+
}
|
|
175
|
+
target.ids.sort();
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
isValidId(id);
|
|
179
|
+
target.id = id;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const def = createQueryDef(db, QueryDefType.Root, target);
|
|
184
|
+
super(db, def);
|
|
185
|
+
}
|
|
186
|
+
#getInternal = async (resolve, reject) => {
|
|
187
|
+
if (!this.def.include.stringFields.size && !this.def.references.size) {
|
|
188
|
+
includeFields(this.def, ['*']);
|
|
189
|
+
}
|
|
190
|
+
const buf = registerQuery(this);
|
|
191
|
+
const d = performance.now();
|
|
192
|
+
const res = await this.db.hooks.getQueryBuf(buf);
|
|
193
|
+
if (res instanceof Error) {
|
|
194
|
+
reject(res);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
const result = Buffer.from(res);
|
|
198
|
+
resolve(new BasedQueryResponse(this.id, this.def, result, performance.now() - d));
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
// if !id not initialized yet
|
|
202
|
+
id;
|
|
203
|
+
get() {
|
|
204
|
+
return new GetPromise(this.#getInternal);
|
|
205
|
+
}
|
|
206
|
+
buffer;
|
|
207
|
+
register() {
|
|
208
|
+
return registerQuery(this);
|
|
209
|
+
}
|
|
210
|
+
subscribe(onData, onError) {
|
|
211
|
+
return subscribe(this, onData, onError ??
|
|
212
|
+
((err) => {
|
|
213
|
+
console.error(err);
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
_getSync(dbCtxExternal) {
|
|
217
|
+
if (!this.def.include.stringFields.size && !this.def.references.size) {
|
|
218
|
+
includeFields(this.def, ['*']);
|
|
219
|
+
}
|
|
220
|
+
const buf = registerQuery(this);
|
|
221
|
+
const d = performance.now();
|
|
222
|
+
const res = native.getQueryBuf(buf, dbCtxExternal);
|
|
223
|
+
const result = Buffer.from(res);
|
|
224
|
+
return new BasedQueryResponse(this.id, this.def, result, performance.now() - d);
|
|
225
|
+
}
|
|
226
|
+
toBuffer() {
|
|
227
|
+
if (!this.def.include.stringFields.size && !this.def.references.size) {
|
|
228
|
+
includeFields(this.def, ['*']);
|
|
229
|
+
}
|
|
230
|
+
const b = defToBuffer(this.db, this.def);
|
|
231
|
+
checkTotalBufferSize(b);
|
|
232
|
+
return Buffer.concat(b);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=BasedDbQuery.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import { QueryDef } from './types.js';
|
|
3
|
+
import { Item } from './query.js';
|
|
4
|
+
import { size, time, inspectData } from './display.js';
|
|
5
|
+
export { time, size, inspectData };
|
|
6
|
+
export declare class BasedQueryResponse {
|
|
7
|
+
result: Buffer;
|
|
8
|
+
def: QueryDef;
|
|
9
|
+
execTime: number;
|
|
10
|
+
end: number;
|
|
11
|
+
id: number;
|
|
12
|
+
constructor(id: number, def: QueryDef, result: Buffer, execTime: number, end?: number);
|
|
13
|
+
get size(): number;
|
|
14
|
+
[inspect.custom](depth: number): string;
|
|
15
|
+
debug(): this;
|
|
16
|
+
node(index?: number): any;
|
|
17
|
+
[Symbol.iterator](): Generator<Item, void, unknown>;
|
|
18
|
+
inspect(depth?: number): this;
|
|
19
|
+
forEach(fn: (item: any, key: number) => void): void;
|
|
20
|
+
map(fn: (item: any, key: number) => any): any[];
|
|
21
|
+
get checksum(): number;
|
|
22
|
+
get length(): number;
|
|
23
|
+
toObject(): any;
|
|
24
|
+
toJSON(): string;
|
|
25
|
+
toString(): string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import picocolors from 'picocolors';
|
|
3
|
+
import { debug, resultToObject, readAllFields } from './query.js';
|
|
4
|
+
import { size, time, inspectData } from './display.js';
|
|
5
|
+
export { time, size, inspectData };
|
|
6
|
+
export class BasedQueryResponse {
|
|
7
|
+
result;
|
|
8
|
+
def;
|
|
9
|
+
execTime;
|
|
10
|
+
end;
|
|
11
|
+
id;
|
|
12
|
+
constructor(id, def, result, execTime, end = result.byteLength) {
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.def = def;
|
|
15
|
+
this.result = result;
|
|
16
|
+
this.execTime = execTime;
|
|
17
|
+
this.end = end;
|
|
18
|
+
}
|
|
19
|
+
get size() {
|
|
20
|
+
return this.result.byteLength;
|
|
21
|
+
}
|
|
22
|
+
[inspect.custom](depth) {
|
|
23
|
+
const hasId = 'id' in this.def.target || 'alias' in this.def.target;
|
|
24
|
+
const target = hasId
|
|
25
|
+
? this.def.schema.type +
|
|
26
|
+
':' +
|
|
27
|
+
('alias' in this.def.target
|
|
28
|
+
? inspect(this.def.target.alias)
|
|
29
|
+
: // @ts-ignore
|
|
30
|
+
this.def.target.id)
|
|
31
|
+
: this.def.schema.type;
|
|
32
|
+
let str = '';
|
|
33
|
+
str += '\n execTime: ' + time(this.execTime);
|
|
34
|
+
str += '\n size: ' + size(this.result.byteLength);
|
|
35
|
+
const dataStr = inspectData(this, this.def, 0, true, hasId && depth == 2 ? 5 : depth, hasId);
|
|
36
|
+
str += '\n';
|
|
37
|
+
str += dataStr;
|
|
38
|
+
return `${picocolors.bold(`BasedQueryResponse[${target}]`)} {${str}\n}\n`;
|
|
39
|
+
}
|
|
40
|
+
debug() {
|
|
41
|
+
debug(this.result, 0, this.end);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
node(index = 0) {
|
|
45
|
+
let i = 0;
|
|
46
|
+
if ('id' in this.def.target || 'alias' in this.def.target) {
|
|
47
|
+
return this.toObject();
|
|
48
|
+
}
|
|
49
|
+
if (index < 0) {
|
|
50
|
+
index = this.length + index;
|
|
51
|
+
}
|
|
52
|
+
for (const x of this) {
|
|
53
|
+
if (i === index) {
|
|
54
|
+
return x;
|
|
55
|
+
}
|
|
56
|
+
i++;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
*[Symbol.iterator]() {
|
|
61
|
+
let i = 5;
|
|
62
|
+
const result = this.result;
|
|
63
|
+
while (i < result.byteLength - 4) {
|
|
64
|
+
let id = result.readUInt32LE(i);
|
|
65
|
+
i += 4;
|
|
66
|
+
const item = {
|
|
67
|
+
id,
|
|
68
|
+
};
|
|
69
|
+
if (this.def.search) {
|
|
70
|
+
item.$searchScore = result[i];
|
|
71
|
+
i += 1;
|
|
72
|
+
}
|
|
73
|
+
const l = readAllFields(this.def, result, i, result.byteLength - 4, item, id);
|
|
74
|
+
i += l;
|
|
75
|
+
yield item;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
inspect(depth = 2) {
|
|
79
|
+
console.log(this[inspect.custom](depth));
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
forEach(fn) {
|
|
83
|
+
let i = 0;
|
|
84
|
+
for (const item of this) {
|
|
85
|
+
fn(item, ++i);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
map(fn) {
|
|
89
|
+
const arr = new Array(this.length);
|
|
90
|
+
let i = 0;
|
|
91
|
+
for (const item of this) {
|
|
92
|
+
arr[i++] = fn(item, i);
|
|
93
|
+
}
|
|
94
|
+
return arr;
|
|
95
|
+
}
|
|
96
|
+
get checksum() {
|
|
97
|
+
return this.result.readUint32LE(this.result.byteLength - 4);
|
|
98
|
+
}
|
|
99
|
+
get length() {
|
|
100
|
+
return this.result.readUint32LE(0);
|
|
101
|
+
}
|
|
102
|
+
toObject() {
|
|
103
|
+
return resultToObject(this.def, this.result, this.end - 4, 0);
|
|
104
|
+
}
|
|
105
|
+
toJSON() {
|
|
106
|
+
// TODO: optimize
|
|
107
|
+
return JSON.stringify(this.toObject());
|
|
108
|
+
}
|
|
109
|
+
toString() {
|
|
110
|
+
return this.toJSON();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=BasedIterable.js.map
|