@based/db 0.0.30 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +565 -3
- package/dist/lib/darwin_aarch64/include/selva/db.h +3 -2
- package/dist/lib/darwin_aarch64/include/selva/fields.h +10 -7
- package/dist/lib/darwin_aarch64/include/selva/types.h +3 -1
- 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/libselva.dylib +0 -0
- package/dist/src/client/flushModify.d.ts +1 -1
- package/dist/src/client/flushModify.js +5 -4
- package/dist/src/client/index.d.ts +3 -2
- package/dist/src/client/modify/binary.js +1 -1
- package/dist/src/client/modify/cardinality.js +1 -1
- package/dist/src/client/modify/references/appendEdgeRefs.js +3 -0
- package/dist/src/client/modify/references/edge.js +6 -0
- package/dist/src/client/modify/references/getEdgeSize.js +1 -1
- package/dist/src/client/modify/string.js +10 -4
- package/dist/src/client/modify/text.js +1 -9
- package/dist/src/client/modify/types.d.ts +1 -0
- package/dist/src/client/modify/types.js +1 -0
- package/dist/src/client/modify/upsert.js +33 -21
- package/dist/src/client/query/BasedDbQuery.js +1 -1
- package/dist/src/client/query/BasedIterable.d.ts +2 -2
- package/dist/src/client/query/BasedIterable.js +7 -1
- package/dist/src/client/query/aggregates/aggregation.d.ts +4 -0
- package/dist/src/client/query/aggregates/aggregation.js +12 -0
- package/dist/src/client/query/aggregation.d.ts +1 -1
- package/dist/src/client/query/debug.js +3 -2
- package/dist/src/client/query/display.js +1 -1
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +1 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +1 -1
- package/dist/src/client/query/filter/parseFilterValue.js +1 -2
- package/dist/src/client/query/queryDef.js +2 -2
- package/dist/src/client/query/read/read.js +4 -14
- package/dist/src/client/query/registerQuery.js +1 -1
- package/dist/src/client/query/search/index.d.ts +1 -1
- package/dist/src/client/query/search/index.js +1 -1
- package/dist/src/client/query/sort.d.ts +1 -1
- package/dist/src/client/query/toBuffer.js +11 -15
- package/dist/src/client/query/types.d.ts +7 -0
- package/dist/src/client/query/types.js +8 -0
- package/dist/src/client/query/validation.d.ts +1 -1
- package/dist/src/client/query/validation.js +4 -5
- package/dist/src/client/string.js +1 -3
- package/dist/src/client/xxHash64.d.ts +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +31 -3
- package/dist/src/native.d.ts +1 -2
- package/dist/src/native.js +2 -5
- package/dist/src/server/csmt/draw-dot.d.ts +3 -1
- package/dist/src/server/csmt/draw-dot.js +7 -2
- package/dist/src/server/csmt/match.d.ts +1 -1
- package/dist/src/server/csmt/memebership-proof.d.ts +1 -1
- package/dist/src/server/csmt/tree-utils.d.ts +4 -4
- package/dist/src/server/csmt/tree.d.ts +1 -1
- package/dist/src/server/csmt/tree.js +1 -1
- package/dist/src/server/csmt/types.d.ts +10 -10
- package/dist/src/server/dbHash.d.ts +1 -1
- package/dist/src/server/dbHash.js +1 -1
- package/dist/src/server/index.d.ts +8 -4
- package/dist/src/server/index.js +28 -13
- package/dist/src/server/migrate/worker.js +11 -0
- package/dist/src/server/save.js +4 -6
- package/dist/src/server/start.js +17 -11
- package/dist/src/server/tree.d.ts +1 -1
- package/dist/src/server/tree.js +2 -2
- package/dist/src/utils.d.ts +0 -10
- package/dist/src/utils.js +0 -152
- package/package.json +3 -3
- package/dist/lib/darwin_aarch64/include/selva/xxhash64.h +0 -23
- 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/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 -322
- 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/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 -417
- package/dist/lib/linux_aarch64/include/selva/endian.h +0 -301
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +0 -23
- 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 -378
- package/dist/lib/linux_aarch64/include/selva/find.h +0 -47
- package/dist/lib/linux_aarch64/include/selva/history.h +0 -64
- package/dist/lib/linux_aarch64/include/selva/hll.h +0 -81
- package/dist/lib/linux_aarch64/include/selva/lpf.h +0 -28
- 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/queue_r.h +0 -190
- 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 -674
- 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/timestamp.h +0 -25
- package/dist/lib/linux_aarch64/include/selva/traverse.h +0 -65
- package/dist/lib/linux_aarch64/include/selva/types.h +0 -104
- package/dist/lib/linux_aarch64/include/selva/vector.h +0 -35
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -13
- package/dist/lib/linux_aarch64/include/selva/xxhash64.h +0 -23
- package/dist/lib/linux_aarch64/include/selva_error.h +0 -137
- package/dist/lib/linux_aarch64/include/selva_lang_code.h +0 -157
- 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-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_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 -322
- 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/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 -417
- 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 -23
- 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 -378
- package/dist/lib/linux_x86_64/include/selva/find.h +0 -47
- package/dist/lib/linux_x86_64/include/selva/history.h +0 -64
- package/dist/lib/linux_x86_64/include/selva/hll.h +0 -81
- package/dist/lib/linux_x86_64/include/selva/lpf.h +0 -28
- 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/queue_r.h +0 -190
- 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 -674
- 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/timestamp.h +0 -25
- package/dist/lib/linux_x86_64/include/selva/traverse.h +0 -65
- package/dist/lib/linux_x86_64/include/selva/types.h +0 -104
- package/dist/lib/linux_x86_64/include/selva/vector.h +0 -35
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -13
- package/dist/lib/linux_x86_64/include/selva/xxhash64.h +0 -23
- package/dist/lib/linux_x86_64/include/selva_error.h +0 -137
- package/dist/lib/linux_x86_64/include/selva_lang_code.h +0 -157
- 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-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/lib/linux_x86_64/libxxhash.so.0 +0 -0
- package/dist/src/client/query/subscription/markers.d.ts +0 -10
- package/dist/src/client/query/subscription/markers.js +0 -213
- package/dist/src/client/query/subscription/run.d.ts +0 -5
- package/dist/src/client/query/subscription/run.js +0 -76
|
@@ -93,10 +93,11 @@ export const flushBuffer = (db) => {
|
|
|
93
93
|
const lastIds = {};
|
|
94
94
|
const data = ctx.getData(lastIds);
|
|
95
95
|
const resCtx = ctx.ctx;
|
|
96
|
-
|
|
97
|
-
flushPromise = db.hooks
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
// pass from flushModify
|
|
97
|
+
flushPromise = db.hooks
|
|
98
|
+
.flushModify(data)
|
|
99
|
+
.then(({ offsets, dbWriteTime }) => {
|
|
100
|
+
db.writeTime += dbWriteTime ?? 0;
|
|
100
101
|
resCtx.offsets = offsets;
|
|
101
102
|
for (const typeId in lastIds) {
|
|
102
103
|
if (typeId in offsets) {
|
|
@@ -12,6 +12,7 @@ export type DbClientHooks = {
|
|
|
12
12
|
setSchema(schema: StrictSchema, fromStart?: boolean, transformFns?: TransformFns): Promise<DbServer['schema']>;
|
|
13
13
|
flushModify(buf: Uint8Array): Promise<{
|
|
14
14
|
offsets: Record<number, number>;
|
|
15
|
+
dbWriteTime?: number;
|
|
15
16
|
}>;
|
|
16
17
|
getQueryBuf(buf: Uint8Array): Promise<Uint8Array>;
|
|
17
18
|
subscribe(q: BasedDbQuery, onData: OnData, onError?: OnError): OnClose;
|
|
@@ -39,7 +40,7 @@ export declare class DbClient {
|
|
|
39
40
|
isDraining: boolean;
|
|
40
41
|
modifyCtx: ModifyCtx;
|
|
41
42
|
maxModifySize: number;
|
|
42
|
-
upserting: Map<
|
|
43
|
+
upserting: Map<number, {
|
|
43
44
|
o: Record<string, any>;
|
|
44
45
|
p: Promise<number | ModifyRes>;
|
|
45
46
|
}>;
|
|
@@ -54,7 +55,7 @@ export declare class DbClient {
|
|
|
54
55
|
update(type: string, value: Record<string, any> & {
|
|
55
56
|
id: number | ModifyRes;
|
|
56
57
|
}, opts?: ModifyOpts): ModifyRes;
|
|
57
|
-
update(value:
|
|
58
|
+
update(value: Record<string, any>, opts?: ModifyOpts): ModifyRes;
|
|
58
59
|
upsert(type: string, obj: Record<string, any>, opts?: ModifyOpts): Promise<any>;
|
|
59
60
|
delete(type: string, id: number | ModifyRes): ModifyRes;
|
|
60
61
|
expire(type: string, id: number | ModifyRes, seconds: number): void;
|
|
@@ -2,7 +2,7 @@ import { RANGE_ERR, CREATE } from './types.js';
|
|
|
2
2
|
import { ModifyError } from './ModifyRes.js';
|
|
3
3
|
import { setCursor } from './setCursor.js';
|
|
4
4
|
import { xxHash64 } from '../xxHash64.js';
|
|
5
|
-
import { ENCODER } from '
|
|
5
|
+
import { ENCODER } from '@saulx/utils';
|
|
6
6
|
export function writeHll(value, ctx, def, t, parentId, modifyOp) {
|
|
7
7
|
if (!value) {
|
|
8
8
|
return new ModifyError(t, value);
|
|
@@ -106,8 +106,14 @@ export function writeEdges(t, ref, ctx) {
|
|
|
106
106
|
// add null
|
|
107
107
|
if (typeof value !== 'number') {
|
|
108
108
|
if (value instanceof ModifyState) {
|
|
109
|
+
if (value.error) {
|
|
110
|
+
return value.error;
|
|
111
|
+
}
|
|
109
112
|
value = value.tmpId;
|
|
110
113
|
}
|
|
114
|
+
else if (typeof value === 'object' && value !== null && value.id) {
|
|
115
|
+
value = value.id;
|
|
116
|
+
}
|
|
111
117
|
else {
|
|
112
118
|
return new ModifyError(edge, value);
|
|
113
119
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ENCODER } from '../../index.js';
|
|
2
|
-
import { CREATE, UPDATE, RANGE_ERR, DELETE, } from './types.js';
|
|
2
|
+
import { CREATE, UPDATE, RANGE_ERR, DELETE, DELETE_TEXT_FIELD, } from './types.js';
|
|
3
3
|
import { ModifyError } from './ModifyRes.js';
|
|
4
4
|
import { setCursor } from './setCursor.js';
|
|
5
5
|
import { write } from '../string.js';
|
|
@@ -8,13 +8,19 @@ import { write } from '../string.js';
|
|
|
8
8
|
// add compression handling for edge fields
|
|
9
9
|
export function writeString(lang, value, ctx, def, t, parentId, modifyOp) {
|
|
10
10
|
const isBuffer = value instanceof Uint8Array;
|
|
11
|
-
if (value ===
|
|
11
|
+
if (value === null || value === '') {
|
|
12
12
|
if (modifyOp === UPDATE) {
|
|
13
|
-
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ +
|
|
13
|
+
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 2 > ctx.max) {
|
|
14
14
|
return RANGE_ERR;
|
|
15
15
|
}
|
|
16
16
|
setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
|
|
17
|
-
|
|
17
|
+
if (lang === 0) {
|
|
18
|
+
ctx.buf[ctx.len++] = DELETE;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
ctx.buf[ctx.len++] = DELETE_TEXT_FIELD;
|
|
22
|
+
ctx.buf[ctx.len++] = lang;
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
26
|
else {
|
|
@@ -13,7 +13,7 @@ export function writeText(value, ctx, def, t, res, parentId, modifyOp) {
|
|
|
13
13
|
}
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
if ((value && typeof value !== 'object') || value === null) {
|
|
16
|
+
if ((value && typeof value !== 'object') || value === null || value === '') {
|
|
17
17
|
let locale = res.locale;
|
|
18
18
|
if (!locale) {
|
|
19
19
|
// TODO: Add def lang option...
|
|
@@ -25,10 +25,6 @@ export function writeText(value, ctx, def, t, res, parentId, modifyOp) {
|
|
|
25
25
|
if (!def.seperateTextSort.localeToIndex.has(locale)) {
|
|
26
26
|
return new ModifyError(t, locale, 'Invalid locale');
|
|
27
27
|
}
|
|
28
|
-
if (value == null) {
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
value = '';
|
|
31
|
-
}
|
|
32
28
|
const err = writeString(res.locale, value, ctx, def, t, res.tmpId, modifyOp);
|
|
33
29
|
if (modifyOp === CREATE) {
|
|
34
30
|
const index = t.prop * (def.localeSize + 1);
|
|
@@ -47,10 +43,6 @@ export function writeText(value, ctx, def, t, res, parentId, modifyOp) {
|
|
|
47
43
|
return new ModifyError(t, lang, 'Invalid locale');
|
|
48
44
|
}
|
|
49
45
|
let s = value[lang];
|
|
50
|
-
if (s == null) {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
s = '';
|
|
53
|
-
}
|
|
54
46
|
const err = writeString(langC[1], s, ctx, def, t, res.tmpId, modifyOp);
|
|
55
47
|
if (err) {
|
|
56
48
|
return err;
|
|
@@ -12,6 +12,7 @@ export declare const DECREMENT = 13;
|
|
|
12
12
|
export declare const EXPIRE = 14;
|
|
13
13
|
export declare const ADD_EMPTY_SORT_TEXT = 15;
|
|
14
14
|
export declare const ADD_EMPTY_SORT = 7;
|
|
15
|
+
export declare const DELETE_TEXT_FIELD = 16;
|
|
15
16
|
export declare const SWITCH_TYPE = 2;
|
|
16
17
|
export declare const SWITCH_FIELD = 0;
|
|
17
18
|
export declare const SWITCH_ID_CREATE = 9;
|
|
@@ -10,6 +10,7 @@ export const DECREMENT = 13;
|
|
|
10
10
|
export const EXPIRE = 14;
|
|
11
11
|
export const ADD_EMPTY_SORT_TEXT = 15;
|
|
12
12
|
export const ADD_EMPTY_SORT = 7;
|
|
13
|
+
export const DELETE_TEXT_FIELD = 16;
|
|
13
14
|
export const SWITCH_TYPE = 2;
|
|
14
15
|
export const SWITCH_FIELD = 0;
|
|
15
16
|
export const SWITCH_ID_CREATE = 9;
|
|
@@ -1,41 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let
|
|
5
|
-
let id = type;
|
|
1
|
+
import { deepMerge } from '@saulx/utils';
|
|
2
|
+
import { ALIAS, isPropDef } from '@based/schema/def';
|
|
3
|
+
const filterAliases = (obj, tree) => {
|
|
4
|
+
let aliases;
|
|
6
5
|
for (const key in obj) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const def = tree[key];
|
|
7
|
+
if (def === undefined) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (isPropDef(def)) {
|
|
11
|
+
if (def.typeIndex === ALIAS) {
|
|
12
|
+
aliases ??= {};
|
|
13
|
+
aliases[key] = obj[key];
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const nested = filterAliases(obj[key], def);
|
|
18
|
+
if (nested) {
|
|
19
|
+
aliases ??= {};
|
|
20
|
+
aliases[key] = nested;
|
|
14
21
|
}
|
|
15
22
|
}
|
|
16
23
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
return aliases;
|
|
25
|
+
};
|
|
26
|
+
export async function upsert(db, type, obj, opts) {
|
|
27
|
+
const tree = db.schemaTypesParsed[type].tree;
|
|
28
|
+
const aliases = filterAliases(obj, tree);
|
|
29
|
+
const q = db.query(type, aliases);
|
|
30
|
+
q.register();
|
|
31
|
+
if (db.upserting.has(q.id)) {
|
|
32
|
+
const store = db.upserting.get(q.id);
|
|
33
|
+
deepMerge(store.o, obj);
|
|
24
34
|
return store.p;
|
|
25
35
|
}
|
|
26
36
|
const store = {
|
|
27
37
|
o: obj,
|
|
28
38
|
p: q.get().then((res) => {
|
|
29
|
-
db.upserting.delete(id);
|
|
39
|
+
db.upserting.delete(q.id);
|
|
30
40
|
if (res.length === 0) {
|
|
31
41
|
return db.create(type, store.o, opts);
|
|
32
42
|
}
|
|
33
43
|
else {
|
|
34
|
-
|
|
44
|
+
const obj = res.toObject();
|
|
45
|
+
const id = Array.isArray(obj) ? obj[0].id : obj.id;
|
|
46
|
+
return db.update(type, id, store.o, opts);
|
|
35
47
|
}
|
|
36
48
|
}),
|
|
37
49
|
};
|
|
38
|
-
db.upserting.set(id, store);
|
|
50
|
+
db.upserting.set(q.id, store);
|
|
39
51
|
return store.p;
|
|
40
52
|
}
|
|
41
53
|
//# sourceMappingURL=upsert.js.map
|
|
@@ -11,7 +11,7 @@ import { langCodesMap } from '@based/schema';
|
|
|
11
11
|
import { convertFilter } from './filter/convertFilter.js';
|
|
12
12
|
import { validateLocale, validateRange } from './validation.js';
|
|
13
13
|
import { DEF_RANGE_PROP_LIMIT } from './thresholds.js';
|
|
14
|
-
import { concatUint8Arr } from '
|
|
14
|
+
import { concatUint8Arr } from '@saulx/utils';
|
|
15
15
|
export class QueryBranch {
|
|
16
16
|
db;
|
|
17
17
|
def;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
2
|
import { QueryDef } from './types.js';
|
|
3
|
-
import { Item } from './query.js';
|
|
4
3
|
import { size, time, inspectData } from './display.js';
|
|
5
4
|
export { time, size, inspectData };
|
|
6
5
|
export declare class BasedQueryResponse {
|
|
@@ -10,11 +9,12 @@ export declare class BasedQueryResponse {
|
|
|
10
9
|
end: number;
|
|
11
10
|
id: number;
|
|
12
11
|
constructor(id: number, def: QueryDef, result: Uint8Array, execTime: number, end?: number);
|
|
12
|
+
get version(): number;
|
|
13
13
|
get size(): number;
|
|
14
14
|
[inspect.custom](depth: number): string;
|
|
15
15
|
debug(): this;
|
|
16
16
|
node(index?: number): any;
|
|
17
|
-
[Symbol.iterator](): Generator<Partial<Item>, void, unknown>;
|
|
17
|
+
[Symbol.iterator](): Generator<Partial<import("./query.js").Item>, void, unknown>;
|
|
18
18
|
inspect(depth?: number, raw?: boolean): this;
|
|
19
19
|
forEach(fn: (item: any, key: number) => void): void;
|
|
20
20
|
map(fn: (item: any, key: number) => any): any[];
|
|
@@ -2,8 +2,11 @@ import { inspect } from 'node:util';
|
|
|
2
2
|
import picocolors from 'picocolors';
|
|
3
3
|
import { debug, resultToObject, readAllFields } from './query.js';
|
|
4
4
|
import { size, time, inspectData, defHasId, displayTarget } from './display.js';
|
|
5
|
-
import { readFloatLE, readUint32 } from '
|
|
5
|
+
import { readFloatLE, readUint32 } from '@saulx/utils';
|
|
6
6
|
export { time, size, inspectData };
|
|
7
|
+
const BITS_FOR_BYTE_LEN = 21;
|
|
8
|
+
const FACTOR = 2 ** BITS_FOR_BYTE_LEN;
|
|
9
|
+
const MASK_B = FACTOR - 1;
|
|
7
10
|
export class BasedQueryResponse {
|
|
8
11
|
result;
|
|
9
12
|
def;
|
|
@@ -17,6 +20,9 @@ export class BasedQueryResponse {
|
|
|
17
20
|
this.execTime = execTime;
|
|
18
21
|
this.end = end;
|
|
19
22
|
}
|
|
23
|
+
get version() {
|
|
24
|
+
return (this.checksum >>> 0) * FACTOR + (this.result.byteLength & MASK_B);
|
|
25
|
+
}
|
|
20
26
|
get size() {
|
|
21
27
|
return this.result.length;
|
|
22
28
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const createAggFlagBuffer = (aggregation) => {
|
|
2
|
+
const buf = new Uint8Array(1);
|
|
3
|
+
buf[0] = aggregation;
|
|
4
|
+
return buf;
|
|
5
|
+
};
|
|
6
|
+
export const count = (def) => {
|
|
7
|
+
def.aggregation = 4 /* AggFlag.COUNT */;
|
|
8
|
+
};
|
|
9
|
+
export const sum = (def) => {
|
|
10
|
+
def.aggregation = 11 /* AggFlag.SUM */;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=aggregation.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { QueryDef, AggFlag } from './types.js';
|
|
2
|
-
export declare const createAggFlagBuffer: (aggregation: AggFlag) => Uint8Array
|
|
2
|
+
export declare const createAggFlagBuffer: (aggregation: AggFlag) => Uint8Array<ArrayBuffer>;
|
|
3
3
|
export declare const count: (def: QueryDef) => void;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import picocolors from 'picocolors';
|
|
2
2
|
import { isPropDef, REVERSE_TYPE_INDEX_MAP } from '@based/schema/def';
|
|
3
3
|
import { QueryDefType } from './types.js';
|
|
4
|
-
import { concatUint8Arr } from '
|
|
4
|
+
import { concatUint8Arr } from '@saulx/utils';
|
|
5
5
|
export const debugQueryDef = (q, returnIt) => {
|
|
6
6
|
const loggableObject = { type: 'bla', schema: null };
|
|
7
7
|
const f = (a) => {
|
|
8
8
|
if (a === null) {
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
|
-
if (a instanceof Buffer) {
|
|
11
|
+
if (a instanceof Buffer) {
|
|
12
|
+
// RFE is this necessary?
|
|
12
13
|
return new Uint8Array(a);
|
|
13
14
|
}
|
|
14
15
|
if (a instanceof Uint8Array) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import picocolors from 'picocolors';
|
|
2
2
|
import { BINARY, CARDINALITY, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, } from '@based/schema/def';
|
|
3
|
-
import { ENCODER } from '
|
|
3
|
+
import { ENCODER } from '@saulx/utils';
|
|
4
4
|
const decimals = (v) => ~~(v * 100) / 100;
|
|
5
5
|
const sizeCalc = (size) => {
|
|
6
6
|
if (size > 1e6) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BINARY, STRING, REFERENCES, } from '@based/schema/def';
|
|
2
2
|
import { ALIGNMENT_NOT_SET, EQUAL, MODE_AND_FIXED, MODE_DEFAULT, MODE_OR_FIXED, } from './types.js';
|
|
3
3
|
import { parseFilterValue } from './parseFilterValue.js';
|
|
4
|
-
import { ENCODER } from '
|
|
4
|
+
import { ENCODER } from '@saulx/utils';
|
|
5
5
|
export const writeFixed = (prop, buf, value, size, offset) => {
|
|
6
6
|
if (prop.typeIndex === BINARY || prop.typeIndex === STRING) {
|
|
7
7
|
if (typeof value === 'string') {
|
|
@@ -2,7 +2,7 @@ import { ALIAS, TEXT, VECTOR } from '@based/schema/def';
|
|
|
2
2
|
import { EQUAL, EQUAL_CRC32, HAS, HAS_TO_LOWER_CASE, LIKE, MODE_DEFAULT_VAR, MODE_OR_VAR, getVectorFn, } from './types.js';
|
|
3
3
|
import { createFixedFilterBuffer } from './createFixedFilterBuffer.js';
|
|
4
4
|
import { crc32 } from '../../crc32.js';
|
|
5
|
-
import { ENCODER, concatUint8Arr } from '
|
|
5
|
+
import { ENCODER, concatUint8Arr } from '@saulx/utils';
|
|
6
6
|
const DEFAULT_SCORE = new Uint8Array(new Float32Array([0.5]).buffer);
|
|
7
7
|
const parseValue = (value, prop, ctx, lang) => {
|
|
8
8
|
let val = value;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TIMESTAMP, ENUM, BOOLEAN, STRING, BINARY, TEXT, } from '@based/schema/def';
|
|
2
2
|
import { crc32 } from '../../crc32.js';
|
|
3
|
-
import { convertToTimestamp } from '@saulx/utils';
|
|
4
|
-
import { ENCODER } from '../../../utils.js';
|
|
3
|
+
import { convertToTimestamp, ENCODER } from '@saulx/utils';
|
|
5
4
|
// -------------------------------------------
|
|
6
5
|
// conditions normal
|
|
7
6
|
// field, [size 2]
|
|
@@ -21,7 +21,7 @@ const createEmptySharedDef = (skipValidation) => {
|
|
|
21
21
|
},
|
|
22
22
|
sort: null,
|
|
23
23
|
references: new Map(),
|
|
24
|
-
aggregation:
|
|
24
|
+
aggregation: 0 /* AggFlag.NONE */,
|
|
25
25
|
};
|
|
26
26
|
return q;
|
|
27
27
|
};
|
|
@@ -51,7 +51,7 @@ export const createQueryDef = (db, type, target, skipValidation) => {
|
|
|
51
51
|
q.range.limit = t.ids.length;
|
|
52
52
|
}
|
|
53
53
|
else if (t.alias) {
|
|
54
|
-
t.resolvedAlias = validateAlias(t.alias
|
|
54
|
+
t.resolvedAlias = validateAlias(q, t.alias);
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
q.range.limit = DEF_RANGE_PROP_LIMIT;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, JSON, CARDINALITY, } from '@based/schema/def';
|
|
2
2
|
import { QueryDefType } from '../types.js';
|
|
3
3
|
import { read, readUtf8 } from '../../string.js';
|
|
4
|
-
import { readDoubleLE, readFloatLE, readInt16, readInt32, readUint16, readUint32, } from '
|
|
4
|
+
import { readDoubleLE, readFloatLE, readInt16, readInt32, readUint16, readUint32, } from '@saulx/utils';
|
|
5
5
|
import { inverseLangMap } from '@based/schema';
|
|
6
6
|
import { READ_EDGE, READ_ID, READ_REFERENCE, READ_REFERENCES, READ_AGGREGATION, CREATE_AGGREGATION, } from '../types.js';
|
|
7
7
|
const addField = (p, value, item, defaultOnly = false, lang = 0) => {
|
|
@@ -47,14 +47,7 @@ const getEmptyField = (p, item) => {
|
|
|
47
47
|
else {
|
|
48
48
|
for (; i < len; i++) {
|
|
49
49
|
const field = path[i];
|
|
50
|
-
|
|
51
|
-
if (!(field in select)) {
|
|
52
|
-
select = select[field] = {};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
select = select[field] ?? (select[field] = {});
|
|
57
|
-
}
|
|
50
|
+
select = select[field] ?? (select[field] = {});
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
53
|
return select;
|
|
@@ -132,7 +125,7 @@ const readMain = (q, result, offset, item) => {
|
|
|
132
125
|
return i - offset;
|
|
133
126
|
};
|
|
134
127
|
const handleUndefinedProps = (id, q, item) => {
|
|
135
|
-
if (q.aggregation
|
|
128
|
+
if (q.aggregation === 0 /* AggFlag.NONE */ || q.aggregation === null) {
|
|
136
129
|
for (const k in q.include.propsRead) {
|
|
137
130
|
if (q.include.propsRead[k] !== id) {
|
|
138
131
|
// Only relevant for seperate props
|
|
@@ -145,8 +138,7 @@ const handleUndefinedProps = (id, q, item) => {
|
|
|
145
138
|
const lang = q.include.langTextFields.get(prop.prop).codes;
|
|
146
139
|
if (lang.has(0)) {
|
|
147
140
|
for (const locale in q.schema.locales) {
|
|
148
|
-
if (
|
|
149
|
-
// console.log('???', locale, prop.default)
|
|
141
|
+
if (lan[locale] == undefined) {
|
|
150
142
|
lan[locale] = prop.default[locale] || '';
|
|
151
143
|
}
|
|
152
144
|
}
|
|
@@ -164,8 +156,6 @@ const handleUndefinedProps = (id, q, item) => {
|
|
|
164
156
|
addField(prop, prop.default, item);
|
|
165
157
|
}
|
|
166
158
|
else if (prop.typeIndex === TEXT) {
|
|
167
|
-
// q.lang
|
|
168
|
-
// console.log('???')
|
|
169
159
|
addField(prop, '', item);
|
|
170
160
|
}
|
|
171
161
|
else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import native from '../../native.js';
|
|
2
|
-
import { concatUint8Arr } from '
|
|
2
|
+
import { concatUint8Arr } from '@saulx/utils';
|
|
3
3
|
import { defToBuffer } from './toBuffer.js';
|
|
4
4
|
import { handleErrors } from './validation.js';
|
|
5
5
|
export const registerQuery = (q) => {
|
|
@@ -5,4 +5,4 @@ export type Search = string[] | {
|
|
|
5
5
|
} | string;
|
|
6
6
|
export declare const vectorSearch: (def: QueryDef, q: ArrayBufferView, field: string, opts: Omit<FilterOpts, "lowerCase">) => void;
|
|
7
7
|
export declare const search: (def: QueryDef, q: string, s?: Search) => void;
|
|
8
|
-
export declare const searchToBuffer: (search: QueryDefSearch) => Uint8Array
|
|
8
|
+
export declare const searchToBuffer: (search: QueryDefSearch) => Uint8Array<ArrayBuffer>;
|
|
@@ -2,7 +2,7 @@ import { langCodesMap } from '@based/schema';
|
|
|
2
2
|
import { STRING, TEXT, VECTOR } from '@based/schema/def';
|
|
3
3
|
import { getVectorFn } from '../filter/types.js';
|
|
4
4
|
import { searchDoesNotExist, searchIncorrecQueryValue, searchIncorrectType, } from '../validation.js';
|
|
5
|
-
import { ENCODER, concatUint8Arr } from '
|
|
5
|
+
import { ENCODER, concatUint8Arr } from '@saulx/utils';
|
|
6
6
|
// vector
|
|
7
7
|
export const vectorSearch = (def, q, field, opts) => {
|
|
8
8
|
let prop = def.props[field];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { QueryDef, QueryDefSort } from './types.js';
|
|
2
|
-
export declare const createSortBuffer: (sort: QueryDefSort) => Uint8Array
|
|
2
|
+
export declare const createSortBuffer: (sort: QueryDefSort) => Uint8Array<ArrayBuffer>;
|
|
3
3
|
export declare const sort: (def: QueryDef, field: string, order?: "asc" | "desc") => void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createSortBuffer } from './sort.js';
|
|
2
|
-
import { QueryDefType } from './types.js';
|
|
2
|
+
import { QueryDefType, QueryType } from './types.js';
|
|
3
3
|
import { includeToBuffer } from './include/toBuffer.js';
|
|
4
4
|
import { filterToBuffer } from './query.js';
|
|
5
5
|
import { searchToBuffer } from './search/index.js';
|
|
6
6
|
import { createAggFlagBuffer } from './aggregation.js';
|
|
7
|
-
import { ENCODER } from '
|
|
7
|
+
import { ENCODER } from '@saulx/utils';
|
|
8
8
|
const byteSize = (arr) => {
|
|
9
9
|
return arr.reduce((a, b) => {
|
|
10
10
|
return a + b.byteLength;
|
|
@@ -20,6 +20,7 @@ export function defToBuffer(db, def) {
|
|
|
20
20
|
def.errors.push(...ref.errors);
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
+
const aggregation = createAggFlagBuffer(def.aggregation || 0 /* AggFlag.NONE */);
|
|
23
24
|
let edges;
|
|
24
25
|
let edgesSize = 0;
|
|
25
26
|
if (def.edges) {
|
|
@@ -49,7 +50,7 @@ export function defToBuffer(db, def) {
|
|
|
49
50
|
const aliasStr = ENCODER.encode(alias.value);
|
|
50
51
|
const aliasLen = aliasStr.byteLength;
|
|
51
52
|
const buf = new Uint8Array(8 + filterSize + aliasLen);
|
|
52
|
-
buf[0] =
|
|
53
|
+
buf[0] = QueryType.alias;
|
|
53
54
|
buf[1] = def.schema.idUint8[0];
|
|
54
55
|
buf[2] = def.schema.idUint8[1];
|
|
55
56
|
buf[3] = alias.def.prop;
|
|
@@ -65,7 +66,7 @@ export function defToBuffer(db, def) {
|
|
|
65
66
|
}
|
|
66
67
|
else if (def.target.id) {
|
|
67
68
|
const buf = new Uint8Array(9 + filterSize);
|
|
68
|
-
buf[0] =
|
|
69
|
+
buf[0] = QueryType.id;
|
|
69
70
|
buf[1] = def.schema.idUint8[0];
|
|
70
71
|
buf[2] = def.schema.idUint8[1];
|
|
71
72
|
buf[3] = def.target.id;
|
|
@@ -86,10 +87,6 @@ export function defToBuffer(db, def) {
|
|
|
86
87
|
sort = createSortBuffer(def.sort);
|
|
87
88
|
sortSize = sort.byteLength;
|
|
88
89
|
}
|
|
89
|
-
let aggregation;
|
|
90
|
-
if (def.aggregation) {
|
|
91
|
-
aggregation = createAggFlagBuffer(def.aggregation);
|
|
92
|
-
}
|
|
93
90
|
if (def.target.ids) {
|
|
94
91
|
if (!sortSize &&
|
|
95
92
|
(def.range.offset || def.range.limit < def.target.ids.length)) {
|
|
@@ -97,7 +94,7 @@ export function defToBuffer(db, def) {
|
|
|
97
94
|
}
|
|
98
95
|
const idsSize = def.target.ids.length * 4;
|
|
99
96
|
const buf = new Uint8Array(21 + idsSize + filterSize + sortSize + searchSize);
|
|
100
|
-
buf[0] =
|
|
97
|
+
buf[0] = QueryType.ids;
|
|
101
98
|
buf[1] = def.schema.idUint8[0];
|
|
102
99
|
buf[2] = def.schema.idUint8[1];
|
|
103
100
|
buf[3] = idsSize;
|
|
@@ -134,7 +131,7 @@ export function defToBuffer(db, def) {
|
|
|
134
131
|
}
|
|
135
132
|
else {
|
|
136
133
|
const buf = new Uint8Array(18 + filterSize + sortSize + searchSize);
|
|
137
|
-
buf[0] =
|
|
134
|
+
buf[0] = QueryType.default;
|
|
138
135
|
buf[1] = def.schema.idUint8[0];
|
|
139
136
|
buf[2] = def.schema.idUint8[1];
|
|
140
137
|
buf[3] = def.range.offset;
|
|
@@ -160,9 +157,7 @@ export function defToBuffer(db, def) {
|
|
|
160
157
|
if (searchSize) {
|
|
161
158
|
buf.set(search, 17 + filterSize + sortSize);
|
|
162
159
|
}
|
|
163
|
-
|
|
164
|
-
buf.set(aggregation, 17 + filterSize + sortSize + searchSize);
|
|
165
|
-
}
|
|
160
|
+
buf.set(aggregation, 17 + filterSize + sortSize + searchSize);
|
|
166
161
|
result.push(buf);
|
|
167
162
|
}
|
|
168
163
|
}
|
|
@@ -175,8 +170,8 @@ export function defToBuffer(db, def) {
|
|
|
175
170
|
}
|
|
176
171
|
const sortSize = sort?.byteLength ?? 0;
|
|
177
172
|
const modsSize = filterSize + sortSize;
|
|
178
|
-
const meta = new Uint8Array(modsSize + 10 + 8);
|
|
179
|
-
const sz = size + 7 + modsSize + 8;
|
|
173
|
+
const meta = new Uint8Array(modsSize + 10 + 8 + 1);
|
|
174
|
+
const sz = size + 7 + modsSize + 8 + 1;
|
|
180
175
|
meta[0] = 254;
|
|
181
176
|
meta[1] = sz;
|
|
182
177
|
meta[2] = sz >>> 8;
|
|
@@ -201,6 +196,7 @@ export function defToBuffer(db, def) {
|
|
|
201
196
|
meta[15 + modsSize] = def.schema.idUint8[0];
|
|
202
197
|
meta[15 + 1 + modsSize] = def.schema.idUint8[1];
|
|
203
198
|
meta[15 + 2 + modsSize] = def.target.propDef.prop;
|
|
199
|
+
meta[15 + 3 + modsSize] = aggregation[0];
|
|
204
200
|
result.push(meta);
|
|
205
201
|
}
|
|
206
202
|
else if (def.type === QueryDefType.Reference) {
|
|
@@ -6,6 +6,13 @@ export type MainIncludes = {
|
|
|
6
6
|
[start: string]: [number, PropDef];
|
|
7
7
|
};
|
|
8
8
|
export type IncludeTreeArr = (string | PropDef | IncludeTreeArr)[];
|
|
9
|
+
export declare enum QueryType {
|
|
10
|
+
id = 0,
|
|
11
|
+
ids = 1,
|
|
12
|
+
default = 2,
|
|
13
|
+
alias = 3,
|
|
14
|
+
aggregates = 4
|
|
15
|
+
}
|
|
9
16
|
declare enum QueryDefType {
|
|
10
17
|
Edge = 1,
|
|
11
18
|
Reference = 2,
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export var QueryType;
|
|
2
|
+
(function (QueryType) {
|
|
3
|
+
QueryType[QueryType["id"] = 0] = "id";
|
|
4
|
+
QueryType[QueryType["ids"] = 1] = "ids";
|
|
5
|
+
QueryType[QueryType["default"] = 2] = "default";
|
|
6
|
+
QueryType[QueryType["alias"] = 3] = "alias";
|
|
7
|
+
QueryType[QueryType["aggregates"] = 4] = "aggregates";
|
|
8
|
+
})(QueryType || (QueryType = {}));
|
|
1
9
|
var QueryDefType;
|
|
2
10
|
(function (QueryDefType) {
|
|
3
11
|
QueryDefType[QueryDefType["Edge"] = 1] = "Edge";
|
|
@@ -71,7 +71,7 @@ export declare const includeDoesNotExist: (def: QueryDef, field: string) => void
|
|
|
71
71
|
export declare const includeLangDoesNotExist: (def: QueryDef, field: string) => void;
|
|
72
72
|
export declare const validateLocale: (def: QueryDef, lang: string) => void;
|
|
73
73
|
export declare const validateSort: (def: QueryDef, field: string, orderInput?: "asc" | "desc") => QueryDef["sort"];
|
|
74
|
-
export declare const validateAlias: (alias: QueryByAliasObj, path
|
|
74
|
+
export declare const validateAlias: (def: QueryDef, alias: QueryByAliasObj, path?: string) => {
|
|
75
75
|
def: PropDef;
|
|
76
76
|
value: string;
|
|
77
77
|
};
|