skuba 4.2.1-beta.0 → 4.2.1
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/README.md +1 -1
- package/lib/api/jest/index.d.ts +26 -11
- package/lib/cli/adapter/eslint.d.ts +2 -1
- package/lib/cli/adapter/eslint.js +5 -1
- package/lib/cli/adapter/eslint.js.map +1 -1
- package/lib/cli/lint/annotate/buildkite/index.js.map +1 -1
- package/lib/cli/lint/autofix.d.ts +7 -1
- package/lib/cli/lint/autofix.js +14 -7
- package/lib/cli/lint/autofix.js.map +1 -1
- package/lib/cli/lint/external.js +16 -16
- package/lib/cli/lint/external.js.map +1 -1
- package/lib/cli/test/reporters/github/index.d.ts +2 -2
- package/lib/cli/test/reporters/github/index.js +11 -1
- package/lib/cli/test/reporters/github/index.js.map +1 -1
- package/lib/utils/args.js +1 -1
- package/lib/utils/args.js.map +1 -1
- package/lib/utils/error.d.ts +14 -0
- package/lib/utils/error.js +14 -1
- package/lib/utils/error.js.map +1 -1
- package/lib/utils/version.js +3 -4
- package/lib/utils/version.js.map +1 -1
- package/lib/utils/wait.d.ts +17 -0
- package/lib/utils/wait.js +32 -0
- package/lib/utils/wait.js.map +1 -0
- package/package.json +18 -19
- package/template/express-rest-api/.buildkite/pipeline.yml +2 -1
- package/template/greeter/.buildkite/pipeline.yml +2 -1
- package/template/koa-rest-api/.buildkite/pipeline.yml +2 -1
- package/template/koa-rest-api/package.json +5 -5
- package/template/koa-rest-api/src/api/jobs/getJobs.ts +2 -2
- package/template/koa-rest-api/src/api/jobs/postJob.ts +2 -2
- package/template/koa-rest-api/src/framework/logging.ts +8 -5
- package/template/koa-rest-api/src/framework/metrics.ts +2 -2
- package/template/koa-rest-api/src/framework/server.test.ts +21 -21
- package/template/koa-rest-api/src/framework/server.ts +4 -3
- package/template/koa-rest-api/src/listen.ts +2 -2
- package/template/koa-rest-api/src/testing/logging.ts +5 -20
- package/template/lambda-sqs-worker/.buildkite/pipeline.yml +2 -1
- package/template/lambda-sqs-worker/.nvmrc +1 -1
- package/template/lambda-sqs-worker/Dockerfile +1 -1
- package/template/lambda-sqs-worker/package.json +4 -4
- package/template/lambda-sqs-worker/serverless.yml +2 -2
- package/template/lambda-sqs-worker/src/app.test.ts +9 -9
- package/template/lambda-sqs-worker/src/app.ts +2 -1
- package/template/lambda-sqs-worker/src/framework/handler.test.ts +10 -10
- package/template/lambda-sqs-worker/src/framework/handler.ts +14 -17
- package/template/lambda-sqs-worker/src/framework/logging.ts +11 -6
- package/template/lambda-sqs-worker/src/testing/logging.ts +7 -5
- package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +2 -1
- package/template/lambda-sqs-worker-cdk/.nvmrc +1 -1
- package/template/lambda-sqs-worker-cdk/Dockerfile +1 -1
- package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +2 -2
- package/template/lambda-sqs-worker-cdk/infra/appStack.ts +1 -1
- package/template/lambda-sqs-worker-cdk/package.json +9 -11
- package/template/private-npm-package/.buildkite/pipeline.yml +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createCtx } from 'src/testing/handler';
|
|
2
|
-
import {
|
|
2
|
+
import { logger } from 'src/testing/logging';
|
|
3
3
|
import { chance } from 'src/testing/types';
|
|
4
4
|
|
|
5
5
|
import { createHandler } from './handler';
|
|
@@ -8,14 +8,14 @@ describe('createHandler', () => {
|
|
|
8
8
|
const ctx = createCtx();
|
|
9
9
|
const input = chance.paragraph();
|
|
10
10
|
|
|
11
|
-
beforeAll(
|
|
11
|
+
beforeAll(logger.spy);
|
|
12
12
|
|
|
13
|
-
afterEach(
|
|
13
|
+
afterEach(logger.clear);
|
|
14
14
|
|
|
15
15
|
it('handles happy path', async () => {
|
|
16
16
|
const output = chance.paragraph();
|
|
17
17
|
|
|
18
|
-
const handler = createHandler((event
|
|
18
|
+
const handler = createHandler((event) => {
|
|
19
19
|
expect(event).toBe(input);
|
|
20
20
|
|
|
21
21
|
logger.info('hello from handler');
|
|
@@ -25,9 +25,9 @@ describe('createHandler', () => {
|
|
|
25
25
|
|
|
26
26
|
await expect(handler(input, ctx)).resolves.toBe(output);
|
|
27
27
|
|
|
28
|
-
expect(
|
|
28
|
+
expect(logger.error).not.toBeCalled();
|
|
29
29
|
|
|
30
|
-
expect(
|
|
30
|
+
expect(logger.info.mock.calls).toEqual([
|
|
31
31
|
['hello from handler'],
|
|
32
32
|
['request'],
|
|
33
33
|
]);
|
|
@@ -40,9 +40,9 @@ describe('createHandler', () => {
|
|
|
40
40
|
|
|
41
41
|
await expect(handler(input, ctx)).rejects.toThrow('invoke error');
|
|
42
42
|
|
|
43
|
-
expect(
|
|
43
|
+
expect(logger.error.mock.calls).toEqual([[{ err }, 'request']]);
|
|
44
44
|
|
|
45
|
-
expect(
|
|
45
|
+
expect(logger.info).not.toBeCalled();
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it('handles sync error', async () => {
|
|
@@ -54,8 +54,8 @@ describe('createHandler', () => {
|
|
|
54
54
|
|
|
55
55
|
await expect(handler(input, ctx)).rejects.toThrow('invoke error');
|
|
56
56
|
|
|
57
|
-
expect(
|
|
57
|
+
expect(logger.error.mock.calls).toEqual([[{ err }, 'request']]);
|
|
58
58
|
|
|
59
|
-
expect(
|
|
59
|
+
expect(logger.info).not.toBeCalled();
|
|
60
60
|
});
|
|
61
61
|
});
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { Logger } from '@seek/logger';
|
|
2
1
|
import { Context } from 'aws-lambda';
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { logger, loggerContext } from 'src/framework/logging';
|
|
5
4
|
|
|
6
|
-
export const createHandler =
|
|
7
|
-
fn: (event: Event
|
|
8
|
-
) =>
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
export const createHandler =
|
|
6
|
+
<Event, Output = unknown>(fn: (event: Event) => Promise<Output>) =>
|
|
7
|
+
(event: Event, { awsRequestId }: Context) =>
|
|
8
|
+
loggerContext.run({ awsRequestId }, async () => {
|
|
9
|
+
try {
|
|
10
|
+
const output = await fn(event);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
const output = await fn(event, { logger });
|
|
12
|
+
logger.info('request');
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
return output;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
logger.error({ err }, 'request');
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
throw new Error('invoke error');
|
|
22
|
-
}
|
|
23
|
-
};
|
|
18
|
+
throw new Error('invoke error');
|
|
19
|
+
}
|
|
20
|
+
});
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
|
|
1
3
|
import createLogger from '@seek/logger';
|
|
2
|
-
import { Context } from 'aws-lambda';
|
|
3
4
|
|
|
4
5
|
import { config } from 'src/config';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
interface LoggerContext {
|
|
8
|
+
awsRequestId: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const loggerContext = new AsyncLocalStorage<LoggerContext>();
|
|
12
|
+
|
|
13
|
+
export const logger = createLogger({
|
|
7
14
|
base: {
|
|
8
15
|
environment: config.environment,
|
|
9
16
|
version: config.version,
|
|
@@ -11,12 +18,10 @@ export const rootLogger = createLogger({
|
|
|
11
18
|
|
|
12
19
|
level: config.logLevel,
|
|
13
20
|
|
|
21
|
+
mixin: () => loggerContext.getStore() ?? {},
|
|
22
|
+
|
|
14
23
|
name: config.name,
|
|
15
24
|
|
|
16
25
|
transport:
|
|
17
26
|
config.environment === 'local' ? { target: 'pino-pretty' } : undefined,
|
|
18
27
|
});
|
|
19
|
-
|
|
20
|
-
/* istanbul ignore next: @seek/logger interface */
|
|
21
|
-
export const contextLogger = ({ awsRequestId }: Context) =>
|
|
22
|
-
rootLogger.child({ awsRequestId });
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import * as logging from 'src/framework/logging';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const logger = {
|
|
4
4
|
error: jest.fn(),
|
|
5
5
|
info: jest.fn(),
|
|
6
6
|
|
|
7
7
|
clear: () => {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
logger.error.mockClear();
|
|
9
|
+
logger.info.mockClear();
|
|
10
10
|
},
|
|
11
11
|
|
|
12
|
-
spy: () =>
|
|
13
|
-
jest.spyOn(logging, '
|
|
12
|
+
spy: () => {
|
|
13
|
+
jest.spyOn(logging.logger, 'error').mockImplementation(logger.error);
|
|
14
|
+
jest.spyOn(logging.logger, 'info').mockImplementation(logger.info);
|
|
15
|
+
},
|
|
14
16
|
};
|
|
@@ -9,7 +9,7 @@ configs:
|
|
|
9
9
|
NPM_READ_TOKEN: arn:aws:secretsmanager:ap-southeast-2:987872074697:secret:npm/npm-read-token
|
|
10
10
|
|
|
11
11
|
- &docker-ecr-cache
|
|
12
|
-
seek-oss/docker-ecr-cache#
|
|
12
|
+
seek-oss/docker-ecr-cache#v2.0.0:
|
|
13
13
|
cache-on:
|
|
14
14
|
- package.json
|
|
15
15
|
- yarn.lock
|
|
@@ -59,6 +59,7 @@ steps:
|
|
|
59
59
|
- *docker-ecr-cache
|
|
60
60
|
- docker-compose#v3.9.0:
|
|
61
61
|
run: app
|
|
62
|
+
timeout_in_minutes: 10
|
|
62
63
|
|
|
63
64
|
- agents:
|
|
64
65
|
queue: <%- devBuildkiteQueueName %>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
16
|
|
@@ -174,7 +174,7 @@ Object {
|
|
|
174
174
|
"Arn",
|
|
175
175
|
],
|
|
176
176
|
},
|
|
177
|
-
"Runtime": "
|
|
177
|
+
"Runtime": "nodejs16.x",
|
|
178
178
|
},
|
|
179
179
|
"Type": "AWS::Lambda::Function",
|
|
180
180
|
},
|
|
@@ -530,7 +530,7 @@ Object {
|
|
|
530
530
|
"Arn",
|
|
531
531
|
],
|
|
532
532
|
},
|
|
533
|
-
"Runtime": "
|
|
533
|
+
"Runtime": "nodejs16.x",
|
|
534
534
|
},
|
|
535
535
|
"Type": "AWS::Lambda::Function",
|
|
536
536
|
},
|
|
@@ -52,7 +52,7 @@ export class AppStack extends Stack {
|
|
|
52
52
|
|
|
53
53
|
const worker = new aws_lambda.Function(this, 'worker', {
|
|
54
54
|
code: new aws_lambda.AssetCode('./lib'),
|
|
55
|
-
runtime: aws_lambda.Runtime.
|
|
55
|
+
runtime: aws_lambda.Runtime.NODEJS_16_X,
|
|
56
56
|
handler: 'app.handler',
|
|
57
57
|
functionName: '<%- serviceName %>',
|
|
58
58
|
environmentEncryption: kmsKey,
|
|
@@ -4,12 +4,16 @@
|
|
|
4
4
|
"runtypes": "^6.3.2"
|
|
5
5
|
},
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@aws-cdk/assert": "^2.
|
|
7
|
+
"@aws-cdk/assert": "^2.24.0",
|
|
8
8
|
"@types/aws-lambda": "^8.10.82",
|
|
9
|
-
"@types/node": "^
|
|
10
|
-
"aws-cdk": "^2.
|
|
11
|
-
"aws-cdk-lib": "^2.
|
|
12
|
-
"constructs": "^10.0.17"
|
|
9
|
+
"@types/node": "^16.0.0",
|
|
10
|
+
"aws-cdk": "^2.24.0",
|
|
11
|
+
"aws-cdk-lib": "^2.24.0",
|
|
12
|
+
"constructs": "^10.0.17",
|
|
13
|
+
"skuba": "*"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=16"
|
|
13
17
|
},
|
|
14
18
|
"license": "UNLICENSED",
|
|
15
19
|
"private": true,
|
|
@@ -22,11 +26,5 @@
|
|
|
22
26
|
"test": "skuba test",
|
|
23
27
|
"test:ci": "skuba test --coverage",
|
|
24
28
|
"test:watch": "skuba test --watch"
|
|
25
|
-
},
|
|
26
|
-
"skuba": {
|
|
27
|
-
"entryPoint": "src/app.ts#handler",
|
|
28
|
-
"template": "lambda-sqs-worker-cdk",
|
|
29
|
-
"type": "application",
|
|
30
|
-
"version": "3.16.2"
|
|
31
29
|
}
|
|
32
30
|
}
|