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
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BucketView = void 0;
7
+ const trx_node_1 = require("../../../../engine/transaction/trx_node");
7
8
  const promise_1 = __importDefault(require("../../../../engine/util/promise"));
8
9
  const error_1 = require("../../../../engine/data/error");
9
10
  const tree_1 = require("../../../../engine/data/tree");
11
+ const dependency_1 = require("../../../../engine/dependency");
10
12
  class ViewValue {
11
13
  constructor() {
12
14
  this.value = undefined;
@@ -27,6 +29,7 @@ class BucketView {
27
29
  Object.assign(parsed, raw);
28
30
  }
29
31
  let layer = Object.values(this.schema.fields).map(field => ({
32
+ bucket: this.bucket,
30
33
  field,
31
34
  data: [{
32
35
  raw,
@@ -54,6 +57,7 @@ class BucketView {
54
57
  parseds.push(parsed);
55
58
  }
56
59
  let layer = Object.values(this.schema.fields).map(field => ({
60
+ bucket: this.bucket,
57
61
  field,
58
62
  data: raws.map((raw, i) => ({
59
63
  raw,
@@ -89,7 +93,7 @@ class BucketView {
89
93
  for (const node of layer) {
90
94
  if (node.field.scope !== 'graph')
91
95
  continue;
92
- await this.parseGraphProp(trx, node);
96
+ next.push(...await this.parseGraphProp(trx, node));
93
97
  }
94
98
  // Drive props
95
99
  for (const node of layer) {
@@ -109,6 +113,7 @@ class BucketView {
109
113
  }
110
114
  }
111
115
  next.push(...Object.values(node.field.children).map(field => ({
116
+ bucket: node.bucket,
112
117
  field,
113
118
  data: node.data
114
119
  })));
@@ -118,6 +123,7 @@ class BucketView {
118
123
  if (!node.field.chain)
119
124
  continue;
120
125
  next.push({
126
+ bucket: node.bucket,
121
127
  field: node.field.chain,
122
128
  data: node.data.map(d => ({
123
129
  index: d.index,
@@ -144,6 +150,7 @@ class BucketView {
144
150
  if (key === '__raw')
145
151
  continue;
146
152
  next.push({
153
+ bucket: node.bucket,
147
154
  field: node.field.children[key],
148
155
  data: nextData
149
156
  });
@@ -249,7 +256,7 @@ class BucketView {
249
256
  async parseComputedProp(trx, node) {
250
257
  const meta = node.field.meta.computed;
251
258
  for (const entry of node.data) {
252
- entry.target[node.field.name] = await promise_1.default.solve(meta.fn({ trx, raw: entry.raw, bucket: this.bucket.schema }));
259
+ entry.target[node.field.name] = await promise_1.default.solve(meta.fn({ trx, raw: entry.raw, bucket: node.bucket.schema }));
253
260
  }
254
261
  }
255
262
  /**
@@ -257,23 +264,69 @@ class BucketView {
257
264
  */
258
265
  async parseGraphProp(trx, node) {
259
266
  const meta = node.field.meta.graph;
260
- for (const entry of node.data) {
261
- let link;
262
- if (!meta.view) {
263
- link = this.bucket.graph.readLink(trx, entry.raw, meta.link, { silent: true });
267
+ const links = await node.bucket.graph.readManyLinks(trx, node.data.map(entry => entry.raw), meta.link, { silent: true });
268
+ for (let i = 0; i < links.length; i++) {
269
+ if (meta.view) {
270
+ const link = node.bucket.schema.graph.links[meta.link];
271
+ node.data[i].target[node.field.name] = link.many ? [] : {};
264
272
  }
265
273
  else {
266
- link = this.bucket.graph.viewLink(trx, entry.raw, meta.link, meta.view, { silent: true });
274
+ node.data[i].target[node.field.name] = links[i];
267
275
  }
268
- entry.target[node.field.name] = await promise_1.default.solve(link);
269
276
  }
277
+ let next = [];
278
+ if (meta.view) {
279
+ const schema = node.bucket.schema;
280
+ const otherBucketDep = schema.graph.links[meta.link].bucket;
281
+ const module = trx_node_1.TrxNode.getModule(trx);
282
+ const otherBucket = dependency_1.$Dependency.resolve(module.schema, otherBucketDep);
283
+ const view = otherBucket.views[meta.view];
284
+ const { __raw, ...v } = view.fields;
285
+ const link = node.bucket.schema.graph.links[meta.link];
286
+ let nextData;
287
+ if (link.many) {
288
+ const _links = links;
289
+ for (let i = 0; i < _links.length; i++) {
290
+ const target = node.data[i].target[node.field.name];
291
+ for (let j = 0; j < _links[i].length; j++) {
292
+ target.push(__raw ? { ..._links[i][j] } : {});
293
+ target[j].$v = meta.view;
294
+ }
295
+ }
296
+ nextData = _links.map((ll, i) => ll.map((l, j) => ({ value: l, target: node.data[i].target[node.field.name][j] }))).flat(1);
297
+ }
298
+ else {
299
+ const _links = links;
300
+ for (let i = 0; i < _links.length; i++) {
301
+ const target = node.data[i].target[node.field.name];
302
+ if (__raw) {
303
+ Object.assign(target, _links[i]);
304
+ }
305
+ target.$v = meta.view;
306
+ }
307
+ nextData = _links.map((l, i) => ({
308
+ value: l, target: node.data[i].target[node.field.name]
309
+ }));
310
+ }
311
+ next = Object.values(v).map(field => ({
312
+ bucket: module.buckets[otherBucketDep.refName],
313
+ field,
314
+ data: nextData.map($ => ({
315
+ raw: $.value,
316
+ value: $.value,
317
+ index: [],
318
+ target: $.target
319
+ }))
320
+ }));
321
+ }
322
+ return next;
270
323
  }
271
324
  /**
272
325
  * [drive]
273
326
  */
274
327
  async parseDriveProp(trx, node) {
275
- if (!this.bucket.drive) {
276
- throw error_1.NesoiError.Bucket.Drive.NoAdapter({ bucket: this.bucket.schema.alias });
328
+ if (!node.bucket.drive) {
329
+ throw error_1.NesoiError.Bucket.Drive.NoAdapter({ bucket: node.bucket.schema.alias });
277
330
  }
278
331
  const meta = node.field.meta.drive;
279
332
  for (const entry of node.data) {
@@ -281,12 +334,12 @@ class BucketView {
281
334
  if (Array.isArray(value)) {
282
335
  const public_urls = [];
283
336
  for (const obj of value) {
284
- public_urls.push(await this.bucket.drive.public(obj));
337
+ public_urls.push(await node.bucket.drive.public(obj));
285
338
  }
286
339
  entry.target[node.field.name] = public_urls;
287
340
  }
288
341
  else {
289
- entry.target[node.field.name] = await this.bucket.drive.public(value);
342
+ entry.target[node.field.name] = await node.bucket.drive.public(value);
290
343
  }
291
344
  }
292
345
  }
@@ -54,10 +54,8 @@ type CompatibleMessageKey<Data, Subs extends string> = {
54
54
  }[keyof Data];
55
55
  type ParseMessageEnumpath<Message extends $Message, Path extends string, Subs extends string> = Path extends `${infer X}.#` ? `${X}.{${CompatibleMessageKey<Message['#parsed'], Subs> & string}}` : Path;
56
56
  export type MessageEnumpath<Module extends $Module, Message extends $Message, Modules extends Record<string, $Module>> = MergeUnion<{
57
- [M in keyof Modules]: {
58
- [K in keyof Modules[M]['constants']['#enumpath'] as M extends Module['name'] ? ParseMessageEnumpath<Message, K & string, Modules[M]['constants']['#enumpath'][K]['_subs']> : `${M & string}::${ParseMessageEnumpath<Message, K & string, Modules[M]['constants']['#enumpath'][K]['_subs']>}`]: Modules[M]['constants']['#enumpath'][K]['_enum'];
59
- };
60
- }[keyof Modules]>;
57
+ [K in keyof Module['constants']['#enumpath'] as ParseMessageEnumpath<Message, K & string, Module['constants']['#enumpath'][K]['_subs']>]: Module['constants']['#enumpath'][K]['_enum'];
58
+ }>;
61
59
  export type EnumName<Space extends $Space> = MergeUnion<{
62
60
  [M in keyof Space['modules']]: {
63
61
  [K in keyof Space['modules'][M]['constants']['enums'] as `${M & string}::${K & string}`]: Space['modules'][M]['constants']['enums'][K];
@@ -127,6 +127,7 @@ class InlineApp extends app_1.App {
127
127
  messages: Object.values(module.schema.externals.messages),
128
128
  jobs: Object.values(module.schema.externals.jobs),
129
129
  machines: Object.values(module.schema.externals.machines),
130
+ enums: Object.values(module.schema.externals.enums)
130
131
  });
131
132
  const buckets = module.schema.externals.buckets;
132
133
  Object.values(buckets).forEach(bucket => {
@@ -133,8 +133,7 @@ export declare class Module<S extends $Space, $ extends $Module> {
133
133
  }): this;
134
134
  /**
135
135
  * Include references for external elements on the module.
136
- * This allows a module to use elements from other modules directly,
137
- * on single-threaded `Apps`.
136
+ * This allows a module to use elements from other modules directly.
138
137
  * This implementation also includes transitive dependencies.
139
138
  *
140
139
  * @param daemon A `Daemon` instance
@@ -146,6 +145,7 @@ export declare class Module<S extends $Space, $ extends $Module> {
146
145
  jobs?: $Dependency[];
147
146
  messages?: $Dependency[];
148
147
  machines?: $Dependency[];
148
+ enums?: $Dependency[];
149
149
  }): this;
150
150
  /**
151
151
  * Include references for external elements on the module.
@@ -171,8 +171,7 @@ class Module {
171
171
  }
172
172
  /**
173
173
  * Include references for external elements on the module.
174
- * This allows a module to use elements from other modules directly,
175
- * on single-threaded `Apps`.
174
+ * This allows a module to use elements from other modules directly.
176
175
  * This implementation also includes transitive dependencies.
177
176
  *
178
177
  * @param daemon A `Daemon` instance
@@ -222,6 +221,14 @@ class Module {
222
221
  jobs: schema.jobs
223
222
  });
224
223
  });
224
+ dependencies.enums?.forEach(dep => {
225
+ const enumModule = modules[dep.module];
226
+ const _enum = enumModule.schema.constants.enums[dep.name];
227
+ if (!_enum) {
228
+ throw new Error(`Internal Error: unable to find enum '${dep.refName}' during injection to module '${this.name}'`);
229
+ }
230
+ this.schema.constants.enums[`${dep.refName}`] = _enum;
231
+ });
225
232
  return this;
226
233
  }
227
234
  /**
@@ -64,6 +64,11 @@ export declare class BucketTrxNode<M extends $Module, $ extends $Bucket> {
64
64
  * or `undefined` if the graph link doesn't resolve.
65
65
  */
66
66
  readLink<LinkName extends keyof $['graph']['links'], Link extends $['graph']['links'][LinkName], Obj extends Link['#bucket']['#data']>(id: $['#data']['id'], link: LinkName): Promise<Link['#many'] extends true ? Obj[] : (Obj | undefined)>;
67
+ /**
68
+ * Returns one or more objects referenced by the graph link,
69
+ * or `undefined` if the graph link doesn't resolve.
70
+ */
71
+ readManyLinks<LinkName extends keyof $['graph']['links'], Link extends $['graph']['links'][LinkName], Obj extends Link['#bucket']['#data']>(ids: $['#data']['id'][], link: LinkName): Promise<Link['#many'] extends true ? Obj[] : (Obj | undefined)>;
67
72
  /**
68
73
  * Returns one or more objects referenced by the graph link built with a view,
69
74
  * or `undefined` if the graph link doesn't resolve.
@@ -133,6 +133,16 @@ class BucketTrxNode {
133
133
  no_tenancy: !this.enableTenancy
134
134
  }));
135
135
  }
136
+ /**
137
+ * Returns one or more objects referenced by the graph link,
138
+ * or `undefined` if the graph link doesn't resolve.
139
+ */
140
+ async readManyLinks(ids, link) {
141
+ return this.wrap('readLinks', { ids, link }, trx => this.bucket.readManyLinks(trx, ids, link, {
142
+ silent: true,
143
+ no_tenancy: !this.enableTenancy
144
+ }));
145
+ }
136
146
  /**
137
147
  * Returns one or more objects referenced by the graph link built with a view,
138
148
  * or `undefined` if the graph link doesn't resolve.
@@ -14,8 +14,10 @@ export declare class BucketQueryTrxNode<M extends $Module, B extends $Bucket, V
14
14
  private query;
15
15
  private enableTenancy;
16
16
  private view?;
17
+ private _params?;
17
18
  constructor(trx: TrxNode<any, M, any>, bucket: Bucket<M, B>, query: NQL_AnyQuery, enableTenancy: boolean, view?: V | undefined);
18
19
  merge($: NQL_Query<M, B>): void;
20
+ params(value: Record<string, any>): this;
19
21
  first(): Promise<Obj | undefined>;
20
22
  firstOrFail(): Promise<Obj>;
21
23
  all(): Promise<Obj[]>;
@@ -14,6 +14,7 @@ class BucketQueryTrxNode {
14
14
  this.query = query;
15
15
  this.enableTenancy = enableTenancy;
16
16
  this.view = view;
17
+ this._params = [];
17
18
  }
18
19
  merge($) {
19
20
  const and = $['#and'];
@@ -24,6 +25,10 @@ class BucketQueryTrxNode {
24
25
  this.query['#and*'] = and; // TODO: make this a little better
25
26
  this.query['#or*'] = or; // TODO: make this a little better
26
27
  }
28
+ params(value) {
29
+ this._params = [value];
30
+ return this;
31
+ }
27
32
  async first() {
28
33
  await trx_node_1.TrxNode.open(this.trx, 'queryFirst', { schema: this.query, view: this.view });
29
34
  let results;
@@ -31,7 +36,8 @@ class BucketQueryTrxNode {
31
36
  results = await this.bucket.query(this.trx, this.query, {
32
37
  perPage: 1
33
38
  }, this.view, {
34
- no_tenancy: !this.enableTenancy
39
+ no_tenancy: !this.enableTenancy,
40
+ params: this._params
35
41
  });
36
42
  }
37
43
  catch (e) {
@@ -47,7 +53,8 @@ class BucketQueryTrxNode {
47
53
  let results;
48
54
  try {
49
55
  results = await this.bucket.query(this.trx, this.query, undefined, this.view, {
50
- no_tenancy: !this.enableTenancy
56
+ no_tenancy: !this.enableTenancy,
57
+ params: this._params
51
58
  });
52
59
  }
53
60
  catch (e) {
@@ -64,7 +71,9 @@ class BucketQueryTrxNode {
64
71
  await trx_node_1.TrxNode.open(this.trx, 'queryAll', { schema: this.query, view: this.view });
65
72
  let results;
66
73
  try {
67
- results = await this.bucket.query(this.trx, this.query, undefined, this.view);
74
+ results = await this.bucket.query(this.trx, this.query, undefined, this.view, {
75
+ params: this._params
76
+ });
68
77
  }
69
78
  catch (e) {
70
79
  throw await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
@@ -81,7 +90,9 @@ class BucketQueryTrxNode {
81
90
  await trx_node_1.TrxNode.open(this.trx, 'queryPage', { schema: this.query, pagination, view: this.view });
82
91
  let result;
83
92
  try {
84
- result = await this.bucket.query(this.trx, this.query, pagination, this.view);
93
+ result = await this.bucket.query(this.trx, this.query, pagination, this.view, {
94
+ params: this._params
95
+ });
85
96
  }
86
97
  catch (e) {
87
98
  throw await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
@@ -10,7 +10,6 @@ import { $Message } from "../../elements/entities/message/message.schema";
10
10
  import { MachineTrxNode } from './nodes/machine.trx_node';
11
11
  import { AnyUsers, AuthnRequest } from '../auth/authn';
12
12
  import { Enum } from "../../elements/entities/constants/constants";
13
- import { KeysOfUnion } from '../util/type';
14
13
  import { TopicTrxNode } from './nodes/topic.trx_node';
15
14
  type TrxNodeBlock = 'bucket' | 'message' | 'job' | 'resource' | 'machine' | 'queue' | 'topic' | 'controller';
16
15
  export type TrxNodeStatus = {
@@ -52,7 +51,7 @@ export declare class TrxNode<Space extends $Space, M extends $Module, Authn exte
52
51
  static error(node: AnyTrxNode, error: any): Promise<any>;
53
52
  message<Raw extends M['#input']['#raw'], Msg extends $Message = M['messages'][Raw['$'] & keyof M['messages']]>(raw: Raw): Promise<M['#input']['#parsed']>;
54
53
  value<K extends keyof M['constants']['values']>(key: K): M["constants"]["values"][K]["value"];
55
- enum<EnumName extends KeysOfUnion<Space['modules'][keyof Space['modules']]['constants']['enums']>>(name: EnumName): Enum<M['constants']['enums'][EnumName]>;
54
+ enum<EnumName extends keyof M['constants']['enums']>(name: EnumName): Enum<M['constants']['enums'][EnumName]>;
56
55
  bucket<Name extends keyof M['buckets'], Bucket extends M['buckets'][Name]>(name: Name): BucketTrxNode<M, Bucket>;
57
56
  job<Name extends keyof M['jobs'], Job extends M['jobs'][Name]>(name: Name): JobTrxNode<M, Job>;
58
57
  static jobWithCustomCtx<M extends $Module, JobName extends keyof M['jobs'], Job extends M['jobs'][JobName]>(node: AnyTrxNode, name: string, ctx?: Record<string, any>): JobTrxNode<M, Job>;
@@ -1,7 +1,7 @@
1
1
  import { $BlockType } from "../../elements/blocks/block.schema";
2
2
  declare const LogLevel: readonly ["off", "error", "warn", "info", "debug", "trace"];
3
3
  export type LogLevel = typeof LogLevel[number];
4
- export type LogScope = $BlockType | 'compiler' | 'trx' | 'daemon' | 'app' | 'module' | 'layer' | 'message' | 'bucket' | 'job' | 'resource' | 'controller' | 'queue' | 'topic' | 'constants' | 'externals' | 'inc.server' | 'inc.client';
4
+ export type LogScope = $BlockType | 'compiler' | 'trx' | 'daemon' | 'app' | 'module' | 'layer' | 'message' | 'bucket' | 'job' | 'resource' | 'controller' | 'queue' | 'topic' | 'constants' | 'externals' | 'nql' | 'inc.server' | 'inc.client';
5
5
  export declare function scopeTag(scope: LogScope, scope_id: string): string;
6
6
  export declare function anyScopeTag(scopeWithId: string): string;
7
7
  export declare class Log {
@@ -25,6 +25,7 @@ function scopeTag(scope, scope_id) {
25
25
  machine: 'lightblue',
26
26
  queue: 'lightblue',
27
27
  topic: 'lightblue',
28
+ nql: 'lightpurple',
28
29
  'inc.server': 'lightgreen',
29
30
  'inc.client': 'lightcyan',
30
31
  }[scope] || 'lightgray';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesoi",
3
- "version": "3.2.1",
3
+ "version": "3.2.3",
4
4
  "description": "Declarative framework for data-driven applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,9 +1,29 @@
1
- import { AnyBucketBuilder } from "../../src/elements/entities/bucket/bucket.builder";
1
+ import { AnyBucketBuilder, BucketBuilder } from "../../src/elements/entities/bucket/bucket.builder";
2
2
  import { NesoiError } from "../../src/engine/data/error";
3
3
  import { AnyBuilder } from "../../src/engine/module";
4
- export declare function expectBucket(def: (builder: AnyBucketBuilder) => any, inject?: AnyBuilder[]): {
4
+ export declare function givenBucket<Def>(name: string, def: (builder: AnyBucketBuilder) => any): {
5
+ builder: BucketBuilder<import("../../src/elements").$Space, import("../../src/elements").$Module, Omit<import("../../src/elements").$Bucket, "views"> & {
6
+ views: {};
7
+ }>;
8
+ data: Record<string, any>;
9
+ withData(mock: Record<string, any>): {
10
+ builder: BucketBuilder<import("../../src/elements").$Space, import("../../src/elements").$Module, Omit<import("../../src/elements").$Bucket, "views"> & {
11
+ views: {};
12
+ }>;
13
+ data: Record<string, any>;
14
+ withData(mock: Record<string, any>): /*elided*/ any;
15
+ };
16
+ };
17
+ export declare function expectBucket(def: (builder: AnyBucketBuilder) => any, inject?: (AnyBuilder | {
18
+ builder: AnyBucketBuilder;
19
+ data: Record<string, any>;
20
+ })[]): {
5
21
  toBuildOne(raw: Record<string, any>, view: string): {
6
- as(parsed: Record<string, any>): Promise<void>;
22
+ as(parsed: Record<string, any> | Record<string, any>[]): Promise<void>;
23
+ butFail(error: (...args: any[]) => NesoiError.BaseError): Promise<void>;
24
+ };
25
+ toBuildMany(raws: Record<string, any>[], view: string): {
26
+ as(parsed: Record<string, any> | Record<string, any>[]): Promise<void>;
7
27
  butFail(error: (...args: any[]) => NesoiError.BaseError): Promise<void>;
8
28
  };
9
29
  };
@@ -1,43 +1,71 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.givenBucket = givenBucket;
3
4
  exports.expectBucket = expectBucket;
4
5
  const bucket_builder_1 = require("../../src/elements/entities/bucket/bucket.builder");
5
6
  const inline_app_1 = require("../../src/engine/apps/inline.app");
7
+ const elements_1 = require("../../src/elements");
8
+ function givenBucket(name, def) {
9
+ const builder = new bucket_builder_1.BucketBuilder('test', name);
10
+ const data = {};
11
+ def(builder);
12
+ return {
13
+ builder,
14
+ data,
15
+ withData(mock) {
16
+ Object.assign(data, mock);
17
+ return this;
18
+ }
19
+ };
20
+ }
6
21
  function expectBucket(def, inject = []) {
7
22
  const builder = new bucket_builder_1.BucketBuilder('test', 'test');
8
23
  def(builder);
9
- const app = new inline_app_1.InlineApp('test', [...inject, builder]);
24
+ const injectBuilders = inject.map(i => 'builder' in i ? i.builder : i);
25
+ const app = new inline_app_1.InlineApp('test', [...injectBuilders, builder]);
26
+ // Configure buckets
27
+ const bucketConfig = {};
28
+ for (const i of inject) {
29
+ if (!('data' in i))
30
+ continue;
31
+ bucketConfig[i.builder.name] = {
32
+ adapter: (schema) => new elements_1.MemoryBucketAdapter(schema, i.data)
33
+ };
34
+ }
35
+ app.config.module('test', {
36
+ buckets: bucketConfig
37
+ });
10
38
  let promise;
11
39
  const step1 = {
12
40
  toBuildOne(raw, view) {
13
- promise = Promise.all([raw].map(raw => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.bucket('test').buildOne(raw, view)))));
41
+ promise = () => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.bucket('test').buildOne(raw, view)));
42
+ return step2;
43
+ },
44
+ toBuildMany(raws, view) {
45
+ promise = () => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.bucket('test').buildMany(raws, view)));
14
46
  return step2;
15
47
  }
16
48
  };
17
49
  const step2 = {
18
50
  async as(parsed) {
19
- const status = await promise;
20
- status.forEach(st => {
21
- if (st.state === 'error') {
22
- console.log(st.summary());
23
- console.error(st.error?.data);
24
- console.error(st.error?.data?.unionErrors);
25
- console.error(st.error?.stack);
26
- }
27
- expect(st.state).toEqual('ok');
28
- expect(st.output)
29
- .toEqual(parsed);
30
- });
51
+ const status = await promise();
52
+ if (status.state === 'error') {
53
+ console.log(status.summary());
54
+ console.error(status.error?.data);
55
+ console.error(status.error?.data?.unionErrors);
56
+ console.error(status.error?.stack);
57
+ }
58
+ expect(status.state).toEqual('ok');
59
+ expect(status.output)
60
+ .toEqual(parsed);
31
61
  },
32
62
  async butFail(error) {
33
63
  const errorObj = error({});
34
64
  try {
35
- const status = await promise;
36
- status.forEach(st => {
37
- expect(st.state).toEqual('error');
38
- expect(st.error?.name)
39
- .toEqual(errorObj.name);
40
- });
65
+ const status = await promise();
66
+ expect(status.state).toEqual('error');
67
+ expect(status.error?.name)
68
+ .toEqual(errorObj.name);
41
69
  }
42
70
  catch (e) {
43
71
  expect(e.toString())
@@ -13,18 +13,18 @@ function expectJob(def) {
13
13
  const step1 = {
14
14
  onRaw(_raw) {
15
15
  raw = _raw;
16
- promise = app.daemon().then(daemon => daemon.trx('test').run(trx => trx.job('test').run(_raw)));
16
+ promise = () => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.job('test').run(_raw)));
17
17
  return step2;
18
18
  },
19
19
  onMessage(_msg) {
20
20
  msg = _msg;
21
- promise = app.daemon().then(daemon => daemon.trx('test').run(trx => trx.job('test').forward(_msg)));
21
+ promise = () => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.job('test').forward(_msg)));
22
22
  return step2;
23
23
  }
24
24
  };
25
25
  const step2 = {
26
26
  async toResolve(value) {
27
- const status = await promise;
27
+ const status = await promise();
28
28
  expect(status.state).toEqual('ok');
29
29
  expect(status.output)
30
30
  .toEqual(value({ raw, msg }));
@@ -32,7 +32,7 @@ function expectJob(def) {
32
32
  async toReject(error) {
33
33
  const errorObj = error({ raw, msg })({});
34
34
  try {
35
- const status = await promise;
35
+ const status = await promise();
36
36
  expect(status.state).toEqual('error');
37
37
  expect(status.error?.name)
38
38
  .toEqual(errorObj.name);