@yopdev/dev-server 1.1.0 → 1.1.3

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/config.d.ts CHANGED
@@ -3,13 +3,13 @@ import { Sns } from "./sns";
3
3
  import { DynamoDb } from "./dynamodb";
4
4
  import { StartedNetwork } from "testcontainers";
5
5
  export type Config = {
6
- servicesPort: number;
7
- localStackDockerImage: string | undefined;
6
+ servicesPort?: number;
7
+ localStackDockerImage?: string;
8
8
  useRandomPorts: boolean;
9
- localStateBindMount: string | undefined;
10
- queueName: string;
11
- topicName: string;
12
- table: string;
9
+ localStateBindMount?: string;
10
+ queueName?: string;
11
+ topicName?: string;
12
+ table?: string;
13
13
  };
14
14
  export type AwsConfig = {
15
15
  region: string;
@@ -4,6 +4,9 @@ export declare class DevServer implements Lifecycle<DevServer> {
4
4
  readonly name: string;
5
5
  private readonly config;
6
6
  private readonly service;
7
+ private readonly topicName;
8
+ private readonly queueName;
9
+ private readonly tableName;
7
10
  private LOGGER;
8
11
  private localStack;
9
12
  constructor(name: string, config: Config, service: Service<any>);
@@ -10,6 +10,7 @@ var sns_1 = require("./sns");
10
10
  var DevServer = /** @class */ (function () {
11
11
  function DevServer(name, config, service) {
12
12
  var _this = this;
13
+ var _a, _b, _c;
13
14
  this.name = name;
14
15
  this.config = config;
15
16
  this.service = service;
@@ -29,12 +30,12 @@ var DevServer = /** @class */ (function () {
29
30
  sqs: new sqs_1.Sqs(infra.aws),
30
31
  sns: new sns_1.Sns(infra.aws),
31
32
  dynamo: new dynamodb_1.DynamoDb(infra.aws),
32
- table: _this.config.table,
33
+ table: _this.tableName,
33
34
  topic: {
34
- arn: "arn:aws:sns:us-east-1:000000000000:".concat(_this.config.topicName),
35
- name: _this.config.topicName,
35
+ arn: "arn:aws:sns:us-east-1:000000000000:".concat(_this.topicName),
36
+ name: _this.topicName,
36
37
  },
37
- queue: _this.config.queueName,
38
+ queue: _this.queueName,
38
39
  }); })
39
40
  .then(function (config) { _this.LOGGER.debug('starting. config is %o', config); return config; })
40
41
  .then(function (aws) { return _this.service.start(aws); })
@@ -45,6 +46,10 @@ var DevServer = /** @class */ (function () {
45
46
  .then(function () { var _a; return (_a = _this.localStack) === null || _a === void 0 ? void 0 : _a.stop(); })
46
47
  .then(function () { return _this.LOGGER.info('stopped'); }); };
47
48
  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.topicName) !== null && _a !== void 0 ? _a : "Topic".concat(encodedName);
51
+ this.queueName = (_b = config.queueName) !== null && _b !== void 0 ? _b : "Queue".concat(encodedName);
52
+ this.tableName = (_c = config.table) !== null && _c !== void 0 ? _c : "Table".concat(encodedName);
48
53
  }
49
54
  return DevServer;
50
55
  }());
@@ -1,9 +1,9 @@
1
1
  import { CreateTableCommand } from "@aws-sdk/client-dynamodb";
2
2
  import { AwsConfig } from "./config";
