@based/db 0.0.20 → 0.0.21
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/basedDbNative.cjs +6 -2
- package/dist/lib/darwin_aarch64/include/selva/db.h +3 -3
- package/dist/lib/darwin_aarch64/include/selva/fast_memcmp.h +18 -0
- package/dist/lib/darwin_aarch64/include/selva/fields.h +3 -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.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v21.node +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/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +3 -3
- package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +18 -0
- package/dist/lib/linux_aarch64/include/selva/fields.h +3 -0
- package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v21.node +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/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +3 -3
- package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +18 -0
- package/dist/lib/linux_x86_64/include/selva/fields.h +3 -0
- package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v21.node +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/libselva.so +0 -0
- package/dist/src/client/bitWise.js +0 -1
- package/dist/src/client/crc32.d.ts +1 -1
- package/dist/src/client/modify/alias.js +3 -3
- package/dist/src/client/modify/binary.d.ts +1 -1
- package/dist/src/client/modify/binary.js +7 -6
- package/dist/src/client/modify/cardinality.d.ts +3 -1
- package/dist/src/client/modify/cardinality.js +8 -4
- package/dist/src/client/modify/create.js +41 -5
- package/dist/src/client/modify/delete.js +9 -8
- package/dist/src/client/modify/expire.js +1 -1
- package/dist/src/client/modify/modify.js +3 -3
- package/dist/src/client/modify/references/edge.js +15 -1
- package/dist/src/client/modify/setCursor.js +0 -2
- package/dist/src/client/modify/string.d.ts +1 -1
- package/dist/src/client/modify/string.js +5 -3
- package/dist/src/client/modify/text.d.ts +1 -1
- package/dist/src/client/modify/text.js +52 -9
- package/dist/src/client/modify/types.d.ts +5 -1
- package/dist/src/client/modify/types.js +2 -1
- package/dist/src/client/modify/vector.js +4 -4
- package/dist/src/client/query/filter/convertFilter.js +3 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +1 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +10 -4
- package/dist/src/client/query/filter/parseFilterValue.js +13 -4
- package/dist/src/client/query/filter/primitiveFilter.js +13 -3
- package/dist/src/client/query/filter/toBuffer.js +13 -3
- package/dist/src/client/query/filter/types.d.ts +5 -3
- package/dist/src/client/query/filter/types.js +12 -0
- package/dist/src/client/query/read/read.js +7 -1
- package/dist/src/client/query/search/index.js +25 -19
- package/dist/src/client/query/serialize.d.ts +4 -0
- package/dist/src/client/query/serialize.js +26 -0
- package/dist/src/client/query/sort.d.ts +1 -1
- package/dist/src/client/query/sort.js +5 -5
- package/dist/src/client/query/subscription/run.js +1 -1
- package/dist/src/client/query/types.d.ts +6 -2
- package/dist/src/client/query/validation.js +14 -32
- package/dist/src/client/string.d.ts +2 -2
- package/dist/src/client/string.js +32 -29
- package/dist/src/client/tmpBuffer.d.ts +3 -0
- package/dist/src/client/tmpBuffer.js +20 -0
- package/dist/src/client/xxHash64.d.ts +1 -1
- package/dist/src/client/xxHash64.js +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/native.d.ts +14 -13
- package/dist/src/native.js +41 -25
- package/dist/src/server/csmt/draw-dot.js +2 -1
- package/dist/src/server/csmt/memebership-proof.d.ts +1 -1
- package/dist/src/server/csmt/tree.d.ts +2 -1
- package/dist/src/server/csmt/tree.js +10 -9
- package/dist/src/server/csmt/types.d.ts +4 -3
- package/dist/src/server/index.d.ts +5 -4
- package/dist/src/server/index.js +5 -6
- package/dist/src/server/save.js +4 -3
- package/dist/src/server/start.d.ts +1 -0
- package/dist/src/server/start.js +43 -16
- package/dist/src/server/tree.d.ts +1 -1
- package/dist/src/server/tree.js +17 -2
- package/dist/src/server/worker.js +2 -1
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.js +84 -0
- package/package.json +3 -3
- 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/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_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/basedDbNative.cjs
CHANGED
|
@@ -4,7 +4,7 @@ const process = require('process')
|
|
|
4
4
|
|
|
5
5
|
const platform = os.platform()
|
|
6
6
|
const arch = os.arch()
|
|
7
|
-
const
|
|
7
|
+
const nodeMajorVersion = parseInt(process.version.match(/^v?(\d+)/)[1], 10)
|
|
8
8
|
|
|
9
9
|
const baseDir = path.join(__dirname, 'dist/lib')
|
|
10
10
|
let platformDir
|
|
@@ -20,7 +20,11 @@ switch (platform) {
|
|
|
20
20
|
throw new Error(`Unsupported platform: ${platform}`)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const libPath = path.join(
|
|
23
|
+
const libPath = path.join(
|
|
24
|
+
baseDir,
|
|
25
|
+
platformDir,
|
|
26
|
+
`libnode-v${nodeMajorVersion}.node`,
|
|
27
|
+
)
|
|
24
28
|
const addon = require(libPath)
|
|
25
29
|
|
|
26
30
|
module.exports = addon
|
|
@@ -31,7 +31,7 @@ void selva_db_destroy(struct SelvaDb *db) __attribute__((nonnull));
|
|
|
31
31
|
* @param type must not exist before.
|
|
32
32
|
*/
|
|
33
33
|
SELVA_EXPORT
|
|
34
|
-
int
|
|
34
|
+
int selva_db_create_type(struct SelvaDb *db, node_type_t type, const char *schema_buf, size_t schema_len) __attribute__((nonnull));
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Save the common/shared data of the database.
|
|
@@ -54,10 +54,10 @@ int selva_dump_save_range(struct SelvaDb *db, struct SelvaTypeEntry *te, const c
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
SELVA_EXPORT
|
|
57
|
-
int selva_dump_load_common(struct SelvaDb *db, const char *filename) __attribute__((nonnull));
|
|
57
|
+
int selva_dump_load_common(struct SelvaDb *db, const char *filename, char *errlog_buf, size_t errlog_size) __attribute__((nonnull));
|
|
58
58
|
|
|
59
59
|
SELVA_EXPORT
|
|
60
|
-
int selva_dump_load_range(struct SelvaDb *db, const char *filename) __attribute__((nonnull));
|
|
60
|
+
int selva_dump_load_range(struct SelvaDb *db, const char *filename, char *errlog_buf, size_t errlog_size) __attribute__((nonnull));
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Find a type by type id.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include "selva/_export.h"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Fast buffer equals comparison.
|
|
12
|
+
* @param a is an array of length len.
|
|
13
|
+
* @param b is an array of length len.
|
|
14
|
+
* @param len length of a and b in bytes, must be greater than 0.
|
|
15
|
+
* @returns true if a and b contains the same byte sequence; Otherwise false.
|
|
16
|
+
*/
|
|
17
|
+
SELVA_EXPORT
|
|
18
|
+
bool fast_memcmp(const void *restrict a, const void *restrict b, size_t len);
|
|
@@ -283,6 +283,9 @@ struct SelvaNode *selva_fields_resolve_weak_reference(
|
|
|
283
283
|
const struct SelvaFieldSchema *fs,
|
|
284
284
|
const struct SelvaNodeWeakReference *weak_ref);
|
|
285
285
|
|
|
286
|
+
SELVA_EXPORT
|
|
287
|
+
struct selva_string *selva_fields_get_selva_string3(struct SelvaNodeReference *ref, const struct SelvaFieldSchema *fs);
|
|
288
|
+
|
|
286
289
|
SELVA_EXPORT
|
|
287
290
|
struct selva_string *selva_fields_get_selva_string2(struct SelvaFields *fields, const struct SelvaFieldSchema *fs);
|
|
288
291
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -31,7 +31,7 @@ void selva_db_destroy(struct SelvaDb *db) __attribute__((nonnull));
|
|
|
31
31
|
* @param type must not exist before.
|
|
32
32
|
*/
|
|
33
33
|
SELVA_EXPORT
|
|
34
|
-
int
|
|
34
|
+
int selva_db_create_type(struct SelvaDb *db, node_type_t type, const char *schema_buf, size_t schema_len) __attribute__((nonnull));
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Save the common/shared data of the database.
|
|
@@ -54,10 +54,10 @@ int selva_dump_save_range(struct SelvaDb *db, struct SelvaTypeEntry *te, const c
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
SELVA_EXPORT
|
|
57
|
-
int selva_dump_load_common(struct SelvaDb *db, const char *filename) __attribute__((nonnull));
|
|
57
|
+
int selva_dump_load_common(struct SelvaDb *db, const char *filename, char *errlog_buf, size_t errlog_size) __attribute__((nonnull));
|
|
58
58
|
|
|
59
59
|
SELVA_EXPORT
|
|
60
|
-
int selva_dump_load_range(struct SelvaDb *db, const char *filename) __attribute__((nonnull));
|
|
60
|
+
int selva_dump_load_range(struct SelvaDb *db, const char *filename, char *errlog_buf, size_t errlog_size) __attribute__((nonnull));
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Find a type by type id.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include "selva/_export.h"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Fast buffer equals comparison.
|
|
12
|
+
* @param a is an array of length len.
|
|
13
|
+
* @param b is an array of length len.
|
|
14
|
+
* @param len length of a and b in bytes, must be greater than 0.
|
|
15
|
+
* @returns true if a and b contains the same byte sequence; Otherwise false.
|
|
16
|
+
*/
|
|
17
|
+
SELVA_EXPORT
|
|
18
|
+
bool fast_memcmp(const void *restrict a, const void *restrict b, size_t len);
|
|
@@ -283,6 +283,9 @@ struct SelvaNode *selva_fields_resolve_weak_reference(
|
|
|
283
283
|
const struct SelvaFieldSchema *fs,
|
|
284
284
|
const struct SelvaNodeWeakReference *weak_ref);
|
|
285
285
|
|
|
286
|
+
SELVA_EXPORT
|
|
287
|
+
struct selva_string *selva_fields_get_selva_string3(struct SelvaNodeReference *ref, const struct SelvaFieldSchema *fs);
|
|
288
|
+
|
|
286
289
|
SELVA_EXPORT
|
|
287
290
|
struct selva_string *selva_fields_get_selva_string2(struct SelvaFields *fields, const struct SelvaFieldSchema *fs);
|
|
288
291
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -31,7 +31,7 @@ void selva_db_destroy(struct SelvaDb *db) __attribute__((nonnull));
|
|
|
31
31
|
* @param type must not exist before.
|
|
32
32
|
*/
|
|
33
33
|
SELVA_EXPORT
|
|
34
|
-
int
|
|
34
|
+
int selva_db_create_type(struct SelvaDb *db, node_type_t type, const char *schema_buf, size_t schema_len) __attribute__((nonnull));
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Save the common/shared data of the database.
|
|
@@ -54,10 +54,10 @@ int selva_dump_save_range(struct SelvaDb *db, struct SelvaTypeEntry *te, const c
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
SELVA_EXPORT
|
|
57
|
-
int selva_dump_load_common(struct SelvaDb *db, const char *filename) __attribute__((nonnull));
|
|
57
|
+
int selva_dump_load_common(struct SelvaDb *db, const char *filename, char *errlog_buf, size_t errlog_size) __attribute__((nonnull));
|
|
58
58
|
|
|
59
59
|
SELVA_EXPORT
|
|
60
|
-
int selva_dump_load_range(struct SelvaDb *db, const char *filename) __attribute__((nonnull));
|
|
60
|
+
int selva_dump_load_range(struct SelvaDb *db, const char *filename, char *errlog_buf, size_t errlog_size) __attribute__((nonnull));
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Find a type by type id.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include "selva/_export.h"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Fast buffer equals comparison.
|
|
12
|
+
* @param a is an array of length len.
|
|
13
|
+
* @param b is an array of length len.
|
|
14
|
+
* @param len length of a and b in bytes, must be greater than 0.
|
|
15
|
+
* @returns true if a and b contains the same byte sequence; Otherwise false.
|
|
16
|
+
*/
|
|
17
|
+
SELVA_EXPORT
|
|
18
|
+
bool fast_memcmp(const void *restrict a, const void *restrict b, size_t len);
|
|
@@ -283,6 +283,9 @@ struct SelvaNode *selva_fields_resolve_weak_reference(
|
|
|
283
283
|
const struct SelvaFieldSchema *fs,
|
|
284
284
|
const struct SelvaNodeWeakReference *weak_ref);
|
|
285
285
|
|
|
286
|
+
SELVA_EXPORT
|
|
287
|
+
struct selva_string *selva_fields_get_selva_string3(struct SelvaNodeReference *ref, const struct SelvaFieldSchema *fs);
|
|
288
|
+
|
|
286
289
|
SELVA_EXPORT
|
|
287
290
|
struct selva_string *selva_fields_get_selva_string2(struct SelvaFields *fields, const struct SelvaFieldSchema *fs);
|
|
288
291
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const crc32: (buf:
|
|
1
|
+
export declare const crc32: (buf: Uint8Array) => any;
|
|
@@ -5,7 +5,7 @@ export function writeAlias(value, ctx, def, t, parentId, modifyOp) {
|
|
|
5
5
|
if (typeof value === 'string') {
|
|
6
6
|
if (value.length === 0) {
|
|
7
7
|
if (modifyOp === UPDATE) {
|
|
8
|
-
if (ctx.len + 11 > ctx.max) {
|
|
8
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ > ctx.max) {
|
|
9
9
|
return RANGE_ERR;
|
|
10
10
|
}
|
|
11
11
|
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
@@ -14,7 +14,7 @@ export function writeAlias(value, ctx, def, t, parentId, modifyOp) {
|
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
16
|
let size = Buffer.byteLength(value, 'utf8');
|
|
17
|
-
if (ctx.len +
|
|
17
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 + size > ctx.max) {
|
|
18
18
|
// 5 compression size
|
|
19
19
|
return RANGE_ERR;
|
|
20
20
|
}
|
|
@@ -33,7 +33,7 @@ export function writeAlias(value, ctx, def, t, parentId, modifyOp) {
|
|
|
33
33
|
}
|
|
34
34
|
else if (value === null) {
|
|
35
35
|
if (modifyOp === UPDATE) {
|
|
36
|
-
if (ctx.len + 11 > ctx.max) {
|
|
36
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 1 > ctx.max) {
|
|
37
37
|
return RANGE_ERR;
|
|
38
38
|
}
|
|
39
39
|
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ModifyCtx } from '../../index.js';
|
|
2
2
|
import { PropDef, SchemaTypeDef } from '@based/schema/def';
|
|
3
3
|
import { ModifyOp, ModifyErr } from './types.js';
|
|
4
|
-
export declare function getBuffer(value: any):
|
|
4
|
+
export declare function getBuffer(value: any): Uint8Array | undefined;
|
|
5
5
|
export declare function writeBinaryRaw(value: Buffer, ctx: ModifyCtx): void;
|
|
6
6
|
export declare function writeBinary(value: any, ctx: ModifyCtx, schema: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { UPDATE, RANGE_ERR, DELETE } from './types.js';
|
|
1
|
+
import { UPDATE, RANGE_ERR, DELETE, } from './types.js';
|
|
2
2
|
import { ModifyError } from './ModifyRes.js';
|
|
3
3
|
import { setCursor } from './setCursor.js';
|
|
4
4
|
import native from '../../native.js';
|
|
5
|
+
const ENCODER = new TextEncoder();
|
|
5
6
|
export function getBuffer(value) {
|
|
6
7
|
if (typeof value === 'object') {
|
|
7
|
-
if (value instanceof
|
|
8
|
+
if (value instanceof Uint8Array) {
|
|
8
9
|
return value;
|
|
9
10
|
}
|
|
10
11
|
if (value.buffer instanceof ArrayBuffer) {
|
|
11
|
-
return
|
|
12
|
+
return new Uint8Array(value.buffer, 0, value.byteLength);
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
else if (typeof value === 'string') {
|
|
15
|
-
return
|
|
16
|
+
return ENCODER.encode(value);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
export function writeBinaryRaw(value, ctx) {
|
|
@@ -45,7 +46,7 @@ export function writeBinary(value, ctx, schema, t, parentId, modifyOp) {
|
|
|
45
46
|
}
|
|
46
47
|
if (size === 0) {
|
|
47
48
|
if (modifyOp === UPDATE) {
|
|
48
|
-
if (ctx.len + 11 > ctx.max) {
|
|
49
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 1 > ctx.max) {
|
|
49
50
|
return RANGE_ERR;
|
|
50
51
|
}
|
|
51
52
|
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
@@ -53,7 +54,7 @@ export function writeBinary(value, ctx, schema, t, parentId, modifyOp) {
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
else {
|
|
56
|
-
if (ctx.len +
|
|
57
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 + size > ctx.max) {
|
|
57
58
|
return RANGE_ERR;
|
|
58
59
|
}
|
|
59
60
|
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ModifyCtx } from '../../index.js';
|
|
2
2
|
import { SchemaTypeDef, PropDef } from '@based/schema/def';
|
|
3
3
|
import { ModifyOp, ModifyErr } from './types.js';
|
|
4
|
-
|
|
4
|
+
import { ModifyError } from './ModifyRes.js';
|
|
5
|
+
export declare function writeHll(value: string | null | Buffer | Uint8Array | Array<string | Buffer | Uint8Array>, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
6
|
+
export declare function writeHllBuf(value: (string | Buffer | Uint8Array)[], ctx: ModifyCtx, t: PropDef, len: number): ModifyError;
|
|
@@ -7,7 +7,7 @@ export function writeHll(value, ctx, def, t, parentId, modifyOp) {
|
|
|
7
7
|
return new ModifyError(t, value);
|
|
8
8
|
}
|
|
9
9
|
if (value === null) {
|
|
10
|
-
// Future hll_reset
|
|
10
|
+
// Future hll_reset function
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
else if (!Array.isArray(value)) {
|
|
@@ -23,18 +23,22 @@ export function writeHll(value, ctx, def, t, parentId, modifyOp) {
|
|
|
23
23
|
function addHll(value, ctx, def, t, parentId, modifyOp) {
|
|
24
24
|
const len = value.length;
|
|
25
25
|
let size = 4 + len * 8;
|
|
26
|
-
if (ctx.len + size + 11 > ctx.max) {
|
|
26
|
+
if (ctx.len + size + 11 /* SIZE.DEFAULT_CURSOR */ > ctx.max) {
|
|
27
27
|
return RANGE_ERR;
|
|
28
28
|
}
|
|
29
29
|
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
30
30
|
ctx.buf[ctx.len++] = modifyOp;
|
|
31
|
+
writeHllBuf(value, ctx, t, len);
|
|
32
|
+
}
|
|
33
|
+
export function writeHllBuf(value, ctx, t, len) {
|
|
31
34
|
ctx.buf.writeUint32LE(len, ctx.len);
|
|
32
35
|
ctx.len += 4;
|
|
33
36
|
for (let val of value) {
|
|
34
37
|
if (typeof val === 'string') {
|
|
35
|
-
xxHash64(
|
|
38
|
+
xxHash64(new TextEncoder().encode(val), ctx.buf, ctx.len);
|
|
36
39
|
}
|
|
37
|
-
else if (val instanceof Buffer
|
|
40
|
+
else if ((val instanceof Buffer || val instanceof Uint8Array) &&
|
|
41
|
+
val.byteLength === 8) {
|
|
38
42
|
ctx.buf.set(val, ctx.len);
|
|
39
43
|
}
|
|
40
44
|
else {
|
|
@@ -3,7 +3,7 @@ import { startDrain, flushBuffer } from '../operations.js';
|
|
|
3
3
|
import { setCursor } from './setCursor.js';
|
|
4
4
|
import { modify } from './modify.js';
|
|
5
5
|
import { ModifyState } from './ModifyRes.js';
|
|
6
|
-
import { CREATE, RANGE_ERR, ADD_EMPTY_SORT, } from './types.js';
|
|
6
|
+
import { CREATE, RANGE_ERR, ADD_EMPTY_SORT, ADD_EMPTY_SORT_TEXT, } from './types.js';
|
|
7
7
|
import { writeFixedValue } from './fixed.js';
|
|
8
8
|
import { getSubscriptionMarkers } from '../query/subscription/index.js';
|
|
9
9
|
const appendCreate = (ctx, def, obj, res, unsafe) => {
|
|
@@ -13,7 +13,7 @@ const appendCreate = (ctx, def, obj, res, unsafe) => {
|
|
|
13
13
|
return err;
|
|
14
14
|
}
|
|
15
15
|
if (ctx.len === len || def.mainLen === 0) {
|
|
16
|
-
if (ctx.len +
|
|
16
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ > ctx.max) {
|
|
17
17
|
return RANGE_ERR;
|
|
18
18
|
}
|
|
19
19
|
setCursor(ctx, def, 0, MICRO_BUFFER, res.tmpId, CREATE);
|
|
@@ -47,7 +47,7 @@ const appendCreate = (ctx, def, obj, res, unsafe) => {
|
|
|
47
47
|
let sizepos = ctx.len;
|
|
48
48
|
ctx.len += 2;
|
|
49
49
|
for (const { prop } of def.seperateSort.props) {
|
|
50
|
-
if (def.seperateSort.bufferTmp[prop] ===
|
|
50
|
+
if (def.seperateSort.bufferTmp[prop] === 0) {
|
|
51
51
|
if (ctx.len + 1 > ctx.max) {
|
|
52
52
|
return RANGE_ERR;
|
|
53
53
|
}
|
|
@@ -59,8 +59,44 @@ const appendCreate = (ctx, def, obj, res, unsafe) => {
|
|
|
59
59
|
ctx.buf[sizepos] = size >>>= 8;
|
|
60
60
|
}
|
|
61
61
|
if (ctx.hasSortField !== -1) {
|
|
62
|
-
def.seperateSort.
|
|
62
|
+
def.seperateSort.bufferTmp.set(def.seperateSort.buffer, 0);
|
|
63
63
|
}
|
|
64
|
+
// add test for this
|
|
65
|
+
ctx.hasSortField = -1;
|
|
66
|
+
}
|
|
67
|
+
if (def.hasSeperateTextSort) {
|
|
68
|
+
const buf = def.seperateTextSort.bufferTmp;
|
|
69
|
+
if (ctx.hasSortText !== def.seperateTextSort.size - 1) {
|
|
70
|
+
if (ctx.len + 3 > ctx.max) {
|
|
71
|
+
return RANGE_ERR;
|
|
72
|
+
}
|
|
73
|
+
ctx.buf[ctx.len++] = ADD_EMPTY_SORT_TEXT;
|
|
74
|
+
let sizepos = ctx.len;
|
|
75
|
+
ctx.len += 2;
|
|
76
|
+
const amount = def.localeSize + 1;
|
|
77
|
+
const len = amount * def.seperateTextSort.props.length;
|
|
78
|
+
for (const { prop } of def.seperateTextSort.props) {
|
|
79
|
+
const index = prop * amount;
|
|
80
|
+
if (buf[index] !== 0) {
|
|
81
|
+
ctx.buf[ctx.len++] = prop;
|
|
82
|
+
ctx.buf[ctx.len++] = buf[index];
|
|
83
|
+
for (let i = index + 1; i < len + index; i++) {
|
|
84
|
+
const lang = buf[i];
|
|
85
|
+
if (lang !== 0) {
|
|
86
|
+
ctx.buf[ctx.len++] = lang;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
let size = ctx.len - sizepos - 2;
|
|
92
|
+
ctx.buf[sizepos++] = size;
|
|
93
|
+
ctx.buf[sizepos] = size >>>= 8;
|
|
94
|
+
// [size][size] [prop][len][lang][lang]
|
|
95
|
+
}
|
|
96
|
+
if (ctx.hasSortText !== -1) {
|
|
97
|
+
buf.set(def.seperateTextSort.buffer, 0);
|
|
98
|
+
}
|
|
99
|
+
ctx.hasSortText = -1;
|
|
64
100
|
}
|
|
65
101
|
};
|
|
66
102
|
export function create(db, type, obj, opts) {
|
|
@@ -89,7 +125,7 @@ export function create(db, type, obj, opts) {
|
|
|
89
125
|
ctx.len = pos;
|
|
90
126
|
if (err === RANGE_ERR) {
|
|
91
127
|
if (pos === 0) {
|
|
92
|
-
throw new Error('
|
|
128
|
+
throw new Error('!No range available');
|
|
93
129
|
}
|
|
94
130
|
flushBuffer(db);
|
|
95
131
|
return db.create(type, obj, opts);
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import { flushBuffer, startDrain } from '../operations.js';
|
|
2
2
|
import { setCursor } from './setCursor.js';
|
|
3
|
-
import { UPDATE } from './types.js';
|
|
3
|
+
import { UPDATE, DELETE_SORT_INDEX, DELETE_NODE } from './types.js';
|
|
4
4
|
import { MICRO_BUFFER } from '@based/schema/def';
|
|
5
5
|
export const deleteFn = (db, type, id) => {
|
|
6
6
|
const ctx = db.modifyCtx;
|
|
7
7
|
const schema = db.schemaTypesParsed[type];
|
|
8
8
|
const separate = schema.separate;
|
|
9
|
+
// TODO: pretty slow actually
|
|
9
10
|
if (separate) {
|
|
10
|
-
const size =
|
|
11
|
+
const size = 11 /* SIZE.DEFAULT_CURSOR */ + 2 + separate.length * 12;
|
|
11
12
|
if (ctx.len + size > ctx.max) {
|
|
12
13
|
flushBuffer(db);
|
|
13
14
|
return deleteFn(db, type, id);
|
|
14
15
|
}
|
|
15
16
|
setCursor(ctx, schema, 0, MICRO_BUFFER, id, UPDATE);
|
|
16
|
-
ctx.buf[ctx.len++] =
|
|
17
|
+
ctx.buf[ctx.len++] = DELETE_SORT_INDEX;
|
|
17
18
|
for (const s of separate) {
|
|
18
19
|
setCursor(ctx, schema, s.prop, s.typeIndex, id, UPDATE);
|
|
19
|
-
ctx.buf[ctx.len++] =
|
|
20
|
+
ctx.buf[ctx.len++] = DELETE_SORT_INDEX;
|
|
20
21
|
}
|
|
21
|
-
ctx.buf[ctx.len++] =
|
|
22
|
+
ctx.buf[ctx.len++] = DELETE_NODE;
|
|
22
23
|
}
|
|
23
24
|
else {
|
|
24
|
-
if (ctx.len +
|
|
25
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 2 > ctx.max) {
|
|
25
26
|
flushBuffer(db);
|
|
26
27
|
return deleteFn(db, type, id);
|
|
27
28
|
}
|
|
28
29
|
setCursor(ctx, schema, 0, MICRO_BUFFER, id, UPDATE);
|
|
29
|
-
ctx.buf[ctx.len++] =
|
|
30
|
-
ctx.buf[ctx.len++] =
|
|
30
|
+
ctx.buf[ctx.len++] = DELETE_SORT_INDEX;
|
|
31
|
+
ctx.buf[ctx.len++] = DELETE_NODE;
|
|
31
32
|
}
|
|
32
33
|
if (!db.isDraining) {
|
|
33
34
|
startDrain(db);
|
|
@@ -8,7 +8,7 @@ export function expire(db, type, id, seconds) {
|
|
|
8
8
|
throw new Error(`Unknown type: ${type}. Did you mean on of: ${Object.keys(db.schemaTypesParsed).join(', ')}`);
|
|
9
9
|
}
|
|
10
10
|
const ctx = db.modifyCtx;
|
|
11
|
-
if (ctx.len +
|
|
11
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 > ctx.max) {
|
|
12
12
|
flushBuffer(db);
|
|
13
13
|
return expire(db, type, id, seconds);
|
|
14
14
|
}
|
|
@@ -34,7 +34,7 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
34
34
|
err = writeString(0, val, ctx, schema, def, res.tmpId, mod);
|
|
35
35
|
}
|
|
36
36
|
else if (type === TEXT) {
|
|
37
|
-
err = writeText(val, ctx, schema, def, res, mod);
|
|
37
|
+
err = writeText(val, ctx, schema, def, res, res.tmpId, mod);
|
|
38
38
|
}
|
|
39
39
|
else if (type === REFERENCE) {
|
|
40
40
|
err = writeReference(val, ctx, schema, def, res, mod);
|
|
@@ -59,7 +59,7 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
else if (overwrite) {
|
|
62
|
-
if (ctx.len +
|
|
62
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 + schema.mainLen > ctx.max) {
|
|
63
63
|
return RANGE_ERR;
|
|
64
64
|
}
|
|
65
65
|
setCursor(ctx, schema, def.prop, MICRO_BUFFER, res.tmpId, mod, true);
|
|
@@ -87,7 +87,7 @@ function _modify(ctx, res, obj, schema, mod, tree, overwrite, unsafe) {
|
|
|
87
87
|
if (increment === 0) {
|
|
88
88
|
continue;
|
|
89
89
|
}
|
|
90
|
-
if (ctx.len +
|
|
90
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ > ctx.max) {
|
|
91
91
|
return RANGE_ERR;
|
|
92
92
|
}
|
|
93
93
|
setCursor(ctx, schema, def.prop, MICRO_BUFFER, res.tmpId, mod);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BINARY, REFERENCE, REFERENCES, STRING, } from '@based/schema/def';
|
|
1
|
+
import { BINARY, CARDINALITY, REFERENCE, REFERENCES, STRING, } from '@based/schema/def';
|
|
2
2
|
import { write } from '../../string.js';
|
|
3
|
+
import { writeHllBuf } from '../cardinality.js';
|
|
3
4
|
import { getBuffer, writeBinaryRaw } from '../binary.js';
|
|
4
5
|
import { ModifyError, ModifyState } from '../ModifyRes.js';
|
|
5
6
|
import { DECREMENT, INCREMENT, RANGE_ERR } from '../types.js';
|
|
@@ -140,6 +141,19 @@ export function writeEdges(t, ref, ctx) {
|
|
|
140
141
|
ctx.buf[ctx.len++] = size >>>= 8;
|
|
141
142
|
appendRefs(edge, ctx, value);
|
|
142
143
|
}
|
|
144
|
+
else if (edge.typeIndex === CARDINALITY) {
|
|
145
|
+
if (!Array.isArray(value)) {
|
|
146
|
+
value = [value];
|
|
147
|
+
}
|
|
148
|
+
const len = value.length;
|
|
149
|
+
let size = 4 + len * 8;
|
|
150
|
+
if (ctx.len + size + 11 > ctx.max) {
|
|
151
|
+
return RANGE_ERR;
|
|
152
|
+
}
|
|
153
|
+
ctx.buf[ctx.len++] = edge.prop;
|
|
154
|
+
ctx.buf[ctx.len++] = CARDINALITY;
|
|
155
|
+
writeHllBuf(value, ctx, t, size);
|
|
156
|
+
}
|
|
143
157
|
}
|
|
144
158
|
else {
|
|
145
159
|
if (ctx.len + 2 > ctx.max) {
|
|
@@ -20,8 +20,6 @@ typeIndex, id, modifyOp, ignoreField) => {
|
|
|
20
20
|
ctx.buf[ctx.len++] = SWITCH_FIELD; // switch field
|
|
21
21
|
ctx.buf[ctx.len++] = field; // actual field
|
|
22
22
|
ctx.buf[ctx.len++] = typeIndex;
|
|
23
|
-
// field === 0 ? MICRO_BUFFER : schema.reverseProps[field].typeIndex
|
|
24
|
-
// add start and len if its main
|
|
25
23
|
ctx.field = field;
|
|
26
24
|
}
|
|
27
25
|
if (ctx.id !== id) {
|
|
@@ -2,4 +2,4 @@ import { LangCode } from '@based/schema';
|
|
|
2
2
|
import { ModifyCtx } from '../../index.js';
|
|
3
3
|
import { SchemaTypeDef, PropDef } from '@based/schema/def';
|
|
4
4
|
import { ModifyOp, ModifyErr } from './types.js';
|
|
5
|
-
export declare function writeString(lang: LangCode, value: string | null |
|
|
5
|
+
export declare function writeString(lang: LangCode, value: string | null | Uint8Array, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, parentId: number, modifyOp: ModifyOp): ModifyErr;
|
|
@@ -6,14 +6,14 @@ import { write } from '../string.js';
|
|
|
6
6
|
// add compression handling for main buffer
|
|
7
7
|
// add compression handling for edge fields
|
|
8
8
|
export function writeString(lang, value, ctx, def, t, parentId, modifyOp) {
|
|
9
|
-
const isBuffer = value instanceof
|
|
9
|
+
const isBuffer = value instanceof Uint8Array;
|
|
10
10
|
if (typeof value !== 'string' && value !== null && !isBuffer) {
|
|
11
11
|
return new ModifyError(t, value);
|
|
12
12
|
}
|
|
13
13
|
const len = value?.length;
|
|
14
14
|
if (!len) {
|
|
15
15
|
if (modifyOp === UPDATE) {
|
|
16
|
-
if (ctx.len + 11 > ctx.max) {
|
|
16
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 1 > ctx.max) {
|
|
17
17
|
return RANGE_ERR;
|
|
18
18
|
}
|
|
19
19
|
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
@@ -24,7 +24,9 @@ export function writeString(lang, value, ctx, def, t, parentId, modifyOp) {
|
|
|
24
24
|
let size = isBuffer
|
|
25
25
|
? value.byteLength
|
|
26
26
|
: Buffer.byteLength(value, 'utf8') + 6;
|
|
27
|
-
if (ctx.len +
|
|
27
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 11 + size > ctx.max) {
|
|
28
|
+
// +10 OR +11, teh original check was +20 but
|
|
29
|
+
// there are 10 addtional bytes in this scope
|
|
28
30
|
// 5 compression size
|
|
29
31
|
return RANGE_ERR;
|
|
30
32
|
}
|
|
@@ -5,4 +5,4 @@ import { writeString } from './string.js';
|
|
|
5
5
|
import { ModifyState } from './ModifyRes.js';
|
|
6
6
|
export declare function writeText(value: {
|
|
7
7
|
[k: string]: Parameters<typeof writeString>[1];
|
|
8
|
-
}, ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, res: ModifyState, modifyOp: ModifyOp): ModifyErr;
|
|
8
|
+
} | Parameters<typeof writeString>[1], ctx: ModifyCtx, def: SchemaTypeDef, t: PropDef, res: ModifyState, parentId: number, modifyOp: ModifyOp): ModifyErr;
|