nesoi 3.4.2 → 3.4.4

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 (37) hide show
  1. package/lib/elements/blocks/job/internal/resource_job.schema.d.ts +1 -0
  2. package/lib/elements/blocks/resource/resource.builder.js +2 -2
  3. package/lib/elements/blocks/resource/resource_query.builder.d.ts +3 -0
  4. package/lib/elements/blocks/resource/resource_query.builder.js +7 -1
  5. package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +5 -3
  6. package/lib/elements/entities/bucket/adapters/bucket_adapter.js +3 -3
  7. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.d.ts +2 -2
  8. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +5 -5
  9. package/lib/elements/entities/bucket/adapters/memory.nql.d.ts +3 -1
  10. package/lib/elements/entities/bucket/adapters/memory.nql.js +14 -5
  11. package/lib/elements/entities/bucket/adapters/rest.nql.d.ts +1 -1
  12. package/lib/elements/entities/bucket/adapters/rest.nql.js +1 -1
  13. package/lib/elements/entities/bucket/bucket.d.ts +12 -0
  14. package/lib/elements/entities/bucket/bucket.js +23 -4
  15. package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +4 -2
  16. package/lib/elements/entities/bucket/cache/bucket_cache.js +7 -3
  17. package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +10 -1
  18. package/lib/elements/entities/bucket/graph/bucket_graph.js +50 -4
  19. package/lib/elements/entities/bucket/model/bucket_model.d.ts +8 -2
  20. package/lib/elements/entities/bucket/model/bucket_model.js +287 -275
  21. package/lib/elements/entities/bucket/query/nql_engine.d.ts +2 -2
  22. package/lib/elements/entities/bucket/query/nql_engine.js +2 -2
  23. package/lib/elements/entities/bucket/view/bucket_view.js +48 -9
  24. package/lib/elements/entities/message/template/message_template_parser.js +3 -3
  25. package/lib/engine/data/error.d.ts +4 -0
  26. package/lib/engine/data/error.js +4 -0
  27. package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +5 -1
  28. package/lib/engine/transaction/nodes/bucket.trx_node.js +8 -0
  29. package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +4 -0
  30. package/lib/engine/transaction/nodes/bucket_query.trx_node.js +22 -0
  31. package/lib/engine/transaction/trx_engine.d.ts +2 -2
  32. package/lib/engine/transaction/trx_engine.js +14 -13
  33. package/lib/engine/util/parse.d.ts +0 -7
  34. package/package.json +1 -1
  35. package/tools/joaquin/bucket.d.ts +4 -0
  36. package/tools/joaquin/bucket.js +13 -0
  37. package/tsconfig.build.tsbuildinfo +1 -1
@@ -30,6 +30,10 @@ class BucketView {
30
30
  const module = trx_node_1.TrxNode.getModule(trx);
31
31
  const tag = new dependency_1.Tag(this.bucket.module.name, 'bucket', this.bucket.schema.name);
32
32
  const meta = await daemon_1.Daemon.getBucketMetadata(module.daemon, tag);
33
+ if (flags?.serialize) {
34
+ const model = new bucket_model_1.BucketModel(meta.schema);
35
+ root = model.copy(root, 'load', () => true);
36
+ }
33
37
  const parsed = {};
34
38
  if ('__root' in this.schema.fields || '__parent' in this.schema.fields || '__value' in this.schema.fields) {
35
39
  Object.assign(parsed, root);
@@ -56,6 +60,8 @@ class BucketView {
56
60
  };
57
61
  }
58
62
  async parseMany(trx, roots, flags) {
63
+ if (!roots.length)
64
+ return [];
59
65
  const module = trx_node_1.TrxNode.getModule(trx);
60
66
  const tag = new dependency_1.Tag(this.bucket.module.name, 'bucket', this.bucket.schema.name);
61
67
  const meta = await daemon_1.Daemon.getBucketMetadata(module.daemon, tag);
@@ -89,7 +95,7 @@ class BucketView {
89
95
  return parseds;
90
96
  }
91
97
  async parseLayer(trx, layer, flags) {
92
- const next = [];
98
+ let next = [];
93
99
  // Model props
94
100
  for (const node of layer) {
95
101
  if (node.field.scope !== 'model')
@@ -131,6 +137,8 @@ class BucketView {
131
137
  data: node.data
132
138
  })));
133
139
  }
140
+ // Exclude eventual nodes without data
141
+ next = next.filter(node => node.data.length);
134
142
  return next;