3
- import { Service, ServiceConfig } from "./services";
3
+ import { Service, Callback } from "./services";
4
4
  export declare const newDynamoDbTable: (name: string, config: {
5
5
  command: CreateTableCommand;
6
- }, service: ServiceConfig<string>) => Service<string>;
6
+ }, callback?: Callback<string>) => Service<string>;
7
7
  export declare class DynamoDb {
8
8
  private readonly dynamo;
9
9
  constructor(config: AwsConfig);
package/dist/dynamodb.js CHANGED
@@ -40,7 +40,7 @@ exports.DynamoDb = exports.newDynamoDbTable = void 0;
40
40
  var client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
41
41
  var logging_1 = require("@yopdev/logging");
42
42
  var services_1 = require("./services");
43
- var newDynamoDbTable = function (name, config, service) { return new services_1.Service(new DynamoDbTableCreator(name, config.command), service); };
43
+ var newDynamoDbTable = function (name, config, callback) { return new services_1.Service(new DynamoDbTableCreator(name, config.command), callback); };
44
44
  exports.newDynamoDbTable = newDynamoDbTable;
45
45
  var DynamoDbTableCreator = /** @class */ (function () {
46
46
  function DynamoDbTableCreator(name, command) {
@@ -1,9 +1,9 @@
1
1
  import { SQSEvent } from 'aws-lambda';
2
- import { Lifecycle, Service, ServiceConfig } from './services';
2
+ 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
- }, service: ServiceConfig<EventsProxy>) => Service<EventsProxy>;
6
+ }, callback?: Callback<EventsProxy>) => Service<EventsProxy>;
7
7
  declare class EventsProxy implements Lifecycle<EventsProxy> {
8
8
  readonly name: string;
9
9
  private readonly handlers;
@@ -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, service) { return new services_1.Service(new EventsProxy(name, config.handlers), service); };
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
49
  function EventsProxy(name, handlers) {
@@ -1,2 +1,3 @@
1
1
  import { Service } from "./services";
2
2
  export declare const all: (services: Service<any>[]) => Service<any>;
3
+ export declare const oneThenOther: (one: Service<unknown>, other: Service<unknown>) => Service<unknown>;
package/dist/factories.js CHANGED
@@ -1,11 +1,69 @@
1
1
  "use strict";
2
- var _this = this;
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
3
38
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.all = void 0;
39
+ exports.oneThenOther = exports.all = void 0;
5
40
  var services_1 = require("./services");
6
41
  var all = function (services) { return new services_1.Service({
7
42
  name: "ALLOF[".concat(services.map(function (each) { return each.name; }).join(','), "]"),
8
- start: function (config) { return Promise.all(services.map(function (each) { return each.start(config); })).then(function () { return _this; }); },
9
- stop: function () { return Promise.all(services.map(function (each) { return each.stop(); })).then(); }
10
- }, {}); };
43
+ start: function (config) { return __awaiter(void 0, void 0, void 0, function () {
44
+ var _this = this;
45
+ return __generator(this, function (_a) {
46
+ return [2 /*return*/, Promise.all(services.map(function (each) { return each.start(config); })).then(function () { return _this; })];
47
+ });
48
+ }); },
49
+ stop: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
50
+ return [2 /*return*/, Promise.all(services.map(function (each) { return each.stop(); })).then()];
51
+ }); }); }
52
+ }); };
11
53
  exports.all = all;
