nesoi 3.3.19 → 3.3.21

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 (44) hide show
  1. package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +4 -1
  2. package/lib/elements/edge/controller/adapters/controller_adapter.js +8 -4
  3. package/lib/elements/edge/controller/controller.js +3 -3
  4. package/lib/elements/edge/controller/controller.schema.d.ts +2 -1
  5. package/lib/elements/edge/controller/controller.schema.js +3 -1
  6. package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +25 -3
  7. package/lib/elements/entities/bucket/adapters/bucket_adapter.js +21 -2
  8. package/lib/elements/entities/bucket/adapters/memory.nql.js +86 -50
  9. package/lib/elements/entities/bucket/adapters/test.bucket_adapter.d.ts +22 -0
  10. package/lib/elements/entities/bucket/adapters/test.bucket_adapter.js +23 -0
  11. package/lib/elements/entities/bucket/bucket.js +2 -2
  12. package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +16 -1
  13. package/lib/elements/entities/bucket/cache/bucket_cache.js +36 -15
  14. package/lib/elements/entities/bucket/graph/bucket_graph.js +28 -18
  15. package/lib/elements/entities/bucket/query/nql.schema.d.ts +3 -0
  16. package/lib/elements/entities/bucket/query/nql_compiler.d.ts +10 -4
  17. package/lib/elements/entities/bucket/query/nql_compiler.js +42 -35
  18. package/lib/elements/entities/bucket/query/nql_engine.d.ts +4 -1
  19. package/lib/elements/entities/bucket/query/nql_engine.js +3 -5
  20. package/lib/elements/entities/message/template/message_template_field.builder.d.ts +2 -0
  21. package/lib/elements/entities/message/template/message_template_field.builder.js +5 -0
  22. package/lib/engine/daemon.d.ts +19 -0
  23. package/lib/engine/daemon.js +40 -2
  24. package/lib/engine/data/tree.d.ts +1 -2
  25. package/lib/engine/data/tree.js +6 -94
  26. package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +1 -1
  27. package/lib/engine/transaction/nodes/bucket.trx_node.js +15 -15
  28. package/lib/engine/transaction/nodes/bucket_query.trx_node.js +2 -2
  29. package/lib/engine/transaction/nodes/external.trx_node.d.ts +3 -1
  30. package/lib/engine/transaction/nodes/external.trx_node.js +54 -4
  31. package/lib/engine/transaction/nodes/job.trx_node.js +3 -2
  32. package/lib/engine/transaction/nodes/machine.trx_node.js +1 -1
  33. package/lib/engine/transaction/nodes/queue.trx_node.js +1 -1
  34. package/lib/engine/transaction/nodes/resource.trx_node.js +1 -1
  35. package/lib/engine/transaction/nodes/topic.trx_node.js +1 -1
  36. package/lib/engine/transaction/trx.d.ts +7 -1
  37. package/lib/engine/transaction/trx.js +15 -1
  38. package/lib/engine/transaction/trx_engine.config.d.ts +6 -1
  39. package/lib/engine/transaction/trx_engine.d.ts +5 -5
  40. package/lib/engine/transaction/trx_engine.js +59 -36
  41. package/lib/engine/transaction/trx_node.d.ts +1 -1
  42. package/lib/engine/transaction/trx_node.js +1 -1
  43. package/package.json +1 -1
  44. package/tsconfig.build.tsbuildinfo +1 -1
