@based/db 0.0.15 → 0.0.17
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/db.h +3 -0
- package/dist/lib/darwin_aarch64/include/selva/fields.h +1 -2
- package/dist/lib/darwin_aarch64/include/selva/history.h +16 -1
- package/dist/lib/darwin_aarch64/include/selva/hll.h +2 -1
- package/dist/lib/darwin_aarch64/include/selva/types.h +4 -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/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +3 -0
- package/dist/lib/linux_aarch64/include/selva/fields.h +1 -2
- package/dist/lib/linux_aarch64/include/selva/history.h +16 -1
- package/dist/lib/linux_aarch64/include/selva/hll.h +2 -1
- package/dist/lib/linux_aarch64/include/selva/types.h +4 -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/selva/db.h +3 -0
- package/dist/lib/linux_x86_64/include/selva/fields.h +1 -2
- package/dist/lib/linux_x86_64/include/selva/history.h +16 -1
- package/dist/lib/linux_x86_64/include/selva/hll.h +2 -1
- package/dist/lib/linux_x86_64/include/selva/types.h +4 -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.js +1 -0
- package/dist/src/client/crc32.js +0 -276
- package/dist/src/client/modify/ModifyRes.d.ts +4 -2
- package/dist/src/client/modify/ModifyRes.js +11 -6
- package/dist/src/client/modify/alias.js +2 -2
- package/dist/src/client/modify/cardinality.js +14 -10
- package/dist/src/client/modify/create.js +8 -9
- package/dist/src/client/modify/references/reference.js +14 -7
- package/dist/src/client/modify/references/references.js +10 -4
- package/dist/src/client/modify/string.js +2 -2
- package/dist/src/client/modify/text.js +1 -1
- package/dist/src/client/modify/types.d.ts +3 -1
- package/dist/src/client/modify/types.js +2 -0
- package/dist/src/client/modify/update.js +1 -1
- package/dist/src/client/operations.d.ts +2 -2
- package/dist/src/client/operations.js +19 -3
- package/dist/src/client/query/BasedDbQuery.d.ts +5 -4
- package/dist/src/client/query/BasedDbQuery.js +28 -13
- package/dist/src/client/query/BasedIterable.js +3 -10
- package/dist/src/client/query/display.d.ts +6 -0
- package/dist/src/client/query/display.js +63 -4
- package/dist/src/client/query/filter/FilterBranch.js +8 -3
- package/dist/src/client/query/filter/convertFilter.d.ts +4 -0
- package/dist/src/client/query/filter/convertFilter.js +56 -0
- package/dist/src/client/query/filter/createFixedFilterBuffer.js +9 -8
- package/dist/src/client/query/filter/createReferenceFilter.js +5 -4
- package/dist/src/client/query/filter/createVariableFilterBuffer.js +6 -10
- package/dist/src/client/query/filter/filter.d.ts +1 -2
- package/dist/src/client/query/filter/filter.js +5 -56
- package/dist/src/client/query/filter/primitiveFilter.d.ts +2 -2
- package/dist/src/client/query/filter/primitiveFilter.js +5 -1
- package/dist/src/client/query/filter/toBuffer.js +1 -6
- package/dist/src/client/query/filter/types.d.ts +2 -1
- package/dist/src/client/query/filter/types.js +23 -12
- package/dist/src/client/query/include/props.js +14 -6
- package/dist/src/client/query/include/utils.js +2 -2
- package/dist/src/client/query/include/walk.js +1 -7
- package/dist/src/client/query/queryDef.d.ts +1 -1
- package/dist/src/client/query/queryDef.js +4 -3
- package/dist/src/client/query/read/read.js +21 -32
- package/dist/src/client/query/read/types.d.ts +4 -0
- package/dist/src/client/query/read/types.js +5 -0
- package/dist/src/client/query/registerQuery.js +1 -0
- package/dist/src/client/query/search/index.js +12 -6
- package/dist/src/client/query/sort.js +7 -6
- package/dist/src/client/query/thresholds.d.ts +0 -1
- package/dist/src/client/query/thresholds.js +0 -8
- package/dist/src/client/query/toBuffer.js +0 -3
- package/dist/src/client/query/types.d.ts +2 -0
- package/dist/src/client/query/validation.d.ts +39 -1
- package/dist/src/client/query/validation.js +299 -93
- package/dist/src/client/xxHash64.d.ts +1 -1
- package/dist/src/client/xxHash64.js +7 -2
- package/dist/src/index.d.ts +6 -1
- package/dist/src/index.js +31 -1
- package/dist/src/native.d.ts +3 -1
- package/dist/src/native.js +8 -2
- package/dist/src/server/index.d.ts +8 -6
- package/dist/src/server/index.js +56 -30
- package/dist/src/server/migrate/index.js +10 -2
- package/dist/src/server/migrate/worker.js +1 -1
- package/dist/src/server/schema/typeDef.js +35 -25
- package/dist/src/server/schema/types.d.ts +10 -5
- package/dist/src/server/schema/types.js +1 -1
- package/dist/src/server/schema/utils.d.ts +1 -0
- package/dist/src/server/schema/utils.js +18 -5
- package/package.json +5 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { langCodesMap } from '@based/schema';
|
|
2
2
|
import { STRING, TEXT, VECTOR } from '../../../server/schema/types.js';
|
|
3
3
|
import { getVectorFn } from '../filter/types.js';
|
|
4
|
+
import { searchDoesNotExist, searchIncorrecQueryValue, searchIncorrectType, } from '../validation.js';
|
|
4
5
|
const makeSize = (nr, u8 = false) => {
|
|
5
6
|
if (u8) {
|
|
6
7
|
const size = Buffer.allocUnsafe(1);
|
|
@@ -13,12 +14,12 @@ const makeSize = (nr, u8 = false) => {
|
|
|
13
14
|
};
|
|
14
15
|
// vector
|
|
15
16
|
export const vectorSearch = (def, q, field, opts) => {
|
|
16
|
-
|
|
17
|
+
let prop = def.props[field];
|
|
17
18
|
if (!prop) {
|
|
18
|
-
|
|
19
|
+
prop = searchDoesNotExist(def, field, true);
|
|
19
20
|
}
|
|
20
21
|
if (prop.typeIndex !== VECTOR) {
|
|
21
|
-
|
|
22
|
+
searchIncorrectType(def, prop);
|
|
22
23
|
}
|
|
23
24
|
// [isVec] [q len] [q len] [field] [fn] [score] [score] [score] [score] [q..]
|
|
24
25
|
let size = 9;
|
|
@@ -35,6 +36,10 @@ export const vectorSearch = (def, q, field, opts) => {
|
|
|
35
36
|
export const search = (def, q, s) => {
|
|
36
37
|
const bufs = [];
|
|
37
38
|
let blocks = 0;
|
|
39
|
+
if (typeof q !== 'string') {
|
|
40
|
+
searchIncorrecQueryValue(def, q);
|
|
41
|
+
q = '';
|
|
42
|
+
}
|
|
38
43
|
const x = q.toLowerCase().trim().split(' ');
|
|
39
44
|
for (const s of x) {
|
|
40
45
|
if (s) {
|
|
@@ -80,17 +85,18 @@ export const search = (def, q, s) => {
|
|
|
80
85
|
prop = def.props[k.slice(0, -1).join('.')];
|
|
81
86
|
if (prop && prop.typeIndex === TEXT) {
|
|
82
87
|
lang = langCodesMap.get(k[k.length - 1]);
|
|
88
|
+
// incorrect LANG
|
|
83
89
|
}
|
|
84
90
|
else {
|
|
85
|
-
|
|
91
|
+
prop = searchDoesNotExist(def, key, false);
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
else {
|
|
89
|
-
|
|
95
|
+
prop = searchDoesNotExist(def, key, false);
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
if (prop.typeIndex !== STRING && prop.typeIndex !== TEXT) {
|
|
93
|
-
|
|
99
|
+
searchIncorrectType(def, prop);
|
|
94
100
|
}
|
|
95
101
|
def.search.size += 5;
|
|
96
102
|
def.search.fields.push({
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
import { validateSort } from './validation.js';
|
|
1
2
|
export const createSortBuffer = (sort) => {
|
|
2
|
-
const buf = Buffer.allocUnsafe(
|
|
3
|
-
// [order] [propType] [start] [start] [len] [len]
|
|
3
|
+
const buf = Buffer.allocUnsafe(8);
|
|
4
|
+
// [order] [propType] [start] [start] [len] [len] [lang]
|
|
4
5
|
buf[0] = sort.order;
|
|
5
6
|
buf[1] = sort.prop.prop;
|
|
6
7
|
buf[2] = sort.prop.typeIndex;
|
|
7
8
|
buf.writeUint16LE(sort.prop.start, 3);
|
|
8
9
|
buf.writeUint16LE(sort.prop.len, 5);
|
|
10
|
+
buf[7] = sort.lang;
|
|
11
|
+
// console.info({ sort, buf: new Uint8Array(buf) })
|
|
12
|
+
//[LANG]
|
|
9
13
|
return buf;
|
|
10
14
|
};
|
|
11
15
|
// NO REF / REFERENCES SUPPORT
|
|
12
16
|
export const sort = (def, field, order) => {
|
|
13
|
-
def.sort =
|
|
14
|
-
prop: def.props[field],
|
|
15
|
-
order: order === 'asc' || order === undefined ? 0 : 1,
|
|
16
|
-
};
|
|
17
|
+
def.sort = validateSort(def, field, order);
|
|
17
18
|
};
|
|
18
19
|
//# sourceMappingURL=sort.js.map
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
// Query thresholds
|
|
2
2
|
export const MAX_IDS_PER_QUERY = 1e6; // Max number of IDs that can be queried at once
|
|
3
|
-
export const MAX_BUFFER_SIZE = 5 * 1024 * 1024; // 5MB (max buffer size)
|
|
4
3
|
export const DEF_RANGE_PROP_LIMIT = 1e3;
|
|
5
4
|
export const DEF_RANGE_REF_LIMIT = 1e4;
|
|
6
5
|
export const MAX_ID = 4294967295;
|
|
7
6
|
// Data validation thresholds
|
|
8
7
|
export const MIN_ID_VALUE = 1; // Minimum allowed value for an ID (id array stared)
|
|
9
8
|
export const MAX_ID_VALUE = 2 ** 32 - 1; /// Maximum allowed value for an ID (Uint32)
|
|
10
|
-
// Performance-related thresholds
|
|
11
|
-
// <Just making room to further threshoulds e.g. MAX_MEMORY_BLABLABLA>
|
|
12
|
-
// Network-related thresholds
|
|
13
|
-
// <Just making room to further threshoulds e.g. MAX_NETWORK_RETRIES, NETWORK_TIMEOUT, etc.>
|
|
14
|
-
// Security-related thresholds
|
|
15
|
-
// <Just making room to further threshoulds that could make sense such. e.g.
|
|
16
|
-
// MAX_INPUT_LENGTH (strings/json to prevent DDoS attacks) or MAX_API_DUMP_LENGTH to avoid undesired dumps>
|
|
17
9
|
//# sourceMappingURL=thresholds.js.map
|
|
@@ -57,6 +57,7 @@ export type QueryDefSearch = {
|
|
|
57
57
|
export type QueryDefSort = {
|
|
58
58
|
prop: PropDefEdge | PropDef;
|
|
59
59
|
order: 0 | 1;
|
|
60
|
+
lang: LangCode;
|
|
60
61
|
};
|
|
61
62
|
export type QueryDefShared = {
|
|
62
63
|
errors: QueryError[];
|
|
@@ -65,6 +66,7 @@ export type QueryDefShared = {
|
|
|
65
66
|
search: null | QueryDefSearch;
|
|
66
67
|
sort: null | QueryDefSort;
|
|
67
68
|
reverseProps: any;
|
|
69
|
+
skipValidation: boolean;
|
|
68
70
|
range: {
|
|
69
71
|
offset: number;
|
|
70
72
|
limit: number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { PropDef, SchemaTypeDef } from '../../server/schema/types.js';
|
|
1
|
+
import { PropDef, PropDefEdge, SchemaTypeDef } from '../../server/schema/types.js';
|
|
2
2
|
import { DbClient } from '../index.js';
|
|
3
|
+
import { Filter } from './query.js';
|
|
3
4
|
import { QueryByAliasObj, QueryDef } from './types.js';
|
|
4
5
|
export type QueryError = {
|
|
5
6
|
code: number;
|
|
@@ -18,6 +19,17 @@ export declare const ERR_FILTER_INVALID_VAL = 10;
|
|
|
18
19
|
export declare const ERR_FILTER_INVALID_OPTS = 11;
|
|
19
20
|
export declare const ERR_FILTER_INVALID_LANG = 12;
|
|
20
21
|
export declare const ERR_INCLUDE_INVALID_LANG = 13;
|
|
22
|
+
export declare const ERR_SORT_ENOENT = 14;
|
|
23
|
+
export declare const ERR_SORT_TYPE = 15;
|
|
24
|
+
export declare const ERR_SORT_ORDER = 16;
|
|
25
|
+
export declare const ERR_SORT_WRONG_TARGET = 17;
|
|
26
|
+
export declare const ERR_RANGE_INVALID_OFFSET = 18;
|
|
27
|
+
export declare const ERR_RANGE_INVALID_LIMIT = 19;
|
|
28
|
+
export declare const ERR_INVALID_LANG = 20;
|
|
29
|
+
export declare const ERR_SEARCH_ENOENT = 21;
|
|
30
|
+
export declare const ERR_SEARCH_TYPE = 22;
|
|
31
|
+
export declare const ERR_SEARCH_INCORRECT_VALUE = 23;
|
|
32
|
+
export declare const ERR_SORT_LANG = 24;
|
|
21
33
|
declare const messages: {
|
|
22
34
|
1: (p: any) => string;
|
|
23
35
|
2: (p: any) => string;
|
|
@@ -29,14 +41,38 @@ declare const messages: {
|
|
|
29
41
|
7: (p: any) => string;
|
|
30
42
|
12: (p: any) => string;
|
|
31
43
|
9: (p: any) => string;
|
|
44
|
+
8: (p: Filter) => string;
|
|
45
|
+
11: (p: any) => string;
|
|
46
|
+
10: (p: any) => string;
|
|
47
|
+
14: (p: any) => string;
|
|
48
|
+
17: (p: any) => string;
|
|
49
|
+
16: (p: any) => string;
|
|
50
|
+
15: (p: any) => string;
|
|
51
|
+
18: (p: any) => string;
|
|
52
|
+
19: (p: any) => string;
|
|
53
|
+
20: (p: any) => string;
|
|
54
|
+
21: (p: any) => string;
|
|
55
|
+
22: (p: any) => string;
|
|
56
|
+
23: (p: any) => string;
|
|
57
|
+
24: (p: any) => string;
|
|
32
58
|
};
|
|
33
59
|
export type ErrorCode = keyof typeof messages;
|
|
60
|
+
export declare const searchIncorrecQueryValue: (def: QueryDef, payload: any) => void;
|
|
61
|
+
export declare const searchIncorrectType: (def: QueryDef, payload: PropDef | PropDefEdge) => void;
|
|
62
|
+
export declare const searchDoesNotExist: (def: QueryDef, field: string, isVector: boolean) => PropDef;
|
|
63
|
+
export declare const validateRange: (def: QueryDef, offset: number, limit: number) => boolean;
|
|
64
|
+
export declare const isValidId: (id: number) => boolean;
|
|
65
|
+
export declare const isValidString: (v: any) => boolean;
|
|
66
|
+
export declare const validateVal: (def: QueryDef, f: Filter, validate: (v: any) => boolean) => boolean;
|
|
67
|
+
export declare const validateFilter: (def: QueryDef, prop: PropDef | PropDefEdge, f: Filter) => boolean;
|
|
34
68
|
export declare const validateType: (db: DbClient, def: QueryDef, type: string) => SchemaTypeDef;
|
|
35
69
|
export declare const filterOperatorDoesNotExist: (def: QueryDef, field: string) => void;
|
|
36
70
|
export declare const filterInvalidLang: (def: QueryDef, field: string) => void;
|
|
37
71
|
export declare const filterFieldDoesNotExist: (def: QueryDef, field: string) => void;
|
|
38
72
|
export declare const includeDoesNotExist: (def: QueryDef, field: string) => void;
|
|
39
73
|
export declare const includeLangDoesNotExist: (def: QueryDef, field: string) => void;
|
|
74
|
+
export declare const validateLocale: (def: QueryDef, lang: string) => void;
|
|
75
|
+
export declare const validateSort: (def: QueryDef, field: string, orderInput?: "asc" | "desc") => QueryDef["sort"];
|
|
40
76
|
export declare const validateAlias: (alias: QueryByAliasObj, path: string[], def: QueryDef) => {
|
|
41
77
|
def: PropDef;
|
|
42
78
|
value: string;
|
|
@@ -45,5 +81,7 @@ export declare const validateId: (def: QueryDef, id: any) => number;
|
|
|
45
81
|
export declare const validateIds: (def: QueryDef, ids: any) => Uint32Array;
|
|
46
82
|
export declare const handleErrors: (def: QueryDef) => void;
|
|
47
83
|
export declare const EMPTY_ALIAS_PROP_DEF: PropDef;
|
|
84
|
+
export declare const ERROR_STRING: PropDef;
|
|
85
|
+
export declare const ERROR_VECTOR: PropDef;
|
|
48
86
|
export declare const EMPTY_SCHEMA_DEF: SchemaTypeDef;
|
|
49
87
|
export {};
|