54
+ var oneThenOther = function (one, other) {
55
+ return new services_1.Service({
56
+ name: "[".concat(one.name, "]->[").concat(other.name, "]"),
57
+ start: function (config) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
58
+ return [2 /*return*/, one.start(config).then(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
59
+ return [2 /*return*/, other.start(config)];
60
+ }); }); })];
61
+ }); }); },
62
+ stop: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
63
+ return [2 /*return*/, other.stop().then(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
64
+ return [2 /*return*/, one.stop()];
65
+ }); }); })];
66
+ }); }); },
67
+ });
68
+ };
69
+ exports.oneThenOther = oneThenOther;
@@ -1,10 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingMessage, ServerResponse } from "http";
3
- import { Lifecycle, Service, ServiceConfig } from "./services";
3
+ import { Lifecycle, Service, Callback } from "./services";
4
4
  export declare const newHttpServer: (name: string, config: {
5
5
  settings: HttpSettings;
6
6
  handler: (request: IncomingMessage, requestBody: string, response: ServerResponse) => void;
7
- }, service: ServiceConfig<string>) => Service<string>;
7
+ }, callback?: Callback<string>) => Service<string>;
8
8
  export declare class HttpServer implements Lifecycle<string> {
9
9
  readonly name: string;
10
10
  readonly settings: HttpSettings;
@@ -6,7 +6,7 @@ var events_1 = require("events");
6
6
  var logging_1 = require("@yopdev/logging");
7
7
  var assert_1 = require("./assert");
8
8
  var services_1 = require("./services");
9
- var newHttpServer = function (name, config, service) { return new services_1.Service(new HttpServer(name, config.settings, config.handler), service); };
9
+ var newHttpServer = function (name, config, callback) { return new services_1.Service(new HttpServer(name, config.settings, config.handler), callback); };
10
10
  exports.newHttpServer = newHttpServer;
11
11
  var HttpServer = /** @class */ (function () {
12
12
  function HttpServer(name, settings, handler) {
package/dist/index.d.ts CHANGED
@@ -7,4 +7,4 @@ export { newEventsProxy as eventsProxy } from './event-proxy';
7
7
  export { newScheduledTasks as scheduledTasks } from './scheduled-tasks';
8
8
  export { newPreTrafficHooks as preTrafficHooks } from './pre-traffic-hooks';
9
9
  export { newDynamoDbTable as dynamoDbTable } from './dynamodb';
10
- export { all as allOf } from './factories';
10
+ export { all as allOf, oneThenOther } from './factories';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.allOf = exports.dynamoDbTable = exports.preTrafficHooks = exports.scheduledTasks = exports.eventsProxy = exports.internalQueue = exports.snsHttpProxy = exports.lambdaHttpProxy = exports.httpServer = exports.DevServer = void 0;
3
+ exports.oneThenOther = exports.allOf = exports.dynamoDbTable = exports.preTrafficHooks = exports.scheduledTasks = exports.eventsProxy = exports.internalQueue = exports.snsHttpProxy = exports.lambdaHttpProxy = exports.httpServer = exports.DevServer = void 0;
4
4
  var dev_server_1 = require("./dev-server");
5
5
  Object.defineProperty(exports, "DevServer", { enumerable: true, get: function () { return dev_server_1.DevServer; } });
6
6
  var http_server_1 = require("./http-server");
@@ -21,3 +21,4 @@ var dynamodb_1 = require("./dynamodb");
21
21
  Object.defineProperty(exports, "dynamoDbTable", { enumerable: true, get: function () { return dynamodb_1.newDynamoDbTable; } });
22
22
  var factories_1 = require("./factories");
23
23
  Object.defineProperty(exports, "allOf", { enumerable: true, get: function () { return factories_1.all; } });
24
+ Object.defineProperty(exports, "oneThenOther", { enumerable: true, get: function () { return factories_1.oneThenOther; } });
@@ -1,7 +1,7 @@
1
1
  import { SQSEvent } from "aws-lambda";
2
- import { Service, ServiceConfig } from "./services";
2
+ import { Service, Callback } from "./services";
3
3
  export declare const newInternalQueue: (name: string, config: {
4
4
  index: number;
5
5
  visibility: number;
6
6
  handler: (e: SQSEvent) => Promise<void>;
7
- }, service: ServiceConfig<string>) => Service<string>;
7
+ }, callback?: Callback<string>) => Service<string>;
@@ -42,7 +42,7 @@ var sqs_consumer_1 = require("sqs-consumer");
42
42
  var stoppable_1 = require("./stoppable");
43
43
  var mappers_1 = require("./mappers");
44
44
  var services_1 = require("./services");
45
- var newInternalQueue = function (name, config, service) { return new services_1.Service(new InternalQueue(name, config.visibility, config.handler, config.index), service); };
45
+ var newInternalQueue = function (name, config, callback) { return new services_1.Service(new InternalQueue(name, config.visibility, config.handler, config.index), callback); };
46
46
  exports.newInternalQueue = newInternalQueue;
47
47
  var InternalQueue = /** @class */ (function () {
48
48
  function InternalQueue(name, visibility, handler, index) {
@@ -1,7 +1,7 @@
1
1
  import { HttpSettings } from "./http-server";
2
2
  import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
3
- import { Service, ServiceConfig } from "./services";
3
+ import { Service, Callback } from "./services";
4
4
  export declare const newLambdaHttpProxy: (name: string, config: {
5
5
  settings: HttpSettings;
6
6
  handler: (event: APIGatewayProxyEvent) => Promise<APIGatewayProxyResult>;
7
- }, service: ServiceConfig<string>) => Service<string>;
7
+ }, callback?: Callback<string>) => Service<string>;
@@ -6,7 +6,7 @@ var http_server_1 = require("./http-server");
6
6
  var mappers_1 = require("./mappers");
7
7
  var responses_1 = require("./responses");
8
8
  var services_1 = require("./services");
9
- var newLambdaHttpProxy = function (name, config, service) { return new services_1.Service(new LambdaHttpProxy(name, config.settings, config.handler), service); };
9
+ var newLambdaHttpProxy = function (name, config, callback) { return new services_1.Service(new LambdaHttpProxy(name, config.settings, config.handler), callback); };
10
10
  exports.newLambdaHttpProxy = newLambdaHttpProxy;
11
11
  var LambdaHttpProxy = /** @class */ (function () {
12
12
  function LambdaHttpProxy(name, settings, handler) {
@@ -40,6 +40,7 @@ exports.LocalStack = void 0;
40
40
  var logging_1 = require("@yopdev/logging");
41
41
  var testcontainers_1 = require("testcontainers");
42
42
  var LOGGER = logging_1.LoggerFactory.create('LOCALSTACK');
43
+ var DEFAULT_SERVICES_PORT = 4566;
43
44
  var NETWORK_ALIAS = 'localstack';
44
45
  var PROTOCOL = 'http';
45
46
  var DEFAULT_DOCKER_IMAGE = 'localstack/localstack:stable';
@@ -62,6 +63,7 @@ var LocalStack = /** @class */ (function () {
62
63
  this.stop = function () { return Promise.resolve(_this.started)
63
64
  .then(function (container) { return container ? container.stop().then(function () { return 'stopped'; }) : 'not started'; })
64
65
  .then(function (status) { return LOGGER.info(status); }); };
66
+ var servicesPort = config.servicesPort || DEFAULT_SERVICES_PORT;
65
67
  var container = new testcontainers_1.GenericContainer(config.localStackDockerImage || DEFAULT_DOCKER_IMAGE);
66
68
  var localStatePath = config.localStateBindMount;
67
69
  var withLocalState = localStatePath !== undefined ?
@@ -75,17 +77,17 @@ var LocalStack = /** @class */ (function () {
75
77
  : container;
76
78
  var ready = withLocalState
77
79
  .withExposedPorts(config.useRandomPorts ?
78
- config.servicesPort :
80
+ servicesPort :
79
81
  {
80
- container: config.servicesPort,
81
- host: config.servicesPort
82
+ container: servicesPort,
83
+ host: servicesPort
82
84
  })
83
85
  .withNetwork(network)
84
86
  .withNetworkAliases(NETWORK_ALIAS);
85
87
  this._start = function () { return ready
86
88
  .start()
87
89
  .then(function (container) { return _this.started = container; })
88
- .then(function (container) { return "".concat(PROTOCOL, "://").concat(container.getHost(), ":").concat(container.getMappedPort(config.servicesPort)); }); };
90
+ .then(function (container) { return "".concat(PROTOCOL, "://").concat(container.getHost(), ":").concat(container.getMappedPort(servicesPort)); }); };
89
91
  LOGGER.debug('initialized');
90
92
  }
91
93
  return LocalStack;
@@ -1,5 +1,5 @@
1
- import { Lifecycle, Service, ServiceConfig } from './services';
2
- export declare const newPreTrafficHooks: (name: string, hooks: () => Promise<void>[], service: ServiceConfig<PreTrafficHooks>) => Service<PreTrafficHooks>;
1
+ import { Lifecycle, Service, Callback } from './services';
2
+ export declare const newPreTrafficHooks: (name: string, hooks: () => Promise<void>[], callback?: Callback<PreTrafficHooks>) => Service<PreTrafficHooks>;
3
3
  declare class PreTrafficHooks implements Lifecycle<PreTrafficHooks> {
4
4
  readonly name: string;
5
5
  private readonly hooks;
@@ -39,7 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.newPreTrafficHooks = void 0;
40
40
  var logging_1 = require("@yopdev/logging");
41
41
  var services_1 = require("./services");
42
- var newPreTrafficHooks = function (name, hooks, service) { return new services_1.Service(new PreTrafficHooks(name, hooks), service); };
42
+ var newPreTrafficHooks = function (name, hooks, callback) { return new services_1.Service(new PreTrafficHooks(name, hooks), callback); };
43
43
  exports.newPreTrafficHooks = newPreTrafficHooks;
44
44
  var PreTrafficHooks = /** @class */ (function () {
45
45
  function PreTrafficHooks(name, hooks) {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Lifecycle, Service, ServiceConfig } from './services';
3
- export declare const newScheduledTasks: (name: string, schedules: Rate[], service: ServiceConfig<ScheduledTasks>) => Service<ScheduledTasks>;
2
+ import { Lifecycle, Service, Callback } from './services';
3
+ export declare const newScheduledTasks: (name: string, schedules: Rate[], callback?: Callback<ScheduledTasks>) => Service<ScheduledTasks>;
4
4
  declare class ScheduledTasks implements Lifecycle<ScheduledTasks> {
5
5
  readonly name: string;
6
6
  private readonly schedules;
@@ -40,7 +40,7 @@ exports.newScheduledTasks = void 0;
40
40
  var logging_1 = require("@yopdev/logging");
41
41
  var timers_1 = require("timers");
42
42
  var services_1 = require("./services");
43
- var newScheduledTasks = function (name, schedules, service) { return new services_1.Service(new ScheduledTasks(name, schedules), service); };
43
+ var newScheduledTasks = function (name, schedules, callback) { return new services_1.Service(new ScheduledTasks(name, schedules), callback); };
44
44
  exports.newScheduledTasks = newScheduledTasks;
45
45
  var ScheduledTasks = /** @class */ (function () {
46
46
  function ScheduledTasks(name, schedules) {
@@ -6,19 +6,14 @@ export interface Lifecycle<I> extends Stoppable {
6
6
  export interface Stoppable {
7
7
  stop(): Promise<void>;
8
8
  }
9
- export interface Callbackable<I> {
10
- callback?: ((instance: I) => Promise<void>);
11
- }
9
+ export type Callback<I> = (instance: I) => Promise<void>;
12
10
  export declare class Service<I> implements Lifecycle<I> {
13
- private readonly config;
11
+ private readonly callback?;
12
+ private readonly DEFAULT_CALLBACK;
14
13
  readonly name: string;
15
14
  readonly start: (config: DevServerConfig) => Promise<I>;
16
15
  readonly stop: () => Promise<void>;
17
16
  private LOGGER;
18
- constructor(service: Lifecycle<I>, config: ServiceConfig<I>);
19
- private callback;
20
- private dependsOnOrNothing;
17
+ constructor(service: Lifecycle<I>, callback?: Callback<I>);
18
+ private callbackOrDefault;
21
19
  }
22
- export type ServiceConfig<I> = {
23
- dependsOn?: Lifecycle<any>;
24
- } & Callbackable<I>;
package/dist/services.js CHANGED
@@ -39,35 +39,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.Service = void 0;
40
40
  var logging_1 = require("@yopdev/logging");
41
41
  var Service = /** @class */ (function () {
42
- function Service(service, config) {
42
+ function Service(service, callback) {
43
43
  var _this = this;
44
- this.config = config;
45
- this.callback = function (instance) { return __awaiter(_this, void 0, void 0, function () {
46
- var _this = this;
47
- return __generator(this, function (_a) {
48
- return [2 /*return*/, (this.config.callback || (function () { return _this.LOGGER.debug('no callback', _this.name); }))(instance)];
49
- });
50
- }); };
51
- this.dependsOnOrNothing = function () {
52
- var _a;
53
- return (_a = _this.config.dependsOn) !== null && _a !== void 0 ? _a : {
54
- name: _this.name,
55
- start: function () { return Promise.resolve(_this.LOGGER.trace('no start dependency for %s', _this.name)); },
56
- stop: function () { return Promise.resolve(_this.LOGGER.trace('no stop dependency for %s', _this.name)); }
57
- };
58
- };
44
+ this.callback = callback;
45
+ this.DEFAULT_CALLBACK = function () { return Promise.resolve(_this.LOGGER.debug('no callback')); };
46
+ this.callbackOrDefault = function (instance) { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
47
+ return [2 /*return*/, ((_a = this.callback) !== null && _a !== void 0 ? _a : this.DEFAULT_CALLBACK)(instance)];
48
+ }); }); };
59
49
  this.name = service.name;
60
50
  this.LOGGER = logging_1.LoggerFactory.create("SERVICE[".concat(this.name, "]"));
61
- this.start = function (config) { return _this.dependsOnOrNothing()
62
- .start(config)
63
- .then(function () { return service.start(config); })
51
+ this.start = function (config) { return service.start(config)
64
52
  .then(function (started) { return _this
65
- .callback(started)
53
+ .callbackOrDefault(started)
66
54
  .then(function () { return _this.LOGGER.info('started'); })
67
55
  .then(function () { return started; }); }); };
68
56
  this.stop = function () { return service
69
57
  .stop()
70
- .then(function () { return _this.dependsOnOrNothing().stop(); })
71
58
  .then(function () { return _this.LOGGER.info('stopped'); }); };
72
59
  }
73
60
  return Service;
@@ -1,12 +1,12 @@
1
1
  import { HttpSettings } from "./http-server";
2
2
  import { IncomingMessage, ServerResponse } from "http";
3
- import { Lifecycle, Service, ServiceConfig } from "./services";
3
+ import { Lifecycle, Service, Callback } from "./services";
4
4
  import { DevServerConfig } from "./config";
5
5
  export declare const newSnsHttpProxy: (name: string, config: {
6
6
  settings: HttpSettings;
7
7
  method: string;
8
8
  subject: string | undefined;
9
- }, service: ServiceConfig<string>) => Service<string>;
9
+ }, callback?: Callback<string>) => Service<string>;
10
10
  export declare class SnsHttpProxy implements Lifecycle<string> {
11
11
  readonly name: string;
12
12
  private readonly settings;
@@ -17,7 +17,7 @@ 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, service) { return new services_1.Service(new SnsHttpProxy(name, config.settings, config.method, config.subject), service); };
20
+ var newSnsHttpProxy = function (name, config, callback) { return new services_1.Service(new SnsHttpProxy(name, config.settings, config.method, config.subject), callback); };
21
21
  exports.newSnsHttpProxy = newSnsHttpProxy;
22
22
  var SnsHttpProxy = /** @class */ (function () {
23
23
  function SnsHttpProxy(name, settings, method, subject) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yopdev/dev-server",
3
- "version": "1.1.0",
3
+ "version": "1.1.3",
4
4
  "scripts": {
5
5
  "compile": "tsc",
6
6
  "clean": "rm -rf dist",