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
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.InlineDaemon = exports.InlineApp = void 0;
|
|
4
7
|
const app_1 = require("./app");
|
|
@@ -7,6 +10,7 @@ const trx_engine_1 = require("../transaction/trx_engine");
|
|
|
7
10
|
const tree_1 = require("../tree");
|
|
8
11
|
const daemon_1 = require("../daemon");
|
|
9
12
|
const app_config_1 = require("./app.config");
|
|
13
|
+
const promise_1 = __importDefault(require("../util/promise"));
|
|
10
14
|
/**
|
|
11
15
|
* @category App
|
|
12
16
|
*/
|
|
@@ -44,7 +48,7 @@ class InlineApp extends app_1.App {
|
|
|
44
48
|
});
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
47
|
-
* Build the application, start
|
|
51
|
+
* Build the application, start services and trx engines.
|
|
48
52
|
* Returns references to start a daemon.
|
|
49
53
|
*/
|
|
50
54
|
async make() {
|
|
@@ -56,19 +60,19 @@ class InlineApp extends app_1.App {
|
|
|
56
60
|
const mod = this._injectedModules[key];
|
|
57
61
|
modules[mod.name] = mod;
|
|
58
62
|
}
|
|
59
|
-
const
|
|
60
|
-
for (const key in this.
|
|
61
|
-
const
|
|
63
|
+
const services = {};
|
|
64
|
+
for (const key in this._services) {
|
|
65
|
+
const service = this._services[key];
|
|
66
|
+
await promise_1.default.solve(service.up({
|
|
62
67
|
modules
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
providers[key] = provider;
|
|
68
|
+
}));
|
|
69
|
+
services[key] = service;
|
|
66
70
|
}
|
|
67
71
|
log_1.Log.debug('app', this.name, 'Starting transaction engines');
|
|
68
72
|
const trxEngines = {};
|
|
69
73
|
for (const m in modules) {
|
|
70
74
|
const module = modules[m];
|
|
71
|
-
module.start(this,
|
|
75
|
+
module.start(this, services);
|
|
72
76
|
const trxConfig = this._config.trxEngine?.[m];
|
|
73
77
|
const authn = {};
|
|
74
78
|
for (const a in this._config?.authn || {}) {
|
|
@@ -77,13 +81,13 @@ class InlineApp extends app_1.App {
|
|
|
77
81
|
authn[a] = prov;
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
|
-
trxEngines[m] = new trx_engine_1.TrxEngine(`app:${this.name}`, module, authn, trxConfig,
|
|
84
|
+
trxEngines[m] = new trx_engine_1.TrxEngine(`app:${this.name}`, module, authn, trxConfig, services);
|
|
81
85
|
}
|
|
82
86
|
log_1.Log.debug('app', this.name, 'Linking externals');
|
|
83
87
|
this.linkExternals(modules);
|
|
84
88
|
return {
|
|
85
89
|
modules,
|
|
86
|
-
|
|
90
|
+
services,
|
|
87
91
|
trxEngines
|
|
88
92
|
};
|
|
89
93
|
}
|
|
@@ -93,7 +97,7 @@ class InlineApp extends app_1.App {
|
|
|
93
97
|
}
|
|
94
98
|
const app = await this.make();
|
|
95
99
|
log_1.Log.debug('app', this.name, 'Spawning daemon');
|
|
96
|
-
this._daemon = this.makeDaemon(app.trxEngines, app.
|
|
100
|
+
this._daemon = this.makeDaemon(app.trxEngines, app.services);
|
|
97
101
|
// Link daemon to modules
|
|
98
102
|
for (const m in app.modules) {
|
|
99
103
|
const module = app.modules[m];
|
|
@@ -101,8 +105,8 @@ class InlineApp extends app_1.App {
|
|
|
101
105
|
}
|
|
102
106
|
return this._daemon;
|
|
103
107
|
}
|
|
104
|
-
makeDaemon(trxEngines,
|
|
105
|
-
return new InlineDaemon(this.name, trxEngines,
|
|
108
|
+
makeDaemon(trxEngines, services) {
|
|
109
|
+
return new InlineDaemon(this.name, trxEngines, services, this._config);
|
|
106
110
|
}
|
|
107
111
|
package(_package) {
|
|
108
112
|
this.packageJson = _package;
|
|
@@ -116,19 +120,15 @@ class InlineApp extends app_1.App {
|
|
|
116
120
|
*/
|
|
117
121
|
linkExternals(modules) {
|
|
118
122
|
Object.values(modules).forEach(module => {
|
|
123
|
+
module.injectDependencies(modules, {
|
|
124
|
+
buckets: Object.values(module.schema.externals.buckets),
|
|
125
|
+
jobs: Object.values(module.schema.externals.jobs),
|
|
126
|
+
machines: Object.values(module.schema.externals.machines),
|
|
127
|
+
});
|
|
119
128
|
const buckets = module.schema.externals.buckets;
|
|
120
129
|
Object.values(buckets).forEach(bucket => {
|
|
121
|
-
module.buckets[bucket.refName] = modules[bucket.module].buckets[bucket.name];
|
|
122
130
|
module.nql.linkExternal(modules[bucket.module].buckets[bucket.name]);
|
|
123
131
|
});
|
|
124
|
-
const jobs = module.schema.externals.jobs;
|
|
125
|
-
Object.values(jobs).forEach(job => {
|
|
126
|
-
module.jobs[job.refName] = modules[job.module].jobs[job.name];
|
|
127
|
-
});
|
|
128
|
-
const machines = module.schema.externals.machines;
|
|
129
|
-
Object.values(machines).forEach(machine => {
|
|
130
|
-
module.machines[machine.refName] = modules[machine.module].machines[machine.name];
|
|
131
|
-
});
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
// Type Builder Overrides
|
|
@@ -136,8 +136,8 @@ class InlineApp extends app_1.App {
|
|
|
136
136
|
super.modules(modules);
|
|
137
137
|
return this;
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
super.
|
|
139
|
+
service($) {
|
|
140
|
+
super.service($);
|
|
141
141
|
return this;
|
|
142
142
|
}
|
|
143
143
|
get config() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $Space, ModuleName } from "../../../schema";
|
|
2
|
-
import {
|
|
2
|
+
import { IService } from '../service';
|
|
3
3
|
import { InlineApp } from './../inline.app';
|
|
4
4
|
import { AnyTrxEngine } from '../../transaction/trx_engine';
|
|
5
5
|
import { Space } from '../../space';
|
|
@@ -9,18 +9,18 @@ import { AppConfigFactory } from '../app.config';
|
|
|
9
9
|
* @category App
|
|
10
10
|
* @subcategory Monolyth
|
|
11
11
|
*/
|
|
12
|
-
export declare class MonolythApp<S extends $Space, ModuleNames extends string = ModuleName<S> & string,
|
|
12
|
+
export declare class MonolythApp<S extends $Space, ModuleNames extends string = ModuleName<S> & string, Services extends Record<string, any> = Record<string, any>> extends InlineApp<S, ModuleNames, Services> {
|
|
13
13
|
private watcher?;
|
|
14
14
|
constructor(name: string, space?: Space<S>);
|
|
15
15
|
protected _packageJson?: Record<string, any>;
|
|
16
16
|
daemon($?: {
|
|
17
17
|
watch?: boolean;
|
|
18
18
|
}): Promise<Daemon<S, ModuleNames>>;
|
|
19
|
-
protected makeDaemon(trxEngines: Record<ModuleNames, AnyTrxEngine>,
|
|
19
|
+
protected makeDaemon(trxEngines: Record<ModuleNames, AnyTrxEngine>, services: Record<string, IService>): MonolythDaemon<$Space, ModuleNames>;
|
|
20
20
|
remake(): Promise<void>;
|
|
21
21
|
modules<M extends ModuleName<S>>(modules: M[]): MonolythApp<S, M & ModuleNames>;
|
|
22
|
-
|
|
23
|
-
get config(): AppConfigFactory<S, ModuleNames,
|
|
22
|
+
service<T extends IService>($: T): MonolythApp<S, ModuleNames, Services & { [K in T["name"]]: T; }>;
|
|
23
|
+
get config(): AppConfigFactory<S, ModuleNames, Services, typeof this>;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* @category App
|
|
@@ -76,8 +76,8 @@ class MonolythApp extends inline_app_1.InlineApp {
|
|
|
76
76
|
}
|
|
77
77
|
return super.daemon();
|
|
78
78
|
}
|
|
79
|
-
makeDaemon(trxEngines,
|
|
80
|
-
return new MonolythDaemon(this.name, trxEngines,
|
|
79
|
+
makeDaemon(trxEngines, services) {
|
|
80
|
+
return new MonolythDaemon(this.name, trxEngines, services, this._config);
|
|
81
81
|
}
|
|
82
82
|
// Reboot (from Watcher)
|
|
83
83
|
async remake() {
|
|
@@ -86,18 +86,18 @@ class MonolythApp extends inline_app_1.InlineApp {
|
|
|
86
86
|
log_1.Log.error('app', 'monolyth', `Attempt to remake app ${this.name} failed: Daemon not running.`);
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
|
-
await
|
|
89
|
+
await this._daemon.destroy();
|
|
90
90
|
this.bootPromise = undefined;
|
|
91
91
|
const app = await this.make();
|
|
92
|
-
await
|
|
92
|
+
await this._daemon.reload(app.trxEngines, app.services);
|
|
93
93
|
}
|
|
94
94
|
// Type Builder Overrides
|
|
95
95
|
modules(modules) {
|
|
96
96
|
super.modules(modules);
|
|
97
97
|
return this;
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
super.
|
|
99
|
+
service($) {
|
|
100
|
+
super.service($);
|
|
101
101
|
return this;
|
|
102
102
|
}
|
|
103
103
|
get config() {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AnyModule } from '../module';
|
|
2
|
+
/**
|
|
3
|
+
* Service
|
|
4
|
+
*/
|
|
5
|
+
type Optional<T> = (T extends undefined ? [] : never) | [cfg: T];
|
|
6
|
+
export declare abstract class Service<out Name extends string, Config = never> {
|
|
7
|
+
/**
|
|
8
|
+
* This property MUST be set on the implementation class.
|
|
9
|
+
*/
|
|
10
|
+
static defaultName: string;
|
|
11
|
+
name: Name;
|
|
12
|
+
config: Config;
|
|
13
|
+
libPaths?: string[];
|
|
14
|
+
abstract up($: {
|
|
15
|
+
modules: Record<string, AnyModule>;
|
|
16
|
+
}): void | Promise<void>;
|
|
17
|
+
abstract down(): void | Promise<void>;
|
|
18
|
+
constructor(...cfg: Optional<Config>);
|
|
19
|
+
constructor(name: Name, ...cfg: Optional<Config>);
|
|
20
|
+
}
|
|
21
|
+
export type AnyService = Service<any, any>;
|
|
22
|
+
export interface IService {
|
|
23
|
+
name: string;
|
|
24
|
+
libPaths?: string[];
|
|
25
|
+
up(this: IService, $: {
|
|
26
|
+
modules: Record<string, AnyModule>;
|
|
27
|
+
}): void | Promise<void>;
|
|
28
|
+
down(this: IService): void | Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Service = void 0;
|
|
4
|
+
class Service {
|
|
5
|
+
constructor(arg1, arg2) {
|
|
6
|
+
if (typeof arg1 === 'string') {
|
|
7
|
+
this.name = arg1;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
this.name = this.constructor.defaultName;
|
|
11
|
+
}
|
|
12
|
+
this.config = arg2 || arg1;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Service = Service;
|
|
@@ -13,10 +13,19 @@ export type AuthnRequest<P extends keyof any> = {
|
|
|
13
13
|
* @subcategory Auth
|
|
14
14
|
*/
|
|
15
15
|
export declare abstract class AuthnProvider<U extends User> {
|
|
16
|
+
/**
|
|
17
|
+
* - If `true`, this provider is run for all transactions, regardless
|
|
18
|
+
* of a token being sent on the authentication request.
|
|
19
|
+
* - If `false`, the `$.token` is always defined.
|
|
20
|
+
*/
|
|
21
|
+
abstract eager: boolean;
|
|
16
22
|
abstract authenticate($: {
|
|
17
23
|
trx: AnyTrxNode;
|
|
24
|
+
token?: AuthnToken;
|
|
25
|
+
}): Promise<{
|
|
18
26
|
token: AuthnToken;
|
|
19
|
-
|
|
27
|
+
user: U;
|
|
28
|
+
}>;
|
|
20
29
|
}
|
|
21
30
|
export type AnyAuthnProviders = {
|
|
22
31
|
[K: string]: AuthnProvider<any>;
|
|
@@ -9,11 +9,15 @@ type ZeroUser = {
|
|
|
9
9
|
* @subcategory Auth
|
|
10
10
|
*/
|
|
11
11
|
export declare class ZeroAuthnProvider extends AuthnProvider<ZeroUser> {
|
|
12
|
+
eager: boolean;
|
|
12
13
|
authenticate($: {
|
|
13
|
-
token
|
|
14
|
+
token?: string;
|
|
14
15
|
}): Promise<{
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
token: string;
|
|
17
|
+
user: {
|
|
18
|
+
id: number;
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
17
21
|
}>;
|
|
18
22
|
}
|
|
19
23
|
export {};
|
|
@@ -7,10 +7,17 @@ const authn_1 = require("./authn");
|
|
|
7
7
|
* @subcategory Auth
|
|
8
8
|
*/
|
|
9
9
|
class ZeroAuthnProvider extends authn_1.AuthnProvider {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.eager = false;
|
|
13
|
+
}
|
|
10
14
|
authenticate($) {
|
|
11
15
|
return Promise.resolve({
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
token: $.token,
|
|
17
|
+
user: {
|
|
18
|
+
id: 0,
|
|
19
|
+
name: $.token
|
|
20
|
+
}
|
|
14
21
|
});
|
|
15
22
|
}
|
|
16
23
|
}
|
package/lib/engine/cli/cli.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AnyDaemon } from '../daemon';
|
|
2
2
|
import { CLIAdapter } from './cli_adapter';
|
|
3
|
-
export type CLIConfig<
|
|
3
|
+
export type CLIConfig<Services> = {
|
|
4
4
|
editor?: string;
|
|
5
5
|
adapters?: {
|
|
6
|
-
[x: string]: (cli: CLI,
|
|
6
|
+
[x: string]: (cli: CLI, services: Services) => CLIAdapter;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
9
|
/**
|
package/lib/engine/cli/cli.js
CHANGED
|
@@ -25,7 +25,7 @@ class CLI {
|
|
|
25
25
|
// Build adapters
|
|
26
26
|
this.adapters = {};
|
|
27
27
|
Object.entries(config?.adapters || {}).forEach(([key, val]) => {
|
|
28
|
-
this.adapters[key] = val(this, daemon_1.Daemon.get(daemon, '
|
|
28
|
+
this.adapters[key] = val(this, daemon_1.Daemon.get(daemon, 'services'));
|
|
29
29
|
this.adapters[key].name = key;
|
|
30
30
|
});
|
|
31
31
|
this.input = new cli_input_1.CLIInputHandler(this.getCmds());
|
package/lib/engine/cli/ui.js
CHANGED
|
@@ -142,7 +142,7 @@ class UI {
|
|
|
142
142
|
* Ask a yes or no question and wait for the answer
|
|
143
143
|
*/
|
|
144
144
|
static async yesOrNo(text, defaul = 'n') {
|
|
145
|
-
const answer = await this.waitForAnyKey('\n\t» ' + (0, string_1.colored)(text, 'lightblue') + (0, string_1.colored)(' [y|n]', '
|
|
145
|
+
const answer = await this.waitForAnyKey('\n\t» ' + (0, string_1.colored)(text, 'lightblue') + (0, string_1.colored)(' [y|n]', 'darkgray'));
|
|
146
146
|
if (answer.name === 'y')
|
|
147
147
|
return true;
|
|
148
148
|
return false;
|
package/lib/engine/daemon.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { AnyUsers, AuthnRequest } from './auth/authn';
|
|
|
6
6
|
import { TrxNode } from './transaction/trx_node';
|
|
7
7
|
import { TrxStatus } from './transaction/trx';
|
|
8
8
|
import { AnyModule } from './module';
|
|
9
|
-
import {
|
|
9
|
+
import { IService } from './apps/service';
|
|
10
10
|
/**
|
|
11
11
|
* A background process running one or more modules,
|
|
12
12
|
* which runs _Transactions_ for the available elements.
|
|
@@ -18,15 +18,15 @@ import { AnyAppProvider } from './apps/app';
|
|
|
18
18
|
export declare abstract class Daemon<S extends $Space, Modules extends ModuleName<S>> {
|
|
19
19
|
protected name: string;
|
|
20
20
|
protected trxEngines: Record<Modules, AnyTrxEngine>;
|
|
21
|
-
protected
|
|
21
|
+
protected services: Record<string, IService>;
|
|
22
22
|
protected config?: AnyAppConfig | undefined;
|
|
23
23
|
/**
|
|
24
24
|
* @param name Name of the daemon (taken from App)
|
|
25
25
|
* @param trxEngines A dictionary of Transaction Engine by module name
|
|
26
|
-
* @param
|
|
26
|
+
* @param services A dictionary of Service by name
|
|
27
27
|
* @param config Optional `AppConfig`
|
|
28
28
|
*/
|
|
29
|
-
constructor(name: string, trxEngines: Record<Modules, AnyTrxEngine>,
|
|
29
|
+
constructor(name: string, trxEngines: Record<Modules, AnyTrxEngine>, services: Record<string, IService>, config?: AnyAppConfig | undefined);
|
|
30
30
|
/**
|
|
31
31
|
* Prepare a transaction to be run by the Daemon.
|
|
32
32
|
*
|
|
@@ -45,32 +45,32 @@ export declare abstract class Daemon<S extends $Space, Modules extends ModuleNam
|
|
|
45
45
|
*/
|
|
46
46
|
private bindControllers;
|
|
47
47
|
/**
|
|
48
|
-
* Destroy the
|
|
48
|
+
* Destroy the services and transaction engines of this daemon
|
|
49
49
|
*
|
|
50
50
|
* @param A `Daemon` instance
|
|
51
51
|
*/
|
|
52
|
-
|
|
52
|
+
destroy(): Promise<void>;
|
|
53
53
|
/**
|
|
54
|
-
* Replace the
|
|
54
|
+
* Replace the services and transaction engines of this daemon
|
|
55
55
|
* and rebind the controllers
|
|
56
56
|
*
|
|
57
57
|
* @param daemon A `Daemon` instance
|
|
58
58
|
* @param trxEngines A dictionary of Transaction Engine by module name
|
|
59
|
-
* @param
|
|
59
|
+
* @param services A dictionary of Service by name
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
reload(trxEngines: Record<Modules, AnyTrxEngine>, services: Record<string, any>): void;
|
|
62
62
|
/**
|
|
63
63
|
* Return a `Daemon` property.
|
|
64
64
|
* This is used to read private properties.
|
|
65
65
|
*
|
|
66
66
|
* @param daemon A `Daemon` instance
|
|
67
|
-
* @param key A `Daemon` property `'name'|'
|
|
67
|
+
* @param key A `Daemon` property `'name'|'services'|'app'`
|
|
68
68
|
* @returns The selected property
|
|
69
69
|
*/
|
|
70
70
|
static get<T extends {
|
|
71
71
|
name: string;
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
services: Record<string, any>;
|
|
73
|
+
config: AnyAppConfig;
|
|
74
74
|
}, K extends keyof T>(daemon: AnyDaemon | undefined, key: K): T[K];
|
|
75
75
|
/**
|
|
76
76
|
* Return one module of the `Daemon` by name.
|
package/lib/engine/daemon.js
CHANGED
|
@@ -16,13 +16,13 @@ class Daemon {
|
|
|
16
16
|
/**
|
|
17
17
|
* @param name Name of the daemon (taken from App)
|
|
18
18
|
* @param trxEngines A dictionary of Transaction Engine by module name
|
|
19
|
-
* @param
|
|
19
|
+
* @param services A dictionary of Service by name
|
|
20
20
|
* @param config Optional `AppConfig`
|
|
21
21
|
*/
|
|
22
|
-
constructor(name, trxEngines,
|
|
22
|
+
constructor(name, trxEngines, services, config) {
|
|
23
23
|
this.name = name;
|
|
24
24
|
this.trxEngines = trxEngines;
|
|
25
|
-
this.
|
|
25
|
+
this.services = services;
|
|
26
26
|
this.config = config;
|
|
27
27
|
this.bindControllers();
|
|
28
28
|
log_1.Log.info('daemon', name, 'Woo-ha!');
|
|
@@ -63,41 +63,41 @@ class Daemon {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* Destroy the
|
|
66
|
+
* Destroy the services and transaction engines of this daemon
|
|
67
67
|
*
|
|
68
68
|
* @param A `Daemon` instance
|
|
69
69
|
*/
|
|
70
|
-
|
|
70
|
+
async destroy() {
|
|
71
71
|
log_1.Log.info('daemon', this.name, 'Stop');
|
|
72
|
-
for (const key in
|
|
73
|
-
const
|
|
74
|
-
await
|
|
75
|
-
delete
|
|
72
|
+
for (const key in this.services) {
|
|
73
|
+
const service = this.services[key];
|
|
74
|
+
await service.down();
|
|
75
|
+
delete this.services[key];
|
|
76
76
|
}
|
|
77
|
-
for (const key in
|
|
78
|
-
delete
|
|
77
|
+
for (const key in this.trxEngines) {
|
|
78
|
+
delete this.trxEngines[key];
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
* Replace the
|
|
82
|
+
* Replace the services and transaction engines of this daemon
|
|
83
83
|
* and rebind the controllers
|
|
84
84
|
*
|
|
85
85
|
* @param daemon A `Daemon` instance
|
|
86
86
|
* @param trxEngines A dictionary of Transaction Engine by module name
|
|
87
|
-
* @param
|
|
87
|
+
* @param services A dictionary of Service by name
|
|
88
88
|
*/
|
|
89
|
-
|
|
89
|
+
reload(trxEngines, services) {
|
|
90
90
|
log_1.Log.info('daemon', this.name, 'Reloaded');
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
this.trxEngines = trxEngines;
|
|
92
|
+
this.services = services;
|
|
93
|
+
this.bindControllers();
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Return a `Daemon` property.
|
|
97
97
|
* This is used to read private properties.
|
|
98
98
|
*
|
|
99
99
|
* @param daemon A `Daemon` instance
|
|
100
|
-
* @param key A `Daemon` property `'name'|'
|
|
100
|
+
* @param key A `Daemon` property `'name'|'services'|'app'`
|
|
101
101
|
* @returns The selected property
|
|
102
102
|
*/
|
|
103
103
|
static get(daemon, key) {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category Engine
|
|
3
|
+
* @subcategory Data
|
|
4
|
+
*/
|
|
5
|
+
export declare class NesoiDuration {
|
|
6
|
+
static UNITS: {
|
|
7
|
+
ms: "miliseconds";
|
|
8
|
+
milisecond: "miliseconds";
|
|
9
|
+
miliseconds: "miliseconds";
|
|
10
|
+
s: "seconds";
|
|
11
|
+
second: "seconds";
|
|
12
|
+
seconds: "seconds";
|
|
13
|
+
min: "minutes";
|
|
14
|
+
mins: "minutes";
|
|
15
|
+
minute: "minutes";
|
|
16
|
+
minutes: "minutes";
|
|
17
|
+
h: "hours";
|
|
18
|
+
hour: "hours";
|
|
19
|
+
hours: "hours";
|
|
20
|
+
d: "days";
|
|
21
|
+
day: "days";
|
|
22
|
+
days: "days";
|
|
23
|
+
w: "weeks";
|
|
24
|
+
week: "weeks";
|
|
25
|
+
weeks: "weeks";
|
|
26
|
+
month: "months";
|
|
27
|
+
months: "months";
|
|
28
|
+
y: "years";
|
|
29
|
+
year: "years";
|
|
30
|
+
years: "years";
|
|
31
|
+
};
|
|
32
|
+
value: number;
|
|
33
|
+
unit: typeof NesoiDuration.UNITS[keyof typeof NesoiDuration.UNITS];
|
|
34
|
+
constructor(value: {
|
|
35
|
+
miliseconds: number;
|
|
36
|
+
} | {
|
|
37
|
+
seconds: number;
|
|
38
|
+
} | {
|
|
39
|
+
minutes: number;
|
|
40
|
+
} | {
|
|
41
|
+
hours: number;
|
|
42
|
+
} | {
|
|
43
|
+
days: number;
|
|
44
|
+
} | {
|
|
45
|
+
weeks: number;
|
|
46
|
+
} | {
|
|
47
|
+
months: number;
|
|
48
|
+
} | {
|
|
49
|
+
years: number;
|
|
50
|
+
});
|
|
51
|
+
static fromString(value: string): NesoiDuration;
|
|
52
|
+
toString(): string;
|
|
53
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NesoiDuration = void 0;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
/**
|
|
6
|
+
* @category Engine
|
|
7
|
+
* @subcategory Data
|
|
8
|
+
*/
|
|
9
|
+
class NesoiDuration {
|
|
10
|
+
constructor(value) {
|
|
11
|
+
this.unit = Object.keys(value)[0];
|
|
12
|
+
this.value = value[this.unit];
|
|
13
|
+
}
|
|
14
|
+
static fromString(value) {
|
|
15
|
+
const split = value.split(' ');
|
|
16
|
+
if (split.length !== 2) {
|
|
17
|
+
throw error_1.NesoiError.Data.InvalidDuration({ value });
|
|
18
|
+
}
|
|
19
|
+
const number = parseInt(split[0]);
|
|
20
|
+
if (isNaN(number)) {
|
|
21
|
+
throw error_1.NesoiError.Data.InvalidDuration({ value });
|
|
22
|
+
}
|
|
23
|
+
const unit_str = split[1];
|
|
24
|
+
const unit = NesoiDuration.UNITS[unit_str];
|
|
25
|
+
if (!unit) {
|
|
26
|
+
throw error_1.NesoiError.Data.InvalidDurationUnit({ value, unit: unit_str });
|
|
27
|
+
}
|
|
28
|
+
return new NesoiDuration({
|
|
29
|
+
[unit]: number
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
toString() {
|
|
33
|
+
return `${this.value} ${this.unit}`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.NesoiDuration = NesoiDuration;
|
|
37
|
+
NesoiDuration.UNITS = {
|
|
38
|
+
ms: 'miliseconds',
|
|
39
|
+
milisecond: 'miliseconds',
|
|
40
|
+
miliseconds: 'miliseconds',
|
|
41
|
+
s: 'seconds',
|
|
42
|
+
second: 'seconds',
|
|
43
|
+
seconds: 'seconds',
|
|
44
|
+
min: 'minutes',
|
|
45
|
+
mins: 'minutes',
|
|
46
|
+
minute: 'minutes',
|
|
47
|
+
minutes: 'minutes',
|
|
48
|
+
h: 'hours',
|
|
49
|
+
hour: 'hours',
|
|
50
|
+
hours: 'hours',
|
|
51
|
+
d: 'days',
|
|
52
|
+
day: 'days',
|
|
53
|
+
days: 'days',
|
|
54
|
+
w: 'weeks',
|
|
55
|
+
week: 'weeks',
|
|
56
|
+
weeks: 'weeks',
|
|
57
|
+
month: 'months',
|
|
58
|
+
months: 'months',
|
|
59
|
+
y: 'years',
|
|
60
|
+
year: 'years',
|
|
61
|
+
years: 'years',
|
|
62
|
+
};
|
|
@@ -134,6 +134,13 @@ export declare namespace NesoiError {
|
|
|
134
134
|
function InvalidISOString($: {
|
|
135
135
|
value: string;
|
|
136
136
|
}): BaseError;
|
|
137
|
+
function InvalidDuration($: {
|
|
138
|
+
value: string;
|
|
139
|
+
}): BaseError;
|
|
140
|
+
function InvalidDurationUnit($: {
|
|
141
|
+
value: string;
|
|
142
|
+
unit: string;
|
|
143
|
+
}): BaseError;
|
|
137
144
|
function UnsupportedDecimalPrecision($: {
|
|
138
145
|
left: number;
|
|
139
146
|
right: number;
|
package/lib/engine/data/error.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.NesoiError = void 0;
|
|
|
4
4
|
var NesoiError;
|
|
5
5
|
(function (NesoiError) {
|
|
6
6
|
class BaseError extends Error {
|
|
7
|
-
constructor(name, message, status =
|
|
7
|
+
constructor(name, message, status = 400, data) {
|
|
8
8
|
super(message);
|
|
9
9
|
this.name = name;
|
|
10
10
|
this.status = status;
|
|
@@ -262,6 +262,14 @@ var NesoiError;
|
|
|
262
262
|
return new BaseError('Message.Data.InvalidISOString', `'${$.value}' is not a valid ISO string`, Status.BAD_REQUEST, $);
|
|
263
263
|
}
|
|
264
264
|
Data.InvalidISOString = InvalidISOString;
|
|
265
|
+
function InvalidDuration($) {
|
|
266
|
+
return new BaseError('Message.Data.InvalidDuration', `'${$.value}' is not a valid duration`, Status.BAD_REQUEST, $);
|
|
267
|
+
}
|
|
268
|
+
Data.InvalidDuration = InvalidDuration;
|
|
269
|
+
function InvalidDurationUnit($) {
|
|
270
|
+
return new BaseError('Message.Data.InvalidDuration', `Invalid unit '${$.unit}' for duration '${$.value}'`, Status.BAD_REQUEST, $);
|
|
271
|
+
}
|
|
272
|
+
Data.InvalidDurationUnit = InvalidDurationUnit;
|
|
265
273
|
function UnsupportedDecimalPrecision($) {
|
|
266
274
|
return new BaseError('Message.Data.UnsupportedDecimalPrecision', `Decimal precision [${$.left},${$.right}]' is invalid. Supported range: 1~12.`, Status.BAD_REQUEST, $);
|
|
267
275
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuilderType } from "../schema";
|
|
1
|
+
import { $Module, BuilderType } from "../schema";
|
|
2
2
|
import { AnyBuilder, AnyElementSchema } from './module';
|
|
3
3
|
import { Overlay } from './util/type';
|
|
4
4
|
import { JobBuilderNode } from "../elements/blocks/job/job.builder";
|
|
@@ -80,6 +80,7 @@ export declare class $Dependency {
|
|
|
80
80
|
* @returns The type name of the dependency
|
|
81
81
|
*/
|
|
82
82
|
static typeName(dep: $Dependency, fromModule: string): string;
|
|
83
|
+
static resolve(module: $Module, dep: $Dependency): import("../elements").$Message | import("../elements").$Machine | import("../elements").$Bucket | import("../elements").$Constants | import("../elements").$Job | import("../elements").$Externals | import("../elements").$Resource | import("../elements").$Controller | undefined;
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
86
|
* A element builder, along with metadata required for building it.
|