nesoi 3.1.7 → 3.2.1
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/distributed/distributed_compiler.d.ts +31 -0
- package/lib/compiler/apps/distributed/distributed_compiler.js +121 -0
- package/lib/compiler/apps/distributed/stages/1_mkdir_stage.d.ts +15 -0
- package/lib/compiler/apps/distributed/stages/1_mkdir_stage.js +96 -0
- package/lib/compiler/apps/distributed/stages/2_build_typescript_stage.d.ts +15 -0
- package/lib/compiler/apps/distributed/stages/2_build_typescript_stage.js +174 -0
- package/lib/compiler/apps/distributed/stages/3_copy_types_stage.d.ts +15 -0
- package/lib/compiler/apps/distributed/stages/3_copy_types_stage.js +82 -0
- package/lib/compiler/apps/distributed/stages/4_dump_modules_stage.d.ts +16 -0
- package/lib/compiler/apps/distributed/stages/4_dump_modules_stage.js +182 -0
- package/lib/compiler/apps/distributed/stages/5_copy_static_stage.d.ts +0 -0
- package/lib/compiler/apps/distributed/stages/5_copy_static_stage.js +31 -0
- package/lib/compiler/apps/distributed/stages/6_dump_cli_stage.d.ts +0 -0
- package/lib/compiler/apps/distributed/stages/6_dump_cli_stage.js +34 -0
- package/lib/compiler/apps/distributed/stages/7_dump_package_json_stage.d.ts +0 -0
- package/lib/compiler/apps/distributed/stages/7_dump_package_json_stage.js +45 -0
- package/lib/compiler/elements/element.js +2 -2
- package/lib/compiler/index.d.ts +1 -0
- package/lib/compiler/index.js +3 -1
- package/lib/elements/blocks/block.builder.d.ts +1 -0
- package/lib/elements/blocks/block.builder.js +16 -1
- package/lib/elements/blocks/block.schema.d.ts +4 -1
- package/lib/elements/blocks/job/job.builder.d.ts +1 -0
- package/lib/elements/blocks/job/job.builder.js +2 -1
- package/lib/elements/entities/bucket/bucket.d.ts +2 -2
- package/lib/elements/entities/bucket/bucket.js +30 -16
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +1 -1
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +1 -0
- package/lib/engine/apps/app.config.d.ts +24 -30
- package/lib/engine/apps/app.config.js +11 -21
- package/lib/engine/apps/app.d.ts +6 -5
- package/lib/engine/apps/app.js +1 -1
- package/lib/engine/apps/distributed/distributed.app.config.d.ts +44 -0
- package/lib/engine/apps/distributed/distributed.app.config.js +36 -0
- package/lib/engine/apps/distributed/distributed.app.d.ts +30 -0
- package/lib/engine/apps/distributed/distributed.app.js +52 -0
- package/lib/engine/apps/distributed/distributed_node.app.d.ts +67 -0
- package/lib/engine/apps/distributed/distributed_node.app.js +191 -0
- package/lib/engine/apps/distributed/elements/distributed_job.d.ts +7 -0
- package/lib/engine/apps/distributed/elements/distributed_job.js +11 -0
- package/lib/engine/apps/distributed/inc/inc.client.d.ts +17 -0
- package/lib/engine/apps/distributed/inc/inc.client.js +105 -0
- package/lib/engine/apps/distributed/inc/inc.server.d.ts +19 -0
- package/lib/engine/apps/distributed/inc/inc.server.js +174 -0
- package/lib/engine/apps/distributed/inc/test.d.ts +1 -0
- package/lib/engine/apps/distributed/inc/test.js +24 -0
- package/lib/engine/apps/inline.app.d.ts +7 -2
- package/lib/engine/apps/inline.app.js +18 -2
- package/lib/engine/apps/monolyth/monolyth.app.d.ts +2 -2
- package/lib/engine/apps/monolyth/monolyth.app.js +1 -1
- package/lib/engine/module.d.ts +11 -1
- package/lib/engine/module.js +17 -4
- package/lib/engine/util/crypto.d.ts +4 -13
- package/lib/engine/util/crypto.js +26 -37
- package/lib/engine/util/log.d.ts +1 -1
- package/lib/engine/util/log.js +2 -0
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,52 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AppConfigBuilder = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Factory
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* @category App
|
|
9
9
|
*/
|
|
10
|
-
class
|
|
10
|
+
class AppConfigBuilder {
|
|
11
11
|
constructor(app) {
|
|
12
12
|
this.app = app;
|
|
13
13
|
this.config = app._config;
|
|
14
14
|
}
|
|
15
|
-
i18n(config) {
|
|
16
|
-
this.config.i18n = config;
|
|
17
|
-
return this.app;
|
|
18
|
-
}
|
|
19
15
|
authn(config) {
|
|
20
16
|
this.config.authn = config;
|
|
21
17
|
return this.app;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
trash(config) {
|
|
28
|
-
this.config.trash = config;
|
|
29
|
-
return this.app;
|
|
30
|
-
}
|
|
31
|
-
controllers(config) {
|
|
32
|
-
this.config.controllers = config;
|
|
19
|
+
module(name, config) {
|
|
20
|
+
var _a;
|
|
21
|
+
(_a = this.config).modules ?? (_a.modules = {});
|
|
22
|
+
this.config.modules[name] = config;
|
|
33
23
|
return this.app;
|
|
34
24
|
}
|
|
35
25
|
audit(config) {
|
|
36
26
|
this.config.i18n = config;
|
|
37
27
|
return this.app;
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
this.config.
|
|
29
|
+
i18n(config) {
|
|
30
|
+
this.config.i18n = config;
|
|
41
31
|
return this.app;
|
|
42
32
|
}
|
|
43
33
|
cli(config) {
|
|
44
34
|
this.config.cli = config;
|
|
45
35
|
return this.app;
|
|
46
36
|
}
|
|
47
|
-
|
|
48
|
-
this.config.
|
|
37
|
+
compiler(config) {
|
|
38
|
+
this.config.compiler = config;
|
|
49
39
|
return this.app;
|
|
50
40
|
}
|
|
51
41
|
}
|
|
52
|
-
exports.
|
|
42
|
+
exports.AppConfigBuilder = AppConfigBuilder;
|
package/lib/engine/apps/app.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { $Space, ModuleName } from "../../schema";
|
|
|
2
2
|
import { AnyBuilder, AnyModule } from '../module';
|
|
3
3
|
import { Space } from '../space';
|
|
4
4
|
import { Daemon } from '../daemon';
|
|
5
|
-
import { AnyAppConfig,
|
|
5
|
+
import { AnyAppConfig, AppConfigBuilder } from './app.config';
|
|
6
6
|
import { IService } from './service';
|
|
7
|
+
import { DistributedAppConfigBuilder } from './distributed/distributed.app.config';
|
|
7
8
|
/**
|
|
8
9
|
* @category App
|
|
9
10
|
*/
|
|
@@ -37,14 +38,14 @@ export declare abstract class App<S extends $Space, Modules extends string = Mod
|
|
|
37
38
|
* ⚠ This has no effect on apps without a `Space`, such as `InlineApp`.
|
|
38
39
|
* @param modules A list of names of modules from the current `Space`.
|
|
39
40
|
*/
|
|
40
|
-
modules<M extends ModuleName<S>>(modules: M[]): App<S, M & Modules, Services>;
|
|
41
|
+
protected modules<M extends ModuleName<S>>(modules: M[]): App<S, M & Modules, Services>;
|
|
41
42
|
/**
|
|
42
43
|
* Injects pre-built modules into this App.
|
|
43
44
|
* These will be included on the Daemon once it starts.
|
|
44
45
|
*
|
|
45
46
|
* @param modules A list of pre-built modules.
|
|
46
47
|
*/
|
|
47
|
-
inject(modules: AnyModule[]): this;
|
|
48
|
+
protected inject(modules: AnyModule[]): this;
|
|
48
49
|
/**
|
|
49
50
|
* Declares a `Service`.
|
|
50
51
|
*
|
|
@@ -52,8 +53,8 @@ export declare abstract class App<S extends $Space, Modules extends string = Mod
|
|
|
52
53
|
* config to share globals between adapters and other methods.
|
|
53
54
|
* @param $ object with an `up` and `down` method to create/destroy the service
|
|
54
55
|
*/
|
|
55
|
-
service<T extends IService>($: T): App<S, Modules, Services & { [K in T["name"]]: T; }>;
|
|
56
|
-
get config():
|
|
56
|
+
protected service<T extends IService>($: T): App<S, Modules, Services & { [K in T["name"]]: T; }>;
|
|
57
|
+
protected get config(): AppConfigBuilder<S, Modules, Services> | DistributedAppConfigBuilder<S, any, Modules, Services>;
|
|
57
58
|
protected makeModules(): Record<string, AnyModule>;
|
|
58
59
|
static getServices(app: AnyApp): Record<string, IService>;
|
|
59
60
|
static getInfo(app: AnyApp): {
|
package/lib/engine/apps/app.js
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { $Space, ModuleName } from "../../../schema";
|
|
2
|
+
import { CompilerConfig } from "../../../compiler/compiler";
|
|
3
|
+
import { AppAuthnConfig, AppI18nConfig, AppConfig, AppControllerConfig, AppTrashConfig } from '../app.config';
|
|
4
|
+
import { CLIConfig } from "../../cli/cli";
|
|
5
|
+
import { IService } from '../service';
|
|
6
|
+
import { DistributedAppNode } from './distributed_node.app';
|
|
7
|
+
import { TrxEngineConfig } from "../../transaction/trx_engine.config";
|
|
8
|
+
import { BucketConfig } from "../../../elements/entities/bucket/bucket.config";
|
|
9
|
+
export type DistributedAppModuleConfig<S extends $Space, M extends ModuleName<S>, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, Services extends Record<string, IService>> = {
|
|
10
|
+
buckets?: DistributedAppBucketConfig<S, M, Nodes, Services>;
|
|
11
|
+
jobs?: DistributedAppJobConfig<S, M, Nodes>;
|
|
12
|
+
trash?: AppTrashConfig<Services>;
|
|
13
|
+
controllers?: AppControllerConfig<S, M, Services>;
|
|
14
|
+
trx?: TrxEngineConfig<S, S['modules'][M], any, Services>;
|
|
15
|
+
};
|
|
16
|
+
export type DistributedAppConfig<S extends $Space, Modules extends ModuleName<S>, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, Services extends Record<string, IService>> = {
|
|
17
|
+
authn?: AppAuthnConfig<S>;
|
|
18
|
+
modules?: Partial<{
|
|
19
|
+
[M in (Modules & keyof S['modules'])]: DistributedAppModuleConfig<S, M, Nodes, Services>;
|
|
20
|
+
}>;
|
|
21
|
+
i18n?: AppI18nConfig;
|
|
22
|
+
cli?: CLIConfig<any>;
|
|
23
|
+
compiler?: CompilerConfig;
|
|
24
|
+
};
|
|
25
|
+
export type AnyAppConfig = AppConfig<any, any, any>;
|
|
26
|
+
export type DistributedAppBucketConfig<S extends $Space, M extends keyof S['modules'], Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, Services extends Record<string, IService>> = Partial<{
|
|
27
|
+
[K in keyof S['modules'][M]['buckets']]: keyof Nodes | BucketConfig<S['modules'][M], S['modules'][M]['buckets'][K], Services>;
|
|
28
|
+
}>;
|
|
29
|
+
export type DistributedAppJobConfig<S extends $Space, M extends keyof S['modules'], Nodes extends Record<string, DistributedAppNode<any, any, any, any>>> = Partial<{
|
|
30
|
+
[K in keyof S['modules'][M]['jobs']]: keyof Nodes;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* @category DistributedApp
|
|
34
|
+
*/
|
|
35
|
+
export declare class DistributedAppConfigBuilder<S extends $Space, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, Modules extends string = ModuleName<S> & string, Services extends Record<string, any> = Record<string, any>> {
|
|
36
|
+
private node;
|
|
37
|
+
constructor(node: DistributedAppNode<S, Nodes, Modules, Services>);
|
|
38
|
+
authn(config: AppAuthnConfig<S>): DistributedAppNode<S, Nodes, Modules, Services>;
|
|
39
|
+
module<M extends Modules>(name: M, config: DistributedAppModuleConfig<S, M, Nodes, Services>): DistributedAppNode<S, Nodes, Modules, Services>;
|
|
40
|
+
audit(config: AppI18nConfig): DistributedAppNode<S, Nodes, Modules, Services>;
|
|
41
|
+
i18n(config: AppI18nConfig): DistributedAppNode<S, Nodes, Modules, Services>;
|
|
42
|
+
cli(config: CLIConfig<Services>): DistributedAppNode<S, Nodes, Modules, Services>;
|
|
43
|
+
compiler(config: CompilerConfig): DistributedAppNode<S, Nodes, Modules, Services>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DistributedAppConfigBuilder = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category DistributedApp
|
|
6
|
+
*/
|
|
7
|
+
class DistributedAppConfigBuilder {
|
|
8
|
+
constructor(node) {
|
|
9
|
+
this.node = node;
|
|
10
|
+
}
|
|
11
|
+
authn(config) {
|
|
12
|
+
// TODO
|
|
13
|
+
return this.node;
|
|
14
|
+
}
|
|
15
|
+
module(name, config) {
|
|
16
|
+
// TODO
|
|
17
|
+
return this.node;
|
|
18
|
+
}
|
|
19
|
+
audit(config) {
|
|
20
|
+
// TODO
|
|
21
|
+
return this.node;
|
|
22
|
+
}
|
|
23
|
+
i18n(config) {
|
|
24
|
+
// TODO
|
|
25
|
+
return this.node;
|
|
26
|
+
}
|
|
27
|
+
cli(config) {
|
|
28
|
+
// TODO
|
|
29
|
+
return this.node;
|
|
30
|
+
}
|
|
31
|
+
compiler(config) {
|
|
32
|
+
// TODO
|
|
33
|
+
return this.node;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.DistributedAppConfigBuilder = DistributedAppConfigBuilder;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { $Space } from "../../../schema";
|
|
2
|
+
import { Space } from '../../space';
|
|
3
|
+
import { Daemon } from "../../daemon";
|
|
4
|
+
import { DistributedAppConfig } from './distributed.app.config';
|
|
5
|
+
import { App } from '../app';
|
|
6
|
+
import { DistributedAppNode, DistributedAppNodeDef, DistributedNodeDaemon } from './distributed_node.app';
|
|
7
|
+
/**
|
|
8
|
+
* @category App
|
|
9
|
+
* @subcategory Distributed
|
|
10
|
+
*/
|
|
11
|
+
export declare class DistributedApp<S extends $Space, Name extends string, Nodes extends Record<string, DistributedAppNode<any, any, any, any>> = {}> extends App<S, never, never> {
|
|
12
|
+
nodes: Nodes;
|
|
13
|
+
constructor(name: Name, space?: Space<S>);
|
|
14
|
+
boot(): DistributedApp<S, Name, Nodes>;
|
|
15
|
+
daemon(): Promise<DistributedDaemon<S, { [N in keyof Nodes as `${Name}-${N & string}`]: Nodes[N]; }>>;
|
|
16
|
+
node<N extends string, ModuleNames extends string, Services extends Record<string, any>, Def extends DistributedAppNodeDef<S, Nodes, ModuleNames, Services>>(name: N, def: Def): DistributedApp<S, Name, Nodes & {
|
|
17
|
+
[K in N]: ReturnType<Def>;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @category App
|
|
22
|
+
* @subcategory Distributed
|
|
23
|
+
*/
|
|
24
|
+
export declare class DistributedDaemon<S extends $Space, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>> extends Daemon<S, never> {
|
|
25
|
+
nodes: {
|
|
26
|
+
[K in keyof Nodes]: DistributedNodeDaemon<S, Nodes[K] extends DistributedAppNode<any, any, infer X, any> ? X : never>;
|
|
27
|
+
};
|
|
28
|
+
constructor(name: string, config: DistributedAppConfig<any, any, any, any>);
|
|
29
|
+
boot(nodes: Nodes): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DistributedDaemon = exports.DistributedApp = void 0;
|
|
4
|
+
const daemon_1 = require("../../daemon");
|
|
5
|
+
const app_1 = require("../app");
|
|
6
|
+
const distributed_node_app_1 = require("./distributed_node.app");
|
|
7
|
+
/**
|
|
8
|
+
* @category App
|
|
9
|
+
* @subcategory Distributed
|
|
10
|
+
*/
|
|
11
|
+
class DistributedApp extends app_1.App {
|
|
12
|
+
constructor(name, space) {
|
|
13
|
+
super(name, { builders: [] });
|
|
14
|
+
this.nodes = {};
|
|
15
|
+
this.builders = undefined;
|
|
16
|
+
this.space = space;
|
|
17
|
+
}
|
|
18
|
+
// Override App abstract methods
|
|
19
|
+
boot() {
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
async daemon() {
|
|
23
|
+
const config = this._config;
|
|
24
|
+
const daemon = new DistributedDaemon(this.name, config);
|
|
25
|
+
await daemon.boot(this.nodes);
|
|
26
|
+
return daemon;
|
|
27
|
+
}
|
|
28
|
+
// Type Builder Overrides
|
|
29
|
+
node(name, def) {
|
|
30
|
+
let node = new distributed_node_app_1.DistributedAppNode(`${this.name}-${name}`, this.space);
|
|
31
|
+
node = def(node);
|
|
32
|
+
this.nodes[node.name] = node;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.DistributedApp = DistributedApp;
|
|
37
|
+
/**
|
|
38
|
+
* @category App
|
|
39
|
+
* @subcategory Distributed
|
|
40
|
+
*/
|
|
41
|
+
class DistributedDaemon extends daemon_1.Daemon {
|
|
42
|
+
constructor(name, config) {
|
|
43
|
+
super(name, {}, {}, config);
|
|
44
|
+
this.nodes = {};
|
|
45
|
+
}
|
|
46
|
+
async boot(nodes) {
|
|
47
|
+
for (const name in nodes) {
|
|
48
|
+
this.nodes[name] = await nodes[name].daemon();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.DistributedDaemon = DistributedDaemon;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { $Module, $Space, ModuleName } from "../../../schema";
|
|
2
|
+
import { IService } from '../service';
|
|
3
|
+
import { DistributedAppConfig, DistributedAppConfigBuilder } from './distributed.app.config';
|
|
4
|
+
import { App } from '../app';
|
|
5
|
+
import { MonolythDaemon } from '../monolyth/monolyth.app';
|
|
6
|
+
import { AnyTrxEngine } from "../../transaction/trx_engine";
|
|
7
|
+
import { AnyModule, Module } from "../../module";
|
|
8
|
+
import { Space } from "../../space";
|
|
9
|
+
export declare class DistributedAppNode<S extends $Space, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, ModuleNames extends string, Services extends Record<string, any>> extends App<S, ModuleNames, Services> {
|
|
10
|
+
_host: {
|
|
11
|
+
host: string;
|
|
12
|
+
port: number;
|
|
13
|
+
};
|
|
14
|
+
protected _daemon?: DistributedNodeDaemon<S, ModuleNames>;
|
|
15
|
+
protected _modules: Record<string, AnyModule>;
|
|
16
|
+
protected packageJson?: Record<string, any>;
|
|
17
|
+
protected bootPromise?: Promise<void>;
|
|
18
|
+
constructor(name: string, space?: Space<S>);
|
|
19
|
+
/**
|
|
20
|
+
* Treeshake and build modules declared for this application.
|
|
21
|
+
*/
|
|
22
|
+
protected build(): Promise<void>;
|
|
23
|
+
boot(): DistributedAppNode<S, Nodes, ModuleNames, Services>;
|
|
24
|
+
/**
|
|
25
|
+
* Build the application, start services and trx engines.
|
|
26
|
+
* Returns references to start a daemon.
|
|
27
|
+
*/
|
|
28
|
+
protected make(): Promise<{
|
|
29
|
+
modules: Record<string, AnyModule>;
|
|
30
|
+
services: Record<string, any>;
|
|
31
|
+
trxEngines: Record<ModuleNames, AnyTrxEngine>;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* This method injects elements flagged as externals by referencing them
|
|
35
|
+
* from the other module directly, given this is a single-threaded App.
|
|
36
|
+
*
|
|
37
|
+
* TODO: allow overriding this behavior with adapters
|
|
38
|
+
*/
|
|
39
|
+
protected linkExternals(modules: Record<string, Module<S, $Module>>): void;
|
|
40
|
+
/**
|
|
41
|
+
* This method injects values from environment variables into each module's
|
|
42
|
+
* app constants.
|
|
43
|
+
*/
|
|
44
|
+
protected linkAppValues(modules: Record<string, Module<S, $Module>>): void;
|
|
45
|
+
daemon(): Promise<DistributedNodeDaemon<S, ModuleNames>>;
|
|
46
|
+
host(config: {
|
|
47
|
+
host: string;
|
|
48
|
+
port: number;
|
|
49
|
+
}): this;
|
|
50
|
+
modules<M extends ModuleName<S>>(modules: M[]): DistributedAppNode<S, Nodes, M & ModuleNames, Services>;
|
|
51
|
+
service<T extends IService>($: T): DistributedAppNode<S, Nodes, ModuleNames, Services & { [K in T["name"]]: T; }>;
|
|
52
|
+
package(_package: Record<string, any>): this;
|
|
53
|
+
get config(): DistributedAppConfigBuilder<S, Nodes, ModuleNames, Services>;
|
|
54
|
+
}
|
|
55
|
+
export type DistributedAppNodeDef<S extends $Space, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, ModuleNames extends string, Services extends Record<string, any>> = (builder: DistributedAppNode<S, Nodes, keyof S['modules'] & string, {}>) => DistributedAppNode<S, Nodes, ModuleNames, Services>;
|
|
56
|
+
/**
|
|
57
|
+
* @category App
|
|
58
|
+
* @subcategory Distributed
|
|
59
|
+
*/
|
|
60
|
+
export declare class DistributedNodeDaemon<S extends $Space, Modules extends ModuleName<S>> extends MonolythDaemon<S, Modules> {
|
|
61
|
+
private inc;
|
|
62
|
+
constructor(name: string, host: {
|
|
63
|
+
host: string;
|
|
64
|
+
port: number;
|
|
65
|
+
}, trxEngines: Record<Modules, AnyTrxEngine>, services: Record<string, IService>, config?: DistributedAppConfig<any, any, any, any> | undefined);
|
|
66
|
+
boot(): Promise<void>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DistributedNodeDaemon = exports.DistributedAppNode = void 0;
|
|
7
|
+
const distributed_app_config_1 = require("./distributed.app.config");
|
|
8
|
+
const app_1 = require("../app");
|
|
9
|
+
const monolyth_app_1 = require("../monolyth/monolyth.app");
|
|
10
|
+
const inc_server_1 = require("./inc/inc.server");
|
|
11
|
+
const trx_engine_1 = require("../../transaction/trx_engine");
|
|
12
|
+
const tree_1 = require("../../tree");
|
|
13
|
+
const log_1 = require("../../util/log");
|
|
14
|
+
const promise_1 = __importDefault(require("../../util/promise"));
|
|
15
|
+
const distributed_job_1 = require("./elements/distributed_job");
|
|
16
|
+
class DistributedAppNode extends app_1.App {
|
|
17
|
+
constructor(name, space) {
|
|
18
|
+
super(name, { builders: [] });
|
|
19
|
+
this._modules = {};
|
|
20
|
+
this.space = space;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Treeshake and build modules declared for this application.
|
|
24
|
+
*/
|
|
25
|
+
async build() {
|
|
26
|
+
log_1.Log.info('app', this.name, 'Booting');
|
|
27
|
+
this._modules = await this.makeModules();
|
|
28
|
+
log_1.Log.debug('app', this.name, 'Building');
|
|
29
|
+
const tree = new tree_1.ModuleTree(this._modules, {
|
|
30
|
+
exclude: ['*.test.ts']
|
|
31
|
+
});
|
|
32
|
+
await tree.resolve();
|
|
33
|
+
await tree.traverse('Building', async (node) => {
|
|
34
|
+
// Inline nodes are built by their root builder
|
|
35
|
+
if (node.isInline) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const module = this._modules[node.module];
|
|
39
|
+
await module.buildNode(node, tree);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
boot() {
|
|
43
|
+
if (!this.bootPromise) {
|
|
44
|
+
this.bootPromise = this.build();
|
|
45
|
+
}
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build the application, start services and trx engines.
|
|
50
|
+
* Returns references to start a daemon.
|
|
51
|
+
*/
|
|
52
|
+
async make() {
|
|
53
|
+
if (this.space || this.builders) {
|
|
54
|
+
await this.boot().bootPromise;
|
|
55
|
+
}
|
|
56
|
+
const modules = this._modules;
|
|
57
|
+
for (const key in this._injectedModules) {
|
|
58
|
+
const mod = this._injectedModules[key];
|
|
59
|
+
modules[mod.name] = mod;
|
|
60
|
+
}
|
|
61
|
+
const services = {};
|
|
62
|
+
for (const key in this._services) {
|
|
63
|
+
const service = this._services[key];
|
|
64
|
+
await promise_1.default.solve(service.up({
|
|
65
|
+
modules
|
|
66
|
+
}));
|
|
67
|
+
services[key] = service;
|
|
68
|
+
}
|
|
69
|
+
log_1.Log.debug('app', this.name, 'Starting transaction engines');
|
|
70
|
+
const trxEngines = {};
|
|
71
|
+
for (const m in modules) {
|
|
72
|
+
const module = modules[m];
|
|
73
|
+
module.start(this, services);
|
|
74
|
+
const trxConfig = this._config.modules?.[m]?.trx;
|
|
75
|
+
const authn = {};
|
|
76
|
+
for (const a in this._config?.authn || {}) {
|
|
77
|
+
const prov = this._config.authn?.[a]?.();
|
|
78
|
+
if (prov) {
|
|
79
|
+
authn[a] = prov;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
trxEngines[m] = new trx_engine_1.TrxEngine(`app:${this.name}`, module, authn, trxConfig, services);
|
|
83
|
+
}
|
|
84
|
+
log_1.Log.debug('app', this.name, 'Linking externals');
|
|
85
|
+
this.linkExternals(modules);
|
|
86
|
+
log_1.Log.debug('app', this.name, 'Linking app values');
|
|
87
|
+
this.linkAppValues(modules);
|
|
88
|
+
return {
|
|
89
|
+
modules,
|
|
90
|
+
services,
|
|
91
|
+
trxEngines
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* This method injects elements flagged as externals by referencing them
|
|
96
|
+
* from the other module directly, given this is a single-threaded App.
|
|
97
|
+
*
|
|
98
|
+
* TODO: allow overriding this behavior with adapters
|
|
99
|
+
*/
|
|
100
|
+
linkExternals(modules) {
|
|
101
|
+
Object.values(modules).forEach(module => {
|
|
102
|
+
const jobs = {};
|
|
103
|
+
for (const name in module.schema.externals.jobs) {
|
|
104
|
+
const dep = module.schema.externals.jobs[name];
|
|
105
|
+
const config = this._config;
|
|
106
|
+
const node = config?.modules?.[dep.module]?.jobs?.[dep.name];
|
|
107
|
+
if (!node) {
|
|
108
|
+
throw new Error(`External job '${dep.tag}' not configured on module '${this.name}'`);
|
|
109
|
+
}
|
|
110
|
+
jobs[name] = new distributed_job_1.DistributedJob(module, node);
|
|
111
|
+
}
|
|
112
|
+
module.injectRunners({
|
|
113
|
+
// buckets: Object.values(module.schema.externals.buckets),
|
|
114
|
+
// messages: Object.values(module.schema.externals.messages),
|
|
115
|
+
jobs
|
|
116
|
+
// machines: Object.values(module.schema.externals.machines),
|
|
117
|
+
});
|
|
118
|
+
// const buckets = module.schema.externals.buckets;
|
|
119
|
+
// Object.values(buckets).forEach(bucket => {
|
|
120
|
+
// module.nql.linkExternal(modules[bucket.module].buckets[bucket.name]);
|
|
121
|
+
// })
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* This method injects values from environment variables into each module's
|
|
126
|
+
* app constants.
|
|
127
|
+
*/
|
|
128
|
+
linkAppValues(modules) {
|
|
129
|
+
Object.values(modules).forEach(module => {
|
|
130
|
+
const values = module.schema.constants.values;
|
|
131
|
+
Object.values(values).forEach(value => {
|
|
132
|
+
if (value.scope !== 'app')
|
|
133
|
+
return;
|
|
134
|
+
value.value = process.env[value.key];
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// Override App abstract methods
|
|
139
|
+
async daemon() {
|
|
140
|
+
if (this._daemon) {
|
|
141
|
+
return this._daemon;
|
|
142
|
+
}
|
|
143
|
+
const app = await this.make();
|
|
144
|
+
log_1.Log.debug('app', this.name, 'Spawning daemon');
|
|
145
|
+
this._daemon = new DistributedNodeDaemon(this.name, this._host, app.trxEngines, app.services, this._config);
|
|
146
|
+
await this._daemon.boot();
|
|
147
|
+
// Link daemon to modules
|
|
148
|
+
for (const m in app.modules) {
|
|
149
|
+
const module = app.modules[m];
|
|
150
|
+
module.daemon = this._daemon;
|
|
151
|
+
}
|
|
152
|
+
return this._daemon;
|
|
153
|
+
}
|
|
154
|
+
host(config) {
|
|
155
|
+
this._host = config;
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
modules(modules) {
|
|
159
|
+
super.modules(modules);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
service($) {
|
|
163
|
+
super.service($);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
package(_package) {
|
|
167
|
+
this.packageJson = _package;
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
get config() {
|
|
171
|
+
return new distributed_app_config_1.DistributedAppConfigBuilder(this);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.DistributedAppNode = DistributedAppNode;
|
|
175
|
+
/**
|
|
176
|
+
* @category App
|
|
177
|
+
* @subcategory Distributed
|
|
178
|
+
*/
|
|
179
|
+
class DistributedNodeDaemon extends monolyth_app_1.MonolythDaemon {
|
|
180
|
+
constructor(name, host, trxEngines, services, config) {
|
|
181
|
+
super(name, trxEngines, services, config);
|
|
182
|
+
this.inc = new inc_server_1.INCServer({
|
|
183
|
+
name,
|
|
184
|
+
...host
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
async boot() {
|
|
188
|
+
await this.inc.start();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.DistributedNodeDaemon = DistributedNodeDaemon;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { $Job, $Module, $Space } from "../../../../elements";
|
|
2
|
+
import { Job } from "../../../../elements/blocks/job/job";
|
|
3
|
+
import { Module } from "../../../module";
|
|
4
|
+
export declare class DistributedJob<S extends $Space, M extends $Module, $ extends $Job> extends Job<S, M, $> {
|
|
5
|
+
node: string;
|
|
6
|
+
constructor(module: Module<S, M>, node: string);
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DistributedJob = void 0;
|
|
4
|
+
const job_1 = require("../../../../elements/blocks/job/job");
|
|
5
|
+
class DistributedJob extends job_1.Job {
|
|
6
|
+
constructor(module, node) {
|
|
7
|
+
super(module, {});
|
|
8
|
+
this.node = node;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.DistributedJob = DistributedJob;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type INCClientConfig = {
|
|
2
|
+
name: string;
|
|
3
|
+
server: {
|
|
4
|
+
host: string;
|
|
5
|
+
port: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare class INCClient {
|
|
9
|
+
config: INCClientConfig;
|
|
10
|
+
private client;
|
|
11
|
+
constructor(config: INCClientConfig);
|
|
12
|
+
start(): Promise<void>;
|
|
13
|
+
stop(): Promise<void>;
|
|
14
|
+
send(data: string | Buffer): Promise<void>;
|
|
15
|
+
private onError;
|
|
16
|
+
private onData;
|
|
17
|
+
}
|