@yopdev/dev-server 3.0.3-beta.1 → 3.0.3-beta.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/src/cloudformation-dynamodb-table.js +1 -1
- package/dist/src/cloudformation.js +2 -2
- package/dist/src/container.js +1 -1
- package/dist/src/deferred.js +3 -3
- package/dist/src/dynamodb.js +4 -3
- package/dist/src/internal-queue.js +3 -3
- package/dist/src/lambda-http-proxy.js +1 -1
- package/dist/src/pre-traffic-hooks.js +1 -1
- package/dist/src/scheduled-tasks.js +1 -1
- package/dist/src/services.js +2 -2
- package/dist/src/sns-http-proxy.js +1 -1
- package/package.json +1 -1
- package/src/cloudformation-dynamodb-table.ts +1 -1
- package/src/cloudformation.ts +2 -2
- package/src/container.ts +1 -1
- package/src/deferred.ts +3 -3
- package/src/dynamodb.ts +13 -9
- package/src/internal-queue.ts +3 -3
- package/src/lambda-http-proxy.ts +1 -1
- package/src/pre-traffic-hooks.ts +1 -1
- package/src/scheduled-tasks.ts +1 -1
- package/src/services.ts +2 -2
- package/src/sns-http-proxy.ts +1 -1
|
@@ -23,7 +23,7 @@ class DynamoDbTableCloudFormation {
|
|
|
23
23
|
command: command,
|
|
24
24
|
ttlAttribute: resource.TimeToLiveSpecification?.AttributeName,
|
|
25
25
|
}))))
|
|
26
|
-
.tap(() => this.LOGGER.
|
|
26
|
+
.tap(() => this.LOGGER.debug('configured'))
|
|
27
27
|
.then((service) => service.start(config));
|
|
28
28
|
this.stop = () => Promise.resolve();
|
|
29
29
|
this.createTableCommand = async (definition, throughput) => new client_dynamodb_1.CreateTableCommand({
|
|
@@ -17,7 +17,7 @@ class CloudFormationSetup {
|
|
|
17
17
|
.then(async (routes) => this.afterStart(this.name, config, routes));
|
|
18
18
|
this.resolvedHandlers = async () => {
|
|
19
19
|
const template = this.template(this.name);
|
|
20
|
-
this.LOGGER.
|
|
20
|
+
this.LOGGER.debug('parsing %s', template);
|
|
21
21
|
const definition = this.parseApiEvents(template);
|
|
22
22
|
const functions = this.handlers(this.name);
|
|
23
23
|
const routes = Object.values(definition)
|
|
@@ -33,7 +33,7 @@ class CloudFormationSetup {
|
|
|
33
33
|
this.handlerResolver(event, handler) :
|
|
34
34
|
Promise.reject(new Error(`function ${event.Handler} defined in ${(0, path_1.resolve)(template)} not found in ${(0, path_1.resolve)(functions)}`)))
|
|
35
35
|
.then((handler) => {
|
|
36
|
-
this.LOGGER.
|
|
36
|
+
this.LOGGER.debug(this.logHandler(handler));
|
|
37
37
|
return handler;
|
|
38
38
|
})));
|
|
39
39
|
return Promise.all(routes);
|
package/dist/src/container.js
CHANGED
|
@@ -10,7 +10,7 @@ class Container {
|
|
|
10
10
|
constructor(name, image, networkAlias, environment, bindMounts, exposedPorts, logConsumer, startup, endpointBuilder) {
|
|
11
11
|
this.name = name;
|
|
12
12
|
this.networkAlias = networkAlias;
|
|
13
|
-
this.start = async (config) => Promise.resolve(this.LOGGER.
|
|
13
|
+
this.start = async (config) => Promise.resolve(this.LOGGER.debug('start'))
|
|
14
14
|
.then(() => this.container
|
|
15
15
|
.withNetwork(config.network)
|
|
16
16
|
.withNetworkAliases(this.networkAlias)
|
package/dist/src/deferred.js
CHANGED
|
@@ -19,7 +19,7 @@ class Lazy {
|
|
|
19
19
|
async start(config) {
|
|
20
20
|
const local = this.configurable(config);
|
|
21
21
|
this.started = local;
|
|
22
|
-
this.LOGGER.
|
|
22
|
+
this.LOGGER.debug('DISCOVERY:%s', local.name);
|
|
23
23
|
return local.start(config);
|
|
24
24
|
}
|
|
25
25
|
withStartedOr(task, fallback) {
|
|
@@ -38,8 +38,8 @@ class Promised {
|
|
|
38
38
|
this.start = async (config) => configurable(config)
|
|
39
39
|
.catch((e) => e?.cleanup?.() ?? Promise.reject(e))
|
|
40
40
|
.then((service) => initialized = service)
|
|
41
|
-
.tap((service) => this.LOGGER.
|
|
41
|
+
.tap((service) => this.LOGGER.debug('DISCOVERY:%s', service.name))
|
|
42
42
|
.then((service) => service.start(config));
|
|
43
|
-
this.stop = async () => (initialized ?? { stop: async () => this.LOGGER.
|
|
43
|
+
this.stop = async () => (initialized ?? { stop: async () => this.LOGGER.warn('not started') }).stop();
|
|
44
44
|
}
|
|
45
45
|
}
|
package/dist/src/dynamodb.js
CHANGED
|
@@ -24,7 +24,7 @@ class DynamoDbTableCreator {
|
|
|
24
24
|
AttributeName: attributeName,
|
|
25
25
|
}
|
|
26
26
|
}))
|
|
27
|
-
.tap((out) => this.LOGGER.
|
|
27
|
+
.tap((out) => this.LOGGER.debug('set ttl attribute %s? %s', attributeName, out.$metadata.httpStatusCode === 200))
|
|
28
28
|
.then(() => undefined);
|
|
29
29
|
this.stop = () => Promise.resolve();
|
|
30
30
|
this.LOGGER = logging_1.LoggerFactory.create(`TABLE[${name}]`);
|
|
@@ -37,9 +37,10 @@ class DynamoDb {
|
|
|
37
37
|
.send(factory) //
|
|
38
38
|
.tap((table) => LOGGER.debug('created %s', (0, assert_1.assertNotUndefined)(table.TableDescription).TableName))
|
|
39
39
|
.catch((reason) => {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
if (reason.name !== 'ResourceInUseException') {
|
|
41
|
+
LOGGER.error('failed to create table');
|
|
42
42
|
return Promise.reject(reason);
|
|
43
|
+
}
|
|
43
44
|
return { TableDescription: { TableName: factory.input.TableName } };
|
|
44
45
|
});
|
|
45
46
|
this.client = new client_dynamodb_1.DynamoDBClient(config);
|
|
@@ -34,11 +34,11 @@ class InternalQueue {
|
|
|
34
34
|
consumer.on('processing_error', (err) => {
|
|
35
35
|
this.LOGGER.error(err, 'failed to process message');
|
|
36
36
|
});
|
|
37
|
-
this.LOGGER.
|
|
37
|
+
this.LOGGER.debug('consumer for %s initialized', name);
|
|
38
38
|
return consumer;
|
|
39
39
|
})
|
|
40
40
|
.then(async (consumer) => consumer.start())
|
|
41
|
-
.then(() => this.LOGGER.
|
|
41
|
+
.then(() => this.LOGGER.debug('started'))
|
|
42
42
|
.then(() => this);
|
|
43
43
|
this.stop = async () => this.consumer !== undefined ? (0, stoppable_1.stopConsumer)(this.visibility, this.consumer) : this.LOGGER.warn('no consumer');
|
|
44
44
|
this.LOGGER = logging_1.LoggerFactory.create(`INTERNALQUEUE[${name}]`);
|
|
@@ -46,7 +46,7 @@ class InternalQueue {
|
|
|
46
46
|
async createQueue(sqs, name) {
|
|
47
47
|
return this.creator(sqs)(name) //
|
|
48
48
|
.then((queue) => {
|
|
49
|
-
this.LOGGER.
|
|
49
|
+
this.LOGGER.debug('created: %s', queue.url);
|
|
50
50
|
return queue;
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -39,7 +39,7 @@ class LambdaHttpProxy {
|
|
|
39
39
|
.find(() => true) ?? this.fallback)(request, body, response);
|
|
40
40
|
this.server = new http_server_1.HttpServer(name, settings, this.resolveRoute);
|
|
41
41
|
this.LOGGER = logging_1.LoggerFactory.create(`HTTP->LAMBDA[${this.name}]`);
|
|
42
|
-
this.LOGGER.
|
|
42
|
+
this.LOGGER.debug('registered %i routes', routes.length);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
class Response {
|
|
@@ -14,6 +14,6 @@ class PreTrafficHooks {
|
|
|
14
14
|
.then(() => undefined);
|
|
15
15
|
this.stop = async () => Promise.resolve();
|
|
16
16
|
this.LOGGER = logging_1.LoggerFactory.create(`PRETRAFFIC[${name}]`);
|
|
17
|
-
this.LOGGER.
|
|
17
|
+
this.LOGGER.debug('%i hooks registered', hooks.length);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -15,6 +15,6 @@ class ScheduledTasks {
|
|
|
15
15
|
.then(() => undefined);
|
|
16
16
|
this.stop = async () => Promise.resolve(this.intervals.forEach((interval) => (0, timers_1.clearInterval)(interval)));
|
|
17
17
|
this.LOGGER = logging_1.LoggerFactory.create(`SCHEDULER[${name}]`);
|
|
18
|
-
this.LOGGER.
|
|
18
|
+
this.LOGGER.debug('registered %i scheduled tasks', schedules.length);
|
|
19
19
|
}
|
|
20
20
|
}
|
package/dist/src/services.js
CHANGED
|
@@ -16,10 +16,10 @@ class Service {
|
|
|
16
16
|
.then(() => Promise.reject(error)))
|
|
17
17
|
.then((started) => this
|
|
18
18
|
.callbackOrDefault(started)
|
|
19
|
-
.then(() => this.LOGGER.
|
|
19
|
+
.then(() => this.LOGGER.debug('started'))
|
|
20
20
|
.then(() => started));
|
|
21
21
|
this.doStop = () => stop()
|
|
22
|
-
.then(() => this.LOGGER.
|
|
22
|
+
.then(() => this.LOGGER.debug('stopped'));
|
|
23
23
|
this.stop = () => this.doStop();
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -60,7 +60,7 @@ class SnsHttpProxy {
|
|
|
60
60
|
};
|
|
61
61
|
this.server = new http_server_1.HttpServer(this.name, this.settings, this.handler(this.method, this.subject));
|
|
62
62
|
this.LOGGER = logging_1.LoggerFactory.create(`HTTP->SNS[${name}]`);
|
|
63
|
-
this.LOGGER.
|
|
63
|
+
this.LOGGER.debug('forwarding %s %s events to %s', subject ? `events with ${subject} subject` : 'all', method, topic ?? 'the event bus');
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
exports.SnsHttpProxy = SnsHttpProxy;
|
package/package.json
CHANGED
|
@@ -42,7 +42,7 @@ class DynamoDbTableCloudFormation implements Lifecycle<string> {
|
|
|
42
42
|
command: command,
|
|
43
43
|
ttlAttribute: resource.TimeToLiveSpecification?.AttributeName,
|
|
44
44
|
}))))
|
|
45
|
-
.tap(() => this.LOGGER.
|
|
45
|
+
.tap(() => this.LOGGER.debug('configured'))
|
|
46
46
|
.then((service) => service.start(config))
|
|
47
47
|
|
|
48
48
|
stop = () => Promise.resolve()
|
package/src/cloudformation.ts
CHANGED
|
@@ -32,7 +32,7 @@ export abstract class CloudFormationSetup<P, H, R, F> implements Startable<F> {
|
|
|
32
32
|
|
|
33
33
|
private resolvedHandlers = async (): Promise<R[]> => {
|
|
34
34
|
const template = this.template(this.name);
|
|
35
|
-
this.LOGGER.
|
|
35
|
+
this.LOGGER.debug('parsing %s', template);
|
|
36
36
|
const definition = this.parseApiEvents(template);
|
|
37
37
|
const functions = this.handlers(this.name);
|
|
38
38
|
const routes = Object.values(definition)
|
|
@@ -53,7 +53,7 @@ export abstract class CloudFormationSetup<P, H, R, F> implements Startable<F> {
|
|
|
53
53
|
this.handlerResolver(event, handler) :
|
|
54
54
|
Promise.reject(new Error(`function ${event.Handler} defined in ${resolve(template)} not found in ${resolve(functions)}`)))
|
|
55
55
|
.then((handler) => {
|
|
56
|
-
this.LOGGER.
|
|
56
|
+
this.LOGGER.debug(this.logHandler(handler));
|
|
57
57
|
return handler;
|
|
58
58
|
}),
|
|
59
59
|
),
|
package/src/container.ts
CHANGED
|
@@ -68,7 +68,7 @@ class Container implements Lifecycle<string> {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
start = async (config: DevServerConfig) =>
|
|
71
|
-
Promise.resolve(this.LOGGER.
|
|
71
|
+
Promise.resolve(this.LOGGER.debug('start'))
|
|
72
72
|
.then(() => this.container
|
|
73
73
|
.withNetwork(config.network)
|
|
74
74
|
.withNetworkAliases(this.networkAlias)
|
package/src/deferred.ts
CHANGED
|
@@ -20,7 +20,7 @@ class Lazy<I> implements Lifecycle<I> {
|
|
|
20
20
|
async start(config: DevServerConfig) {
|
|
21
21
|
const local = this.configurable(config);
|
|
22
22
|
this.started = local;
|
|
23
|
-
this.LOGGER.
|
|
23
|
+
this.LOGGER.debug('DISCOVERY:%s', local.name)
|
|
24
24
|
return local.start(config);
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -52,9 +52,9 @@ class Promised<I> implements Lifecycle<I> {
|
|
|
52
52
|
configurable(config)
|
|
53
53
|
.catch((e) => e?.cleanup?.() ?? Promise.reject(e))
|
|
54
54
|
.then((service) => initialized = service)
|
|
55
|
-
.tap((service) => this.LOGGER.
|
|
55
|
+
.tap((service) => this.LOGGER.debug('DISCOVERY:%s', service.name))
|
|
56
56
|
.then((service) => service.start(config))
|
|
57
57
|
|
|
58
|
-
this.stop = async () => (initialized ?? { stop: async () => this.LOGGER.
|
|
58
|
+
this.stop = async () => (initialized ?? { stop: async () => this.LOGGER.warn('not started') }).stop()
|
|
59
59
|
}
|
|
60
60
|
}
|
package/src/dynamodb.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import {CreateTableCommand, DynamoDBClient, UpdateTimeToLiveCommand} from "@aws-sdk/client-dynamodb";
|
|
2
|
+
import {AwsConfig, DevServerConfig} from "./config";
|
|
3
|
+
import {Logger, LoggerFactory} from "@yopdev/logging";
|
|
4
|
+
import {Lifecycle, Service, Callback} from "./services";
|
|
5
|
+
import {assertNotUndefined} from "./assert";
|
|
6
6
|
|
|
7
7
|
export const newDynamoDbTable = (
|
|
8
8
|
name: string,
|
|
@@ -15,6 +15,7 @@ export const newDynamoDbTable = (
|
|
|
15
15
|
|
|
16
16
|
class DynamoDbTableCreator implements Lifecycle<string> {
|
|
17
17
|
private LOGGER: Logger;
|
|
18
|
+
|
|
18
19
|
constructor(
|
|
19
20
|
readonly name: string,
|
|
20
21
|
private readonly command: CreateTableCommand,
|
|
@@ -37,13 +38,14 @@ class DynamoDbTableCreator implements Lifecycle<string> {
|
|
|
37
38
|
AttributeName: attributeName,
|
|
38
39
|
}
|
|
39
40
|
}))
|
|
40
|
-
.tap((out) => this.LOGGER.
|
|
41
|
+
.tap((out) => this.LOGGER.debug('set ttl attribute %s? %s', attributeName, out.$metadata.httpStatusCode === 200))
|
|
41
42
|
.then(() => undefined)
|
|
42
43
|
|
|
43
44
|
stop = () => Promise.resolve()
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
const LOGGER = LoggerFactory.create('DYNAMODB');
|
|
48
|
+
|
|
47
49
|
export class DynamoDb {
|
|
48
50
|
readonly client: DynamoDBClient
|
|
49
51
|
|
|
@@ -55,8 +57,10 @@ export class DynamoDb {
|
|
|
55
57
|
.send(factory) //
|
|
56
58
|
.tap((table) => LOGGER.debug('created %s', assertNotUndefined(table.TableDescription).TableName))
|
|
57
59
|
.catch((reason) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
if (reason.name !== 'ResourceInUseException') {
|
|
61
|
+
LOGGER.error('failed to create table')
|
|
62
|
+
return Promise.reject(reason);
|
|
63
|
+
}
|
|
64
|
+
return {TableDescription: {TableName: factory.input.TableName}}
|
|
61
65
|
})
|
|
62
66
|
}
|
package/src/internal-queue.ts
CHANGED
|
@@ -52,7 +52,7 @@ class InternalQueue implements Lifecycle<string> {
|
|
|
52
52
|
private async createQueue(sqs: Sqs, name: string) {
|
|
53
53
|
return this.creator(sqs)(name) //
|
|
54
54
|
.then((queue) => {
|
|
55
|
-
this.LOGGER.
|
|
55
|
+
this.LOGGER.debug('created: %s', queue.url);
|
|
56
56
|
return queue;
|
|
57
57
|
});
|
|
58
58
|
}
|
|
@@ -78,11 +78,11 @@ class InternalQueue implements Lifecycle<string> {
|
|
|
78
78
|
consumer.on('processing_error', (err) => {
|
|
79
79
|
this.LOGGER.error(err, 'failed to process message');
|
|
80
80
|
});
|
|
81
|
-
this.LOGGER.
|
|
81
|
+
this.LOGGER.debug('consumer for %s initialized', name);
|
|
82
82
|
return consumer;
|
|
83
83
|
})
|
|
84
84
|
.then(async (consumer) => consumer.start())
|
|
85
|
-
.then(() => this.LOGGER.
|
|
85
|
+
.then(() => this.LOGGER.debug('started'))
|
|
86
86
|
.then(() => this)
|
|
87
87
|
|
|
88
88
|
stop = async () => this.consumer !== undefined ? stopConsumer(this.visibility, this.consumer) : this.LOGGER.warn('no consumer')
|
package/src/lambda-http-proxy.ts
CHANGED
|
@@ -40,7 +40,7 @@ class LambdaHttpProxy<Context, Event, HandlerResponse> implements Lifecycle<stri
|
|
|
40
40
|
) {
|
|
41
41
|
this.server = new HttpServer(name, settings, this.resolveRoute)
|
|
42
42
|
this.LOGGER = LoggerFactory.create(`HTTP->LAMBDA[${this.name}]`);
|
|
43
|
-
this.LOGGER.
|
|
43
|
+
this.LOGGER.debug('registered %i routes', routes.length)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
start = () => this.server.start()
|
package/src/pre-traffic-hooks.ts
CHANGED
|
@@ -13,7 +13,7 @@ class PreTrafficHooks implements Lifecycle<void> {
|
|
|
13
13
|
private readonly hooks: () => Promise<void>[]
|
|
14
14
|
) {
|
|
15
15
|
this.LOGGER = LoggerFactory.create(`PRETRAFFIC[${name}]`);
|
|
16
|
-
this.LOGGER.
|
|
16
|
+
this.LOGGER.debug('%i hooks registered', hooks.length);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
start = async () => Promise
|
package/src/scheduled-tasks.ts
CHANGED
|
@@ -12,7 +12,7 @@ class ScheduledTasks implements Lifecycle<void> {
|
|
|
12
12
|
|
|
13
13
|
constructor(readonly name: string, private readonly schedules: Rate[]) {
|
|
14
14
|
this.LOGGER = LoggerFactory.create(`SCHEDULER[${name}]`)
|
|
15
|
-
this.LOGGER.
|
|
15
|
+
this.LOGGER.debug('registered %i scheduled tasks', schedules.length);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
intervals: NodeJS.Timeout[] = [];
|
package/src/services.ts
CHANGED
|
@@ -34,11 +34,11 @@ export class Service<I> implements Lifecycle<I> {
|
|
|
34
34
|
)
|
|
35
35
|
.then((started) => this
|
|
36
36
|
.callbackOrDefault(started)
|
|
37
|
-
.then(() => this.LOGGER.
|
|
37
|
+
.then(() => this.LOGGER.debug('started'))
|
|
38
38
|
.then(() => started)
|
|
39
39
|
)
|
|
40
40
|
this.doStop = () => stop()
|
|
41
|
-
.then(() => this.LOGGER.
|
|
41
|
+
.then(() => this.LOGGER.debug('stopped'))
|
|
42
42
|
this.stop = () => this.doStop();
|
|
43
43
|
}
|
|
44
44
|
|
package/src/sns-http-proxy.ts
CHANGED
|
@@ -40,7 +40,7 @@ export class SnsHttpProxy implements Lifecycle<string> {
|
|
|
40
40
|
this.handler(this.method, this.subject)
|
|
41
41
|
)
|
|
42
42
|
this.LOGGER = LoggerFactory.create(`HTTP->SNS[${name}]`)
|
|
43
|
-
this.LOGGER.
|
|
43
|
+
this.LOGGER.debug(
|
|
44
44
|
'forwarding %s %s events to %s',
|
|
45
45
|
subject ? `events with ${subject} subject` : 'all',
|
|
46
46
|
method,
|