Skip to content

Commit 42c404d

Browse files
authored
Merge pull request #89 from silvermine/ts-eslint-upgrades
build: update TS and eslint packages
2 parents 6ae97c4 + b9d009c commit 42c404d

File tree

7 files changed

+644
-744
lines changed

7 files changed

+644
-744
lines changed

package-lock.json

Lines changed: 592 additions & 692 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929
"homepage": "https://github.com/silvermine/lambda-express#readme",
3030
"devDependencies": {
3131
"@silvermine/chai-strictly-equal": "1.1.1",
32-
"@silvermine/eslint-config": "3.1.0-beta.0",
32+
"@silvermine/eslint-config": "3.2.0",
3333
"@silvermine/standardization": "2.0.0",
34-
"@silvermine/typescript-config": "0.9.0",
34+
"@silvermine/typescript-config": "1.0.0",
3535
"@types/aws-lambda": "8.10.17",
3636
"@types/chai": "4.1.7",
3737
"@types/cookie": "0.3.2",
3838
"@types/mocha": "5.2.5",
39-
"@types/node": "8.10.36",
39+
"@types/node": "20.12.2",
4040
"@types/qs": "6.5.1",
4141
"@types/sinon": "5.0.5",
4242
"@types/underscore": "1.8.9",
4343
"chai": "4.2.0",
4444
"coveralls": "3.0.2",
4545
"cz-conventional-changelog": "3.1.0",
46-
"eslint": "6.8.0",
46+
"eslint": "8.57.0",
4747
"grunt": "1.4.1",
4848
"grunt-cli": "1.3.2",
4949
"grunt-concurrent": "2.3.1",
@@ -56,7 +56,7 @@
5656
"source-map-support": "0.5.9",
5757
"standard-version": "git+https://github.com/jthomerson/standard-version.git#fix-305-header-repeat",
5858
"ts-node": "7.0.1",
59-
"typescript": "3.2.2"
59+
"typescript": "4.7.4"
6060
},
6161
"dependencies": {
6262
"@silvermine/toolbox": "0.1.0",

src/Application.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Callback, Context } from 'aws-lambda';
22
import Router from './Router';
33
import { RequestEvent, HandlerContext } from './request-response-types';
4-
import { StringUnknownMap, Writable } from '@silvermine/toolbox';
4+
import { isUndefined, StringUnknownMap, Writable } from '@silvermine/toolbox';
55
import { Request, Response } from '.';
6-
import _ from 'underscore';
76
import { isErrorWithStatusCode } from './interfaces';
87

98
export default class Application extends Router {
@@ -102,28 +101,26 @@ export default class Application extends Router {
102101
}
103102

104103
private _createHandlerContext(context: Context): HandlerContext {
105-
// keys should exist on both `HandlerContext` and `Context`
106-
const keys: (keyof HandlerContext & keyof Context)[] = [
107-
'functionName', 'functionVersion', 'invokedFunctionArn', 'memoryLimitInMB',
108-
'awsRequestId', 'logGroupName', 'logStreamName', 'identity', 'clientContext',
109-
'getRemainingTimeInMillis',
110-
];
111-
112-
let handlerContext: Writable<HandlerContext>;
113-
114-
handlerContext = _.reduce(keys, (memo, key) => {
115-
let contextValue = context[key];
104+
const newContext: Writable<HandlerContext> = {
105+
functionName: context.functionName,
106+
functionVersion: context.functionVersion,
107+
invokedFunctionArn: context.invokedFunctionArn,
108+
memoryLimitInMB: context.memoryLimitInMB,
109+
awsRequestId: context.awsRequestId,
110+
logGroupName: context.logGroupName,
111+
logStreamName: context.logStreamName,
112+
getRemainingTimeInMillis: context.getRemainingTimeInMillis,
113+
};
114+
115+
if (!isUndefined(context.identity)) {
116+
newContext.identity = Object.freeze({ ...context.identity });
117+
}
116118

117-
if (typeof contextValue === 'object' && contextValue) {
118-
// Freeze sub-objects
119-
memo[key] = Object.freeze(_.extend({}, contextValue));
120-
} else if (typeof contextValue !== 'undefined') {
121-
memo[key] = contextValue;
122-
}
123-
return memo;
124-
}, {} as Writable<HandlerContext>);
119+
if (!isUndefined(context.clientContext)) {
120+
newContext.clientContext = Object.freeze({ ...context.clientContext });
121+
}
125122

126-
return Object.freeze(handlerContext);
123+
return Object.freeze(newContext);
127124
}
128125

129126
}

tests/Request.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
apiGatewayRequestRawQuery,
1212
albMultiValHeadersRawQuery,
1313
} from './samples';
14-
import { isKeyValueStringObject } from '@silvermine/toolbox';
14+
import { isKeyValueStringObject, Optional } from '@silvermine/toolbox';
1515
import ConsoleLogger from '../src/logging/ConsoleLogger';
1616
import sinon from 'sinon';
1717
import { DebugLogObject } from '../src/logging/logging-types';
@@ -44,13 +44,16 @@ describe('Request', () => {
4444
expect(new Request(app, albRequest(), handlerContext()).method).to.strictlyEqual('GET');
4545
expect(new Request(app, _.extend({}, albRequest(), { httpMethod: 'get' }), handlerContext()).method).to.strictlyEqual('GET');
4646
expect(new Request(app, _.extend({}, albRequest(), { httpMethod: 'PoSt' }), handlerContext()).method).to.strictlyEqual('POST');
47+
});
4748