135
143
  }
136
144
  toDict(as_dict, data, final = false) {
@@ -255,7 +263,7 @@ class BucketView {
255
263
  }
256
264
  }
257
265
  // Copy modelpath value from object
258
- const value = model.copy(data.parent, 'save', () => !!flags?.serialize, node_modelpath);
266
+ const value = model.copy(data.parent, 'load', () => !!flags?.serialize, node_modelpath);
259
267
  const many = modelpath.split('.').includes('*');
260
268
  // Modelpath contains '*', so it returns N results
261
269
  if (many) {
@@ -417,7 +425,13 @@ class BucketView {
417
425
  const otherBucket = await daemon_1.Daemon.getBucketMetadata(daemon, otherBucketDep);
418
426
  // Step 3: Build view
419
427
  let next = [];
420
- let nextData = linksObjs;
428
+ let nextData = linksObjs.map((link, i) => ({
429
+ root: node.data[i].root,
430
+ parent: link,
431
+ value: link,
432
+ index: node.data[i].index,
433
+ target: node.data[i].target[node.data[i].key]
434
+ }));
421
435
  if (meta.view) {
422
436
  const view = otherBucket.schema.views[meta.view];
423
437
  const includeRoot = '__root' in view.fields;
@@ -445,7 +459,13 @@ class BucketView {
445
459
  }
446
460
  }
447
461
  if (!node.field.prop) {
448
- nextData = _links.map((ll, i) => ll.map((l, j) => ({ value: l, target: node.data[i].target[node.data[i].key][j] }))).flat(1);
462
+ nextData = _links.map((ll, i) => ll.map((l, j) => ({
463
+ root: l,
464
+ parent: l,
465
+ value: l,
466
+ index: node.data[i].index,
467
+ target: node.data[i].target[node.data[i].key][j]
468
+ }))).flat(1);
449
469
  }
450
470
  else {
451
471
  nextData = [];
@@ -468,7 +488,11 @@ class BucketView {
468
488
  }
469
489
  target.$v = meta.view;
470
490
  nextData.push({
471
- value: _links[i], target: node.data[i].target[key]
491
+ root: _links[i],
492
+ parent: _links[i],
493
+ value: _links[i],
494
+ index: [],
495
+ target: node.data[i].target[key]
472
496
  });
473
497
  }
474
498
  }
@@ -483,10 +507,10 @@ class BucketView {
483
507
  bucket: otherBucket,
484
508
  field,
485
509
  data: nextData.map($ => ({
486
- root: $.value,
487
- parent: $.value,
510
+ root: $.root,
511
+ parent: $.parent,
488
512
  value: $.value,
489
- index: [],
513
+ index: $.index,
490
514
  target: $.target,
491
515
  key: field.name
492
516
  }))
@@ -561,6 +585,21 @@ class BucketView {
561
585
  });
562
586
  }
563
587
  }
588
+ // Step 4b: Add chain to queue
589
+ if (node.field.chain) {
590
+ next.push({
591
+ bucket: node.bucket,
592
+ field: node.field.chain,
593
+ data: linksObjs.map((l, i) => ({
594
+ root: node.data[i].root,
595
+ parent: l,
596
+ index: node.data[i].index,
597
+ value: l,
598
+ target: node.data[i].target,
599
+ key: node.data[i].key
600
+ }))
601
+ });
602
+ }
564
603
  return next;
565
604
  }
