nesoi 3.4.22 → 3.4.24
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/bundler/browser/browser.bundler.js +1 -1
- package/lib/bundler/monolyth/monolyth.bundler.d.ts +2 -2
- package/lib/bundler/monolyth/monolyth.bundler.js +9 -6
- package/lib/bundler/monolyth/stages/2_build_typescript_stage.js +5 -6
- package/lib/bundler/monolyth/stages/3_copy_types_stage.js +2 -3
- package/lib/compiler/compiler.d.ts +10 -1
- package/lib/compiler/compiler.js +54 -5
- package/lib/compiler/elements/controller.element.d.ts +1 -1
- package/lib/compiler/elements/controller.element.js +8 -0
- package/lib/compiler/progressive.js +2 -2
- package/lib/compiler/stages/4_build_schemas_stage.js +1 -1
- package/lib/compiler/stages/5_inject_ts_stage.js +2 -0
- package/lib/compiler/stages/6_build_elements_stage.js +2 -0
- package/lib/compiler/stages/7_dump_stage.js +4 -2
- package/lib/elements/edge/controller/adapters/cli.controller_adapter.d.ts +3 -6
- package/lib/elements/edge/controller/adapters/cli.controller_adapter.js +4 -4
- package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +16 -6
- package/lib/elements/edge/controller/adapters/controller_adapter.js +20 -23
- package/lib/elements/edge/controller/adapters/fetch.controller_adapter.d.ts +27 -0
- package/lib/elements/edge/controller/adapters/fetch.controller_adapter.js +83 -0
- package/lib/elements/edge/controller/controller.schema.d.ts +9 -0
- package/lib/elements/edge/controller/controller.schema.js +41 -0
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +2 -2
- package/lib/elements/entities/bucket/adapters/memory.nql.js +2 -2
- package/lib/elements/entities/bucket/bucket.js +2 -2
- package/lib/elements/entities/bucket/model/bucket_model.js +1 -1
- package/lib/elements/entities/constants/constants.d.ts +1 -1
- package/lib/elements/entities/constants/constants.js +1 -1
- package/lib/elements/entities/message/template/message_template_parser.js +1 -1
- package/lib/engine/app/app.config.d.ts +5 -1
- package/lib/engine/app/app.d.ts +11 -0
- package/lib/engine/app/app.js +30 -0
- package/lib/engine/app/inline.app.js +2 -1
- package/lib/engine/builder.d.ts +4 -2
- package/lib/engine/builder.js +65 -9
- package/lib/engine/data/error.d.ts +8 -0
- package/lib/engine/data/error.js +8 -0
- package/lib/engine/data/tree.js +4 -1
- package/lib/engine/dependency.d.ts +1 -0
- package/lib/engine/transaction/nodes/controller.trx_node.d.ts +17 -0
- package/lib/engine/transaction/nodes/controller.trx_node.js +60 -0
- package/lib/engine/transaction/trx_node.d.ts +2 -0
- package/lib/engine/transaction/trx_node.js +5 -0
- package/lib/engine/treeshake.js +1 -1
- package/lib/engine/util/deep.js +2 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -17,7 +17,7 @@ class BrowserBundler extends monolyth_bundler_1.MonolythBundler {
|
|
|
17
17
|
async run() {
|
|
18
18
|
await super.run();
|
|
19
19
|
console_1.default.header('Browser Bundler');
|
|
20
|
-
log_1.Log.info('bundler', 'browser', `Importing the monolyth definition from ${this.appPath}`);
|
|
20
|
+
log_1.Log.info('bundler', 'browser', `Importing the monolyth definition from ${this.compiler.appPath}`);
|
|
21
21
|
await new _8_replace_nesoi_for_browser_stage_1.ReplaceNesoiForBrowserStage(this).run();
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -4,16 +4,16 @@ import type { MonolythBundlerConfig } from "../../engine/app/native/monolyth.app
|
|
|
4
4
|
import { MonolythApp } from "../../engine/app/native/monolyth.app";
|
|
5
5
|
export declare class MonolythBundler {
|
|
6
6
|
compiler: Compiler;
|
|
7
|
-
appPath: string;
|
|
8
7
|
config: MonolythBundlerConfig;
|
|
9
8
|
tsconfig: Record<string, string | number>;
|
|
10
9
|
dirs: {
|
|
10
|
+
dot_nesoi: string;
|
|
11
11
|
build: string;
|
|
12
12
|
build_modules: string;
|
|
13
13
|
build_types: string;
|
|
14
14
|
build_bin: string;
|
|
15
15
|
};
|
|
16
|
-
constructor(compiler: Compiler,
|
|
16
|
+
constructor(compiler: Compiler, config?: MonolythBundlerConfig);
|
|
17
17
|
run(): Promise<void>;
|
|
18
18
|
mergeServicePaths(app: AnyApp): void;
|
|
19
19
|
expandLibPaths(): void;
|
|
@@ -54,20 +54,23 @@ const monolyth_app_1 = require("../../engine/app/native/monolyth.app");
|
|
|
54
54
|
const path_1 = require("../../engine/util/path");
|
|
55
55
|
class MonolythBundler {
|
|
56
56
|
compiler;
|
|
57
|
-
appPath;
|
|
58
57
|
config;
|
|
59
58
|
tsconfig = {};
|
|
60
59
|
dirs;
|
|
61
|
-
constructor(compiler,
|
|
60
|
+
constructor(compiler, config = {}) {
|
|
62
61
|
this.compiler = compiler;
|
|
63
|
-
this.appPath = appPath;
|
|
64
62
|
this.config = config;
|
|
65
|
-
this.dirs = {
|
|
63
|
+
this.dirs = {
|
|
64
|
+
dot_nesoi: space_1.Space.path(this.compiler.space, '.nesoi', this.compiler.targetDir)
|
|
65
|
+
};
|
|
66
66
|
}
|
|
67
67
|
async run() {
|
|
68
68
|
console_1.default.header('Monolyth Bundler');
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
if (!this.compiler.appPath) {
|
|
70
|
+
throw new Error('The compiler passed as argument to the bundler MUST include some app as argument.');
|
|
71
|
+
}
|
|
72
|
+
log_1.Log.info('bundler', 'monolyth', `Importing the monolyth definition from ${this.compiler.appPath}`);
|
|
73
|
+
const appFile = space_1.Space.path(this.compiler.space, this.compiler.appPath);
|
|
71
74
|
const app = (await Promise.resolve(`${appFile}`).then(s => __importStar(require(s)))).default;
|
|
72
75
|
this.config = Object.assign({}, app_1.App.getInfo(app).config?.compiler || {}, this.config);
|
|
73
76
|
this.mergeServicePaths(app);
|
|
@@ -56,7 +56,7 @@ class BuildTypescriptStage {
|
|
|
56
56
|
}
|
|
57
57
|
async run() {
|
|
58
58
|
log_1.Log.info('compiler', 'monolyth', 'Building TypeScript files...');
|
|
59
|
-
const { config, compiler, dirs
|
|
59
|
+
const { config, compiler, dirs } = this.bundler;
|
|
60
60
|
const libPaths = (config.libPaths || []).map(path => {
|
|
61
61
|
return space_1.Space.path(compiler.space, path);
|
|
62
62
|
});
|
|
@@ -67,13 +67,13 @@ class BuildTypescriptStage {
|
|
|
67
67
|
const modulePaths = [];
|
|
68
68
|
space_1.Space.scan(compiler.space, (name) => {
|
|
69
69
|
if (info.spaceModules.includes(name)) {
|
|
70
|
-
modulePaths.push(
|
|
70
|
+
modulePaths.push(path.join(dirs.dot_nesoi, name));
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
73
|
const space = compiler.space;
|
|
74
74
|
const spacePath = space_1.Space.path(space);
|
|
75
75
|
const libFiles = typescript_compiler_1.TypeScriptCompiler.allFiles(libPaths);
|
|
76
|
-
const appFile = space_1.Space.path(space, appPath);
|
|
76
|
+
const appFile = space_1.Space.path(space, compiler.appPath);
|
|
77
77
|
const nesoiFile = space_1.Space.path(space, 'nesoi.ts');
|
|
78
78
|
const moduleFiles = typescript_compiler_1.TypeScriptCompiler.allFiles(modulePaths);
|
|
79
79
|
const replacePaths = {
|
|
@@ -128,10 +128,9 @@ class BuildTypescriptStage {
|
|
|
128
128
|
replacePaths[lib] = path.resolve(dirs.build, outPath);
|
|
129
129
|
tsPaths[lib + '/*'] = [space_1.Space.path(compiler.space, lib) + '/*'];
|
|
130
130
|
});
|
|
131
|
-
tsPaths['.nesoi/*'] = [
|
|
132
|
-
const dotNesoiPath = space_1.Space.path(compiler.space, '.nesoi');
|
|
131
|
+
tsPaths['.nesoi/*'] = [path.join(dirs.dot_nesoi, '*')];
|
|
133
132
|
moduleFiles.forEach(moduleFile => {
|
|
134
|
-
const module = moduleFile.replace(
|
|
133
|
+
const module = moduleFile.replace(dirs.dot_nesoi, '').split(path.sep)[1];
|
|
135
134
|
if (!module?.length) {
|
|
136
135
|
throw new Error(`Unable to find module name from path ${moduleFile}`);
|
|
137
136
|
}
|
|
@@ -36,7 +36,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.CopyTypesStage = void 0;
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
|
-
const space_1 = require("../../../engine/space");
|
|
40
39
|
const log_1 = require("../../../engine/util/log");
|
|
41
40
|
const name_helpers_1 = require("../../../engine/util/name_helpers");
|
|
42
41
|
const app_1 = require("../../../engine/app/app");
|
|
@@ -61,7 +60,7 @@ class CopyTypesStage {
|
|
|
61
60
|
// Copy module types to types folder
|
|
62
61
|
for (const name of info.spaceModules) {
|
|
63
62
|
const module = compiler.modules[name];
|
|
64
|
-
const from =
|
|
63
|
+
const from = path.join(dirs.dot_nesoi, module.lowName + '.module.ts');
|
|
65
64
|
const to = path.resolve(dirs.build_types, module.lowName + '.module.ts');
|
|
66
65
|
log_1.Log.debug('compiler', 'monolyth', `Copying module types from ${from} to ${to}`);
|
|
67
66
|
fs.cpSync(from, to, { recursive: true });
|
|
@@ -70,7 +69,7 @@ class CopyTypesStage {
|
|
|
70
69
|
{
|
|
71
70
|
const space = compiler.space._name;
|
|
72
71
|
const spaceLow = name_helpers_1.NameHelpers.nameHighToLow(space);
|
|
73
|
-
const from =
|
|
72
|
+
const from = path.join(dirs.dot_nesoi, spaceLow + '.ts');
|
|
74
73
|
const to = path.resolve(dirs.build_types, spaceLow + '.ts');
|
|
75
74
|
log_1.Log.debug('compiler', 'monolyth', `Copying space types from ${from} to ${to}`);
|
|
76
75
|
fs.cpSync(from, to, { recursive: true });
|
|
@@ -4,13 +4,22 @@ import type { CompilerConfig } from "../engine/app/app.config";
|
|
|
4
4
|
import { ModuleTree } from "../engine/tree";
|
|
5
5
|
import { Space } from "../engine/space";
|
|
6
6
|
import { TypeScriptCompiler } from './typescript/typescript_compiler';
|
|
7
|
+
import type { Tag } from "../engine/dependency";
|
|
7
8
|
export declare class Compiler {
|
|
8
9
|
space: Space<$Space>;
|
|
9
10
|
config?: CompilerConfig | undefined;
|
|
11
|
+
appPath?: string | undefined;
|
|
10
12
|
modules: Record<string, CompilerModule>;
|
|
11
13
|
tree: ModuleTree;
|
|
12
14
|
tsCompiler: TypeScriptCompiler;
|
|
15
|
+
targetDir: string;
|
|
13
16
|
logFn?: (msg: string) => void;
|
|
14
|
-
|
|
17
|
+
tags?: {
|
|
18
|
+
[module: string]: {
|
|
19
|
+
include?: Tag[];
|
|
20
|
+
exclude?: Tag[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
constructor(space: Space<$Space>, config?: CompilerConfig | undefined, appPath?: string | undefined);
|
|
15
24
|
run(): Promise<this>;
|
|
16
25
|
}
|
package/lib/compiler/compiler.js
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.Compiler = void 0;
|
|
40
|
+
const app_1 = require("../engine/app/app");
|
|
7
41
|
const tree_1 = require("../engine/tree");
|
|
8
42
|
const space_1 = require("../engine/space");
|
|
9
43
|
const typescript_compiler_1 = require("./typescript/typescript_compiler");
|
|
@@ -21,22 +55,37 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
21
55
|
class Compiler {
|
|
22
56
|
space;
|
|
23
57
|
config;
|
|
58
|
+
appPath;
|
|
24
59
|
modules = {};
|
|
25
60
|
tree;
|
|
26
61
|
tsCompiler;
|
|
62
|
+
targetDir;
|
|
27
63
|
logFn;
|
|
28
|
-
|
|
64
|
+
tags;
|
|
65
|
+
constructor(space, config, appPath) {
|
|
29
66
|
this.space = space;
|
|
30
67
|
this.config = config;
|
|
68
|
+
this.appPath = appPath;
|
|
31
69
|
console_1.default.header('Compiler');
|
|
32
|
-
log_1.Log.info('compiler', 'ts', '
|
|
33
|
-
this.tree = new tree_1.ModuleTree({}, this.config);
|
|
70
|
+
log_1.Log.info('compiler', 'ts', 'Preparing TypeScript...');
|
|
34
71
|
this.tsCompiler = new typescript_compiler_1.TypeScriptCompiler(space, config?.nesoiPath);
|
|
35
72
|
}
|
|
36
73
|
async run() {
|
|
37
|
-
|
|
74
|
+
let app;
|
|
75
|
+
if (this.appPath) {
|
|
76
|
+
log_1.Log.info('compiler', 'ts', `Importing the app definition from ${this.appPath}`);
|
|
77
|
+
const appFile = space_1.Space.path(this.space, this.appPath);
|
|
78
|
+
app = (await Promise.resolve(`${appFile}`).then(s => __importStar(require(s)))).default;
|
|
79
|
+
}
|
|
80
|
+
this.tags = app ? app_1.App.getIncludeExcludeTags(app) : undefined;
|
|
81
|
+
log_1.Log.info('compiler', 'ts', 'Starting');
|
|
82
|
+
this.tree = new tree_1.ModuleTree({}, {
|
|
83
|
+
exclude: this.config?.exclude
|
|
84
|
+
});
|
|
85
|
+
this.targetDir = app ? `.app.${app.name}` : '';
|
|
86
|
+
if (this.appPath || this.config?.reset) {
|
|
38
87
|
// Cleanup .nesoi folder
|
|
39
|
-
fs_1.default.rmSync(space_1.Space.path(this.space, '.nesoi'), { recursive: true, force: true });
|
|
88
|
+
fs_1.default.rmSync(space_1.Space.path(this.space, '.nesoi', this.targetDir), { recursive: true, force: true });
|
|
40
89
|
}
|
|
41
90
|
try {
|
|
42
91
|
await new _1_scan_stage_1.ScanStage(this).run();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { $Controller } from "../../elements/edge/controller/controller.schema";
|
|
2
2
|
import { Element } from './element';
|
|
3
3
|
export declare class ControllerElement extends Element<$Controller> {
|
|
4
4
|
protected prepare(): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ControllerElement = void 0;
|
|
4
|
+
const controller_schema_1 = require("../../elements/edge/controller/controller.schema");
|
|
4
5
|
const element_1 = require("./element");
|
|
5
6
|
const dump_helpers_1 = require("../helpers/dump_helpers");
|
|
6
7
|
const name_helpers_1 = require("../../engine/util/name_helpers");
|
|
@@ -8,14 +9,21 @@ class ControllerElement extends element_1.Element {
|
|
|
8
9
|
prepare() {
|
|
9
10
|
this.schema['#authn'] = element_1.Element.Any;
|
|
10
11
|
this.schema['#input'] = element_1.Element.Any;
|
|
12
|
+
this.schema['#path'] = element_1.Element.Any;
|
|
11
13
|
}
|
|
12
14
|
buildType() {
|
|
13
15
|
const type = dump_helpers_1.DumpHelpers.dumpValueToType(this.schema);
|
|
14
16
|
const input = this.schema.input.map(tag => name_helpers_1.NameHelpers.tagType(tag, this.module)).join(' | ');
|
|
17
|
+
const endpoints = controller_schema_1.$Controller.endpoints(this.schema);
|
|
18
|
+
const path = Object.fromEntries(Object.entries(endpoints).map(p => [
|
|
19
|
+
p[0],
|
|
20
|
+
name_helpers_1.NameHelpers.tagType(p[1].endpoint.msg, this.module)
|
|
21
|
+
]));
|
|
15
22
|
return {
|
|
16
23
|
...type,
|
|
17
24
|
'#authn': element_1.Element.makeAuthnType(this.schema.auth),
|
|
18
25
|
'#input': input,
|
|
26
|
+
'#path': path
|
|
19
27
|
};
|
|
20
28
|
}
|
|
21
29
|
}
|
|
@@ -45,7 +45,7 @@ const hash_1 = require("../engine/util/hash");
|
|
|
45
45
|
const path_1 = __importDefault(require("path"));
|
|
46
46
|
class ProgressiveBuild {
|
|
47
47
|
static cache(compiler, $) {
|
|
48
|
-
const path = space_1.Space.path(compiler.space, '.nesoi', '.cache');
|
|
48
|
+
const path = space_1.Space.path(compiler.space, '.nesoi', compiler.targetDir, '.cache');
|
|
49
49
|
if (!(0, fs_1.existsSync)(path)) {
|
|
50
50
|
return this.init(compiler);
|
|
51
51
|
}
|
|
@@ -85,7 +85,7 @@ class ProgressiveBuild {
|
|
|
85
85
|
}
|
|
86
86
|
static async init(compiler) {
|
|
87
87
|
const cache = {
|
|
88
|
-
nesoidir: space_1.Space.path(compiler.space, '.nesoi'),
|
|
88
|
+
nesoidir: space_1.Space.path(compiler.space, '.nesoi', compiler.targetDir),
|
|
89
89
|
hash: await ProgressiveBuild.hash(compiler),
|
|
90
90
|
files: {},
|
|
91
91
|
modules: {},
|
|
@@ -41,7 +41,7 @@ class BuildSchemasStage {
|
|
|
41
41
|
if (node.isInline) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
await builder_1.Builder.buildNode(module, node, this.compiler.tree);
|
|
44
|
+
await builder_1.Builder.buildNode(module, node, this.compiler.tree, this.compiler.tags);
|
|
45
45
|
});
|
|
46
46
|
const t = new Date().getTime();
|
|
47
47
|
log_1.Log.debug('compiler', 'stage.build_schemas', `[t: ${(t - t0) / 1000} ms]`);
|
|
@@ -21,6 +21,8 @@ class InjectTSStage {
|
|
|
21
21
|
const { tree } = this.compiler;
|
|
22
22
|
const nodes = tree.allNodes();
|
|
23
23
|
tree.traverse('inject', node => {
|
|
24
|
+
if (node.filtered)
|
|
25
|
+
return Promise.resolve();
|
|
24
26
|
inject_1.TSBridgeInject.inject(this.compiler, nodes, node);
|
|
25
27
|
return Promise.resolve();
|
|
26
28
|
});
|
|
@@ -19,6 +19,8 @@ class BuildElementsStage {
|
|
|
19
19
|
log_1.Log.info('compiler', 'stage.build_elements', 'Building Elements...');
|
|
20
20
|
const t0 = new Date().getTime();
|
|
21
21
|
await this.compiler.tree.traverse('Building elements ', async (node) => {
|
|
22
|
+
if (node.filtered)
|
|
23
|
+
return;
|
|
22
24
|
const module = this.compiler.modules[node.tag.module];
|
|
23
25
|
await module.buildElementNode(node);
|
|
24
26
|
});
|
|
@@ -127,7 +127,8 @@ class DumpStage {
|
|
|
127
127
|
dump += `\nexport default interface ${name} extends $Space `;
|
|
128
128
|
dump += dump_helpers_1.DumpHelpers.dumpType(type);
|
|
129
129
|
// Create dir and write to file
|
|
130
|
-
const
|
|
130
|
+
const targetPath = path_1.default.join('.', '.nesoi', this.compiler.targetDir);
|
|
131
|
+
const dumpDir = space_1.Space.path(this.compiler.space, targetPath);
|
|
131
132
|
if (!fs.existsSync(dumpDir)) {
|
|
132
133
|
fs.mkdirSync(dumpDir, { recursive: true });
|
|
133
134
|
}
|
|
@@ -137,7 +138,8 @@ class DumpStage {
|
|
|
137
138
|
}
|
|
138
139
|
/* Module */
|
|
139
140
|
dumpModule(module, spaceType) {
|
|
140
|
-
const
|
|
141
|
+
const targetPath = path_1.default.join('.', '.nesoi', this.compiler.targetDir, module.lowName);
|
|
142
|
+
const dumpDir = space_1.Space.path(this.compiler.space, targetPath);
|
|
141
143
|
if (!fs.existsSync(dumpDir)) {
|
|
142
144
|
fs.mkdirSync(dumpDir, { recursive: true });
|
|
143
145
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type $ControllerEndpoint, type $ControllerTopic } from '../controller.schema';
|
|
2
2
|
import { ControllerAdapter } from './controller_adapter';
|
|
3
3
|
import { ControllerEndpoint, ControllerTopic } from '../controller';
|
|
4
|
-
export type ControllerEndpointPath = ($ControllerDomain | $ControllerGroup | $ControllerEndpoint)[];
|
|
5
4
|
/**
|
|
6
5
|
* @category Adapters
|
|
7
6
|
* @subcategory Edge
|
|
8
7
|
*/
|
|
9
8
|
export declare class CLIControllerAdapter extends ControllerAdapter {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
protected makeEndpoint(path: string, schema: $ControllerEndpoint): void;
|
|
13
|
-
protected makeTopic(schema: $ControllerTopic): void;
|
|
9
|
+
protected makeEndpoint(path: string, schema: $ControllerEndpoint): ControllerEndpoint<$ControllerEndpoint>;
|
|
10
|
+
protected makeTopic(schema: $ControllerTopic): ControllerTopic<$ControllerTopic>;
|
|
14
11
|
}
|
|
@@ -9,15 +9,15 @@ const log_1 = require("../../../../engine/util/log");
|
|
|
9
9
|
* @subcategory Edge
|
|
10
10
|
*/
|
|
11
11
|
class CLIControllerAdapter extends controller_adapter_1.ControllerAdapter {
|
|
12
|
-
endpoints = {};
|
|
13
|
-
topics = {};
|
|
14
12
|
makeEndpoint(path, schema) {
|
|
15
|
-
|
|
13
|
+
const endpoint = new controller_1.ControllerEndpoint(schema, this, path);
|
|
16
14
|
log_1.Log.debug('controller', this.schema.name, `Bound endpoint '${path}' to '${schema.target}'`);
|
|
15
|
+
return endpoint;
|
|
17
16
|
}
|
|
18
17
|
makeTopic(schema) {
|
|
19
|
-
|
|
18
|
+
const topic = new controller_1.ControllerTopic(schema, this, schema.name);
|
|
20
19
|
log_1.Log.debug('controller', this.schema.name, `Bound topic '${schema.name}'`);
|
|
20
|
+
return topic;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.CLIControllerAdapter = CLIControllerAdapter;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { AnyTrxNode } from "../../../../engine/transaction/trx_node";
|
|
2
|
-
import type { $
|
|
2
|
+
import type { $ControllerEndpoint, $ControllerTopic, ControllerEndpointPath } from '../controller.schema';
|
|
3
|
+
import { $Controller } from '../controller.schema';
|
|
3
4
|
import type { AnyDaemon } from "../../../../engine/daemon";
|
|
4
5
|
import type { AuthRequest } from "../../../../engine/auth/authn";
|
|
5
6
|
import type { $Module } from "../../..";
|
|
6
|
-
|
|
7
|
+
import type { ControllerEndpoint, ControllerTopic } from '../controller';
|
|
7
8
|
/**
|
|
8
9
|
* @category Adapters
|
|
9
10
|
* @subcategory Edge
|
|
@@ -12,14 +13,23 @@ export declare abstract class ControllerAdapter {
|
|
|
12
13
|
protected module: $Module;
|
|
13
14
|
protected schema: $Controller;
|
|
14
15
|
protected daemon?: AnyDaemon;
|
|
16
|
+
protected endpoints: {
|
|
17
|
+
[path_str: string]: {
|
|
18
|
+
path: ControllerEndpointPath;
|
|
19
|
+
endpoint: ControllerEndpoint<$ControllerEndpoint>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
protected topics: {
|
|
23
|
+
[path: string]: ControllerTopic<$ControllerTopic>;
|
|
24
|
+
};
|
|
15
25
|
constructor(module: $Module, schema: $Controller);
|
|
16
26
|
trx(fn: (trx: AnyTrxNode) => Promise<any>, endpoint: {
|
|
17
27
|
name: string;
|
|
18
28
|
idempotent?: boolean;
|
|
19
29
|
}, auth?: AuthRequest<any>): Promise<import("../../../../engine/transaction/trx").TrxStatus<any>>;
|
|
20
30
|
bind(daemon: AnyDaemon): void;
|
|
21
|
-
|
|
22
|
-
protected
|
|
23
|
-
protected
|
|
24
|
-
protected
|
|
31
|
+
invoke(path: string, data: Record<string, any>, auth?: AuthRequest<any>): Promise<import("../../../../engine/transaction/trx").TrxStatus<any>>;
|
|
32
|
+
protected makePath(path: ControllerEndpointPath, endpoint: $ControllerEndpoint): string;
|
|
33
|
+
protected abstract makeEndpoint(path: string, schema: $ControllerEndpoint): ControllerEndpoint<$ControllerEndpoint>;
|
|
34
|
+
protected abstract makeTopic(schema: $ControllerTopic): ControllerTopic<$ControllerTopic>;
|
|
25
35
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ControllerAdapter = void 0;
|
|
4
|
+
const controller_schema_1 = require("../controller.schema");
|
|
4
5
|
const log_1 = require("../../../../engine/util/log");
|
|
6
|
+
const error_1 = require("../../../../engine/data/error");
|
|
5
7
|
/**
|
|
6
8
|
* @category Adapters
|
|
7
9
|
* @subcategory Edge
|
|
@@ -10,6 +12,8 @@ class ControllerAdapter {
|
|
|
10
12
|
module;
|
|
11
13
|
schema;
|
|
12
14
|
daemon;
|
|
15
|
+
endpoints = {};
|
|
16
|
+
topics = {};
|
|
13
17
|
constructor(module, schema) {
|
|
14
18
|
this.module = module;
|
|
15
19
|
this.schema = schema;
|
|
@@ -31,36 +35,29 @@ class ControllerAdapter {
|
|
|
31
35
|
}
|
|
32
36
|
bind(daemon) {
|
|
33
37
|
this.daemon = daemon;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
const endpoints = controller_schema_1.$Controller.endpoints(this.schema);
|
|
39
|
+
for (const key in endpoints) {
|
|
40
|
+
const { endpoint, path } = endpoints[key];
|
|
41
|
+
const path_str = this.makePath(path, endpoint);
|
|
42
|
+
this.endpoints[key] = {
|
|
43
|
+
path,
|
|
44
|
+
endpoint: this.makeEndpoint(path_str, endpoint)
|
|
45
|
+
};
|
|
37
46
|
}
|
|
38
47
|
for (const t in this.schema.topics) {
|
|
39
48
|
const topic = this.schema.topics[t];
|
|
40
|
-
this.makeTopic(topic);
|
|
49
|
+
this.topics[t] = this.makeTopic(topic);
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.makeEndpoint(path, endpoint);
|
|
48
|
-
}
|
|
49
|
-
for (const e in group.groups) {
|
|
50
|
-
const childGroup = group.groups[e];
|
|
51
|
-
const childRoot = [...root, childGroup];
|
|
52
|
-
this.makeGroup(childGroup, childRoot);
|
|
52
|
+
invoke(path, data, auth) {
|
|
53
|
+
const e = this.endpoints[path];
|
|
54
|
+
if (!e) {
|
|
55
|
+
throw error_1.NesoiError.Controller.EndpointNotFound({ endpoint: path, controller: this.schema.alias });
|
|
53
56
|
}
|
|
57
|
+
return e.endpoint.invoke(data, auth);
|
|
54
58
|
}
|
|
55
|
-
makePath(
|
|
56
|
-
|
|
57
|
-
const root = domain.name
|
|
58
|
-
? [schema.name, domain.name, domain.version]
|
|
59
|
-
: [schema.name, domain.version];
|
|
60
|
-
const list = root.concat(path
|
|
61
|
-
.slice(1)
|
|
62
|
-
.map(node => node.name));
|
|
63
|
-
return '/' + list.join('/');
|
|
59
|
+
makePath(path, endpoint) {
|
|
60
|
+
return controller_schema_1.$Controller.makePath(this.schema, path, endpoint);
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
63
|
exports.ControllerAdapter = ControllerAdapter;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { $Controller, $ControllerEndpoint, $ControllerTopic, ControllerEndpointPath } from '../controller.schema';
|
|
2
|
+
import { ControllerAdapter } from './controller_adapter';
|
|
3
|
+
import { ControllerEndpoint, ControllerTopic } from '../controller';
|
|
4
|
+
import type { $Module } from "../../..";
|
|
5
|
+
import type { AuthRequest } from "../../../../engine/auth/authn";
|
|
6
|
+
import { TrxStatus } from "../../../../engine/transaction/trx";
|
|
7
|
+
/**
|
|
8
|
+
* @category Adapters
|
|
9
|
+
* @subcategory Edge
|
|
10
|
+
*/
|
|
11
|
+
export declare class FetchControllerAdapter extends ControllerAdapter {
|
|
12
|
+
protected config: {
|
|
13
|
+
base_url: string;
|
|
14
|
+
};
|
|
15
|
+
constructor(module: $Module, schema: $Controller, config: {
|
|
16
|
+
base_url: string;
|
|
17
|
+
});
|
|
18
|
+
protected makeEndpoint(path: string, schema: $ControllerEndpoint): ControllerEndpoint<$ControllerEndpoint>;
|
|
19
|
+
protected makeTopic(schema: $ControllerTopic): ControllerTopic<$ControllerTopic>;
|
|
20
|
+
invoke(path: string, data: Record<string, any>, auth?: AuthRequest<any>): Promise<TrxStatus<{
|
|
21
|
+
data: Record<string, any> | Record<string, any>[];
|
|
22
|
+
}> | TrxStatus<undefined>>;
|
|
23
|
+
protected makeApiPath(endpoint: {
|
|
24
|
+
path: ControllerEndpointPath;
|
|
25
|
+
endpoint: ControllerEndpoint<any>;
|
|
26
|
+
}): string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchControllerAdapter = void 0;
|
|
4
|
+
const controller_adapter_1 = require("./controller_adapter");
|
|
5
|
+
const controller_1 = require("../controller");
|
|
6
|
+
const log_1 = require("../../../../engine/util/log");
|
|
7
|
+
const error_1 = require("../../../../engine/data/error");
|
|
8
|
+
const trx_1 = require("../../../../engine/transaction/trx");
|
|
9
|
+
const datetime_1 = require("../../../../engine/data/datetime");
|
|
10
|
+
/**
|
|
11
|
+
* @category Adapters
|
|
12
|
+
* @subcategory Edge
|
|
13
|
+
*/
|
|
14
|
+
class FetchControllerAdapter extends controller_adapter_1.ControllerAdapter {
|
|
15
|
+
config;
|
|
16
|
+
constructor(module, schema, config) {
|
|
17
|
+
super(module, schema);
|
|
18
|
+
this.config = config;
|
|
19
|
+
}
|
|
20
|
+
makeEndpoint(path, schema) {
|
|
21
|
+
const endpoint = new controller_1.ControllerEndpoint(schema, this, path);
|
|
22
|
+
log_1.Log.debug('controller', this.schema.name, `Bound endpoint '${path}' to '${schema.target}'`);
|
|
23
|
+
return endpoint;
|
|
24
|
+
}
|
|
25
|
+
makeTopic(schema) {
|
|
26
|
+
const topic = new controller_1.ControllerTopic(schema, this, schema.name);
|
|
27
|
+
log_1.Log.debug('controller', this.schema.name, `Bound topic '${schema.name}'`);
|
|
28
|
+
return topic;
|
|
29
|
+
}
|
|
30
|
+
async invoke(path, data, auth) {
|
|
31
|
+
const endpoint = this.endpoints[path];
|
|
32
|
+
if (!endpoint) {
|
|
33
|
+
throw error_1.NesoiError.Controller.EndpointNotFound({ endpoint: path, controller: this.schema.alias });
|
|
34
|
+
}
|
|
35
|
+
const start = datetime_1.NesoiDatetime.now();
|
|
36
|
+
const url = this.config.base_url + this.makeApiPath(endpoint);
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetch(url, {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'application/json'
|
|
42
|
+
},
|
|
43
|
+
body: JSON.stringify(data)
|
|
44
|
+
})
|
|
45
|
+
.then(async (response) => ({
|
|
46
|
+
status: response.status,
|
|
47
|
+
headers: response.headers,
|
|
48
|
+
body: await response.json().catch(() => null)
|
|
49
|
+
}))
|
|
50
|
+
.then((response) => {
|
|
51
|
+
// if (response.status === 401) {
|
|
52
|
+
// // ...
|
|
53
|
+
// }
|
|
54
|
+
return response.body;
|
|
55
|
+
})
|
|
56
|
+
.catch((e) => {
|
|
57
|
+
log_1.Log.error('controller', 'fetch', e.toString(), e);
|
|
58
|
+
// ...
|
|
59
|
+
throw e;
|
|
60
|
+
});
|
|
61
|
+
const end = datetime_1.NesoiDatetime.now();
|
|
62
|
+
return new trx_1.TrxStatus('#', 'plugin:fetch', start, end, 'ok', response);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
const end = datetime_1.NesoiDatetime.now();
|
|
66
|
+
const error = new error_1.NesoiError.BaseError('FetchError', e.toString(), 401, e);
|
|
67
|
+
return new trx_1.TrxStatus('#', 'plugin:fetch', start, end, 'error', undefined, error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
makeApiPath(endpoint) {
|
|
71
|
+
const domain = endpoint.path[0];
|
|
72
|
+
const root = domain.name
|
|
73
|
+
? [this.schema.name, domain.version, domain.name]
|
|
74
|
+
: [this.schema.name, domain.version];
|
|
75
|
+
const list = [
|
|
76
|
+
...root,
|
|
77
|
+
...endpoint.path.slice(1).map(node => node.name),
|
|
78
|
+
endpoint.endpoint.schema.name.startsWith('#') ? '' : endpoint.endpoint.schema.name
|
|
79
|
+
];
|
|
80
|
+
return '/' + list.join('/');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.FetchControllerAdapter = FetchControllerAdapter;
|
|
@@ -2,6 +2,7 @@ import type { $BlockAuth } from "../../blocks/block.schema";
|
|
|
2
2
|
import type { $Message } from "../../entities/message/message.schema";
|
|
3
3
|
import type { AnyUsers } from "../../../engine/auth/authn";
|
|
4
4
|
import type { Tag } from "../../../engine/dependency";
|
|
5
|
+
export type ControllerEndpointPath = ($ControllerDomain | $ControllerGroup | $ControllerEndpoint)[];
|
|
5
6
|
/**
|
|
6
7
|
* @category Schemas
|
|
7
8
|
* @subcategory Edge
|
|
@@ -74,5 +75,13 @@ export declare class $Controller {
|
|
|
74
75
|
$t: "controller";
|
|
75
76
|
'#authn': AnyUsers;
|
|
76
77
|
'#input': $Message;
|
|
78
|
+
'#path': Record<string, $Message>;
|
|
77
79
|
constructor(module: string, name: string, alias: string, auth: $BlockAuth[], input: Tag[], domains?: Record<string, $ControllerDomain>, topics?: Record<string, $ControllerTopic>);
|
|
80
|
+
static endpoints(schema: $Controller): {
|
|
81
|
+
[path_str: string]: {
|
|
82
|
+
path: ControllerEndpointPath;
|
|
83
|
+
endpoint: $ControllerEndpoint;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
static makePath(schema: $Controller, path: ControllerEndpointPath, endpoint: $ControllerEndpoint): string;
|
|
78
87
|
}
|