@yopdev/dev-server 1.2.4 → 1.3.0-alpha.2
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/config.d.ts +0 -9
- package/dist/src/dev-server.d.ts +0 -3
- package/dist/src/dev-server.js +0 -11
- package/dist/src/event-proxy.d.ts +10 -19
- package/dist/src/event-proxy.js +15 -8
- package/dist/src/sns-http-proxy.d.ts +8 -2
- package/dist/src/sns-http-proxy.js +4 -3
- package/dist/src/sns.d.ts +4 -1
- package/dist/src/sns.js +5 -1
- package/package.json +2 -1
package/dist/src/config.d.ts
CHANGED
|
@@ -6,9 +6,6 @@ export type Config = {
|
|
|
6
6
|
boundServicesPort?: number;
|
|
7
7
|
localStackDockerImage?: string;
|
|
8
8
|
localStateBindMount?: string;
|
|
9
|
-
queueName?: string;
|
|
10
|
-
topicName?: string;
|
|
11
|
-
tableName?: string;
|
|
12
9
|
};
|
|
13
10
|
export type AwsConfig = {
|
|
14
11
|
region: string;
|
|
@@ -24,10 +21,4 @@ export type DevServerConfig = {
|
|
|
24
21
|
sqs: Sqs;
|
|
25
22
|
sns: Sns;
|
|
26
23
|
dynamo: DynamoDb;
|
|
27
|
-
table: string;
|
|
28
|
-
topic: {
|
|
29
|
-
arn: string;
|
|
30
|
-
name: string;
|
|
31
|
-
};
|
|
32
|
-
queue: string;
|
|
33
24
|
};
|
package/dist/src/dev-server.d.ts
CHANGED
|
@@ -4,9 +4,6 @@ export declare class DevServer implements Lifecycle<DevServer> {
|
|
|
4
4
|
readonly name: string;
|
|
5
5
|
private readonly service;
|
|
6
6
|
private readonly config?;
|
|
7
|
-
private readonly topicName;
|
|
8
|
-
private readonly queueName;
|
|
9
|
-
private readonly tableName;
|
|
10
7
|
private LOGGER;
|
|
11
8
|
private localStack;
|
|
12
9
|
constructor(name: string, service: Service<any>, config?: Config);
|
package/dist/src/dev-server.js
CHANGED
|
@@ -10,7 +10,6 @@ var sns_1 = require("./sns");
|
|
|
10
10
|
var DevServer = /** @class */ (function () {
|
|
11
11
|
function DevServer(name, service, config) {
|
|
12
12
|
var _this = this;
|
|
13
|
-
var _a, _b, _c;
|
|
14
13
|
this.name = name;
|
|
15
14
|
this.service = service;
|
|
16
15
|
this.config = config;
|
|
@@ -30,12 +29,6 @@ var DevServer = /** @class */ (function () {
|
|
|
30
29
|
sqs: new sqs_1.Sqs(infra.aws),
|
|
31
30
|
sns: new sns_1.Sns(infra.aws),
|
|
32
31
|
dynamo: new dynamodb_1.DynamoDb(infra.aws),
|
|
33
|
-
table: _this.tableName,
|
|
34
|
-
topic: {
|
|
35
|
-
arn: "arn:aws:sns:us-east-1:000000000000:".concat(_this.topicName),
|
|
36
|
-
name: _this.topicName,
|
|
37
|
-
},
|
|
38
|
-
queue: _this.queueName,
|
|
39
32
|
}); })
|
|
40
33
|
.then(function (config) { _this.LOGGER.debug('starting. config is %o', config); return config; })
|
|
41
34
|
.then(function (aws) { return _this.service.start(aws); })
|
|
@@ -46,10 +39,6 @@ var DevServer = /** @class */ (function () {
|
|
|
46
39
|
.then(function () { var _a; return (_a = _this.localStack) === null || _a === void 0 ? void 0 : _a.stop(); })
|
|
47
40
|
.then(function () { return _this.LOGGER.info('stopped'); }); };
|
|
48
41
|
this.LOGGER = logging_1.LoggerFactory.create("DEVSERVER[".concat(name, "]"));
|
|
49
|
-
var encodedName = Buffer.from(name).toString('hex').substring(0, 16);
|
|
50
|
-
this.topicName = (_a = config === null || config === void 0 ? void 0 : config.topicName) !== null && _a !== void 0 ? _a : "Topic".concat(encodedName);
|
|
51
|
-
this.queueName = (_b = config === null || config === void 0 ? void 0 : config.queueName) !== null && _b !== void 0 ? _b : "Queue".concat(encodedName);
|
|
52
|
-
this.tableName = (_c = config === null || config === void 0 ? void 0 : config.tableName) !== null && _c !== void 0 ? _c : "Table".concat(encodedName);
|
|
53
42
|
}
|
|
54
43
|
return DevServer;
|
|
55
44
|
}());
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
import { SQSEvent } from 'aws-lambda';
|
|
2
|
-
import {
|
|
3
|
-
import { DevServerConfig } from './config';
|
|
2
|
+
import { Service, Callback } from './services';
|
|
4
3
|
export declare const newEventsProxy: (name: string, config: {
|
|
5
4
|
handlers: EventHandler[];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
start: (config: DevServerConfig) => Promise<this>;
|
|
16
|
-
private queueConnectedToTopic;
|
|
17
|
-
private startEventsConsumer;
|
|
18
|
-
private extractErrorMessage;
|
|
19
|
-
private onEachMessage;
|
|
20
|
-
stop: () => Promise<void>;
|
|
21
|
-
}
|
|
5
|
+
topic?: string;
|
|
6
|
+
queue?: string;
|
|
7
|
+
}, callback?: Callback<{
|
|
8
|
+
arn: string;
|
|
9
|
+
name: string;
|
|
10
|
+
}>) => Service<{
|
|
11
|
+
arn: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}>;
|
|
22
14
|
export type EventHandler = {
|
|
23
15
|
handler: (event: SQSEvent) => Promise<unknown>;
|
|
24
16
|
matcher: (subject: string) => boolean;
|
|
25
17
|
};
|
|
26
|
-
export {};
|
package/dist/src/event-proxy.js
CHANGED
|
@@ -46,7 +46,7 @@ var services_1 = require("./services");
|
|
|
46
46
|
var newEventsProxy = function (name, config, callback) { return new services_1.Service(new EventsProxy(name, config.handlers), callback); };
|
|
47
47
|
exports.newEventsProxy = newEventsProxy;
|
|
48
48
|
var EventsProxy = /** @class */ (function () {
|
|
49
|
-
function EventsProxy(name, handlers) {
|
|
49
|
+
function EventsProxy(name, handlers, topic, queue) {
|
|
50
50
|
var _this = this;
|
|
51
51
|
this.name = name;
|
|
52
52
|
this.handlers = handlers;
|
|
@@ -55,11 +55,14 @@ var EventsProxy = /** @class */ (function () {
|
|
|
55
55
|
this.start = function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
56
56
|
var _this = this;
|
|
57
57
|
return __generator(this, function (_a) {
|
|
58
|
-
return [2 /*return*/, this.queueConnectedToTopic(config.sns,
|
|
59
|
-
.then(function (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
return [2 /*return*/, this.queueConnectedToTopic(config.sns, this.topic, config.sqs, this.queue)
|
|
59
|
+
.then(function (_a) {
|
|
60
|
+
var topic = _a[0], queue = _a[1];
|
|
61
|
+
return _this.startEventsConsumer(config.sqs.client, queue.url)
|
|
62
|
+
.then(function () { return _this.LOGGER.info('started'); })
|
|
63
|
+
.then(function () { return _this.stopped = false; })
|
|
64
|
+
.then(function () { return topic; });
|
|
65
|
+
})];
|
|
63
66
|
});
|
|
64
67
|
}); };
|
|
65
68
|
this.queueConnectedToTopic = function (sns, topic, sqs, queue) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -68,8 +71,8 @@ var EventsProxy = /** @class */ (function () {
|
|
|
68
71
|
sns.createTopic(topic), sqs.createNamedQueue(queue)
|
|
69
72
|
])
|
|
70
73
|
.then(function (values) { return sns
|
|
71
|
-
.createSubscription(
|
|
72
|
-
.then(function () { return values
|
|
74
|
+
.createSubscription(values[0], values[1])
|
|
75
|
+
.then(function () { return values; }); })];
|
|
73
76
|
});
|
|
74
77
|
}); };
|
|
75
78
|
this.startEventsConsumer = function (sqs, url) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -124,6 +127,10 @@ var EventsProxy = /** @class */ (function () {
|
|
|
124
127
|
});
|
|
125
128
|
}); };
|
|
126
129
|
this.LOGGER = logging_1.LoggerFactory.create("SNS->SQS[".concat(name, "]"));
|
|
130
|
+
var encodedName = Buffer.from(name).toString('hex').substring(0, 64);
|
|
131
|
+
this.topic = topic !== null && topic !== void 0 ? topic : "EventProxyTopic".concat(encodedName);
|
|
132
|
+
this.queue = queue !== null && queue !== void 0 ? queue : "EventProxyQueue".concat(encodedName);
|
|
133
|
+
this.LOGGER.info('proxying events from %s to %s', this.topic, this.queue);
|
|
127
134
|
}
|
|
128
135
|
return EventsProxy;
|
|
129
136
|
}());
|
|
@@ -5,17 +5,23 @@ import { DevServerConfig } from "./config";
|
|
|
5
5
|
export declare const newSnsHttpProxy: (name: string, config: {
|
|
6
6
|
settings: HttpSettings;
|
|
7
7
|
method: string;
|
|
8
|
+
topic: {
|
|
9
|
+
arn: string;
|
|
10
|
+
};
|
|
8
11
|
subject: string | undefined;
|
|
9
12
|
}, callback?: Callback<string>) => Service<string>;
|
|
10
13
|
export declare class SnsHttpProxy implements Lifecycle<string> {
|
|
11
14
|
readonly name: string;
|
|
12
15
|
private readonly settings;
|
|
13
16
|
private readonly method;
|
|
17
|
+
private readonly topic;
|
|
14
18
|
private readonly subject?;
|
|
15
19
|
private LOGGER;
|
|
16
|
-
private server;
|
|
20
|
+
private readonly server;
|
|
17
21
|
private config;
|
|
18
|
-
constructor(name: string, settings: HttpSettings, method: string,
|
|
22
|
+
constructor(name: string, settings: HttpSettings, method: string, topic: {
|
|
23
|
+
arn: string;
|
|
24
|
+
}, subject?: string);
|
|
19
25
|
start: (config: DevServerConfig) => Promise<string>;
|
|
20
26
|
stop: () => Promise<void>;
|
|
21
27
|
handler: (method: string, subject?: string) => (request: IncomingMessage, body: string, response: ServerResponse) => Promise<void>;
|
|
@@ -17,20 +17,21 @@ var http_server_1 = require("./http-server");
|
|
|
17
17
|
var responses_1 = require("./responses");
|
|
18
18
|
var services_1 = require("./services");
|
|
19
19
|
var assert_1 = require("./assert");
|
|
20
|
-
var newSnsHttpProxy = function (name, config, callback) { return new services_1.Service(new SnsHttpProxy(name, config.settings, config.method, config.subject), callback); };
|
|
20
|
+
var newSnsHttpProxy = function (name, config, callback) { return new services_1.Service(new SnsHttpProxy(name, config.settings, config.method, config.topic, config.subject), callback); };
|
|
21
21
|
exports.newSnsHttpProxy = newSnsHttpProxy;
|
|
22
22
|
var SnsHttpProxy = /** @class */ (function () {
|
|
23
|
-
function SnsHttpProxy(name, settings, method, subject) {
|
|
23
|
+
function SnsHttpProxy(name, settings, method, topic, subject) {
|
|
24
24
|
var _this = this;
|
|
25
25
|
this.name = name;
|
|
26
26
|
this.settings = settings;
|
|
27
27
|
this.method = method;
|
|
28
|
+
this.topic = topic;
|
|
28
29
|
this.subject = subject;
|
|
29
30
|
this.start = function (config) { return Promise.resolve(_this.server)
|
|
30
31
|
.then(function (server) { return server.start(); })
|
|
31
32
|
.then(function (endpoint) {
|
|
32
33
|
_this.config = {
|
|
33
|
-
topic:
|
|
34
|
+
topic: _this.topic.arn,
|
|
34
35
|
sns: config.sns
|
|
35
36
|
};
|
|
36
37
|
return endpoint;
|
package/dist/src/sns.d.ts
CHANGED
|
@@ -3,7 +3,10 @@ import { AwsConfig } from "./config";
|
|
|
3
3
|
export declare class Sns {
|
|
4
4
|
readonly client: SNSClient;
|
|
5
5
|
constructor(aws: AwsConfig);
|
|
6
|
-
createTopic: (topic: string) => Promise<
|
|
6
|
+
createTopic: (topic: string) => Promise<{
|
|
7
|
+
arn: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}>;
|
|
7
10
|
createSubscription: (topic: {
|
|
8
11
|
arn: string;
|
|
9
12
|
}, queue: {
|
package/dist/src/sns.js
CHANGED
|
@@ -50,7 +50,11 @@ var Sns = /** @class */ (function () {
|
|
|
50
50
|
.send(new client_sns_1.CreateTopicCommand({
|
|
51
51
|
Name: topic,
|
|
52
52
|
}))
|
|
53
|
-
.then(function (o) { return (0, assert_1.assertNotUndefined)(o.TopicArn, 'TopicArn is not present'); })
|
|
53
|
+
.then(function (o) { return (0, assert_1.assertNotUndefined)(o.TopicArn, 'TopicArn is not present'); })
|
|
54
|
+
.then(function (arn) { return ({
|
|
55
|
+
arn: arn,
|
|
56
|
+
name: topic,
|
|
57
|
+
}); })];
|
|
54
58
|
});
|
|
55
59
|
}); };
|
|
56
60
|
this.createSubscription = function (topic, queue) { return __awaiter(_this, void 0, void 0, function () {
|