566
605
  /**
@@ -574,7 +613,7 @@ class BucketView {
574
613
  }
575
614
  const meta = node.field.meta.drive;
576
615
  for (const entry of node.data) {
577
- const value = tree_1.Tree.get(entry.root, meta.path);
616
+ const value = tree_1.Tree.get(entry.parent, meta.path);
578
617
  if (Array.isArray(value)) {
579
618
  const public_urls = [];
580
619
  for (const obj of value) {
@@ -15,7 +15,7 @@ async function MessageTemplateFieldParser(trx, fields, raw) {
15
15
  const key_raw = field.pathRaw.split('.')[0];
16
16
  const key_parsed = field.pathParsed.split('.')[0];
17
17
  const value = raw[key_raw];
18
- parsed[key_parsed] = await parseFieldValue(trx, field, field.pathRaw.split('.'), raw, value, inject);
18
+ parsed[key_parsed] = await parseFieldValue(trx, field, [field.pathRaw], raw, value, inject);
19
19
  }
20
20
  Object.assign(parsed, inject);
21
21
  return parsed;
@@ -137,7 +137,7 @@ async function parseParentField(trx, field, path, raw, value, inject) {
137
137
  const parsedParent = [];
138
138
  for (const key in children) {
139
139
  const child = children[key];
140
- parsedParent.push(await parseFieldValue(trx, child.field, child.field.pathRaw.split('.'), raw, child.value, inject));
140
+ parsedParent.push(await parseFieldValue(trx, child.field, [...path, key], raw, child.value, inject));
141
141
  }
142
142
  return parsedParent;
143
143
  }
@@ -152,7 +152,7 @@ async function parseParentField(trx, field, path, raw, value, inject) {
152
152
  const parsedParent = {};
153
153
  for (const key in children) {
154
154
  const child = children[key];
155
- parsedParent[key] = await parseFieldValue(trx, child.field, child.field.pathRaw.split('.'), raw, child.value, inject);
155
+ parsedParent[key] = await parseFieldValue(trx, child.field, [...path, key], raw, child.value, inject);
156
156
  }
157
157
  return parsedParent;
158
158
  }
@@ -158,6 +158,10 @@ export declare namespace NesoiError {
158
158
  }): BaseError;
159
159
  }
160
160
  namespace Model {
161
+ function FieldRequired($: {
162
+ bucket: string;
163
+ field: string;
164
+ }): BaseError;
161
165
  function InvalidModelpath($: {
162
166
  bucket: string;
163
167
  modelpath: string;
@@ -296,6 +296,10 @@ var NesoiError;
296
296
  })(Fieldpath = Bucket.Fieldpath || (Bucket.Fieldpath = {}));
297
297
  let Model;
298
298
  (function (Model) {
299
+ function FieldRequired($) {
300
+ return new BaseError('Bucket.Model.InvalidModelpath', `Field '${$.field}' is required on bucket '${$.bucket}'`, Status.BAD_REQUEST, $);
301
+ }
302
+ Model.FieldRequired = FieldRequired;
299
303
  function InvalidModelpath($) {
300
304
  return new BaseError('Bucket.Model.InvalidModelpath', `Modelpath '${$.modelpath}' not found on bucket '${$.bucket}'`, Status.BAD_REQUEST, $);
301
305
  }
@@ -91,7 +91,11 @@ export declare class BucketTrxNode<M extends $Module, $ extends $Bucket> {
91
91
  /**
92
92
  * Returns `true` if the graph link resolves to at least 1 object.
93
93
  */
94
- hasLink<LinkName extends keyof $['graph']['links']>(id: $['#data']['id'], link: LinkName): Promise<boolean | undefined>;
94
+ hasLink<LinkName extends keyof $['graph']['links']>(id: $['#data']['id'], link: LinkName): Promise<boolean>;
95
+ /**
96
+ * Returns the number of objects matching the link.
97
+ */
98
+ countLink<LinkName extends keyof $['graph']['links']>(id: $['#data']['id'], link: LinkName): Promise<number>;
95
99
  /**
96
100
  * Creates an object by passing it to the bucket adapter.
97
101
  * Also creates the compositions of this bucket, from the
@@ -211,6 +211,14 @@ class BucketTrxNode {
211
211
  no_tenancy: !this.enableTenancy
212
212
  }), undefined, true);
213
213
  }
214
+ /**
215
+ * Returns the number of objects matching the link.
216
+ */
217
+ async countLink(id, link) {
218
+ return this.wrap('countLink', { id, link }, (trx, bucket) => bucket.countLink(trx, id, link, {
219
+ no_tenancy: !this.enableTenancy
220
+ }), undefined, true);
221
+ }
214
222
  /*
215
223
  Create
216
224
  */
@@ -17,10 +17,14 @@ export declare class BucketQueryTrxNode<M extends $Module, B extends $Bucket, V
17
17
  private view?;
18
18
  private _params?;
19
19
  private _param_templates?;
20
+ private _serialize;
21
+ private _metadata_only;
20
22
  private external;
21
23
  private bucket?;
22
24
  constructor(trx: TrxNode<any, M, any>, tag: Tag, query: NQL_AnyQuery, enableTenancy: boolean, view?: V | undefined);
23
25
  merge($: NQL_Query<M, B>): void;
26
+ serialize(value?: boolean): this;
27
+ metadata_only(value?: boolean): this;
24
28
  params(value?: Record<string, any> | Record<string, any>[]): this;
25
29
  param_templates(value?: Record<string, any> | Record<string, any>[]): this;
