nesoi 3.2.1 → 3.2.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 (46) hide show
  1. package/lib/compiler/elements/constants.element.js +1 -1
  2. package/lib/compiler/error.d.ts +1 -0
  3. package/lib/compiler/error.js +3 -0
  4. package/lib/compiler/stages/4_build_schemas_stage.js +14 -0
  5. package/lib/compiler/treeshake.js +3 -1
  6. package/lib/elements/blocks/job/internal/resource_job.js +1 -1
  7. package/lib/elements/blocks/resource/resource.builder.js +1 -1
  8. package/lib/elements/blocks/resource/resource.js +1 -0
  9. package/lib/elements/edge/externals/externals.builder.d.ts +2 -0
  10. package/lib/elements/edge/externals/externals.builder.js +6 -1
  11. package/lib/elements/edge/externals/externals.schema.d.ts +2 -1
  12. package/lib/elements/edge/externals/externals.schema.js +3 -1
  13. package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +2 -2
  14. package/lib/elements/entities/bucket/adapters/bucket_adapter.js +2 -2
  15. package/lib/elements/entities/bucket/adapters/memory.nql.d.ts +1 -1
  16. package/lib/elements/entities/bucket/adapters/memory.nql.js +9 -5
  17. package/lib/elements/entities/bucket/bucket.d.ts +15 -3
  18. package/lib/elements/entities/bucket/bucket.js +51 -15
  19. package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +14 -10
  20. package/lib/elements/entities/bucket/cache/bucket_cache.js +92 -58
  21. package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +11 -0
  22. package/lib/elements/entities/bucket/graph/bucket_graph.js +57 -3
  23. package/lib/elements/entities/bucket/model/bucket_model.schema.js +16 -13
  24. package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +3 -4
  25. package/lib/elements/entities/bucket/query/nql_compiler.js +7 -1
  26. package/lib/elements/entities/bucket/query/nql_engine.d.ts +2 -2
  27. package/lib/elements/entities/bucket/query/nql_engine.js +8 -4
  28. package/lib/elements/entities/bucket/view/bucket_view.js +65 -12
  29. package/lib/elements/entities/constants/constants.schema.d.ts +2 -4
  30. package/lib/engine/apps/inline.app.js +1 -0
  31. package/lib/engine/module.d.ts +2 -2
  32. package/lib/engine/module.js +9 -2
  33. package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +5 -0
  34. package/lib/engine/transaction/nodes/bucket.trx_node.js +10 -0
  35. package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +2 -0
  36. package/lib/engine/transaction/nodes/bucket_query.trx_node.js +15 -4
  37. package/lib/engine/transaction/trx_node.d.ts +1 -2
  38. package/lib/engine/util/log.d.ts +1 -1
  39. package/lib/engine/util/log.js +1 -0
  40. package/package.json +1 -1
  41. package/tools/joaquin/bucket.d.ts +23 -3
  42. package/tools/joaquin/bucket.js +48 -20
  43. package/tools/joaquin/job.js +4 -4
  44. package/tsconfig.build.tsbuildinfo +1 -1
  45. /package/lib/engine/apps/distributed/inc/{test.d.ts → sandbox.d.ts} +0 -0
  46. /package/lib/engine/apps/distributed/inc/{test.js → sandbox.js} +0 -0
@@ -38,7 +38,7 @@ class ConstantsElement extends element_1.Element {
38
38
  });
39
39
  enums[key] = {
40
40
  '#data': data,
41
- name: dump_helpers_1.DumpHelpers.dumpValueToType(key),
41
+ name: dump_helpers_1.DumpHelpers.dumpValueToType(val.name),
42
42
  options: type
43
43
  };
44
44
  });
@@ -6,6 +6,7 @@ export declare class CompilerError extends Error {
6
6
  static UnmetModuleDependency(from: string, name: string): CompilerError;
7
7
  static UnmetDependency(from: string, name: string): CompilerError;
8
8
  static CircularDependency(): CompilerError;
9
+ static ExternalEnumNotFound(name: string): CompilerError;
9
10
  }
