nesoi 3.0.9 → 3.0.11
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.
- package/lib/compiler/apps/monolyth/monolyth_compiler.d.ts +1 -1
- package/lib/compiler/apps/monolyth/monolyth_compiler.js +7 -7
- package/lib/elements/blocks/block.builder.js +1 -1
- package/lib/elements/blocks/job/job.builder.js +3 -2
- package/lib/elements/blocks/machine/machine.builder.js +12 -1
- package/lib/elements/blocks/machine/machine.schema.d.ts +2 -1
- package/lib/elements/blocks/machine/machine.schema.js +2 -1
- package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +3 -1
- package/lib/elements/edge/controller/adapters/controller_adapter.js +2 -1
- package/lib/elements/edge/controller/controller.config.d.ts +3 -2
- package/lib/elements/edge/controller/controller.d.ts +3 -3
- package/lib/elements/edge/controller/controller.js +3 -3
- package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +2 -1
- package/lib/elements/entities/bucket/bucket.config.d.ts +3 -3
- package/lib/elements/entities/bucket/bucket.d.ts +3 -2
- package/lib/elements/entities/bucket/bucket.js +4 -4
- package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +1 -1
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +4 -0
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +3 -0
- package/lib/elements/entities/bucket/query/nql_compiler.js +2 -1
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +6 -0
- package/lib/elements/entities/message/template/message_template_field.builder.js +3 -0
- package/lib/elements/entities/message/template/message_template_parser.js +5 -0
- package/lib/engine/apps/app.config.d.ts +12 -11
- package/lib/engine/apps/app.d.ts +11 -22
- package/lib/engine/apps/app.js +9 -9
- package/lib/engine/apps/inline.app.d.ts +9 -8
- package/lib/engine/apps/inline.app.js +24 -24
- package/lib/engine/apps/monolyth/monolyth.app.d.ts +5 -5
- package/lib/engine/apps/monolyth/monolyth.app.js +6 -6
- package/lib/engine/apps/service.d.ts +30 -0
- package/lib/engine/apps/service.js +15 -0
- package/lib/engine/auth/authn.d.ts +10 -1
- package/lib/engine/auth/zero.authn_provider.d.ts +7 -3
- package/lib/engine/auth/zero.authn_provider.js +9 -2
- package/lib/engine/cli/cli.d.ts +2 -2
- package/lib/engine/cli/cli.js +1 -1
- package/lib/engine/cli/ui.js +1 -1
- package/lib/engine/daemon.d.ts +12 -12
- package/lib/engine/daemon.js +18 -18
- package/lib/engine/data/duration.d.ts +53 -0
- package/lib/engine/data/duration.js +62 -0
- package/lib/engine/data/error.d.ts +7 -0
- package/lib/engine/data/error.js +9 -1
- package/lib/engine/dependency.d.ts +2 -1
- package/lib/engine/dependency.js +18 -0
- package/lib/engine/module.d.ts +6 -4
- package/lib/engine/module.js +25 -10
- package/lib/engine/transaction/nodes/bucket.trx_node.js +1 -2
- package/lib/engine/transaction/nodes/bucket_query.trx_node.js +5 -10
- package/lib/engine/transaction/nodes/job.trx_node.js +2 -4
- package/lib/engine/transaction/nodes/machine.trx_node.js +2 -4
- package/lib/engine/transaction/nodes/queue.trx_node.js +1 -2
- package/lib/engine/transaction/nodes/resource.trx_node.js +2 -4
- package/lib/engine/transaction/trx.d.ts +6 -4
- package/lib/engine/transaction/trx.js +2 -1
- package/lib/engine/transaction/trx_engine.config.d.ts +2 -2
- package/lib/engine/transaction/trx_engine.d.ts +4 -3
- package/lib/engine/transaction/trx_engine.js +20 -17
- package/lib/engine/transaction/trx_node.d.ts +4 -2
- package/lib/engine/transaction/trx_node.js +13 -1
- package/lib/engine/tree.js +6 -17
- package/lib/engine/util/i18n.js +3 -3
- package/lib/engine/util/parse.d.ts +5 -0
- package/lib/engine/util/parse.js +10 -0
- package/lib/schema.d.ts +1 -1
- package/package.json +2 -3
- package/tools/joaquin/job.js +2 -2
- package/tools/joaquin/message.js +2 -2
- package/tools/joaquin/mock.d.ts +6 -6
- package/tsconfig.build.tsbuildinfo +1 -1
- package/lib/adapters/postgres/src/migrator/csv.d.ts +0 -7
- package/lib/adapters/postgres/src/migrator/csv.js +0 -72
- package/lib/adapters/postgres/src/migrator/database.d.ts +0 -34
- package/lib/adapters/postgres/src/migrator/database.js +0 -88
- package/lib/adapters/postgres/src/migrator/generator/generator.d.ts +0 -22
- package/lib/adapters/postgres/src/migrator/generator/generator.js +0 -326
- package/lib/adapters/postgres/src/migrator/generator/migration.d.ts +0 -66
- package/lib/adapters/postgres/src/migrator/generator/migration.js +0 -249
- package/lib/adapters/postgres/src/migrator/generator/provider.d.ts +0 -19
- package/lib/adapters/postgres/src/migrator/generator/provider.js +0 -74
- package/lib/adapters/postgres/src/migrator/index.d.ts +0 -47
- package/lib/adapters/postgres/src/migrator/index.js +0 -22
- package/lib/adapters/postgres/src/migrator/runner/runner.d.ts +0 -17
- package/lib/adapters/postgres/src/migrator/runner/runner.js +0 -249
- package/lib/adapters/postgres/src/migrator/runner/status.d.ts +0 -17
- package/lib/adapters/postgres/src/migrator/runner/status.js +0 -55
- package/lib/adapters/postgres/src/postgres.bucket_adapter.d.ts +0 -42
- package/lib/adapters/postgres/src/postgres.bucket_adapter.js +0 -294
- package/lib/adapters/postgres/src/postgres.cli.d.ts +0 -76
- package/lib/adapters/postgres/src/postgres.cli.js +0 -207
- package/lib/adapters/postgres/src/postgres.config.d.ts +0 -5
- package/lib/adapters/postgres/src/postgres.config.js +0 -2
- package/lib/adapters/postgres/src/postgres.nql.d.ts +0 -16
- package/lib/adapters/postgres/src/postgres.nql.js +0 -123
- package/lib/adapters/postgres/src/postgres.provider.d.ts +0 -18
- package/lib/adapters/postgres/src/postgres.provider.js +0 -77
- package/lib/adapters/postgres/test/postgres.bucket_adapter.test.d.ts +0 -1
- package/lib/adapters/postgres/test/postgres.bucket_adapter.test.js +0 -210
package/lib/engine/dependency.js
CHANGED
|
@@ -121,6 +121,24 @@ class $Dependency {
|
|
|
121
121
|
.type;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
+
static resolve(module, dep) {
|
|
125
|
+
if (dep.type === 'constants')
|
|
126
|
+
return module.constants;
|
|
127
|
+
if (dep.type === 'externals')
|
|
128
|
+
return module.externals;
|
|
129
|
+
if (dep.type === 'bucket')
|
|
130
|
+
return module.buckets[dep.name];
|
|
131
|
+
if (dep.type === 'message')
|
|
132
|
+
return module.messages[dep.name];
|
|
133
|
+
if (dep.type === 'job')
|
|
134
|
+
return module.jobs[dep.name];
|
|
135
|
+
if (dep.type === 'resource')
|
|
136
|
+
return module.resources[dep.name];
|
|
137
|
+
if (dep.type === 'machine')
|
|
138
|
+
return module.machines[dep.name];
|
|
139
|
+
if (dep.type === 'controller')
|
|
140
|
+
return module.controllers[dep.name];
|
|
141
|
+
}
|
|
124
142
|
}
|
|
125
143
|
exports.$Dependency = $Dependency;
|
|
126
144
|
/**
|
package/lib/engine/module.d.ts
CHANGED
|
@@ -25,7 +25,8 @@ import { $Controller } from "../elements/edge/controller/controller.schema";
|
|
|
25
25
|
import { $Job } from "../elements/blocks/job/job.schema";
|
|
26
26
|
import { ModuleTree } from './tree';
|
|
27
27
|
import { AnyResourceJobBuilder } from "../elements/blocks/job/internal/resource_job.builder";
|
|
28
|
-
import { AnyApp
|
|
28
|
+
import { AnyApp } from './apps/app';
|
|
29
|
+
import { AnyService } from './apps/service';
|
|
29
30
|
import { AnyMachineJobBuilder } from "../elements/blocks/job/internal/machine_job.builder";
|
|
30
31
|
import { AnyQueueBuilder } from "../elements/blocks/queue/queue.builder";
|
|
31
32
|
import { $Queue } from "../elements/blocks/queue/queue.schema";
|
|
@@ -127,12 +128,13 @@ export declare class Module<S extends $Space, $ extends $Module> {
|
|
|
127
128
|
* Include references for external elements on the module.
|
|
128
129
|
* This allows a module to use elements from other modules directly,
|
|
129
130
|
* on single-threaded `Apps`.
|
|
131
|
+
* This implementation also includes transitive dependencies.
|
|
130
132
|
*
|
|
131
133
|
* @param daemon A `Daemon` instance
|
|
132
134
|
* @param dependencies: A dictionary of dependencies by element type
|
|
133
135
|
* @returns The `Module`, for call-chaining
|
|
134
136
|
*/
|
|
135
|
-
injectDependencies(
|
|
137
|
+
injectDependencies(modules: Record<string, AnyModule>, dependencies: {
|
|
136
138
|
buckets?: $Dependency[];
|
|
137
139
|
jobs?: $Dependency[];
|
|
138
140
|
messages?: $Dependency[];
|
|
@@ -173,9 +175,9 @@ export declare class Module<S extends $Space, $ extends $Module> {
|
|
|
173
175
|
* Create elements from schemas, and the NQL engine for this module.
|
|
174
176
|
*
|
|
175
177
|
* @param app A `App` instance
|
|
176
|
-
* @param
|
|
178
|
+
* @param services A dictionary of services by name
|
|
177
179
|
*/
|
|
178
|
-
start(app: AnyApp,
|
|
180
|
+
start(app: AnyApp, services: Record<string, AnyService>): void;
|
|
179
181
|
/**
|
|
180
182
|
* Destroy all elements from module.
|
|
181
183
|
*/
|
package/lib/engine/module.js
CHANGED
|
@@ -163,14 +163,15 @@ class Module {
|
|
|
163
163
|
* Include references for external elements on the module.
|
|
164
164
|
* This allows a module to use elements from other modules directly,
|
|
165
165
|
* on single-threaded `Apps`.
|
|
166
|
+
* This implementation also includes transitive dependencies.
|
|
166
167
|
*
|
|
167
168
|
* @param daemon A `Daemon` instance
|
|
168
169
|
* @param dependencies: A dictionary of dependencies by element type
|
|
169
170
|
* @returns The `Module`, for call-chaining
|
|
170
171
|
*/
|
|
171
|
-
injectDependencies(
|
|
172
|
+
injectDependencies(modules, dependencies) {
|
|
172
173
|
dependencies.buckets?.forEach(dep => {
|
|
173
|
-
const bucketModule =
|
|
174
|
+
const bucketModule = modules[dep.module];
|
|
174
175
|
const bucket = bucketModule.buckets[dep.name];
|
|
175
176
|
if (!bucket) {
|
|
176
177
|
throw new Error(`Internal Error: unable to find bucket '${dep.tag}' during injection to module '${this.name}'`);
|
|
@@ -178,15 +179,19 @@ class Module {
|
|
|
178
179
|
this.buckets[dep.refName] = bucket;
|
|
179
180
|
});
|
|
180
181
|
dependencies.jobs?.forEach(dep => {
|
|
181
|
-
const jobModule =
|
|
182
|
+
const jobModule = modules[dep.module];
|
|
182
183
|
const job = jobModule.jobs[dep.name];
|
|
183
184
|
if (!job) {
|
|
184
185
|
throw new Error(`Internal Error: unable to find job '${dep.tag}' during injection to module '${this.name}'`);
|
|
185
186
|
}
|
|
186
187
|
this.jobs[dep.refName] = job;
|
|
188
|
+
const schema = job.schema;
|
|
189
|
+
this.injectDependencies(modules, {
|
|
190
|
+
messages: schema.input
|
|
191
|
+
});
|
|
187
192
|
});
|
|
188
193
|
dependencies.messages?.forEach(dep => {
|
|
189
|
-
const messageModule =
|
|
194
|
+
const messageModule = modules[dep.module];
|
|
190
195
|
const message = messageModule.messages[dep.name];
|
|
191
196
|
if (!message) {
|
|
192
197
|
throw new Error(`Internal Error: unable to find message '${dep.tag}' during injection to module '${this.name}'`);
|
|
@@ -194,12 +199,18 @@ class Module {
|
|
|
194
199
|
this.messages[dep.refName] = message;
|
|
195
200
|
});
|
|
196
201
|
dependencies.machines?.forEach(dep => {
|
|
197
|
-
const machineModule =
|
|
202
|
+
const machineModule = modules[dep.module];
|
|
198
203
|
const machine = machineModule.machines[dep.name];
|
|
199
204
|
if (!machine) {
|
|
200
205
|
throw new Error(`Internal Error: unable to find machine '${dep.tag}' during injection to module '${this.name}'`);
|
|
201
206
|
}
|
|
202
207
|
this.machines[dep.refName] = machine;
|
|
208
|
+
const schema = machine.schema;
|
|
209
|
+
this.injectDependencies(modules, {
|
|
210
|
+
messages: schema.input,
|
|
211
|
+
buckets: schema.buckets,
|
|
212
|
+
jobs: schema.jobs
|
|
213
|
+
});
|
|
203
214
|
});
|
|
204
215
|
return this;
|
|
205
216
|
}
|
|
@@ -316,14 +327,14 @@ class Module {
|
|
|
316
327
|
* Create elements from schemas, and the NQL engine for this module.
|
|
317
328
|
*
|
|
318
329
|
* @param app A `App` instance
|
|
319
|
-
* @param
|
|
330
|
+
* @param services A dictionary of services by name
|
|
320
331
|
*/
|
|
321
|
-
start(app,
|
|
332
|
+
start(app, services) {
|
|
322
333
|
const info = app_1.App.getInfo(app);
|
|
323
334
|
const config = info.config;
|
|
324
335
|
Object.entries(this.schema.buckets).forEach(([name, schema]) => {
|
|
325
336
|
const bucketConfig = config.buckets?.[this.name]?.[name];
|
|
326
|
-
this.buckets[name] = new bucket_1.Bucket(schema, bucketConfig,
|
|
337
|
+
this.buckets[name] = new bucket_1.Bucket(schema, bucketConfig, services);
|
|
327
338
|
});
|
|
328
339
|
Object.entries(this.schema.messages).forEach(([name, schema]) => {
|
|
329
340
|
this.messages[name] = new message_parser_1.MessageParser(schema);
|
|
@@ -339,7 +350,7 @@ class Module {
|
|
|
339
350
|
});
|
|
340
351
|
Object.entries(this.schema.controllers).forEach(([name, schema]) => {
|
|
341
352
|
const controllerConfig = config.controllers?.[this.name]?.[name];
|
|
342
|
-
this.controllers[name] = new controller_1.Controller(this, schema, controllerConfig,
|
|
353
|
+
this.controllers[name] = new controller_1.Controller(this, schema, controllerConfig, services);
|
|
343
354
|
});
|
|
344
355
|
Object.entries(this.schema.queues).forEach(([name, schema]) => {
|
|
345
356
|
this.queues[name] = new queue_1.Queue(this, schema);
|
|
@@ -409,7 +420,11 @@ class Module {
|
|
|
409
420
|
await virtualModule.start({ config: {} }, {});
|
|
410
421
|
// Inject externals
|
|
411
422
|
if (def.externals) {
|
|
412
|
-
|
|
423
|
+
const modules = {};
|
|
424
|
+
daemon_1.Daemon.getModules(daemon).forEach(module => {
|
|
425
|
+
modules[module.name] = module;
|
|
426
|
+
});
|
|
427
|
+
virtualModule.injectDependencies(modules, def.externals);
|
|
413
428
|
}
|
|
414
429
|
return virtualModule;
|
|
415
430
|
}
|
|
@@ -32,8 +32,7 @@ class BucketTrxNode {
|
|
|
32
32
|
out = await fn(trx);
|
|
33
33
|
}
|
|
34
34
|
catch (e) {
|
|
35
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
36
|
-
throw e;
|
|
35
|
+
throw await trx_node_1.TrxNode.error(trx, e);
|
|
37
36
|
}
|
|
38
37
|
await trx_node_1.TrxNode.ok(trx, fmtTrxOut ? fmtTrxOut(out) : out);
|
|
39
38
|
return out;
|
|
@@ -35,8 +35,7 @@ class BucketQueryTrxNode {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
catch (e) {
|
|
38
|
-
await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
39
|
-
throw e;
|
|
38
|
+
throw await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
40
39
|
}
|
|
41
40
|
await trx_node_1.TrxNode.ok(this.trx, { length: results.data.length });
|
|
42
41
|
return results.data.length
|
|
@@ -52,13 +51,11 @@ class BucketQueryTrxNode {
|
|
|
52
51
|
});
|
|
53
52
|
}
|
|
54
53
|
catch (e) {
|
|
55
|
-
await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
56
|
-
throw e;
|
|
54
|
+
throw await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
57
55
|
}
|
|
58
56
|
if (!results.data.length) {
|
|
59
57
|
const e = error_1.NesoiError.Bucket.Query.NoResults({ bucket: this.bucket.schema.alias, query: this.query });
|
|
60
|
-
await trx_node_1.TrxNode.error(this.trx, e);
|
|
61
|
-
throw e;
|
|
58
|
+
throw await trx_node_1.TrxNode.error(this.trx, e);
|
|
62
59
|
}
|
|
63
60
|
await trx_node_1.TrxNode.ok(this.trx, { length: results.data.length });
|
|
64
61
|
return results.data[0];
|
|
@@ -70,8 +67,7 @@ class BucketQueryTrxNode {
|
|
|
70
67
|
results = await this.bucket.query(this.trx, this.query, undefined, this.view);
|
|
71
68
|
}
|
|
72
69
|
catch (e) {
|
|
73
|
-
await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
74
|
-
throw e;
|
|
70
|
+
throw await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
75
71
|
}
|
|
76
72
|
await trx_node_1.TrxNode.ok(this.trx, { length: results.data.length });
|
|
77
73
|
return results.data;
|
|
@@ -88,8 +84,7 @@ class BucketQueryTrxNode {
|
|
|
88
84
|
result = await this.bucket.query(this.trx, this.query, pagination, this.view);
|
|
89
85
|
}
|
|
90
86
|
catch (e) {
|
|
91
|
-
await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
92
|
-
throw e;
|
|
87
|
+
throw await trx_node_1.TrxNode.error(this.trx, e); // Bucket unexpected error
|
|
93
88
|
}
|
|
94
89
|
await trx_node_1.TrxNode.ok(this.trx, { length: result.data.length });
|
|
95
90
|
return result;
|
|
@@ -26,8 +26,7 @@ class JobTrxNode {
|
|
|
26
26
|
response = await this.job.consumeRaw(trx, message, this.ctx);
|
|
27
27
|
}
|
|
28
28
|
catch (e) {
|
|
29
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
30
|
-
throw e;
|
|
29
|
+
throw await trx_node_1.TrxNode.error(trx, e);
|
|
31
30
|
}
|
|
32
31
|
await trx_node_1.TrxNode.ok(trx, response);
|
|
33
32
|
return response;
|
|
@@ -40,8 +39,7 @@ class JobTrxNode {
|
|
|
40
39
|
response = await this.job.consume(trx, message, this.ctx);
|
|
41
40
|
}
|
|
42
41
|
catch (e) {
|
|
43
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
44
|
-
throw e;
|
|
42
|
+
throw await trx_node_1.TrxNode.error(trx, e);
|
|
45
43
|
}
|
|
46
44
|
await trx_node_1.TrxNode.ok(trx, response);
|
|
47
45
|
return response;
|
|
@@ -19,8 +19,7 @@ class MachineTrxNode {
|
|
|
19
19
|
response = await this.machine.consumeRaw(trx, message);
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
23
|
-
throw e;
|
|
22
|
+
throw await trx_node_1.TrxNode.error(trx, e);
|
|
24
23
|
}
|
|
25
24
|
await trx_node_1.TrxNode.ok(trx, response);
|
|
26
25
|
return response;
|
|
@@ -33,8 +32,7 @@ class MachineTrxNode {
|
|
|
33
32
|
response = await this.machine.consume(trx, message);
|
|
34
33
|
}
|
|
35
34
|
catch (e) {
|
|
36
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
37
|
-
throw e;
|
|
35
|
+
throw await trx_node_1.TrxNode.error(trx, e);
|
|
38
36
|
}
|
|
39
37
|
await trx_node_1.TrxNode.ok(trx, response);
|
|
40
38
|
return response;
|
|
@@ -19,8 +19,7 @@ class ResourceTrxNode {
|
|
|
19
19
|
response = await this.resource.consume(trx, message);
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
23
|
-
throw e;
|
|
22
|
+
throw await trx_node_1.TrxNode.error(trx, e);
|
|
24
23
|
}
|
|
25
24
|
await trx_node_1.TrxNode.ok(trx, response);
|
|
26
25
|
return response;
|
|
@@ -71,8 +70,7 @@ class ResourceTrxNode {
|
|
|
71
70
|
response = await this.resource.consumeRaw(trx, message);
|
|
72
71
|
}
|
|
73
72
|
catch (e) {
|
|
74
|
-
await trx_node_1.TrxNode.error(trx, e);
|
|
75
|
-
throw e;
|
|
73
|
+
throw await trx_node_1.TrxNode.error(trx, e);
|
|
76
74
|
}
|
|
77
75
|
await trx_node_1.TrxNode.ok(trx, response);
|
|
78
76
|
return response;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { $Module, $Space } from "../../schema";
|
|
2
2
|
import { Module } from '../module';
|
|
3
3
|
import { AnyTrxNode, TrxNode, TrxNodeStatus } from './trx_node';
|
|
4
|
-
import { TrxEngineOrigin } from './trx_engine';
|
|
4
|
+
import { AnyTrxEngine, TrxEngineOrigin } from './trx_engine';
|
|
5
5
|
import { AnyUsers, AuthnRequest } from '../auth/authn';
|
|
6
6
|
import { NesoiDatetime } from '../data/datetime';
|
|
7
|
+
import { NesoiError } from '../data/error';
|
|
7
8
|
type TrxOrigin = TrxEngineOrigin | `trx:${string}`;
|
|
8
9
|
type TrxState = 'open' | 'ok' | 'error';
|
|
9
10
|
/**
|
|
@@ -17,9 +18,9 @@ export declare class TrxStatus<Output> {
|
|
|
17
18
|
end?: NesoiDatetime | undefined;
|
|
18
19
|
state?: TrxState | undefined;
|
|
19
20
|
output?: Output | undefined;
|
|
20
|
-
error?:
|
|
21
|
+
error?: NesoiError.BaseError | undefined;
|
|
21
22
|
nodes: TrxNodeStatus[];
|
|
22
|
-
constructor(id: string, origin: TrxOrigin, start: NesoiDatetime, end?: NesoiDatetime | undefined, state?: TrxState | undefined, output?: Output | undefined, error?:
|
|
23
|
+
constructor(id: string, origin: TrxOrigin, start: NesoiDatetime, end?: NesoiDatetime | undefined, state?: TrxState | undefined, output?: Output | undefined, error?: NesoiError.BaseError | undefined, nodes?: TrxNodeStatus[]);
|
|
23
24
|
summary(): string;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
@@ -27,6 +28,7 @@ export declare class TrxStatus<Output> {
|
|
|
27
28
|
* @subcategory Transaction
|
|
28
29
|
*/
|
|
29
30
|
export declare class Trx<S extends $Space, M extends $Module, Authn extends AnyUsers> {
|
|
31
|
+
engine: AnyTrxEngine;
|
|
30
32
|
private module;
|
|
31
33
|
id: string;
|
|
32
34
|
private origin;
|
|
@@ -35,7 +37,7 @@ export declare class Trx<S extends $Space, M extends $Module, Authn extends AnyU
|
|
|
35
37
|
start: NesoiDatetime;
|
|
36
38
|
end?: NesoiDatetime;
|
|
37
39
|
ctx: Record<string, any>;
|
|
38
|
-
constructor(module: Module<S, M>, origin: TrxOrigin, authn?: {
|
|
40
|
+
constructor(engine: AnyTrxEngine, module: Module<S, M>, origin: TrxOrigin, authn?: {
|
|
39
41
|
tokens: AuthnRequest<any>;
|
|
40
42
|
users: Authn;
|
|
41
43
|
}, id?: string, root?: TrxNode<S, M, Authn>, nodes?: Record<string, TrxNode<S, M, Authn>>);
|
|
@@ -54,7 +54,8 @@ exports.TrxStatus = TrxStatus;
|
|
|
54
54
|
* @subcategory Transaction
|
|
55
55
|
*/
|
|
56
56
|
class Trx {
|
|
57
|
-
constructor(module, origin, authn, id, root, nodes) {
|
|
57
|
+
constructor(engine, module, origin, authn, id, root, nodes) {
|
|
58
|
+
this.engine = engine;
|
|
58
59
|
this.start = datetime_1.NesoiDatetime.now();
|
|
59
60
|
this.ctx = {};
|
|
60
61
|
this.module = module;
|
|
@@ -4,10 +4,10 @@ import { AnyTrx, Trx } from './trx';
|
|
|
4
4
|
import { AnyUsers } from '../auth/authn';
|
|
5
5
|
import { TrxNode, TrxNodeStatus } from './trx_node';
|
|
6
6
|
export type TrxEngineWrapFn<S extends $Space, M extends $Module> = (trx: TrxNode<S, M, any>) => Promise<TrxNodeStatus>;
|
|
7
|
-
export type TrxEngineConfig<S extends $Space, M extends $Module, Authn extends AnyUsers,
|
|
7
|
+
export type TrxEngineConfig<S extends $Space, M extends $Module, Authn extends AnyUsers, Services extends Record<string, any>> = {
|
|
8
8
|
/**
|
|
9
9
|
* Adapter used to store transactions of this module.
|
|
10
10
|
*/
|
|
11
11
|
adapter?: (schema: M) => BucketAdapter<AnyTrx>;
|
|
12
|
-
wrap?: <T extends Trx<S, M, Authn>>(trx: T, fn: TrxEngineWrapFn<S, M>,
|
|
12
|
+
wrap?: <T extends Trx<S, M, Authn>>(trx: T, fn: TrxEngineWrapFn<S, M>, services: Services) => Promise<any>;
|
|
13
13
|
};
|
|
@@ -4,6 +4,7 @@ import { Trx } from './trx';
|
|
|
4
4
|
import { TrxNode, TrxNodeStatus } from './trx_node';
|
|
5
5
|
import { AnyAuthnProviders, AuthnRequest } from '../auth/authn';
|
|
6
6
|
import { TrxEngineConfig } from './trx_engine.config';
|
|
7
|
+
import { IService } from '../apps/service';
|
|
7
8
|
export type TrxEngineOrigin = `app:${string}`;
|
|
8
9
|
/**
|
|
9
10
|
* @category Engine
|
|
@@ -14,17 +15,17 @@ export declare class TrxEngine<S extends $Space, M extends $Module, Authn extend
|
|
|
14
15
|
private module;
|
|
15
16
|
private authnProviders?;
|
|
16
17
|
private config?;
|
|
17
|
-
private
|
|
18
|
+
private services;
|
|
18
19
|
/**
|
|
19
20
|
* Transaction used to read/write transactions on the adapter
|
|
20
21
|
*/
|
|
21
22
|
private innerTrx;
|
|
22
23
|
private adapter;
|
|
23
|
-
constructor(origin: TrxEngineOrigin, module: Module<S, M>, authnProviders?: Authn | undefined, config?: TrxEngineConfig<S, M, any, any> | undefined,
|
|
24
|
+
constructor(origin: TrxEngineOrigin, module: Module<S, M>, authnProviders?: Authn | undefined, config?: TrxEngineConfig<S, M, any, any> | undefined, services?: Record<string, IService>);
|
|
24
25
|
getModule(): Module<S, M>;
|
|
25
26
|
get(id?: string): Promise<Trx<S, M, any>>;
|
|
26
27
|
trx(fn: (trx: TrxNode<S, M, any>) => Promise<TrxNodeStatus>, authn?: AuthnRequest<keyof Authn>): Promise<import("./trx").TrxStatus<any>>;
|
|
27
|
-
|
|
28
|
+
authenticate(node: TrxNode<S, M, any>, request?: AuthnRequest<keyof Authn>): Promise<void>;
|
|
28
29
|
private commit;
|
|
29
30
|
private rollback;
|
|
30
31
|
}
|
|
@@ -11,13 +11,13 @@ const memory_bucket_adapter_1 = require("../../elements/entities/bucket/adapters
|
|
|
11
11
|
* @subcategory Transaction
|
|
12
12
|
*/
|
|
13
13
|
class TrxEngine {
|
|
14
|
-
constructor(origin, module, authnProviders, config,
|
|
14
|
+
constructor(origin, module, authnProviders, config, services = {}) {
|
|
15
15
|
this.origin = origin;
|
|
16
16
|
this.module = module;
|
|
17
17
|
this.authnProviders = authnProviders;
|
|
18
18
|
this.config = config;
|
|
19
|
-
this.
|
|
20
|
-
this.innerTrx = new trx_1.Trx(this.module, `trx:${origin}`);
|
|
19
|
+
this.services = services;
|
|
20
|
+
this.innerTrx = new trx_1.Trx(this, this.module, `trx:${origin}`);
|
|
21
21
|
this.adapter = config?.adapter?.(module.schema) || new memory_bucket_adapter_1.MemoryBucketAdapter({}, {});
|
|
22
22
|
}
|
|
23
23
|
getModule() {
|
|
@@ -26,7 +26,7 @@ class TrxEngine {
|
|
|
26
26
|
async get(id) {
|
|
27
27
|
let trx = undefined;
|
|
28
28
|
if (!id) {
|
|
29
|
-
trx = new trx_1.Trx(this.module, this.origin);
|
|
29
|
+
trx = new trx_1.Trx(this, this.module, this.origin);
|
|
30
30
|
log_1.Log.info('module', this.module.name, `Begin ${(0, log_1.scopeTag)('trx', trx.id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
|
|
31
31
|
return this.adapter.create(this.innerTrx.root, trx);
|
|
32
32
|
}
|
|
@@ -37,7 +37,7 @@ class TrxEngine {
|
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
log_1.Log.info('module', this.module.name, `Chain ${(0, log_1.scopeTag)('trx', id)} @ ${(0, log_1.anyScopeTag)(this.origin)}`);
|
|
40
|
-
trx = new trx_1.Trx(this.module, this.origin, undefined, id);
|
|
40
|
+
trx = new trx_1.Trx(this, this.module, this.origin, undefined, id);
|
|
41
41
|
return this.adapter.create(this.innerTrx.root, trx);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -46,13 +46,10 @@ class TrxEngine {
|
|
|
46
46
|
async trx(fn, authn) {
|
|
47
47
|
const trx = await this.get(undefined);
|
|
48
48
|
try {
|
|
49
|
-
|
|
50
|
-
if (users) {
|
|
51
|
-
trx_node_1.TrxNode.addAuthn(trx.root, authn, users);
|
|
52
|
-
}
|
|
49
|
+
await this.authenticate(trx.root, authn);
|
|
53
50
|
let output;
|
|
54
51
|
if (this.config?.wrap) {
|
|
55
|
-
output = await this.config?.wrap(trx, fn, this.
|
|
52
|
+
output = await this.config?.wrap(trx, fn, this.services);
|
|
56
53
|
}
|
|
57
54
|
else {
|
|
58
55
|
output = await fn(trx.root);
|
|
@@ -65,19 +62,25 @@ class TrxEngine {
|
|
|
65
62
|
return trx.status();
|
|
66
63
|
}
|
|
67
64
|
// authentication
|
|
68
|
-
async authenticate(
|
|
65
|
+
async authenticate(node, request = {}) {
|
|
69
66
|
if (!this.authnProviders) {
|
|
70
67
|
throw error_1.NesoiError.Authn.NoProvidersRegisteredForModule(this.module.name);
|
|
71
68
|
}
|
|
72
69
|
const users = {};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
const tokens = {};
|
|
71
|
+
for (const providerName in this.authnProviders) {
|
|
72
|
+
const provider = this.authnProviders[providerName];
|
|
73
|
+
const reqToken = request[providerName];
|
|
74
|
+
if (provider.eager || reqToken) {
|
|
75
|
+
if (!provider) {
|
|
76
|
+
throw error_1.NesoiError.Authn.NoProviderRegisteredForModule(this.module.name, providerName);
|
|
77
|
+
}
|
|
78
|
+
const { user, token } = await provider.authenticate({ trx: node, token: reqToken });
|
|
79
|
+
users[providerName] = user;
|
|
80
|
+
tokens[providerName] = token;
|
|
77
81
|
}
|
|
78
|
-
users[provider] = await this.authnProviders[provider].authenticate({ trx, token });
|
|
79
82
|
}
|
|
80
|
-
|
|
83
|
+
trx_node_1.TrxNode.addAuthn(node, tokens, users);
|
|
81
84
|
}
|
|
82
85
|
//
|
|
83
86
|
async commit(trx, output) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { $Module, $Space } from "../../schema";
|
|
2
|
+
import { NesoiError } from '../data/error';
|
|
2
3
|
import { AnyModule, VirtualModuleDef } from '../module';
|
|
3
4
|
import { AnyTrx } from './trx';
|
|
4
5
|
import { BucketTrxNode } from './nodes/bucket.trx_node';
|
|
@@ -18,7 +19,7 @@ export type TrxNodeStatus = {
|
|
|
18
19
|
action?: string;
|
|
19
20
|
input?: Record<string, any>;
|
|
20
21
|
output?: Record<string, any>;
|
|
21
|
-
error?:
|
|
22
|
+
error?: NesoiError.BaseError;
|
|
22
23
|
nodes: TrxNodeStatus[];
|
|
23
24
|
app: number;
|
|
24
25
|
};
|
|
@@ -47,7 +48,7 @@ export declare class TrxNode<Space extends $Space, M extends $Module, Authn exte
|
|
|
47
48
|
} | undefined, id?: string);
|
|
48
49
|
static open(node: AnyTrxNode, action: string, input: Record<string, any>): Promise<void>;
|
|
49
50
|
static ok(node: AnyTrxNode, output?: Record<string, any>): Promise<void>;
|
|
50
|
-
static error(node: AnyTrxNode, error: any): Promise<
|
|
51
|
+
static error(node: AnyTrxNode, error: any): Promise<any>;
|
|
51
52
|
message<Raw extends M['#input']['#raw'], Msg extends $Message = M['messages'][Raw['$'] & keyof M['messages']]>(raw: Raw): Promise<M['#input']['#parsed']>;
|
|
52
53
|
value<K extends keyof M['constants']['values']>(key: K): M["constants"]["values"][K]["value"];
|
|
53
54
|
enum<EnumName extends KeysOfUnion<Space['modules'][keyof Space['modules']]['constants']['enums']>>(name: EnumName): Enum<M['constants']['enums'][EnumName]>;
|
|
@@ -57,6 +58,7 @@ export declare class TrxNode<Space extends $Space, M extends $Module, Authn exte
|
|
|
57
58
|
resource<Name extends keyof M['resources'], Resource extends M['resources'][Name]>(name: Name): ResourceTrxNode<M, Resource>;
|
|
58
59
|
machine<Name extends keyof M['machines'], Machine extends M['machines'][Name]>(name: Name): MachineTrxNode<M, Machine>;
|
|
59
60
|
queue<Name extends keyof M['queues'], Queue extends M['queues'][Name]>(name: Name): QueueTrxNode<M, Queue>;
|
|
61
|
+
authenticate(authnRequest: AuthnRequest<keyof Authn>): Promise<TrxNode<$Space, $Module, Authn>>;
|
|
60
62
|
token<U extends keyof Authn & keyof M['#authn']>(provider: U): M['#authn'][U];
|
|
61
63
|
user<U extends keyof Authn & keyof M['#authn']>(provider: U): M['#authn'][U];
|
|
62
64
|
virtual<T>(def: VirtualModuleDef, fn: ($: AnyTrxNode) => T | Promise<T>): Promise<T>;
|
|
@@ -51,8 +51,15 @@ class TrxNode {
|
|
|
51
51
|
}
|
|
52
52
|
static async error(node, error) {
|
|
53
53
|
node.state = 'error';
|
|
54
|
-
|
|
54
|
+
if (error instanceof error_1.NesoiError.BaseError) {
|
|
55
|
+
error.message = i18n_1.i18n.error(error, node.trx.root.module.daemon);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
error = new error_1.NesoiError.BaseError('UnknownError', error.message);
|
|
59
|
+
}
|
|
60
|
+
node.error = error;
|
|
55
61
|
node.time.end = datetime_1.NesoiDatetime.now();
|
|
62
|
+
return error;
|
|
56
63
|
}
|
|
57
64
|
// Entities
|
|
58
65
|
async message(raw) {
|
|
@@ -121,6 +128,11 @@ class TrxNode {
|
|
|
121
128
|
return new queue_trx_node_1.QueueTrxNode(this, queue);
|
|
122
129
|
}
|
|
123
130
|
// Authentication
|
|
131
|
+
async authenticate(authnRequest) {
|
|
132
|
+
const newNode = new TrxNode(this.scope, this.trx, this, this.module, this.authn);
|
|
133
|
+
await this.trx.engine.authenticate(newNode, authnRequest);
|
|
134
|
+
return newNode;
|
|
135
|
+
}
|
|
124
136
|
token(provider) {
|
|
125
137
|
if (!this.authn?.tokens) {
|
|
126
138
|
throw error_1.NesoiError.Authn.NoUsersAuthenticatedForTrxNode(this.globalId);
|
package/lib/engine/tree.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModuleTree = void 0;
|
|
4
|
+
const dependency_1 = require("./dependency");
|
|
4
5
|
const error_1 = require("../compiler/error");
|
|
5
6
|
const log_1 = require("./util/log");
|
|
6
7
|
const string_1 = require("./util/string");
|
|
@@ -253,23 +254,11 @@ class ModuleTree {
|
|
|
253
254
|
*/
|
|
254
255
|
getSchema(node) {
|
|
255
256
|
const mod = this.modules[node.module];
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return mod.schema.buckets[node.name];
|
|
262
|
-
if (node.type === 'message')
|
|
263
|
-
return mod.schema.messages[node.name];
|
|
264
|
-
if (node.type === 'job')
|
|
265
|
-
return mod.schema.jobs[node.name];
|
|
266
|
-
if (node.type === 'resource')
|
|
267
|
-
return mod.schema.resources[node.name];
|
|
268
|
-
if (node.type === 'machine')
|
|
269
|
-
return mod.schema.machines[node.name];
|
|
270
|
-
if (node.type === 'controller')
|
|
271
|
-
return mod.schema.controllers[node.name];
|
|
272
|
-
throw error_1.CompilerError.UnmetDependency('tree', node.name);
|
|
257
|
+
const schema = dependency_1.$Dependency.resolve(mod.schema, node);
|
|
258
|
+
if (!schema) {
|
|
259
|
+
throw error_1.CompilerError.UnmetDependency('tree', node.name);
|
|
260
|
+
}
|
|
261
|
+
return schema;
|
|
273
262
|
}
|
|
274
263
|
/**
|
|
275
264
|
* Return a list of all nodes of all modules on the tree.
|
package/lib/engine/util/i18n.js
CHANGED
|
@@ -5,15 +5,15 @@ const daemon_1 = require("../daemon");
|
|
|
5
5
|
class i18n {
|
|
6
6
|
static error(error, daemon) {
|
|
7
7
|
if (!daemon) {
|
|
8
|
-
return error.
|
|
8
|
+
return error.message;
|
|
9
9
|
}
|
|
10
|
-
const strings = daemon_1.Daemon.get(daemon, '
|
|
10
|
+
const strings = daemon_1.Daemon.get(daemon, 'config')?.i18n || {};
|
|
11
11
|
if (error.name in strings) {
|
|
12
12
|
const msg = strings[error.name](error.data || {});
|
|
13
13
|
error.message = msg;
|
|
14
14
|
return msg;
|
|
15
15
|
}
|
|
16
|
-
return error.
|
|
16
|
+
return error.message;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.i18n = i18n;
|
|
@@ -5,6 +5,7 @@ import { AnyTrxNode } from '../transaction/trx_node';
|
|
|
5
5
|
import { NesoiDecimal } from '../data/decimal';
|
|
6
6
|
import { NesoiDatetime } from '../data/datetime';
|
|
7
7
|
import { NesoiFile } from '../data/file';
|
|
8
|
+
import { NesoiDuration } from '../data/duration';
|
|
8
9
|
export declare function parseBoolean(field: {
|
|
9
10
|
name: string;
|
|
10
11
|
alias: string;
|
|
@@ -17,6 +18,10 @@ export declare function parseDatetime(field: {
|
|
|
17
18
|
name: string;
|
|
18
19
|
alias: string;
|
|
19
20
|
}, value: any, array: boolean): Promise<NesoiDatetime | NesoiDatetime[]>;
|
|
21
|
+
export declare function parseDuration(field: {
|
|
22
|
+
name: string;
|
|
23
|
+
alias: string;
|
|
24
|
+
}, value: any, array: boolean): Promise<NesoiDuration | NesoiDuration[]>;
|
|
20
25
|
export declare function parseDecimal(field: {
|
|
21
26
|
name: string;
|
|
22
27
|
alias: string;
|
package/lib/engine/util/parse.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseBoolean = parseBoolean;
|
|
4
4
|
exports.parseDate = parseDate;
|
|
5
5
|
exports.parseDatetime = parseDatetime;
|
|
6
|
+
exports.parseDuration = parseDuration;
|
|
6
7
|
exports.parseDecimal = parseDecimal;
|
|
7
8
|
exports.parseEnum = parseEnum;
|
|
8
9
|
exports.parseFile = parseFile;
|
|
@@ -19,6 +20,7 @@ const tree_1 = require("../data/tree");
|
|
|
19
20
|
const decimal_1 = require("../data/decimal");
|
|
20
21
|
const datetime_1 = require("../data/datetime");
|
|
21
22
|
const file_1 = require("../data/file");
|
|
23
|
+
const duration_1 = require("../data/duration");
|
|
22
24
|
// TODO: check the performance of this wild thing below
|
|
23
25
|
async function parse(type, field, value, array, fn) {
|
|
24
26
|
if (array) {
|
|
@@ -64,6 +66,14 @@ function parseDatetime(field, value, array) {
|
|
|
64
66
|
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'datetime' });
|
|
65
67
|
});
|
|
66
68
|
}
|
|
69
|
+
function parseDuration(field, value, array) {
|
|
70
|
+
return parse('duration', field, value, array, (v) => {
|
|
71
|
+
if (typeof v === 'string') {
|
|
72
|
+
return duration_1.NesoiDuration.fromString(v);
|
|
73
|
+
}
|
|
74
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'duration' });
|
|
75
|
+
});
|
|
76
|
+
}
|
|
67
77
|
function parseDecimal(field, value, array) {
|
|
68
78
|
return parse('decimal', field, value, array, (v) => {
|
|
69
79
|
if (typeof v === 'string') {
|
package/lib/schema.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export type $Module = {
|
|
|
44
44
|
};
|
|
45
45
|
'#input': $Message;
|
|
46
46
|
'#authn': AnyUsers;
|
|
47
|
-
'#
|
|
47
|
+
'#services': Record<string, any>;
|
|
48
48
|
};
|
|
49
49
|
export type ModuleName<$ extends $Space> = keyof $['modules'];
|
|
50
50
|
export type MessageName<$ extends $Module> = keyof $['messages'];
|