@based/db 0.0.15 → 0.0.16

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.
Files changed (43) hide show
  1. package/dist/lib/darwin_aarch64/include/selva/hll.h +2 -1
  2. package/dist/lib/darwin_aarch64/libnode-v20.11.1.node +0 -0
  3. package/dist/lib/darwin_aarch64/libnode-v20.18.1.node +0 -0
  4. package/dist/lib/darwin_aarch64/libnode-v22.13.0.node +0 -0
  5. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  6. package/dist/lib/linux_aarch64/include/selva/hll.h +2 -1
  7. package/dist/lib/linux_aarch64/libnode-v20.11.1.node +0 -0
  8. package/dist/lib/linux_aarch64/libnode-v20.18.1.node +0 -0
  9. package/dist/lib/linux_aarch64/libnode-v22.13.0.node +0 -0
  10. package/dist/lib/linux_aarch64/libselva.so +0 -0
  11. package/dist/lib/linux_x86_64/include/selva/hll.h +2 -1
  12. package/dist/lib/linux_x86_64/libnode-v20.11.1.node +0 -0
  13. package/dist/lib/linux_x86_64/libnode-v20.18.1.node +0 -0
  14. package/dist/lib/linux_x86_64/libnode-v22.13.0.node +0 -0
  15. package/dist/lib/linux_x86_64/libselva.so +0 -0
  16. package/dist/src/client/bitWise.js +1 -0
  17. package/dist/src/client/modify/cardinality.js +8 -9
  18. package/dist/src/client/query/BasedDbQuery.d.ts +1 -1
  19. package/dist/src/client/query/BasedDbQuery.js +14 -7
  20. package/dist/src/client/query/display.js +11 -3
  21. package/dist/src/client/query/filter/FilterBranch.js +8 -3
  22. package/dist/src/client/query/filter/convertFilter.d.ts +4 -0
  23. package/dist/src/client/query/filter/convertFilter.js +56 -0
  24. package/dist/src/client/query/filter/filter.d.ts +1 -2
  25. package/dist/src/client/query/filter/filter.js +5 -56
  26. package/dist/src/client/query/filter/primitiveFilter.d.ts +2 -2
  27. package/dist/src/client/query/filter/primitiveFilter.js +5 -1
  28. package/dist/src/client/query/filter/types.d.ts +2 -1
  29. package/dist/src/client/query/filter/types.js +23 -12
  30. package/dist/src/client/query/read/read.js +21 -32
  31. package/dist/src/client/query/read/types.d.ts +4 -0
  32. package/dist/src/client/query/read/types.js +5 -0
  33. package/dist/src/client/query/validation.d.ts +7 -1
  34. package/dist/src/client/query/validation.js +129 -46
  35. package/dist/src/client/xxHash64.d.ts +1 -1
  36. package/dist/src/client/xxHash64.js +7 -2
  37. package/dist/src/index.d.ts +4 -1
  38. package/dist/src/index.js +16 -1
  39. package/dist/src/native.d.ts +1 -1
  40. package/dist/src/native.js +2 -2
  41. package/dist/src/server/schema/utils.d.ts +1 -0
  42. package/dist/src/server/schema/utils.js +18 -5
  43. package/package.json +1 -1
@@ -8,13 +8,14 @@
8
8
  #include <stdbool.h>
9
9
  #include "cdefs.h"
10
10
 
11
+ #define HLL_INIT_SIZE 8
11
12
 
12
13
  SELVA_EXPORT
13
14
  void hll_init(struct selva_string *hllss, uint8_t precision, bool is_sparse);
14
15
  SELVA_EXPORT
15
16
  void hll_add(struct selva_string *hllss, uint64_t element);
16
17
  SELVA_EXPORT
17
- double hll_count(struct selva_string *hllss);
18
+ uint8_t *hll_count(struct selva_string *hllss);
18
19
  SELVA_EXPORT
19
20
  struct selva_string hll_array_union(struct selva_string *hll_array, size_t count);
20
21
 
@@ -8,13 +8,14 @@
8
8
  #include <stdbool.h>
9
9
  #include "cdefs.h"
10
10
 
11
+ #define HLL_INIT_SIZE 8
11
12
 
12
13
  SELVA_EXPORT
13
14
  void hll_init(struct selva_string *hllss, uint8_t precision, bool is_sparse);
14
15
  SELVA_EXPORT
15
16
  void hll_add(struct selva_string *hllss, uint64_t element);
16
17
  SELVA_EXPORT
17
- double hll_count(struct selva_string *hllss);
18
+ uint8_t *hll_count(struct selva_string *hllss);
18
19
  SELVA_EXPORT
19
20
  struct selva_string hll_array_union(struct selva_string *hll_array, size_t count);
20
21
 
Binary file
@@ -8,13 +8,14 @@
8
8
  #include <stdbool.h>
9
9
  #include "cdefs.h"
10
10
 
11
+ #define HLL_INIT_SIZE 8
11
12
 
12
13
  SELVA_EXPORT
13
14
  void hll_init(struct selva_string *hllss, uint8_t precision, bool is_sparse);
14
15
  SELVA_EXPORT
15
16
  void hll_add(struct selva_string *hllss, uint64_t element);
16
17
  SELVA_EXPORT
17
- double hll_count(struct selva_string *hllss);
18
+ uint8_t *hll_count(struct selva_string *hllss);
18
19
  SELVA_EXPORT
19
20
  struct selva_string hll_array_union(struct selva_string *hll_array, size_t count);
20
21
 
Binary file
@@ -79,4 +79,5 @@ export const concatUint8Arr = (arrs) => {
79
79
  });
80
80
  return result;
81
81
  };
82
+ const textDecoder = new TextDecoder('utf-8');
82
83
  //# sourceMappingURL=bitWise.js.map
@@ -17,25 +17,24 @@ export function writeHll(value, ctx, def, t, parentId, modifyOp) {
17
17
  }
