Skip to content

Commit 0664f82

Browse files
committed
build: upgrade typescript-related package versions
1 parent 6ae97c4 commit 0664f82

5 files changed

Lines changed: 59 additions & 48 deletions

File tree

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
"@silvermine/chai-strictly-equal": "1.1.1",
3232
"@silvermine/eslint-config": "3.1.0-beta.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",
@@ -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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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 '.';
66
import _ from 'underscore';
77
import { isErrorWithStatusCode } from './interfaces';
@@ -102,28 +102,26 @@ export default class Application extends Router {
102102
}
103103

104104
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];
105+
const newContext: Writable<HandlerContext> = {
106+
functionName: context.functionName,
107+
functionVersion: context.functionVersion,
108+
invokedFunctionArn: context.invokedFunctionArn,
109+
memoryLimitInMB: context.memoryLimitInMB,
110+
awsRequestId: context.awsRequestId,
111+
logGroupName: context.logGroupName,
112+
logStreamName: context.logStreamName,
113+
getRemainingTimeInMillis: context.getRemainingTimeInMillis,
114+
};
115+
116+
if (!isUndefined(context.identity)) {
117+
newContext.identity = Object.freeze({ ...context.identity });
118+
}
116119

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>);
120+
if (!isUndefined(context.clientContext)) {
121+
newContext.clientContext = Object.freeze({ ...context.clientContext });
122+
}
125123

126-
return Object.freeze(handlerContext);
124+
return Object.freeze(newContext);
127125
}
128126

129127
}

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/integration-tests.test.ts

Lines changed: 8 additions & 7 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) {

0 commit comments

Comments
 (0)