10
11
  export declare class HelperError extends Error {
11
12
  constructor(message: string);
@@ -23,6 +23,9 @@ class CompilerError extends Error {
23
23
  static CircularDependency() {
24
24
  return new CompilerError('Circular dependency found while building.');
25
25
  }
26
+ static ExternalEnumNotFound(name) {
27
+ return new CompilerError(`External enum '${name}' not found`);
28
+ }
26
29
  }
27
30
  exports.CompilerError = CompilerError;
28
31
  class HelperError extends Error {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BuildSchemasStage = void 0;
4
4
  const log_1 = require("../../engine/util/log");
5
+ const error_1 = require("../error");
5
6
  /**
6
7
  * [Compiler Stage #4]
7
8
  * Build the node schemas, following the graph resolved on previous steps.
@@ -41,6 +42,19 @@ class BuildSchemasStage {
41
42
  return;
42
43
  }
43
44
  await module.buildNode(node, this.compiler.tree);
45
+ // Inject external enums on the module schema
46
+ if (node.type === 'externals') {
47
+ const schema = node.schema;
48
+ for (const e in schema.enums) {
49
+ const enumDep = schema.enums[e];
50
+ const enumModule = this.compiler.modules[enumDep.module].module;
51
+ const constants = enumModule.schema.constants;
52
+ if (!constants.enums[enumDep.name]) {
53
+ throw error_1.CompilerError.ExternalEnumNotFound(e);
54
+ }
55
+ module.schema.constants.enums[enumDep.refName] = constants.enums[enumDep.name];
56
+ }
57
+ }
44
58
  });
45
59
  const t = new Date().getTime();
46
60
  log_1.Log.debug('compiler', 'stage.build_schemas', `[t: ${(t - t0) / 1000} ms]`);
@@ -21,11 +21,13 @@ class Treeshake {
21
21
  const buckets = b.buckets;
22
22
  const messages = b.messages;
23
23
  const jobs = b.jobs;
24
+ const enums = b.enums;
24
25
  log_1.Log.trace('compiler', 'treeshake', `${' '.repeat(depth)} └ Treeshaking node ${(0, log_1.scopeTag)($b, node.name)}`);
25
26
  node.dependencies = [
26
27
  ...Object.values(buckets),
27
28
  ...Object.values(messages),
28
- ...Object.values(jobs)
29
+ ...Object.values(jobs),
30
+ ...Object.values(enums).map(dep => new dependency_1.$Dependency(node.module, 'constants', `${dep.module}::*`))
29
31
  ];
30
32
  node.dependencies = this.cleanNodeDependencies(node);
31
33
  }
@@ -30,7 +30,7 @@ class ResourceJob {
30
30
  obj = await scope.execMethod({ ...$, obj, bucket: scope.bucket });
31
31
  }
32
32
  if (scope.afterMethod) {
33
- obj = await scope.afterMethod({ ...$, obj, bucket: scope.bucket });
33
+ await scope.afterMethod({ ...$, obj, bucket: scope.bucket });
34
34
  }
35
35
  return obj;
36
36
  }
@@ -63,7 +63,7 @@ class ResourceBuilder extends block_builder_1.BlockBuilder {
63
63
  const jobBuilder = new resource_job_builder_1.ResourceJobBuilder(this.module, name, this._bucket.refName, 'query', alias, resource_1.Resource.query, this._authn)
64
64
  .input($ => ({
65
65
  view: $.enum(views).default(views[0]),
66
- query: $.dict($.any).default({}),
66
+ query: $.dict($.any.optional).default({}),
67
67
  page: $.int.default(0),
68
68
  perPage: $.int.default(10)
69
69
  }))
@@ -120,6 +120,7 @@ class Resource extends block_1.Block {
120
120
  if (type === 'query is empty') {
121
121
  out = !(await trx.bucket(bucket.refName)
122
122
  .query(arg)
123
+ .params(obj)
123
124
  .first());
124
125
  }
125
126
  else if (type === 'has no link') {
@@ -20,11 +20,13 @@ export declare class ExternalsBuilder<Space extends $Space, ModuleName extends k
20
20
  private messages;
21
21
  private jobs;
22
22
  private machines;
23
+ private enums;
23
24
  constructor(module: string);
24
25
  bucket<M extends keyof Space['modules'], B extends ExternalBucketRefName<Space, ModuleName>>(ref: B): this;
25
26
  message<M extends Exclude<keyof Space['modules'], ModuleName>, B extends keyof Space['modules'][M]['messages']>(ref: `${M & string}::${B & string}`): this;
26
27
  job<M extends Exclude<keyof Space['modules'], ModuleName>, B extends keyof Space['modules'][M]['jobs']>(ref: `${M & string}::${B & string}`): this;
27
28
  machine<M extends Exclude<keyof Space['modules'], ModuleName>, B extends keyof Space['modules'][M]['machines']>(ref: `${M & string}::${B & string}`): this;
29
+ enum<M extends Exclude<keyof Space['modules'], ModuleName>, B extends keyof Space['modules'][M]['constants']['enums']>(ref: `${M & string}::${B & string}`): this;
28
30
  static merge(to: AnyExternalsBuilder, from: AnyExternalsBuilder): void;
29
31
  static build(node: ExternalsBuilderNode): $Externals;
30
32
  }
@@ -16,6 +16,7 @@ class ExternalsBuilder {
16
16
  this.messages = {};
17
17
  this.jobs = {};
18
18
  this.machines = {};
19
+ this.enums = {};
19
20
  }
20
21
  bucket(ref) {
21
22
  this.buckets[ref] = new dependency_1.$Dependency(this.module, 'bucket', ref);
@@ -33,13 +34,17 @@ class ExternalsBuilder {
33
34
  this.machines[ref] = new dependency_1.$Dependency(this.module, 'machine', ref);
34
35
  return this;
35
36
  }
37
+ enum(ref) {
38
+ this.enums[ref] = new dependency_1.$Dependency(this.module, 'enum', ref);
39
+ return this;
40
+ }
36
41
  static merge(to, from) {
37
42
  Object.assign(to.buckets, from.buckets);
38
43
  Object.assign(to.jobs, from.jobs);
39
44
  }
40
45
  // Build
41
46
  static build(node) {
42
- node.schema = new externals_schema_1.$Externals(node.module, node.builder.buckets, node.builder.messages, node.builder.jobs, node.builder.machines);
47
+ node.schema = new externals_schema_1.$Externals(node.module, node.builder.buckets, node.builder.messages, node.builder.jobs, node.builder.machines, node.builder.enums);
43
48
  return node.schema;
44
49
  }
45
50
  }
@@ -9,8 +9,9 @@ export declare class $Externals {
9
9
  messages: Record<string, $Dependency>;
10
10
  jobs: Record<string, $Dependency>;
11
11
  machines: Record<string, $Dependency>;
12
+ enums: Record<string, $Dependency>;
12
13
  $t: "externals";
13
14
  module: string;
14
- constructor(name: string, buckets?: Record<string, $Dependency>, messages?: Record<string, $Dependency>, jobs?: Record<string, $Dependency>, machines?: Record<string, $Dependency>);
15
+ constructor(name: string, buckets?: Record<string, $Dependency>, messages?: Record<string, $Dependency>, jobs?: Record<string, $Dependency>, machines?: Record<string, $Dependency>, enums?: Record<string, $Dependency>);
15
16
  static merge(to: $Externals, from: $Externals): void;
16
17
  }
@@ -6,12 +6,13 @@ exports.$Externals = void 0;
6
6
  * @subcategory Edge
7
7
  */
8
8
  class $Externals {
9
- constructor(name, buckets = {}, messages = {}, jobs = {}, machines = {}) {
9
+ constructor(name, buckets = {}, messages = {}, jobs = {}, machines = {}, enums = {}) {
10
10
  this.name = name;
11
11
  this.buckets = buckets;
12
12
  this.messages = messages;
13
13
  this.jobs = jobs;
14
14
  this.machines = machines;
15
+ this.enums = enums;
15
16
  this.$t = 'externals';
16
17
  this.module = this.name;
17
18
  }
@@ -20,6 +21,7 @@ class $Externals {
20
21
  Object.assign(to.messages, from.messages);
21
22
  Object.assign(to.jobs, from.jobs);
22
23
  Object.assign(to.machines, from.machines);
24
+ Object.assign(to.enums, from.enums);
23
25
  }
24
26
  }
25
27
  exports.$Externals = $Externals;
@@ -136,10 +136,10 @@ export declare abstract class BucketAdapter<Obj extends NesoiObj> {
136
136
  /**
137
137
  * Return the results of a query
138
138
  */
139
- query<MetadataOnly extends boolean>(trx: AnyTrxNode, query: NQL_AnyQuery, pagination?: NQL_Pagination, params?: Record<string, any>, config?: {
139
+ query<MetadataOnly extends boolean>(trx: AnyTrxNode, query: NQL_AnyQuery, pagination?: NQL_Pagination, params?: Record<string, any>[], config?: {
140
140
  view?: string;
141
141
  metadataOnly?: MetadataOnly;
142
- }): Promise<NQL_Result<MetadataOnly extends true ? {
142
+ }, runner?: NQLRunner): Promise<NQL_Result<MetadataOnly extends true ? {
143
143
  id: Obj['id'];
144
144
  [x: string]: any;
145
145
  } : Obj>>;
@@ -25,14 +25,14 @@ class BucketAdapter {
25
25
  /**
26
26
  * Return the results of a query
27
27
  */
28
- async query(trx, query, pagination, params, config) {
28
+ async query(trx, query, pagination, params, config, runner) {
29
29
  const module = trx_node_1.TrxNode.getModule(trx);
30
30
  const refName = (module.name === this.schema.module
31
31
  ? '' : `${this.schema.module}::`)
32
32
  + this.schema.name;
33
33
  const compiled = await nql_compiler_1.NQL_Compiler.build(module, refName, query);
34
34
  const view = config?.view ? this.schema.views[config.view] : undefined;
35
- const result = await module.nql.run(trx, compiled, pagination, params, view);
35
+ const result = await module.nql.run(trx, compiled, pagination, params, view, runner);
36
36
  if (config?.metadataOnly) {
37
37
  result.data = result.data.map(obj => ({
38
38
  id: obj.id,
@@ -10,7 +10,7 @@ export declare class MemoryNQLRunner extends NQLRunner {
10
10
  protected adapter?: AnyMemoryBucketAdapter;
11
11
  constructor();
12
12
  bind(adapter: AnyMemoryBucketAdapter): void;
13
- run(trx: AnyTrxNode, part: NQL_Part, params: Obj, pagination?: NQL_Pagination): Promise<{
13
+ run(trx: AnyTrxNode, part: NQL_Part, params: Obj[], pagination?: NQL_Pagination): Promise<{
14
14
  data: any[];
15
15
  totalItems: number | undefined;
16
16
  page: number | undefined;
@@ -21,7 +21,7 @@ class MemoryNQLRunner extends nql_engine_1.NQLRunner {
21
21
  let response;
22
22
  // Empty query, don't filter data
23
23
  if (part.union.inters.length === 0) {
24
- response = data;
24
+ response = { ...data };
25
25
  }
26
26
  // Non-empty query
27
27
  else {
@@ -105,7 +105,7 @@ class MemoryNQLRunner extends nql_engine_1.NQLRunner {
105
105
  for (const rule of inter.rules) {
106
106
  // <Union>
107
107
  if ('inters' in rule) {
108
- if (!_union(rule, objs, objs))
108
+ if (!_union(rule, objs, params))
109
109
  return false;
110
110
  }
111
111
  // <Rule>
@@ -132,8 +132,12 @@ class MemoryNQLRunner extends nql_engine_1.NQLRunner {
132
132
  continue;
133
133
  }
134
134
  const obj = objs[id];
135
- let match = _obj(rule, obj, params);
136
- // console.log(` -> match: ${match}\n`)
135
+ let match = false;
136
+ for (const paramGroup of params) {
137
+ match = _obj(rule, obj, paramGroup);
138
+ if (match)
139
+ break;
140
+ }
137
141
  if (rule.not) {
138
142
  match = !match;
139
143
  }
@@ -174,7 +178,7 @@ class MemoryNQLRunner extends nql_engine_1.NQLRunner {
174
178
  let queryValue;
175
179
  // Value is a subquery, run union
176
180
  if ('subquery' in rule.value) {
177
- const subOut = _union(rule.value.subquery.union, objs, params);
181
+ const subOut = _union(rule.value.subquery.union, objs, [params]);
178
182
  const subList = Object.values(subOut);
179
183
  // Subquery operator is for a list, filter
180
184
  if (rule.op === 'in' || rule.op === 'contains_any') {
@@ -4,6 +4,7 @@ import { $Module, ViewName, ViewObj } from "../../../schema";
4
4
  import { $Bucket } from './bucket.schema';
5
5
  import { BucketAdapter } from './adapters/bucket_adapter';
6
6
  import { BucketConfig } from './bucket.config';
7
+ import { AnyBucketCache } from './cache/bucket_cache';
7
8
  import { BucketGraph } from './graph/bucket_graph';
8
9
  import { NQL_AnyQuery, NQL_Pagination } from './query/nql.schema';
9
10
  import { CreateObj, PatchObj, PutObj } from './bucket.types';
@@ -32,7 +33,7 @@ export declare class Bucket<M extends $Module, $ extends $Bucket> {
32
33
  private config?;
33
34
  services: Record<string, IService>;
34
35
  adapter: BucketAdapter<$['#data']>;
35
- private cache?;
36
+ cache?: AnyBucketCache;
36
37
  graph: BucketGraph<M, $>;
37
38
  private views;
38
39
  drive?: DriveAdapter;
@@ -85,7 +86,7 @@ export declare class Bucket<M extends $Module, $ extends $Bucket> {
85
86
  no_tenancy: boolean;
86
87
  }): Promise<Obj[]>;
87
88
  /**
88
- * Read raw entity of a graph link
89
+ * Read raw entity of a graph link for 1 object
89
90
  *
90
91
  * - Options:
91
92
  * - `silent`: If not found, return `undefined` instead of throwing an exception
@@ -95,6 +96,17 @@ export declare class Bucket<M extends $Module, $ extends $Bucket> {
95
96
  silent?: boolean;
96
97
  no_tenancy?: boolean;
97
98
  }): Promise<Link['#many'] extends true ? Obj[] : (Obj | undefined)>;
99
+ /**
100
+ * Read raw entities of a graph link for N objects
101
+ *
102
+ * - Options:
103
+ * - `silent`: If not found, return `undefined` instead of throwing an exception
104
+ * - `no_tenancy`: Don't apply tenancy rules.
105
+ */
106
+ readManyLinks<LinkName extends keyof $['graph']['links'], Link extends $['graph']['links'][LinkName], LinkBucket extends Link['#bucket'], V extends ViewName<LinkBucket>, Obj extends ViewObj<LinkBucket, V>>(trx: AnyTrxNode, ids: $['#data']['id'][], link: LinkName, options?: {
107
+ silent?: boolean;
108
+ no_tenancy?: boolean;
109
+ }): Promise<Link['#many'] extends true ? Obj[] : (Obj | undefined)>;
98
110
  /**
99
111
  * Read the view of an entity of a graph link
100
112
  *
@@ -190,7 +202,7 @@ export declare class Bucket<M extends $Module, $ extends $Bucket> {
190
202
  */
191
203
  query<V extends ViewName<$>, Obj extends ViewObj<$, V>>(trx: AnyTrxNode, query: NQL_AnyQuery, pagination?: NQL_Pagination, view?: V, options?: {
192
204
  no_tenancy?: boolean;
193
- params?: Record<string, any>;
205
+ params?: Record<string, any>[];
194
206
  }): Promise<NQL_Result<Obj>>;
195
207
  /**
196
208
  * Add `created_by`, `created_at`, `updated_by` and `updated_at` fields to object
@@ -45,7 +45,7 @@ class Bucket {
45
45
  this.views = views;
46
46
  // Cache
47
47
  if (this.config?.cache) {
48
- this.cache = new bucket_cache_1.BucketCache(this.schema.name, this.adapter, this.config.cache);
48
+ this.cache = new bucket_cache_1.BucketCache(this, this.config.cache);
49
49
  }
50
50
  // Drive
51
51
  if (this.config?.drive) {
@@ -79,8 +79,9 @@ class Bucket {
79
79
  : this.getTenancyQuery(trx);
80
80
  let raw;
81
81
  // With Tenancy
82
+ const adapter = this.cache || this.adapter;
82
83
  if (tenancy) {
83
- const result = await this.adapter.query(trx, {
84
+ const result = await adapter.query(trx, {
84
85
  id,
85
86
  '#and': tenancy
86
87
  }, { perPage: 1 }, undefined, options?.query_view ? { view: options?.query_view } : undefined);
@@ -88,9 +89,7 @@ class Bucket {
88
89
  }
89
90
  // Without Tenancy
90
91
  else {
91
- raw = this.cache
92
- ? await this.cache.get(trx, id)
93
- : await this.adapter.get(trx, id);
92
+ raw = await adapter.get(trx, id);
94
93
  }
95
94
  // Empty result
96
95
  if (!raw) {
@@ -119,15 +118,14 @@ class Bucket {
119
118
  : this.getTenancyQuery(trx);
120
119
  let raws;
121
120
  // With Tenancy
121
+ const adapter = this.cache || this.adapter;
122
122
  if (tenancy) {
123
- const result = await this.adapter.query(trx, tenancy, undefined, options?.query_view ? { view: options?.query_view } : undefined);
123
+ const result = await adapter.query(trx, tenancy, undefined, options?.query_view ? [{ view: options?.query_view }] : undefined);
124
124
  raws = result.data;
125
125
  }
126
126
  // Without Tenancy
127
127
  else {
128
- raws = this.cache
129
- ? await this.cache.index(trx)
130
- : await this.adapter.index(trx);
128
+ raws = await this.adapter.index(trx);
131
129
  }
132
130
  // Encryption
133
131
  if (this.schema.model.hasEncryptedField) {
@@ -169,7 +167,7 @@ class Bucket {
169
167
  }
170
168
  // Graph
171
169
  /**
172
- * Read raw entity of a graph link
170
+ * Read raw entity of a graph link for 1 object
173
171
  *
174
172
  * - Options:
175
173
  * - `silent`: If not found, return `undefined` instead of throwing an exception
@@ -201,6 +199,44 @@ class Bucket {
201
199
  }
202
200
  return linkObj;
203
201
  }
202
+ /**
203
+ * Read raw entities of a graph link for N objects
204
+ *
205
+ * - Options:
206
+ * - `silent`: If not found, return `undefined` instead of throwing an exception
207
+ * - `no_tenancy`: Don't apply tenancy rules.
208
+ */
209
+ async readManyLinks(trx, ids, link, options) {
210
+ log_1.Log.debug('bucket', this.schema.name, `Read Link, ids=${ids} l=${link}`);
211
+ // Validate IDs
212
+ for (const id of ids) {
213
+ if (typeof id !== 'string' && typeof id !== 'number') {
214
+ throw error_1.NesoiError.Bucket.InvalidId({ bucket: this.schema.alias, id });
215
+ }
216
+ }
217
+ // Read object
218
+ const objs = await this.query(trx, {
219
+ 'id in': ids
220
+ }).then(res => res.data);
221
+ // Empty response
222
+ if (!objs.length) {
223
+ const schema = this.schema.graph.links[link];
224
+ if (schema.many) {
225
+ return [];
226
+ }
227
+ return undefined;
228
+ }
229
+ // Read link
230
+ const linkObj = await this.graph.readManyLinks(trx, objs, link, options);
231
+ // TODO
232
+ // // Encryption
233
+ // if (linkObj) {
234
+ // if (this.schema.model.hasEncryptedField) {
235
+ // await this.decrypt(trx, linkObj);
236
+ // }
237
+ // }
238
+ return linkObj;
239
+ }
204
240
  /**
205
241
  * Read the view of an entity of a graph link
206
242
  *
@@ -388,9 +424,10 @@ class Bucket {
388
424
  // Read old object, if safe, to check if it exists
389
425
  let oldObj;
390
426
  if (!options?.unsafe) {
427
+ const adapter = this.cache || this.adapter;
391
428
  // With Tenancy
392
429
  if (tenancy) {
393
- const result = await this.adapter.query(trx, {
430
+ const result = await adapter.query(trx, {
394
431
  id: obj.id,
395
432
  '#and': tenancy
396
433
  }, { perPage: 1 }, undefined, {
@@ -400,9 +437,7 @@ class Bucket {
400
437
  }
401
438
  // Without Tenancy
402
439
  else {
403
- oldObj = this.cache
404
- ? await this.cache.get(trx, obj['id'])
405
- : await this.adapter.get(trx, obj['id']);
440
+ oldObj = await adapter.get(trx, obj['id']);
406
441
  }
407
442
  // Empty response
408
443
  if (!oldObj) {
@@ -678,7 +713,8 @@ class Bucket {
678
713
  '#and': tenancy
679
714
  };
680
715
  // Query
681
- const result = await this.adapter.query(trx, query, pagination, options?.params);
716
+ const adapter = this.cache || this.adapter;
717
+ const result = await adapter.query(trx, query, pagination, options?.params);
682
718
  if (!result.data.length)
683
719
  return result;
684
720
  // Encryption
@@ -1,10 +1,9 @@
1
1
  import { BucketConfig } from '../bucket.config';
2
2
  import { AnyTrxNode } from "../../../../engine/transaction/trx_node";
3
3
  import { NesoiObj } from "../../../../engine/data/obj";
4
- import { AnyBucketAdapter } from '../adapters/bucket_adapter';
5
- import { $BucketView } from '../view/bucket_view.schema';
6
4
  import { NQL_AnyQuery, NQL_Pagination } from '../query/nql.schema';
7
5
  import { NQL_Result } from '../query/nql_engine';
6
+ import { AnyBucket } from '../bucket';
8
7
  export type BucketCacheSync<T> = {
9
8
  obj: T;
10
9
  updateEpoch: number;
@@ -14,28 +13,33 @@ export type BucketCacheSync<T> = {
14
13
  * @subcategory Entity
15
14
  * */
16
15
  export declare class BucketCacheEntry<Obj extends NesoiObj> {
16
+ __update_epoch: number;
17
+ __sync_epoch: number;
17
18
  id: Obj['id'];
18
- obj: Obj;
19
- updateEpoch: number;
20
- syncEpoch: number;
21
- constructor(id: Obj['id'], obj: Obj, updateEpoch: number, syncEpoch: number);
19
+ constructor(obj: Obj, __update_epoch: number, __sync_epoch: number);
22
20
  }
23
21
  /**
24
22
  * @category Elements
25
23
  * @subcategory Entity
26
24
  * */
27
25
  export declare class BucketCache<Obj extends NesoiObj> {
28
- private bucketName;
29
- private outerAdapter;
26
+ private bucket;
30
27
  private config;
31
28
  private lastUpdateEpoch?;
32
29
  private lastSyncEpoch?;
33
30
  private lastHash?;
34
31
  private innerAdapter;
35
- constructor(bucketName: string, outerAdapter: AnyBucketAdapter, config: NonNullable<BucketConfig<any, any, any>['cache']>);
32
+ private outerAdapter;
33
+ constructor(bucket: AnyBucket, config: NonNullable<BucketConfig<any, any, any>['cache']>);
36
34
  get(trx: AnyTrxNode, id: NesoiObj['id']): Promise<any>;
37
35
  index(trx: AnyTrxNode): Promise<any[]>;
38
- query(trx: AnyTrxNode, view: $BucketView, query: NQL_AnyQuery, pagination?: NQL_Pagination): Promise<NQL_Result<any> | Obj[]>;
36
+ query<MetadataOnly extends boolean>(trx: AnyTrxNode, query: NQL_AnyQuery, pagination?: NQL_Pagination, params?: Record<string, any>[], config?: {
37
+ view?: string;
38
+ metadataOnly?: MetadataOnly;
39
+ }): Promise<NQL_Result<MetadataOnly extends true ? {
40
+ id: Obj['id'];
41
+ [x: string]: any;
42
+ } : Obj>>;
39
43
  private syncOne;
40
44
  private syncOneAndPast;
41
45
  private syncAll;