@@ -32,7 +32,7 @@ class TrxEngine {
32
32
  this.authnProviders = authnProviders;
33
33
  this.config = config;
34
34
  this.services = services;
35
- this.innerTrx = new trx_1.Trx(this, this.module, `trx:${origin}`);
35
+ this.innerTrx = new trx_1.Trx(this, this.module, `trx:${origin}`, true);
36
36
  this.$TrxBucket = new elements_1.$Bucket(this.module.name, '__trx__', `Transaction of Module '${this.module.name}'`, new bucket_model_schema_1.$BucketModel({
37
37
  id: new bucket_model_schema_1.$BucketModelField('id', 'id', 'string', 'ID', true),
38
38
  origin: new bucket_model_schema_1.$BucketModelField('origin', 'origin', 'string', 'Origin', true),
@@ -45,39 +45,59 @@ class TrxEngine {
45
45
  getModule() {
46
46
  return this.module;
47
47
  }
48
- async get(id) {
48
+ async get(id, origin, idempotent = false) {
49
+ const _origin = origin ?? this.origin;
49
50
  let trx;
50
51
  if (!id) {
51
- trx = new trx_1.Trx(this, this.module, this.origin);
52
- log_1.Log.info('module', this.module.name, `Begin ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
53
- await this.adapter.create(this.innerTrx.root, {
54
- id: trx.id,
55
- origin: trx.origin,
56
- start: trx.start,
57
- end: trx.end,
58
- module: this.module.name
59
- });
52
+ trx = new trx_1.Trx(this, this.module, _origin, idempotent);
53
+ log_1.Log.info('module', this.module.name, `Begin ${(0, log_1.scopeTag)('trx', trx.id)}${idempotent ? '*' : ''} @ ${(0, log_1.anyScopeTag)(_origin)}`);
54
+ for (const wrap of this.config?.wrap || []) {
55
+ await wrap.begin(trx, this.services);
56
+ }
57
+ if (!idempotent) {
58
+ await this.adapter.create(this.innerTrx.root, {
59
+ id: trx.id,
60
+ origin: trx.origin,
61
+ start: trx.start,
62
+ end: trx.end,
63
+ module: this.module.name
64
+ });
65
+ }
60
66
  return trx;
61
67
  }
62
68
  else {
69
+ if (idempotent) {
70
+ log_1.Log.debug('module', this.module.name, `Continue Idempotent ${(0, log_1.scopeTag)('trx', id)}* @ ${(0, log_1.anyScopeTag)(_origin)}`);
71
+ const trx = new trx_1.Trx(this, this.module, _origin, idempotent, undefined, id);
72
+ for (const wrap of this.config?.wrap || []) {
73
+ await wrap.continue(trx, this.services);
74
+ }
75
+ return trx;
76
+ }
63
77
  const trxData = await this.adapter.get(this.innerTrx.root, id);
64
78
  if (trxData) {
65
- log_1.Log.info('module', this.module.name, `Continue ${(0, log_1.scopeTag)('trx', trxData.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
79
+ log_1.Log.debug('module', this.module.name, `Continue ${(0, log_1.scopeTag)('trx', trxData.id)} @ ${(0, log_1.anyScopeTag)(_origin)}`);
66
80
  // Objects read from adapters are not the proper JS class, so they don't
67
81
  // carry methods. This must be used to recover the methods.
68
- trx = Object.assign(new trx_1.Trx(this, this.module, this.origin), {
82
+ trx = Object.assign(new trx_1.Trx(this, this.module, _origin, idempotent), {
69
83
  id: trxData.id,
70
84
  origin: trxData.origin,
71
85
  start: trxData.start,
72
86
  end: trxData.end
73
87
  });
88
+ for (const wrap of this.config?.wrap || []) {
89
+ await wrap.continue(trx, this.services);
90
+ }
74
91
  }
75
92
  else {
76
- log_1.Log.info('module', this.module.name, `Chain ${(0, log_1.scopeTag)('trx', id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
77
- trx = new trx_1.Trx(this, this.module, this.origin, undefined, id);
93
+ log_1.Log.info('module', this.module.name, `Chain ${(0, log_1.scopeTag)('trx', id)} @ ${(0, log_1.anyScopeTag)(_origin)}`);
94
+ trx = new trx_1.Trx(this, this.module, _origin, idempotent, undefined, id);
95
+ for (const wrap of this.config?.wrap || []) {
96
+ await wrap.begin(trx, this.services);
97
+ }
78
98
  await this.adapter.create(this.innerTrx.root, {
79
99
  id: trx.id,
80
- origin: this.origin,
100
+ origin: _origin,
81
101
  start: trx.start,
82
102
  end: trx.end,
83
103
  module: this.module.name
@@ -86,17 +106,11 @@ class TrxEngine {
86
106
  }
87
107
  return trx;
88
108
  }
89
- async trx(fn, id, tokens, users) {
90
- const trx = await this.get(id);
109
+ async trx(fn, id, tokens, users, origin, idempotent = false) {
110
+ const trx = await this.get(id, origin, idempotent);
91
111
  try {
92
112
  await this.authenticate(trx.root, tokens, users);
93
- let output;
94
- if (this.config?.wrap) {
95
- output = await this.config?.wrap(trx, fn, this.services);
96
- }
97
- else {
98
- output = await fn(trx.root);
99
- }
113
+ const output = await fn(trx.root);
100
114
  await this.commit(trx, output);
101
115
  }
102
116
  catch (e) {
@@ -104,17 +118,12 @@ class TrxEngine {
104
118
  }
105
119
  return trx.status();
106
120
  }
107
- async trx_hold(fn, id, authn, users) {
108
- const trx = await this.get(id);
121
+ async trx_hold(fn, id, authn, users, origin, idempotent = false) {
122
+ const trx = await this.get(id, origin, idempotent);
109
123
  let output = {};
110
124
  try {
111
125
  await this.authenticate(trx.root, authn, users);
112
- if (this.config?.wrap) {
113
- output = await this.config?.wrap(trx, fn, this.services);
114
- }
115
- else {
116
- output = await fn(trx.root);
117
- }
126
+ output = await fn(trx.root);
118
127
  await this.hold(trx, output);
119
128
  }
120
129
  catch (e) {
@@ -146,6 +155,8 @@ class TrxEngine {
146
155
  const _users = { ...users };
147
156
  const _tokens = {};
148
157
  for (const providerName in this.authnProviders) {
158
+ if (providerName in _users)
159
+ continue;
149
160
  const provider = this.authnProviders[providerName];
150
161
  if (!provider) {
151
162
  throw error_1.NesoiError.Auth.NoProviderRegisteredForModule(this.module.name, providerName);
@@ -163,8 +174,10 @@ class TrxEngine {
163
174
  }
164
175
  //
165
176
  async hold(trx, output) {
166
- log_1.Log.info('module', this.module.name, `Hold ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
177
+ log_1.Log.debug('module', this.module.name, `Hold ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
167
178
  trx_node_1.TrxNode.hold(trx.root, output);
179
+ if (trx.idempotent)
180
+ return trx;
168
181
  await this.adapter.put(this.innerTrx.root, {
169
182
  id: trx.id,
170
183
  origin: this.origin,
@@ -175,9 +188,11 @@ class TrxEngine {
175
188
  return trx;
176
189
  }
177
190
  async commit(trx, output) {
178
- log_1.Log.info('module', this.module.name, `Commit ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
179
191
  trx_node_1.TrxNode.ok(trx.root, output);
180
192
  trx.end = datetime_1.NesoiDatetime.now();
193
+ if (trx.idempotent)
194
+ return trx;
195
+ log_1.Log.info('module', this.module.name, `Commit ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
181
196
  await this.adapter.put(this.innerTrx.root, {
182
197
  id: trx.id,
183
198
  origin: this.origin,
@@ -186,13 +201,18 @@ class TrxEngine {
186
201
  module: this.module.name
187
202
  });
188
203
  await trx_1.Trx.onCommit(trx);
204
+ for (const wrap of this.config?.wrap || []) {
205
+ await wrap.commit(trx, this.services);
206
+ }
189
207
  return trx;
190
208
  }
191
209
  async rollback(trx, error) {
192
210
  log_1.Log.error('module', this.module.name, `[${error.status}] ${error.toString()}`, error.stack);
193
- log_1.Log.warn('module', this.module.name, `Rollback ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
194
211
  trx_node_1.TrxNode.error(trx.root, error);
195
212
  trx.end = datetime_1.NesoiDatetime.now();
213
+ if (trx.idempotent)
214
+ return trx;
215
+ log_1.Log.warn('module', this.module.name, `Rollback ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
196
216
  await this.adapter.put(this.innerTrx.root, {
197
217
  id: trx.id,
198
218
  origin: this.origin,
@@ -201,6 +221,9 @@ class TrxEngine {
201
221
  module: this.module.name
202
222
  });
203
223
  await trx_1.Trx.onRollback(trx);
224
+ for (const wrap of this.config?.wrap || []) {
225
+ await wrap.rollback(trx, this.services);
226
+ }
204
227
  return trx;
205
228
  }
206
229
  }
@@ -56,7 +56,7 @@ export declare class TrxNode<Space extends $Space, M extends $Module, AuthUsers
56
56
  message<Raw extends M['#input']['#raw'], Msg extends $Message = M['messages'][Raw['$'] & keyof M['messages']]>(raw: Raw): Promise<M['#input']['#parsed']>;
57
57
  value<K extends keyof M['constants']['values']>(name: K): M['constants']['values'][K]['value'];
58
58
  enum<EnumName extends keyof M['constants']['enums']>(name: EnumName): Enum<M['constants']['enums'][EnumName]>;
59
- cache(config: Record<keyof M['buckets'], 'eager'>): this;
59
+ cache(config: Partial<Record<keyof M['buckets'], 'eager'>>): this;
60
60
  bucket<Name extends keyof M['buckets'], Bucket extends M['buckets'][Name]>(name: Name): BucketTrxNode<M, Bucket>;
61
61
  job<Name extends keyof M['jobs'], Job extends M['jobs'][Name]>(name: Name): JobTrxNode<M, Job>;
62
62
  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>;
@@ -120,7 +120,6 @@ class TrxNode {
120
120
  }
121
121
  return new constants_1.Enum(this.module.schema.constants.enums[key]);
122
122
  }
123
- // Blocks
124
123
  /*
125
124
  Cache
126
125
  */
@@ -132,6 +131,7 @@ class TrxNode {
132
131
  }
133
132
  return this;
134
133
  }
134
+ // Blocks
135
135
  bucket(name) {
136
136
  const tag = dependency_1.Tag.fromNameOrShort(this.module.name, 'bucket', name);
137
137
  return new bucket_trx_node_1.BucketTrxNode(this, tag);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesoi",
3
- "version": "3.3.19",
3
+ "version": "3.3.21",
4
4
  "description": "Declarative framework for data-driven applications",
5
5
  "repository": {
6
6
  "type": "git",