nesoi 3.0.9 → 3.0.10
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/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/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 +11 -11
- package/lib/engine/daemon.js +18 -18
- 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/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
|
@@ -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,31 +45,31 @@ 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
|
-
|
|
72
|
+
services: Record<string, any>;
|
|
73
73
|
app: AnyAppConfig;
|
|
74
74
|
}, K extends keyof T>(daemon: AnyDaemon | undefined, key: K): T[K];
|
|
75
75
|
/**
|
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) {
|
|
@@ -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.
|
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;
|