@based/db 0.1.0 → 0.1.2
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/dist/lib/darwin_aarch64/include/selva/hll.h +2 -0
- package/dist/lib/darwin_aarch64/include/selva/membar.h +9 -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-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/src/client/index.d.ts +1 -2
- package/dist/src/client/modify/Ctx.js +1 -1
- package/dist/src/client/modify/cursor.d.ts +1 -1
- package/dist/src/client/modify/cursor.js +2 -2
- package/dist/src/client/modify/error.js +0 -2
- package/dist/src/client/modify/props/binary.js +2 -1
- package/dist/src/client/modify/props/cardinality.js +7 -0
- package/dist/src/client/modify/props/object.d.ts +2 -0
- package/dist/src/client/modify/props/object.js +50 -17
- package/dist/src/client/modify/props/vector.js +25 -7
- package/dist/src/client/query/BasedQueryResponse.js +3 -8
- package/dist/src/client/query/display.js +9 -16
- package/dist/src/client/query/include/toByteCode.js +14 -10
- package/dist/src/client/query/queryDefToReadSchema.js +7 -2
- package/dist/src/client/query/registerQuery.js +4 -3
- package/dist/src/client/query/types.d.ts +1 -0
- package/dist/src/client/query/validation.js +4 -1
- package/dist/src/client/setLocalClientSchema.d.ts +1 -1
- package/dist/src/hooks.d.ts +1 -2
- package/dist/src/native.d.ts +2 -0
- package/dist/src/native.js +7 -1
- package/dist/src/server/index.d.ts +1 -2
- package/dist/src/server/index.js +2 -3
- package/dist/src/server/migrate/index.d.ts +1 -2
- package/dist/src/server/migrate/index.js +3 -2
- package/dist/src/server/migrate/worker.js +31 -25
- package/dist/src/server/schema.d.ts +7 -3
- package/dist/src/server/schema.js +7 -56
- package/dist/src/server/workers/DbWorker.js +19 -5
- package/dist/src/shared/DbBase.d.ts +1 -1
- package/dist/src/shared/Emitter.d.ts +1 -1
- package/package.json +6 -6
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/include/cdefs.h +0 -317
- package/dist/lib/linux_aarch64/include/jemalloc.h +0 -468
- package/dist/lib/linux_aarch64/include/libdeflate.h +0 -345
- package/dist/lib/linux_aarch64/include/libdeflate_strings.h +0 -35
- package/dist/lib/linux_aarch64/include/linker_set.h +0 -109
- package/dist/lib/linux_aarch64/include/queue.h +0 -627
- package/dist/lib/linux_aarch64/include/selva/_export.h +0 -7
- package/dist/lib/linux_aarch64/include/selva/align.h +0 -9
- package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +0 -29
- package/dist/lib/linux_aarch64/include/selva/bitmap.h +0 -95
- package/dist/lib/linux_aarch64/include/selva/colvec.h +0 -71
- package/dist/lib/linux_aarch64/include/selva/crc32c.h +0 -17
- package/dist/lib/linux_aarch64/include/selva/ctime.h +0 -135
- package/dist/lib/linux_aarch64/include/selva/db.h +0 -407
- package/dist/lib/linux_aarch64/include/selva/endian.h +0 -301
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +0 -27
- package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +0 -18
- package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +0 -11
- package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +0 -36
- package/dist/lib/linux_aarch64/include/selva/fields.h +0 -407
- package/dist/lib/linux_aarch64/include/selva/gmtime.h +0 -137
- package/dist/lib/linux_aarch64/include/selva/hll.h +0 -83
- package/dist/lib/linux_aarch64/include/selva/lpf.h +0 -28
- package/dist/lib/linux_aarch64/include/selva/mblen.h +0 -40
- package/dist/lib/linux_aarch64/include/selva/membar.h +0 -23
- package/dist/lib/linux_aarch64/include/selva/node_id_set.h +0 -43
- package/dist/lib/linux_aarch64/include/selva/poptop.h +0 -114
- package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +0 -49
- package/dist/lib/linux_aarch64/include/selva/selva_lang.h +0 -105
- package/dist/lib/linux_aarch64/include/selva/selva_math.h +0 -37
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +0 -679
- package/dist/lib/linux_aarch64/include/selva/sort.h +0 -140
- package/dist/lib/linux_aarch64/include/selva/strsearch.h +0 -43
- package/dist/lib/linux_aarch64/include/selva/thread.h +0 -37
- package/dist/lib/linux_aarch64/include/selva/timestamp.h +0 -25
- package/dist/lib/linux_aarch64/include/selva/types.h +0 -129
- package/dist/lib/linux_aarch64/include/selva/vector.h +0 -35
- package/dist/lib/linux_aarch64/include/selva_error.h +0 -140
- package/dist/lib/linux_aarch64/include/selva_lang_code.h +0 -160
- package/dist/lib/linux_aarch64/include/tree.h +0 -852
- 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-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_aarch64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_x86_64/include/cdefs.h +0 -317
- package/dist/lib/linux_x86_64/include/jemalloc.h +0 -468
- package/dist/lib/linux_x86_64/include/libdeflate.h +0 -345
- package/dist/lib/linux_x86_64/include/libdeflate_strings.h +0 -35
- package/dist/lib/linux_x86_64/include/linker_set.h +0 -109
- package/dist/lib/linux_x86_64/include/queue.h +0 -627
- package/dist/lib/linux_x86_64/include/selva/_export.h +0 -7
- package/dist/lib/linux_x86_64/include/selva/align.h +0 -9
- package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +0 -29
- package/dist/lib/linux_x86_64/include/selva/bitmap.h +0 -95
- package/dist/lib/linux_x86_64/include/selva/colvec.h +0 -71
- package/dist/lib/linux_x86_64/include/selva/crc32c.h +0 -17
- package/dist/lib/linux_x86_64/include/selva/ctime.h +0 -135
- package/dist/lib/linux_x86_64/include/selva/db.h +0 -407
- package/dist/lib/linux_x86_64/include/selva/endian.h +0 -301
- package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +0 -27
- package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +0 -18
- package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +0 -11
- package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +0 -36
- package/dist/lib/linux_x86_64/include/selva/fields.h +0 -407
- package/dist/lib/linux_x86_64/include/selva/gmtime.h +0 -137
- package/dist/lib/linux_x86_64/include/selva/hll.h +0 -83
- package/dist/lib/linux_x86_64/include/selva/lpf.h +0 -28
- package/dist/lib/linux_x86_64/include/selva/mblen.h +0 -40
- package/dist/lib/linux_x86_64/include/selva/membar.h +0 -23
- package/dist/lib/linux_x86_64/include/selva/node_id_set.h +0 -43
- package/dist/lib/linux_x86_64/include/selva/poptop.h +0 -114
- package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +0 -49
- package/dist/lib/linux_x86_64/include/selva/selva_lang.h +0 -105
- package/dist/lib/linux_x86_64/include/selva/selva_math.h +0 -37
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +0 -679
- package/dist/lib/linux_x86_64/include/selva/sort.h +0 -140
- package/dist/lib/linux_x86_64/include/selva/strsearch.h +0 -43
- package/dist/lib/linux_x86_64/include/selva/thread.h +0 -37
- package/dist/lib/linux_x86_64/include/selva/timestamp.h +0 -25
- package/dist/lib/linux_x86_64/include/selva/types.h +0 -129
- package/dist/lib/linux_x86_64/include/selva/vector.h +0 -35
- package/dist/lib/linux_x86_64/include/selva_error.h +0 -140
- package/dist/lib/linux_x86_64/include/selva_lang_code.h +0 -160
- package/dist/lib/linux_x86_64/include/tree.h +0 -852
- 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-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/lib/linux_x86_64/libxxhash.so.0 +0 -0
- package/dist/src/schema.d.ts +0 -6
- package/dist/src/schema.js +0 -2
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
SELVA_EXPORT
|
|
14
14
|
void hll_init(struct selva_string *hllss, uint8_t precision, bool is_sparse);
|
|
15
15
|
SELVA_EXPORT
|
|
16
|
+
void hll_init_like(struct selva_string *hlla, struct selva_string *hllb);
|
|
17
|
+
SELVA_EXPORT
|
|
16
18
|
void hll_add(struct selva_string *hllss, uint64_t element);
|
|
17
19
|
SELVA_EXPORT
|
|
18
20
|
uint8_t *hll_count(struct selva_string *hllss);
|
|
@@ -4,6 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
#include "selva/_export.h"
|
|
6
6
|
|
|
7
|
+
/*
|
|
8
|
+
* When you run threads on different cores on Graviton it doesn't guarantee that
|
|
9
|
+
* a write in one thread is seen in the other one immediately.
|
|
10
|
+
* https://github.com/aws/aws-graviton-getting-started/blob/main/optimizing.md#ordering-issues
|
|
11
|
+
*
|
|
12
|
+
* This is also true on the Apple M arch:
|
|
13
|
+
* https://developer.apple.com/documentation/apple-silicon/addressing-architectural-differences-in-your-macos-code
|
|
14
|
+
*/
|
|
15
|
+
|
|
7
16
|
/**
|
|
8
17
|
* Read memory barrier.
|
|
9
18
|
* Call this function before read in case another thread has potentially
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { MigrateFns, Schema } from '@based/schema';
|
|
1
|
+
import { MigrateFns, Schema, SchemaChecksum } from '@based/schema';
|
|
2
2
|
import { BasedDbQuery, QueryByAliasObj } from './query/BasedDbQuery.js';
|
|
3
3
|
import { SubStore } from './query/subscription/index.js';
|
|
4
4
|
import { DbShared } from '../shared/DbBase.js';
|
|
5
5
|
import { DbClientHooks } from '../hooks.js';
|
|
6
|
-
import { SchemaChecksum } from '../schema.js';
|
|
7
6
|
import { ModifyOpts } from './modify/types.js';
|
|
8
7
|
import { Ctx } from './modify/Ctx.js';
|
|
9
8
|
type DbClientOpts = {
|
|
@@ -3,7 +3,7 @@ export class Ctx {
|
|
|
3
3
|
constructor(schemaChecksum, array) {
|
|
4
4
|
this.array = array;
|
|
5
5
|
this.max = array.buffer.maxByteLength - 4; // dataLen
|
|
6
|
-
this.size = array.buffer.byteLength -
|
|
6
|
+
this.size = array.buffer.byteLength - 4;
|
|
7
7
|
writeUint64(array, schemaChecksum, 0);
|
|
8
8
|
}
|
|
9
9
|
id;
|
|
@@ -5,6 +5,6 @@ export declare const PROP_CURSOR_SIZE = 3;
|
|
|
5
5
|
export declare const NODE_CURSOR_SIZE = 5;
|
|
6
6
|
export declare const FULL_CURSOR_SIZE: number;
|
|
7
7
|
export declare const writeTypeCursor: (ctx: Ctx) => void;
|
|
8
|
-
export declare const writePropCursor: (ctx: Ctx, def: PropDef) => void;
|
|
8
|
+
export declare const writePropCursor: (ctx: Ctx, def: PropDef, typeIndex?: import("@based/schema/prop-types").TypeIndex) => void;
|
|
9
9
|
export declare const writeMainCursor: (ctx: Ctx) => void;
|
|
10
10
|
export declare const writeNodeCursor: (ctx: Ctx) => void;
|
|
@@ -16,11 +16,11 @@ export const writeTypeCursor = (ctx) => {
|
|
|
16
16
|
ctx.cursor.id = null;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
export const writePropCursor = (ctx, def) => {
|
|
19
|
+
export const writePropCursor = (ctx, def, typeIndex = def.typeIndex) => {
|
|
20
20
|
if (def.prop !== ctx.cursor.prop) {
|
|
21
21
|
ctx.array[ctx.index] = SWITCH_FIELD;
|
|
22
22
|
ctx.array[ctx.index + 1] = def.prop;
|
|
23
|
-
ctx.array[ctx.index + 2] =
|
|
23
|
+
ctx.array[ctx.index + 2] = typeIndex;
|
|
24
24
|
ctx.index += 3;
|
|
25
25
|
ctx.cursor.prop = def.prop;
|
|
26
26
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { writeU16, writeU32, writeU8, writeU8Array } from '../uint.js';
|
|
2
2
|
import { PROP_CURSOR_SIZE, writePropCursor } from '../cursor.js';
|
|
3
3
|
import { validate } from '../validate.js';
|
|
4
|
+
import { BINARY } from '@based/schema/def';
|
|
4
5
|
import native from '../../../native.js';
|
|
5
6
|
import { reserve } from '../resize.js';
|
|
6
7
|
import { deleteProp } from './delete.js';
|
|
@@ -45,7 +46,7 @@ export const writeBinary = (ctx, def, val, validated) => {
|
|
|
45
46
|
}
|
|
46
47
|
const size = buf.byteLength + 6;
|
|
47
48
|
reserve(ctx, PROP_CURSOR_SIZE + size + 11);
|
|
48
|
-
writePropCursor(ctx, def);
|
|
49
|
+
writePropCursor(ctx, def, BINARY);
|
|
49
50
|
writeU8(ctx, ctx.operation);
|
|
50
51
|
writeBinaryRaw(ctx, buf);
|
|
51
52
|
};
|
|
@@ -6,6 +6,7 @@ import { ENCODER } from '@based/utils';
|
|
|
6
6
|
import { reserve } from '../resize.js';
|
|
7
7
|
import { PROP_CURSOR_SIZE, writePropCursor } from '../cursor.js';
|
|
8
8
|
import { CREATE } from '../types.js';
|
|
9
|
+
import { writeBinary } from './binary.js';
|
|
9
10
|
export const writeCardinalityRaw = (ctx, def, val, sizeFixBecauseEdgeIsDifferent = val.length) => {
|
|
10
11
|
writeU32(ctx, sizeFixBecauseEdgeIsDifferent);
|
|
11
12
|
for (const item of val) {
|
|
@@ -27,6 +28,10 @@ export const writeCardinality = (ctx, def, val) => {
|
|
|
27
28
|
deleteProp(ctx, def);
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
31
|
+
if (val instanceof Uint8Array && val.byteLength !== 8) {
|
|
32
|
+
writeBinary(ctx, def, val, true);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
30
35
|
if (!Array.isArray(val)) {
|
|
31
36
|
val = [val];
|
|
32
37
|
}
|
|
@@ -37,6 +42,8 @@ export const writeCardinality = (ctx, def, val) => {
|
|
|
37
42
|
reserve(ctx, PROP_CURSOR_SIZE + size + 1);
|
|
38
43
|
writePropCursor(ctx, def);
|
|
39
44
|
writeU8(ctx, ctx.operation);
|
|
45
|
+
writeU8(ctx, def.cardinalityMode);
|
|
46
|
+
writeU8(ctx, def.cardinalityPrecision);
|
|
40
47
|
writeCardinalityRaw(ctx, def, val);
|
|
41
48
|
if (ctx.operation === CREATE) {
|
|
42
49
|
ctx.schema.separateSort.bufferTmp[def.prop] = 2;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { SchemaTypeDef } from '@based/schema/def';
|
|
2
2
|
import { Ctx } from '../Ctx.js';
|
|
3
|
+
export declare const writeObjectSafe: (ctx: Ctx, tree: SchemaTypeDef["tree"], obj: Record<string, any>) => void;
|
|
4
|
+
export declare const writeObjectUnsafe: (ctx: Ctx, tree: SchemaTypeDef["tree"], obj: Record<string, any>) => void;
|
|
3
5
|
export declare const writeObject: (ctx: Ctx, tree: SchemaTypeDef["tree"], obj: Record<string, any>) => void;
|
|
@@ -2,7 +2,21 @@ import { isPropDef } from '@based/schema/def';
|
|
|
2
2
|
import { writeSeparate } from './separate.js';
|
|
3
3
|
import { writeMainValue } from './main.js';
|
|
4
4
|
import { writeIncrement } from './increment.js';
|
|
5
|
-
|
|
5
|
+
const writeProp = (ctx, def, val) => {
|
|
6
|
+
if (def.separate) {
|
|
7
|
+
writeSeparate(ctx, def, val);
|
|
8
|
+
}
|
|
9
|
+
else if (ctx.overwrite) {
|
|
10
|
+
writeMainValue(ctx, def, val);
|
|
11
|
+
}
|
|
12
|
+
else if (typeof val === 'object' && val !== null) {
|
|
13
|
+
writeIncrement(ctx, def, val);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
ctx.main.set(def, val);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const writeObjectSafe = (ctx, tree, obj) => {
|
|
6
20
|
for (const key in obj) {
|
|
7
21
|
const val = obj[key];
|
|
8
22
|
if (val === undefined) {
|
|
@@ -10,28 +24,47 @@ export const writeObject = (ctx, tree, obj) => {
|
|
|
10
24
|
}
|
|
11
25
|
const def = tree[key];
|
|
12
26
|
if (def === undefined) {
|
|
13
|
-
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
throw [tree, key];
|
|
27
|
+
throw [def, val];
|
|
17
28
|
}
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
continue;
|
|
29
|
+
if (isPropDef(def)) {
|
|
30
|
+
writeProp(ctx, def, val);
|
|
21
31
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
continue;
|
|
32
|
+
else {
|
|
33
|
+
writeObjectSafe(ctx, def, val);
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export const writeObjectUnsafe = (ctx, tree, obj) => {
|
|
38
|
+
for (const key in obj) {
|
|
39
|
+
const def = tree[key];
|
|
40
|
+
const val = obj[key];
|
|
41
|
+
if (def === undefined || val === undefined) {
|
|
28
42
|
continue;
|
|
29
43
|
}
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
if (isPropDef(def)) {
|
|
45
|
+
const index = ctx.index;
|
|
46
|
+
try {
|
|
47
|
+
writeProp(ctx, def, val);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (Array.isArray(e)) {
|
|
51
|
+
ctx.index = index;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
33
56
|
}
|
|
34
|
-
|
|
57
|
+
else {
|
|
58
|
+
writeObjectUnsafe(ctx, def, val);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export const writeObject = (ctx, tree, obj) => {
|
|
63
|
+
if (ctx.unsafe) {
|
|
64
|
+
writeObjectUnsafe(ctx, tree, obj);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
writeObjectSafe(ctx, tree, obj);
|
|
35
68
|
}
|
|
36
69
|
};
|
|
37
70
|
//# sourceMappingURL=object.js.map
|
|
@@ -2,7 +2,7 @@ import { deleteProp } from './delete.js';
|
|
|
2
2
|
import { validate } from '../validate.js';
|
|
3
3
|
import { PROP_CURSOR_SIZE, writePropCursor } from '../cursor.js';
|
|
4
4
|
import { reserve } from '../resize.js';
|
|
5
|
-
import {
|
|
5
|
+
import { writeU8 } from '../uint.js';
|
|
6
6
|
export const writeVector = (ctx, def, val) => {
|
|
7
7
|
if (val === null) {
|
|
8
8
|
deleteProp(ctx, def);
|
|
@@ -18,13 +18,31 @@ export const writeVector = (ctx, def, val) => {
|
|
|
18
18
|
writeU8(ctx, ctx.operation);
|
|
19
19
|
let size = Math.min(val.byteLength, def.len);
|
|
20
20
|
let padding = 0;
|
|
21
|
-
if (ctx.index % 4
|
|
21
|
+
if (ctx.index % 4 != 0) {
|
|
22
22
|
padding = ctx.index % 4;
|
|
23
|
-
size -= padding;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
size -= padding;
|
|
25
|
+
let tmp = size + 4;
|
|
26
|
+
// 16-bits would be enough but the zig expects 32-bits
|
|
27
|
+
ctx.array[ctx.index++] = tmp;
|
|
28
|
+
ctx.array[ctx.index++] = tmp >>>= 8;
|
|
29
|
+
ctx.array[ctx.index++] = tmp >>>= 8;
|
|
30
|
+
ctx.array[ctx.index++] = tmp >>>= 8;
|
|
31
|
+
ctx.array[ctx.index++] = padding;
|
|
32
|
+
ctx.array[ctx.index++] = 0;
|
|
33
|
+
ctx.array[ctx.index++] = 0;
|
|
34
|
+
ctx.array[ctx.index++] = 0;
|
|
35
|
+
ctx.array.set(new Uint8Array(val.buffer).subarray(0, size), ctx.index - padding);
|
|
36
|
+
ctx.index += size;
|
|
37
|
+
// let size = Math.min(val.byteLength, def.len)
|
|
38
|
+
// let padding = 0
|
|
39
|
+
// if (ctx.index % 4 !== 0) {
|
|
40
|
+
// padding = ctx.index % 4
|
|
41
|
+
// size -= padding
|
|
42
|
+
// }
|
|
43
|
+
// writeU32(ctx, size + 4)
|
|
44
|
+
// writeU8(ctx, padding)
|
|
45
|
+
// writePadding(ctx, 3 - padding)
|
|
46
|
+
// writeU8Array(ctx, new Uint8Array(val.buffer).subarray(0, size))
|
|
29
47
|
};
|
|
30
48
|
//# sourceMappingURL=vector.js.map
|
|
@@ -3,11 +3,8 @@ import picocolors from 'picocolors';
|
|
|
3
3
|
import { debug } from './query.js';
|
|
4
4
|
import { size, time, inspectData, defHasId, displayTarget } from './display.js';
|
|
5
5
|
import { readFloatLE, readUint32 } from '@based/utils';
|
|
6
|
-
import { resultToObject, readProps, readId, } from '@based/protocol/db-read';
|
|
6
|
+
import { resultToObject, readProps, readId, readChecksum, readVersion, } from '@based/protocol/db-read';
|
|
7
7
|
export { time, size, inspectData };
|
|
8
|
-
const BITS_FOR_BYTE_LEN = 21;
|
|
9
|
-
const FACTOR = 2 ** BITS_FOR_BYTE_LEN;
|
|
10
|
-
const MASK_B = FACTOR - 1;
|
|
11
8
|
export class BasedQueryResponse {
|
|
12
9
|
result;
|
|
13
10
|
def;
|
|
@@ -26,7 +23,7 @@ export class BasedQueryResponse {
|
|
|
26
23
|
return this.def.queryId;
|
|
27
24
|
}
|
|
28
25
|
get version() {
|
|
29
|
-
return (this.
|
|
26
|
+
return readVersion(this.result);
|
|
30
27
|
}
|
|
31
28
|
get size() {
|
|
32
29
|
return this.result.length;
|
|
@@ -106,9 +103,7 @@ export class BasedQueryResponse {
|
|
|
106
103
|
return arr;
|
|
107
104
|
}
|
|
108
105
|
get checksum() {
|
|
109
|
-
|
|
110
|
-
const offset = result.byteLength - 4;
|
|
111
|
-
return readUint32(result, offset);
|
|
106
|
+
return readChecksum(this.result);
|
|
112
107
|
}
|
|
113
108
|
get length() {
|
|
114
109
|
const l = readUint32(this.result, 0);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import picocolors from 'picocolors';
|
|
2
2
|
import { BINARY, CARDINALITY, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, } from '@based/schema/def';
|
|
3
3
|
import { ENCODER } from '@based/utils';
|
|
4
|
-
import { AggregateType } from '@based/protocol/db-read';
|
|
5
4
|
const decimals = (v) => ~~(v * 100) / 100;
|
|
6
5
|
const sizeCalc = (size) => {
|
|
7
6
|
if (size > 1e6) {
|
|
@@ -160,10 +159,7 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
|
|
|
160
159
|
if (typeof v === 'number') {
|
|
161
160
|
if (q.aggregate) {
|
|
162
161
|
str += printNumber(v);
|
|
163
|
-
|
|
164
|
-
const [[__, akv], _] = q.aggregate.aggregates;
|
|
165
|
-
const aggType = akv[0].type;
|
|
166
|
-
str += picocolors.italic(picocolors.dim(` ${AggregateType[aggType].toLowerCase()}`));
|
|
162
|
+
str += picocolors.italic(picocolors.dim(` ${k.toLowerCase()}`));
|
|
167
163
|
str += ',\n';
|
|
168
164
|
}
|
|
169
165
|
else {
|
|
@@ -179,9 +175,7 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
|
|
|
179
175
|
if (def.typeIndex === REFERENCES) {
|
|
180
176
|
if (q.aggregate) {
|
|
181
177
|
str += printNumber(v);
|
|
182
|
-
|
|
183
|
-
const aggType = akv[0].type;
|
|
184
|
-
str += picocolors.italic(picocolors.dim(` ${AggregateType[aggType].toLowerCase()}`));
|
|
178
|
+
str += picocolors.italic(picocolors.dim(` ${k.toLowerCase()}`));
|
|
185
179
|
}
|
|
186
180
|
else {
|
|
187
181
|
str += inspectData(v, q.references.get(def.prop), level + 2, false, depth);
|
|
@@ -194,9 +188,7 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
|
|
|
194
188
|
else {
|
|
195
189
|
if (q.aggregate) {
|
|
196
190
|
str += printNumber(v);
|
|
197
|
-
|
|
198
|
-
const aggType = akv[0].type;
|
|
199
|
-
str += picocolors.italic(picocolors.dim(` ${AggregateType[aggType].toLowerCase()}`));
|
|
191
|
+
str += picocolors.italic(picocolors.dim(` ${k.toLowerCase()}`));
|
|
200
192
|
}
|
|
201
193
|
else {
|
|
202
194
|
str += inspectObject(v, q.references.get(def.prop), '', level + 2, false, false, true, depth);
|
|
@@ -240,22 +232,23 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
|
|
|
240
232
|
if (typeof v === 'number') {
|
|
241
233
|
if (q.aggregate) {
|
|
242
234
|
str += printNumber(v);
|
|
243
|
-
|
|
244
|
-
const aggType = akv[0].type;
|
|
245
|
-
str += picocolors.italic(picocolors.dim(` ${AggregateType[aggType].toLowerCase()}`));
|
|
235
|
+
str += picocolors.italic(picocolors.dim(` ${k.toLowerCase()}`));
|
|
246
236
|
}
|
|
247
237
|
else {
|
|
248
238
|
str += printNumber(v);
|
|
249
239
|
}
|
|
250
240
|
}
|
|
251
241
|
else if (typeof v === 'object' && v) {
|
|
252
|
-
|
|
242
|
+
str +=
|
|
243
|
+
inspectObject(v, q, key, level + 2, false, false, true, depth) + '';
|
|
253
244
|
}
|
|
254
245
|
else {
|
|
255
246
|
str += v;
|
|
256
247
|
}
|
|
257
248
|
}
|
|
258
|
-
if (def?.typeIndex !== REFERENCE &&
|
|
249
|
+
if (def?.typeIndex !== REFERENCE &&
|
|
250
|
+
def?.typeIndex !== REFERENCES &&
|
|
251
|
+
typeof v !== 'object') {
|
|
259
252
|
str += ',\n';
|
|
260
253
|
}
|
|
261
254
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MICRO_BUFFER, STRING, TEXT, JSON } from '@based/schema/def';
|
|
1
|
+
import { MICRO_BUFFER, STRING, TEXT, JSON, BINARY } from '@based/schema/def';
|
|
2
2
|
import { QueryDefType } from '../types.js';
|
|
3
3
|
import { walkDefs } from './walk.js';
|
|
4
4
|
import { langCodesMap } from '@based/schema';
|
|
@@ -76,6 +76,7 @@ export const includeToBuffer = (db, def) => {
|
|
|
76
76
|
}
|
|
77
77
|
if (propSize) {
|
|
78
78
|
for (const [prop, propDef] of def.include.props.entries()) {
|
|
79
|
+
const typeIndex = propDef.opts?.raw ? BINARY : propDef.def.typeIndex;
|
|
79
80
|
if (propDef.opts?.meta) {
|
|
80
81
|
if (propDef.opts.codes) {
|
|
81
82
|
if (propDef.opts.codes.has(0)) {
|
|
@@ -84,7 +85,7 @@ export const includeToBuffer = (db, def) => {
|
|
|
84
85
|
const buf = new Uint8Array(4);
|
|
85
86
|
buf[0] = 6 /* includeOp.META */;
|
|
86
87
|
buf[1] = prop;
|
|
87
|
-
buf[2] =
|
|
88
|
+
buf[2] = typeIndex;
|
|
88
89
|
buf[3] = langCodesMap.get(code);
|
|
89
90
|
result.push(buf);
|
|
90
91
|
}
|
|
@@ -94,7 +95,7 @@ export const includeToBuffer = (db, def) => {
|
|
|
94
95
|
const buf = new Uint8Array(4);
|
|
95
96
|
buf[0] = 6 /* includeOp.META */;
|
|
96
97
|
buf[1] = prop;
|
|
97
|
-
buf[2] =
|
|
98
|
+
buf[2] = typeIndex;
|
|
98
99
|
buf[3] = code;
|
|
99
100
|
result.push(buf);
|
|
100
101
|
}
|
|
@@ -104,21 +105,20 @@ export const includeToBuffer = (db, def) => {
|
|
|
104
105
|
const buf = new Uint8Array(4);
|
|
105
106
|
buf[0] = 6 /* includeOp.META */;
|
|
106
107
|
buf[1] = prop;
|
|
107
|
-
buf[2] =
|
|
108
|
+
buf[2] = typeIndex;
|
|
108
109
|
buf[3] = 0;
|
|
109
110
|
result.push(buf);
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
if (propDef.opts?.meta !== 'only') {
|
|
113
114
|
const hasEnd = propDef.opts?.end;
|
|
114
|
-
|
|
115
|
-
if (t === TEXT) {
|
|
115
|
+
if (typeIndex === TEXT) {
|
|
116
116
|
const codes = propDef.opts.codes;
|
|
117
117
|
if (codes.has(0)) {
|
|
118
118
|
const b = new Uint8Array(hasEnd ? 12 : 4);
|
|
119
119
|
b[0] = 1 /* includeOp.DEFAULT */;
|
|
120
120
|
b[1] = prop;
|
|
121
|
-
b[2] =
|
|
121
|
+
b[2] = typeIndex;
|
|
122
122
|
if (hasEnd) {
|
|
123
123
|
b[3] = 8; // opts len
|
|
124
124
|
b[4] = 0; // lang code
|
|
@@ -139,7 +139,7 @@ export const includeToBuffer = (db, def) => {
|
|
|
139
139
|
const b = new Uint8Array(7 + (endCode ? 5 : 0) + fallBackSize);
|
|
140
140
|
b[0] = 1 /* includeOp.DEFAULT */;
|
|
141
141
|
b[1] = prop;
|
|
142
|
-
b[2] =
|
|
142
|
+
b[2] = typeIndex;
|
|
143
143
|
let i = 0;
|
|
144
144
|
if (endCode) {
|
|
145
145
|
b[3] = fallBackSize + 8; // opts
|
|
@@ -169,10 +169,14 @@ export const includeToBuffer = (db, def) => {
|
|
|
169
169
|
const buf = new Uint8Array(hasEnd ? 9 : 4);
|
|
170
170
|
buf[0] = 1 /* includeOp.DEFAULT */;
|
|
171
171
|
buf[1] = prop;
|
|
172
|
-
buf[2] =
|
|
172
|
+
buf[2] = typeIndex;
|
|
173
173
|
if (hasEnd) {
|
|
174
174
|
buf[3] = 5; // opts len
|
|
175
|
-
buf[4] =
|
|
175
|
+
buf[4] =
|
|
176
|
+
propDef.opts?.bytes ||
|
|
177
|
+
(typeIndex !== JSON && typeIndex !== STRING)
|
|
178
|
+
? 0
|
|
179
|
+
: 1;
|
|
176
180
|
writeUint32(buf, getEnd(propDef.opts), 5);
|
|
177
181
|
}
|
|
178
182
|
else {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// import type { IncludeOpts, QueryDef, Target } from '@based/db'
|
|
2
2
|
import { inverseLangMap, langCodesMap } from '@based/schema';
|
|
3
|
-
import { COLVEC, ENUM, TEXT, VECTOR, } from '@based/schema/def';
|
|
3
|
+
import { COLVEC, ENUM, TEXT, VECTOR, BINARY, CARDINALITY, } from '@based/schema/def';
|
|
4
4
|
import { ReaderMeta, ReaderSchemaEnum, } from '@based/protocol/db-read';
|
|
5
5
|
const createReaderPropDef = (p, locales, opts) => {
|
|
6
6
|
const readerPropDef = {
|
|
7
7
|
path: p.__isEdge ? p.path.slice(1) : p.path,
|
|
8
|
-
typeIndex: p.typeIndex,
|
|
8
|
+
typeIndex: opts?.raw ? BINARY : p.typeIndex,
|
|
9
9
|
readBy: 0,
|
|
10
10
|
};
|
|
11
11
|
if (opts?.meta) {
|
|
@@ -19,6 +19,10 @@ const createReaderPropDef = (p, locales, opts) => {
|
|
|
19
19
|
readerPropDef.vectorBaseType = p.vectorBaseType;
|
|
20
20
|
readerPropDef.len = p.len;
|
|
21
21
|
}
|
|
22
|
+
if (p.typeIndex === CARDINALITY) {
|
|
23
|
+
readerPropDef.cardinalityMode = p.cardinalityMode;
|
|
24
|
+
readerPropDef.cardinalityPrecision = p.cardinalityPrecision;
|
|
25
|
+
}
|
|
22
26
|
if (p.typeIndex === TEXT) {
|
|
23
27
|
if (opts.codes.has(0)) {
|
|
24
28
|
readerPropDef.locales = locales;
|
|
@@ -51,6 +55,7 @@ export const convertToReaderSchema = (q, locales) => {
|
|
|
51
55
|
const readerSchema = {
|
|
52
56
|
readId: 0,
|
|
53
57
|
props: {},
|
|
58
|
+
search: false,
|
|
54
59
|
main: { len: 0, props: {} },
|
|
55
60
|
refs: {},
|
|
56
61
|
type: isEdge
|
|
@@ -15,11 +15,9 @@ export const registerQuery = (q) => {
|
|
|
15
15
|
q.target, q.skipValidation);
|
|
16
16
|
def.schemaChecksum = q.db.schema?.hash || 0;
|
|
17
17
|
q.def = def;
|
|
18
|
-
// proposal:
|
|
19
18
|
for (const command of commands) {
|
|
20
19
|
q[command.method](...command.args);
|
|
21
20
|
}
|
|
22
|
-
// locale first...
|
|
23
21
|
if (!q.def.include.stringFields.size && !q.def.references.size) {
|
|
24
22
|
includeField(q.def, { field: '*' });
|
|
25
23
|
}
|
|
@@ -32,10 +30,13 @@ export const registerQuery = (q) => {
|
|
|
32
30
|
q.buffer = buf;
|
|
33
31
|
// console.log('--------------------------------------------------')
|
|
34
32
|
// console.dir(convertToReaderSchema(q.def), { depth: 100 })
|
|
35
|
-
//
|
|
33
|
+
// const c = convertToReaderSchema(q.def)
|
|
34
|
+
// const s = serialize(c)
|
|
35
|
+
// console.log(deSerializeSchema(s))
|
|
36
36
|
// q.def.readSchema = deSerializeSchema(
|
|
37
37
|
// serialize(convertToReaderSchema(q.def)),
|
|
38
38
|
// )
|
|
39
|
+
// console.log('--------------------------------------------------')
|
|
39
40
|
q.def.readSchema = convertToReaderSchema(q.def);
|
|
40
41
|
handleErrors(q.def);
|
|
41
42
|
return buf;
|
|
@@ -352,7 +352,10 @@ export const validateAlias = (def, alias, path) => {
|
|
|
352
352
|
if (typeof alias[k] === 'string') {
|
|
353
353
|
const p = path ? `${path}.${k}` : k;
|
|
354
354
|
const prop = schema.props[p];
|
|
355
|
-
if (prop
|
|
355
|
+
if (!prop) {
|
|
356
|
+
// def.errors.push({ code: ERR_TARGET_INVAL_ALIAS, payload: def })
|
|
357
|
+
}
|
|
358
|
+
else if (prop.typeIndex === ALIAS) {
|
|
356
359
|
return { def: prop, value: alias[k] };
|
|
357
360
|
}
|
|
358
361
|
}
|
package/dist/src/hooks.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { StrictSchema, MigrateFns } from '@based/schema';
|
|
1
|
+
import { StrictSchema, MigrateFns, DbSchema, SchemaChecksum } from '@based/schema';
|
|
2
2
|
import { BasedDbQuery } from './client/query/BasedDbQuery.js';
|
|
3
3
|
import { OnClose, OnData, OnError } from './client/query/subscription/types.js';
|
|
4
4
|
import { DbServer } from './server/index.js';
|
|
5
|
-
import { DbSchema, SchemaChecksum } from './schema.js';
|
|
6
5
|
export type DbClientHooks = {
|
|
7
6
|
setSchema(schema: StrictSchema, transformFns?: MigrateFns): Promise<SchemaChecksum>;
|
|
8
7
|
flushModify(buf: Uint8Array): Promise<{
|
package/dist/src/native.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ declare const native: {
|
|
|
16
16
|
updateSchemaType: (prefix: number, buf: Uint8Array, dbCtx: any) => any;
|
|
17
17
|
getTypeInfo: (typeId: number, dbCtx: any) => any;
|
|
18
18
|
getNodeRangeHash: (typeId: number, start: number, end: number, bufOut: Uint8Array, dbCtx: any) => any;
|
|
19
|
+
createCompressor(): any;
|
|
20
|
+
compressRaw: (compressor: any, buf: Uint8Array, offset: number, stringSize: number) => any;
|
|
19
21
|
compress: (buf: Uint8Array, offset: number, stringSize: number) => any;
|
|
20
22
|
decompress: (input: Uint8Array, output: Uint8Array, offset: number, len: number) => any;
|
|
21
23
|
crc32: (buf: Uint8Array) => any;
|
package/dist/src/native.js
CHANGED
|
@@ -74,6 +74,12 @@ const native = {
|
|
|
74
74
|
getNodeRangeHash: (typeId, start, end, bufOut, dbCtx) => {
|
|
75
75
|
return db.getNodeRangeHash(typeId, start, end, bufOut, dbCtx);
|
|
76
76
|
},
|
|
77
|
+
createCompressor() {
|
|
78
|
+
return db.createCompressor();
|
|
79
|
+
},
|
|
80
|
+
compressRaw: (compressor, buf, offset, stringSize) => {
|
|
81
|
+
return db.compress(compressor, buf, offset, stringSize);
|
|
82
|
+
},
|
|
77
83
|
compress: (buf, offset, stringSize) => {
|
|
78
84
|
return db.compress(compressor, buf, offset, stringSize);
|
|
79
85
|
},
|
|
@@ -106,7 +112,7 @@ const native = {
|
|
|
106
112
|
},
|
|
107
113
|
colvecTest: (dbCtx, typeId, field, nodeId, len) => {
|
|
108
114
|
return db.colvecTest(dbCtx, typeId, field, nodeId, len);
|
|
109
|
-
}
|
|
115
|
+
},
|
|
110
116
|
};
|
|
111
117
|
global.__basedDb__native__ = native;
|
|
112
118
|
export default native;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { LangName, MigrateFns,
|
|
1
|
+
import { StrictSchema, LangName, MigrateFns, SchemaChecksum } from '@based/schema';
|
|
2
2
|
import { StartOpts } from './start.js';
|
|
3
3
|
import { VerifTree } from './tree.js';
|
|
4
4
|
import exitHook from 'exit-hook';
|
|
5
|
-
import { SchemaChecksum } from '../schema.js';
|
|
6
5
|
import { IoWorker } from './IoWorker.js';
|
|
7
6
|
import { QueryWorker } from './QueryWorker.js';
|
|
8
7
|
import { DbShared } from '../shared/DbBase.js';
|
package/dist/src/server/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import native from '../native.js';
|
|
2
2
|
import { rm } from 'node:fs/promises';
|
|
3
|
-
import { langCodesMap } from '@based/schema';
|
|
3
|
+
import { langCodesMap, strictSchemaToDbSchema } from '@based/schema';
|
|
4
4
|
import { ID_FIELD_DEF } from '@based/schema/def';
|
|
5
5
|
import { start } from './start.js';
|
|
6
6
|
import { destructureTreeKey, makeTreeKeyFromNodeId } from './tree.js';
|
|
@@ -10,7 +10,6 @@ import { migrate } from './migrate/index.js';
|
|
|
10
10
|
import { debugServer } from '../utils.js';
|
|
11
11
|
import { readUint16, readUint32, readUint64, writeUint32 } from '@based/utils';
|
|
12
12
|
import { QueryType } from '../client/query/types.js';
|
|
13
|
-
import { strictSchemaToDbSchema } from './schema.js';
|
|
14
13
|
import { DbShared } from '../shared/DbBase.js';
|
|
15
14
|
import { setNativeSchema, setSchemaOnServer, writeSchemaFile, } from './schema.js';
|
|
16
15
|
import { resizeModifyDirtyRanges } from './resizeModifyDirtyRanges.js';
|
|
@@ -263,8 +262,8 @@ export class DbServer extends DbShared {
|
|
|
263
262
|
return this.schema.hash;
|
|
264
263
|
}
|
|
265
264
|
setSchemaOnServer(this, schema);
|
|
265
|
+
setNativeSchema(this, schema);
|
|
266
266
|
await writeSchemaFile(this, schema);
|
|
267
|
-
await setNativeSchema(this, schema);
|
|
268
267
|
process.nextTick(() => {
|
|
269
268
|
this.emit('schema', this.schema);
|
|
270
269
|
});
|