Skip to content

Commit c1024ef

Browse files
committed
refactor: format
1 parent bc54f89 commit c1024ef

File tree

11 files changed

+149
-114
lines changed

11 files changed

+149
-114
lines changed

.prettierrc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 4,
4+
"useTabs": true,
5+
"jsxSingleQuote": false,
6+
"trailingComma": "es5",
7+
"prettier.tslintIntegration": true,
8+
"overrides": [
9+
{
10+
"files": "*.yml",
11+
"options": {
12+
"tabWidth": 2
13+
}
14+
},
15+
{
16+
"files": "*.yaml",
17+
"options": {
18+
"tabWidth": 2
19+
}
20+
},
21+
{
22+
"files": "*.json",
23+
"options": {
24+
"tabWidth": 2,
25+
"useTabs": false
26+
}
27+
}
28+
]
29+
}

services/functions/echo/handler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getEchoHandler } from "@api";
2-
import { APIGatewayProxyHandlerV2 } from "aws-lambda";
3-
import { EchoOperation } from "./operation";
4-
import { getApiGatewayHandler } from "@utils/apiGatewayHandler";
1+
import { getEchoHandler } from '@api';
2+
import { APIGatewayProxyHandlerV2 } from 'aws-lambda';
3+
import { EchoOperation } from './operation';
4+
import { getApiGatewayHandler } from '@utils/apiGatewayHandler';
55

66
export const lambdaHandler: APIGatewayProxyHandlerV2 = getApiGatewayHandler(
7-
getEchoHandler(EchoOperation)
7+
getEchoHandler(EchoOperation)
88
);

services/functions/echo/operation.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
import { Operation } from "@aws-smithy/server-common";
2-
import { EchoServerInput, EchoServerOutput, PalindromeException } from "@api";
3-
import { HandlerContext } from "../../utils/apiGatewayHandler";
1+
import { Operation } from '@aws-smithy/server-common';
2+
import { EchoServerInput, EchoServerOutput, PalindromeException } from '@api';
3+
import { HandlerContext } from '../../utils/apiGatewayHandler';
44

55
export const EchoOperation: Operation<
6-
EchoServerInput,
7-
EchoServerOutput,
8-
HandlerContext
6+
EchoServerInput,
7+
EchoServerOutput,
8+
HandlerContext
99
> = async (input, context) => {
10-
console.log(`Received Echo operation from: ${context.user}`);
10+
console.log(`Received Echo operation from: ${context.user}`);
1111

12-
if (input.message != undefined && input.message === reverse(input.message)) {
13-
throw new PalindromeException({
14-
message: "Cannot handle palindrome",
15-
});
16-
}
12+
if (
13+
input.message != undefined &&
14+
input.message === reverse(input.message)
15+
) {
16+
throw new PalindromeException({
17+
message: 'Cannot handle palindrome',
18+
});
19+
}
1720

18-
return {
19-
message: input.message,
20-
};
21+
return {
22+
message: input.message,
23+
};
2124
};
2225

2326
export function reverse(str: string) {
24-
return str.split("").reverse().join("");
27+
return str.split('').reverse().join('');
2528
}

services/functions/lambda.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { APIGatewayProxyHandlerV2 } from "aws-lambda";
1+
import { APIGatewayProxyHandlerV2 } from 'aws-lambda';
22

33
export const handler: APIGatewayProxyHandlerV2 = async (event) => {
4-
console.log("Hi");
5-
return {
6-
statusCode: 200,
7-
headers: { "Content-Type": "text/plain" },
8-
body: `Hello, World! Your request was received at ${event.requestContext.time}.`,
9-
};
4+
console.log('Hi');
5+
return {
6+
statusCode: 200,
7+
headers: { 'Content-Type': 'text/plain' },
8+
body: `Hello, World! Your request was received at ${event.requestContext.time}.`,
9+
};
1010
};
1111

