@based/db 0.0.1 → 0.0.3
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/jemalloc.h +468 -0
- package/dist/lib/darwin_aarch64/include/selva/selva_string.h +2 -0
- package/dist/lib/darwin_aarch64/libnode-v20.11.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.8.0.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/jemalloc.h +468 -0
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +2 -0
- package/dist/lib/linux_aarch64/libnode-v20.11.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/jemalloc.h +468 -0
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +2 -0
- package/dist/lib/linux_x86_64/libnode-v20.11.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.18.1.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.13.0.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/bitWise.d.ts +7 -0
- package/dist/src/client/bitWise.js +62 -0
- package/dist/src/client/modify/modify.js +5 -1
- package/dist/src/client/modify/text.d.ts +4 -2
- package/dist/src/client/modify/text.js +1 -2
- package/dist/src/client/modify/vector.d.ts +4 -0
- package/dist/src/client/modify/vector.js +44 -0
- package/dist/src/client/query/BasedDbQuery.d.ts +3 -1
- package/dist/src/client/query/BasedDbQuery.js +9 -7
- package/dist/src/client/query/BasedIterable.d.ts +2 -2
- package/dist/src/client/query/BasedIterable.js +10 -5
- package/dist/src/client/query/debug.js +4 -3
- package/dist/src/client/query/display.js +19 -4
- package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +16 -7
- package/dist/src/client/query/filter/filter.js +17 -4
- package/dist/src/client/query/filter/primitiveFilter.d.ts +2 -1
- package/dist/src/client/query/filter/primitiveFilter.js +2 -2
- package/dist/src/client/query/include/utils.js +1 -0
- package/dist/src/client/query/include/walk.js +1 -0
- package/dist/src/client/query/queryDef.js +2 -0
- package/dist/src/client/query/read/read.d.ts +2 -2
- package/dist/src/client/query/read/read.js +64 -38
- package/dist/src/client/query/subscription/index.js +3 -3
- package/dist/src/client/query/subscription/run.d.ts +1 -1
- package/dist/src/client/query/subscription/run.js +12 -2
- package/dist/src/client/query/toBuffer.js +3 -0
- package/dist/src/client/query/types.d.ts +2 -0
- package/dist/src/client/string.d.ts +3 -2
- package/dist/src/client/string.js +13 -7
- package/dist/src/native.d.ts +1 -1
- package/dist/src/native.js +2 -1
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/server/index.js +2 -1
- package/dist/src/server/schema/selvaBuffer.js +4 -3
- package/dist/src/server/schema/typeDef.js +4 -1
- package/dist/src/server/schema/types.d.ts +3 -0
- package/dist/src/server/schema/types.js +5 -0
- package/dist/src/server/worker.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Subscription } from './types.js';
|
|
2
2
|
import { DbClient } from '../../index.js';
|
|
3
|
-
export declare const resultsAreEqual: (a:
|
|
3
|
+
export declare const resultsAreEqual: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
4
4
|
export declare const runSubscription: (subscription: Subscription) => void;
|
|
5
5
|
export declare const startSubscription: (db: DbClient) => void;
|
|
@@ -16,6 +16,7 @@ export const resultsAreEqual = (a, b) => {
|
|
|
16
16
|
return false;
|
|
17
17
|
return true;
|
|
18
18
|
};
|
|
19
|
+
const EMPTY = new Uint8Array(Buffer.alloc(4));
|
|
19
20
|
export const runSubscription = (subscription) => {
|
|
20
21
|
if (!subscription.inProgress) {
|
|
21
22
|
subscription.inProgress = true;
|
|
@@ -29,7 +30,15 @@ export const runSubscription = (subscription) => {
|
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
32
|
subscription.inProgress = false;
|
|
32
|
-
|
|
33
|
+
let err = null;
|
|
34
|
+
let buf;
|
|
35
|
+
if (res instanceof Error) {
|
|
36
|
+
err = res;
|
|
37
|
+
buf = EMPTY;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
buf = res;
|
|
41
|
+
}
|
|
33
42
|
if (subscription.res) {
|
|
34
43
|
if (resultsAreEqual(subscription.res.result, buf)) {
|
|
35
44
|
return;
|
|
@@ -41,8 +50,9 @@ export const runSubscription = (subscription) => {
|
|
|
41
50
|
else {
|
|
42
51
|
subscription.res = new BasedQueryResponse(q.id, q.def, buf, performance.now() - d);
|
|
43
52
|
}
|
|
53
|
+
console.log('RUN ', subscription.subs.size);
|
|
44
54
|
subscription.subs.forEach((fn) => {
|
|
45
|
-
fn(subscription.res);
|
|
55
|
+
fn(subscription.res, err);
|
|
46
56
|
});
|
|
47
57
|
})
|
|
48
58
|
.catch((err) => {
|
|
@@ -224,6 +224,9 @@ export function defToBuffer(db, def) {
|
|
|
224
224
|
result.push(metaEdgeBuffer, ...edges);
|
|
225
225
|
}
|
|
226
226
|
// 8 byte crc 32
|
|
227
|
+
if (def.type === QueryDefType.Root) {
|
|
228
|
+
result.push(Buffer.from([def.lang]));
|
|
229
|
+
}
|
|
227
230
|
return result;
|
|
228
231
|
}
|
|
229
232
|
//# sourceMappingURL=toBuffer.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LangCode } from '@based/schema';
|
|
1
2
|
import { PropDef, PropDefEdge, SchemaTypeDef } from '../../server/schema/schema.js';
|
|
2
3
|
export type MainIncludes = {
|
|
3
4
|
[start: string]: [number, PropDef];
|
|
@@ -44,6 +45,7 @@ export type QueryDefSort = {
|
|
|
44
45
|
order: 0 | 1;
|
|
45
46
|
};
|
|
46
47
|
export type QueryDefShared = {
|
|
48
|
+
lang: LangCode;
|
|
47
49
|
filter: QueryDefFilter;
|
|
48
50
|
search: null | QueryDefSearch;
|
|
49
51
|
sort: null | QueryDefSort;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LangCode } from '@based/schema';
|
|
2
2
|
export declare const write: (buf: Buffer, value: string, offset: number, noCompression: boolean, lang?: LangCode) => number;
|
|
3
3
|
export declare const compress: (str: string) => Buffer;
|
|
4
|
-
export declare const decompress: (
|
|
5
|
-
export declare const read: (
|
|
4
|
+
export declare const decompress: (val: Uint8Array) => string;
|
|
5
|
+
export declare const read: (val: Uint8Array, offset: number, len: number) => string;
|
|
6
|
+
export declare const readUtf8: (val: Uint8Array, offset: number, len: number) => string;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import native from '../native.js';
|
|
2
|
+
import { readUint32 } from './bitWise.js';
|
|
3
|
+
const DECODER = new TextDecoder('utf-8');
|
|
4
|
+
// add encoder
|
|
2
5
|
// type 0 = no compression; 1 = deflate
|
|
3
6
|
// [lang] [type] [uncompressed size 4] [compressed string] [crc32]
|
|
4
7
|
// var cnt = 0
|
|
@@ -54,20 +57,23 @@ export const compress = (str) => {
|
|
|
54
57
|
tmpCompressBlock.copy(nBuffer, 0, 0, s);
|
|
55
58
|
return nBuffer;
|
|
56
59
|
};
|
|
57
|
-
export const decompress = (
|
|
58
|
-
return read(
|
|
60
|
+
export const decompress = (val) => {
|
|
61
|
+
return read(val, 0, val.length);
|
|
59
62
|
};
|
|
60
|
-
export const read = (
|
|
61
|
-
const type =
|
|
63
|
+
export const read = (val, offset, len) => {
|
|
64
|
+
const type = val[offset + 1];
|
|
62
65
|
if (type == 1) {
|
|
63
|
-
const origSize =
|
|
66
|
+
const origSize = readUint32(val, offset + 2);
|
|
64
67
|
const newBuffer = Buffer.allocUnsafe(origSize);
|
|
65
|
-
native.decompress(
|
|
68
|
+
native.decompress(Buffer.from(val), newBuffer, offset + 6, len - 6);
|
|
66
69
|
return newBuffer.toString('utf8');
|
|
67
70
|
}
|
|
68
71
|
else if (type == 0) {
|
|
69
|
-
return
|
|
72
|
+
return DECODER.decode(val.subarray(offset + 2, len + offset - 4));
|
|
70
73
|
}
|
|
71
74
|
return '';
|
|
72
75
|
};
|
|
76
|
+
export const readUtf8 = (val, offset, len) => {
|
|
77
|
+
return DECODER.decode(val.subarray(offset, len + offset));
|
|
78
|
+
};
|
|
73
79
|
//# sourceMappingURL=string.js.map
|
package/dist/src/native.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ declare const _default: {
|
|
|
4
4
|
externalFromInt(address: BigInt): any;
|
|
5
5
|
intFromExternal(external: any): BigInt;
|
|
6
6
|
modify: (data: Buffer, types: Buffer, dbCtx: any) => any;
|
|
7
|
-
getQueryBuf: (q: Buffer, dbCtx: any) =>
|
|
7
|
+
getQueryBuf: (q: Buffer, dbCtx: any) => ArrayBuffer | null;
|
|
8
8
|
start: (id: number) => any;
|
|
9
9
|
stop: (dbCtx: any) => any;
|
|
10
10
|
saveCommon: (path: string, dbCtx: any) => number;
|
package/dist/src/native.js
CHANGED
|
@@ -11,7 +11,7 @@ export declare class DbWorker {
|
|
|
11
11
|
resolvers: any[];
|
|
12
12
|
callback: (resolve: any) => void;
|
|
13
13
|
updateCtx(address: BigInt): Promise<void>;
|
|
14
|
-
getQueryBuf(buf: Buffer): Promise<
|
|
14
|
+
getQueryBuf(buf: Buffer): Promise<Uint8Array>;
|
|
15
15
|
}
|
|
16
16
|
type OnSchemaChange = (schema: StrictSchema) => void;
|
|
17
17
|
export declare class DbServer {
|
package/dist/src/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ALIAS, ALIASES, BINARY, BOOLEAN, CREATED, EMPTY_MICRO_BUFFER, ENUM, HLL, INT16, INT32, INT64, INT8, MICRO_BUFFER, NULL, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, UPDATED, VECTOR, WEAK_REFERENCE, WEAK_REFERENCES, } from './types.js';
|
|
2
2
|
const selvaTypeMap = [];
|
|
3
3
|
selvaTypeMap[NULL] = 0;
|
|
4
4
|
selvaTypeMap[TIMESTAMP] = 1;
|
|
@@ -25,13 +25,14 @@ selvaTypeMap[MICRO_BUFFER] = 17;
|
|
|
25
25
|
selvaTypeMap[ALIAS] = 18;
|
|
26
26
|
selvaTypeMap[ALIASES] = 19;
|
|
27
27
|
selvaTypeMap[BINARY] = 11;
|
|
28
|
+
selvaTypeMap[VECTOR] = 17;
|
|
28
29
|
function sepPropCount(props) {
|
|
29
30
|
return props.filter((prop) => prop.separate).length;
|
|
30
31
|
}
|
|
31
32
|
const propDefBuffer = (schema, prop, isEdge) => {
|
|
32
33
|
const type = prop.typeIndex;
|
|
33
34
|
const selvaType = selvaTypeMap[type];
|
|
34
|
-
if (prop.len && type === MICRO_BUFFER) {
|
|
35
|
+
if (prop.len && (type === MICRO_BUFFER || type === VECTOR)) {
|
|
35
36
|
const buf = Buffer.allocUnsafe(3);
|
|
36
37
|
buf[0] = selvaType;
|
|
37
38
|
buf.writeUint16LE(prop.len, 1);
|
|
@@ -80,7 +81,7 @@ export function schemaToSelvaBuffer(schema) {
|
|
|
80
81
|
let refFields = 0;
|
|
81
82
|
for (const f of props) {
|
|
82
83
|
if (f.separate) {
|
|
83
|
-
if (f.typeIndex ===
|
|
84
|
+
if (f.typeIndex === REFERENCE || f.typeIndex === REFERENCES) {
|
|
84
85
|
refFields++;
|
|
85
86
|
}
|
|
86
87
|
rest.push(f);
|
|
@@ -140,7 +140,10 @@ export const createSchemaTypeDef = (typeName, type, parsed, result = {
|
|
|
140
140
|
else if (isPropType('text', schemaProp)) {
|
|
141
141
|
stringFields++;
|
|
142
142
|
}
|
|
143
|
-
|
|
143
|
+
else if (isPropType('vector', schemaProp)) {
|
|
144
|
+
len = 4 * schemaProp.size;
|
|
145
|
+
}
|
|
146
|
+
const isseparate = len === 0 || isPropType('vector', schemaProp);
|
|
144
147
|
if (isseparate) {
|
|
145
148
|
result.cnt++;
|
|
146
149
|
}
|
|
@@ -23,6 +23,8 @@ export declare const MICRO_BUFFER = 17;
|
|
|
23
23
|
export declare const ALIAS = 18;
|
|
24
24
|
export declare const ALIASES = 19;
|
|
25
25
|
export declare const BINARY = 25;
|
|
26
|
+
export declare const ID = 26;
|
|
27
|
+
export declare const VECTOR = 27;
|
|
26
28
|
export declare const TYPE_INDEX_MAP: {
|
|
27
29
|
alias: number;
|
|
28
30
|
aliases: number;
|
|
@@ -46,6 +48,7 @@ export declare const TYPE_INDEX_MAP: {
|
|
|
46
48
|
id: number;
|
|
47
49
|
binary: number;
|
|
48
50
|
hll: number;
|
|
51
|
+
vector: number;
|
|
49
52
|
};
|
|
50
53
|
export type InternalSchemaProp = keyof typeof TYPE_INDEX_MAP;
|
|
51
54
|
export type TypeIndex = (typeof TYPE_INDEX_MAP)[InternalSchemaProp];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// WARN: The following type codes are used in js and zig but selva has its own typing.
|
|
1
2
|
export const NULL = 0;
|
|
2
3
|
export const TIMESTAMP = 1;
|
|
3
4
|
export const CREATED = 2;
|
|
@@ -23,6 +24,8 @@ export const MICRO_BUFFER = 17;
|
|
|
23
24
|
export const ALIAS = 18;
|
|
24
25
|
export const ALIASES = 19;
|
|
25
26
|
export const BINARY = 25;
|
|
27
|
+
export const ID = 26;
|
|
28
|
+
export const VECTOR = 27;
|
|
26
29
|
export const TYPE_INDEX_MAP = {
|
|
27
30
|
alias: ALIAS,
|
|
28
31
|
aliases: ALIASES,
|
|
@@ -46,6 +49,7 @@ export const TYPE_INDEX_MAP = {
|
|
|
46
49
|
id: NULL,
|
|
47
50
|
binary: BINARY,
|
|
48
51
|
hll: HLL,
|
|
52
|
+
vector: VECTOR,
|
|
49
53
|
};
|
|
50
54
|
export const SIZE_MAP = {
|
|
51
55
|
timestamp: 8, // 64bit
|
|
@@ -71,6 +75,7 @@ export const SIZE_MAP = {
|
|
|
71
75
|
aliases: 0,
|
|
72
76
|
id: 4,
|
|
73
77
|
binary: 0,
|
|
78
|
+
vector: 0, // separate
|
|
74
79
|
};
|
|
75
80
|
const reverseMap = {};
|
|
76
81
|
for (const k in TYPE_INDEX_MAP) {
|