@yopdev/dev-server 2.0.0-alpha.1 → 2.0.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/container.js +1 -1
- package/dist/src/deferred.js +7 -6
- package/dist/src/dev-server.d.ts +1 -0
- package/dist/src/dev-server.js +7 -3
- package/dist/src/internal-queue.js +5 -7
- package/dist/src/services.d.ts +1 -0
- package/dist/src/services.js +6 -2
- package/dist/src/sqs.js +1 -1
- package/package.json +1 -1
package/dist/src/container.js
CHANGED
|
@@ -18,7 +18,7 @@ class Container {
|
|
|
18
18
|
.then((started) => this.started = started)
|
|
19
19
|
.then(() => this.endpointBuilder(this.started.getFirstMappedPort()))
|
|
20
20
|
.tap((url) => this.LOGGER.debug(url));
|
|
21
|
-
this.stop = async () => this.started.stop().then(() => undefined);
|
|
21
|
+
this.stop = async () => (this.started ?? { stop: async () => { this.LOGGER.warn('no container'); } }).stop().then(() => undefined);
|
|
22
22
|
this.LOGGER = logging_1.LoggerFactory.create(`CONTAINER[${name}]`);
|
|
23
23
|
const generic = new testcontainers_1.GenericContainer(image);
|
|
24
24
|
const withEnvironment = environment ? generic.withEnvironment(environment) : generic;
|
package/dist/src/deferred.js
CHANGED
|
@@ -32,13 +32,14 @@ class Lazy {
|
|
|
32
32
|
}
|
|
33
33
|
class Promised {
|
|
34
34
|
constructor(configurable) {
|
|
35
|
-
this.configurable = configurable;
|
|
36
|
-
this.start = async (config) => this.configurable(config)
|
|
37
|
-
.then((service) => this.service = service)
|
|
38
|
-
.then((service) => this.LOGGER.info('DISCOVERY:%s', service.name))
|
|
39
|
-
.then(() => this.service.start(config));
|
|
40
|
-
this.stop = async () => this.service.stop();
|
|
41
35
|
this.name = (0, crypto_1.randomUUID)();
|
|
42
36
|
this.LOGGER = logging_1.LoggerFactory.create(`PROMISED[${this.name}]`);
|
|
37
|
+
let initialized;
|
|
38
|
+
this.start = async (config) => configurable(config)
|
|
39
|
+
.catch((e) => e?.cleanup?.() ?? Promise.reject(e))
|
|
40
|
+
.then((service) => initialized = service)
|
|
41
|
+
.tap((service) => this.LOGGER.info('DISCOVERY:%s', service.name))
|
|
42
|
+
.then((service) => service.start(config));
|
|
43
|
+
this.stop = async () => (initialized ?? { stop: async () => this.LOGGER.info('not started') }).stop();
|
|
43
44
|
}
|
|
44
45
|
}
|
package/dist/src/dev-server.d.ts
CHANGED
package/dist/src/dev-server.js
CHANGED
|
@@ -42,12 +42,16 @@ class DevServer {
|
|
|
42
42
|
}))))
|
|
43
43
|
.tap((config) => this.LOGGER.debug('config is %o', config))
|
|
44
44
|
.then((aws) => this.service.start(aws))
|
|
45
|
+
.catch((e) => this.shutdown()
|
|
46
|
+
.then(() => this.LOGGER.error('error starting service'))
|
|
47
|
+
.then(() => Promise.reject(e)))
|
|
45
48
|
.then(() => this.LOGGER.info('started'))
|
|
46
49
|
.then(() => this);
|
|
47
|
-
this.stop = () => this.
|
|
48
|
-
.then(tunnel_1.terminate)
|
|
49
|
-
.then(() => this.localStack?.stop())
|
|
50
|
+
this.stop = () => this.shutdown()
|
|
50
51
|
.then(() => this.LOGGER.info('stopped'));
|
|
52
|
+
this.shutdown = async () => this.service.stop()
|
|
53
|
+
.then(tunnel_1.terminate)
|
|
54
|
+
.then(() => this.localStack?.stop());
|
|
51
55
|
this.LOGGER = logging_1.LoggerFactory.create(`DEVSERVER[${name}]`);
|
|
52
56
|
const encodedName = Buffer.from(name).toString('hex').substring(0, 64);
|
|
53
57
|
this.eventProxyTopic = `EventProxyTopic${encodedName}`;
|
|
@@ -20,12 +20,13 @@ class InternalQueue {
|
|
|
20
20
|
.then((queue) => this
|
|
21
21
|
.createConsumer(sqs.client, this.name, queue.url, this.handler(queue), this.visibility)
|
|
22
22
|
.then(() => queue.url));
|
|
23
|
-
this.createConsumer = async (sqs, name, url, handler, visibility) => Promise.resolve(sqs_consumer_1.Consumer.create({
|
|
23
|
+
this.createConsumer = async (sqs, name, url, handler, visibility) => Promise.resolve(() => this.consumer = sqs_consumer_1.Consumer.create({
|
|
24
24
|
queueUrl: url,
|
|
25
25
|
waitTimeSeconds: visibility,
|
|
26
26
|
sqs: sqs,
|
|
27
27
|
handleMessage: async (message) => handler({ Records: [this.mapper(message)] }),
|
|
28
28
|
}))
|
|
29
|
+
.then((factory) => factory())
|
|
29
30
|
.then((consumer) => {
|
|
30
31
|
consumer.on('error', (err) => {
|
|
31
32
|
this.LOGGER.error(err, 'failed to handle message');
|
|
@@ -33,16 +34,13 @@ class InternalQueue {
|
|
|
33
34
|
consumer.on('processing_error', (err) => {
|
|
34
35
|
this.LOGGER.error(err, 'failed to process message');
|
|
35
36
|
});
|
|
36
|
-
consumer.start();
|
|
37
37
|
this.LOGGER.info('consumer for %s initialized', name);
|
|
38
|
-
|
|
39
|
-
consumer: consumer,
|
|
40
|
-
visibility: visibility,
|
|
41
|
-
};
|
|
38
|
+
return consumer;
|
|
42
39
|
})
|
|
40
|
+
.then(async (consumer) => consumer.start())
|
|
43
41
|
.then(() => this.LOGGER.info('started'))
|
|
44
42
|
.then(() => this);
|
|
45
|
-
this.stop = () => (0, stoppable_1.stopConsumer)(this.
|
|
43
|
+
this.stop = async () => this.consumer !== undefined ? (0, stoppable_1.stopConsumer)(this.visibility, this.consumer) : this.LOGGER.warn('no consumer');
|
|
46
44
|
this.LOGGER = logging_1.LoggerFactory.create(`INTERNALQUEUE[${name}]`);
|
|
47
45
|
}
|
|
48
46
|
async createQueue(sqs, name) {
|
package/dist/src/services.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class Service<I> implements Lifecycle<I> {
|
|
|
15
15
|
readonly name: string;
|
|
16
16
|
readonly start: (config: DevServerConfig) => Promise<I>;
|
|
17
17
|
readonly stop: () => Promise<void>;
|
|
18
|
+
private doStop;
|
|
18
19
|
private readonly LOGGER;
|
|
19
20
|
constructor(service: Lifecycle<I>, callback?: Callback<I>);
|
|
20
21
|
private callbackOrDefault;
|
package/dist/src/services.js
CHANGED
|
@@ -9,14 +9,18 @@ class Service {
|
|
|
9
9
|
this.callbackOrDefault = async (instance) => (this.callback ?? this.DEFAULT_CALLBACK)(instance);
|
|
10
10
|
this.name = service.name;
|
|
11
11
|
this.LOGGER = logging_1.LoggerFactory.create(`SERVICE[${this.name}]`);
|
|
12
|
+
const stop = async () => service.stop();
|
|
12
13
|
this.start = (config) => service.start(config)
|
|
14
|
+
.catch((error) => stop()
|
|
15
|
+
.then(() => this.doStop = () => Promise.resolve(this.LOGGER.error(error, 'failed')))
|
|
16
|
+
.then(() => Promise.reject(error)))
|
|
13
17
|
.then((started) => this
|
|
14
18
|
.callbackOrDefault(started)
|
|
15
19
|
.then(() => this.LOGGER.info('started'))
|
|
16
20
|
.then(() => started));
|
|
17
|
-
this.
|
|
18
|
-
.stop()
|
|
21
|
+
this.doStop = () => stop()
|
|
19
22
|
.then(() => this.LOGGER.info('stopped'));
|
|
23
|
+
this.stop = () => this.doStop();
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
exports.Service = Service;
|
package/dist/src/sqs.js
CHANGED