@conduitplatform/module-tools 0.16.5 → 0.16.6
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/dist/classes/ConduitServiceModule.d.ts +1 -1
- package/dist/index.cjs +1776 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.esm.js +1749 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +24 -5
- package/dist/ManagedModule.js +0 -221
- package/dist/ManagedModule.js.map +0 -1
- package/dist/classes/ConduitActiveSchema.js +0 -44
- package/dist/classes/ConduitActiveSchema.js.map +0 -1
- package/dist/classes/ConduitServiceModule.js +0 -110
- package/dist/classes/ConduitServiceModule.js.map +0 -1
- package/dist/classes/ConfigController.js +0 -16
- package/dist/classes/ConfigController.js.map +0 -1
- package/dist/classes/GrpcServer.js +0 -121
- package/dist/classes/GrpcServer.js.map +0 -1
- package/dist/classes/index.js +0 -5
- package/dist/classes/index.js.map +0 -1
- package/dist/helpers/GrpcHelper.js +0 -38
- package/dist/helpers/GrpcHelper.js.map +0 -1
- package/dist/helpers/GrpcToParsedRouterRequest.js +0 -15
- package/dist/helpers/GrpcToParsedRouterRequest.js.map +0 -1
- package/dist/helpers/TypeHelpers.js +0 -79
- package/dist/helpers/TypeHelpers.js.map +0 -1
- package/dist/helpers/index.js +0 -5
- package/dist/helpers/index.js.map +0 -1
- package/dist/helpers/wrapGrpcFunctions.js +0 -48
- package/dist/helpers/wrapGrpcFunctions.js.map +0 -1
- package/dist/index.js +0 -7
- package/dist/index.js.map +0 -1
- package/dist/interfaces/ConduitService.js +0 -2
- package/dist/interfaces/ConduitService.js.map +0 -1
- package/dist/interfaces/ModuleLifecycleStage.js +0 -9
- package/dist/interfaces/ModuleLifecycleStage.js.map +0 -1
- package/dist/interfaces/index.js +0 -3
- package/dist/interfaces/index.js.map +0 -1
- package/dist/logging/index.js +0 -124
- package/dist/logging/index.js.map +0 -1
- package/dist/metrics/MetricsServer.js +0 -42
- package/dist/metrics/MetricsServer.js.map +0 -1
- package/dist/metrics/clientMiddleware.js +0 -120
- package/dist/metrics/clientMiddleware.js.map +0 -1
- package/dist/metrics/config/defaults.js +0 -91
- package/dist/metrics/config/defaults.js.map +0 -1
- package/dist/metrics/index.js +0 -109
- package/dist/metrics/index.js.map +0 -1
- package/dist/routing/ProxyRouteBuilder.js +0 -74
- package/dist/routing/ProxyRouteBuilder.js.map +0 -1
- package/dist/routing/RouteBuilder.js +0 -100
- package/dist/routing/RouteBuilder.js.map +0 -1
- package/dist/routing/RoutingController.js +0 -21
- package/dist/routing/RoutingController.js.map +0 -1
- package/dist/routing/RoutingManager.js +0 -140
- package/dist/routing/RoutingManager.js.map +0 -1
- package/dist/routing/RoutingUtilities.js +0 -9
- package/dist/routing/RoutingUtilities.js.map +0 -1
- package/dist/routing/index.js +0 -6
- package/dist/routing/index.js.map +0 -1
- package/dist/routing/wrapRouterFunctions.js +0 -120
- package/dist/routing/wrapRouterFunctions.js.map +0 -1
- package/dist/utilities/convictConfigParser.js +0 -14
- package/dist/utilities/convictConfigParser.js.map +0 -1
- package/dist/utilities/index.js +0 -4
- package/dist/utilities/index.js.map +0 -1
- package/dist/utilities/initializeSdk.js +0 -35
- package/dist/utilities/initializeSdk.js.map +0 -1
- package/dist/utilities/linearBackoffTimeout.js +0 -57
- package/dist/utilities/linearBackoffTimeout.js.map +0 -1
- package/dist/utilities/merge.js +0 -11
- package/dist/utilities/merge.js.map +0 -1
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// Forked from nice-grpc-prometheus
|
|
2
|
-
import { isAbortError } from 'abort-controller-x';
|
|
3
|
-
import { ClientError, Status, } from 'nice-grpc-common';
|
|
4
|
-
import { Counter, exponentialBuckets, Histogram, Registry } from 'prom-client';
|
|
5
|
-
const registry = new Registry();
|
|
6
|
-
const typeLabel = 'grpc_type';
|
|
7
|
-
const serviceLabel = 'grpc_service';
|
|
8
|
-
const methodLabel = 'grpc_method';
|
|
9
|
-
const pathLabel = 'grpc_path';
|
|
10
|
-
const codeLabel = 'grpc_code';
|
|
11
|
-
/**
|
|
12
|
-
* 1ms, 4ms, 16ms, ..., ~1 hour in seconds
|
|
13
|
-
*/
|
|
14
|
-
const latencySecondsBuckets = exponentialBuckets(0.001, 4, 12);
|
|
15
|
-
function getLabels(method) {
|
|
16
|
-
const callType = method.requestStream
|
|
17
|
-
? method.responseStream
|
|
18
|
-
? 'bidi_stream'
|
|
19
|
-
: 'client_stream'
|
|
20
|
-
: method.responseStream
|
|
21
|
-
? 'server_stream'
|
|
22
|
-
: 'unary';
|
|
23
|
-
const { path } = method;
|
|
24
|
-
const [serviceName, methodName] = path.split('/').slice(1);
|
|
25
|
-
return {
|
|
26
|
-
[typeLabel]: callType,
|
|
27
|
-
[serviceLabel]: serviceName,
|
|
28
|
-
[methodLabel]: methodName,
|
|
29
|
-
[pathLabel]: path,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
async function* incrementStreamMessagesCounter(iterable, counter) {
|
|
33
|
-
for await (const item of iterable) {
|
|
34
|
-
counter.inc();
|
|
35
|
-
yield item;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const clientStartedMetric = new Counter({
|
|
39
|
-
registers: [registry],
|
|
40
|
-
name: 'conduit_grpc_client_started_total',
|
|
41
|
-
help: 'Total number of RPCs started on the client.',
|
|
42
|
-
labelNames: [typeLabel, serviceLabel, methodLabel, pathLabel],
|
|
43
|
-
});
|
|
44
|
-
const clientHandledMetric = new Counter({
|
|
45
|
-
registers: [registry],
|
|
46
|
-
name: 'conduit_grpc_client_handled_total',
|
|
47
|
-
help: 'Total number of RPCs completed on the client, regardless of success or failure.',
|
|
48
|
-
labelNames: [typeLabel, serviceLabel, methodLabel, pathLabel, codeLabel],
|
|
49
|
-
});
|
|
50
|
-
const clientStreamMsgReceivedMetric = new Counter({
|
|
51
|
-
registers: [registry],
|
|
52
|
-
name: 'conduit_grpc_client_msg_received_total',
|
|
53
|
-
help: 'Total number of RPC stream messages received by the client.',
|
|
54
|
-
labelNames: [typeLabel, serviceLabel, methodLabel, pathLabel],
|
|
55
|
-
});
|
|
56
|
-
const clientStreamMsgSentMetric = new Counter({
|
|
57
|
-
registers: [registry],
|
|
58
|
-
name: 'conduit_grpc_client_msg_sent_total',
|
|
59
|
-
help: 'Total number of gRPC stream messages sent by the client.',
|
|
60
|
-
labelNames: [typeLabel, serviceLabel, methodLabel, pathLabel],
|
|
61
|
-
});
|
|
62
|
-
const clientHandlingSecondsMetric = new Histogram({
|
|
63
|
-
registers: [registry],
|
|
64
|
-
name: 'grpc_client_handling_seconds',
|
|
65
|
-
help: 'Histogram of response latency (seconds) of the gRPC until it is finished by the application.',
|
|
66
|
-
labelNames: [typeLabel, serviceLabel, methodLabel, pathLabel, codeLabel],
|
|
67
|
-
buckets: latencySecondsBuckets,
|
|
68
|
-
});
|
|
69
|
-
export function clientMiddleware() {
|
|
70
|
-
return async function* prometheusClientMiddlewareGenerator(call, options) {
|
|
71
|
-
const labels = getLabels(call.method);
|
|
72
|
-
clientStartedMetric.inc(labels);
|
|
73
|
-
const stopTimer = clientHandlingSecondsMetric.startTimer(labels);
|
|
74
|
-
let settled = false;
|
|
75
|
-
let status = Status.OK;
|
|
76
|
-
try {
|
|
77
|
-
let request;
|
|
78
|
-
if (!call.requestStream) {
|
|
79
|
-
request = call.request;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
request = incrementStreamMessagesCounter(call.request, clientStreamMsgSentMetric.labels(labels));
|
|
83
|
-
}
|
|
84
|
-
if (!call.responseStream) {
|
|
85
|
-
const response = yield* call.next(request, options);
|
|
86
|
-
settled = true;
|
|
87
|
-
return response;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
yield* incrementStreamMessagesCounter(call.next(request, options), clientStreamMsgReceivedMetric.labels(labels));
|
|
91
|
-
settled = true;
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
settled = true;
|
|
97
|
-
if (err instanceof ClientError) {
|
|
98
|
-
status = err.code;
|
|
99
|
-
}
|
|
100
|
-
else if (isAbortError(err)) {
|
|
101
|
-
status = Status.ABORTED;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
status = Status.UNKNOWN;
|
|
105
|
-
}
|
|
106
|
-
throw err;
|
|
107
|
-
}
|
|
108
|
-
finally {
|
|
109
|
-
if (!settled) {
|
|
110
|
-
status = Status.CANCELLED;
|
|
111
|
-
}
|
|
112
|
-
stopTimer({ [codeLabel]: Status[status] });
|
|
113
|
-
clientHandledMetric.inc({
|
|
114
|
-
...labels,
|
|
115
|
-
[codeLabel]: Status[status],
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=clientMiddleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clientMiddleware.js","sourceRoot":"","sources":["../../src/metrics/clientMiddleware.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAEL,WAAW,EAIX,MAAM,GACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE/E,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;AAEhC,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,YAAY,GAAG,cAAc,CAAC;AACpC,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B;;GAEG;AACH,MAAM,qBAAqB,GAAG,kBAAkB,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AAE/D,SAAS,SAAS,CAAC,MAAwB;IACzC,MAAM,QAAQ,GAAG,M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AC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { MetricType } from '@conduitplatform/grpc-sdk';
|
|
2
|
-
export default {
|
|
3
|
-
internalGrpcRequests: {
|
|
4
|
-
type: MetricType.Counter,
|
|
5
|
-
config: {
|
|
6
|
-
name: 'internal_grpc_requests_total',
|
|
7
|
-
help: "Tracks the total number of Conduit's internal gRPC requests",
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
clientGrpcRequests: {
|
|
11
|
-
type: MetricType.Counter,
|
|
12
|
-
config: {
|
|
13
|
-
name: 'client_grpc_requests_total',
|
|
14
|
-
help: 'Tracks the total number of the client gRPC requests',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
adminGrpcRequests: {
|
|
18
|
-
type: MetricType.Counter,
|
|
19
|
-
config: {
|
|
20
|
-
name: 'admin_grpc_requests_total',
|
|
21
|
-
help: 'Tracks the total number of the admin gRPC requests',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
clientGrpcErrors: {
|
|
25
|
-
type: MetricType.Counter,
|
|
26
|
-
config: {
|
|
27
|
-
name: 'client_grpc_errors_total',
|
|
28
|
-
help: 'Tracks the total number of client grpc errors',
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
adminGrpcErrors: {
|
|
32
|
-
type: MetricType.Counter,
|
|
33
|
-
config: {
|
|
34
|
-
name: 'admin_grpc_errors_total',
|
|
35
|
-
help: 'Tracks the total number of admin grpc errors',
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
moduleHealthState: {
|
|
39
|
-
type: MetricType.Gauge,
|
|
40
|
-
config: {
|
|
41
|
-
name: 'module_health_state',
|
|
42
|
-
help: 'Tracks the health state of the module',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
grpcRequestLatency: {
|
|
46
|
-
type: MetricType.Gauge,
|
|
47
|
-
config: {
|
|
48
|
-
name: 'grpc_request_latency_seconds',
|
|
49
|
-
help: 'Tracks the latency of grpc requests in seconds',
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
adminGrpcRequestLatency: {
|
|
53
|
-
type: MetricType.Gauge,
|
|
54
|
-
config: {
|
|
55
|
-
name: 'admin_grpc_request_latency_seconds',
|
|
56
|
-
help: 'Tracks the latency of admin grpc requests in seconds',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
clientGrpcRequestLatency: {
|
|
60
|
-
type: MetricType.Gauge,
|
|
61
|
-
config: {
|
|
62
|
-
name: 'client_grpc_request_latency_seconds',
|
|
63
|
-
help: 'Tracks the latency of client grpc requests in seconds',
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
grpcResponseStatuses: {
|
|
67
|
-
type: MetricType.Counter,
|
|
68
|
-
config: {
|
|
69
|
-
name: 'grpc_response_statuses_total',
|
|
70
|
-
help: 'Tracks the total number of grpc response codes',
|
|
71
|
-
labelNames: ['success'],
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
adminGrpcResponseStatuses: {
|
|
75
|
-
type: MetricType.Counter,
|
|
76
|
-
config: {
|
|
77
|
-
name: 'admin_grpc_response_statuses_total',
|
|
78
|
-
help: 'Tracks the total number of admin grpc response codes',
|
|
79
|
-
labelNames: ['success'],
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
clientGrpcResponseStatuses: {
|
|
83
|
-
type: MetricType.Counter,
|
|
84
|
-
config: {
|
|
85
|
-
name: 'client_grpc_response_statuses_total',
|
|
86
|
-
help: 'Tracks the total number of client grpc response codes',
|
|
87
|
-
labelNames: ['success'],
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
//# sourceMappingURL=defaults.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../src/metrics/config/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MA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AI,EAAE,uDAAuD;SAC9D;KACF;IACD,oBAAoB,EAAE;QACpB,IAAI,EAAE,UAAU,CAAC,OAAO;QACxB,MAAM,EAAE;YACN,IAAI,EAAE,8BAA8B;YACpC,IAAI,EAAE,gDAAgD;YACtD,UAAU,EAAE,CAAC,SAAS,CAAC;SACxB;KACF;IACD,yBAAyB,EAAE;QACzB,IAAI,EAAE,UAAU,CAAC,OAAO;QACxB,MAAM,EAAE;YACN,IAAI,EAAE,oCAAoC;YAC1C,IAAI,EAAE,sDAAsD;YAC5D,UAAU,EAAE,CAAC,SAAS,CAAC;SACxB;KACF;IACD,0BAA0B,EAAE;QAC1B,IAAI,EAAE,UAAU,CAAC,OAAO;QACxB,MAAM,EAAE;YACN,IAAI,EAAE,qCAAqC;YAC3C,IAAI,EAAE,wDAAwD;YAC9D,UAAU,EAAE,CAAC,SAAS,CAAC;SACxB;KACF;CACF,CAAC"}
|
package/dist/metrics/index.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { collectDefaultMetrics, Counter, Gauge, Histogram, Registry, Summary, } from 'prom-client';
|
|
2
|
-
import { MetricsServer } from './MetricsServer.js';
|
|
3
|
-
import defaultMetrics from './config/defaults.js';
|
|
4
|
-
import { MetricType } from '@conduitplatform/grpc-sdk';
|
|
5
|
-
export class ConduitMetrics {
|
|
6
|
-
constructor(moduleName, instance) {
|
|
7
|
-
this.moduleName = moduleName;
|
|
8
|
-
this.instance = instance;
|
|
9
|
-
this._registry = new Registry();
|
|
10
|
-
this._registry.setDefaultLabels({
|
|
11
|
-
module_name: this.moduleName,
|
|
12
|
-
module_instance: this.instance,
|
|
13
|
-
});
|
|
14
|
-
this.collectDefaultMetrics();
|
|
15
|
-
this._httpServer = new MetricsServer(moduleName, instance, this._registry);
|
|
16
|
-
this._httpServer.initialize();
|
|
17
|
-
}
|
|
18
|
-
initializeDefaultMetrics() {
|
|
19
|
-
for (const metric of Object.values(defaultMetrics)) {
|
|
20
|
-
this.registerMetric(metric.type, metric.config);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
registerMetric(type, config) {
|
|
24
|
-
if (this.getMetric(config.name))
|
|
25
|
-
return;
|
|
26
|
-
const metricConfig = JSON.parse(JSON.stringify(config));
|
|
27
|
-
metricConfig.name = this.addPrefix(config.name);
|
|
28
|
-
switch (type) {
|
|
29
|
-
case MetricType.Counter:
|
|
30
|
-
this.createCounter(metricConfig);
|
|
31
|
-
break;
|
|
32
|
-
case MetricType.Gauge:
|
|
33
|
-
this.createGauge(metricConfig);
|
|
34
|
-
break;
|
|
35
|
-
case MetricType.Histogram:
|
|
36
|
-
this.createHistogram(metricConfig);
|
|
37
|
-
break;
|
|
38
|
-
case MetricType.Summary:
|
|
39
|
-
this.createSummary(metricConfig);
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
collectDefaultMetrics() {
|
|
44
|
-
collectDefaultMetrics({
|
|
45
|
-
register: this._registry,
|
|
46
|
-
prefix: 'conduit_',
|
|
47
|
-
// probably not needed
|
|
48
|
-
labels: {
|
|
49
|
-
module_name: this.moduleName,
|
|
50
|
-
instance_instance: this.instance,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
createCounter(config) {
|
|
55
|
-
return new Counter({ ...config, registers: [this._registry] });
|
|
56
|
-
}
|
|
57
|
-
createSummary(config) {
|
|
58
|
-
return new Summary({ ...config, registers: [this._registry] });
|
|
59
|
-
}
|
|
60
|
-
createHistogram(config) {
|
|
61
|
-
return new Histogram({ ...config, registers: [this._registry] });
|
|
62
|
-
}
|
|
63
|
-
createGauge(config) {
|
|
64
|
-
return new Gauge({ ...config, registers: [this._registry] });
|
|
65
|
-
}
|
|
66
|
-
getMetric(name) {
|
|
67
|
-
return this._registry.getSingleMetric(this.addPrefix(name));
|
|
68
|
-
}
|
|
69
|
-
increment(metric, increment = 1, labels) {
|
|
70
|
-
const metricInstance = this._registry.getSingleMetric(this.addPrefix(metric));
|
|
71
|
-
if (!(metricInstance instanceof Counter) && !(metricInstance instanceof Gauge)) {
|
|
72
|
-
throw new Error(`Metric ${metric} is not an incrementable metric`);
|
|
73
|
-
}
|
|
74
|
-
return labels
|
|
75
|
-
? metricInstance.labels({ ...labels }).inc(increment)
|
|
76
|
-
: metricInstance.inc(increment);
|
|
77
|
-
}
|
|
78
|
-
decrement(metric, decrement = 1, labels) {
|
|
79
|
-
const metricInstance = this._registry.getSingleMetric(this.addPrefix(metric));
|
|
80
|
-
if (!(metricInstance instanceof Gauge)) {
|
|
81
|
-
throw new Error(`Metric ${metric} is not a decrementable metric`);
|
|
82
|
-
}
|
|
83
|
-
return labels
|
|
84
|
-
? metricInstance.labels({ ...labels }).dec(decrement)
|
|
85
|
-
: metricInstance.dec(decrement);
|
|
86
|
-
}
|
|
87
|
-
set(metric, value, labels) {
|
|
88
|
-
const metricInstance = this._registry.getSingleMetric(this.addPrefix(metric));
|
|
89
|
-
if (!(metricInstance instanceof Gauge)) {
|
|
90
|
-
throw new Error(`Metric ${metric} is not a Gauge`);
|
|
91
|
-
}
|
|
92
|
-
return labels
|
|
93
|
-
? metricInstance.labels({ ...labels }).set(value)
|
|
94
|
-
: metricInstance.set(value);
|
|
95
|
-
}
|
|
96
|
-
observe(metric, value, labels) {
|
|
97
|
-
const metricInstance = this._registry.getSingleMetric(this.addPrefix(metric));
|
|
98
|
-
if (!(metricInstance instanceof Histogram) && !(metricInstance instanceof Summary)) {
|
|
99
|
-
throw new Error(`Metric ${metric} is not a Histogram`);
|
|
100
|
-
}
|
|
101
|
-
return labels
|
|
102
|
-
? metricInstance.labels({ ...labels }).observe(value)
|
|
103
|
-
: metricInstance.observe(value);
|
|
104
|
-
}
|
|
105
|
-
addPrefix(metric) {
|
|
106
|
-
return `conduit_${metric}`;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","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
this.manager = manager;
|
|
4
|
-
this._options = { path: '' };
|
|
5
|
-
this._proxy = { target: '' };
|
|
6
|
-
}
|
|
7
|
-
method(action) {
|
|
8
|
-
this._options.action = action;
|
|
9
|
-
return this;
|
|
10
|
-
}
|
|
11
|
-
path(path) {
|
|
12
|
-
this._options.path = path;
|
|
13
|
-
return this;
|
|
14
|
-
}
|
|
15
|
-
target(target) {
|
|
16
|
-
this._proxy.target = target;
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
options(options) {
|
|
20
|
-
this._options = options;
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
proxy(proxy) {
|
|
24
|
-
this._proxy = proxy;
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
middleware(middleware, allowDuplicates = false) {
|
|
28
|
-
if (!Array.isArray(middleware)) {
|
|
29
|
-
middleware = [middleware];
|
|
30
|
-
}
|
|
31
|
-
if (this._options.middlewares) {
|
|
32
|
-
if (allowDuplicates) {
|
|
33
|
-
this._options.middlewares = this._options.middlewares.concat(middleware);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this._options.middlewares = this._options.middlewares.concat(middleware.filter(mid => { var _a; return ((_a = this._options.middlewares) === null || _a === void 0 ? void 0 : _a.indexOf(mid)) === -1; }));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this._options.middlewares = middleware;
|
|
41
|
-
}
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
add() {
|
|
45
|
-
if (!this.manager)
|
|
46
|
-
throw new Error('Builder not setup with manager');
|
|
47
|
-
if (!this._options.path)
|
|
48
|
-
throw new Error('Cannot build route without path');
|
|
49
|
-
if (!this._proxy.target)
|
|
50
|
-
throw new Error('Cannot build route without target');
|
|
51
|
-
const input = {
|
|
52
|
-
options: this._options,
|
|
53
|
-
proxy: this._proxy,
|
|
54
|
-
};
|
|
55
|
-
this.manager.proxyRoute(input);
|
|
56
|
-
}
|
|
57
|
-
build() {
|
|
58
|
-
if (!this.manager)
|
|
59
|
-
throw new Error('Builder not setup with manager');
|
|
60
|
-
if (!this._options.path)
|
|
61
|
-
throw new Error('Cannot build route without path');
|
|
62
|
-
if (!this._proxy.target)
|
|
63
|
-
throw new Error('Cannot build route without target');
|
|
64
|
-
if (!this._options.action)
|
|
65
|
-
throw new Error('Cannot build route without action');
|
|
66
|
-
return {
|
|
67
|
-
input: {
|
|
68
|
-
options: this._options,
|
|
69
|
-
proxy: this._proxy,
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=ProxyRouteBuilder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyRouteBuilder.js","sourceRoot":"","sources":["../../src/routing/ProxyRouteBuilder.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,iBAAiB;IAI5B,YAA6B,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QAH7C,aAAQ,GAAsB,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QAC3C,WAAM,GAA2B,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAEA,CAAC;IAEzD,MAAM,CAAC,MAAyB;QAC9B,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,IAAY;QACf,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,OAA0B;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,KAA6B;QACjC,IAAI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KAAK,EAAE,IAAI,CAAC,MAAM;SACnB,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACrE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAChF,OAAO;YACL,KAAK,EAAE;gBACL,OAAO,EAAE,IAAI,CAAC,QAAQ;gBACtB,KAAK,EAAE,IAAI,CAAC,MAAM;aACnB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { ConduitRouteReturnDefinition, } from '@conduitplatform/grpc-sdk';
|
|
2
|
-
export class RouteBuilder {
|
|
3
|
-
constructor(manager) {
|
|
4
|
-
this.manager = manager;
|
|
5
|
-
this._options = {};
|
|
6
|
-
}
|
|
7
|
-
method(action) {
|
|
8
|
-
this._options.action = action;
|
|
9
|
-
return this;
|
|
10
|
-
}
|
|
11
|
-
name(name) {
|
|
12
|
-
this._options.name = name;
|
|
13
|
-
return this;
|
|
14
|
-
}
|
|
15
|
-
description(description) {
|
|
16
|
-
this._options.description = description;
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
cacheControl(cache) {
|
|
20
|
-
this._options.cacheControl = cache;
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
middleware(middleware, allowDuplicates = false) {
|
|
24
|
-
var _a, _b, _c;
|
|
25
|
-
if (!Array.isArray(middleware)) {
|
|
26
|
-
middleware = [middleware];
|
|
27
|
-
}
|
|
28
|
-
if (this._options.middlewares !== undefined &&
|
|
29
|
-
((_a = this._options.middlewares) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
|
|
30
|
-
if (allowDuplicates) {
|
|
31
|
-
this._options.middlewares = (_b = this._options.middlewares) === null || _b === void 0 ? void 0 : _b.concat(middleware);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// add to existing middlewares and filter out potential duplicates
|
|
35
|
-
this._options.middlewares = (_c = this._options.middlewares) === null || _c === void 0 ? void 0 : _c.concat(middleware.filter(mid => { var _a; return ((_a = this._options.middlewares) === null || _a === void 0 ? void 0 : _a.indexOf(mid)) === -1; }));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
this._options.middlewares = middleware;
|
|
40
|
-
}
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
path(path) {
|
|
44
|
-
this._options.path = path;
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
queryParams(params) {
|
|
48
|
-
this._options.queryParams = params;
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
urlParams(params) {
|
|
52
|
-
this._options.urlParams = params;
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
bodyParams(params) {
|
|
56
|
-
this._options.bodyParams = params;
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
return(name, fields) {
|
|
60
|
-
this._returns = new ConduitRouteReturnDefinition(name, fields);
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
handler(fn) {
|
|
64
|
-
this._handler = fn;
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
add() {
|
|
68
|
-
if (!this.manager)
|
|
69
|
-
throw new Error('Builder not setup with manager');
|
|
70
|
-
if (!this._options)
|
|
71
|
-
throw new Error('Cannot build route without options');
|
|
72
|
-
if (!this._options.action)
|
|
73
|
-
throw new Error('Cannot build route without action');
|
|
74
|
-
if (!this._options.path)
|
|
75
|
-
throw new Error('Cannot build route without action');
|
|
76
|
-
if (!this._returns)
|
|
77
|
-
throw new Error('Cannot build route without return');
|
|
78
|
-
if (!this._handler)
|
|
79
|
-
throw new Error('Cannot build route without handler');
|
|
80
|
-
this.manager.route(this._options, this._returns, this._handler);
|
|
81
|
-
}
|
|
82
|
-
build() {
|
|
83
|
-
if (!this._options)
|
|
84
|
-
throw new Error('Cannot build route without options');
|
|
85
|
-
if (!this._options.action)
|
|
86
|
-
throw new Error('Cannot build route without action');
|
|
87
|
-
if (!this._options.path)
|
|
88
|
-
throw new Error('Cannot build route without action');
|
|
89
|
-
if (!this._returns)
|
|
90
|
-
throw new Error('Cannot build route without return');
|
|
91
|
-
if (!this._handler)
|
|
92
|
-
throw new Error('Cannot build route without handler');
|
|
93
|
-
return {
|
|
94
|
-
input: this._options,
|
|
95
|
-
returnType: this._returns,
|
|
96
|
-
handler: this._handler,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=RouteBuilder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RouteBuilder.js","sourceRoot":"","sources":["../../src/routing/RouteBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,4BAA4B,GAE7B,MAAM,2BAA2B,CAAC;AAInC,MAAM,OAAO,YAAY;IAKvB,YAA6B,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QACnD,IAAI,CAAC,QAAQ,GAAG,EAAS,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,MAA2B;QAChC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,IAAY;QACf,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,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,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAC1E,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAChF,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACzE,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAC1E,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,QAAQ;YACpB,UAAU,EAAE,IAAI,CAAC,QAAQ;YACzB,OAAO,EAAE,IAAI,CAAC,QAAQ;SACvB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { status } from '@grpc/grpc-js';
|
|
2
|
-
export class RoutingController {
|
|
3
|
-
constructor() {
|
|
4
|
-
this._routeHandlers = {};
|
|
5
|
-
}
|
|
6
|
-
handleRequest(call, callback) {
|
|
7
|
-
if (this._routeHandlers[call.request.functionName]) {
|
|
8
|
-
this._routeHandlers[call.request.functionName](call, callback);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
callback({
|
|
12
|
-
code: status.NOT_FOUND,
|
|
13
|
-
message: 'Not found',
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
setRoutes(routes) {
|
|
18
|
-
this._routeHandlers = routes;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=RoutingController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RoutingController.js","sourceRoot":"","sources":["../../src/routing/RoutingController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,MAAM,OAAO,iBAAiB;IAA9B;QACU,mBAAc,GAElB,EAAE,CAAC;IAgBT,CAAC;IAdC,aAAa,CAAC,IAAsB,EAAE,QAA2B;QAC/D,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACnD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC;gBACP,IAAI,EAAE,MAAM,CAAC,SAAS;gBACtB,OAAO,EAAE,WAAW;aACrB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,SAAS,CAAC,MAA6D;QACrE,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC;IAC/B,CAAC;CACF"}
|