Skip to content

Commit

Permalink
Merge pull request #113 from hearchco/as/chore/slow-types
Browse files Browse the repository at this point in the history
chore: fix slow types, no return types
  • Loading branch information
aleksasiriski authored Jul 9, 2024
2 parents 4e155a6 + 28b424f commit 32aada2
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion cloudfront/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
/**
* @typedef {import("aws-lambda").CloudFrontFunctionsEvent} CloudFrontFunctionsEvent
* @typedef {import("aws-lambda").CloudFrontFunctionsQuerystring} CloudFrontFunctionsQuerystring
* @typedef {import("aws-lambda").CloudFrontFunctionsEvent.request} CloudFrontFunctionsRequest
*/

/**
* Note: form action requests contain "/" in request query string
* ie. POST request with query string "?/action"
* CloudFront does not allow query string with "/". It needs to be encoded.
* @param {CloudFrontFunctionsEvent} event - Cloudfront functions event
* @returns {any} - Cloudfront function event request
* @returns {CloudFrontFunctionsRequest} - Cloudfront function event request
*/
function handler(event) {
var request = event.request;
Expand Down
2 changes: 1 addition & 1 deletion handler/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const commonBinaryMimeTypes = new Set([

/**
* Determines if the given content type is a binary type.
* @param {string|null} contentType - The MIME type to check.
* @param {string | null} contentType - The MIME type to check.
* @returns {boolean} - Returns true if the content type is a binary type, false otherwise.
*/
export function isBinaryContentType(contentType = null) {
Expand Down
14 changes: 7 additions & 7 deletions handler/event-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { debug } from './logger.js';
/**
* Represents an internal event type.
* @typedef {object} InternalEvent
* @property {"v1"|"v2"|"cf"} type The type of the event.
* @property {"v1" | "v2" | "cf"} type The type of the event.
* @property {string} method HTTP method used in the event.
* @property {string} rawPath The raw path accessed in the event.
* @property {string} url The full URL accessed in the event.
Expand All @@ -27,7 +27,7 @@ import { debug } from './logger.js';
/**
* Represents an internal result format.
* @typedef {object} InternalResult
* @property {"v1"|"v2"|"cf"} type The type of the result.
* @property {"v1" | "v2" | "cf"} type The type of the result.
* @property {number} statusCode HTTP status code.
* @property {Record<string, string|string[]>} headers Headers to send in the response.
* @property {string} body The response body as a string.
Expand All @@ -36,7 +36,7 @@ import { debug } from './logger.js';

/**
* Checks if the event is an API Gateway V2 event.
* @param {any} event The event to check.
* @param {APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent} event The event to check.
* @returns {event is APIGatewayProxyEventV2} True if it's an API Gateway V2 event.
*/
export function isAPIGatewayProxyEventV2(event) {
Expand All @@ -45,7 +45,7 @@ export function isAPIGatewayProxyEventV2(event) {

/**
* Checks if the event is an API Gateway V1 event.
* @param {any} event The event to check.
* @param {APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent} event The event to check.
* @returns {event is APIGatewayProxyEvent} True if it's an API Gateway V1 event.
*/
export function isAPIGatewayProxyEvent(event) {
Expand All @@ -54,7 +54,7 @@ export function isAPIGatewayProxyEvent(event) {

/**
* Checks if the event is a CloudFront request event.
* @param {any} event The event to check.
* @param {APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent} event The event to check.
* @returns {event is CloudFrontRequestEvent} True if it's a CloudFront request event.
*/
export function isCloudFrontRequestEvent(event) {
Expand All @@ -63,7 +63,7 @@ export function isCloudFrontRequestEvent(event) {

/**
* Converts an API Gateway or CloudFront event to an internal event format.
* @param {APIGatewayProxyEventV2|APIGatewayProxyEvent|CloudFrontRequestEvent} event The event to convert.
* @param {APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent} event The event to convert.
* @returns {InternalEvent} The internal event.
*/
export function convertFrom(event) {
Expand All @@ -80,7 +80,7 @@ export function convertFrom(event) {
/**
* Converts an internal result to a corresponding AWS API Gateway or CloudFront result.
* @param {InternalResult} result The internal result to convert.
* @returns {APIGatewayProxyResultV2|APIGatewayProxyResult|CloudFrontRequestResult} The API Gateway or CloudFront result.
* @returns {APIGatewayProxyResultV2 | APIGatewayProxyResult | CloudFrontRequestResult} The API Gateway or CloudFront result.
*/
export function convertTo(result) {
if (result.type === 'v2') {
Expand Down
11 changes: 7 additions & 4 deletions handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ app.init({ env: /** @type {Record<string, string>} */ (process.env) });

/**
* Handles incoming requests from AWS API Gateway or CloudFront and responds appropriately.
* @param {APIGatewayProxyEventV2 | CloudFrontRequestEvent | APIGatewayProxyEvent} event - The incoming event from AWS Lambda.
* @returns {Promise<any>} The response to be returned to AWS Lambda.
* @param {APIGatewayProxyEvent | APIGatewayProxyEventV2 | CloudFrontRequestEvent} event - The incoming event from AWS Lambda.
* @returns {Promise<CloudFrontRequest | CloudFrontRequestResult | APIGatewayProxyResult | APIGatewayProxyResultV2>} - The response to be returned to AWS Lambda.
*/
export async function handler(event) {
debug('event', event);
Expand Down Expand Up @@ -106,16 +106,19 @@ export async function handler(event) {
body
});
}
return {

/** @type {CloudFrontRequestResult} */
const notFoundResp = {
statusCode: 404,
body: 'Not found.'
};
return notFoundResp;
}

/**
* Checks if the URI corresponds to a prerendered file.
* @param {string} uri - The URI to check.
* @returns {string|undefined} The filepath if it is a prerendered file, otherwise undefined.
* @returns {string | undefined} The filepath if it is a prerendered file, otherwise undefined.
*/
function isPrerenderedFile(uri) {
// remove leading and trailing slashes
Expand Down
1 change: 1 addition & 0 deletions handler/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* Logs debug information to the console if the DEBUG environment variable is set.
* @param {...any} args - Arguments to be logged.
* @returns {void}
*/
export function debug(...args) {
if (process.env.DEBUG) {
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default function (options = {}) {
/**
* Adapts the project for deployment.
* @param {Builder} builder - The builder instance from SvelteKit
* @returns {Promise<void>}
*/
async adapt(builder) {
const tmp = path.join('.svelte-kit', name);
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@hearchco/sveltekit-adapter-aws",
"version": "0.1.11",
"version": "0.1.12",
"exports": "./index.js"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hearchco/sveltekit-adapter-aws",
"version": "0.1.11",
"version": "0.1.12",
"description": "SvelteKit AWS universal adapter for creating necessary assets and code which can later be deployed using a custom IaC pipeline",
"repository": {
"type": "git",
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
// "allowJs": true,
// "checkJs": true,
"strict": true,
"declaration": true,
"emitDeclarationOnly": true,
"isolatedDeclarations": true,
"outDir": ".",
"noImplicitAny": true,
"target": "ES2022",
Expand Down

0 comments on commit 32aada2

Please sign in to comment.