18
18
  function addHll(value, ctx, def, t, parentId, modifyOp) {
19
19
  const len = value.length;
20
- let size = 2 + len * 8;
20
+ let size = 4 + len * 8;
21
21
  if (ctx.len + size + 11 > ctx.max) {
22
22
  return RANGE_ERR;
23
23
  }
24
24
  setCursor(ctx, def, t.prop, t.typeIndex, parentId, modifyOp);
25
25
  ctx.buf[ctx.len++] = modifyOp;
26
- ctx.buf.writeUint16LE(len, ctx.len);
27
- ctx.len += 2;
26
+ ctx.buf.writeUint32LE(len, ctx.len);
27
+ ctx.len += 4;
28
28
  for (let val of value) {
29
- let b;
30
29
  if (typeof val === 'string') {
31
- b = Buffer.from(val);
30
+ xxHash64(Buffer.from(val), ctx.buf, ctx.len);
32
31
  }
33
- else if (!(val instanceof Buffer)) {
34
- b = val;
32
+ else if (val instanceof Buffer && val.byteLength === 8) {
33
+ ctx.buf.set(val, ctx.len);
34
+ }
35
+ else {
35
36
  return new ModifyError(t, val);
36
37
  }
37
- const hash = xxHash64(b);
38
- ctx.buf.writeBigUInt64LE(hash, ctx.len);
39
38
  ctx.len += 8;
40
39
  }
41
40
  }
@@ -14,9 +14,9 @@ export declare class QueryBranch<T> {
14
14
  constructor(db: DbClient, def: QueryDef);
15
15
  sort(field: string, order?: 'asc' | 'desc'): T;
16
16
  filter<O extends Operator>(field: string, operator?: O | boolean, value?: any, opts?: FilterOpts<O>): T;
17
+ filterBatch(f: FilterAst): this;
17
18
  search(query: string, ...fields: Search[]): T;
18
19
  search(query: ArrayBufferView, field: string, opts?: Omit<FilterOpts, 'lowerCase'>): T;
19
- filterBatch(f: FilterAst): this;
20
20
  or(fn: FilterBranchFn): T;
21
21
  or(field: string, operator?: Operator | boolean, value?: any, opts?: FilterOpts): T;
22
22
  range(offset: number, limit: number): T;
@@ -1,4 +1,4 @@
1
- import { createQueryDef, QueryDefType, filter, sort, defToBuffer, filterOr, convertFilter, isAlias, includeField, includeFields, } from './query.js';
1
+ import { createQueryDef, QueryDefType, filter, sort, defToBuffer, filterOr, isAlias, includeField, includeFields, } 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';
@@ -8,6 +8,7 @@ import { REFERENCE, REFERENCES } from '../../server/schema/types.js';
8
8
  import { subscribe } from './subscription/index.js';
9
9
  import { registerQuery } from './registerQuery.js';
10
10
  import { langCodesMap } from '@based/schema';
11
+ import { convertFilter } from './filter/convertFilter.js';
11
12
  export class QueryBranch {
12
13
  db;
13
14
  def;
@@ -22,6 +23,15 @@ export class QueryBranch {
22
23
  }
23
24
  filter(field, operator, value, opts) {
24
25
  const f = convertFilter(this.def, field, operator, value, opts);
26
+ if (!f) {
27
+ // @ts-ignore
28
+ return this;
29
+ }
30
+ filter(this.db, this.def, f, this.def.filter);
31
+ // @ts-ignore
32
+ return this;
33
+ }
34
+ filterBatch(f) {
25
35
  filter(this.db, this.def, f, this.def.filter);
26
36
  // @ts-ignore
27
37
  return this;
@@ -81,11 +91,6 @@ export class QueryBranch {
81
91
  // @ts-ignore
82
92
  return this;
83
93
  }
84
- filterBatch(f) {
85
- filter(this.db, this.def, f, this.def.filter);
86
- // @ts-ignore
87
- return this;
88
- }
89
94
  or(field, operator, value, opts) {
90
95
  if (typeof field === 'function') {
91
96
  const f = new FilterBranch(this.db, filterOr(this.db, this.def, [], this.def.filter), this.def);
@@ -94,7 +99,9 @@ export class QueryBranch {
94
99
  }
95
100
  else {
96
101
  const f = convertFilter(this.def, field, operator, value, opts);
97
- filterOr(this.db, this.def, f, this.def.filter);
102
+ if (f) {
103
+ filterOr(this.db, this.def, f, this.def.filter);
104
+ }
98
105
  }
99
106
  // @ts-ignore
100
107
  return this;
@@ -1,5 +1,5 @@
1
1
  import picocolors from 'picocolors';
2
- import { BINARY, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, } from '../../server/schema/types.js';
2
+ import { BINARY, CARDINALITY, NUMBER, REFERENCE, REFERENCES, STRING, TEXT, TIMESTAMP, } from '../../server/schema/types.js';
3
3
  const decimals = (v) => ~~(v * 100) / 100;
4
4
  const sizeCalc = (size) => {
5
5
  if (size > 1e6) {
@@ -59,6 +59,9 @@ const prettyPrintVal = (v, type) => {
59
59
  return `"${v}"`;
60
60
  }
61
61
  }
62
+ if (type === CARDINALITY) {
63
+ return `${picocolors.blue(v)} ${picocolors.italic(picocolors.dim('unique'))}`;
64
+ }
62
65
  if (type === TIMESTAMP) {
63
66
  if (v === 0) {
64
67
  return `0 ${picocolors.italic(picocolors.dim('No date'))}`;
@@ -100,8 +103,10 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
100
103
  // skip
101
104
  }
102
105
  else if (key === 'id') {
103
- // @ts-ignore
104
- str += v + picocolors.italic(picocolors.dim(` ${q.target.type}`));
106
+ str +=
107
+ picocolors.blue(v) +
108
+ // @ts-ignore
109
+ picocolors.italic(picocolors.dim(` ${q.target.type}`));
105
110
  str += ',\n';
106
111
  }
107
112
  else if (!def) {
@@ -146,6 +151,9 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
146
151
  }
147
152
  str += prettyPrintVal(v, def.typeIndex);
148
153
  }
154
+ else if (def.typeIndex === CARDINALITY) {
155
+ str += prettyPrintVal(v, def.typeIndex);
156
+ }
149
157
  else if (def.typeIndex === TIMESTAMP) {
150
158
  str += prettyPrintVal(v, def.typeIndex);
151
159
  }
@@ -1,4 +1,5 @@
1
- import { convertFilter, filter, filterOr } from './filter.js';
1
+ import { filter, filterOr } from './filter.js';
2
+ import { convertFilter } from './convertFilter.js';
2
3
  export class FilterBranch {
3
4
  constructor(db, filterBranch, def) {
4
5
  this.def = def;
@@ -16,13 +17,17 @@ export class FilterBranch {
16
17
  }
17
18
  else {
18
19
  const f = convertFilter(this.def, field, operator, value, opts);
19
- filterOr(this.db, this.def, f, this.filterBranch);
20
+ if (f) {
21
+ filterOr(this.db, this.def, f, this.filterBranch);
22
+ }
20
23
  }
21
24
  return this;
22
25
  }
23
26
  filter(field, operator, value) {
24
27
  const f = convertFilter(this.def, field, operator, value);
25
- filter(this.db, this.def, f, this.filterBranch);
28
+ if (f) {
29
+ filter(this.db, this.def, f, this.filterBranch);
30
+ }
26
31
  return this;
27
32
  }
28
33
  }
@@ -0,0 +1,4 @@
1
+ import { QueryDef } from '../types.js';
2
+ import { Operator } from './filter.js';
3
+ import { FilterOpts, FilterAst } from './types.js';
4
+ export declare const convertFilter: (def: QueryDef, field: string, operator?: Operator | boolean, value?: any, opts?: FilterOpts | undefined) => FilterAst;
@@ -0,0 +1,56 @@
1
+ import { toFilterCtx } from './types.js';
2
+ const normalizeNeedle = (s) => {
3
+ return s
4
+ .normalize('NFKD')
5
+ .split('')
6
+ .filter((ch) => ch.charCodeAt(0) <= 127)
7
+ .join('');
8
+ };
9
+ export const convertFilter = (def, field, operator, value, opts) => {
10
+ if (operator === undefined) {
11
+ operator = '=';
12
+ value = true;
13
+ }
14
+ else if (typeof operator === 'boolean') {
15
+ value = operator;
16
+ operator = '=';
17
+ }
18
+ if (value === '' || value === undefined) {
19
+ return;
20
+ }
21
+ if (operator === '!..') {
22
+ return [
23
+ [field, toFilterCtx(def, '>', opts), value[1]],
24
+ [field, toFilterCtx(def, '<', opts), value[0]],
25
+ ];
26
+ }
27
+ else if (operator === '..') {
28
+ return [
29
+ [field, toFilterCtx(def, '>', opts), value[0]],
30
+ [field, toFilterCtx(def, '<', opts), value[1]],
31
+ ];
32
+ }
33
+ else {
34
+ if (operator == 'like') {
35
+ if (value == null) {
36
+ throw new Error('Value is required');
37
+ }
38
+ if (value?.normalize) {
39
+ value = normalizeNeedle(value);
40
+ }
41
+ else if (Array.isArray(value)) {
42
+ if (value[0]?.normalize) {
43
+ value = value.map(normalizeNeedle);
44
+ }
45
+ else if (value[0]?.BYTES_PER_ELEMENT > 1) {
46
+ value = value.map((v) => v.buffer);
47
+ }
48
+ }
49
+ else if (value?.BYTES_PER_ELEMENT > 1) {
50
+ value = value.buffer;
51
+ }
52
+ }
53
+ return [[field, toFilterCtx(def, operator, opts), value]];
54
+ }
55
+ };
56
+ //# sourceMappingURL=convertFilter.js.map
@@ -1,10 +1,9 @@
1
1
  import { QueryDef, QueryDefFilter } from '../types.js';
2
2
  import { SchemaTypeDef } from '../../../server/schema/schema.js';
3
- import { FilterOpts, Operator } from './types.js';
3
+ import { Operator } from './types.js';
4
4
  import { Filter, FilterAst } from './types.js';
5
5
  import { DbClient } from '../../index.js';
6
6
  export { Operator, Filter };
7
7
  export declare const filterRaw: (db: DbClient, filter: Filter, schema: SchemaTypeDef, conditions: QueryDefFilter, def: QueryDef) => number;
8
8
  export declare const filter: (db: DbClient, def: QueryDef, filterAst: FilterAst, conditions: QueryDefFilter) => void;
9
9
  export declare const filterOr: (db: DbClient, def: QueryDef, filterAst: FilterAst[], conditions: QueryDefFilter) => QueryDefFilter;
10
- export declare const convertFilter: (def: QueryDef, field: string, operator?: Operator | boolean, value?: any, opts?: FilterOpts) => FilterAst;
@@ -1,6 +1,5 @@
1
1
  import { isPropDef, ID_FIELD_DEF, TEXT, REFERENCE, } from '../../../server/schema/schema.js';
2
2
  import { primitiveFilter } from './primitiveFilter.js';
3
- import { toFilterCtx } from './types.js';
4
3
  import { IsFilter } from './types.js';
5
4
  import { langCodesMap } from '@based/schema';
6
5
  import { filterFieldDoesNotExist, filterInvalidLang } from '../validation.js';
@@ -22,7 +21,8 @@ const referencesFilter = (db, filter, schema, conditions, def) => {
22
21
  const edgeDef = edges[p];
23
22
  if (edgeDef) {
24
23
  conditions.edges ??= new Map();
25
- size += 3 + primitiveFilter(edgeDef, filter, conditions, def.lang);
24
+ size +=
25
+ 3 + primitiveFilter(def, edgeDef, filter, conditions, def.lang);
26
26
  }
27
27
  }
28
28
  }
@@ -71,16 +71,16 @@ export const filterRaw = (db, filter, schema, conditions, def) => {
71
71
  filterInvalidLang(def, field);
72
72
  return 0;
73
73
  }
74
- return primitiveFilter(fieldDef, filter, conditions, code);
74
+ return primitiveFilter(def, fieldDef, filter, conditions, code);
75
75
  }
76
76
  }
77
77
  if (field === 'id') {
78
78
  fieldDef = ID_FIELD_DEF;
79
- return primitiveFilter(fieldDef, filter, conditions, def.lang);
79
+ return primitiveFilter(def, fieldDef, filter, conditions, def.lang);
80
80
  }
81
81
  return referencesFilter(db, filter, schema, conditions, def);
82
82
  }
83
- return primitiveFilter(fieldDef, filter, conditions, def.lang);
83
+ return primitiveFilter(def, fieldDef, filter, conditions, def.lang);
84
84
  };
85
85
  export const filter = (db, def, filterAst, conditions) => {
86
86
  for (const f of filterAst) {
@@ -104,55 +104,4 @@ export const filterOr = (db, def, filterAst, conditions) => {
104
104
  conditions.size += conditions.or.size;
105
105
  return conditions.or;
106
106
  };
107
- const normalizeNeedle = (s) => {
108
- return s
109
- .normalize('NFKD')
110
- .split('')
111
- .filter((ch) => ch.charCodeAt(0) <= 127)
112
- .join('');
113
- };
114
- export const convertFilter = (def, field, operator, value, opts) => {
115
- if (operator === undefined) {
116
- operator = '=';
117
- value = true;
118
- }
119
- else if (typeof operator === 'boolean') {
120
- value = operator;
121
- operator = '=';
122
- }
123
- if (operator === '!..') {
124
- return [
125
- [field, toFilterCtx(def, '>', opts), value[1]],
126
- [field, toFilterCtx(def, '<', opts), value[0]],
127
- ];
128
- }
129
- else if (operator === '..') {
130
- return [
131
- [field, toFilterCtx(def, '>', opts), value[0]],
132
- [field, toFilterCtx(def, '<', opts), value[1]],
133
- ];
134
- }
135
- else {
136
- if (operator == 'like') {
137
- if (value == null) {
138
- throw new Error('Value is required');
139
- }
140
- if (value?.normalize) {
141
- value = normalizeNeedle(value);
142
- }
143
- else if (Array.isArray(value)) {
144
- if (value[0]?.normalize) {
145
- value = value.map(normalizeNeedle);
146
- }
147
- else if (value[0]?.BYTES_PER_ELEMENT > 1) {
148
- value = value.map((v) => v.buffer);
149
- }
150
- }
151
- else if (value?.BYTES_PER_ELEMENT > 1) {
152
- value = value.buffer;
153
- }
154
- }
155
- return [[field, toFilterCtx(def, operator, opts), value]];
156
- }
157
- };
158
107
  //# sourceMappingURL=filter.js.map
@@ -1,5 +1,5 @@
1
1
  import { PropDef, PropDefEdge } from '../../../server/schema/types.js';
2
- import { QueryDefFilter } from '../types.js';
2
+ import { QueryDef, QueryDefFilter } from '../types.js';
3
3
  import { Filter } from './types.js';
4
4
  import { LangCode } from '@based/schema';
5
- export declare const primitiveFilter: (prop: PropDef | PropDefEdge, filter: Filter, conditions: QueryDefFilter, lang: LangCode) => number;
5
+ export declare const primitiveFilter: (def: QueryDef, prop: PropDef | PropDefEdge, filter: Filter, conditions: QueryDefFilter, lang: LangCode) => number;
@@ -3,7 +3,11 @@ import { EQUAL, isNumerical } from './types.js';
3
3
  import { createVariableFilterBuffer } from './createVariableFilterBuffer.js';
4
4
  import { createFixedFilterBuffer } from './createFixedFilterBuffer.js';
5
5
  import { createReferenceFilter } from './createReferenceFilter.js';
6
- export const primitiveFilter = (prop, filter, conditions, lang) => {
6
+ import { validateFilter } from '../validation.js';
7
+ export const primitiveFilter = (def, prop, filter, conditions, lang) => {
8
+ if (validateFilter(def, prop, filter)) {
9
+ return;
10
+ }
7
11
  let [, ctx, value] = filter;
8
12
  const fieldIndexChar = prop.prop;
9
13
  let buf;
@@ -4,8 +4,8 @@ export type Filter = [fieldStr: string, ctx: FilterCtx, value: any];
4
4
  export type FilterBranchFn = (filterBranch: FilterBranch) => void;
5
5
  export type FilterAst = (Filter | FilterAst)[];
6
6
  export declare const IsFilter: (f: FilterAst) => f is Filter;
7
- export declare const validOperators: readonly ["=", "has", "!has", "<", ">", "!=", "like", ">=", "<=", "..", "!.."];
8
7
  export type Operator = '=' | 'has' | '!has' | '<' | '>' | '!=' | 'like' | '>=' | '<=' | '..' | '!..' | 'like';
8
+ export declare const VECTOR_FNS: string[];
9
9
  export type FilterOpts<O = Operator> = {
10
10
  lowerCase?: boolean;
11
11
  fn?: 'dotProduct' | 'manhattanDistance' | 'cosineSimilarity' | 'euclideanDistance';
@@ -54,3 +54,4 @@ export declare const VECTOR_COSTINE_SIMILARITY = 2;
54
54
  export declare const VECTOR_EUCLIDEAN_DIST = 3;
55
55
  export declare const getVectorFn: (optsFn?: FilterOpts["fn"]) => 0 | 1 | 2 | 3;
56
56
  export declare const toFilterCtx: (def: QueryDef, op: Operator, opts?: FilterOpts) => FilterCtx;
57
+ export declare const operatorReverseMap: Record<OPERATOR, string>;
@@ -5,18 +5,11 @@ export const IsFilter = (f) => {
5
5
  }
6
6
  return false;
7
7
  };
8
- export const validOperators = [
9
- '=',
10
- 'has',
11
- '!has',
12
- '<',
13
- '>',
14
- '!=',
15
- 'like',
16
- '>=',
17
- '<=',
18
- '..',
19
- '!..',
8
+ export const VECTOR_FNS = [
9
+ 'dotProduct',
10
+ 'manhattanDistance',
11
+ 'cosineSimilarity',
12
+ 'euclideanDistance',
20
13
  ];
21
14
  // -------------------------------------------
22
15
  // operations shared
@@ -119,4 +112,22 @@ export const toFilterCtx = (def, op, opts = {}) => {
119
112
  }
120
113
  filterOperatorDoesNotExist(def, op);
121
114
  };
115
+ export const operatorReverseMap = {
116
+ [EQUAL]: '=',
117
+ [HAS]: 'has',
118
+ [ENDS_WITH]: 'endsWith',
119
+ [STARTS_WITH]: 'startsWith',
120
+ [GREATER_THAN]: '>',
121
+ [SMALLER_THAN]: '<',
122
+ [GREATER_THAN_INCLUSIVE]: '>=',
123
+ [SMALLER_THAN_INCLUSIVE]: '<=',
124
+ [RANGE]: '..',
125
+ [RANGE_EXCLUDE]: '!..',
126
+ [EQUAL_LOWER_CASE]: '= (lowerCase)',
127
+ [HAS_TO_LOWER_CASE]: 'has (lowerCase)',
128
+ [STARTS_WITH_LOWER_CASE]: 'startsWith (lowerCase)',
129
+ [ENDS_WITH_LOWER_CASE]: 'endsWith (lowerCase)',
130
+ [LIKE]: 'like',
131
+ [EQUAL_CRC32]: '= (crc32)',
132
+ };
122
133
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,8 @@
1
- import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, JSON, } from '../../../server/schema/types.js';
1
+ import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, JSON, CARDINALITY, } from '../../../server/schema/types.js';
2
2
  import { read, readUtf8 } from '../../string.js';
3
3
  import { readDoubleLE, readFloatLE, readInt16, readInt32, readUint16, readUint32, } from '../../bitWise.js';
4
4
  import { inverseLangMap } from '@based/schema';
5
+ import { READ_EDGE, READ_ID, READ_REFERENCE, READ_REFERENCES } from './types.js';
5
6
  const addField = (p, value, item, defaultOnly = false, lang = 0) => {
6
7
  let i = p.__isEdge === true ? 1 : 0;
7
8
  // TODO OPTMIZE
@@ -58,19 +59,15 @@ const getEmptyField = (p, item) => {
58
59
  return select;
59
60
  };
60
61
  const readMainValue = (prop, result, index, item) => {
61
- // 1: timestamp, 4: number
62
62
  if (prop.typeIndex === TIMESTAMP || prop.typeIndex === NUMBER) {
63
63
  addField(prop, readDoubleLE(result, index), item);
64
64
  }
65
- // 5: uint32
66
65
  else if (prop.typeIndex === UINT32) {
67
66
  addField(prop, readUint32(result, index), item);
68
67
  }
69
- // 9: boolean
70
68
  else if (prop.typeIndex === BOOLEAN) {
71
69
  addField(prop, Boolean(result[index]), item);
72
70
  }
73
- // 10: Enum
74
71
  else if (prop.typeIndex === ENUM) {
75
72
  if (result[index] === 0) {
76
73
  addField(prop, undefined, item);
@@ -79,9 +76,7 @@ const readMainValue = (prop, result, index, item) => {
79
76
  addField(prop, prop.enum[result[index] - 1], item);
80
77
  }
81
78
  }
82
- // 11: string
83
79
  else if (prop.typeIndex === STRING) {
84
- // Also delete this default then (same as other string)
85
80
  const len = result[index];
86
81
  if (len !== 0) {
87
82
  const str = readUtf8(result, index + 1, len);
@@ -91,32 +86,25 @@ const readMainValue = (prop, result, index, item) => {
91
86
  addField(prop, '', item);
92
87
  }
93
88
  }
94
- // ?: json
95
89
  else if (prop.typeIndex === JSON) {
96
- addField(prop, global.JSON.parse(Buffer.from(result.subarray(index + 1, index + 1 + result[index])).toString()), item);
90
+ addField(prop, global.JSON.parse(readUtf8(result, index + 1, index + 1 + result[index])), item);
97
91
  }
98
- // 25: binary
99
92
  else if (prop.typeIndex === BINARY) {
100
93
  addField(prop, result.subarray(index + 1, index + 1 + result[index]), item);
101
94
  }
102
- // 18: int8
103
95
  else if (prop.typeIndex === INT8) {
104
96
  const signedVal = (result[index] << 24) >> 24;
105
97
  addField(prop, signedVal, item);
106
98
  }
107
- // 19: uint8
108
99
  else if (prop.typeIndex === UINT8) {
109
100
  addField(prop, result[index], item);
110
101
  }
111
- // 20: int16
112
102
  else if (prop.typeIndex === INT16) {
113
103
  addField(prop, readInt16(result, index), item);
114
104
  }
115
- // 21: uint16
116
105
  else if (prop.typeIndex === UINT16) {
117
106
  addField(prop, readUint16(result, index), item);
118
107
  }
119
- // 22: int32
120
108
  else if (prop.typeIndex === INT32) {
121
109
  addField(prop, readInt32(result, index), item);
122
110
  }
@@ -143,7 +131,10 @@ const handleUndefinedProps = (id, q, item) => {
143
131
  for (const k in q.include.propsRead) {
144
132
  if (q.include.propsRead[k] !== id) {
145
133
  const prop = q.schema.reverseProps[k];
146
- if (prop.typeIndex === TEXT && q.lang == 0) {
134
+ if (prop.typeIndex === CARDINALITY) {
135
+ addField(prop, 0, item);
136
+ }
137
+ else if (prop.typeIndex === TEXT && q.lang == 0) {
147
138
  const lan = getEmptyField(prop, item);
148
139
  const lang = q.include.langTextFields.get(prop.prop).codes;
149
140
  if (lang.has(0)) {
@@ -173,16 +164,13 @@ export const readAllFields = (q, result, offset, end, item, id) => {
173
164
  while (i < end) {
174
165
  const index = result[i];
175
166
  i++;
176
- // index:255 id
177
- if (index === 255) {
167
+ if (index === READ_ID) {
178
168
  handleUndefinedProps(id, q, item);
179
169
  return i - offset;
180
170
  }
181
- // index:252 edge
182
- if (index === 252) {
171
+ if (index === READ_EDGE) {
183
172
  let prop = result[i];
184
- // index:254 ref
185
- if (prop === 254) {
173
+ if (prop === READ_REFERENCE) {
186
174
  i++;
187
175
  const field = result[i];
188
176
  i++;
@@ -206,9 +194,8 @@ export const readAllFields = (q, result, offset, end, item, id) => {
206
194
  addField(ref.target.propDef, refItem, item);
207
195
  i += size - 5;
208
196
  }
209
- // index:253 refs
210
197
  }
211
- else if (prop === 253) {
198
+ else if (prop === READ_REFERENCES) {
212
199
  i++;
213
200
  const field = result[i];
214
201
  i++;
@@ -227,7 +214,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
227
214
  if (t === JSON) {
228
215
  i++;
229
216
  const size = readUint32(result, i);
230
- addField(edgeDef, global.JSON.parse(Buffer.from(result.subarray(i + 6, size + i)).toString()), item);
217
+ addField(edgeDef, global.JSON.parse(readUtf8(result, i + 6, size + i)), item);
231
218
  i += size + 4;
232
219
  }
233
220
  else if (t === BINARY) {
@@ -253,9 +240,8 @@ export const readAllFields = (q, result, offset, end, item, id) => {
253
240
  i += edgeDef.len;
254
241
  }
255
242
  }
256
- // index:254 ref
257
243
  }
258
- else if (index === 254) {
244
+ else if (index === READ_REFERENCE) {
259
245
  const field = result[i];
260
246
  i++;
261
247
  const size = readUint32(result, i);
@@ -278,9 +264,8 @@ export const readAllFields = (q, result, offset, end, item, id) => {
278
264
  addField(ref.target.propDef, refItem, item);
279
265
  i += size - 5;
280
266
  }
281
- // index:253 refs
282
267
  }
283
- else if (index === 253) {
268
+ else if (index === READ_REFERENCES) {
284
269
  const field = result[i];
285
270
  i++;
286
271
  const ref = q.references.get(field);
@@ -296,7 +281,13 @@ export const readAllFields = (q, result, offset, end, item, id) => {
296
281
  }
297
282
  else {
298
283
  const prop = q.schema.reverseProps[index];
299
- if (prop.typeIndex === JSON) {
284
+ if (prop.typeIndex === CARDINALITY) {
285
+ q.include.propsRead[index] = id;
286
+ const size = readUint32(result, i);
287
+ addField(prop, readUint32(result, i + 4), item);
288
+ i += size + 4;
289
+ }
290
+ else if (prop.typeIndex === JSON) {
300
291
  q.include.propsRead[index] = id;
301
292
  const size = readUint32(result, i);
302
293
  addField(prop, global.JSON.parse(Buffer.from(result.subarray(i + 6, i + size)).toString()), item);
@@ -329,7 +320,6 @@ export const readAllFields = (q, result, offset, end, item, id) => {
329
320
  addField(prop, read(result, i + 4, size), item);
330
321
  }
331
322
  else {
332
- // q.include.propsRead[index] = id
333
323
  addField(prop, read(result, i + 4, size), item, false, result[i + 4]);
334
324
  }
335
325
  }
@@ -360,7 +350,6 @@ export const readAllFields = (q, result, offset, end, item, id) => {
360
350
  }
361
351
  }
362
352
  }
363
- // to add defaults - may not optimal for performance
364
353
  handleUndefinedProps(id, q, item);
365
354
  return i - offset;
366
355
  };
@@ -0,0 +1,4 @@
1
+ export declare const READ_ID = 255;
2
+ export declare const READ_EDGE = 252;
3
+ export declare const READ_REFERENCES = 253;
4
+ export declare const READ_REFERENCE = 254;
@@ -0,0 +1,5 @@
1
+ export const READ_ID = 255;
2
+ export const READ_EDGE = 252;
3
+ export const READ_REFERENCES = 253;
4
+ export const READ_REFERENCE = 254;
5
+ //# sourceMappingURL=types.js.map
@@ -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;
@@ -29,8 +30,13 @@ declare const messages: {
29
30
  7: (p: any) => string;
30
31
  12: (p: any) => string;
31
32
  9: (p: any) => string;
33
+ 8: (p: Filter) => string;
34
+ 11: (p: any) => string;
35
+ 10: (p: any) => string;
32
36
  };
33
37
  export type ErrorCode = keyof typeof messages;
38
+ export declare const isValidId: (id: number) => boolean;
39
+ export declare const validateFilter: (def: QueryDef, prop: PropDef | PropDefEdge, f: Filter) => boolean;
34
40
  export declare const validateType: (db: DbClient, def: QueryDef, type: string) => SchemaTypeDef;
35
41
  export declare const filterOperatorDoesNotExist: (def: QueryDef, field: string) => void;
36
42
  export declare const filterInvalidLang: (def: QueryDef, field: string) => void;
@@ -1,5 +1,7 @@
1
- import { ALIAS } from '../../server/schema/types.js';
2
- import { MAX_ID, MAX_IDS_PER_QUERY } from './thresholds.js';
1
+ import { ALIAS, BOOLEAN, REFERENCE, REFERENCES, STRING, TEXT, VECTOR, } from '../../server/schema/types.js';
2
+ import { propIsNumerical } from '../../server/schema/utils.js';
3
+ import { EQUAL, HAS, isNumerical, LIKE, operatorReverseMap, VECTOR_FNS, } from './filter/types.js';
4
+ import { MAX_ID, MAX_ID_VALUE, MAX_IDS_PER_QUERY, MIN_ID_VALUE, } from './thresholds.js';
3
5
  export const ERR_TARGET_INVAL_TYPE = 1;
4
6
  export const ERR_TARGET_INVAL_ALIAS = 2;
5
7
  export const ERR_TARGET_EXCEED_MAX_IDS = 3;
@@ -13,17 +15,20 @@ export const ERR_FILTER_INVALID_VAL = 10;
13
15
  export const ERR_FILTER_INVALID_OPTS = 11;
14
16
  export const ERR_FILTER_INVALID_LANG = 12;
15
17
  export const ERR_INCLUDE_INVALID_LANG = 13;
18
+ const safeStringify = (p) => {
19
+ var v;
20
+ try {
21
+ v = JSON.stringify(p).replace(/"/g, '');
22
+ }
23
+ catch (err) {
24
+ v = '';
25
+ }
26
+ return v;
27
+ };
16
28
  const messages = {
17
29
  [ERR_TARGET_INVAL_TYPE]: (p) => `Type "${p}" does not exist`,
18
30
  [ERR_TARGET_INVAL_ALIAS]: (p) => {
19
- var v;
20
- try {
21
- v = JSON.stringify(p).replace(/"/g, '');
22
- }
23
- catch (err) {
24
- v = '';
25
- }
26
- return `Invalid alias prodived to query "${v}"`;
31
+ return `Invalid alias prodived to query "${safeStringify(p)}"`;
27
32
  },
28
33
  [ERR_TARGET_EXCEED_MAX_IDS]: (p) => `Exceeds max ids ${~~(p.length / 1e3)}k (max ${MAX_IDS_PER_QUERY / 1e3}k)`,
29
34
  [ERR_TARGET_INVAL_IDS]: (p) => `Ids should be of type array or Uint32Array with valid ids`,
@@ -33,6 +38,118 @@ const messages = {
33
38
  [ERR_FILTER_ENOENT]: (p) => `Filter: field does not exist "${p}"`,
34
39
  [ERR_FILTER_INVALID_LANG]: (p) => `Filter: invalid lang "${p}"`,
35
40
  [ERR_FILTER_OP_ENOENT]: (p) => `Filter: invalid operator "${p}"`,
41
+ [ERR_FILTER_OP_FIELD]: (p) => `Cannot use operator "${operatorReverseMap[p[1].operation]}" on field "${p[0]}"`,
42
+ [ERR_FILTER_INVALID_OPTS]: (p) => {
43
+ return `Filter: Invalid opts "${safeStringify(p)}"`;
44
+ },
45
+ [ERR_FILTER_INVALID_VAL]: (p) => {
46
+ return `Filter: Invalid value ${p[0]} ${operatorReverseMap[p[1].operation]} "${safeStringify(p[2])}"`;
47
+ },
48
+ };
49
+ export const isValidId = (id) => {
50
+ if (typeof id != 'number') {
51
+ return false;
52
+ }
53
+ else if (id < MIN_ID_VALUE || id > MAX_ID_VALUE) {
54
+ return false;
55
+ }
56
+ return true;
57
+ };
58
+ export const validateFilter = (def, prop, f) => {
59
+ const t = prop.typeIndex;
60
+ const op = f[1].operation;
61
+ const value = f[2];
62
+ if (t === REFERENCES) {
63
+ if (op == LIKE) {
64
+ def.errors.push({
65
+ code: ERR_FILTER_OP_FIELD,
66
+ payload: f,
67
+ });
68
+ return true;
69
+ }
70
+ }
71
+ else if (t === REFERENCE) {
72
+ if (op != EQUAL) {
73
+ def.errors.push({
74
+ code: ERR_FILTER_OP_FIELD,
75
+ payload: f,
76
+ });
77
+ return true;
78
+ }
79
+ if (Array.isArray(value)) {
80
+ for (const v of value) {
81
+ if (!isValidId(v)) {
82
+ def.errors.push({
83
+ code: ERR_FILTER_INVALID_VAL,
84
+ payload: f,
85
+ });
86
+ return true;
87
+ }
88
+ }
89
+ }
90
+ else if (!isValidId(value)) {
91
+ def.errors.push({
92
+ code: ERR_FILTER_INVALID_VAL,
93
+ payload: f,
94
+ });
95
+ return true;
96
+ }
97
+ }
98
+ else if (t === VECTOR) {
99
+ if (isNumerical(op) || op === HAS) {
100
+ def.errors.push({
101
+ code: ERR_FILTER_OP_FIELD,
102
+ payload: f,
103
+ });
104
+ return true;
105
+ }
106
+ if (op === LIKE) {
107
+ const opts = f[1].opts;
108
+ if ((opts.fn && !VECTOR_FNS.includes(opts.fn)) ||
109
+ (opts.score != undefined && typeof opts.score !== 'number')) {
110
+ def.errors.push({
111
+ code: ERR_FILTER_INVALID_OPTS,
112
+ payload: f,
113
+ });
114
+ return true;
115
+ }
116
+ }
117
+ }
118
+ else if (t === TEXT || t === STRING) {
119
+ if (isNumerical(op)) {
120
+ def.errors.push({
121
+ code: ERR_FILTER_OP_FIELD,
122
+ payload: f,
123
+ });
124
+ return true;
125
+ }
126
+ if (op === LIKE) {
127
+ const opts = f[1].opts;
128
+ if (opts.score &&
129
+ (typeof opts.score !== 'number' || opts.score < 0 || opts.score > 255)) {
130
+ def.errors.push({
131
+ code: ERR_FILTER_INVALID_OPTS,
132
+ payload: f,
133
+ });
134
+ return true;
135
+ }
136
+ }
137
+ }
138
+ else if (propIsNumerical(prop) && op !== EQUAL && !isNumerical(op)) {
139
+ def.errors.push({
140
+ code: ERR_FILTER_OP_FIELD,
141
+ payload: f,
142
+ });
143
+ return true;
144
+ }
145
+ else if (t === BOOLEAN && op !== EQUAL) {
146
+ def.errors.push({
147
+ code: ERR_FILTER_OP_FIELD,
148
+ payload: f,
149
+ });
150
+ return true;
151
+ }
152
+ return false;
36
153
  };
37
154
  export const validateType = (db, def, type) => {
38
155
  const r = db.schemaTypesParsed[type];
@@ -155,8 +272,8 @@ export const handleErrors = (def) => {
155
272
  for (const err of def.errors) {
156
273
  name += ` ${messages[err.code](err.payload)}\n`;
157
274
  }
158
- const err = new Error(name);
159
- err.stack = '';
275
+ const err = new Error(`Query\n`);
276
+ err.stack = name;
160
277
  throw err;
161
278
  }
162
279
  };
@@ -193,40 +310,6 @@ export const EMPTY_SCHEMA_DEF = {
193
310
  stringProps: Buffer.from([]),
194
311
  stringPropsLoop: [],
195
312
  };
196
- // import { ALIAS, PropDef, PropDefEdge } from '../../server/schema/types.js'
197
- // import {
198
- // MAX_IDS_PER_QUERY,
199
- // MIN_ID_VALUE,
200
- // MAX_ID_VALUE,
201
- // MAX_BUFFER_SIZE,
202
- // } from './thresholds.js'
203
- // import { QueryByAliasObj, QueryDef } from './types.js'
204
- // import { DbClient } from '../index.js'
205
- // export const isValidId = (id: number): void => {
206
- // if (typeof id != 'number') {
207
- // throw new Error('Id has to be a number')
208
- // } else if (id < MIN_ID_VALUE || id > MAX_ID_VALUE) {
209
- // throw new Error(
210
- // `Invalid Id: The Id should range between ${MIN_ID_VALUE} and ${MAX_ID_VALUE}.)`,
211
- // )
212
- // }
213
- // }
214
- // export const isValidType = (
215
- // type: string,
216
- // schema: DbClient['schemaTypesParsed'],
217
- // ): void => {
218
- // if (!schema[type]) {
219
- // throw new Error(`Incorrect type provided to query "${type}"`)
220
- // }
221
- // }
222
- // export const isValidAlias = (def: QueryDef, id: QueryByAliasObj) => {
223
- // for (const key in id) {
224
- // const prop = def.schema.props[key]
225
- // if (!prop || prop.typeIndex !== ALIAS) {
226
- // throw new Error(`Incorrect alias provided to query "${key}"`)
227
- // }
228
- // }
229
- // }
230
313
  // export const checkMaxIdsPerQuery = (
231
314
  // ids: (number | QueryByAliasObj)[],
232
315
  // ): void => {
@@ -1 +1 @@
1
- export declare const xxHash64: (buf: Buffer) => any;
1
+ export declare const xxHash64: (buf: Buffer, target?: Buffer, index?: number) => Buffer;
@@ -1,5 +1,10 @@
1
1
  import native from '../native.js';
2
- export const xxHash64 = (buf) => {
3
- return native.xxHash64(buf);
2
+ export const xxHash64 = (buf, target, index) => {
3
+ if (!target) {
4
+ target = Buffer.allocUnsafe(8);
5
+ index = 0;
6
+ }
7
+ native.xxHash64(buf, target, index);
8
+ return target;
4
9
  };
5
10
  //# sourceMappingURL=xxHash64.js.map
@@ -7,12 +7,14 @@ export * from './client/modify/modify.js';
7
7
  export { compress, decompress };
8
8
  export { ModifyCtx };
9
9
  export { DbClient, DbServer };
10
+ export { xxHash64 } from './client/xxHash64.js';
10
11
  export declare class BasedDb {
12
+ #private;
11
13
  client: DbClient;
12
14
  server: DbServer;
13
15
  fileSystemPath: string;
14
16
  maxModifySize: number;
15
- constructor({ path, maxModifySize, }: {
17
+ constructor(opt: {
16
18
  path: string;
17
19
  maxModifySize?: number;
18
20
  });
@@ -31,4 +33,5 @@ export declare class BasedDb {
31
33
  save: DbServer['save'];
32
34
  migrateSchema: DbServer['migrateSchema'];
33
35
  destroy(): Promise<void>;
36
+ wipe(): Promise<void>;
34
37
  }
package/dist/src/index.js CHANGED
@@ -7,12 +7,18 @@ export * from './client/modify/modify.js';
7
7
  export { compress, decompress };
8
8
  export { ModifyCtx }; // TODO move this somewhere
9
9
  export { DbClient, DbServer };
10
+ export { xxHash64 } from './client/xxHash64.js';
10
11
  export class BasedDb {
11
12
  client;
12
13
  server;
13
14
  fileSystemPath;
14
15
  maxModifySize;
15
- constructor({ path, maxModifySize, }) {
16
+ constructor(opt) {
17
+ this.#init(opt);
18
+ }
19
+ #init({ path, maxModifySize }) {
20
+ this.fileSystemPath = path;
21
+ this.maxModifySize = maxModifySize;
16
22
  const server = new DbServer({
17
23
  path,
18
24
  maxModifySize,
@@ -91,5 +97,14 @@ export class BasedDb {
91
97
  this.client.destroy();
92
98
  return this.server.destroy();
93
99
  }
100
+ async wipe() {
101
+ const opts = {
102
+ maxModifySize: this.maxModifySize,
103
+ path: this.fileSystemPath,
104
+ };
105
+ await this.destroy();
106
+ this.#init(opts);
107
+ await this.start({ clean: true });
108
+ }
94
109
  }
95
110
  //# sourceMappingURL=index.js.map
@@ -24,6 +24,6 @@ declare const _default: {
24
24
  crc32: (buf: Buffer) => any;
25
25
  createSortIndex: (buf: Buffer, dbCtx: any) => any;
26
26
  destroySortIndex: (buf: Buffer, dbCtx: any) => any;
27
- xxHash64: (buf: Buffer) => any;
27
+ xxHash64: (buf: Buffer, target: Buffer, index: number) => any;
28
28
  };
29
29
  export default _default;
@@ -93,8 +93,8 @@ export default {
93
93
  destroySortIndex: (buf, dbCtx) => {
94
94
  return db.destroySortIndex(dbCtx, buf);
95
95
  },
96
- xxHash64: (buf) => {
97
- return db.xxHash64(buf);
96
+ xxHash64: (buf, target, index) => {
97
+ return db.xxHash64(buf, target, index);
98
98
  },
99
99
  };
100
100
  //# sourceMappingURL=native.js.map
@@ -2,5 +2,6 @@ import { DbClient } from '../../client/index.js';
2
2
  import { DbServer } from '../index.js';
3
3
  import { PropDef, PropDefEdge } from './types.js';
4
4
  export declare const propIsSigned: (prop: PropDef | PropDefEdge) => boolean;
5
+ export declare const propIsNumerical: (prop: PropDef | PropDefEdge) => boolean;
5
6
  export declare const genRootId: () => number;
6
7
  export declare const genId: (db: DbServer | DbClient) => number;
@@ -1,9 +1,22 @@
1
- import { INT16, INT32, INT64, INT8 } from './types.js';
1
+ import { INT16, INT32, INT64, INT8, UINT16, UINT32, UINT8, NUMBER, TIMESTAMP, } from './types.js';
2
2
  export const propIsSigned = (prop) => {
3
- if (prop.typeIndex === INT16 ||
4
- prop.typeIndex === INT32 ||
5
- prop.typeIndex === INT64 ||
6
- prop.typeIndex === INT8) {
3
+ const t = prop.typeIndex;
4
+ if (t === INT16 || t === INT32 || t === INT64 || t === INT8) {
5
+ return true;
6
+ }
7
+ return false;
8
+ };
9
+ export const propIsNumerical = (prop) => {
10
+ const t = prop.typeIndex;
11
+ if (t === INT16 ||
12
+ t === INT32 ||
13
+ t === INT64 ||
14
+ t === INT8 ||
15
+ t === UINT8 ||
16
+ t === UINT16 ||
17
+ t === UINT32 ||
18
+ t === NUMBER ||
19
+ t === TIMESTAMP) {
7
20
  return true;
8
21
  }
9
22
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@based/db",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",