@yopdev/dev-server 1.3.0-alpha.3 → 1.3.0-alpha.5
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/src/event-proxy.d.ts +2 -20
- package/dist/src/event-proxy.js +5 -6
- package/package.json +1 -1
|
@@ -1,27 +1,9 @@
|
|
|
1
1
|
import { SQSEvent } from 'aws-lambda';
|
|
2
|
-
import {
|
|
3
|
-
import { DevServerConfig } from './config';
|
|
2
|
+
import { Service } from './services';
|
|
4
3
|
export declare const newEventsProxy: (name: string, config: {
|
|
5
4
|
handlers: EventHandler[];
|
|
6
|
-
}
|
|
7
|
-
declare class EventsProxy implements Lifecycle<EventsProxy> {
|
|
8
|
-
readonly name: string;
|
|
9
|
-
private readonly handlers;
|
|
10
|
-
private LOGGER;
|
|
11
|
-
private consumer;
|
|
12
|
-
private readonly pollingFrequency;
|
|
13
|
-
private readonly queue;
|
|
14
|
-
private stopped;
|
|
15
|
-
constructor(name: string, handlers: EventHandler[]);
|
|
16
|
-
start: (config: DevServerConfig) => Promise<this>;
|
|
17
|
-
private queueConnectedToTopic;
|
|
18
|
-
private startEventsConsumer;
|
|
19
|
-
private extractErrorMessage;
|
|
20
|
-
private onEachMessage;
|
|
21
|
-
stop: () => Promise<void>;
|
|
22
|
-
}
|
|
5
|
+
}) => Service<any>;
|
|
23
6
|
export type EventHandler = {
|
|
24
7
|
handler: (event: SQSEvent) => Promise<unknown>;
|
|
25
8
|
matcher: (subject: string) => boolean;
|
|
26
9
|
};
|
|
27
|
-
export {};
|
package/dist/src/event-proxy.js
CHANGED
|
@@ -43,7 +43,7 @@ var logging_1 = require("@yopdev/logging");
|
|
|
43
43
|
var stoppable_1 = require("./stoppable");
|
|
44
44
|
var assert_1 = require("./assert");
|
|
45
45
|
var services_1 = require("./services");
|
|
46
|
-
var newEventsProxy = function (name, config
|
|
46
|
+
var newEventsProxy = function (name, config) { return new services_1.Service(new EventsProxy(name, config.handlers)); };
|
|
47
47
|
exports.newEventsProxy = newEventsProxy;
|
|
48
48
|
var EventsProxy = /** @class */ (function () {
|
|
49
49
|
function EventsProxy(name, handlers) {
|
|
@@ -52,13 +52,14 @@ var EventsProxy = /** @class */ (function () {
|
|
|
52
52
|
this.handlers = handlers;
|
|
53
53
|
this.pollingFrequency = 1;
|
|
54
54
|
this.stopped = true;
|
|
55
|
+
this.queueName = function () { return "EventProxyQueue".concat(Buffer.from(_this.name).toString('hex').substring(0, 64)); };
|
|
55
56
|
this.start = function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
56
57
|
var _this = this;
|
|
57
58
|
return __generator(this, function (_a) {
|
|
58
|
-
return [2 /*return*/, this.queueConnectedToTopic(config.sns, config.eventsProxy.topic.arn, config.sqs, this.
|
|
59
|
+
return [2 /*return*/, this.queueConnectedToTopic(config.sns, config.eventsProxy.topic.arn, config.sqs, this.queueName())
|
|
59
60
|
.then(function (url) { return _this.startEventsConsumer(config.sqs.client, url); })
|
|
60
61
|
.then(function () { return _this.stopped = false; })
|
|
61
|
-
.then(function () { return
|
|
62
|
+
.then(function () { return undefined; })];
|
|
62
63
|
});
|
|
63
64
|
}); };
|
|
64
65
|
this.queueConnectedToTopic = function (sns, topic, sqs, queue) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -66,7 +67,7 @@ var EventsProxy = /** @class */ (function () {
|
|
|
66
67
|
return [2 /*return*/, sqs.createNamedQueue(queue)
|
|
67
68
|
.then(function (queue) { return sns
|
|
68
69
|
.createSubscription({ arn: topic }, { arn: queue.arn })
|
|
69
|
-
.then(function () { return queue
|
|
70
|
+
.then(function () { return queue.url; }); })];
|
|
70
71
|
});
|
|
71
72
|
}); };
|
|
72
73
|
this.startEventsConsumer = function (sqs, url) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -121,8 +122,6 @@ var EventsProxy = /** @class */ (function () {
|
|
|
121
122
|
});
|
|
122
123
|
}); };
|
|
123
124
|
this.LOGGER = logging_1.LoggerFactory.create("SNS->SQS[".concat(name, "]"));
|
|
124
|
-
var encodedName = Buffer.from(name).toString('hex').substring(0, 64);
|
|
125
|
-
this.queue = "EventProxyQueue".concat(encodedName);
|
|
126
125
|
}
|
|
127
126
|
return EventsProxy;
|
|
128
127
|
}());
|