48-
// make sure that undefined values don't break it:
49-
let evt2: RequestEvent = albRequest();
49+
// TODO: Why is this test here? It was added during initial implementation but none
50+
// of the types agree with this test.
51+
it('an undefined `httpMethod` doesn\'t break the setting of `method`', () => {
52+
let evt2: Optional<RequestEvent, 'httpMethod'> = albRequest();
5053

5154
delete evt2.httpMethod;
5255
expect(evt2.httpMethod).to.strictlyEqual(undefined);
53-
expect(new Request(app, evt2, handlerContext()).method).to.strictlyEqual('');
56+
expect(new Request(app, evt2 as RequestEvent, handlerContext()).method).to.strictlyEqual('');
5457
});
5558

5659
it('sets URL related fields correctly, when created from an event', () => {

tests/Response.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class TestResponse extends Response {
2020

2121
}
2222

23+
const EMPTY_CB = (): void => {}; // eslint-disable-line no-empty-function
24+
2325
describe('Response', () => {
24-
const EMPTY_CB = (): void => {}; // eslint-disable-line no-empty-function
2526

2627
let app: Application, sampleReq: Request, sampleResp: Response;
2728

@@ -1020,8 +1021,6 @@ describe('Response', () => {
10201021
});
10211022

10221023
describe('send', () => {
1023-
type Extender = (resp: Response, output: any) => void;
1024-
10251024
const test = (evt: RequestEvent, code: number, msg: string | false, body: any, extender?: Extender): void => {
10261025
let output = makeOutput(code, msg, body);
10271026

tests/integration-tests.test.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from './samples';
99
import { spy, SinonSpy, assert } from 'sinon';
1010
import { Application, Request, Response, Router } from '../src';
11-
import { RequestEvent } from '../src/request-response-types';
11+
import { RequestEvent, ResponseResult } from '../src/request-response-types';
1212
import { NextCallback, IRoute, IRouter, ErrorWithStatusCode } from '../src/interfaces';
1313
import { expect } from 'chai';
1414
import { StringArrayOfStringsMap, StringMap, KeyValueStringObject } from '@silvermine/toolbox';
@@ -369,20 +369,21 @@ describe('integration tests', () => {
369369

370370
app.run(evt, handlerContext(), cb);
371371

372-
const expectedCallbackValue = {
372+
const expectedCallbackValue: ResponseResult = {
373373
statusCode: code,
374374
statusDescription: desc,
375375
body: expectedBody,
376376
isBase64Encoded: false,
377-
headers: {
378-
'X-Did-Run-All-Hello-World': 'true',
379-
} as StringMap,
380377
multiValueHeaders: {
381378
'X-Did-Run-All-Hello-World': [ 'true' ],
382-
} as StringArrayOfStringsMap,
379+
},
380+
};
381+
382+
expectedCallbackValue.headers = {
383+
'X-Did-Run-All-Hello-World': 'true',
384+
[hdrName]: hdrVal,
383385
};
384386

385-
expectedCallbackValue.headers[hdrName] = hdrVal;
386387
expectedCallbackValue.multiValueHeaders[hdrName] = [ hdrVal ];
387388

388389
if (contentType) {
@@ -729,14 +730,14 @@ describe('integration tests', () => {
729730
it('updates path params when `request.url` changes to a URL with different path params', () => {
730731
const router1 = new Router(),
731732
router2 = new Router(),
732-
USER_ID = '1337',
733-
USERNAME = 'mluedke';
733+
userID = '1337',
734+
username = 'mluedke';
734735

735736
let router1Params, router2Params;
736737

737738
router1.get('/users/:userID', (req: Request, _resp: Response, next: NextCallback) => {
738739
router1Params = req.params;
739-
req.url = `/profile/${USERNAME}`;
740+
req.url = `/profile/${username}`;
740741
next();
741742
});
742743

@@ -748,10 +749,10 @@ describe('integration tests', () => {
748749
app.addSubRouter('/admin', router1);
749750
app.addSubRouter('/admin', router2);
750751

751-
testOutcome('GET', `/admin/users/${USER_ID}`, `${USERNAME} profile`);
752+
testOutcome('GET', `/admin/users/${userID}`, `${username} profile`);
752753

753-
expect(router1Params).to.eql({ userID: USER_ID });
754-
expect(router2Params).to.eql({ username: USERNAME });
754+
expect(router1Params).to.eql({ userID: userID });
755+
expect(router2Params).to.eql({ username: username });
755756
});
756757

757758
});

tests/logging/ConsoleLogger.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import ConsoleLogger from '../../src/logging/ConsoleLogger';
1111
import _ from 'underscore';
1212
import sinon, { SinonSpy } from 'sinon';
1313

14-
describe('ConsoleLogger', () => {
14+
const DEFAULT_LOGGER_CONFIG: LoggerConfig = {
15+
interface: 'ALB',
16+
getTimeUntilFnTimeout: () => { return 0; },
17+
};
1518

16-
const DEFAULT_LOGGER_CONFIG: LoggerConfig = {
17-
interface: 'ALB',
18-
getTimeUntilFnTimeout: () => { return 0; },
19-
};
19+
describe('ConsoleLogger', () => {
2020

2121
interface Spies {
2222
log: SinonSpy;

0 commit comments

Comments
 (0)