1212
/**

services/functions/length/handler.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
import { Operation } from "@aws-smithy/server-common";
2-
import { APIGatewayProxyHandlerV2 } from "aws-lambda";
1+
import { Operation } from '@aws-smithy/server-common';
2+
import { APIGatewayProxyHandlerV2 } from 'aws-lambda';
33
import {
4-
getLengthHandler,
5-
LengthServerInput,
6-
LengthServerOutput,
7-
PalindromeException,
8-
} from "@api";
9-
import { getApiGatewayHandler, HandlerContext } from "@utils/apiGatewayHandler";
4+
getLengthHandler,
5+
LengthServerInput,
6+
LengthServerOutput,
7+
PalindromeException,
8+
} from '@api';
9+
import { getApiGatewayHandler, HandlerContext } from '@utils/apiGatewayHandler';
1010

1111
const LengthOperation: Operation<
12-
LengthServerInput,
13-
LengthServerOutput,
14-
HandlerContext
12+
LengthServerInput,
13+
LengthServerOutput,
14+
HandlerContext
1515
> = async (input, context) => {
16-
console.log(`Received Length operation from: ${context.user}`);
16+
console.log(`Received Length operation from: ${context.user}`);
1717

18-
if (input.message != undefined && input.message === reverse(input.message)) {
19-
throw new PalindromeException({
20-
message: "Cannot handle palindrome",
21-
});
22-
}
18+
if (
19+
input.message != undefined &&
20+
input.message === reverse(input.message)
21+
) {
22+
throw new PalindromeException({
23+
message: 'Cannot handle palindrome',
24+
});
25+
}
2326

24-
return {
25-
length: input.message?.length,
26-
};
27+
return {
28+
length: input.message?.length,
29+
};
2730
};
2831

2932
function reverse(str: string) {
30-
return str.split("").reverse().join("");
33+
return str.split('').reverse().join('');
3134
}
3235

3336
export const lambdaHandler: APIGatewayProxyHandlerV2 = getApiGatewayHandler(
34-
getLengthHandler(LengthOperation)
37+
getLengthHandler(LengthOperation)
3538
);

services/test/sample.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { describe, it, expect } from "vitest";
1+
import { describe, it, expect } from 'vitest';
22

3-
describe("sample", () => {
4-
it("should work", () => {
5-
expect(true).toBe(true);
6-
});
3+
describe('sample', () => {
4+
it('should work', () => {
5+
expect(true).toBe(true);
6+
});
77
});

services/utils/apiGatewayHandler.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import {
2-
APIGatewayProxyEventV2,
3-
APIGatewayProxyHandlerV2,
4-
APIGatewayProxyResultV2,
5-
} from "aws-lambda";
2+
APIGatewayProxyEventV2,
3+
APIGatewayProxyHandlerV2,
4+
APIGatewayProxyResultV2,
5+
} from 'aws-lambda';
66
import {
7-
convertEvent,
8-
convertVersion2Response,
9-
} from "@aws-smithy/server-apigateway";
10-
import { ServiceHandler } from "@aws-smithy/server-common";
7+
convertEvent,
8+
convertVersion2Response,
9+
} from '@aws-smithy/server-apigateway';
10+
import { ServiceHandler } from '@aws-smithy/server-common';
1111

1212
export interface HandlerContext {
13-
user: string;
13+
user: string;
1414
}
1515

1616
export function getApiGatewayHandler(
17-
handler: ServiceHandler<HandlerContext>
17+
handler: ServiceHandler<HandlerContext>
1818
): APIGatewayProxyHandlerV2 {
19-
return async (
20-
event: APIGatewayProxyEventV2
21-
): Promise<APIGatewayProxyResultV2> => {
22-
// Extract anything from the APIGateway requestContext that you'd need in your operation handler
23-
const userArn = event.requestContext.accountId;
24-
if (!userArn) {
25-
throw new Error("IAM Auth is not enabled");
26-
}
27-
const context = { user: userArn };
19+
return async (
20+
event: APIGatewayProxyEventV2
21+
): Promise<APIGatewayProxyResultV2> => {
22+
// Extract anything from the APIGateway requestContext that you'd need in your operation handler
23+
const userArn = event.requestContext.accountId;
24+
if (!userArn) {
25+
throw new Error('IAM Auth is not enabled');
26+
}
27+
const context = { user: userArn };
2828

29-
const httpRequest = convertEvent(event);
30-
const httpResponse = await handler.handle(httpRequest, context);
31-
return convertVersion2Response(httpResponse);
32-
};
29+
const httpRequest = convertEvent(event);
30+
const httpResponse = await handler.handle(httpRequest, context);
31+
return convertVersion2Response(httpResponse);
32+
};
3333
}

sst.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"name": "app",
33
"region": "us-east-1",
44
"main": "stacks/index.ts"
5-
}
5+
}

stacks/MyStack.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { StackContext, Api } from "@serverless-stack/resources";
1+
import { StackContext, Api } from '@serverless-stack/resources';
22

33
export function MyStack({ stack }: StackContext) {
4-
const api = new Api(stack, "api", {
5-
routes: {
6-
"GET /": "functions/lambda.handler",
7-
"GET /length/{message}": "functions/length/handler.lambdaHandler",
8-
"POST /echo": "functions/echo/handler.lambdaHandler",
9-
},
10-
});
11-
stack.addOutputs({
12-
ApiEndpoint: api.url,
13-
});
4+
const api = new Api(stack, 'api', {
5+
routes: {
6+
'GET /': 'functions/lambda.handler',
7+
'GET /length/{message}': 'functions/length/handler.lambdaHandler',
8+
'POST /echo': 'functions/echo/handler.lambdaHandler',
9+
},
10+
});
11+
stack.addOutputs({
12+
ApiEndpoint: api.url,
13+
});
1414
}

stacks/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { MyStack } from "./MyStack";
2-
import { App } from "@serverless-stack/resources";
1+
import { MyStack } from './MyStack';
2+
import { App } from '@serverless-stack/resources';
33

44
export default function (app: App) {
5-
app.setDefaultFunctionProps({
6-
runtime: "nodejs16.x",
7-
srcPath: "services",
8-
bundle: {
9-
nodeModules: ["re2-wasm"],
10-
format: "cjs",
11-
},
12-
});
13-
app.stack(MyStack);
5+
app.setDefaultFunctionProps({
6+
runtime: 'nodejs16.x',
7+
srcPath: 'services',
8+
bundle: {
9+
nodeModules: ['re2-wasm'],
10+
format: 'cjs',
11+
},
12+
});
13+
app.stack(MyStack);
1414
}

vitest.config.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/// <reference types="vitest" />
22

3-
import { defineConfig } from "vitest/config";
3+
import { defineConfig } from 'vitest/config';
44

55
export default defineConfig({
6-
test: {
7-
testTimeout: 30000,
8-
},
9-
logLevel: "info",
10-
esbuild: {
11-
sourcemap: "both",
12-
},
13-
resolve: {
14-
alias: {
15-
"@my-app/core": "./services/core",
16-
},
17-
},
6+
test: {
7+
testTimeout: 30000,
8+
},
9+
logLevel: 'info',
10+
esbuild: {
11+
sourcemap: 'both',
12+
},
13+
resolve: {
14+
alias: {
15+
'@my-app/core': './services/core',
16+
},
17+
},
1818
});

0 commit comments

Comments
 (0)