Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: update TS and eslint packages #89

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,284 changes: 592 additions & 692 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@
"homepage": "https://github.com/silvermine/lambda-express#readme",
"devDependencies": {
"@silvermine/chai-strictly-equal": "1.1.1",
"@silvermine/eslint-config": "3.1.0-beta.0",
"@silvermine/eslint-config": "3.2.0",
"@silvermine/standardization": "2.0.0",
"@silvermine/typescript-config": "0.9.0",
"@silvermine/typescript-config": "1.0.0",
"@types/aws-lambda": "8.10.17",
"@types/chai": "4.1.7",
"@types/cookie": "0.3.2",
"@types/mocha": "5.2.5",
"@types/node": "8.10.36",
"@types/node": "20.12.2",
"@types/qs": "6.5.1",
"@types/sinon": "5.0.5",
"@types/underscore": "1.8.9",
"chai": "4.2.0",
"coveralls": "3.0.2",
"cz-conventional-changelog": "3.1.0",
"eslint": "6.8.0",
"eslint": "8.57.0",
"grunt": "1.4.1",
"grunt-cli": "1.3.2",
"grunt-concurrent": "2.3.1",
Expand All @@ -56,7 +56,7 @@
"source-map-support": "0.5.9",
"standard-version": "git+https://github.com/jthomerson/standard-version.git#fix-305-header-repeat",
"ts-node": "7.0.1",
"typescript": "3.2.2"
"typescript": "4.7.4"
},
"dependencies": {
"@silvermine/toolbox": "0.1.0",
Expand Down
41 changes: 19 additions & 22 deletions src/Application.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Callback, Context } from 'aws-lambda';
import Router from './Router';
import { RequestEvent, HandlerContext } from './request-response-types';
import { StringUnknownMap, Writable } from '@silvermine/toolbox';
import { isUndefined, StringUnknownMap, Writable } from '@silvermine/toolbox';
import { Request, Response } from '.';
import _ from 'underscore';
import { isErrorWithStatusCode } from './interfaces';

export default class Application extends Router {
Expand Down Expand Up @@ -102,28 +101,26 @@ export default class Application extends Router {
}

private _createHandlerContext(context: Context): HandlerContext {
// keys should exist on both `HandlerContext` and `Context`
const keys: (keyof HandlerContext & keyof Context)[] = [
'functionName', 'functionVersion', 'invokedFunctionArn', 'memoryLimitInMB',
'awsRequestId', 'logGroupName', 'logStreamName', 'identity', 'clientContext',
'getRemainingTimeInMillis',
];

let handlerContext: Writable<HandlerContext>;

handlerContext = _.reduce(keys, (memo, key) => {
let contextValue = context[key];
const newContext: Writable<HandlerContext> = {
functionName: context.functionName,
functionVersion: context.functionVersion,
invokedFunctionArn: context.invokedFunctionArn,
memoryLimitInMB: context.memoryLimitInMB,
awsRequestId: context.awsRequestId,
logGroupName: context.logGroupName,
logStreamName: context.logStreamName,
getRemainingTimeInMillis: context.getRemainingTimeInMillis,
};

if (!isUndefined(context.identity)) {
newContext.identity = Object.freeze({ ...context.identity });
}

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

return Object.freeze(handlerContext);
return Object.freeze(newContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hooray I can read this code now!

}

}
11 changes: 7 additions & 4 deletions tests/Request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
apiGatewayRequestRawQuery,
albMultiValHeadersRawQuery,
} from './samples';
import { isKeyValueStringObject } from '@silvermine/toolbox';
import { isKeyValueStringObject, Optional } from '@silvermine/toolbox';
import ConsoleLogger from '../src/logging/ConsoleLogger';
import sinon from 'sinon';
import { DebugLogObject } from '../src/logging/logging-types';
Expand Down Expand Up @@ -44,13 +44,16 @@ describe('Request', () => {
expect(new Request(app, albRequest(), handlerContext()).method).to.strictlyEqual('GET');
expect(new Request(app, _.extend({}, albRequest(), { httpMethod: 'get' }), handlerContext()).method).to.strictlyEqual('GET');
expect(new Request(app, _.extend({}, albRequest(), { httpMethod: 'PoSt' }), handlerContext()).method).to.strictlyEqual('POST');
});

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

delete evt2.httpMethod;
expect(evt2.httpMethod).to.strictlyEqual(undefined);
expect(new Request(app, evt2, handlerContext()).method).to.strictlyEqual('');
expect(new Request(app, evt2 as RequestEvent, handlerContext()).method).to.strictlyEqual('');
});

