1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const metadataReading_1 = require("./internal/metadata/metadataReading");
|
4 | const string_1 = require("./internal/util/string");
|
5 | const scan_1 = require("./scan");
|
6 | const constructionUtils_1 = require("./util/constructionUtils");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function commandHandlerFrom(h, factory, name = h.name || `Command${string_1.generateHash(h.toString())}`, description = name, intent = [], tags = []) {
|
19 | const handler = new FunctionWrappingCommandHandler(name, description, h, factory, tags, intent);
|
20 | scan_1.registerCommand(handler);
|
21 | return handler;
|
22 | }
|
23 | exports.commandHandlerFrom = commandHandlerFrom;
|
24 | class FunctionWrappingCommandHandler {
|
25 | constructor(name, description, h, parametersFactory,
|
26 | // tslint:disable-next-line:variable-name
|
27 | _tags = [],
|
28 | // tslint:disable-next-line:variable-name
|
29 | _intent = []) {
|
30 | this.name = name;
|
31 | this.description = description;
|
32 | this.h = h;
|
33 | this.parametersFactory = parametersFactory;
|
34 | this._tags = _tags;
|
35 | this._intent = _intent;
|
36 | const newParamInstance = this.freshParametersInstance();
|
37 | const md = metadataReading_1.metadataFromInstance(newParamInstance);
|
38 | this.parameters = md.parameters;
|
39 | this.mapped_parameters = md.mapped_parameters;
|
40 | this.values = md.values;
|
41 | this.secrets = md.secrets;
|
42 | this.intent = string_1.toStringArray(_intent);
|
43 | this.tags = string_1.toStringArray(_tags).map(t => ({ name: t, description: t }));
|
44 | }
|
45 | freshParametersInstance() {
|
46 | return constructionUtils_1.toFactory(this.parametersFactory)();
|
47 | }
|
48 | handle(ctx, params) {
|
49 | return this.h(ctx, params);
|
50 | }
|
51 | }
|
52 |
|
\ | No newline at end of file |