-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Add lesgo framework type declarations #53881
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0927f03
Add lesgo initial types setup
xXLXx 57b0523
Add all lesgo type declarations
xXLXx 10fd182
Add pagination types to exported
xXLXx 2a5bd09
Refactor including tests
xXLXx 90dca9d
Refactor including of paginator/index.ts
xXLXx 9f42b66
Remove paths from tsconfig and use relative configs
xXLXx f8bdea0
Add missing dependencies aws-sdk and firebase-admin
xXLXx 0150e60
Fix incorrect/missing code
xXLXx df8edcf
Fix export *s
xXLXx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| export default class LesgoException { | ||
| name: string; | ||
|
|
||
| message: string; | ||
|
|
||
| statusCode: number; | ||
|
|
||
| code: string; | ||
|
|
||
| extra: any; | ||
|
|
||
| constructor(message: string, errorCode?: string, httpStatusCode?: number, extra?: any); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import LesgoException from './LesgoException'; | ||
|
|
||
| export { LesgoException }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Type definitions for lesgo 0.6 | ||
| // Project: https://github.com/reflex-media/lesgo-framework#readme | ||
| // Definitions by: xXLXx <https://github.com/xxlxx> | ||
| // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
| // Minimum TypeScript Version: 3.8 | ||
|
|
||
| // We did this to adjust to data-api-client | ||
|
|
||
| export * from "./middlewares"; | ||
|
|
||
| export * from "./exceptions"; | ||
|
|
||
| export * from "./services"; | ||
|
|
||
| export * from "./utils"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| import httpMiddleware from "lesgo/middlewares/httpMiddleware"; | ||
| import normalizeHttpRequestMiddleware from "lesgo/middlewares/normalizeHttpRequestMiddleware"; | ||
| import successHttpResponseMiddleware from "lesgo/middlewares/successHttpResponseMiddleware"; | ||
| import errorHttpResponseMiddleware from "lesgo/middlewares/errorHttpResponseMiddleware"; | ||
| import verifyJwtMiddleware from "lesgo/middlewares/verifyJwtMiddleware"; | ||
| import normalizeSQSMessageMiddleware from "lesgo/middlewares/normalizeSQSMessageMiddleware"; | ||
|
|
||
| import LesgoException from "lesgo/exceptions/LesgoException"; | ||
|
|
||
| import ElasticCacheService from "lesgo/services/ElasticCacheService"; | ||
| import "./tests/services/ElasticsearchService"; | ||
| import "./tests/services/AuroraDbService"; | ||
| import "./tests/services/DynamoDbService"; | ||
| import "./tests/services/LoggerService"; | ||
| import "./tests/services/S3Service"; | ||
| import "./tests/services/SQSService"; | ||
| import "./tests/services/FirebaseAdminService"; | ||
| import "./tests/services/JWTService"; | ||
|
|
||
| import { ec, get, set, del } from "lesgo/utils/cache"; | ||
| import { encrypt, decrypt, hash, hashMD5 } from "lesgo/utils/crypto"; | ||
| import db from "lesgo/utils/db"; | ||
| import dynamodb from "lesgo/utils/dynamodb"; | ||
| import elasticsearch from "lesgo/utils/elasticsearch"; | ||
| import generateUid from "lesgo/utils/generateUid"; | ||
| import getJwtSubFromAuthHeader, { getTokenData } from "lesgo/utils/getJwtSubFromAuthHeader"; | ||
| import isDecimal from "lesgo/utils/isDecimal"; | ||
| import isEmail from "lesgo/utils/isEmail"; | ||
| import isEmpty from "lesgo/utils/isEmpty"; | ||
| import logger from "lesgo/utils/logger"; | ||
| import objectStore, { getObject } from "lesgo/utils/objectStore"; | ||
| import prepSQLInsertParams from "lesgo/utils/prepSQLInsertParams"; | ||
| import prepSQLUpdateParams from "lesgo/utils/prepSQLUpdateParams"; | ||
| import queue, { dispatch } from "lesgo/utils/queue"; | ||
| import validateFields from "lesgo/utils/validateFields"; | ||
|
|
||
| /* Middlewares */ | ||
| httpMiddleware({ debugMode: true }); // $ExpectType HttpMiddleware | ||
| normalizeHttpRequestMiddleware(); // $ExpectType NormalizeHttpMiddleware | ||
| successHttpResponseMiddleware(); // $ExpectType SuccessHttpMiddleware | ||
| errorHttpResponseMiddleware({ debugMode: true }); // $ExpectType ErrorHttpMiddleware | ||
| verifyJwtMiddleware(); // $ExpectType VerifyJwtMiddleware | ||
| normalizeSQSMessageMiddleware(); // $ExpectType NormalizeSQSMiddleware | ||
|
|
||
| /* Exceptions */ | ||
| const lesgoException = new LesgoException("Error"); | ||
| lesgoException.name; // $ExpectType string | ||
| lesgoException.message; // $ExpectType string | ||
| lesgoException.statusCode; // $ExpectType number | ||
| lesgoException.code; // $ExpectType string | ||
| lesgoException.extra; // $ExpectType any | ||
|
|
||
| /* Services */ | ||
| const elasticCache = new ElasticCacheService({ | ||
| url: "12.0.0.1", | ||
| options: { | ||
| autoDiscover: true, | ||
| autoDiscoverInterval: 60000, | ||
| autoDiscoverOverridesRemove: false, | ||
| timeout: 30, | ||
| }, | ||
| }); | ||
| elasticCache.driver; // $ExpectType Memcached | ||
|
|
||
| /* Utils */ | ||
| ec("conname"); // $ExpectType Memcached | ||
| (async () => { | ||
| // $ExpectType boolean | ||
| await set( | ||
| "cache-key", | ||
| { | ||
| test: 1, | ||
| }, | ||
| 1000, | ||
| ); | ||
| await get("cache-key"); // $ExpectType any | ||
| await del("cache-key"); // $ExpectType boolean | ||
| })(); | ||
|
|
||
| encrypt("this is a test"); // $ExpectType string | ||
| decrypt("TMxLqkHSs8D7tD02ptbtWQxocJO93ZPvqS4IruHEpj8="); // $ExpectType string | ||
| hash("this is a test"); // $ExpectType Buffer | ||
| hashMD5(new Uint8Array([21, 31])); // $ExpectType Buffer | ||
|
|
||
| db; // $ExpectType AuroraDbService | ||
| (async () => { | ||
| await db.select("SELECT * FROM users;", []); // $ExpectType any[] | ||
| })(); | ||
| dynamodb; // $ExpectType DynamoDb | ||
| (async () => { | ||
| await dynamodb.query("analytics", "ForumName = :name", { ":title": { SS: ["The Man"] } }, "#title, tag"); // $ExpectType ItemList | ||
| })(); | ||
| elasticsearch("production"); // $ExpectType ElasticsearchService | ||
| (async () => { | ||
| // $ExpectType string | ||
| await generateUid({ | ||
| length: 20, | ||
| }); | ||
| })(); | ||
| (async () => { | ||
| // $ExpectType string | null | ||
| await getJwtSubFromAuthHeader( | ||
| "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", | ||
| ); | ||
| })(); | ||
| // $ExpectType { sub?: string | undefined; } | ||
| getTokenData( | ||
| "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", | ||
| ); | ||
| isDecimal(1); // $ExpectType boolean | ||
| isEmail("leo.lavarias@gmail.com"); // $ExpectType boolean | ||
| isEmpty(["test"]); // $ExpectType boolean | ||
| logger; // $ExpectType LoggerService | ||
| // $ExpectType void | ||
| logger.info("SAVED TO DYNAMODB", { | ||
| id: 10, | ||
| name: "Leo", | ||
| }); | ||
| objectStore; // $ExpectType S3Service | ||
| (async () => { | ||
| await getObject("TILES/Level4/A3_B3_C2/A5_B67_C59_Tiles.par", "test-aws-imagery"); // $ExpectType GetObjectOutput | ||
| })(); | ||
| // $ExpectType SQLInsertParams | ||
| prepSQLInsertParams( | ||
| { | ||
| id: 1, | ||
| name: "Leo", | ||
| }, | ||
| [{ key: "id" }, { key: "name" }], | ||
| ); | ||
| // $ExpectType SQLUpdateParams | ||
| prepSQLUpdateParams( | ||
| { | ||
| id: 1, | ||
| name: "Leo", | ||
| }, | ||
| [{ key: "id" }, { key: "name" }], | ||
| ); | ||
| queue; // $ExpectType SQSService<Record<string, QueueConfig>> | ||
| (async () => { | ||
| await dispatch("ping", "myqueue"); // $ExpectType SendMessageResult | ||
| })(); | ||
| // $ExpectType boolean | ||
| validateFields( | ||
| { | ||
| id: 1, | ||
| name: "test", | ||
| }, | ||
| [ | ||
| { key: "id", type: "number", required: true }, | ||
| { key: "name", type: "string" }, | ||
| ], | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { MiddlewareFunction } from "middy"; | ||
| import { HttpGatewayEvent } from "./normalizeHttpRequestMiddleware"; | ||
| import { MiddlewareOptions } from "./successHttpResponseMiddleware"; | ||
|
|
||
| export interface ErrorHttpResponse { | ||
| headers: Record<string, string | null>; | ||
| statusCode: number; | ||
| body: string; | ||
| } | ||
|
|
||
| export interface ErrorHttpMiddleware { | ||
| onError: MiddlewareFunction<HttpGatewayEvent, ErrorHttpResponse>; | ||
| } | ||
|
|
||
| export default function errorHttpResponseMiddleware(opts?: MiddlewareOptions): ErrorHttpMiddleware; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { MiddlewareObject } from "middy"; | ||
| import { APIGatewayEvent, Context } from "aws-lambda"; | ||
| import { NormalizeHttpMiddleware } from "./normalizeHttpRequestMiddleware"; | ||
| import { MiddlewareOptions, SuccessHttpMiddleware } from "./successHttpResponseMiddleware"; | ||
| import { ErrorHttpMiddleware } from "./errorHttpResponseMiddleware"; | ||
|
|
||
| export type HttpMiddleware = NormalizeHttpMiddleware & SuccessHttpMiddleware & ErrorHttpMiddleware; | ||
|
|
||
| export default function httpMiddleware(opts?: MiddlewareOptions): HttpMiddleware; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export * from "./httpMiddleware"; | ||
| export * from "./normalizeHttpRequestMiddleware"; | ||
| export * from "./errorHttpResponseMiddleware"; | ||
| export * from "./successHttpResponseMiddleware"; | ||
| export * from "./verifyJwtMiddleware"; | ||
| export * from "./normalizeSQSMessageMiddleware"; |
15 changes: 15 additions & 0 deletions
15
types/lesgo/middlewares/normalizeHttpRequestMiddleware.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { MiddlewareFunction } from "middy"; | ||
| import { APIGatewayEvent } from "aws-lambda"; | ||
|
|
||
| export interface HttpGatewayEvent extends APIGatewayEvent { | ||
| input: Record<string, any> | null | string; | ||
| auth: { | ||
| sub?: Record<string, any> | null; | ||
| }; | ||
| } | ||
|
|
||
| export interface NormalizeHttpMiddleware { | ||
| before: MiddlewareFunction<HttpGatewayEvent, {}>; | ||
| } | ||
|
|
||
| export default function normalizeHttpRequestMiddleware(): NormalizeHttpMiddleware; |
12 changes: 12 additions & 0 deletions
12
types/lesgo/middlewares/normalizeSQSMessageMiddleware.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { MiddlewareFunction } from "middy"; | ||
| import { SQSEvent, SQSRecord } from "aws-lambda"; | ||
|
|
||
| export interface SQSEventWithCollection extends SQSEvent { | ||
| collection?: Pick<SQSRecord, "messageId" | "receiptHandle"> & Record<string, any>; | ||
| } | ||
|
|
||
| export interface NormalizeSQSMiddleware { | ||
| before: MiddlewareFunction<SQSEventWithCollection, {}>; | ||
| } | ||
|
|
||
| export default function normalizeSQSMessageMiddleware(): NormalizeSQSMiddleware; |
21 changes: 21 additions & 0 deletions
21
types/lesgo/middlewares/successHttpResponseMiddleware.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { MiddlewareFunction } from "middy"; | ||
| import { HttpGatewayEvent } from "./normalizeHttpRequestMiddleware"; | ||
|
|
||
| export interface MiddlewareOptions { | ||
| headers?: Record<string, string>; | ||
| debugMode?: boolean; | ||
| zipWhenRequest?: Array<"ELB" | "APIGATEWAY">; | ||
| } | ||
|
|
||
| export interface SuccessHttpResponse { | ||
| headers: Record<string, string | null>; | ||
| statusCode: number; | ||
| body: string; | ||
| isBase64Encoded: boolean; | ||
| } | ||
|
|
||
| export interface SuccessHttpMiddleware { | ||
| after: MiddlewareFunction<HttpGatewayEvent, SuccessHttpResponse>; | ||
| } | ||
|
|
||
| export default function successHttpResponseMiddleware(opts?: MiddlewareOptions): SuccessHttpMiddleware; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { MiddlewareFunction } from "middy"; | ||
| import { APIGatewayEvent } from "aws-lambda"; | ||
|
|
||
| export interface JwtGatewayEvent extends APIGatewayEvent { | ||
| decodedJwt?: string; | ||
| } | ||
|
|
||
| export interface VerifyJwtMiddleware { | ||
| before: MiddlewareFunction<JwtGatewayEvent, {}>; | ||
| } | ||
|
|
||
| export default function verifyJwtMiddleware(): VerifyJwtMiddleware; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "private": true, | ||
| "dependencies": { | ||
| "middy": "^0.29.0", | ||
| "@elastic/elasticsearch": "^7.4.0", | ||
| "aws-sdk": "^2.541.0", | ||
| "firebase-admin": "^9.3.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import DataApiClient = require("data-api-client"); | ||
| import { PaginatorObject } from "./pagination/Paginator"; | ||
|
|
||
| export type iParams = Parameters<typeof DataApiClient>[0]; | ||
|
|
||
| export type iDataAPIClient = ReturnType<typeof DataApiClient>; | ||
|
|
||
| export type AuroraDbServiceParams = Pick<iParams, "secretArn" | "resourceArn" | "database">; | ||
|
|
||
| export default class AuroraDbService { | ||
| protected client: iDataAPIClient; | ||
|
|
||
| constructor(params?: AuroraDbServiceParams); | ||
|
|
||
| connect(opts: AuroraDbServiceParams): void; | ||
|
|
||
| query(sql: string, params: [] | unknown): ReturnType<iDataAPIClient["query"]>; | ||
|
|
||
| select(sql: string, params: [] | unknown): Promise<any[]>; | ||
|
|
||
| selectFirst(sql: string, params: [] | unknown): Promise<any>; | ||
|
|
||
| selectPaginate( | ||
| sql: string, | ||
| params: [] | unknown, | ||
| perPage?: number, | ||
| currentPage?: number, | ||
| total?: number | null, | ||
| ): PaginatorObject<any>; | ||
|
|
||
| insert(sql: string, sqlParams: [] | unknown): Promise<any>; | ||
|
|
||
| update(sql: string, sqlParams: [] | unknown): Promise<void>; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.