Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: humanmade/tachyon
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.0.3
Choose a base ref
...
head repository: humanmade/tachyon
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.0.4
Choose a head ref
  • 7 commits
  • 8 files changed
  • 2 contributors

Commits on Mar 5, 2024

  1. Add pull_request event

    It's not totally clear how GH selects the right event, but I think we need pull_request to be part of the `on` for the event_name to trigger.
    joehoyle committed Mar 5, 2024
    Copy the full SHA
    cdee388 View commit details
  2. Merge pull request #181 from humanmade/fix-pr-build-zip

    Add pull_request event
    joehoyle authored Mar 5, 2024
    Copy the full SHA
    00b3e26 View commit details
  3. Import with file extensions

    Setting the tsconfig properly makes TSC also throw an error / warning for the extensionless imports too.
    joehoyle committed Mar 5, 2024
    Copy the full SHA
    8ec8a50 View commit details
  4. Fix imports

    - FIx imports to use file extensions per latest spec
    - Pass Content-Type as a header, as it's not possible to use response.contentType() with header streaming.
    - Fix jest with js extensions imports
    joehoyle committed Mar 5, 2024
    Copy the full SHA
    25ff598 View commit details
  5. Fix tests

    joehoyle committed Mar 5, 2024
    Copy the full SHA
    78e568d View commit details
  6. Also mock the content type from headers

    joehoyle committed Mar 5, 2024
    Copy the full SHA
    6dda3aa View commit details
  7. Merge pull request #182 from humanmade/fix-import

    Import with file extensions
    joehoyle authored Mar 5, 2024
    Copy the full SHA
    2e73546 View commit details
Showing with 28 additions and 9 deletions.
  1. +3 −0 .github/workflows/release.yml
  2. +2 −1 global.d.ts
  3. +3 −0 jest.config.js
  4. +4 −2 src/lambda-handler.ts
  5. +6 −2 tests/test-lambda.ts
  6. +6 −0 tests/test-private-upload.ts
  7. +2 −2 tsconfig.json
  8. +2 −2 tsconfig.test.json
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@ on:
- "**"
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
build:
3 changes: 2 additions & 1 deletion global.d.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ declare type ResponseStream = {
setContentType( type: string ): void;
write( stream: string | Buffer ): void;
end(): void;
metadata?: any;
};

declare type StreamifyHandler = ( event: APIGatewayProxyEventV2, response: ResponseStream ) => Promise<any>;
@@ -13,7 +14,7 @@ declare var awslambda: {
HttpResponseStream: {
from( response: ResponseStream, metadata: {
headers?: Record<string, string>,
statusCode?: number,
statusCode: number,
cookies?: string[],
} ): ResponseStream
}
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -13,4 +13,7 @@ export default {
},
],
},
moduleNameMapper: {
"(.+)\\.js": "$1"
},
};
6 changes: 4 additions & 2 deletions src/lambda-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Args, getS3File, resizeBuffer, Config } from './lib';
import { Args, getS3File, resizeBuffer, Config } from './lib.js';
/**
*
* @param event
@@ -67,13 +67,14 @@ const streamify_handler: StreamifyHandler = async ( event, response ) => {

// Somewhat undocumented API on how to pass headers to a stream response.
response = awslambda.HttpResponseStream.from( response, {
statusCode: 200,
headers: {
'Cache-Control': `max-age=${ maxAge }`,
'Last-Modified': ( new Date() ).toUTCString(),
'Content-Type': 'image/' + info.format,
},
} );

response.setContentType( 'image/' + info.format );
response.write( data );
response.end();
};
@@ -96,6 +97,7 @@ if ( typeof awslambda === 'undefined' ) {
from( response: ResponseStream, metadata: {
headers?: Record<string, string>,
} ): ResponseStream {
response.metadata = metadata;
return response;
},
},
8 changes: 6 additions & 2 deletions tests/test-lambda.ts
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ class TestResponseStream {
contentType: string | undefined;
body: string | Buffer | undefined;
headers: { [key: string]: string } = {};
metadata: any;

setContentType( type: string ): void {
this.contentType = type;
@@ -46,7 +47,9 @@ class TestResponseStream {
}
}
end(): void {

if ( this.metadata.headers['Content-Type'] ) {
this.contentType = this.metadata.headers['Content-Type'];
}
}
}

@@ -63,7 +66,8 @@ global.awslambda = {
* @param stream The response stream.
* @param metadata The metadata for the response.
*/
from( stream: ResponseStream, metadata ) : ResponseStream {
from( stream: TestResponseStream, metadata ) : TestResponseStream {
stream.metadata = metadata;
return stream;
},
},
6 changes: 6 additions & 0 deletions tests/test-private-upload.ts
Original file line number Diff line number Diff line change
@@ -74,6 +74,9 @@ test( 'Test get private upload', async () => {
* End the response.
*/
end(): void {
if ( this.metadata.headers['Cache-Control'] ) {
contentType = this.metadata.headers['Content-Type'];
}
},
} );

@@ -115,6 +118,9 @@ test( 'Test get private upload with presign params', async () => {
* End the response.
*/
end(): void {
if ( this.metadata.headers['Cache-Control'] ) {
contentType = this.metadata.headers['Content-Type'];
}
},
} );

4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@
"strict": true,
"preserveConstEnums": true,
"sourceMap": false,
"module": "ES2022",
"moduleResolution": "node",
"module": "Node16",
"moduleResolution": "node16",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
4 changes: 2 additions & 2 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
"preserveConstEnums": true,
"noEmit": false,
"sourceMap": true,
"module": "ES2022",
"moduleResolution": "node",
"module": "Node16",
"moduleResolution": "Node16",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,