@yopdev/dev-server 1.2.4 → 1.3.0-alpha.0

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.
@@ -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
  };
@@ -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);
@@ -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
  }());
@@ -3,15 +3,19 @@ import { Lifecycle, Service, Callback } from './services';
3
3
  import { DevServerConfig } from './config';
4
4
  export declare const newEventsProxy: (name: string, config: {
5
5
  handlers: EventHandler[];
6
+ topic?: string;
7
+ queue?: string;
6
8
  }, callback?: Callback<EventsProxy>) => Service<EventsProxy>;
7
9
  declare class EventsProxy implements Lifecycle<EventsProxy> {
8
10
  readonly name: string;
9
- private readonly handlers;
11
+ readonly handlers: EventHandler[];
10
12
  private LOGGER;
11
13
  private consumer;
12
14
  private readonly pollingFrequency;
15
+ private readonly topic;
16
+ private readonly queue;
13
17
  private stopped;
14
- constructor(name: string, handlers: EventHandler[]);
18
+ constructor(name: string, handlers: EventHandler[], topic?: string, queue?: string);
15
19
  start: (config: DevServerConfig) => Promise<this>;
16
20
  private queueConnectedToTopic;
17
21
  private startEventsConsumer;
@@ -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,7 +55,7 @@ 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, config.topic.name, config.sqs, config.queue)
58
+ return [2 /*return*/, this.queueConnectedToTopic(config.sns, this.topic, config.sqs, this.queue)
59
59
  .then(function (url) { return _this.startEventsConsumer(config.sqs.client, url); })
60
60
  .then(function (url) { return _this.LOGGER.debug('initialized: %s', url); })
61
61
  .then(function () { return _this.stopped = false; })
@@ -124,6 +124,10 @@ var EventsProxy = /** @class */ (function () {
124
124
  });
125
125
  }); };
126
126
  this.LOGGER = logging_1.LoggerFactory.create("SNS->SQS[".concat(name, "]"));
127
+ var encodedName = Buffer.from(name).toString('hex').substring(0, 64);
128
+ this.topic = topic !== null && topic !== void 0 ? topic : "EventProxyTopic".concat(encodedName);
129
+ this.queue = queue !== null && queue !== void 0 ? queue : "EventProxyQueue".concat(encodedName);
130
+ this.LOGGER.info('proxying events from %s to %s', this.topic, this.queue);
127
131
  }
128
132
  return EventsProxy;
129
133
  }());
@@ -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, subject?: 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: config.topic.arn,
34
+ topic: _this.topic.arn,
34
35
  sns: config.sns
35
36
  };
36
37
  return endpoint;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yopdev/dev-server",
3
- "version": "1.2.4",
3
+ "version": "1.3.0-alpha.0",
4
4
  "scripts": {
5
5
  "compile": "tsc",
6
6
  "test": "jest",