@based/db 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/lib/darwin_aarch64/include/jemalloc.h +468 -0
  2. package/dist/lib/darwin_aarch64/include/selva/selva_string.h +2 -0
  3. package/dist/lib/darwin_aarch64/libnode-v20.11.1.node +0 -0
  4. package/dist/lib/darwin_aarch64/libnode-v20.18.1.node +0 -0
  5. package/dist/lib/darwin_aarch64/libnode-v22.13.0.node +0 -0
  6. package/dist/lib/darwin_aarch64/libnode-v22.8.0.node +0 -0
  7. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  8. package/dist/lib/linux_aarch64/include/jemalloc.h +468 -0
  9. package/dist/lib/linux_aarch64/include/selva/selva_string.h +2 -0
  10. package/dist/lib/linux_aarch64/libnode-v20.11.1.node +0 -0
  11. package/dist/lib/linux_aarch64/libnode-v20.18.1.node +0 -0
  12. package/dist/lib/linux_aarch64/libnode-v22.13.0.node +0 -0
  13. package/dist/lib/linux_aarch64/libselva.so +0 -0
  14. package/dist/lib/linux_x86_64/include/jemalloc.h +468 -0
  15. package/dist/lib/linux_x86_64/include/selva/selva_string.h +2 -0
  16. package/dist/lib/linux_x86_64/libnode-v20.11.1.node +0 -0
  17. package/dist/lib/linux_x86_64/libnode-v20.18.1.node +0 -0
  18. package/dist/lib/linux_x86_64/libnode-v22.13.0.node +0 -0
  19. package/dist/lib/linux_x86_64/libselva.so +0 -0
  20. package/dist/src/client/bitWise.d.ts +7 -0
  21. package/dist/src/client/bitWise.js +62 -0
  22. package/dist/src/client/modify/modify.js +5 -1
  23. package/dist/src/client/modify/text.d.ts +4 -2
  24. package/dist/src/client/modify/text.js +1 -2
  25. package/dist/src/client/modify/vector.d.ts +4 -0
  26. package/dist/src/client/modify/vector.js +44 -0
  27. package/dist/src/client/query/BasedDbQuery.d.ts +3 -1
  28. package/dist/src/client/query/BasedDbQuery.js +9 -7
  29. package/dist/src/client/query/BasedIterable.d.ts +2 -2
  30. package/dist/src/client/query/BasedIterable.js +10 -5
  31. package/dist/src/client/query/debug.js +4 -3
  32. package/dist/src/client/query/display.js +19 -4
  33. package/dist/src/client/query/filter/createVariableFilterBuffer.d.ts +2 -1
  34. package/dist/src/client/query/filter/createVariableFilterBuffer.js +16 -7
  35. package/dist/src/client/query/filter/filter.js +17 -4
  36. package/dist/src/client/query/filter/primitiveFilter.d.ts +2 -1
  37. package/dist/src/client/query/filter/primitiveFilter.js +2 -2
  38. package/dist/src/client/query/include/utils.js +1 -0
  39. package/dist/src/client/query/include/walk.js +1 -0
  40. package/dist/src/client/query/queryDef.js +2 -0
  41. package/dist/src/client/query/read/read.d.ts +2 -2
  42. package/dist/src/client/query/read/read.js +64 -38
  43. package/dist/src/client/query/subscription/index.js +3 -3
  44. package/dist/src/client/query/subscription/run.d.ts +1 -1
  45. package/dist/src/client/query/subscription/run.js +12 -2
  46. package/dist/src/client/query/toBuffer.js +3 -0
  47. package/dist/src/client/query/types.d.ts +2 -0
  48. package/dist/src/client/string.d.ts +3 -2
  49. package/dist/src/client/string.js +13 -7
  50. package/dist/src/native.d.ts +1 -1
  51. package/dist/src/native.js +2 -1
  52. package/dist/src/server/index.d.ts +1 -1
  53. package/dist/src/server/index.js +2 -1
  54. package/dist/src/server/schema/selvaBuffer.js +4 -3
  55. package/dist/src/server/schema/typeDef.js +4 -1
  56. package/dist/src/server/schema/types.d.ts +3 -0
  57. package/dist/src/server/schema/types.js +5 -0
  58. package/dist/src/server/worker.js +1 -1
  59. package/package.json +1 -1
@@ -8,6 +8,7 @@ import native from '../../native.js';
8
8
  import { REFERENCE, REFERENCES } from '../../server/schema/types.js';