26
30
  wrap(action: string, input: Record<string, any>, fn: (trx: AnyTrxNode, element: Bucket<M, B>) => Promise<any>): Promise<{
@@ -17,6 +17,8 @@ class BucketQueryTrxNode {
17
17
  view;
18
18
  _params = [];
19
19
  _param_templates = [];
20
+ _serialize = false;
21
+ _metadata_only = false;
20
22
  external;
21
23
  bucket;
22
24
  constructor(trx, tag, query, enableTenancy, view) {
@@ -40,6 +42,18 @@ class BucketQueryTrxNode {
40
42
  this.query['#and*'] = and; // TODO: make this a little better
41
43
  this.query['#or*'] = or; // TODO: make this a little better
42
44
  }
45
+ serialize(value) {
46
+ if (value) {
47
+ this._serialize = true;
48
+ }
49
+ return this;
50
+ }
51
+ metadata_only(value) {
52
+ if (value) {
53
+ this._metadata_only = true;
54
+ }
55
+ return this;
56
+ }
43
57
  params(value) {
44
58
  this._params = value
45
59
  ? Array.isArray(value) ? value : [value]
@@ -82,6 +96,8 @@ class BucketQueryTrxNode {
82
96
  return bucket.query(trx, this.query, {
83
97
  perPage: 1
84
98
  }, this.view, {
99
+ metadata_only: this._metadata_only,
100
+ serialize: this._serialize,
85
101
  no_tenancy: !this.enableTenancy,
86
102
  params: this._params,
87
103
  param_templates: this._param_templates
@@ -94,6 +110,8 @@ class BucketQueryTrxNode {
94
110
  async firstOrFail() {
95
111
  const results = await this.wrap('queryFirstOrFail', { schema: this.query, view: this.view }, async (trx, bucket) => {
96
112
  const results = await bucket.query(trx, this.query, undefined, this.view, {
113
+ metadata_only: this._metadata_only,
114
+ serialize: this._serialize,
97
115
  no_tenancy: !this.enableTenancy,
98
116
  params: this._params,
99
117
  param_templates: this._param_templates
@@ -108,6 +126,8 @@ class BucketQueryTrxNode {
108
126
  async all() {
109
127
  const results = await this.wrap('queryAll', { schema: this.query, view: this.view }, async (trx, bucket) => {
110
128
  return bucket.query(trx, this.query, undefined, this.view, {
129
+ metadata_only: this._metadata_only,
130
+ serialize: this._serialize,
111
131
  params: this._params,
112
132
  param_templates: this._param_templates
113
133
  });
@@ -123,6 +143,8 @@ class BucketQueryTrxNode {
123
143
  }
124
144
  const results = await this.wrap('queryPage', { schema: this.query, view: this.view }, async (trx, bucket) => {
125
145
  return bucket.query(trx, this.query, pagination, this.view, {
146
+ metadata_only: this._metadata_only,
147
+ serialize: this._serialize,
126
148
  params: this._params,
127
149
  param_templates: this._param_templates
128
150
  });
@@ -40,11 +40,11 @@ export declare class TrxEngine<S extends $Space, M extends $Module, AuthUsers ex
40
40
  private services;
41
41
  private $TrxBucket;
42
42
  /**
43
- * Transaction used to read/write transactions on the adapter
43
+ * Transaction used to read/write transactions on the log adapter
44
44
  */
45
45
  private innerTrx;
46
- private adapter;
47
46
  private log_adapter?;
47
+ private ongoing;
48
48
  constructor(origin: TrxEngineOrigin, module: Module<S, M>, authnProviders?: AuthUsers | undefined, config?: TrxEngineConfig<S, M, any, any> | undefined, services?: Record<string, IService>);
49
49
  getModule(): Module<S, M>;
50
50
  get(id?: string, origin?: string, req_idempotent?: boolean): Promise<Trx<S, M, any>>;
@@ -5,7 +5,6 @@ const log_1 = require("../util/log");
5
5
  const trx_1 = require("./trx");
6
6
  const trx_node_1 = require("./trx_node");
7
7
  const error_1 = require("../data/error");
8
- const memory_bucket_adapter_1 = require("../../elements/entities/bucket/adapters/memory.bucket_adapter");
9
8
  const elements_1 = require("../../elements");
10
9
  const bucket_model_schema_1 = require("../../elements/entities/bucket/model/bucket_model.schema");
11
10
  const bucket_graph_schema_1 = require("../../elements/entities/bucket/graph/bucket_graph.schema");
@@ -22,11 +21,14 @@ class TrxEngine {
22
21
  services;
23
22
  $TrxBucket;
24
23
  /**
25
- * Transaction used to read/write transactions on the adapter
24
+ * Transaction used to read/write transactions on the log adapter
26
25
  */
27
26
  innerTrx;
28
- adapter;
29
27
  log_adapter;
28
+ /*
29
+ * Ongoing Transactions
30
+ */
31
+ ongoing = {};
30
32
  constructor(origin, module, authnProviders, config, services = {}) {
31
33
  this.origin = origin;
32
34
  this.module = module;
@@ -42,7 +44,6 @@ class TrxEngine {
42
44
  start: new bucket_model_schema_1.$BucketModelField('start', 'start', 'datetime', 'Start', true),
43
45
  end: new bucket_model_schema_1.$BucketModelField('end', 'end', 'datetime', 'End', false)
44
46
  }), new bucket_graph_schema_1.$BucketGraph(), {});
45
- this.adapter = config?.adapter?.(this.$TrxBucket) || new memory_bucket_adapter_1.MemoryBucketAdapter(this.$TrxBucket, {});
46
47
  if (config?.log_adapter) {
47
48
  this.log_adapter = config?.log_adapter?.(this.$TrxBucket);
48
49
  }
@@ -62,20 +63,20 @@ class TrxEngine {
62
63
  await wrap.begin(trx, this.services);
63
64
  }
64
65
  if (!req_idempotent) {
65
- await this.adapter.create(this.innerTrx.root, {
66
+ this.ongoing[trx.id] = {
66
67
  id: trx.id,
67
68
  state: 'open',
68
69
  origin: trx.origin,
69
70
  start: trx.start,
70
71
  end: trx.end,
71
72
  module: this.module.name,
72
- });
73
+ };
73
74
  }
74
75
  return trx;
75
76
  }
76
77
  // Chain/Continue transaction
77
78
  else {
78
- const trxData = await this.adapter.get(this.innerTrx.root, id);
79
+ const trxData = await this.ongoing[id];
79
80
  // If trxData exists, the transaction to which it refers is non-idempotent,
80
81
  // since idempotent transactions are not stored.
81
82
  //
@@ -145,14 +146,14 @@ class TrxEngine {
145
146
  // The wrappers decide how to begin a db transaction, based on the trx idempotent flag.
146
147
  await wrap.begin(trx, this.services);
147
148
  }
148
- await this.adapter.create(this.innerTrx.root, {
149
+ this.ongoing[trx.id] = {
149
150
  id: trx.id,
150
151
  state: 'open',
151
152
  origin: _origin,
152
153
  start: trx.start,
153
154
  end: trx.end,
154
155
  module: this.module.name,
155
- });
156
+ };
156
157
  }
157
158
  }
158
159
  return trx;
@@ -227,14 +228,14 @@ class TrxEngine {
227
228
  async hold(trx, output) {
228
229
  log_1.Log.debug('module', this.module.name, `Hold ${(0, log_1.scopeTag)('trx', trx.root.globalId)}`);
229
230
  trx_node_1.TrxNode.hold(trx.root, output);
230
- await this.adapter.put(this.innerTrx.root, {
231
+ this.ongoing[trx.id] = {
231
232
  id: trx.id,
232
233
  state: 'hold',
233
234
  origin: this.origin,
234
235
  start: trx.start,
235
236
  end: trx.end,
236
237
  module: this.module.name,
237
- });
238
+ };
238
239
  return trx;
239
240
  }
240
241
  async ok(trx, output, idempotent) {
@@ -260,7 +261,7 @@ class TrxEngine {
260
261
  end: trx.end,
261
262
  module: this.module.name,
262
263
  });
263
- await this.adapter.delete(this.innerTrx.root, trx.id);
264
+ delete this.ongoing[trx.id];
264
265
  for (const wrap of this.config?.wrap || []) {
265
266
  await wrap.commit(trx, this.services);
266
267
  }
@@ -289,7 +290,7 @@ class TrxEngine {
289
290
  end: trx.end,
290
291
  module: this.module.name,
291
292
  });
292
- await this.adapter.delete(this.innerTrx.root, trx.id);
293
+ delete this.ongoing[trx.id];
293
294
  for (const wrap of this.config?.wrap || []) {
294
295
  await wrap.rollback(trx, this.services);
295
296
  }
@@ -8,7 +8,6 @@ import { NesoiFile } from '../data/file';
8
8
  import { NesoiDuration } from '../data/duration';
9
9
  import { Tag } from '../dependency';
10
10
  export declare function parseBoolean(field: {
11
- pathRaw: string;
12
11
  alias: string;
13
12
  }, path: string[], value: any): boolean;
14
13
  export declare function parseDate(field: {
@@ -33,15 +32,12 @@ export declare function parseEnum(raw: Record<string, any>, field: {
33
32
  alias: string;
34
33
  }, path: string[], value: any, meta: NonNullable<$MessageTemplateFieldMeta['enum']>, trx: AnyTrxNode): string;
35
34
  export declare function parseFile(field: {
36
- pathRaw: string;
37
- name: string;
38
35
  alias: string;
39
36
  }, path: string[], value: any, options?: {
40
37
  maxsize?: number;
41
38
  extnames?: string[];
42
39
  }): NesoiFile;
43
40
  export declare function parseFloat_(field: {
44
- pathRaw: string;
45
41
  alias: string;
46
42
  }, path: string[], value: any): number;
47
43
  export declare function parseId<M extends $Module, Name extends BucketName<M>, View extends ViewName<M['buckets'][Name]> | undefined>(field: {
@@ -52,15 +48,12 @@ export declare function parseId<M extends $Module, Name extends BucketName<M>, V
52
48
  obj: any;
53
49
  }>;
54
50
  export declare function parseInt_(field: {
55
- pathRaw: string;
56
51
  alias: string;
57
52
  }, path: string[], value: any): number;
58
53
  export declare function parseString(field: {
59
- pathRaw: string;
60
54
  alias: string;
61
55
  }, path: string[], value: any): string;
62
56
  export declare function parseLiteral(field: {
63
- pathRaw: string;
64
57
  alias: string;
65
58
  }, path: string[], value: any, template: string): string;
66
59
  export declare function parseStringOrNumber(field: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesoi",
3
- "version": "3.4.2",
3
+ "version": "3.4.4",
4
4
  "description": "Declarative framework for data-driven applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,6 +18,10 @@ export declare function expectBucket(def: (builder: AnyBucketBuilder) => any, in
18
18
  builder: AnyBucketBuilder;
19
19
  data: Record<string, any>;
20
20
  })[]): {
21
+ toCopyOne(raw: Record<string, any>, op: "save" | "load"): {
22
+ as(parsed: Record<string, any> | Record<string, any>[]): Promise<void>;
23
+ butFail(error: (...args: any[]) => NesoiError.BaseError): Promise<void>;
24
+ };
21
25
  toBuildOne(raw: Record<string, any>, view: string, flags?: {
22
26
  serialize: boolean;
23
27
  }): {
@@ -4,7 +4,11 @@ exports.givenBucket = givenBucket;
4
4
  exports.expectBucket = expectBucket;
5
5
  const bucket_builder_1 = require("../../src/elements/entities/bucket/bucket.builder");
6
6
  const inline_app_1 = require("../../src/engine/app/inline.app");
7
+ const trx_1 = require("../../src/engine/transaction/trx");
7
8
  const elements_1 = require("../../src/elements");
9
+ const daemon_1 = require("../../src/engine/daemon");
10
+ const datetime_1 = require("../../src/engine/data/datetime");
11
+ const bucket_model_1 = require("../../src/elements/entities/bucket/model/bucket_model");
8
12
  function givenBucket(name, def) {
9
13
  const builder = new bucket_builder_1.BucketBuilder('test', name);
10
14
  const data = {};
@@ -37,6 +41,15 @@ function expectBucket(def, inject = []) {
37
41
  });
38
42
  let promise;
39
43
  const step1 = {
44
+ toCopyOne(raw, op) {
45
+ promise = () => app.daemon().then(daemon => {
46
+ const bucket = daemon_1.Daemon.getModule(daemon, 'test').buckets['test'];
47
+ const model = new bucket_model_1.BucketModel(bucket.schema);
48
+ const copy = model.copy(raw, op);
49
+ return new trx_1.TrxStatus('', 'trx:', datetime_1.NesoiDatetime.now(), datetime_1.NesoiDatetime.now(), 'ok', copy);
50
+ });
51
+ return step2;
52
+ },
40
53
  toBuildOne(raw, view, flags) {
41
54
  promise = () => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.bucket('test').buildOne(raw, view, flags)));
42
55
  return step2;