@based/db 0.0.70 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +105 -77
- package/dist/lib/darwin_aarch64/include/libdeflate.h +23 -0
- package/dist/lib/darwin_aarch64/include/selva/db.h +0 -41
- package/dist/lib/darwin_aarch64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/darwin_aarch64/include/selva/fields.h +52 -37
- package/dist/lib/darwin_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/darwin_aarch64/include/selva/hll.h +1 -1
- package/dist/lib/darwin_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_string.h +8 -5
- package/dist/lib/darwin_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +18 -4
- package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
- package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/lib/linux_aarch64/include/libdeflate.h +23 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +0 -41
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/linux_aarch64/include/selva/fields.h +52 -37
- package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_aarch64/include/selva/hll.h +1 -1
- package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +8 -5
- package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +18 -4
- package/dist/lib/linux_aarch64/libdeflate.so +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/libdeflate.h +23 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +0 -41
- package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +6 -2
- package/dist/lib/linux_x86_64/include/selva/fields.h +52 -37
- package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_x86_64/include/selva/hll.h +1 -1
- package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +8 -5
- package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +18 -4
- package/dist/lib/linux_x86_64/libdeflate.so +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/index.d.ts +16 -21
- package/dist/src/client/index.js +48 -59
- package/dist/src/client/modify/Ctx.d.ts +38 -0
- package/dist/src/client/modify/Ctx.js +30 -0
- package/dist/src/client/modify/Tmp.d.ts +19 -0
- package/dist/src/client/modify/Tmp.js +67 -0
- package/dist/src/client/modify/create/index.d.ts +6 -0
- package/dist/src/client/modify/create/index.js +191 -0
- package/dist/src/client/modify/create/mark.d.ts +7 -0
- package/dist/src/client/modify/create/mark.js +42 -0
- package/dist/src/client/modify/cursor.d.ts +10 -0
- package/dist/src/client/modify/cursor.js +48 -0
- package/dist/src/client/modify/delete/index.d.ts +2 -0
- package/dist/src/client/modify/delete/index.js +39 -0
- package/dist/src/client/modify/drain.d.ts +7 -0
- package/dist/src/client/modify/drain.js +77 -0
- package/dist/src/client/modify/edges/binary.d.ts +3 -0
- package/dist/src/client/modify/edges/binary.js +28 -0
- package/dist/src/client/modify/edges/cardinality.d.ts +3 -0
- package/dist/src/client/modify/edges/cardinality.js +15 -0
- package/dist/src/client/modify/edges/header.d.ts +5 -0
- package/dist/src/client/modify/edges/header.js +21 -0
- package/dist/src/client/modify/edges/index.d.ts +3 -0
- package/dist/src/client/modify/edges/index.js +128 -0
- package/dist/src/client/modify/edges/reference.d.ts +3 -0
- package/dist/src/client/modify/edges/reference.js +31 -0
- package/dist/src/client/modify/edges/references.d.ts +3 -0
- package/dist/src/client/modify/edges/references.js +38 -0
- package/dist/src/client/modify/edges/separate.d.ts +3 -0
- package/dist/src/client/modify/edges/separate.js +24 -0
- package/dist/src/client/modify/edges/string.d.ts +3 -0
- package/dist/src/client/modify/edges/string.js +30 -0
- package/dist/src/client/modify/error.d.ts +7 -0
- package/dist/src/client/modify/error.js +68 -0
- package/dist/src/client/modify/expire/index.d.ts +2 -0
- package/dist/src/client/modify/expire/index.js +31 -0
- package/dist/src/client/modify/props/alias.d.ts +3 -0
- package/dist/src/client/modify/props/alias.js +26 -0
- package/dist/src/client/modify/props/binary.d.ts +5 -0
- package/dist/src/client/modify/props/binary.js +52 -0
- package/dist/src/client/modify/props/cardinality.d.ts +4 -0
- package/dist/src/client/modify/props/cardinality.js +46 -0
- package/dist/src/client/modify/props/delete.d.ts +3 -0
- package/dist/src/client/modify/props/delete.js +13 -0
- package/dist/src/client/modify/props/fixed.d.ts +4 -0
- package/dist/src/client/modify/props/fixed.js +105 -0
- package/dist/src/client/modify/props/increment.d.ts +3 -0
- package/dist/src/client/modify/props/increment.js +28 -0
- package/dist/src/client/modify/props/json.d.ts +3 -0
- package/dist/src/client/modify/props/json.js +5 -0
- package/dist/src/client/modify/props/main.d.ts +4 -0
- package/dist/src/client/modify/props/main.js +22 -0
- package/dist/src/client/modify/props/object.d.ts +3 -0
- package/dist/src/client/modify/props/object.js +37 -0
- package/dist/src/client/modify/props/reference.d.ts +6 -0
- package/dist/src/client/modify/props/reference.js +92 -0
- package/dist/src/client/modify/props/references.d.ts +3 -0
- package/dist/src/client/modify/props/references.js +231 -0
- package/dist/src/client/modify/props/separate.d.ts +3 -0
- package/dist/src/client/modify/props/separate.js +43 -0
- package/dist/src/client/modify/props/string.d.ts +5 -0
- package/dist/src/client/modify/props/string.js +51 -0
- package/dist/src/client/modify/props/text.d.ts +3 -0
- package/dist/src/client/modify/props/text.js +35 -0
- package/dist/src/client/modify/props/vector.d.ts +3 -0
- package/dist/src/client/modify/props/vector.js +30 -0
- package/dist/src/client/modify/resize.d.ts +3 -0
- package/dist/src/client/modify/resize.js +20 -0
- package/dist/src/client/modify/types.d.ts +3 -4
- package/dist/src/client/modify/types.js +2 -1
- package/dist/src/client/modify/uint.d.ts +7 -0
- package/dist/src/client/modify/uint.js +27 -0
- package/dist/src/client/modify/update/index.d.ts +3 -0
- package/dist/src/client/modify/update/index.js +75 -0
- package/dist/src/client/modify/upsert/index.d.ts +3 -0
- package/dist/src/client/modify/{upsert.js → upsert/index.js} +4 -4
- package/dist/src/client/modify/validate.d.ts +6 -0
- package/dist/src/client/modify/validate.js +24 -0
- package/dist/src/client/query/BasedDbQuery.d.ts +18 -15
- package/dist/src/client/query/BasedDbQuery.js +93 -96
- package/dist/src/client/query/{BasedIterable.d.ts → BasedQueryResponse.d.ts} +5 -4
- package/dist/src/client/query/{BasedIterable.js → BasedQueryResponse.js} +15 -10
- package/dist/src/client/query/aggregates/aggregation.d.ts +5 -3
- package/dist/src/client/query/aggregates/aggregation.js +105 -48
- package/dist/src/client/query/aggregates/types.d.ts +34 -12
- package/dist/src/client/query/aggregates/types.js +30 -12
- package/dist/src/client/query/debug.js +1 -1
- package/dist/src/client/query/display.d.ts +1 -1
- package/dist/src/client/query/display.js +21 -4
- package/dist/src/client/query/filter/FilterBranch.js +2 -2
- package/dist/src/client/query/filter/convertFilter.d.ts +3 -2
- package/dist/src/client/query/filter/convertFilter.js +13 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +16 -30
- package/dist/src/client/query/filter/createReferenceFilter.js +6 -20
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +15 -32
- package/dist/src/client/query/filter/parseFilterValue.js +3 -11
- package/dist/src/client/query/filter/primitiveFilter.js +1 -1
- package/dist/src/client/query/filter/toBuffer.js +9 -15
- package/dist/src/client/query/filter/types.d.ts +6 -6
- package/dist/src/client/query/filter/types.js +8 -8
- package/dist/src/client/query/include/include.d.ts +3 -0
- package/dist/src/client/query/include/include.js +58 -0
- package/dist/src/client/query/include/props.d.ts +7 -7
- package/dist/src/client/query/include/props.js +26 -21
- package/dist/src/client/query/include/toByteCode.js +188 -0
- package/dist/src/client/query/include/utils.d.ts +3 -1
- package/dist/src/client/query/include/utils.js +13 -0
- package/dist/src/client/query/include/walk.d.ts +2 -2
- package/dist/src/client/query/include/walk.js +38 -23
- package/dist/src/client/query/query.d.ts +2 -3
- package/dist/src/client/query/query.js +2 -3
- package/dist/src/client/query/queryDef.d.ts +4 -2
- package/dist/src/client/query/queryDef.js +3 -5
- package/dist/src/client/query/queryDefToReadSchema.d.ts +3 -0
- package/dist/src/client/query/queryDefToReadSchema.js +126 -0
- package/dist/src/client/query/registerQuery.js +15 -4
- package/dist/src/client/query/search/index.d.ts +2 -1
- package/dist/src/client/query/search/index.js +9 -2
- package/dist/src/client/query/sort.js +3 -0
- package/dist/src/client/query/subscription/index.d.ts +1 -1
- package/dist/src/client/query/subscription/index.js +2 -2
- package/dist/src/client/query/subscription/types.d.ts +1 -1
- package/dist/src/client/query/thresholds.d.ts +1 -1
- package/dist/src/client/query/thresholds.js +1 -1
- package/dist/src/client/query/toByteCode/{toBuffer.js → toByteCode.js} +8 -8
- package/dist/src/client/query/types.d.ts +40 -25
- package/dist/src/client/query/types.js +2 -6
- package/dist/src/client/query/validation.d.ts +6 -0
- package/dist/src/client/query/validation.js +32 -8
- package/dist/src/client/setLocalClientSchema.js +6 -10
- package/dist/src/client/string.d.ts +3 -7
- package/dist/src/client/string.js +18 -47
- package/dist/src/hooks.d.ts +2 -3
- package/dist/src/hooks.js +14 -9
- package/dist/src/index.d.ts +3 -5
- package/dist/src/index.js +4 -6
- package/dist/src/native.d.ts +3 -2
- package/dist/src/native.js +9 -8
- package/dist/src/server/IoWorker.js +2 -3
- package/dist/src/server/QueryWorker.js +1 -1
- package/dist/src/server/blocks.js +5 -4
- package/dist/src/server/dbHash.js +1 -1
- package/dist/src/server/index.d.ts +4 -6
- package/dist/src/server/index.js +63 -96
- package/dist/src/server/migrate/index.d.ts +2 -4
- package/dist/src/server/migrate/index.js +31 -16
- package/dist/src/server/migrate/worker.js +2 -27
- package/dist/src/server/save.js +10 -8
- package/dist/src/server/schema.js +17 -25
- package/dist/src/server/start.d.ts +1 -0
- package/dist/src/server/start.js +18 -10
- package/dist/src/server/tree.d.ts +20 -0
- package/dist/src/server/tree.js +17 -2
- package/dist/src/server/workers/DbWorker.d.ts +1 -0
- package/dist/src/server/workers/DbWorker.js +8 -1
- package/dist/src/server/workers/io_worker.js +1 -1
- package/dist/src/server/workers/worker.js +9 -4
- package/dist/src/table.d.ts +4 -0
- package/dist/src/table.js +97 -0
- package/dist/src/types.d.ts +1 -1
- package/package.json +18 -17
- package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +0 -29
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -29
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -29
- package/dist/src/client/flushModify.d.ts +0 -36
- package/dist/src/client/flushModify.js +0 -197
- package/dist/src/client/modify/ModifyRes.d.ts +0 -23
- package/dist/src/client/modify/ModifyRes.js +0 -101
- package/dist/src/client/modify/alias.d.ts +0 -4
- package/dist/src/client/modify/alias.js +0 -57
- package/dist/src/client/modify/binary.d.ts +0 -6
- package/dist/src/client/modify/binary.js +0 -80
- package/dist/src/client/modify/cardinality.d.ts +0 -6
- package/dist/src/client/modify/cardinality.js +0 -63
- package/dist/src/client/modify/create.d.ts +0 -5
- package/dist/src/client/modify/create.js +0 -228
- package/dist/src/client/modify/delete.d.ts +0 -4
- package/dist/src/client/modify/delete.js +0 -47
- package/dist/src/client/modify/expire.d.ts +0 -3
- package/dist/src/client/modify/expire.js +0 -25
- package/dist/src/client/modify/fixed.d.ts +0 -5
- package/dist/src/client/modify/fixed.js +0 -235
- package/dist/src/client/modify/index.d.ts +0 -4
- package/dist/src/client/modify/index.js +0 -4
- package/dist/src/client/modify/json.d.ts +0 -4
- package/dist/src/client/modify/json.js +0 -26
- package/dist/src/client/modify/modify.d.ts +0 -5
- package/dist/src/client/modify/modify.js +0 -134
- package/dist/src/client/modify/references/appendEdgeRefs.d.ts +0 -4
- package/dist/src/client/modify/references/appendEdgeRefs.js +0 -33
- package/dist/src/client/modify/references/edge.d.ts +0 -5
- package/dist/src/client/modify/references/edge.js +0 -322
- package/dist/src/client/modify/references/getEdgeSize.d.ts +0 -3
- package/dist/src/client/modify/references/getEdgeSize.js +0 -27
- package/dist/src/client/modify/references/reference.d.ts +0 -11
- package/dist/src/client/modify/references/reference.js +0 -112
- package/dist/src/client/modify/references/references.d.ts +0 -16
- package/dist/src/client/modify/references/references.js +0 -308
- package/dist/src/client/modify/setCursor.d.ts +0 -5
- package/dist/src/client/modify/setCursor.js +0 -33
- package/dist/src/client/modify/string.d.ts +0 -5
- package/dist/src/client/modify/string.js +0 -71
- package/dist/src/client/modify/text.d.ts +0 -8
- package/dist/src/client/modify/text.js +0 -69
- package/dist/src/client/modify/update.d.ts +0 -6
- package/dist/src/client/modify/update.js +0 -90
- package/dist/src/client/modify/upsert.d.ts +0 -3
- package/dist/src/client/modify/vector.d.ts +0 -4
- package/dist/src/client/modify/vector.js +0 -53
- package/dist/src/client/query/include/toBuffer.js +0 -123
- package/dist/src/client/query/read/read.d.ts +0 -9
- package/dist/src/client/query/read/read.js +0 -483
- /package/dist/src/client/query/include/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
- /package/dist/src/client/query/toByteCode/{toBuffer.d.ts → toByteCode.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/db",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"license": "MIT",
|
|
3
|
+
"version": "0.1.0",
|
|
5
4
|
"type": "module",
|
|
6
5
|
"main": "./dist/src/index.js",
|
|
7
6
|
"scripts": {
|
|
8
7
|
"build": "make -C clibs && npm run build-zig && tsc",
|
|
9
8
|
"build-ts": "tsc",
|
|
10
9
|
"build-zig": "npx tsx scripts/zig_cross_compile.ts",
|
|
11
|
-
"build-linux_aarch64": "(cd clibs && podman run --rm -v \"$PWD/../../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64)",
|
|
12
|
-
"build-release-debug": "(cd clibs && ./build-release.sh) && npm run build-zig -- release debug && tsc",
|
|
13
|
-
"build-release": "(cd clibs && ./build-release.sh) && npm run build-zig -- release && tsc",
|
|
10
|
+
"build-linux_aarch64": "(cd clibs && podman run --rm -v \"$PWD/../../..:/usr/src/based-db\" based-db-clibs-build-linux_aarch64) && npm run build-zig linux-aarch64 && tsc",
|
|
11
|
+
"build-release-debug": "rm -rf ./dist .zig-cache .zig-out ./tmp && (cd clibs && ./build-release.sh) && npm run build-zig -- release debug && tsc",
|
|
12
|
+
"build-release": "rm -rf ./dist .zig-cache .zig-out ./tmp && (cd clibs && ./build-release.sh) && npm run build-zig -- release && tsc",
|
|
14
13
|
"watch": "npx tsc --watch",
|
|
15
14
|
"clean-selva": "make -C clibs clean",
|
|
16
|
-
"clean": "
|
|
15
|
+
"clean": "rm -rf ./dist ./node_modules .zig-cache .zig-out ./tmp && npm run clean-selva",
|
|
17
16
|
"playground-nodebug": "npm run build && node ./dist/test/shared/playground.js",
|
|
18
17
|
"playground": "npm run build && LOCPATH=../locale/locale-x86_64-gnu/locale ./scripts/lldb-node ./dist/test/shared/playground.js",
|
|
19
18
|
"playground-fast": "node ./dist/test/shared/playground.js",
|
|
@@ -27,7 +26,9 @@
|
|
|
27
26
|
"test-zig": "npm run build-zig && tsc && npm run test-fast",
|
|
28
27
|
"test-zig-debug": "npm run build-zig -- debug && tsc && LOCPATH=../locale/locale-x86_64-gnu/locale ./scripts/lldb-node ./scripts/test.js",
|
|
29
28
|
"test-ts": "tsc && node ./scripts/test.js",
|
|
30
|
-
"
|
|
29
|
+
"test-ts-watch": "tsc --watch & node --watch ./scripts/test.js",
|
|
30
|
+
"perf": "npm run build && node benchmarks/references.js && node benchmarks/transfermarkt/transfermarkt-based.js",
|
|
31
|
+
"repl": "LOCPATH=../locale/locale-x86_64-gnu/locale node --experimental-strip-types ./scripts/repl.ts"
|
|
31
32
|
},
|
|
32
33
|
"sideEffects": false,
|
|
33
34
|
"files": [
|
|
@@ -39,24 +40,24 @@
|
|
|
39
40
|
"basedDbNative.cjs"
|
|
40
41
|
],
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@based/
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
43
|
+
"@based/hash": "1.0.0",
|
|
44
|
+
"@based/schema": "^5.0.0",
|
|
45
|
+
"@based/utils": "^1.0.0",
|
|
46
|
+
"@based/protocol": "0.0.2",
|
|
47
|
+
"@std/semver": "npm:@jsr/std__semver@^1.0.5",
|
|
45
48
|
"exit-hook": "^4.0.0",
|
|
46
|
-
"picocolors": "^1.1.0"
|
|
47
|
-
"@based/crc32c": "^1.0.0"
|
|
49
|
+
"picocolors": "^1.1.0"
|
|
48
50
|
},
|
|
49
51
|
"optionalDependencies": {
|
|
50
52
|
"@based/locale-x86-64-gnu": "*"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
|
-
"jsondiffpatch": "^0.7.3",
|
|
54
|
-
"@based/crc32c": "^1.0.0",
|
|
55
55
|
"@types/node": "^22.5.3",
|
|
56
|
+
"async-sema": "3.1.1",
|
|
56
57
|
"axios": "^1.7.9",
|
|
57
|
-
"
|
|
58
|
+
"fs-extra": "^11.1.1",
|
|
59
|
+
"jsondiffpatch": "^0.7.3",
|
|
58
60
|
"tar": "^7.4.3",
|
|
59
|
-
"typescript": "^5.6.3"
|
|
60
|
-
"fs-extra": "^11.1.1"
|
|
61
|
+
"typescript": "^5.6.3"
|
|
61
62
|
}
|
|
62
63
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024-2025 SAULX
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "selva/_export.h"
|
|
8
|
-
#include "libdeflate.h"
|
|
9
|
-
|
|
10
|
-
SELVA_EXPORT
|
|
11
|
-
void worker_ctx_init(void);
|
|
12
|
-
|
|
13
|
-
SELVA_EXPORT
|
|
14
|
-
void worker_ctx_deinit(void);
|
|
15
|
-
|
|
16
|
-
SELVA_EXPORT
|
|
17
|
-
enum libdeflate_result worker_ctx_libdeflate_decompress(
|
|
18
|
-
const void *in, size_t in_nbytes,
|
|
19
|
-
void *out, size_t out_nbytes_avail,
|
|
20
|
-
size_t *actual_out_nbytes_ret);
|
|
21
|
-
|
|
22
|
-
SELVA_EXPORT
|
|
23
|
-
enum libdeflate_result worker_ctx_libdeflate_decompress_stream(
|
|
24
|
-
const char *in_buf, size_t in_len,
|
|
25
|
-
libdeflate_decompress_stream_cb_t cb, void *ctx,
|
|
26
|
-
int *result);
|
|
27
|
-
|
|
28
|
-
SELVA_EXPORT
|
|
29
|
-
bool worker_ctx_libdeflate_block_state_growbuf(void);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024-2025 SAULX
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "selva/_export.h"
|
|
8
|
-
#include "libdeflate.h"
|
|
9
|
-
|
|
10
|
-
SELVA_EXPORT
|
|
11
|
-
void worker_ctx_init(void);
|
|
12
|
-
|
|
13
|
-
SELVA_EXPORT
|
|
14
|
-
void worker_ctx_deinit(void);
|
|
15
|
-
|
|
16
|
-
SELVA_EXPORT
|
|
17
|
-
enum libdeflate_result worker_ctx_libdeflate_decompress(
|
|
18
|
-
const void *in, size_t in_nbytes,
|
|
19
|
-
void *out, size_t out_nbytes_avail,
|
|
20
|
-
size_t *actual_out_nbytes_ret);
|
|
21
|
-
|
|
22
|
-
SELVA_EXPORT
|
|
23
|
-
enum libdeflate_result worker_ctx_libdeflate_decompress_stream(
|
|
24
|
-
const char *in_buf, size_t in_len,
|
|
25
|
-
libdeflate_decompress_stream_cb_t cb, void *ctx,
|
|
26
|
-
int *result);
|
|
27
|
-
|
|
28
|
-
SELVA_EXPORT
|
|
29
|
-
bool worker_ctx_libdeflate_block_state_growbuf(void);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024-2025 SAULX
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "selva/_export.h"
|
|
8
|
-
#include "libdeflate.h"
|
|
9
|
-
|
|
10
|
-
SELVA_EXPORT
|
|
11
|
-
void worker_ctx_init(void);
|
|
12
|
-
|
|
13
|
-
SELVA_EXPORT
|
|
14
|
-
void worker_ctx_deinit(void);
|
|
15
|
-
|
|
16
|
-
SELVA_EXPORT
|
|
17
|
-
enum libdeflate_result worker_ctx_libdeflate_decompress(
|
|
18
|
-
const void *in, size_t in_nbytes,
|
|
19
|
-
void *out, size_t out_nbytes_avail,
|
|
20
|
-
size_t *actual_out_nbytes_ret);
|
|
21
|
-
|
|
22
|
-
SELVA_EXPORT
|
|
23
|
-
enum libdeflate_result worker_ctx_libdeflate_decompress_stream(
|
|
24
|
-
const char *in_buf, size_t in_len,
|
|
25
|
-
libdeflate_decompress_stream_cb_t cb, void *ctx,
|
|
26
|
-
int *result);
|
|
27
|
-
|
|
28
|
-
SELVA_EXPORT
|
|
29
|
-
bool worker_ctx_libdeflate_block_state_growbuf(void);
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { PropDef, SchemaTypeDef } from '@based/schema/def';
|
|
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
|
-
hasSortField: number;
|
|
9
|
-
hasSortText: number;
|
|
10
|
-
hasDefaults: number;
|
|
11
|
-
ctx: {
|
|
12
|
-
queue?: Map<(payload: any) => void, ModifyState>;
|
|
13
|
-
offsets?: Record<number, number>;
|
|
14
|
-
};
|
|
15
|
-
payload: Uint8Array;
|
|
16
|
-
max: number;
|
|
17
|
-
buf: Uint8Array;
|
|
18
|
-
field: number;
|
|
19
|
-
prefix0: number;
|
|
20
|
-
prefix1: number;
|
|
21
|
-
lastMain: number;
|
|
22
|
-
mergeMain: (PropDef | any)[] | null;
|
|
23
|
-
mergeMainSize: number;
|
|
24
|
-
db: DbClient;
|
|
25
|
-
dirtyRanges: Set<number>;
|
|
26
|
-
dirtyTypes: Map<number, number>;
|
|
27
|
-
markNodeDirty(schema: SchemaTypeDef, nodeId: number): void;
|
|
28
|
-
markTypeDirty(schema: SchemaTypeDef): void;
|
|
29
|
-
updateMax(): void;
|
|
30
|
-
getData(lastIds: Record<number, number>): Uint8Array<ArrayBufferLike>;
|
|
31
|
-
reset(): void;
|
|
32
|
-
}
|
|
33
|
-
export declare const execCtxQueue: (resCtx: ModifyCtx["ctx"], error?: boolean) => void;
|
|
34
|
-
export declare const flushBuffer: (db: DbClient) => Promise<void>;
|
|
35
|
-
export declare const startDrain: (db: DbClient) => void;
|
|
36
|
-
export declare const makeFlushIsReady: (dbClient: DbClient) => void;
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { writeUint64 } from '@saulx/utils';
|
|
2
|
-
// TODO This definitely shouldn't be copy-pasted here from server/tree.ts
|
|
3
|
-
const makeTreeKeyFromNodeId = (typeId, blockCapacity, nodeId) => {
|
|
4
|
-
const tmp = nodeId - +!(nodeId % blockCapacity);
|
|
5
|
-
return typeId * 4294967296 + ((tmp / blockCapacity) | 0) * blockCapacity + 1;
|
|
6
|
-
};
|
|
7
|
-
export class ModifyCtx {
|
|
8
|
-
constructor(db) {
|
|
9
|
-
this.max = db.maxModifySize;
|
|
10
|
-
this.db = db;
|
|
11
|
-
this.buf = new Uint8Array(db.maxModifySize);
|
|
12
|
-
this.reset();
|
|
13
|
-
}
|
|
14
|
-
// default values
|
|
15
|
-
len = 8;
|
|
16
|
-
id = -1;
|
|
17
|
-
hasSortField = -1;
|
|
18
|
-
hasSortText = -1;
|
|
19
|
-
hasDefaults = -1;
|
|
20
|
-
ctx = {};
|
|
21
|
-
payload;
|
|
22
|
-
max;
|
|
23
|
-
buf;
|
|
24
|
-
field;
|
|
25
|
-
prefix0 = -1;
|
|
26
|
-
prefix1 = -1;
|
|
27
|
-
lastMain = -1;
|
|
28
|
-
mergeMain;
|
|
29
|
-
mergeMainSize;
|
|
30
|
-
db;
|
|
31
|
-
dirtyRanges = new Set();
|
|
32
|
-
dirtyTypes = new Map();
|
|
33
|
-
markNodeDirty(schema, nodeId) {
|
|
34
|
-
const key = makeTreeKeyFromNodeId(schema.id, schema.blockCapacity, nodeId);
|
|
35
|
-
if (this.dirtyRanges.has(key)) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
this.dirtyRanges.add(key);
|
|
39
|
-
this.updateMax();
|
|
40
|
-
}
|
|
41
|
-
markTypeDirty(schema) {
|
|
42
|
-
if (this.dirtyTypes.has(schema.id)) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
this.dirtyTypes.set(schema.id, schema.lastId);
|
|
46
|
-
this.updateMax();
|
|
47
|
-
}
|
|
48
|
-
updateMax() {
|
|
49
|
-
// reserve space in the end of the buf [...data, type (16), lastId (32), typesSize (16), ...ranges (64)[], dataLen (32)]
|
|
50
|
-
this.max =
|
|
51
|
-
this.db.maxModifySize -
|
|
52
|
-
4 -
|
|
53
|
-
2 -
|
|
54
|
-
this.dirtyTypes.size * 10 -
|
|
55
|
-
this.dirtyRanges.size * 8;
|
|
56
|
-
}
|
|
57
|
-
getData(lastIds) {
|
|
58
|
-
const rangesSize = this.dirtyRanges.size;
|
|
59
|
-
const typesSize = this.dirtyTypes.size;
|
|
60
|
-
const data = this.buf.subarray(0, this.len + 4 + 2 + typesSize * 10 + rangesSize * 8);
|
|
61
|
-
let i = this.len;
|
|
62
|
-
data[i] = typesSize;
|
|
63
|
-
data[i + 1] = typesSize >>> 8;
|
|
64
|
-
i += 2;
|
|
65
|
-
for (const [id, startId] of this.dirtyTypes) {
|
|
66
|
-
const lastId = this.db.schemaTypesParsedById[id].lastId;
|
|
67
|
-
lastIds[id] = lastId;
|
|
68
|
-
data[i] = id;
|
|
69
|
-
data[i + 1] = id >>> 8;
|
|
70
|
-
i += 2;
|
|
71
|
-
data[i++] = startId;
|
|
72
|
-
data[i++] = startId >>> 8;
|
|
73
|
-
data[i++] = startId >>> 16;
|
|
74
|
-
data[i++] = startId >>> 24;
|
|
75
|
-
data[i++] = lastId;
|
|
76
|
-
data[i++] = lastId >>> 8;
|
|
77
|
-
data[i++] = lastId >>> 16;
|
|
78
|
-
data[i++] = lastId >>> 24;
|
|
79
|
-
}
|
|
80
|
-
const view = new DataView(data.buffer, data.byteOffset);
|
|
81
|
-
// this is a problem need to remove these dirtyRanges in general...
|
|
82
|
-
for (let key of this.dirtyRanges) {
|
|
83
|
-
if (i < view.byteLength - 8) {
|
|
84
|
-
view.setFloat64(i, key, true);
|
|
85
|
-
i += 8;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
console.warn('Dirty range does not fit - will remove this', this.dirtyRanges.size, i);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const lenMinusSchemaHash = this.len - 8;
|
|
93
|
-
data[i++] = lenMinusSchemaHash;
|
|
94
|
-
data[i++] = lenMinusSchemaHash >>> 8;
|
|
95
|
-
data[i++] = lenMinusSchemaHash >>> 16;
|
|
96
|
-
data[i++] = lenMinusSchemaHash >>> 24;
|
|
97
|
-
return data;
|
|
98
|
-
}
|
|
99
|
-
reset() {
|
|
100
|
-
this.dirtyTypes.clear();
|
|
101
|
-
this.dirtyRanges.clear();
|
|
102
|
-
writeUint64(this.buf, this.db.schema?.hash || 0, 0);
|
|
103
|
-
this.len = 8;
|
|
104
|
-
this.prefix0 = -1;
|
|
105
|
-
this.prefix1 = -1;
|
|
106
|
-
this.lastMain = -1;
|
|
107
|
-
// should these also be reset in setcursor?
|
|
108
|
-
this.hasSortText = -1;
|
|
109
|
-
this.hasSortField = -1;
|
|
110
|
-
this.max = this.db.maxModifySize;
|
|
111
|
-
this.ctx = {};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
export const execCtxQueue = (resCtx, error) => {
|
|
115
|
-
if (resCtx.queue?.size) {
|
|
116
|
-
const queue = resCtx.queue;
|
|
117
|
-
resCtx.queue = null;
|
|
118
|
-
if (error) {
|
|
119
|
-
for (const [resolve] of queue) {
|
|
120
|
-
// should we throw?
|
|
121
|
-
resolve(null);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
for (const [resolve, res] of queue) {
|
|
126
|
-
resolve(res.getId());
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
export const flushBuffer = (db) => {
|
|
132
|
-
const ctx = db.modifyCtx;
|
|
133
|
-
let flushPromise;
|
|
134
|
-
if (ctx.len > 8) {
|
|
135
|
-
// always has schema hash
|
|
136
|
-
const lastIds = {};
|
|
137
|
-
const data = ctx.getData(lastIds);
|
|
138
|
-
const resCtx = ctx.ctx;
|
|
139
|
-
// pass from flushModify
|
|
140
|
-
flushPromise = db.hooks
|
|
141
|
-
.flushModify(data)
|
|
142
|
-
.then(({ offsets, dbWriteTime }) => {
|
|
143
|
-
db.writeTime += dbWriteTime ?? 0;
|
|
144
|
-
if (offsets) {
|
|
145
|
-
resCtx.offsets = offsets;
|
|
146
|
-
for (const typeId in lastIds) {
|
|
147
|
-
if (typeId in offsets) {
|
|
148
|
-
const lastId = lastIds[typeId] + offsets[typeId];
|
|
149
|
-
const def = db.schemaTypesParsedById[typeId];
|
|
150
|
-
const delta = lastId - def.lastId;
|
|
151
|
-
if (delta > 0) {
|
|
152
|
-
def.lastId += delta;
|
|
153
|
-
def.total += delta;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
console.error('Panic: No offset returned in flushModify');
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
execCtxQueue(resCtx);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
console.info('Modify cancelled - schema mismatch');
|
|
164
|
-
execCtxQueue(resCtx, true);
|
|
165
|
-
}
|
|
166
|
-
db.flushReady();
|
|
167
|
-
});
|
|
168
|
-
ctx.reset();
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
db.flushReady();
|
|
172
|
-
}
|
|
173
|
-
db.isDraining = false;
|
|
174
|
-
return flushPromise;
|
|
175
|
-
};
|
|
176
|
-
export const startDrain = (db) => {
|
|
177
|
-
db.isDraining = true;
|
|
178
|
-
if (db.flushTime === 0) {
|
|
179
|
-
process.nextTick(() => {
|
|
180
|
-
void flushBuffer(db);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
setTimeout(() => {
|
|
185
|
-
void flushBuffer(db);
|
|
186
|
-
}, db.flushTime);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
export const makeFlushIsReady = (dbClient) => {
|
|
190
|
-
dbClient.flushIsReady = new Promise((resolve) => {
|
|
191
|
-
dbClient.flushReady = () => {
|
|
192
|
-
resolve();
|
|
193
|
-
makeFlushIsReady(dbClient);
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
|
-
//# sourceMappingURL=flushModify.js.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { PropDef, PropDefEdge, SchemaPropTree } from '@based/schema/def';
|
|
2
|
-
import { DbClient } from '../index.js';
|
|
3
|
-
import { ModifyOpts } from './types.js';
|
|
4
|
-
import { LangCode } from '@based/schema';
|
|
5
|
-
export type ModifyRes = {
|
|
6
|
-
tmpId: number;
|
|
7
|
-
error?: Error;
|
|
8
|
-
} & Promise<number>;
|
|
9
|
-
export declare class ModifyError extends Error {
|
|
10
|
-
constructor(prop: PropDef | PropDefEdge | SchemaPropTree, val: any, msg?: string);
|
|
11
|
-
}
|
|
12
|
-
export declare class ModifyState {
|
|
13
|
-
#private;
|
|
14
|
-
constructor(typeId: number, tmpId: number, db: DbClient, opts: ModifyOpts, update?: boolean);
|
|
15
|
-
update: boolean;
|
|
16
|
-
locale: LangCode;
|
|
17
|
-
tmpId: number;
|
|
18
|
-
error?: ModifyError;
|
|
19
|
-
promises?: Promise<any>[];
|
|
20
|
-
getId(): number;
|
|
21
|
-
then(resolve: any, reject: any): Promise<any>;
|
|
22
|
-
catch(handler: any): this | Promise<unknown>;
|
|
23
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { isPropDef, REVERSE_TYPE_INDEX_MAP, } from '@based/schema/def';
|
|
2
|
-
import { isValidId, langCodesMap } from '@based/schema';
|
|
3
|
-
const MAGIC_KEY = Math.random().toString(36).substring(2);
|
|
4
|
-
const MAGIC_REG = RegExp(`("${MAGIC_KEY}|${MAGIC_KEY}")`, 'g');
|
|
5
|
-
const walk = (val) => {
|
|
6
|
-
if (typeof val === 'object' && val !== null) {
|
|
7
|
-
if (Array.isArray(val)) {
|
|
8
|
-
return val.map(walk);
|
|
9
|
-
}
|
|
10
|
-
const obj = {};
|
|
11
|
-
for (const key in val) {
|
|
12
|
-
obj[MAGIC_KEY + key + MAGIC_KEY] = walk(val[key]);
|
|
13
|
-
}
|
|
14
|
-
return obj;
|
|
15
|
-
}
|
|
16
|
-
return val;
|
|
17
|
-
};
|
|
18
|
-
const parseVal = (val) => {
|
|
19
|
-
if (typeof val === 'object' && val !== null) {
|
|
20
|
-
const str = JSON.stringify(walk(val)).replace(MAGIC_REG, '');
|
|
21
|
-
val = str;
|
|
22
|
-
}
|
|
23
|
-
if (typeof val === 'string' && val.length > 35) {
|
|
24
|
-
return val.slice(0, 35) + `... (${val.length - 35} more characters)`;
|
|
25
|
-
}
|
|
26
|
-
return val;
|
|
27
|
-
};
|
|
28
|
-
const parseErrorMsg = (prop, val, msg) => {
|
|
29
|
-
if (isPropDef(prop)) {
|
|
30
|
-
if (msg) {
|
|
31
|
-
return `Invalid value at '${prop.path.join('.')}'. Expected ${msg} received '${parseVal(val)}'`;
|
|
32
|
-
}
|
|
33
|
-
return `Invalid value at '${prop.path.join('.')}'. Expected ${REVERSE_TYPE_INDEX_MAP[prop.typeIndex]}, received '${parseVal(val)}'`;
|
|
34
|
-
}
|
|
35
|
-
return `Unknown property '${val}'. Expected one of: ${Object.keys(prop).join(', ')}`;
|
|
36
|
-
};
|
|
37
|
-
export class ModifyError extends Error {
|
|
38
|
-
constructor(prop, val, msg) {
|
|
39
|
-
super(parseErrorMsg(prop, val, msg));
|
|
40
|
-
const a = this.stack.split('\n');
|
|
41
|
-
this.stack = a[0] + '\n' + a.slice(6, -1).join('\n');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export class ModifyState {
|
|
45
|
-
constructor(typeId, tmpId, db, opts, update = false) {
|
|
46
|
-
if (!isValidId(tmpId)) {
|
|
47
|
-
throw new Error('Invalid id passed to modify');
|
|
48
|
-
}
|
|
49
|
-
this.tmpId = tmpId;
|
|
50
|
-
this.#typeId = typeId;
|
|
51
|
-
this.#ctx = db.modifyCtx.ctx;
|
|
52
|
-
this.update = update;
|
|
53
|
-
if (opts?.locale) {
|
|
54
|
-
this.locale = langCodesMap.get(opts.locale);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
update;
|
|
58
|
-
locale;
|
|
59
|
-
#ctx;
|
|
60
|
-
#typeId;
|
|
61
|
-
tmpId;
|
|
62
|
-
error;
|
|
63
|
-
promises;
|
|
64
|
-
getId() {
|
|
65
|
-
if (this.update) {
|
|
66
|
-
return this.tmpId;
|
|
67
|
-
}
|
|
68
|
-
if ('offsets' in this.#ctx) {
|
|
69
|
-
const offset = this.#ctx.offsets[this.#typeId] || 0;
|
|
70
|
-
return this.tmpId + offset;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async then(resolve, reject) {
|
|
74
|
-
if (this.promises?.length) {
|
|
75
|
-
await Promise.allSettled(this.promises);
|
|
76
|
-
}
|
|
77
|
-
let promise;
|
|
78
|
-
if (this.error) {
|
|
79
|
-
promise = Promise.reject(new Error(this.error.toString()));
|
|
80
|
-
}
|
|
81
|
-
else if ('offsets' in this.#ctx) {
|
|
82
|
-
promise = Promise.resolve(this.getId());
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
promise = new Promise((resolve) => {
|
|
86
|
-
this.#ctx.queue ??= new Map();
|
|
87
|
-
this.#ctx.queue.set(resolve, this);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return promise.then(resolve, reject);
|
|
91
|
-
}
|
|
92
|
-
catch(handler) {
|
|
93
|
-
if (this.error) {
|
|
94
|
-
return new Promise((resolve) => {
|
|
95
|
-
resolve(handler(new Error(this.error.toString())));
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=ModifyRes.js.map
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ModifyCtx } from '../../index.js';
|
|
2
|
-
import { SchemaTypeDef, PropDef } from '@based/schema/def';
|
|
3
|
-
import { ModifyOp, ModifyErr } from './types.js';
|
|
4
|
-
export declare function writeAlias(value: string | null, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ENCODER } from '../../index.js';
|
|
2
|
-
import { CREATE, UPDATE, RANGE_ERR, DELETE, } from './types.js';
|
|
3
|
-
import { ModifyError } from './ModifyRes.js';
|
|
4
|
-
import { setCursor } from './setCursor.js';
|
|
5
|
-
export function writeAlias(value, ctx, def, t, parentId, modifyOp) {
|
|
6
|
-
if (typeof value === 'string') {
|
|
7
|
-
if (value.length === 0) {
|
|
8
|
-
if (modifyOp === UPDATE) {
|
|
9
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ > ctx.max) {
|
|
10
|
-
return RANGE_ERR;
|
|
11
|
-
}
|
|
12
|
-
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
13
|
-
ctx.buf[ctx.len++] = DELETE;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
if (!t.validation(value, t)) {
|
|
18
|
-
return new ModifyError(t, value);
|
|
19
|
-
}
|
|
20
|
-
const valueBuf = ENCODER.encode(value);
|
|
21
|
-
let size = valueBuf.byteLength;
|
|
22
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 + size > ctx.max) {
|
|
23
|
-
// 5 compression size
|
|
24
|
-
return RANGE_ERR;
|
|
25
|
-
}
|
|
26
|
-
if (modifyOp === CREATE) {
|
|
27
|
-
def.seperateSort.bufferTmp[t.prop] = 2;
|
|
28
|
-
ctx.hasSortField++;
|
|
29
|
-
if (def.hasSeperateDefaults) {
|
|
30
|
-
def.seperateDefaults.bufferTmp[t.prop] = 1;
|
|
31
|
-
ctx.hasDefaults++;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
35
|
-
ctx.buf[ctx.len++] = modifyOp;
|
|
36
|
-
ctx.buf[ctx.len++] = size;
|
|
37
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
38
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
39
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
40
|
-
ctx.buf.set(valueBuf, ctx.len);
|
|
41
|
-
ctx.len += valueBuf.byteLength;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else if (value === null) {
|
|
45
|
-
if (modifyOp === UPDATE) {
|
|
46
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 1 > ctx.max) {
|
|
47
|
-
return RANGE_ERR;
|
|
48
|
-
}
|
|
49
|
-
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
50
|
-
ctx.buf[ctx.len++] = DELETE;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return new ModifyError(t, value);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=alias.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ModifyCtx } from '../../index.js';
|
|
2
|
-
import { PropDef, SchemaTypeDef } from '@based/schema/def';
|
|
3
|
-
import { ModifyOp, ModifyErr } from './types.js';
|
|
4
|
-
export declare function getBuffer(value: any): Uint8Array | undefined;
|
|
5
|
-
export declare function writeBinaryRaw(value: Uint8Array, ctx: ModifyCtx): void;
|
|
6
|
-
export declare function writeBinary(value: any, ctx: ModifyCtx, schema: SchemaTypeDef, t: PropDef, id: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { ENCODER } from '@saulx/utils';
|
|
2
|
-
import { UPDATE, RANGE_ERR, DELETE, CREATE, MOD_OPS_TO_STRING, } from './types.js';
|
|
3
|
-
import { ModifyError } from './ModifyRes.js';
|
|
4
|
-
import { setCursor } from './setCursor.js';
|
|
5
|
-
import native from '../../native.js';
|
|
6
|
-
export function getBuffer(value) {
|
|
7
|
-
if (typeof value === 'object') {
|
|
8
|
-
if (value instanceof Uint8Array) {
|
|
9
|
-
return value;
|
|
10
|
-
}
|
|
11
|
-
if (value.buffer instanceof ArrayBuffer) {
|
|
12
|
-
return new Uint8Array(value.buffer, 0, value.byteLength);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
else if (typeof value === 'string') {
|
|
16
|
-
return ENCODER.encode(value);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export function writeBinaryRaw(value, ctx) {
|
|
20
|
-
let size = value.byteLength + 6;
|
|
21
|
-
let crc = native.crc32(value);
|
|
22
|
-
ctx.buf[ctx.len++] = size;
|
|
23
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
24
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
25
|
-
ctx.buf[ctx.len++] = size >>>= 8;
|
|
26
|
-
ctx.buf[ctx.len++] = 0;
|
|
27
|
-
ctx.buf[ctx.len++] = 0;
|
|
28
|
-
ctx.buf.set(value, ctx.len);
|
|
29
|
-
ctx.len += value.byteLength;
|
|
30
|
-
ctx.buf[ctx.len++] = crc;
|
|
31
|
-
ctx.buf[ctx.len++] = crc >>>= 8;
|
|
32
|
-
ctx.buf[ctx.len++] = crc >>>= 8;
|
|
33
|
-
ctx.buf[ctx.len++] = crc >>>= 8;
|
|
34
|
-
}
|
|
35
|
-
export function writeBinary(value, ctx, schema, t, id, modifyOp) {
|
|
36
|
-
let size;
|
|
37
|
-
if (value === null) {
|
|
38
|
-
size = 0;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
if (t.transform) {
|
|
42
|
-
// validation happens before
|
|
43
|
-
if (!value || !t.validation(value, t)) {
|
|
44
|
-
return new ModifyError(t, value);
|
|
45
|
-
}
|
|
46
|
-
value = getBuffer(t.transform(MOD_OPS_TO_STRING[modifyOp], value));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
value = getBuffer(value);
|
|
50
|
-
if (!value || !t.validation(value, t)) {
|
|
51
|
-
return new ModifyError(t, value);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
size = value.byteLength + 6;
|
|
55
|
-
}
|
|
56
|
-
if (size === 0) {
|
|
57
|
-
if (modifyOp === UPDATE) {
|
|
58
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 1 > ctx.max) {
|
|
59
|
-
return RANGE_ERR;
|
|
60
|
-
}
|
|
61
|
-
setCursor(ctx, schema, t.prop, t.typeIndex, id, modifyOp);
|
|
62
|
-
ctx.buf[ctx.len++] = DELETE;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 + size > ctx.max) {
|
|
67
|
-
return RANGE_ERR;
|
|
68
|
-
}
|
|
69
|
-
if (modifyOp === CREATE) {
|
|
70
|
-
if (schema.hasSeperateDefaults) {
|
|
71
|
-
schema.seperateDefaults.bufferTmp[t.prop] = 1;
|
|
72
|
-
ctx.hasDefaults++;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
setCursor(ctx, schema, t.prop, t.typeIndex, id, modifyOp);
|
|
76
|
-
ctx.buf[ctx.len++] = modifyOp;
|
|
77
|
-
writeBinaryRaw(value, ctx);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=binary.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ModifyCtx } from '../../index.js';
|
|
2
|
-
import { SchemaTypeDef, PropDef, PropDefEdge } from '@based/schema/def';
|
|
3
|
-
import { ModifyOp, ModifyErr } from './types.js';
|
|
4
|
-
import { ModifyError } from './ModifyRes.js';
|
|
5
|
-
export declare function writeHll(value: string | null | Uint8Array | Array<string | Uint8Array>, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
6
|
-
export declare function writeHllBuf(value: (string | Uint8Array)[], ctx: ModifyCtx, t: PropDef | PropDefEdge, len: number): ModifyError;
|