9
9
  import { subscribe } from './subscription/index.js';
10
10
  import { registerQuery } from './registerQuery.js';
11
+ import { langCodesMap } from '@based/schema';
11
12
  export class QueryBranch {
12
13
  db;
13
14
  def;
@@ -136,7 +137,6 @@ export class BasedDbReferenceQuery extends QueryBranch {
136
137
  }
137
138
  const resToJSON = (res) => res.toJSON();
138
139
  const resToObject = (res) => res.toObject();
139
- const resInspect = (res) => new GetPromise((resolve) => resolve(res.inspect()));
140
140
  class GetPromise extends Promise {
141
141
  toObject() {
142
142
  return this.then(resToObject);
@@ -144,8 +144,8 @@ class GetPromise extends Promise {
144
144
  toJSON() {
145
145
  return this.then(resToJSON);
146
146
  }
147
- inspect() {
148
- return this.then(resInspect);
147
+ inspect(depth) {
148
+ return this.then((res) => new GetPromise((resolve) => resolve(res.inspect(depth))));
149
149
  }
150
150
  }
151
151
  export class BasedDbQuery extends QueryBranch {
@@ -194,8 +194,7 @@ export class BasedDbQuery extends QueryBranch {
194
194
  reject(res);
195
195
  }
196
196
  else {
197
- const result = Buffer.from(res);
198
- resolve(new BasedQueryResponse(this.id, this.def, result, performance.now() - d));
197
+ resolve(new BasedQueryResponse(this.id, this.def, res, performance.now() - d));
199
198
  }
200
199
  };
201
200
  // if !id not initialized yet
@@ -207,6 +206,10 @@ export class BasedDbQuery extends QueryBranch {
207
206
  register() {
208
207
  return registerQuery(this);
209
208
  }
209
+ i18n(locale) {
210
+ this.def.lang = langCodesMap.get(locale) ?? 0;
211
+ return this;
212
+ }
210
213
  subscribe(onData, onError) {
211
214
  return subscribe(this, onData, onError ??
212
215
  ((err) => {
@@ -220,8 +223,7 @@ export class BasedDbQuery extends QueryBranch {
220
223
  const buf = registerQuery(this);
221
224
  const d = performance.now();
222
225
  const res = native.getQueryBuf(buf, dbCtxExternal);
223
- const result = Buffer.from(res);
224
- return new BasedQueryResponse(this.id, this.def, result, performance.now() - d);
226
+ return new BasedQueryResponse(this.id, this.def, new Uint8Array(res), performance.now() - d);
225
227
  }
226
228
  toBuffer() {
227
229
  if (!this.def.include.stringFields.size && !this.def.references.size) {
@@ -4,12 +4,12 @@ import { Item } from './query.js';
4
4
  import { size, time, inspectData } from './display.js';
5
5
  export { time, size, inspectData };
6
6
  export declare class BasedQueryResponse {
7
- result: Buffer;
7
+ result: Uint8Array;
8
8
  def: QueryDef;
9
9
  execTime: number;
10
10
  end: number;
11
11
  id: number;
12
- constructor(id: number, def: QueryDef, result: Buffer, execTime: number, end?: number);
12
+ constructor(id: number, def: QueryDef, result: Uint8Array, execTime: number, end?: number);
13
13
  get size(): number;
14
14
  [inspect.custom](depth: number): string;
15
15
  debug(): this;
@@ -2,6 +2,7 @@ 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 } from './display.js';
5
+ import { readUint32 } from '../bitWise.js';
5
6
  export { time, size, inspectData };
6
7
  export class BasedQueryResponse {
7
8
  result;
@@ -9,7 +10,7 @@ export class BasedQueryResponse {
9
10
  execTime;
10
11
  end;
11
12
  id;
12
- constructor(id, def, result, execTime, end = result.byteLength) {
13
+ constructor(id, def, result, execTime, end = result.length) {
13
14
  this.id = id;
14
15
  this.def = def;
15
16
  this.result = result;
@@ -17,7 +18,7 @@ export class BasedQueryResponse {
17
18
  this.end = end;
18
19
  }
19
20
  get size() {
20
- return this.result.byteLength;
21
+ return this.result.length;
21
22
  }
22
23
  [inspect.custom](depth) {
23
24
  const hasId = 'id' in this.def.target || 'alias' in this.def.target;
@@ -42,6 +43,8 @@ export class BasedQueryResponse {
42
43
  return this;
43
44
  }
44
45
  node(index = 0) {
46
+ // get id as well
47
+ // and potentialy a proxy [i] as well
45
48
  let i = 0;
46
49
  if ('id' in this.def.target || 'alias' in this.def.target) {
47
50
  return this.toObject();
@@ -61,7 +64,7 @@ export class BasedQueryResponse {
61
64
  let i = 5;
62
65
  const result = this.result;
63
66
  while (i < result.byteLength - 4) {
64
- let id = result.readUInt32LE(i);
67
+ let id = readUint32(result, i);
65
68
  i += 4;
66
69
  const item = {
67
70
  id,
@@ -94,10 +97,12 @@ export class BasedQueryResponse {
94
97
  return arr;
95
98
  }
96
99
  get checksum() {
97
- return this.result.readUint32LE(this.result.byteLength - 4);
100
+ const result = this.result;
101
+ const offset = result.byteLength - 4;
102
+ return readUint32(result, offset);
98
103
  }
99
104
  get length() {
100
- return this.result.readUint32LE(0);
105
+ return readUint32(this.result, 0);
101
106
  }
102
107
  toObject() {
103
108
  return resultToObject(this.def, this.result, this.end - 4, 0);
@@ -1,6 +1,7 @@
1
1
  import picocolors from 'picocolors';
2
2
  import { isPropDef, REVERSE_TYPE_INDEX_MAP } from '../../server/schema/types.js';
3
3
  import { QueryDefType } from './types.js';
4
+ import { concatUint8Arr } from '../bitWise.js';
4
5
  export const debugQueryDef = (q, returnIt) => {
5
6
  const loggableObject = { type: 'bla', schema: null };
6
7
  const f = (a) => {
@@ -69,10 +70,10 @@ export const debug = (x, start = 0, end = 0, label) => {
69
70
  console.log(x);
70
71
  return;
71
72
  }
72
- if (Array.isArray(x) && x[0] instanceof Buffer) {
73
- debug(Buffer.concat(x), start, end, label);
73
+ if (Array.isArray(x) && x[0] instanceof Uint8Array) {
74
+ debug(concatUint8Arr(x), start, end, label);
74
75
  }
75
- else if (x instanceof Buffer) {
76
+ else if (x instanceof Uint8Array) {
76
77
  console.log(label || '');
77
78
  if (!end) {
78
79
  end = x.byteLength;
@@ -1,5 +1,5 @@
1
1
  import picocolors from 'picocolors';
2
- import { BINARY, NUMBER, REFERENCE, REFERENCES, STRING, TIMESTAMP, } from '../../server/schema/types.js';
2
+ import { BINARY, 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) {
@@ -45,11 +45,11 @@ const prettyPrintVal = (v, type) => {
45
45
  (isLarger ? picocolors.dim('... ') : '') +
46
46
  picocolors.italic(picocolors.dim(`${~~((Buffer.byteLength(v, 'utf8') / 1e3) * 100) / 100}kb`)));
47
47
  }
48
- if (type === STRING) {
49
- if (v.length > 75) {
48
+ if (type === STRING || type === TEXT) {
49
+ if (v.length > 50) {
50
50
  const chars = picocolors.italic(picocolors.dim(`${~~((Buffer.byteLength(v, 'utf8') / 1e3) * 100) / 100}kb`));
51
51
  v =
52
- v.slice(0, 75).replace(/\n/g, '\\n ') +
52
+ v.slice(0, 50).replace(/\n/g, '\\n ') +
53
53
  picocolors.dim('...') +
54
54
  '" ' +
55
55
  chars;
@@ -125,6 +125,21 @@ const inspectObject = (object, q, path, level, isLast, isFirst, isObject, depth)
125
125
  }
126
126
  str += prettyPrintVal(v, def.typeIndex);
127
127
  }
128
+ else if (def.typeIndex === TEXT) {
129
+ if (typeof v === 'object') {
130
+ str += '{\n';
131
+ for (const lang in v) {
132
+ str += `${prefixBody} ${lang}: ${prettyPrintVal(v[lang], def.typeIndex)},\n`;
133
+ }
134
+ str += `${prefixBody}}`;
135
+ }
136
+ else {
137
+ if (v === undefined) {
138
+ return '';
139
+ }
140
+ str += prettyPrintVal(v, def.typeIndex);
141
+ }
142
+ }
128
143
  else if (def.typeIndex === STRING) {
129
144
  if (v === undefined) {
130
145
  return '';
@@ -1,2 +1,3 @@
1
1
  import { PropDef, PropDefEdge } from '../../../server/schema/types.js';
2
- export declare const createVariableFilterBuffer: (value: any, prop: PropDef | PropDefEdge, op: number) => Buffer;
2
+ import { LangCode } from '@based/schema';
3
+ export declare const createVariableFilterBuffer: (value: any, prop: PropDef | PropDefEdge, op: number, lang: LangCode) => Buffer;
@@ -1,7 +1,7 @@
1
- import { ALIAS } from '../../../server/schema/types.js';
1
+ import { ALIAS, TEXT, } from '../../../server/schema/types.js';
2
2
  import { negateType, stripNegation } from './operators.js';
3
3
  import { createFixedFilterBuffer } from './createFixedFilterBuffer.js';
4
- const parseValue = (value, prop, op) => {
4
+ const parseValue = (value, prop, op, lang) => {
5
5
  let val = value;
6
6
  if (op === 19 && typeof val === 'string') {
7
7
  val = val.toLowerCase();
@@ -10,14 +10,20 @@ const parseValue = (value, prop, op) => {
10
10
  typeof value === 'string' ||
11
11
  !prop.separate ||
12
12
  op !== 1) {
13
- val = Buffer.from(val);
13
+ if (prop.typeIndex === TEXT) {
14
+ // can be optmized replace when using uint8array
15
+ val = Buffer.concat([Buffer.from(val), Buffer.from([lang])]);
16
+ }
17
+ else {
18
+ val = Buffer.from(val);
19
+ }
14
20
  }
15
21
  if (!(val instanceof Buffer)) {
16
22
  throw new Error('Incorrect value for filter ' + prop.path);
17
23
  }
18
24
  return val;
19
25
  };
20
- export const createVariableFilterBuffer = (value, prop, op) => {
26
+ export const createVariableFilterBuffer = (value, prop, op, lang) => {
21
27
  let isOr = 4;
22
28
  let val;
23
29
  let buf;
@@ -26,7 +32,7 @@ export const createVariableFilterBuffer = (value, prop, op) => {
26
32
  isOr = 2;
27
33
  const x = [];
28
34
  for (const v of value) {
29
- const a = parseValue(v, prop, op);
35
+ const a = parseValue(v, prop, op, lang);
30
36
  const size = Buffer.allocUnsafe(2);
31
37
  size.writeUint16LE(a.byteLength);
32
38
  x.push(size, a);
@@ -36,18 +42,19 @@ export const createVariableFilterBuffer = (value, prop, op) => {
36
42
  else {
37
43
  const x = [];
38
44
  for (const v of value) {
39
- x.push(parseValue(v, prop, op));
45
+ x.push(parseValue(v, prop, op, lang));
40
46
  }
41
47
  val = x;
42
48
  }
43
49
  }
44
50
  else {
45
- val = parseValue(value, prop, op);
51
+ val = parseValue(value, prop, op, lang);
46
52
  }
47
53
  // --------------------
48
54
  if (op === 3 || op === 1 || op === 2 || op === 16 || op === 18 || op === 19) {
49
55
  if (prop.separate) {
50
56
  if (op === 1 && prop.typeIndex !== ALIAS) {
57
+ // console.log('STRICT EQUAL FOR TEXT ALSO!')
51
58
  // 17 crc32 check
52
59
  buf = createFixedFilterBuffer(prop, 8, 17, val, false);
53
60
  }
@@ -75,6 +82,8 @@ function writeVarFilter(isOr, val, buf, op, prop, start, len) {
75
82
  buf.writeUint32LE(size, 6);
76
83
  buf[10] = stripNegation(op);
77
84
  buf[11] = prop.typeIndex;
85
+ // need to pas LANG FROM QUERY
86
+ // need to set on 12 if TEXT
78
87
  buf.set(val, 12);
79
88
  return buf;
80
89
  }
@@ -1,7 +1,8 @@
1
- import { isPropDef, ID_FIELD_DEF, } from '../../../server/schema/schema.js';
1
+ import { isPropDef, ID_FIELD_DEF, TEXT, } from '../../../server/schema/schema.js';
2
2
  import { primitiveFilter } from './primitiveFilter.js';
3
3
  import { IsFilter } from './types.js';
4
4
  import { hasField, checkOperator, checkValue } from '../validation.js';
5
+ import { langCodesMap } from '@based/schema';
5
6
  const referencesFilter = (db, filter, schema, conditions, def) => {
6
7
  const [fieldStr, operator, value] = filter;
7
8
  var size = 0;
@@ -23,7 +24,7 @@ const referencesFilter = (db, filter, schema, conditions, def) => {
23
24
  const edgeDef = edges[p];
24
25
  if (edgeDef) {
25
26
  conditions.edges ??= new Map();
26
- size += 3 + primitiveFilter(edgeDef, filter, conditions);
27
+ size += 3 + primitiveFilter(edgeDef, filter, conditions, def.lang);
27
28
  }
28
29
  }
29
30
  }
@@ -58,13 +59,25 @@ export const filterRaw = (db, filter, schema, conditions, def) => {
58
59
  checkValue(value, operator); // Validates the value based on the operator
59
60
  let fieldDef = schema.props[field];
60
61
  if (!fieldDef) {
62
+ const s = field.split('.');
63
+ if (s.length > 1) {
64
+ const f = s.slice(0, -1).join();
65
+ fieldDef = schema.props[f];
66
+ if (fieldDef && fieldDef.typeIndex === TEXT) {
67
+ const code = langCodesMap.get(s[s.length - 1]);
68
+ if (!code) {
69
+ throw new Error(`Invalid value for filter on ${field}: expected a valid locale`);
70
+ }
71
+ return primitiveFilter(fieldDef, filter, conditions, code);
72
+ }
73
+ }
61
74
  if (field === 'id') {
62
75
  fieldDef = ID_FIELD_DEF;
63
- return primitiveFilter(fieldDef, filter, conditions);
76
+ return primitiveFilter(fieldDef, filter, conditions, def.lang);
64
77
  }
65
78
  return referencesFilter(db, filter, schema, conditions, def);
66
79
  }
67
- return primitiveFilter(fieldDef, filter, conditions);
80
+ return primitiveFilter(fieldDef, filter, conditions, def.lang);
68
81
  };
69
82
  export const filter = (db, def, filterAst, conditions) => {
70
83
  for (const f of filterAst) {
@@ -1,4 +1,5 @@
1
1
  import { PropDef, PropDefEdge } from '../../../server/schema/types.js';
2
2
  import { QueryDefFilter } from '../types.js';
3
3
  import { Filter } from './types.js';
4
- export declare const primitiveFilter: (prop: PropDef | PropDefEdge, filter: Filter, conditions: QueryDefFilter) => number;
4
+ import { LangCode } from '@based/schema';
5
+ export declare const primitiveFilter: (prop: PropDef | PropDefEdge, filter: Filter, conditions: QueryDefFilter, lang: LangCode) => number;
@@ -4,7 +4,7 @@ import { createVariableFilterBuffer } from './createVariableFilterBuffer.js';
4
4
  import { createFixedFilterBuffer } from './createFixedFilterBuffer.js';
5
5
  import { createReferenceFilter } from './createReferenceFilter.js';
6
6
  import { checkOperator, checkValue } from '../validation.js';
7
- export const primitiveFilter = (prop, filter, conditions) => {
7
+ export const primitiveFilter = (prop, filter, conditions, lang) => {
8
8
  let [, operator, value] = filter;
9
9
  checkOperator(operator);
10
10
  checkValue(value, operator);
@@ -31,7 +31,7 @@ export const primitiveFilter = (prop, filter, conditions) => {
31
31
  buf = createFixedFilterBuffer(prop, propSize, op, value, false);
32
32
  }
33
33
  else {
34
- buf = createVariableFilterBuffer(value, prop, op);
34
+ buf = createVariableFilterBuffer(value, prop, op, lang);
35
35
  }
36
36
  // ADD OR if array for value
37
37
  let arr = bufferMap.get(fieldIndexChar);
@@ -20,6 +20,7 @@ const createRefQueryDef = (db, def, t) => {
20
20
  type: t.inverseTypeName,
21
21
  propDef: t,
22
22
  });
23
+ defRef.lang = def.lang;
23
24
  def.references.set(t.prop, defRef);
24
25
  return defRef;
25
26
  };
@@ -15,6 +15,7 @@ export const walkDefs = (db, def, f) => {
15
15
  def.edges = createQueryDef(db, QueryDefType.Edge, {
16
16
  ref: def.target.propDef,
17
17
  });
18
+ def.edges.lang = def.lang;
18
19
  }
19
20
  const edgeProp = def.edges.props[p];
20
21
  if (edgeProp.typeIndex === REFERENCE ||
@@ -1,9 +1,11 @@
1
+ import { langCodesMap } from '@based/schema';
1
2
  import { MAX_RANGE_PROP_LIMIT, MAX_RANGE_REF_LIMIT } from './thresholds.js';
2
3
  import { QueryDefType, } from './types.js';
3
4
  const createEmptySharedDef = () => {
4
5
  const q = {
5
6
  filter: { conditions: new Map(), size: 0 },
6
7
  range: { offset: 0, limit: 0 },
8
+ lang: langCodesMap.get('none'),
7
9
  include: {
8
10
  stringFields: new Set(),
9
11
  props: new Set(),
@@ -4,5 +4,5 @@ export type Item = {
4
4
  } & {
5
5
  [key: string]: any;
6
6
  };
7
- export declare const readAllFields: (q: QueryDef, result: Buffer, offset: number, end: number, item: Item, id: number) => number;
8
- export declare const resultToObject: (q: QueryDef, result: Buffer, end: number, offset?: number) => any;
7
+ export declare const readAllFields: (q: QueryDef, result: Uint8Array, offset: number, end: number, item: Item, id: number) => number;
8
+ export declare const resultToObject: (q: QueryDef, result: Uint8Array, end: number, offset?: number) => any;
@@ -1,10 +1,14 @@
1
- import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, } from '../../../server/schema/types.js';
2
- import { read } from '../../string.js';
3
- const addField = (p, value, item, defaultOnly = false) => {
1
+ import { ALIAS, ALIASES, BINARY, BOOLEAN, ENUM, INT16, INT32, INT8, NUMBER, STRING, TEXT, TIMESTAMP, UINT16, UINT32, UINT8, VECTOR, } from '../../../server/schema/types.js';
2
+ import { read, readUtf8 } from '../../string.js';
3
+ import { readDoubleLE, readFloatLE, readInt16, readInt32, readUint16, readUint32, } from '../../bitWise.js';
4
+ import { inverseLangMap, langCodesMap } from '@based/schema';
5
+ const addField = (p, value, item, defaultOnly = false, lang = 0) => {
4
6
  let i = p.__isEdge === true ? 1 : 0;
5
- const len = p.path.length;
7
+ // TODO OPTMIZE
8
+ const path = lang ? [...p.path, inverseLangMap.get(lang)] : p.path;
9
+ const len = path.length;
6
10
  if (len - i === 1) {
7
- const field = p.path[i];
11
+ const field = path[i];
8
12
  if (!defaultOnly || !(field in item)) {
9
13
  item[field] = value;
10
14
  }
@@ -12,7 +16,7 @@ const addField = (p, value, item, defaultOnly = false) => {
12
16
  else {
13
17
  let select = item;
14
18
  for (; i < len; i++) {
15
- const field = p.path[i];
19
+ const field = path[i];
16
20
  if (i === len - 1) {
17
21
  if (!defaultOnly || !(field in select)) {
18
22
  select[field] = value;
@@ -27,11 +31,11 @@ const addField = (p, value, item, defaultOnly = false) => {
27
31
  const readMainValue = (prop, result, index, item) => {
28
32
  // 1: timestamp, 4: number
29
33
  if (prop.typeIndex === TIMESTAMP || prop.typeIndex === NUMBER) {
30
- addField(prop, result.readDoubleLE(index), item);
34
+ addField(prop, readDoubleLE(result, index), item);
31
35
  }
32
36
  // 5: uint32
33
37
  else if (prop.typeIndex === UINT32) {
34
- addField(prop, result.readUInt32LE(index), item);
38
+ addField(prop, readUint32(result, index), item);
35
39
  }
36
40
  // 9: boolean
37
41
  else if (prop.typeIndex === BOOLEAN) {
@@ -51,40 +55,37 @@ const readMainValue = (prop, result, index, item) => {
51
55
  // Also remove this default then (same as other string)
52
56
  const len = result[index];
53
57
  if (len !== 0) {
54
- const str = result.toString('utf-8', index + 1, index + len + 1);
58
+ const str = readUtf8(result, index + 1, len);
55
59
  addField(prop, str, item);
56
60
  }
57
61
  else {
58
62
  addField(prop, '', item);
59
63
  }
60
64
  }
61
- // 11: string
65
+ // 25: binary
62
66
  else if (prop.typeIndex === BINARY) {
63
- addField(prop, new Uint8Array(result.buffer, index + 1, result[index]), item);
67
+ addField(prop, result.subarray(index + 1, index + 1 + result[index]), item);
64
68
  }
65
69
  // 18: int8
66
70
  else if (prop.typeIndex === INT8) {
67
- addField(prop, result.readInt8(index), item);
71
+ const signedVal = (result[index] << 24) >> 24;
72
+ addField(prop, signedVal, item);
68
73
  }
69
74
  // 19: uint8
70
75
  else if (prop.typeIndex === UINT8) {
71
- addField(prop, result.readUint8(index), item);
76
+ addField(prop, result[index], item);
72
77
  }
73
78
  // 20: int16
74
79
  else if (prop.typeIndex === INT16) {
75
- addField(prop, result.readInt16LE(index), item);
80
+ addField(prop, readInt16(result, index), item);
76
81
  }
77
82
  // 21: uint16
78
83
  else if (prop.typeIndex === UINT16) {
79
- addField(prop, result.readUint16LE(index), item);
84
+ addField(prop, readUint16(result, index), item);
80
85
  }
81
86
  // 22: int32
82
87
  else if (prop.typeIndex === INT32) {
83
- addField(prop, result.readInt32LE(index), item);
84
- }
85
- // 5: uint32
86
- else if (prop.typeIndex === UINT32) {
87
- addField(prop, result.readUint32LE(index), item);
88
+ addField(prop, readInt32(result, index), item);
88
89
  }
89
90
  };
90
91
  const readMain = (q, result, offset, item) => {
@@ -127,7 +128,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
127
128
  i++;
128
129
  const field = result[i];
129
130
  i++;
130
- const size = result.readUint32LE(i);
131
+ const size = readUint32(result, i);
131
132
  i += 4;
132
133
  const ref = q.edges.references.get(field);
133
134
  if (size === 0) {
@@ -137,7 +138,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
137
138
  }
138
139
  else {
139
140
  i++;
140
- let id = result.readUInt32LE(i);
141
+ const id = readUint32(result, i);
141
142
  i += 4;
142
143
  const refItem = {
143
144
  id,
@@ -153,7 +154,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
153
154
  const field = result[i];
154
155
  i++;
155
156
  const ref = q.edges.references.get(field);
156
- const size = result.readUint32LE(i);
157
+ const size = readUint32(result, i);
157
158
  i += 4;
158
159
  const refs = resultToObject(ref, result, size + i + 4, i);
159
160
  // @ts-ignore
@@ -166,13 +167,13 @@ export const readAllFields = (q, result, offset, end, item, id) => {
166
167
  const t = edgeDef.typeIndex;
167
168
  if (t === BINARY) {
168
169
  i++;
169
- const size = result.readUint32LE(i);
170
- addField(edgeDef, new Uint8Array(result.buffer, i + 6, size - 6), item);
170
+ const size = readUint32(result, i);
171
+ addField(edgeDef, result.subarray(i + 6, size + i), item);
171
172
  i += size + 4;
172
173
  }
173
174
  else if (t === STRING || t === ALIAS || t === ALIASES) {
174
175
  i++;
175
- const size = result.readUint32LE(i);
176
+ const size = readUint32(result, i);
176
177
  if (size === 0) {
177
178
  addField(edgeDef, '', item);
178
179
  }
@@ -191,7 +192,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
191
192
  else if (index === 254) {
192
193
  const field = result[i];
193
194
  i++;
194
- const size = result.readUint32LE(i);
195
+ const size = readUint32(result, i);
195
196
  i += 4;
196
197
  const ref = q.references.get(field);
197
198
  if (size === 0) {
@@ -201,7 +202,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
201
202
  }
202
203
  else {
203
204
  i++;
204
- let id = result.readUInt32LE(i);
205
+ let id = readUint32(result, i);
205
206
  i += 4;
206
207
  const refItem = {
207
208
  id,
@@ -216,7 +217,7 @@ export const readAllFields = (q, result, offset, end, item, id) => {
216
217
  const field = result[i];
217
218
  i++;
218
219
  const ref = q.references.get(field);
219
- const size = result.readUint32LE(i);
220
+ const size = readUint32(result, i);
220
221
  i += 4;
221
222
  const refs = resultToObject(ref, result, size + i + 4, i);
222
223
  // @ts-ignore
@@ -230,13 +231,13 @@ export const readAllFields = (q, result, offset, end, item, id) => {
230
231
  const prop = q.schema.reverseProps[index];
231
232
  if (prop.typeIndex === BINARY) {
232
233
  q.include.propsRead[index] = id;
233
- const size = result.readUint32LE(i);
234
- addField(prop, new Uint8Array(result.buffer, i + 4 + 2, size - 6), item);
234
+ const size = readUint32(result, i);
235
+ addField(prop, result.subarray(i + 6, i + size), item);
235
236
  i += size + 4;
236
237
  }
237
238
  else if (prop.typeIndex === STRING) {
238
239
  q.include.propsRead[index] = id;
239
- const size = result.readUint32LE(i);
240
+ const size = readUint32(result, i);
240
241
  if (size === 0) {
241
242
  addField(prop, '', item);
242
243
  }
@@ -247,27 +248,52 @@ export const readAllFields = (q, result, offset, end, item, id) => {
247
248
  }
248
249
  else if (prop.typeIndex == TEXT) {
249
250
  q.include.propsRead[index] = id;
250
- const size = result.readUint32LE(i);
251
+ const size = readUint32(result, i);
252
+ // if queryDef.LANG do different
253
+ if (size === 0) {
254
+ // LATER
255
+ // addField(prop, '', item)
256
+ }
257
+ else {
258
+ if (q.lang != langCodesMap.get('none')) {
259
+ addField(prop, read(result, i + 4, size), item);
260
+ }
261
+ else {
262
+ addField(prop, read(result, i + 4, size), item, false, result[i + 4]);
263
+ }
264
+ }
265
+ const lan =
251
266
  // TODO Read text
252
267
  //if (size === 0) {
253
268
  // addField(prop, '', item)
254
269
  //} else {
255
270
  // addField(prop, read(result, i + 4, size), item)
256
271
  //}
257
- i += size + 4;
272
+ (i += size + 4);
258
273
  }
259
274
  else if (prop.typeIndex === ALIAS) {
260
275
  q.include.propsRead[index] = id;
261
- const size = result.readUint32LE(i);
276
+ const size = readUint32(result, i);
262
277
  i += 4;
263
278
  if (size === 0) {
264
279
  addField(prop, '', item);
265
280
  }
266
281
  else {
267
- const string = result.toString('utf8', i, (i += size));
282
+ const string = readUtf8(result, i, size);
283
+ i += size;
268
284
  addField(prop, string, item);
269
285
  }
270
286
  }
287
+ else if (prop.typeIndex == VECTOR) {
288
+ q.include.propsRead[index] = id;
289
+ const size = readUint32(result, i);
290
+ const arr = new Float32Array(size / 4);
291
+ for (let j = 0; j < size; j += 4) {
292
+ arr[j / 4] = readFloatLE(result, i + 4 + j);
293
+ }
294
+ addField(prop, arr, item);
295
+ i += size + 4;
296
+ }
271
297
  }
272
298
  }
273
299
  // to add defaults - may not optimal for performance
@@ -275,14 +301,14 @@ export const readAllFields = (q, result, offset, end, item, id) => {
275
301
  return i - offset;
276
302
  };
277
303
  export const resultToObject = (q, result, end, offset = 0) => {
278
- const len = result.readUint32LE(offset);
304
+ const len = readUint32(result, offset);
279
305
  if (len === 0) {
280
306
  return [];
281
307
  }
282
308
  let items = [];
283
309
  let i = 5 + offset;
284
310
  while (i < end) {
285
- let id = result.readUInt32LE(i);
311
+ const id = readUint32(result, i);
286
312
  i += 4;
287
313
  const item = {
288
314
  id,
@@ -41,12 +41,12 @@ export const subscribe = (q, onData, onError) => {
41
41
  return q;
42
42
  };
43
43
  sub.subs.add(fn);
44
+ if (sub.res) {
45
+ onData(sub.res);
46
+ }
44
47
  if (!sub.inProgress) {
45
48
  runSubscription(sub);
46
49
  }
47
- else if (sub.res) {
48
- onData(sub.res);
49
- }
50
50
  return close;
51
51
  };
52
52
  //# sourceMappingURL=index.js.map