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