it('sets URL related fields correctly, when created from an event', () => {
Expand Down
5 changes: 2 additions & 3 deletions tests/Response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class TestResponse extends Response {

}

const EMPTY_CB = (): void => {}; // eslint-disable-line no-empty-function

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

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

Expand Down Expand Up @@ -1020,8 +1021,6 @@ describe('Response', () => {
});

describe('send', () => {
type Extender = (resp: Response, output: any) => void;

const test = (evt: RequestEvent, code: number, msg: string | false, body: any, extender?: Extender): void => {
let output = makeOutput(code, msg, body);

Expand Down
27 changes: 14 additions & 13 deletions tests/integration-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from './samples';
import { spy, SinonSpy, assert } from 'sinon';
import { Application, Request, Response, Router } from '../src';
import { RequestEvent } from '../src/request-response-types';
import { RequestEvent, ResponseResult } from '../src/request-response-types';
import { NextCallback, IRoute, IRouter, ErrorWithStatusCode } from '../src/interfaces';
import { expect } from 'chai';
import { StringArrayOfStringsMap, StringMap, KeyValueStringObject } from '@silvermine/toolbox';
Expand Down Expand Up @@ -369,20 +369,21 @@ describe('integration tests', () => {

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

const expectedCallbackValue = {
const expectedCallbackValue: ResponseResult = {
statusCode: code,
statusDescription: desc,
body: expectedBody,
isBase64Encoded: false,
headers: {
'X-Did-Run-All-Hello-World': 'true',
} as StringMap,
multiValueHeaders: {
'X-Did-Run-All-Hello-World': [ 'true' ],
} as StringArrayOfStringsMap,
},
};

expectedCallbackValue.headers = {
'X-Did-Run-All-Hello-World': 'true',
[hdrName]: hdrVal,
};

expectedCallbackValue.headers[hdrName] = hdrVal;
expectedCallbackValue.multiValueHeaders[hdrName] = [ hdrVal ];

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

let router1Params, router2Params;

router1.get('/users/:userID', (req: Request, _resp: Response, next: NextCallback) => {
router1Params = req.params;
req.url = `/profile/${USERNAME}`;
req.url = `/profile/${username}`;
next();
});

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

testOutcome('GET', `/admin/users/${USER_ID}`, `${USERNAME} profile`);
testOutcome('GET', `/admin/users/${userID}`, `${username} profile`);

expect(router1Params).to.eql({ userID: USER_ID });
expect(router2Params).to.eql({ username: USERNAME });
expect(router1Params).to.eql({ userID: userID });
expect(router2Params).to.eql({ username: username });
});

});
Expand Down
10 changes: 5 additions & 5 deletions tests/logging/ConsoleLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import ConsoleLogger from '../../src/logging/ConsoleLogger';
import _ from 'underscore';
import sinon, { SinonSpy } from 'sinon';

describe('ConsoleLogger', () => {
const DEFAULT_LOGGER_CONFIG: LoggerConfig = {
interface: 'ALB',
getTimeUntilFnTimeout: () => { return 0; },
};

const DEFAULT_LOGGER_CONFIG: LoggerConfig = {
interface: 'ALB',
getTimeUntilFnTimeout: () => { return 0; },
};
describe('ConsoleLogger', () => {

interface Spies {
log: SinonSpy;
Expand Down
Loading