@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,86 @@
|
|
|
1
|
+
import { stringHash } from '@saulx/hash';
|
|
2
|
+
import { DbWorker } from './index.js';
|
|
3
|
+
import native from '../native.js';
|
|
4
|
+
import { rm, mkdir, readFile } from 'node:fs/promises';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { createTree } from './csmt/index.js';
|
|
7
|
+
import { foreachBlock } from './tree.js';
|
|
8
|
+
import { availableParallelism } from 'node:os';
|
|
9
|
+
import './worker.js';
|
|
10
|
+
const SCHEMA_FILE = 'schema.json';
|
|
11
|
+
const WRITELOG_FILE = 'writelog.json';
|
|
12
|
+
export const DEFAULT_BLOCK_CAPACITY = 100_000;
|
|
13
|
+
const makeCsmtKey = (typeId, start) => typeId * 4294967296 + start;
|
|
14
|
+
export async function start(db, opts) {
|
|
15
|
+
const path = db.fileSystemPath;
|
|
16
|
+
const id = stringHash(path) >>> 0;
|
|
17
|
+
const noop = () => { };
|
|
18
|
+
if (opts?.clean) {
|
|
19
|
+
await rm(path, { recursive: true, force: true }).catch(noop);
|
|
20
|
+
}
|
|
21
|
+
await mkdir(path, { recursive: true }).catch(noop);
|
|
22
|
+
// not doing db yet
|
|
23
|
+
// db.modifyBuf = new SharedArrayBuffer(db.maxModifySize)
|
|
24
|
+
db.dbCtxExternal = native.start(id);
|
|
25
|
+
let writelog = null;
|
|
26
|
+
try {
|
|
27
|
+
writelog = JSON.parse((await readFile(join(path, WRITELOG_FILE))).toString());
|
|
28
|
+
// Load the common dump
|
|
29
|
+
native.loadCommon(join(path, writelog.commonDump), db.dbCtxExternal);
|
|
30
|
+
// Load all range dumps
|
|
31
|
+
for (const typeId in writelog.rangeDumps) {
|
|
32
|
+
const dumps = writelog.rangeDumps[typeId];
|
|
33
|
+
for (const dump of dumps) {
|
|
34
|
+
const fname = dump.file;
|
|
35
|
+
const err = native.loadRange(join(path, fname), db.dbCtxExternal);
|
|
36
|
+
if (err) {
|
|
37
|
+
console.log(`Failed to load a range. file: "${fname}": ${err}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const schema = await readFile(join(path, SCHEMA_FILE));
|
|
42
|
+
if (schema) {
|
|
43
|
+
// Prop need to not call setting in selva
|
|
44
|
+
db.putSchema(JSON.parse(schema.toString()), true);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (err) { }
|
|
48
|
+
// The merkle tree should be empty at start.
|
|
49
|
+
if (!db.merkleTree || db.merkleTree.getRoot()) {
|
|
50
|
+
db.merkleTree = createTree(db.createCsmtHashFun);
|
|
51
|
+
}
|
|
52
|
+
for (const key in db.schemaTypesParsed) {
|
|
53
|
+
const def = db.schemaTypesParsed[key];
|
|
54
|
+
const [total, lastId] = native.getTypeInfo(def.id, db.dbCtxExternal);
|
|
55
|
+
def.total = total;
|
|
56
|
+
def.lastId = writelog?.types[def.id].lastId || lastId;
|
|
57
|
+
def.blockCapacity =
|
|
58
|
+
writelog?.types[def.id].blockCapacity || DEFAULT_BLOCK_CAPACITY;
|
|
59
|
+
foreachBlock(db, def, (start, end, hash) => {
|
|
60
|
+
const mtKey = makeCsmtKey(def.id, start);
|
|
61
|
+
const file = writelog.rangeDumps[def.id].find((v) => v.start === start)?.file || '';
|
|
62
|
+
const data = {
|
|
63
|
+
file,
|
|
64
|
+
typeId: def.id,
|
|
65
|
+
start,
|
|
66
|
+
end,
|
|
67
|
+
};
|
|
68
|
+
db.merkleTree.insert(mtKey, hash, data);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (writelog?.hash) {
|
|
72
|
+
const oldHash = Buffer.from(writelog.hash, 'hex');
|
|
73
|
+
const newHash = db.merkleTree.getRoot()?.hash;
|
|
74
|
+
if (!oldHash.equals(newHash)) {
|
|
75
|
+
console.error(`WARN: CSMT hash mismatch: ${writelog.hash} != ${newHash.toString('hex')}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// start workers
|
|
79
|
+
let i = availableParallelism();
|
|
80
|
+
const address = native.intFromExternal(db.dbCtxExternal);
|
|
81
|
+
db.workers = new Array(i);
|
|
82
|
+
while (i--) {
|
|
83
|
+
db.workers[i] = new DbWorker(address, db);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DbServer } from './index.js';
|
|
2
|
+
import { SchemaTypeDef } from './schema/types.js';
|
|
3
|
+
export type CsmtNodeRange = {
|
|
4
|
+
file: string;
|
|
5
|
+
typeId: number;
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const makeCsmtKey: (typeId: number, start: number) => number;
|
|
10
|
+
export declare const destructureCsmtKey: (key: number) => number[];
|
|
11
|
+
export declare const makeCsmtKeyFromNodeId: (typeId: number, blockCapacity: number, nodeId: number) => number;
|
|
12
|
+
export declare function foreachBlock(db: DbServer, def: SchemaTypeDef, cb: (start: number, end: number, hash: Buffer) => void): Promise<void>;
|
|
13
|
+
export declare function foreachDirtyBlock(db: DbServer, cb: (mtKey: number, typeId: number, start: number, end: number) => void): Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import native from '../native.js';
|
|
2
|
+
export const makeCsmtKey = (typeId, start) => typeId * 4294967296 + start;
|
|
3
|
+
export const destructureCsmtKey = (key) => [
|
|
4
|
+
(key / 4294967296) | 0, // typeId
|
|
5
|
+
(key >>> 31) * 2147483648 + (key & 0x7fffffff), // start_node_id
|
|
6
|
+
];
|
|
7
|
+
export const makeCsmtKeyFromNodeId = (typeId, blockCapacity, nodeId) => {
|
|
8
|
+
const tmp = nodeId - +!(nodeId % blockCapacity);
|
|
9
|
+
return typeId * 4294967296 + ((tmp / blockCapacity) | 0) * blockCapacity + 1;
|
|
10
|
+
};
|
|
11
|
+
export async function foreachBlock(db, def, cb) {
|
|
12
|
+
const step = def.blockCapacity;
|
|
13
|
+
for (let start = 1; start <= def.lastId; start += step) {
|
|
14
|
+
const end = start + step - 1;
|
|
15
|
+
const hash = Buffer.allocUnsafe(16);
|
|
16
|
+
native.getNodeRangeHash(def.id, start, end, hash, db.dbCtxExternal);
|
|
17
|
+
cb(start, end, hash);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export async function foreachDirtyBlock(db, cb) {
|
|
21
|
+
const typeIdMap = {};
|
|
22
|
+
for (const typeName in db.schemaTypesParsed) {
|
|
23
|
+
const type = db.schemaTypesParsed[typeName];
|
|
24
|
+
const typeId = type.id;
|
|
25
|
+
typeIdMap[typeId] = type;
|
|
26
|
+
}
|
|
27
|
+
for (const mtKey of db.dirtyRanges) {
|
|
28
|
+
const [typeId, start] = destructureCsmtKey(mtKey);
|
|
29
|
+
const end = start + typeIdMap[typeId].blockCapacity - 1;
|
|
30
|
+
cb(mtKey, typeId, start, end);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isMainThread, receiveMessageOnPort, workerData, } from 'node:worker_threads';
|
|
2
|
+
import native from '../native.js';
|
|
3
|
+
if (isMainThread) {
|
|
4
|
+
console.warn('running query worker.ts in mainthread');
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
let { address, channel } = workerData;
|
|
8
|
+
let dbCtx = native.externalFromInt(address);
|
|
9
|
+
native.workerCtxInit();
|
|
10
|
+
const transferList = new Array(1);
|
|
11
|
+
const handleMsg = (msg) => {
|
|
12
|
+
try {
|
|
13
|
+
if (typeof msg === 'bigint') {
|
|
14
|
+
// it's a ctx address
|
|
15
|
+
address = msg;
|
|
16
|
+
dbCtx = native.externalFromInt(address);
|
|
17
|
+
channel.postMessage(null);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const arrayBuf = native.getQueryBuf(msg, dbCtx).buffer;
|
|
21
|
+
transferList[0] = arrayBuf;
|
|
22
|
+
channel.postMessage(arrayBuf, transferList);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
channel.postMessage(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
channel.on('message', handleMsg);
|
|
30
|
+
const msg = receiveMessageOnPort(channel);
|
|
31
|
+
if (msg) {
|
|
32
|
+
handleMsg(msg.message);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=worker.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@based/db",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "make -C clibs && npm run build-zig && tsc",
|
|
9
|
+
"build-zig": "npx tsx scripts/zig_cross_compile.ts",
|
|
10
|
+
"build-release": "(cd clibs && ./build-release.sh) && npm run build-zig -- release && tsc",
|
|
11
|
+
"watch": "npx tsc --watch",
|
|
12
|
+
"clean-selva": "make -C clibs clean",
|
|
13
|
+
"clean": "rimraf {.turbo,dist,node_modules,.zig-cache,.zig-out,tmp} && npm run clean-selva",
|
|
14
|
+
"playground-nodebug": "npm run build && node ./dist/test/shared/playground.js",
|
|
15
|
+
"playground": "npm run build && LOCPATH=../locale/locale-x86_64-gnu/locale lldb -b -o run --one-line-on-crash bt -o \"script import os; os._exit(0)\" node ./dist/test/shared/playground.js",
|
|
16
|
+
"playground-fast": "node ./dist/test/shared/playground.js",
|
|
17
|
+
"test": "npm run build && LOCPATH=../locale/locale-x86_64-gnu/locale lldb -b -o run --one-line-on-crash bt -o \"script import os; os._exit(0)\" node ./scripts/test.js",
|
|
18
|
+
"test-gdb": "npm run build && LOCPATH=../locale/locale-x86_64-gnu/locale gdb -ex run --args node ./scripts/test.js",
|
|
19
|
+
"test-fast": "LOCPATH=../locale/locale-x86_64-gnu/locale node ./scripts/test.js",
|
|
20
|
+
"test-zig": "npm run build-zig && tsc && npm run test-fast",
|
|
21
|
+
"test-ts": "tsc && node ./scripts/test.js",
|
|
22
|
+
"perf": "npm run build && node benchmarks/references.js && node benchmarks/transfermarkt/transfermarkt-based.js"
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/src",
|
|
27
|
+
"dist/lib",
|
|
28
|
+
"!*.map",
|
|
29
|
+
"README.md",
|
|
30
|
+
"package.json"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@based/schema": "5.0.0-alpha.0",
|
|
34
|
+
"@saulx/hash": "^3.0.0",
|
|
35
|
+
"@saulx/utils": "^4.3.2",
|
|
36
|
+
"picocolors": "^1.1.0"
|
|
37
|
+
},
|
|
38
|
+
"optionalDependencies": {
|
|
39
|
+
"@based/locale-x86-64-gnu": "*"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^22.5.3",
|
|
43
|
+
"axios": "^1.7.9",
|
|
44
|
+
"rimraf": "^3.0.2",
|
|
45
|
+
"tar": "^7.4.3",
|
|
46
|
+
"typescript": "^5.6.3"
|
|
47
|
+
}
|
|
48
|
+
}
|