nesoi 3.1.6 → 3.1.7
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/stages/4_dump_modules_stage.js +8 -0
- package/lib/compiler/elements/element.d.ts +2 -1
- package/lib/compiler/elements/element.js +1 -0
- package/lib/compiler/elements/topic.element.d.ts +6 -0
- package/lib/compiler/elements/topic.element.js +24 -0
- package/lib/compiler/helpers/name_helpers.js +2 -1
- package/lib/compiler/module.d.ts +2 -1
- package/lib/compiler/module.js +7 -0
- package/lib/compiler/stages/7_dump_stage.js +3 -2
- package/lib/compiler/treeshake.d.ts +3 -0
- package/lib/compiler/treeshake.js +21 -0
- package/lib/compiler/typescript/typescript_compiler.js +1 -0
- package/lib/elements/blocks/block.schema.d.ts +1 -1
- package/lib/elements/blocks/topic/topic.builder.d.ts +36 -0
- package/lib/elements/blocks/topic/topic.builder.js +37 -0
- package/lib/elements/blocks/topic/topic.d.ts +20 -0
- package/lib/elements/blocks/topic/topic.js +44 -0
- package/lib/elements/blocks/topic/topic.schema.d.ts +17 -0
- package/lib/elements/blocks/topic/topic.schema.js +22 -0
- package/lib/elements/edge/controller/adapters/cli.controller_adapter.d.ts +4 -2
- package/lib/elements/edge/controller/adapters/cli.controller_adapter.js +5 -0
- package/lib/elements/edge/controller/adapters/controller_adapter.d.ts +2 -1
- package/lib/elements/edge/controller/adapters/controller_adapter.js +4 -0
- package/lib/elements/edge/controller/controller.builder.d.ts +23 -1
- package/lib/elements/edge/controller/controller.builder.js +51 -2
- package/lib/elements/edge/controller/controller.d.ts +14 -1
- package/lib/elements/edge/controller/controller.js +34 -1
- package/lib/elements/edge/controller/controller.schema.d.ts +16 -1
- package/lib/elements/edge/controller/controller.schema.js +19 -2
- package/lib/elements/index.d.ts +1 -0
- package/lib/elements/index.js +3 -1
- package/lib/engine/daemon.js +1 -1
- package/lib/engine/data/error.d.ts +7 -2
- package/lib/engine/data/error.js +11 -3
- package/lib/engine/module.d.ts +7 -2
- package/lib/engine/module.js +20 -0
- package/lib/engine/space.d.ts +12 -0
- package/lib/engine/space.js +13 -0
- package/lib/engine/transaction/nodes/topic.trx_node.d.ts +17 -0
- package/lib/engine/transaction/nodes/topic.trx_node.js +50 -0
- package/lib/engine/transaction/trx_node.d.ts +3 -1
- package/lib/engine/transaction/trx_node.js +8 -0
- package/lib/engine/util/log.d.ts +1 -1
- package/lib/engine/util/log.js +1 -0
- package/lib/schema.d.ts +5 -1
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -161,6 +161,14 @@ class DumpModulesStage {
|
|
|
161
161
|
});
|
|
162
162
|
str += ' ],';
|
|
163
163
|
}
|
|
164
|
+
const topics = Object.values(module.module.schema.topics || {});
|
|
165
|
+
if (topics.length) {
|
|
166
|
+
str += '\n topics: [\n';
|
|
167
|
+
topics.forEach(topic => {
|
|
168
|
+
str += ` require('./${module.lowName}/topic__${topic.name}').default,\n`;
|
|
169
|
+
});
|
|
170
|
+
str += ' ],';
|
|
171
|
+
}
|
|
164
172
|
str += '})';
|
|
165
173
|
const moduleFilename = `${module.lowName}.js`;
|
|
166
174
|
const modulePath = path.resolve(dir, moduleFilename);
|
|
@@ -6,6 +6,7 @@ import { $Queue } from "../../elements/blocks/queue/queue.schema";
|
|
|
6
6
|
import { Compiler } from '../compiler';
|
|
7
7
|
import { $Block } from "../../elements/blocks/block.schema";
|
|
8
8
|
import { ProgressiveBuildCache } from '../progressive';
|
|
9
|
+
import { $Topic } from "../../elements";
|
|
9
10
|
export type TypeAsObj = string | ({
|
|
10
11
|
[x: string]: TypeAsObj;
|
|
11
12
|
} & {
|
|
@@ -45,7 +46,7 @@ export declare abstract class Element<T extends AnyElementSchema> {
|
|
|
45
46
|
__optional?: boolean;
|
|
46
47
|
__or?: TypeAsObj;
|
|
47
48
|
} & Record<string, any>) | "{}";
|
|
48
|
-
static makeIOType(compiler: Compiler, schema: $Job | $Machine | $MachineState | $MachineTransition | $Queue): {
|
|
49
|
+
static makeIOType(compiler: Compiler, schema: $Job | $Machine | $MachineState | $MachineTransition | $Queue | $Topic): {
|
|
49
50
|
input: string;
|
|
50
51
|
output: {};
|
|
51
52
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TopicElement = void 0;
|
|
4
|
+
const element_1 = require("./element");
|
|
5
|
+
const dump_helpers_1 = require("../helpers/dump_helpers");
|
|
6
|
+
class TopicElement extends element_1.Element {
|
|
7
|
+
prepare() {
|
|
8
|
+
this.schema['#authn'] = element_1.Element.Any;
|
|
9
|
+
this.schema['#input'] = element_1.Element.Never;
|
|
10
|
+
this.schema['#output'] = element_1.Element.Any;
|
|
11
|
+
}
|
|
12
|
+
buildType() {
|
|
13
|
+
const { input } = element_1.Element.makeIOType(this.compiler, this.schema);
|
|
14
|
+
const type = dump_helpers_1.DumpHelpers.dumpValueToType(this.schema);
|
|
15
|
+
delete type['output'];
|
|
16
|
+
return {
|
|
17
|
+
'#authn': element_1.Element.makeAuthnType(this.schema.authn),
|
|
18
|
+
'#input': input,
|
|
19
|
+
'#output': input,
|
|
20
|
+
...type,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.TopicElement = TopicElement;
|
package/lib/compiler/module.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { $Module } from "../schema";
|
|
|
13
13
|
import { QueueElement } from './elements/queue.element';
|
|
14
14
|
import { Element } from './elements/element';
|
|
15
15
|
import { CachedElement } from './elements/cached.element';
|
|
16
|
+
import { TopicElement } from './elements/topic.element';
|
|
16
17
|
export declare class CompilerModule {
|
|
17
18
|
compiler: Compiler;
|
|
18
19
|
lowName: string;
|
|
@@ -21,5 +22,5 @@ export declare class CompilerModule {
|
|
|
21
22
|
module: Module<any, $Module>;
|
|
22
23
|
elements: Element<any>[];
|
|
23
24
|
constructor(compiler: Compiler, name: string, path: string, subdir?: string[]);
|
|
24
|
-
buildElementNode(node: ResolvedBuilderNode): Promise<MessageElement | BucketElement | JobElement | ResourceElement | MachineElement | ControllerElement | ConstantsElement | ExternalsElement | QueueElement | CachedElement | undefined>;
|
|
25
|
+
buildElementNode(node: ResolvedBuilderNode): Promise<MessageElement | BucketElement | JobElement | ResourceElement | MachineElement | ControllerElement | ConstantsElement | ExternalsElement | QueueElement | CachedElement | TopicElement | undefined>;
|
|
25
26
|
}
|
package/lib/compiler/module.js
CHANGED
|
@@ -49,6 +49,7 @@ const externals_element_1 = require("./elements/externals.element");
|
|
|
49
49
|
const log_1 = require("../engine/util/log");
|
|
50
50
|
const queue_element_1 = require("./elements/queue.element");
|
|
51
51
|
const cached_element_1 = require("./elements/cached.element");
|
|
52
|
+
const topic_element_1 = require("./elements/topic.element");
|
|
52
53
|
class CompilerModule {
|
|
53
54
|
constructor(compiler, name, path, subdir = []) {
|
|
54
55
|
this.compiler = compiler;
|
|
@@ -124,6 +125,12 @@ class CompilerModule {
|
|
|
124
125
|
this.elements.push(el);
|
|
125
126
|
return el;
|
|
126
127
|
}
|
|
128
|
+
if (node.type === 'topic') {
|
|
129
|
+
const schema = node.schema;
|
|
130
|
+
const el = new topic_element_1.TopicElement(this.compiler, this.lowName, 'topic', [node.filepath], schema, node.dependencies.map(dep => dep.node), undefined, node.bridge);
|
|
131
|
+
this.elements.push(el);
|
|
132
|
+
return el;
|
|
133
|
+
}
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
136
|
exports.CompilerModule = CompilerModule;
|
|
@@ -135,7 +135,7 @@ class DumpStage {
|
|
|
135
135
|
var _a, _b;
|
|
136
136
|
const nesoiPath = this.compiler.config?.nesoiPath ?? 'nesoi';
|
|
137
137
|
const moduleFile = [];
|
|
138
|
-
moduleFile.push(`import { $Module, $Constants, $Bucket, $Message, $Job, $Resource, $Machine, $Controller, $Queue } from '${nesoiPath}/lib/elements';`);
|
|
138
|
+
moduleFile.push(`import { $Module, $Constants, $Bucket, $Message, $Job, $Resource, $Machine, $Controller, $Queue, $Topic } from '${nesoiPath}/lib/elements';`);
|
|
139
139
|
moduleFile.push(`import { NesoiDate } from '${nesoiPath}/lib/engine/data/date';`);
|
|
140
140
|
moduleFile.push(`import { NesoiDatetime } from '${nesoiPath}/lib/engine/data/datetime';`);
|
|
141
141
|
moduleFile.push(`import { NesoiDecimal } from '${nesoiPath}/lib/engine/data/decimal';`);
|
|
@@ -216,6 +216,7 @@ class DumpStage {
|
|
|
216
216
|
resources: {},
|
|
217
217
|
machines: {},
|
|
218
218
|
queues: {},
|
|
219
|
+
topics: {},
|
|
219
220
|
controllers: {},
|
|
220
221
|
};
|
|
221
222
|
// Merge types that currently exist and are found on cache
|
|
@@ -223,7 +224,7 @@ class DumpStage {
|
|
|
223
224
|
if (typeCache) {
|
|
224
225
|
type.externals = typeCache.externals || 'any';
|
|
225
226
|
type.constants = typeCache.constants || 'any';
|
|
226
|
-
for (const eltype of ['buckets', 'messages', 'jobs', 'resources', 'machines', 'queues', 'controllers']) {
|
|
227
|
+
for (const eltype of ['buckets', 'messages', 'jobs', 'resources', 'machines', 'queues', 'topics', 'controllers']) {
|
|
227
228
|
for (const name in typeCache[eltype] || {}) {
|
|
228
229
|
if (name in module.module.schema[eltype]) {
|
|
229
230
|
type[eltype][name] = typeCache[eltype][name];
|
|
@@ -32,6 +32,9 @@ export declare class Treeshake {
|
|
|
32
32
|
static queue(node: BuilderNode): {
|
|
33
33
|
inlines: BuilderNode[];
|
|
34
34
|
};
|
|
35
|
+
static topic(node: BuilderNode): {
|
|
36
|
+
inlines: BuilderNode[];
|
|
37
|
+
};
|
|
35
38
|
/**
|
|
36
39
|
* Scans the module directory, imports the builders and lists
|
|
37
40
|
* all nodes found.
|
|
@@ -208,6 +208,17 @@ class Treeshake {
|
|
|
208
208
|
node.dependencies = this.cleanNodeDependencies(node);
|
|
209
209
|
return { inlines: inlineTreeshake.inlines };
|
|
210
210
|
}
|
|
211
|
+
static topic(node) {
|
|
212
|
+
const builder = node.builder;
|
|
213
|
+
log_1.Log.trace('compiler', 'treeshake', `└ Treeshaking node ${(0, log_1.scopeTag)(builder.$b, node.name)}`);
|
|
214
|
+
const inlineTreeshake = Treeshake.blockInlineNodes(node);
|
|
215
|
+
node.dependencies = [
|
|
216
|
+
...Treeshake.blockIO(node),
|
|
217
|
+
...inlineTreeshake.dependencies
|
|
218
|
+
];
|
|
219
|
+
node.dependencies = this.cleanNodeDependencies(node);
|
|
220
|
+
return { inlines: inlineTreeshake.inlines };
|
|
221
|
+
}
|
|
211
222
|
/* Module */
|
|
212
223
|
/**
|
|
213
224
|
* Scans the module directory, imports the builders and lists
|
|
@@ -374,6 +385,16 @@ class Treeshake {
|
|
|
374
385
|
});
|
|
375
386
|
});
|
|
376
387
|
}
|
|
388
|
+
else if (builder.$b === 'topic') {
|
|
389
|
+
const { inlines } = Treeshake.topic(node);
|
|
390
|
+
inlines.forEach(inline => {
|
|
391
|
+
nodes.push({
|
|
392
|
+
...inline,
|
|
393
|
+
module,
|
|
394
|
+
filepath
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
}
|
|
377
398
|
else {
|
|
378
399
|
throw error_1.NesoiError.Module.UnknownBuilderType({}, filepath, '', builder.$b);
|
|
379
400
|
}
|
|
@@ -2,7 +2,7 @@ import { TypeAsObj } from "../../compiler/elements/element";
|
|
|
2
2
|
import { $Message } from "../entities/message/message.schema";
|
|
3
3
|
import { AnyUsers } from "../../engine/auth/authn";
|
|
4
4
|
import { $Dependency } from "../../engine/dependency";
|
|
5
|
-
export type $BlockType = 'job' | 'resource' | 'machine' | 'queue';
|
|
5
|
+
export type $BlockType = 'job' | 'resource' | 'machine' | 'queue' | 'topic';
|
|
6
6
|
export type $BlockOutput = {
|
|
7
7
|
raw?: TypeAsObj;
|
|
8
8
|
msg?: $Dependency[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { $Module, $Space, ScopedMessage, ScopedMessageName } from "../../../schema";
|
|
2
|
+
import { $Topic } from './topic.schema';
|
|
3
|
+
import { ResolvedBuilderNode } from "../../../engine/dependency";
|
|
4
|
+
import { BlockBuilder } from '../block.builder';
|
|
5
|
+
import { Overlay } from "../../../engine/util/type";
|
|
6
|
+
import { MessageTemplateDef } from "../../entities/message/template/message_template.builder";
|
|
7
|
+
import { $MessageInfer } from "../../entities/message/message.infer";
|
|
8
|
+
import { ModuleTree } from "../../../engine/tree";
|
|
9
|
+
import { $Message } from "../../entities/message/message.schema";
|
|
10
|
+
/**
|
|
11
|
+
* @category Builders
|
|
12
|
+
* @subcategory Block
|
|
13
|
+
*/
|
|
14
|
+
export declare class TopicBuilder<Space extends $Space, Module extends $Module, Topic extends $Topic> extends BlockBuilder<Space, Module, 'topic'> {
|
|
15
|
+
$b: "topic";
|
|
16
|
+
constructor(module: string, name: string);
|
|
17
|
+
authn<U extends keyof Space['authnUsers']>(...providers: U[]): TopicBuilder<Space, Module, Overlay<Topic, {
|
|
18
|
+
"#authn": { [K in U]: Space["authnUsers"][U]; };
|
|
19
|
+
}>>;
|
|
20
|
+
message<Name extends string, Def extends MessageTemplateDef<Space, Module, Name>, FullName extends string = `${Topic['name']}${Name extends '' ? '' : '.'}${Name & string}`, Msg extends $Message = $MessageInfer<FullName, ($: any) => ReturnType<Def>>>(name: Name, def: Def): TopicBuilder<Space, Overlay<Module, {
|
|
21
|
+
messages: Overlay<Module["messages"], { [K in FullName]: Msg; }>;
|
|
22
|
+
}>, Topic>;
|
|
23
|
+
input<MsgName extends ScopedMessageName<Module, Topic['name']>, Msg extends NoInfer<ScopedMessage<Module, Topic['name'], MsgName>>, PreInput extends $Message = Topic['#input']['#raw']['$'] extends string ? Topic['#input'] : never>(...def: MsgName[]): TopicBuilder<Space, Module, Overlay<Topic, {
|
|
24
|
+
"#input": PreInput | Msg;
|
|
25
|
+
"#output": PreInput | Msg;
|
|
26
|
+
}>>;
|
|
27
|
+
static build(node: TopicBuilderNode, tree: ModuleTree, module: $Module): {
|
|
28
|
+
schema: $Topic;
|
|
29
|
+
inlineMessages: Record<string, $Message>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export type AnyTopicBuilder = TopicBuilder<any, any, any>;
|
|
33
|
+
export type TopicBuilderNode = Omit<ResolvedBuilderNode, 'builder'> & {
|
|
34
|
+
builder: AnyTopicBuilder;
|
|
35
|
+
schema?: $Topic;
|
|
36
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TopicBuilder = void 0;
|
|
4
|
+
const topic_schema_1 = require("./topic.schema");
|
|
5
|
+
const block_builder_1 = require("../block.builder");
|
|
6
|
+
const message_builder_1 = require("../../entities/message/message.builder");
|
|
7
|
+
/**
|
|
8
|
+
* @category Builders
|
|
9
|
+
* @subcategory Block
|
|
10
|
+
*/
|
|
11
|
+
class TopicBuilder extends block_builder_1.BlockBuilder {
|
|
12
|
+
constructor(module, name) {
|
|
13
|
+
super(module, 'topic', name);
|
|
14
|
+
this.$b = 'topic';
|
|
15
|
+
}
|
|
16
|
+
/* [Block] */
|
|
17
|
+
authn(...providers) {
|
|
18
|
+
return super.authn(...providers);
|
|
19
|
+
}
|
|
20
|
+
/* [Topic] */
|
|
21
|
+
message(name, def) {
|
|
22
|
+
return super.message(name, def);
|
|
23
|
+
}
|
|
24
|
+
input(...def) {
|
|
25
|
+
return super._input(...def);
|
|
26
|
+
}
|
|
27
|
+
// Build
|
|
28
|
+
static build(node, tree, module) {
|
|
29
|
+
const input = node.builder._inputMsgs;
|
|
30
|
+
node.schema = new topic_schema_1.$Topic(node.builder.module, node.builder.name, node.builder._alias || node.builder.name, node.builder._authn, input, node.builder._output);
|
|
31
|
+
return {
|
|
32
|
+
schema: node.schema,
|
|
33
|
+
inlineMessages: message_builder_1.MessageBuilder.buildInlines(node, tree, module)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.TopicBuilder = TopicBuilder;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { $Module, $Space } from "../../../schema";
|
|
2
|
+
import { $Topic } from './topic.schema';
|
|
3
|
+
import { Module } from "../../../engine/module";
|
|
4
|
+
import { AnyMessage } from "../../entities/message/message";
|
|
5
|
+
import { TrxNode } from "../../../engine/transaction/trx_node";
|
|
6
|
+
import { Block } from '../block';
|
|
7
|
+
export type TopicSubscription = {
|
|
8
|
+
id: string;
|
|
9
|
+
fn: (msg: AnyMessage) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare class Topic<S extends $Space, M extends $Module, $ extends $Topic> extends Block<S, M, $> {
|
|
12
|
+
module: Module<any, M>;
|
|
13
|
+
schema: $;
|
|
14
|
+
private subscriptions;
|
|
15
|
+
constructor(module: Module<any, M>, schema: $);
|
|
16
|
+
protected run(trx: TrxNode<S, M, $['#authn']>, msg: AnyMessage, _ctx?: Record<string, any>): Promise<void>;
|
|
17
|
+
subscribe(trx: TrxNode<S, M, $['#authn']>, fn: (msg: AnyMessage) => void): string;
|
|
18
|
+
unsubscribe(trx: TrxNode<S, M, $['#authn']>, id: string): void;
|
|
19
|
+
}
|
|
20
|
+
export type AnyTopic = Topic<any, any, any>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Topic = void 0;
|
|
4
|
+
const trx_node_1 = require("../../../engine/transaction/trx_node");
|
|
5
|
+
const block_1 = require("../block");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const log_1 = require("../../../engine/util/log");
|
|
8
|
+
class Topic extends block_1.Block {
|
|
9
|
+
constructor(module, schema) {
|
|
10
|
+
super('topic', module, schema);
|
|
11
|
+
this.module = module;
|
|
12
|
+
this.schema = schema;
|
|
13
|
+
this.subscriptions = {};
|
|
14
|
+
}
|
|
15
|
+
// Publish
|
|
16
|
+
async run(trx, msg, _ctx = {}) {
|
|
17
|
+
// Check authentication
|
|
18
|
+
trx_node_1.TrxNode.checkAuthn(trx, this.schema.authn);
|
|
19
|
+
for (const id in this.subscriptions) {
|
|
20
|
+
try {
|
|
21
|
+
this.subscriptions[id].fn(msg);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
log_1.Log.error('topic', this.schema.name, `Subscription ${id} threw an error when executed. Removed.`, { error });
|
|
25
|
+
delete this.subscriptions[id];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
subscribe(trx, fn) {
|
|
30
|
+
// Check authentication
|
|
31
|
+
trx_node_1.TrxNode.checkAuthn(trx, this.schema.authn);
|
|
32
|
+
const id = (0, crypto_1.randomUUID)();
|
|
33
|
+
this.subscriptions[id] = {
|
|
34
|
+
id, fn
|
|
35
|
+
};
|
|
36
|
+
return id;
|
|
37
|
+
}
|
|
38
|
+
unsubscribe(trx, id) {
|
|
39
|
+
// Check authentication
|
|
40
|
+
trx_node_1.TrxNode.checkAuthn(trx, this.schema.authn);
|
|
41
|
+
delete this.subscriptions[id];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.Topic = Topic;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { $Dependency } from "../../../engine/dependency";
|
|
2
|
+
import { $Block, $BlockOutput } from '../block.schema';
|
|
3
|
+
/**
|
|
4
|
+
* @category Schemas
|
|
5
|
+
* @subcategory Block
|
|
6
|
+
*/
|
|
7
|
+
export declare class $Topic extends $Block {
|
|
8
|
+
module: string;
|
|
9
|
+
name: string;
|
|
10
|
+
alias: string;
|
|
11
|
+
authn: string[];
|
|
12
|
+
input: $Dependency[];
|
|
13
|
+
output: $BlockOutput | undefined;
|
|
14
|
+
$t: "topic";
|
|
15
|
+
dependencies: $Dependency[];
|
|
16
|
+
constructor(module: string, name: string, alias: string, authn: string[], input: $Dependency[], output: $BlockOutput | undefined);
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.$Topic = void 0;
|
|
4
|
+
const block_schema_1 = require("../block.schema");
|
|
5
|
+
/**
|
|
6
|
+
* @category Schemas
|
|
7
|
+
* @subcategory Block
|
|
8
|
+
*/
|
|
9
|
+
class $Topic extends block_schema_1.$Block {
|
|
10
|
+
constructor(module, name, alias, authn, input, output) {
|
|
11
|
+
super(module, name, alias, authn, input, output);
|
|
12
|
+
this.module = module;
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.alias = alias;
|
|
15
|
+
this.authn = authn;
|
|
16
|
+
this.input = input;
|
|
17
|
+
this.output = output;
|
|
18
|
+
this.$t = 'topic';
|
|
19
|
+
this.dependencies = [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.$Topic = $Topic;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ControllerAdapter } from './controller_adapter';
|
|
2
|
-
import { ControllerEndpoint } from '../controller';
|
|
3
|
-
import { $ControllerDomain, $ControllerEndpoint, $ControllerGroup } from '../controller.schema';
|
|
2
|
+
import { ControllerEndpoint, ControllerTopic } from '../controller';
|
|
3
|
+
import { $ControllerDomain, $ControllerEndpoint, $ControllerGroup, $ControllerTopic } from '../controller.schema';
|
|
4
4
|
export type ControllerEndpointPath = ($ControllerDomain | $ControllerGroup | $ControllerEndpoint)[];
|
|
5
5
|
/**
|
|
6
6
|
* @category Adapters
|
|
@@ -8,5 +8,7 @@ export type ControllerEndpointPath = ($ControllerDomain | $ControllerGroup | $Co
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class CLIControllerAdapter extends ControllerAdapter {
|
|
10
10
|
endpoints: Record<string, ControllerEndpoint<$ControllerEndpoint>>;
|
|
11
|
+
topics: Record<string, ControllerTopic<$ControllerTopic>>;
|
|
11
12
|
protected makeEndpoint(path: string, schema: $ControllerEndpoint): void;
|
|
13
|
+
protected makeTopic(schema: $ControllerTopic): void;
|
|
12
14
|
}
|
|
@@ -12,10 +12,15 @@ class CLIControllerAdapter extends controller_adapter_1.ControllerAdapter {
|
|
|
12
12
|
constructor() {
|
|
13
13
|
super(...arguments);
|
|
14
14
|
this.endpoints = {};
|
|
15
|
+
this.topics = {};
|
|
15
16
|
}
|
|
16
17
|
makeEndpoint(path, schema) {
|
|
17
18
|
this.endpoints[path] = new controller_1.ControllerEndpoint(schema, this, path);
|
|
18
19
|
log_1.Log.debug('controller', this.schema.name, `Bound endpoint '${path}' to '${schema.target.tag}'`);
|
|
19
20
|
}
|
|
21
|
+
makeTopic(schema) {
|
|
22
|
+
this.topics[schema.name] = new controller_1.ControllerTopic(schema, this, schema.name);
|
|
23
|
+
log_1.Log.debug('controller', this.schema.name, `Bound topic '${schema.name}'`);
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
exports.CLIControllerAdapter = CLIControllerAdapter;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyTrxNode } from "../../../../engine/transaction/trx_node";
|
|
2
|
-
import { $Controller, $ControllerDomain, $ControllerEndpoint, $ControllerGroup } from '../controller.schema';
|
|
2
|
+
import { $Controller, $ControllerDomain, $ControllerEndpoint, $ControllerGroup, $ControllerTopic } from '../controller.schema';
|
|
3
3
|
import { AnyDaemon } from "../../../../engine/daemon";
|
|
4
4
|
import { AuthnRequest } from "../../../../engine/auth/authn";
|
|
5
5
|
import { $Module } from "../../..";
|
|
@@ -16,6 +16,7 @@ export declare abstract class ControllerAdapter {
|
|
|
16
16
|
trx(fn: (trx: AnyTrxNode) => Promise<any>, authn?: AuthnRequest<any>): Promise<import("../../../../engine/transaction/trx").TrxStatus<any>>;
|
|
17
17
|
bind(daemon: AnyDaemon): void;
|
|
18
18
|
protected abstract makeEndpoint(path: string, schema: $ControllerEndpoint): void;
|
|
19
|
+
protected abstract makeTopic(schema: $ControllerTopic): void;
|
|
19
20
|
protected makeGroup(group: $ControllerGroup, root?: ControllerEndpointPath): void;
|
|
20
21
|
protected makePath(schema: $Controller, path: ControllerEndpointPath): string;
|
|
21
22
|
}
|
|
@@ -31,6 +31,10 @@ class ControllerAdapter {
|
|
|
31
31
|
const domain = this.schema.domains[d];
|
|
32
32
|
this.makeGroup(domain, [domain]);
|
|
33
33
|
}
|
|
34
|
+
for (const t in this.schema.topics) {
|
|
35
|
+
const topic = this.schema.topics[t];
|
|
36
|
+
this.makeTopic(topic);
|
|
37
|
+
}
|
|
34
38
|
}
|
|
35
39
|
makeGroup(group, root = []) {
|
|
36
40
|
for (const e in group.endpoints) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { $Module, $Space } from "../../../schema";
|
|
2
|
-
import { $Controller, $ControllerDomain, $ControllerEndpoint, $ControllerGroup } from './controller.schema';
|
|
2
|
+
import { $Controller, $ControllerDomain, $ControllerEndpoint, $ControllerGroup, $ControllerTopic } from './controller.schema';
|
|
3
3
|
import { $Message } from "../../entities/message/message.schema";
|
|
4
4
|
import { $Dependency, ResolvedBuilderNode } from "../../../engine/dependency";
|
|
5
|
+
import { $Topic } from "../../blocks/topic/topic.schema";
|
|
5
6
|
type JobsSupportingMsg<M extends $Module, Msg extends $Message> = {
|
|
6
7
|
[J in keyof M['jobs']]: Msg extends M['jobs'][J]['#input'] ? J : never;
|
|
7
8
|
}[keyof M['jobs']];
|
|
@@ -34,6 +35,23 @@ export declare class ControllerEndpointBuilder<S extends $Space, M extends $Modu
|
|
|
34
35
|
toMachine(machine: MachinesSupportingMsg<M, Msg>): this;
|
|
35
36
|
static build(builder: ControllerEndpointBuilder<any, any>): $ControllerEndpoint;
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @category Builders
|
|
40
|
+
* @subcategory Edge
|
|
41
|
+
*/
|
|
42
|
+
export declare class ControllerTopicBuilder<S extends $Space, Topic extends $Topic> {
|
|
43
|
+
private module;
|
|
44
|
+
private topic;
|
|
45
|
+
private _authn;
|
|
46
|
+
private _alias?;
|
|
47
|
+
private _tags;
|
|
48
|
+
private _msgs;
|
|
49
|
+
constructor(module: string, topic: $Dependency, _authn?: string[]);
|
|
50
|
+
as(alias: string): this;
|
|
51
|
+
authn<U extends keyof S['authnUsers']>(providers: U | U[]): this;
|
|
52
|
+
msg(name: Topic['#input']['#raw']['$']): this;
|
|
53
|
+
static build(builder: ControllerTopicBuilder<any, any>): $ControllerTopic;
|
|
54
|
+
}
|
|
37
55
|
/**
|
|
38
56
|
* @category Builders
|
|
39
57
|
* @subcategory Edge
|
|
@@ -74,16 +92,20 @@ export declare class ControllerBuilder<S extends $Space, M extends $Module> {
|
|
|
74
92
|
private _alias?;
|
|
75
93
|
private _authn;
|
|
76
94
|
private domains;
|
|
95
|
+
protected topics: Record<string, ControllerTopicBuilder<any, any>>;
|
|
77
96
|
constructor(module: string, name: string);
|
|
78
97
|
as(alias: string): this;
|
|
79
98
|
authn<U extends keyof S['authnUsers']>(providers: U | U[]): this;
|
|
80
99
|
domain(name: string, $: ControllerDomainDef<S, M>): this;
|
|
100
|
+
topic<T extends keyof M['topics']>(name: T, $: ControllerTopicDef<S, M['topics'][T]>): this;
|
|
81
101
|
static build(node: ControllerBuilderNode): $Controller;
|
|
82
102
|
static buildInput(group: $ControllerGroup): $Dependency[];
|
|
83
103
|
static buildDomains(builders: Record<string, ControllerDomainBuilder<any, any>>): Record<string, $ControllerDomain>;
|
|
104
|
+
static buildTopics(builders: Record<string, ControllerTopicBuilder<any, any>>): Record<string, $ControllerTopic>;
|
|
84
105
|
}
|
|
85
106
|
type ControllerEndpointDef<S extends $Space, M extends $Module> = ($: ControllerEndpointBuilder<S, M>) => ControllerEndpointBuilder<S, M, any>;
|
|
86
107
|
type ControllerGroupDef<S extends $Space, M extends $Module> = ($: ControllerGroupBuilder<S, M>) => ControllerGroupBuilder<S, M>;
|
|
108
|
+
type ControllerTopicDef<S extends $Space, T extends $Topic> = ($: ControllerTopicBuilder<S, T>) => ControllerTopicBuilder<S, T>;
|
|
87
109
|
type ControllerDomainDef<S extends $Space, M extends $Module> = ($: ControllerDomainBuilder<S, M>) => ControllerDomainBuilder<S, M>;
|
|
88
110
|
export type AnyControllerBuilder = ControllerBuilder<any, any>;
|
|
89
111
|
export type ControllerBuilderNode = Omit<ResolvedBuilderNode, 'builder'> & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ControllerBuilder = exports.ControllerDomainBuilder = exports.ControllerGroupBuilder = exports.ControllerEndpointBuilder = void 0;
|
|
3
|
+
exports.ControllerBuilder = exports.ControllerDomainBuilder = exports.ControllerGroupBuilder = exports.ControllerTopicBuilder = exports.ControllerEndpointBuilder = void 0;
|
|
4
4
|
const controller_schema_1 = require("./controller.schema");
|
|
5
5
|
const dependency_1 = require("../../../engine/dependency");
|
|
6
6
|
/**
|
|
@@ -54,6 +54,38 @@ class ControllerEndpointBuilder {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
exports.ControllerEndpointBuilder = ControllerEndpointBuilder;
|
|
57
|
+
/**
|
|
58
|
+
* @category Builders
|
|
59
|
+
* @subcategory Edge
|
|
60
|
+
*/
|
|
61
|
+
class ControllerTopicBuilder {
|
|
62
|
+
constructor(module, topic, _authn = []) {
|
|
63
|
+
this.module = module;
|
|
64
|
+
this.topic = topic;
|
|
65
|
+
this._authn = _authn;
|
|
66
|
+
this._tags = [];
|
|
67
|
+
this._msgs = [];
|
|
68
|
+
}
|
|
69
|
+
as(alias) {
|
|
70
|
+
this._alias = alias;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
authn(providers) {
|
|
74
|
+
if (!Array.isArray(providers)) {
|
|
75
|
+
providers = [providers];
|
|
76
|
+
}
|
|
77
|
+
this._authn = providers;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
msg(name) {
|
|
81
|
+
this._msgs.push(new dependency_1.$Dependency(this.module, 'message', name));
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
static build(builder) {
|
|
85
|
+
return new controller_schema_1.$ControllerTopic(builder.topic.name, builder._alias || builder.topic.name, builder._authn, builder._tags, builder._msgs, builder.topic);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.ControllerTopicBuilder = ControllerTopicBuilder;
|
|
57
89
|
/**
|
|
58
90
|
* @category Builders
|
|
59
91
|
* @subcategory Edge
|
|
@@ -142,6 +174,7 @@ class ControllerBuilder {
|
|
|
142
174
|
this.$b = 'controller';
|
|
143
175
|
this._authn = [];
|
|
144
176
|
this.domains = {};
|
|
177
|
+
this.topics = {};
|
|
145
178
|
}
|
|
146
179
|
as(alias) {
|
|
147
180
|
this._alias = alias;
|
|
@@ -161,13 +194,21 @@ class ControllerBuilder {
|
|
|
161
194
|
this.domains[name + '.' + version] = builder;
|
|
162
195
|
return this;
|
|
163
196
|
}
|
|
197
|
+
topic(name, $) {
|
|
198
|
+
const topic = new dependency_1.$Dependency(this.module, 'topic', name);
|
|
199
|
+
const builder = new ControllerTopicBuilder(this.module, topic, this._authn);
|
|
200
|
+
$(builder);
|
|
201
|
+
this.topics[name] = builder;
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
164
204
|
// Build
|
|
165
205
|
static build(node) {
|
|
166
206
|
const domains = this.buildDomains(node.builder.domains);
|
|
207
|
+
const topics = this.buildTopics(node.builder.topics);
|
|
167
208
|
const input = Object.values(domains)
|
|
168
209
|
.map(domain => this.buildInput(domain))
|
|
169
210
|
.flat();
|
|
170
|
-
node.schema = new controller_schema_1.$Controller(node.module, node.builder.name, node.builder._alias || node.builder.name, node.builder._authn, input, domains);
|
|
211
|
+
node.schema = new controller_schema_1.$Controller(node.module, node.builder.name, node.builder._alias || node.builder.name, node.builder._authn, input, domains, topics);
|
|
171
212
|
return node.schema;
|
|
172
213
|
}
|
|
173
214
|
static buildInput(group) {
|
|
@@ -190,5 +231,13 @@ class ControllerBuilder {
|
|
|
190
231
|
}
|
|
191
232
|
return domains;
|
|
192
233
|
}
|
|
234
|
+
static buildTopics(builders) {
|
|
235
|
+
const topics = {};
|
|
236
|
+
for (const g in builders) {
|
|
237
|
+
const topic = builders[g];
|
|
238
|
+
topics[g] = ControllerTopicBuilder.build(topic);
|
|
239
|
+
}
|
|
240
|
+
return topics;
|
|
241
|
+
}
|
|
193
242
|
}
|
|
194
243
|
exports.ControllerBuilder = ControllerBuilder;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { $Module, $Space } from "../../../schema";
|
|
2
2
|
import { Module } from "../../../engine/module";
|
|
3
|
-
import { $Controller, $ControllerEndpoint } from './controller.schema';
|
|
3
|
+
import { $Controller, $ControllerEndpoint, $ControllerTopic } from './controller.schema';
|
|
4
4
|
import { ControllerAdapter } from './adapters/controller_adapter';
|
|
5
5
|
import { ControllerConfig } from './controller.config';
|
|
6
6
|
import { AnyDaemon } from "../../../engine/daemon";
|
|
7
7
|
import { AuthnRequest } from "../../../engine/auth/authn";
|
|
8
|
+
import { AnyMessage } from "../../entities/message/message";
|
|
8
9
|
/**
|
|
9
10
|
* @category Elements
|
|
10
11
|
* @subcategory Edge
|
|
@@ -16,6 +17,18 @@ export declare class ControllerEndpoint<$ extends $ControllerEndpoint> {
|
|
|
16
17
|
constructor(schema: $, adapter: ControllerAdapter, path: string);
|
|
17
18
|
invoke(data: Record<string, any>, authn?: AuthnRequest<any>): Promise<import("../../../engine/transaction/trx").TrxStatus<any>>;
|
|
18
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @category Elements
|
|
22
|
+
* @subcategory Edge
|
|
23
|
+
*/
|
|
24
|
+
export declare class ControllerTopic<$ extends $ControllerTopic> {
|
|
25
|
+
schema: $;
|
|
26
|
+
adapter: ControllerAdapter;
|
|
27
|
+
path: string;
|
|
28
|
+
constructor(schema: $, adapter: ControllerAdapter, path: string);
|
|
29
|
+
subscribe(fn: (msg: AnyMessage) => void, authn?: AuthnRequest<any>): Promise<string>;
|
|
30
|
+
unsubscribe(id: string): Promise<string>;
|
|
31
|
+
}
|
|
19
32
|
export declare class Controller<S extends $Space, M extends $Module, $ extends $Controller> {
|
|
20
33
|
schema: $;
|
|
21
34
|
config?: ControllerConfig<M, $, any> | undefined;
|