@based/db 0.0.21 → 0.0.23
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 +10 -10
- package/dist/lib/darwin_aarch64/include/selva/types.h +9 -18
- 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/types.h +9 -18
- 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_x86_64/include/selva/types.h +9 -18
- 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/src/client/bitWise.d.ts +0 -1
- package/dist/src/client/bitWise.js +0 -10
- package/dist/src/client/{operations.d.ts → flushModify.d.ts} +4 -4
- package/dist/src/client/{operations.js → flushModify.js} +39 -15
- package/dist/src/client/index.d.ts +10 -6
- package/dist/src/client/index.js +12 -4
- package/dist/src/client/modify/ModifyRes.d.ts +2 -8
- package/dist/src/client/modify/ModifyRes.js +23 -29
- package/dist/src/client/modify/alias.d.ts +1 -1
- package/dist/src/client/modify/alias.js +5 -2
- package/dist/src/client/modify/binary.d.ts +1 -1
- package/dist/src/client/modify/binary.js +1 -1
- package/dist/src/client/modify/cardinality.d.ts +2 -2
- package/dist/src/client/modify/cardinality.js +7 -5
- package/dist/src/client/modify/create.js +10 -5
- package/dist/src/client/modify/delete.d.ts +3 -1
- package/dist/src/client/modify/delete.js +12 -5
- package/dist/src/client/modify/expire.js +1 -1
- package/dist/src/client/modify/fixed.js +11 -4
- package/dist/src/client/modify/references/appendRefs.d.ts +4 -0
- package/dist/src/client/modify/references/appendRefs.js +27 -0
- package/dist/src/client/modify/references/edge.d.ts +0 -1
- package/dist/src/client/modify/references/edge.js +191 -71
- package/dist/src/client/modify/references/getEdgeSize.d.ts +3 -0
- package/dist/src/client/modify/references/getEdgeSize.js +27 -0
- package/dist/src/client/modify/references/reference.js +40 -26
- package/dist/src/client/modify/references/references.js +18 -6
- package/dist/src/client/modify/string.js +2 -1
- package/dist/src/client/modify/types.d.ts +1 -0
- package/dist/src/client/modify/types.js +1 -0
- package/dist/src/client/modify/update.js +3 -4
- package/dist/src/client/modify/upsert.js +1 -0
- package/dist/src/client/modify/vector.js +0 -2
- package/dist/src/client/query/BasedDbQuery.d.ts +4 -3
- package/dist/src/client/query/BasedDbQuery.js +12 -3
- package/dist/src/client/query/aggregationFn.d.ts +3 -0
- package/dist/src/client/query/aggregationFn.js +9 -0
- package/dist/src/client/query/debug.js +2 -6
- package/dist/src/client/query/display.js +5 -2
- package/dist/src/client/query/filter/createFixedFilterBuffer.d.ts +2 -2
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +34 -26
- package/dist/src/client/query/filter/createReferenceFilter.d.ts +1 -1
- package/dist/src/client/query/filter/createReferenceFilter.js +17 -7
- package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +1 -1
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +45 -22
- package/dist/src/client/query/filter/filter.d.ts +1 -1
- package/dist/src/client/query/filter/filter.js +5 -0
- package/dist/src/client/query/filter/parseFilterValue.js +1 -1
- package/dist/src/client/query/filter/toBuffer.d.ts +2 -2
- package/dist/src/client/query/filter/toBuffer.js +16 -9
- package/dist/src/client/query/include/props.js +18 -1
- package/dist/src/client/query/include/toBuffer.d.ts +1 -1
- package/dist/src/client/query/include/toBuffer.js +22 -12
- package/dist/src/client/query/include/walk.js +2 -1
- package/dist/src/client/query/query.d.ts +1 -0
- package/dist/src/client/query/query.js +1 -0
- package/dist/src/client/query/queryDef.js +2 -1
- package/dist/src/client/query/read/read.d.ts +2 -1
- package/dist/src/client/query/read/read.js +95 -62
- package/dist/src/client/query/registerQuery.d.ts +1 -1
- package/dist/src/client/query/registerQuery.js +2 -1
- package/dist/src/client/query/search/index.d.ts +1 -1
- package/dist/src/client/query/search/index.js +56 -24
- package/dist/src/client/query/subscription/markers.js +2 -1
- package/dist/src/client/query/toBuffer.d.ts +1 -1
- package/dist/src/client/query/toBuffer.js +80 -32
- package/dist/src/client/query/types.d.ts +25 -3
- package/dist/src/client/query/types.js +6 -0
- package/dist/src/client/query/validation.js +1 -1
- package/dist/src/client/string.d.ts +1 -1
- package/dist/src/client/string.js +1 -2
- package/dist/src/client/xxHash64.d.ts +1 -1
- package/dist/src/index.d.ts +4 -3
- package/dist/src/index.js +20 -11
- package/dist/src/native.d.ts +8 -13
- package/dist/src/native.js +9 -31
- package/dist/src/server/dbHash.d.ts +5 -0
- package/dist/src/server/dbHash.js +27 -0
- package/dist/src/server/index.d.ts +10 -10
- package/dist/src/server/index.js +54 -35
- package/dist/src/server/migrate/index.js +1 -1
- package/dist/src/server/migrate/worker.js +2 -2
- package/dist/src/server/save.d.ts +1 -1
- package/dist/src/server/save.js +10 -10
- package/dist/src/server/start.js +4 -2
- package/dist/src/server/tree.d.ts +1 -1
- package/dist/src/server/tree.js +1 -1
- package/dist/src/utils.d.ts +3 -0
- package/dist/src/utils.js +23 -5
- package/package.json +3 -2
- package/dist/src/client/query/read/types.d.ts +0 -4
- package/dist/src/client/query/read/types.js +0 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModifyError, ModifyState } from '../ModifyRes.js';
|
|
2
2
|
import { setCursor } from '../setCursor.js';
|
|
3
3
|
import { DELETE, RANGE_ERR } from '../types.js';
|
|
4
|
-
import {
|
|
4
|
+
import { writeEdges } from './edge.js';
|
|
5
5
|
import { dbUpdateFromUpsert } from './references.js';
|
|
6
6
|
function writeRef(id, ctx, schema, def, parentId, modifyOp, hasEdges, isTmpId) {
|
|
7
7
|
if (ctx.len + 16 > ctx.max) {
|
|
@@ -29,36 +29,46 @@ function singleReferenceEdges(ref, ctx, schema, def, parentId, modifyOp) {
|
|
|
29
29
|
if (id.error) {
|
|
30
30
|
return id.error;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const resolvedId = id.getId();
|
|
33
|
+
if (resolvedId) {
|
|
34
|
+
id = resolvedId;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
isTmpId = !true;
|
|
38
|
+
id = id.tmpId;
|
|
39
|
+
}
|
|
34
40
|
}
|
|
35
41
|
}
|
|
42
|
+
// TODO SINGLE REF
|
|
36
43
|
if (id > 0) {
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
if (def.edgesSeperateCnt === 0 && def.edgeMainLen === 0) {
|
|
45
|
+
// edgeMainLen, edgesSeperateCnt
|
|
39
46
|
return writeRef(id, ctx, schema, def, parentId, modifyOp, false, isTmpId);
|
|
40
47
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
else {
|
|
49
|
+
let err = writeRef(id, ctx, schema, def, parentId, modifyOp, true, isTmpId);
|
|
50
|
+
if (err) {
|
|
51
|
+
return err;
|
|
52
|
+
}
|
|
53
|
+
// def.edgeMainLen
|
|
54
|
+
// const edgesLen = getEdgeSize(def, ref)
|
|
55
|
+
// edgeMainLen can be done better
|
|
56
|
+
// TODO REOMVE - SEEMS REDUNDANT
|
|
57
|
+
if (ctx.len + 4 > ctx.max) {
|
|
58
|
+
return RANGE_ERR;
|
|
59
|
+
}
|
|
60
|
+
let sizepos = ctx.len;
|
|
61
|
+
ctx.len += 4;
|
|
62
|
+
err = writeEdges(def, ref, ctx);
|
|
63
|
+
if (err) {
|
|
64
|
+
return err;
|
|
65
|
+
}
|
|
66
|
+
let size = ctx.len - sizepos;
|
|
67
|
+
ctx.buf[sizepos++] = size;
|
|
68
|
+
ctx.buf[sizepos++] = size >>>= 8;
|
|
69
|
+
ctx.buf[sizepos++] = size >>>= 8;
|
|
70
|
+
ctx.buf[sizepos] = size >>>= 8;
|
|
53
71
|
}
|
|
54
|
-
let size = ctx.len - sizepos;
|
|
55
|
-
ctx.buf[sizepos++] = size;
|
|
56
|
-
ctx.buf[sizepos++] = size >>>= 8;
|
|
57
|
-
ctx.buf[sizepos++] = size >>>= 8;
|
|
58
|
-
ctx.buf[sizepos] = size >>>= 8;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return new ModifyError(def, ref);
|
|
62
72
|
}
|
|
63
73
|
}
|
|
64
74
|
export function writeReference(value, ctx, schema, def, res, modifyOp) {
|
|
@@ -76,7 +86,11 @@ export function writeReference(value, ctx, schema, def, res, modifyOp) {
|
|
|
76
86
|
if (value.error) {
|
|
77
87
|
return value.error;
|
|
78
88
|
}
|
|
79
|
-
|
|
89
|
+
const id = value.getId();
|
|
90
|
+
if (id) {
|
|
91
|
+
return writeRef(id, ctx, schema, def, res.tmpId, modifyOp, false, false);
|
|
92
|
+
}
|
|
93
|
+
return writeRef(value.tmpId, ctx, schema, def, res.tmpId, modifyOp, false, true);
|
|
80
94
|
}
|
|
81
95
|
else if (typeof value === 'object' && value !== null) {
|
|
82
96
|
if (def.edges) {
|
|
@@ -136,16 +136,28 @@ function appendRefs(def, ctx, modifyOp, refs, op, remaining) {
|
|
|
136
136
|
if (ref.error) {
|
|
137
137
|
return ref.error;
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const resolvedId = ref.getId();
|
|
140
|
+
if (resolvedId) {
|
|
141
|
+
id = resolvedId;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
id = ref.tmpId;
|
|
145
|
+
isTmpId = true;
|
|
146
|
+
}
|
|
141
147
|
}
|
|
142
148
|
else if (ref.id instanceof ModifyState) {
|
|
143
149
|
if (ref.id.error) {
|
|
144
150
|
return ref.id.error;
|
|
145
151
|
}
|
|
146
|
-
|
|
152
|
+
const resolvedId = ref.id.getId();
|
|
153
|
+
if (resolvedId) {
|
|
154
|
+
id = resolvedId;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
id = ref.id.tmpId;
|
|
158
|
+
isTmpId = true;
|
|
159
|
+
}
|
|
147
160
|
index = ref.$index;
|
|
148
|
-
isTmpId = !ref.id.resolved;
|
|
149
161
|
}
|
|
150
162
|
else if (ref.id > 0) {
|
|
151
163
|
id = ref.id;
|
|
@@ -258,10 +270,10 @@ function putRefs(def, ctx, modifyOp, refs, op) {
|
|
|
258
270
|
if (ref.error) {
|
|
259
271
|
return ref.error;
|
|
260
272
|
}
|
|
261
|
-
|
|
273
|
+
ref = ref.getId();
|
|
274
|
+
if (!ref) {
|
|
262
275
|
break;
|
|
263
276
|
}
|
|
264
|
-
ref = ref.tmpId;
|
|
265
277
|
ctx.buf[ctx.len++] = ref;
|
|
266
278
|
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
267
279
|
ctx.buf[ctx.len++] = ref >>>= 8;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ENCODER } from '../../index.js';
|
|
1
2
|
import { CREATE, UPDATE, RANGE_ERR, DELETE, } from './types.js';
|
|
2
3
|
import { ModifyError } from './ModifyRes.js';
|
|
3
4
|
import { setCursor } from './setCursor.js';
|
|
@@ -23,7 +24,7 @@ export function writeString(lang, value, ctx, def, t, parentId, modifyOp) {
|
|
|
23
24
|
else {
|
|
24
25
|
let size = isBuffer
|
|
25
26
|
? value.byteLength
|
|
26
|
-
:
|
|
27
|
+
: ENCODER.encode(value).byteLength + 6;
|
|
27
28
|
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 11 + size > ctx.max) {
|
|
28
29
|
// +10 OR +11, teh original check was +20 but
|
|
29
30
|
// there are 10 addtional bytes in this scope
|
|
@@ -2,6 +2,7 @@ import { LangName } from '@based/schema';
|
|
|
2
2
|
import { ModifyError } from './ModifyRes.js';
|
|
3
3
|
export declare const CREATE = 3;
|
|
4
4
|
export declare const UPDATE = 6;
|
|
5
|
+
export declare const UPDATE_PARTIAL = 5;
|
|
5
6
|
export declare const DELETE = 11;
|
|
6
7
|
export declare const DELETE_SORT_INDEX = 4;
|
|
7
8
|
export declare const DELETE_NODE = 10;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MICRO_BUFFER } from '@based/schema/def';
|
|
2
|
-
import { startDrain, flushBuffer } from '../
|
|
2
|
+
import { startDrain, flushBuffer } from '../flushModify.js';
|
|
3
3
|
import { setCursor } from './setCursor.js';
|
|
4
4
|
import { modify } from './modify.js';
|
|
5
5
|
import { ModifyState } from './ModifyRes.js';
|
|
@@ -71,9 +71,8 @@ export const update = (db, type, id, obj, opts) => {
|
|
|
71
71
|
flushBuffer(db);
|
|
72
72
|
return update(db, type, id, obj, opts);
|
|
73
73
|
}
|
|
74
|
-
res.error = err
|
|
75
|
-
|
|
76
|
-
return res;
|
|
74
|
+
// res.error = err
|
|
75
|
+
throw err;
|
|
77
76
|
}
|
|
78
77
|
if (!db.isDraining) {
|
|
79
78
|
startDrain(db);
|
|
@@ -26,7 +26,6 @@ export function writeVector(value, ctx, schema, t, parentId, modifyOp) {
|
|
|
26
26
|
if (size === 0) {
|
|
27
27
|
if (modifyOp === UPDATE) {
|
|
28
28
|
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 1 > ctx.max) {
|
|
29
|
-
// TODO ???
|
|
30
29
|
return RANGE_ERR;
|
|
31
30
|
}
|
|
32
31
|
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
@@ -35,7 +34,6 @@ export function writeVector(value, ctx, schema, t, parentId, modifyOp) {
|
|
|
35
34
|
}
|
|
36
35
|
else {
|
|
37
36
|
if (ctx.len + 11 /* SIZE.DEFAULT_CURSOR */ + 5 + size > ctx.max) {
|
|
38
|
-
// TODO ???
|
|
39
37
|
return RANGE_ERR;
|
|
40
38
|
}
|
|
41
39
|
setCursor(ctx, schema, t.prop, t.typeIndex, parentId, modifyOp);
|
|
@@ -17,9 +17,10 @@ export declare class QueryBranch<T> {
|
|
|
17
17
|
filterBatch(f: FilterAst): this;
|
|
18
18
|
search(query: string, ...fields: Search[]): T;
|
|
19
19
|
search(query: ArrayBufferView, field: string, opts?: Omit<FilterOpts, 'lowerCase'>): T;
|
|
20
|
+
count(): T;
|
|
20
21
|
or(fn: FilterBranchFn): T;
|
|
21
22
|
or(field: string, operator?: Operator | boolean, value?: any, opts?: FilterOpts): T;
|
|
22
|
-
range(
|
|
23
|
+
range(start: number, end?: number): T;
|
|
23
24
|
include(...fields: (string | BranchInclude | string[])[]): T;
|
|
24
25
|
}
|
|
25
26
|
export declare class BasedDbReferenceQuery extends QueryBranch<BasedDbReferenceQuery> {
|
|
@@ -35,10 +36,10 @@ export declare class BasedDbQuery extends QueryBranch<BasedDbQuery> {
|
|
|
35
36
|
constructor(db: DbClient, type: string, id?: QueryByAliasObj | number | Uint32Array | (QueryByAliasObj | number)[], skipValidation?: boolean);
|
|
36
37
|
id: number;
|
|
37
38
|
get(): GetPromise;
|
|
38
|
-
buffer:
|
|
39
|
+
buffer: Uint8Array;
|
|
39
40
|
register(): void;
|
|
40
41
|
locale(locale: LangName): this;
|
|
41
42
|
subscribe(onData: OnData, onError?: OnError): import("./subscription/types.js").OnClose;
|
|
42
43
|
_getSync(dbCtxExternal: any): BasedQueryResponse;
|
|
43
|
-
toBuffer():
|
|
44
|
+
toBuffer(): Uint8Array;
|
|
44
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createQueryDef, QueryDefType, filter, sort, defToBuffer, filterOr, isAlias, includeField, includeFields, } from './query.js';
|
|
1
|
+
import { createQueryDef, QueryDefType, filter, sort, defToBuffer, filterOr, isAlias, includeField, includeFields, count, } from './query.js';
|
|
2
2
|
import { BasedQueryResponse } from './BasedIterable.js';
|
|
3
3
|
import { createOrGetEdgeRefQueryDef, createOrGetRefQueryDef, } from './include/utils.js';
|
|
4
4
|
import { FilterBranch } from './filter/FilterBranch.js';
|
|
@@ -11,6 +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 '../../utils.js';
|
|
14
15
|
export class QueryBranch {
|
|
15
16
|
db;
|
|
16
17
|
def;
|
|
@@ -93,6 +94,11 @@ export class QueryBranch {
|
|
|
93
94
|
// @ts-ignore
|
|
94
95
|
return this;
|
|
95
96
|
}
|
|
97
|
+
count() {
|
|
98
|
+
count(this.def);
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
96
102
|
or(field, operator, value, opts) {
|
|
97
103
|
if (typeof field === 'function') {
|
|
98
104
|
const f = new FilterBranch(this.db, filterOr(this.db, this.def, [], this.def.filter), this.def);
|
|
@@ -108,7 +114,9 @@ export class QueryBranch {
|
|
|
108
114
|
// @ts-ignore
|
|
109
115
|
return this;
|
|
110
116
|
}
|
|
111
|
-
range(
|
|
117
|
+
range(start, end = DEF_RANGE_PROP_LIMIT) {
|
|
118
|
+
const offset = start;
|
|
119
|
+
const limit = end - start;
|
|
112
120
|
if (validateRange(this.def, offset, limit)) {
|
|
113
121
|
this.def.range.offset = 0;
|
|
114
122
|
this.def.range.limit = DEF_RANGE_PROP_LIMIT;
|
|
@@ -216,6 +224,7 @@ export class BasedDbQuery extends QueryBranch {
|
|
|
216
224
|
return;
|
|
217
225
|
}
|
|
218
226
|
const d = performance.now();
|
|
227
|
+
await this.db.isModified();
|
|
219
228
|
const res = await this.db.hooks.getQueryBuf(buf);
|
|
220
229
|
if (res instanceof Error) {
|
|
221
230
|
reject(res);
|
|
@@ -258,7 +267,7 @@ export class BasedDbQuery extends QueryBranch {
|
|
|
258
267
|
includeField(this.def, '*');
|
|
259
268
|
}
|
|
260
269
|
const b = defToBuffer(this.db, this.def);
|
|
261
|
-
return
|
|
270
|
+
return concatUint8Arr(b);
|
|
262
271
|
}
|
|
263
272
|
}
|
|
264
273
|
//# sourceMappingURL=BasedDbQuery.js.map
|
|
@@ -1,18 +1,14 @@
|
|
|
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 '../../utils.js';
|
|
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
|
-
|
|
12
|
-
// // will be changed
|
|
13
|
-
// return 'basedNode'
|
|
14
|
-
// }
|
|
15
|
-
if (a instanceof Buffer) {
|
|
11
|
+
if (a instanceof Buffer) { // RFE is this necessary?
|
|
16
12
|
return new Uint8Array(a);
|
|
17
13
|
}
|
|
18
14
|
if (a instanceof Uint8Array) {
|
|
@@ -1,5 +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 '../../utils.js';
|
|
3
4
|
const decimals = (v) => ~~(v * 100) / 100;
|
|
4
5
|
const sizeCalc = (size) => {
|
|
5
6
|
if (size > 1e6) {
|
|
@@ -38,16 +39,18 @@ export const prettyPrintVal = (v, type) => {
|
|
|
38
39
|
if (type === BINARY) {
|
|
39
40
|
const nr = 12;
|
|
40
41
|
const isLarger = v.length > nr;
|
|
42
|
+
// RFE Doesn't slice make a new alloc? subarray would be probably sufficient here.
|
|
41
43
|
const x = [...v.slice(0, nr)].map((v) => {
|
|
42
44
|
return `${v}`.padStart(3, '0') + ' ';
|
|
43
45
|
});
|
|
44
46
|
return (picocolors.blue(x.join('')) +
|
|
45
47
|
(isLarger ? picocolors.dim('... ') : '') +
|
|
46
|
-
picocolors.italic(picocolors.dim(`${~~((
|
|
48
|
+
picocolors.italic(picocolors.dim(`${~~((v.byteLength / 1e3) * 100) / 100}kb`)));
|
|
47
49
|
}
|
|
48
50
|
if (type === STRING || type === TEXT) {
|
|
49
51
|
if (v.length > 50) {
|
|
50
|
-
const
|
|
52
|
+
const byteLength = ENCODER.encode(v).byteLength;
|
|
53
|
+
const chars = picocolors.italic(picocolors.dim(`${~~((byteLength / 1e3) * 100) / 100}kb`));
|
|
51
54
|
v =
|
|
52
55
|
v.slice(0, 50).replace(/\n/g, '\\n ') +
|
|
53
56
|
picocolors.dim('...') +
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { FilterCtx } from './types.js';
|
|
3
|
-
export declare const writeFixed: (prop: PropDef | PropDefEdge, buf:
|
|
4
|
-
export declare const createFixedFilterBuffer: (prop: PropDef | PropDefEdge, size: number, ctx: FilterCtx, value: any, sort: boolean) =>
|
|
3
|
+
export declare const writeFixed: (prop: PropDef | PropDefEdge, buf: Uint8Array, value: any, size: number, offset: number) => void;
|
|
4
|
+
export declare const createFixedFilterBuffer: (prop: PropDef | PropDefEdge, size: number, ctx: FilterCtx, value: any, sort: boolean) => Uint8Array;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { BINARY, STRING, REFERENCES,
|
|
1
|
+
import { BINARY, STRING, REFERENCES, } from '@based/schema/def';
|
|
2
2
|
import { EQUAL, MODE_AND_FIXED, MODE_DEFAULT, MODE_OR_FIXED, } from './types.js';
|
|
3
3
|
import { parseFilterValue } from './parseFilterValue.js';
|
|
4
|
+
import { ENCODER } from '../../../utils.js';
|
|
4
5
|
// -------------------------------------------
|
|
5
6
|
// conditions normal
|
|
6
7
|
// field, [size 2]
|
|
@@ -17,8 +18,8 @@ import { parseFilterValue } from './parseFilterValue.js';
|
|
|
17
18
|
export const writeFixed = (prop, buf, value, size, offset) => {
|
|
18
19
|
if (prop.typeIndex === BINARY || prop.typeIndex === STRING) {
|
|
19
20
|
if (typeof value === 'string') {
|
|
20
|
-
const
|
|
21
|
-
buf[offset] =
|
|
21
|
+
const { written } = ENCODER.encodeInto(value, buf.subarray(offset + 1));
|
|
22
|
+
buf[offset] = written;
|
|
22
23
|
}
|
|
23
24
|
else if (value instanceof Uint8Array) {
|
|
24
25
|
buf.set(value, offset);
|
|
@@ -31,25 +32,22 @@ export const writeFixed = (prop, buf, value, size, offset) => {
|
|
|
31
32
|
buf[offset] = value;
|
|
32
33
|
}
|
|
33
34
|
else {
|
|
34
|
-
if (size === 8) {
|
|
35
|
-
buf.
|
|
36
|
-
|
|
37
|
-
else if (propIsSigned(prop)) {
|
|
38
|
-
if (size === 4) {
|
|
39
|
-
buf.writeInt32LE(value, offset);
|
|
40
|
-
}
|
|
41
|
-
else if (size === 2) {
|
|
42
|
-
buf.writeInt16LE(value, offset);
|
|
43
|
-
}
|
|
44
|
-
else if (size === 1) {
|
|
45
|
-
buf[offset] = value;
|
|
46
|
-
}
|
|
35
|
+
if (size === 8) { // RFE no int64 for u?
|
|
36
|
+
const view = new DataView(buf.buffer, buf.byteOffset);
|
|
37
|
+
view.setFloat64(offset, value, true);
|
|
47
38
|
}
|
|
48
39
|
else if (size === 4) {
|
|
49
|
-
buf
|
|
40
|
+
buf[offset] = value;
|
|
41
|
+
buf[offset + 1] = value >>> 8;
|
|
42
|
+
buf[offset + 2] = value >>> 16;
|
|
43
|
+
buf[offset + 3] = value >>> 24;
|
|
50
44
|
}
|
|
51
45
|
else if (size === 2) {
|
|
52
|
-
buf
|
|
46
|
+
buf[offset] = value;
|
|
47
|
+
buf[offset + 1] = value >>> 8;
|
|
48
|
+
}
|
|
49
|
+
else if (size === 1) {
|
|
50
|
+
buf[offset] = value;
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
};
|
|
@@ -63,23 +61,31 @@ export const createFixedFilterBuffer = (prop, size, ctx, value, sort) => {
|
|
|
63
61
|
if (Array.isArray(value)) {
|
|
64
62
|
// [or = 1] [size 2] [start 2] [op], [repeat 2], value[size] value[size] value[size]
|
|
65
63
|
const len = value.length;
|
|
66
|
-
buf =
|
|
64
|
+
buf = new Uint8Array(10 + len * size);
|
|
67
65
|
buf[0] = ctx.type;
|
|
68
66
|
buf[1] =
|
|
69
67
|
prop.typeIndex === REFERENCES && ctx.operation === EQUAL
|
|
70
68
|
? MODE_AND_FIXED
|
|
71
69
|
: MODE_OR_FIXED;
|
|
72
70
|
buf[2] = prop.typeIndex;
|
|
73
|
-
buf
|
|
74
|
-
buf
|
|
71
|
+
buf[3] = size;
|
|
72
|
+
buf[4] = size >>> 8;
|
|
73
|
+
buf[5] = start;
|
|
74
|
+
buf[6] = start >>> 8;
|
|
75
75
|
buf[7] = ctx.operation;
|
|
76
76
|
// buf[7] = prop.typeIndex
|
|
77
|
-
buf
|
|
77
|
+
buf[8] = len;
|
|
78
|
+
buf[9] = len >>> 8;
|
|
78
79
|
if (sort) {
|
|
79
80
|
value = new Uint32Array(value.map((v) => parseFilterValue(prop, v)));
|
|
80
81
|
value.sort();
|
|
81
82
|
for (let i = 0; i < len; i++) {
|
|
82
|
-
|
|
83
|
+
const off = 10 + i * size;
|
|
84
|
+
const val = value[i];
|
|
85
|
+
buf[off] = val;
|
|
86
|
+
buf[off + 1] = val >>> 8;
|
|
87
|
+
buf[off + 2] = val >>> 16;
|
|
88
|
+
buf[off + 3] = val >>> 24;
|
|
83
89
|
}
|
|
84
90
|
}
|
|
85
91
|
else {
|
|
@@ -90,12 +96,14 @@ export const createFixedFilterBuffer = (prop, size, ctx, value, sort) => {
|
|
|
90
96
|
}
|
|
91
97
|
else {
|
|
92
98
|
// [or = 0] [size 2] [start 2], [op], value[size]
|
|
93
|
-
buf =
|
|
99
|
+
buf = new Uint8Array(8 + size);
|
|
94
100
|
buf[0] = ctx.type;
|
|
95
101
|
buf[1] = MODE_DEFAULT;
|
|
96
102
|
buf[2] = prop.typeIndex;
|
|
97
|
-
buf
|
|
98
|
-
buf
|
|
103
|
+
buf[3] = size;
|
|
104
|
+
buf[4] = size >>> 8;
|
|
105
|
+
buf[5] = start;
|
|
106
|
+
buf[6] = start >>> 8;
|
|
99
107
|
buf[7] = ctx.operation;
|
|
100
108
|
writeFixed(prop, buf, parseFilterValue(prop, value), size, 8);
|
|
101
109
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { FilterCtx } from './types.js';
|
|
3
|
-
export declare const createReferenceFilter: (prop: PropDef | PropDefEdge, ctx: FilterCtx, value: any) =>
|
|
3
|
+
export declare const createReferenceFilter: (prop: PropDef | PropDefEdge, ctx: FilterCtx, value: any) => Uint8Array;
|
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import { MODE_REFERENCE } from './types.js';
|
|
2
2
|
export const createReferenceFilter = (prop, ctx, value) => {
|
|
3
|
-
let buf;
|
|
4
3
|
const len = Array.isArray(value) ? value.length : 1;
|
|
5
|
-
buf =
|
|
4
|
+
const buf = new Uint8Array(11 + len * 8);
|
|
6
5
|
buf[0] = ctx.type;
|
|
7
6
|
buf[1] = MODE_REFERENCE;
|
|
8
7
|
buf[2] = prop.typeIndex;
|
|
9
|
-
buf
|
|
10
|
-
buf
|
|
8
|
+
buf[3] = 8;
|
|
9
|
+
buf[4] = 8 >>> 8;
|
|
10
|
+
buf[5] = len;
|
|
11
|
+
buf[6] = len >>> 8;
|
|
11
12
|
buf[7] = ctx.operation;
|
|
12
13
|
// buf[7] = prop.typeIndex
|
|
13
14
|
// REF TYPE (only 1 exists now...)
|
|
14
15
|
buf[8] = 0;
|
|
15
|
-
buf
|
|
16
|
+
buf[9] = prop.inverseTypeId;
|
|
17
|
+
buf[10] = prop.inverseTypeId >>> 8;
|
|
16
18
|
if (Array.isArray(value)) {
|
|
17
19
|
for (let i = 0; i < len; i++) {
|
|
18
|
-
|
|
20
|
+
let off = 11 + i * 8;
|
|
21
|
+
const v = value[i];
|
|
22
|
+
buf[off++] = v;
|
|
23
|
+
buf[off++] = v >>> 8;
|
|
24
|
+
buf[off++] = v >>> 16;
|
|
25
|
+
buf[off++] = v >>> 24;
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
28
|
else {
|
|
22
|
-
buf
|
|
29
|
+
buf[11] = value;
|
|
30
|
+
buf[12] = value >>> 8;
|
|
31
|
+
buf[13] = value >>> 16;
|
|
32
|
+
buf[14] = value >>> 24;
|
|
23
33
|
}
|
|
24
34
|
return buf;
|
|
25
35
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PropDef, PropDefEdge } from '@based/schema/def';
|
|
2
2
|
import { FilterCtx } from './types.js';
|
|
3
3
|
import { LangCode } from '@based/schema';
|
|
4
|
-
export declare const createVariableFilterBuffer: (value: any, prop: PropDef | PropDefEdge, ctx: FilterCtx, lang: LangCode) =>
|
|
4
|
+
export declare const createVariableFilterBuffer: (value: any, prop: PropDef | PropDefEdge, ctx: FilterCtx, lang: LangCode) => Uint8Array;
|