@creator.co/wapi 1.2.0-beta12 → 1.2.0-beta14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/API/Request.d.ts +2 -2
- package/dist/src/API/Response.d.ts +6 -6
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +1 -1
- package/dist/src/BaseEvent/Transaction.d.ts +6 -6
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/package.json +1 -1
- package/src/API/Request.ts +2 -2
- package/src/API/Response.ts +12 -9
- package/src/BaseEvent/EventProcessor.ts +2 -2
- package/src/BaseEvent/Transaction.ts +33 -17
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context, APIGatewayEvent } from "aws-lambda";
|
|
2
2
|
import Logger from "../Logger/Logger";
|
|
3
|
-
export default class Request<
|
|
3
|
+
export default class Request<InputType> {
|
|
4
4
|
private requestEvent;
|
|
5
5
|
private context;
|
|
6
6
|
constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger);
|
|
@@ -10,7 +10,7 @@ export default class Request<T> {
|
|
|
10
10
|
getContextParam(cxtParam: string): any | null;
|
|
11
11
|
containsPathParam(paramName: string): boolean;
|
|
12
12
|
getPathParam(paramName: string): string | null;
|
|
13
|
-
getBody():
|
|
13
|
+
getBody(): InputType;
|
|
14
14
|
getPath(): string;
|
|
15
15
|
getMethod(): string;
|
|
16
16
|
getPathParams(): object | null;
|
|
@@ -4,7 +4,7 @@ export type ResponseErrorType = {
|
|
|
4
4
|
err: string;
|
|
5
5
|
errCode?: string;
|
|
6
6
|
};
|
|
7
|
-
export default class Response<
|
|
7
|
+
export default class Response<BodyType = null> {
|
|
8
8
|
private _statusCode;
|
|
9
9
|
private _body;
|
|
10
10
|
private _isPipingOut;
|
|
@@ -13,17 +13,17 @@ export default class Response<B = null> {
|
|
|
13
13
|
readonly rawBody: boolean;
|
|
14
14
|
readonly throwOnErrors: boolean;
|
|
15
15
|
readonly disableTransactionID: boolean;
|
|
16
|
-
constructor(statusCode: number, body:
|
|
16
|
+
constructor(statusCode: number, body: BodyType, optBehaviour?: {
|
|
17
17
|
shouldStream?: boolean;
|
|
18
18
|
rawBody?: boolean;
|
|
19
19
|
throwOnErrors?: boolean;
|
|
20
20
|
disableTransactionID?: boolean;
|
|
21
21
|
} | undefined);
|
|
22
22
|
getCode(): number;
|
|
23
|
-
getBody():
|
|
23
|
+
getBody(): BodyType;
|
|
24
24
|
appendIntoBody(key: string, value: any): void;
|
|
25
25
|
appendHeader(key: string, value: any): void;
|
|
26
|
-
build(context: Context, transaction: Transaction<any,
|
|
26
|
+
build(context: Context, transaction: Transaction<any, any, any>, _optDoNotCallContext: boolean): Promise<void>;
|
|
27
27
|
private _pipe;
|
|
28
28
|
private _rawContext;
|
|
29
29
|
static MissingParamResponse(paramName: string): Response<ResponseErrorType>;
|
|
@@ -31,9 +31,9 @@ export default class Response<B = null> {
|
|
|
31
31
|
static BadRequestResponse(msg?: string, errCode?: string, optBody?: any): Response<ResponseErrorType>;
|
|
32
32
|
static BadRequestResponseWithRollback(msg: string, errCode: string, optBody?: any): Response<ResponseErrorType>;
|
|
33
33
|
static UnauthorizedResponse(msg: string, errCode: string): Response<ResponseErrorType>;
|
|
34
|
-
static SuccessResponse<
|
|
34
|
+
static SuccessResponse<BodyType>(body: BodyType): Response<BodyType>;
|
|
35
35
|
static RedirectResponse(url: string): Response<null>;
|
|
36
36
|
static SuccessNoContentResponse(): Response<null>;
|
|
37
37
|
static SuccessStreamResponse(stream: any, contentType: string): Response;
|
|
38
|
-
static SimpleResponse<
|
|
38
|
+
static SimpleResponse<BodyType>(body: BodyType, optionalCode?: number): Response<BodyType>;
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.ts"],"names":[],"mappings":";;;;;;;;;;;;;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IAAI,CAAA;IACb,CAAC;IACa,iCAAwB,GAAtC;QACE,OAAO,IAAI,QAAQ,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC;IACa,8BAAqB,GAAnC,UACE,MAAW,EACX,WAAmB;QAEnB,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;YACnD,YAAY,EAAE,IAAI;SACnB,CAAC,CAAA;QACF,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;QAC7C,IAAI,WAAW;YAAE,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAA;IACb,CAAC;IACa,uBAAc,GAA5B,UACE,IAAc,EACd,YAAqB;QAErB,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAW,YAAY,IAAI,GAAG,EAAE,IAAI,CAAC,CAAA;QAC9D,OAAO,IAAI,CAAA;IACb,CAAC;IACH,eAAC;AAAD,CAAC,AAhMD,IAgMC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context, SQSBatchResponse, SQSEvent } from "aws-lambda";
|
|
2
2
|
import Transaction, { TransactionConfig } from "./Transaction";
|
|
3
3
|
import Response, { ResponseErrorType } from "../API/Response";
|
|
4
|
-
export type EventProcessorExecution = (transaction: Transaction<null, ResponseErrorType>, recordContent: string | object) => Promise<Response | SQSBatchResponse>;
|
|
4
|
+
export type EventProcessorExecution = (transaction: Transaction<null, ResponseErrorType, SQSBatchResponse>, recordContent: string | object) => Promise<Response | SQSBatchResponse>;
|
|
5
5
|
export default class EventProcessor {
|
|
6
6
|
private readonly _allowFailure;
|
|
7
7
|
private readonly _apiConfig;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import type { APIGatewayEvent, Context,
|
|
1
|
+
import type { APIGatewayEvent, Context, SQSEvent } from "aws-lambda";
|
|
2
2
|
import Request from "../API/Request";
|
|
3
3
|
import Response, { ResponseErrorType } from "../API/Response";
|
|
4
4
|
import Logger, { LoggerConfig } from "../Logger/Logger";
|
|
5
5
|
import Publisher, { PublisherConfig } from "../Publisher/Publisher";
|
|
6
|
-
export type TransactionExecution<
|
|
6
|
+
export type TransactionExecution<TransactionType, ResponseInnerType, MiscRespType = null> = (transaction: TransactionType) => Promise<Response<ResponseInnerType> | Response<ResponseErrorType> | MiscRespType>;
|
|
7
7
|
export type TransactionConfig = {
|
|
8
8
|
throwOnErrors?: boolean;
|
|
9
9
|
syncReturn?: boolean;
|
|
10
10
|
logger?: LoggerConfig;
|
|
11
11
|
publisher?: PublisherConfig;
|
|
12
12
|
};
|
|
13
|
-
export default class Transaction<
|
|
13
|
+
export default class Transaction<InputType = object, ResponseInnerType = null, MiscRespType = null> {
|
|
14
14
|
private event;
|
|
15
15
|
private context;
|
|
16
16
|
private response;
|
|
17
17
|
private syncReturn;
|
|
18
18
|
private retrowErrors;
|
|
19
19
|
readonly logger: Logger;
|
|
20
|
-
readonly request: Request<
|
|
20
|
+
readonly request: Request<InputType>;
|
|
21
21
|
readonly publisher: Publisher;
|
|
22
|
-
responseProxy: (response: Response<
|
|
22
|
+
responseProxy: (response: Response<ResponseInnerType>) => Promise<void>;
|
|
23
23
|
constructor(event: APIGatewayEvent | SQSEvent, context: Context, config?: TransactionConfig);
|
|
24
|
-
execute(executionFunc: TransactionExecution<Transaction<
|
|
24
|
+
execute(executionFunc: TransactionExecution<Transaction<InputType, ResponseInnerType, MiscRespType>, ResponseInnerType, MiscRespType>): Promise<Response<ResponseInnerType | ResponseErrorType> | MiscRespType>;
|
|
25
25
|
private iexecute;
|
|
26
26
|
private executeDBTransactions;
|
|
27
27
|
private executeLoggerFlush;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../src/BaseEvent/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;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@@ import type { Context, APIGatewayEvent } from "aws-lambda"
|
|
|
3
3
|
import Utils from "./Utils"
|
|
4
4
|
import Logger from "../Logger/Logger"
|
|
5
5
|
//
|
|
6
|
-
export default class Request<
|
|
6
|
+
export default class Request<InputType> {
|
|
7
7
|
private requestEvent: APIGatewayEvent
|
|
8
8
|
private context: Context
|
|
9
9
|
constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger) {
|
|
@@ -49,7 +49,7 @@ export default class Request<T> {
|
|
|
49
49
|
)
|
|
50
50
|
}
|
|
51
51
|
//body
|
|
52
|
-
public getBody():
|
|
52
|
+
public getBody(): InputType {
|
|
53
53
|
let b: any = null
|
|
54
54
|
try {
|
|
55
55
|
b = this.requestEvent.body
|
package/src/API/Response.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type ResponseErrorType = {
|
|
|
16
16
|
errCode?: string
|
|
17
17
|
}
|
|
18
18
|
//
|
|
19
|
-
export default class Response<
|
|
19
|
+
export default class Response<BodyType = null> {
|
|
20
20
|
private _statusCode: number
|
|
21
21
|
private _body: any
|
|
22
22
|
private _isPipingOut: boolean
|
|
@@ -28,7 +28,7 @@ export default class Response<B = null> {
|
|
|
28
28
|
//
|
|
29
29
|
constructor(
|
|
30
30
|
statusCode: number,
|
|
31
|
-
body:
|
|
31
|
+
body: BodyType,
|
|
32
32
|
optBehaviour?:
|
|
33
33
|
| {
|
|
34
34
|
shouldStream?: boolean
|
|
@@ -57,7 +57,7 @@ export default class Response<B = null> {
|
|
|
57
57
|
public getCode(): number {
|
|
58
58
|
return this._statusCode
|
|
59
59
|
}
|
|
60
|
-
public getBody():
|
|
60
|
+
public getBody(): BodyType {
|
|
61
61
|
return this._body
|
|
62
62
|
}
|
|
63
63
|
public appendIntoBody(key: string, value: any): void {
|
|
@@ -68,7 +68,7 @@ export default class Response<B = null> {
|
|
|
68
68
|
}
|
|
69
69
|
public async build(
|
|
70
70
|
context: Context,
|
|
71
|
-
transaction: Transaction<any,
|
|
71
|
+
transaction: Transaction<any, any, any>,
|
|
72
72
|
_optDoNotCallContext: boolean,
|
|
73
73
|
): Promise<void> {
|
|
74
74
|
//Stream support
|
|
@@ -113,7 +113,7 @@ export default class Response<B = null> {
|
|
|
113
113
|
}
|
|
114
114
|
private _rawContext(
|
|
115
115
|
context: Context,
|
|
116
|
-
transaction: Transaction<null,
|
|
116
|
+
transaction: Transaction<null, BodyType>,
|
|
117
117
|
): void {
|
|
118
118
|
//log response and respond to context
|
|
119
119
|
transaction.logger.debug(this._body)
|
|
@@ -179,8 +179,8 @@ export default class Response<B = null> {
|
|
|
179
179
|
...(errCode ? { errCode: errCode } : {}),
|
|
180
180
|
})
|
|
181
181
|
}
|
|
182
|
-
public static SuccessResponse<
|
|
183
|
-
return new Response<
|
|
182
|
+
public static SuccessResponse<BodyType>(body: BodyType): Response<BodyType> {
|
|
183
|
+
return new Response<BodyType>(200, (body ? body : {}) as BodyType)
|
|
184
184
|
}
|
|
185
185
|
public static RedirectResponse(url: string): Response<null> {
|
|
186
186
|
const resp = new Response<null>(302, null)
|
|
@@ -201,8 +201,11 @@ export default class Response<B = null> {
|
|
|
201
201
|
if (contentType) resp.appendHeader("Content-type", contentType)
|
|
202
202
|
return resp
|
|
203
203
|
}
|
|
204
|
-
public static SimpleResponse<
|
|
205
|
-
|
|
204
|
+
public static SimpleResponse<BodyType>(
|
|
205
|
+
body: BodyType,
|
|
206
|
+
optionalCode?: number,
|
|
207
|
+
): Response<BodyType> {
|
|
208
|
+
const resp = new Response<BodyType>(optionalCode || 200, body)
|
|
206
209
|
return resp
|
|
207
210
|
}
|
|
208
211
|
}
|
|
@@ -6,7 +6,7 @@ import Globals from "../Globals"
|
|
|
6
6
|
|
|
7
7
|
// Handler
|
|
8
8
|
export type EventProcessorExecution = (
|
|
9
|
-
transaction: Transaction<null, ResponseErrorType>,
|
|
9
|
+
transaction: Transaction<null, ResponseErrorType, SQSBatchResponse>,
|
|
10
10
|
recordContent: string | object,
|
|
11
11
|
) => Promise<Response | SQSBatchResponse>
|
|
12
12
|
|
|
@@ -48,7 +48,7 @@ export default class EventProcessor {
|
|
|
48
48
|
if (this._event.Records && this._event.Records.length > 0) {
|
|
49
49
|
//safe check for empty events?
|
|
50
50
|
//init transaction for all records
|
|
51
|
-
return await new Transaction<null,
|
|
51
|
+
return await new Transaction<null, ResponseErrorType, SQSBatchResponse>(
|
|
52
52
|
this._event,
|
|
53
53
|
this._context,
|
|
54
54
|
{
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
APIGatewayEvent,
|
|
3
|
-
Context,
|
|
4
|
-
SQSBatchResponse,
|
|
5
|
-
SQSEvent,
|
|
6
|
-
} from "aws-lambda"
|
|
1
|
+
import type { APIGatewayEvent, Context, SQSEvent } from "aws-lambda"
|
|
7
2
|
|
|
8
3
|
import Request from "../API/Request"
|
|
9
4
|
import Response, { ResponseErrorType } from "../API/Response"
|
|
@@ -12,9 +7,15 @@ import Logger, { LoggerConfig } from "../Logger/Logger"
|
|
|
12
7
|
import Publisher, { PublisherConfig } from "../Publisher/Publisher"
|
|
13
8
|
|
|
14
9
|
// Request
|
|
15
|
-
export type TransactionExecution<
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
export type TransactionExecution<
|
|
11
|
+
TransactionType,
|
|
12
|
+
ResponseInnerType,
|
|
13
|
+
MiscRespType = null,
|
|
14
|
+
> = (
|
|
15
|
+
transaction: TransactionType,
|
|
16
|
+
) => Promise<
|
|
17
|
+
Response<ResponseInnerType> | Response<ResponseErrorType> | MiscRespType
|
|
18
|
+
>
|
|
18
19
|
// Config
|
|
19
20
|
export type TransactionConfig = {
|
|
20
21
|
throwOnErrors?: boolean
|
|
@@ -24,17 +25,24 @@ export type TransactionConfig = {
|
|
|
24
25
|
publisher?: PublisherConfig
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export default class Transaction<
|
|
28
|
+
export default class Transaction<
|
|
29
|
+
InputType = object,
|
|
30
|
+
ResponseInnerType = null,
|
|
31
|
+
MiscRespType = null,
|
|
32
|
+
> {
|
|
28
33
|
private event: any
|
|
29
34
|
private context: Context
|
|
30
|
-
private response:
|
|
35
|
+
private response:
|
|
36
|
+
| Response<ResponseInnerType | ResponseErrorType>
|
|
37
|
+
| MiscRespType
|
|
38
|
+
| null
|
|
31
39
|
private syncReturn: boolean
|
|
32
40
|
private retrowErrors: boolean
|
|
33
41
|
//
|
|
34
42
|
public readonly logger: Logger
|
|
35
|
-
public readonly request: Request<
|
|
43
|
+
public readonly request: Request<InputType>
|
|
36
44
|
public readonly publisher: Publisher
|
|
37
|
-
public responseProxy: (response: Response<
|
|
45
|
+
public responseProxy: (response: Response<ResponseInnerType>) => Promise<void>
|
|
38
46
|
//
|
|
39
47
|
constructor(
|
|
40
48
|
event: APIGatewayEvent | SQSEvent,
|
|
@@ -57,14 +65,18 @@ export default class Transaction<T = object, B = null> {
|
|
|
57
65
|
this.retrowErrors = !!config?.throwOnErrors /* retrow internal errors */
|
|
58
66
|
// components
|
|
59
67
|
this.logger = new Logger(config?.logger, transactionId)
|
|
60
|
-
this.request = new Request<
|
|
68
|
+
this.request = new Request<InputType>(this.event, this.context, this.logger)
|
|
61
69
|
this.publisher = new Publisher(config?.publisher)
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
//Main interface
|
|
65
73
|
public async execute(
|
|
66
|
-
executionFunc: TransactionExecution<
|
|
67
|
-
|
|
74
|
+
executionFunc: TransactionExecution<
|
|
75
|
+
Transaction<InputType, ResponseInnerType, MiscRespType>,
|
|
76
|
+
ResponseInnerType,
|
|
77
|
+
MiscRespType
|
|
78
|
+
>,
|
|
79
|
+
): Promise<Response<ResponseInnerType | ResponseErrorType> | MiscRespType> {
|
|
68
80
|
await this.executeLoggerFlush(async () => {
|
|
69
81
|
await this.executeDBTransactions(async () => {
|
|
70
82
|
return await this.iexecute(executionFunc)
|
|
@@ -77,7 +89,11 @@ export default class Transaction<T = object, B = null> {
|
|
|
77
89
|
}
|
|
78
90
|
//Executions
|
|
79
91
|
private async iexecute(
|
|
80
|
-
executionFunc: TransactionExecution<
|
|
92
|
+
executionFunc: TransactionExecution<
|
|
93
|
+
Transaction<InputType, ResponseInnerType, MiscRespType>,
|
|
94
|
+
ResponseInnerType,
|
|
95
|
+
MiscRespType
|
|
96
|
+
>,
|
|
81
97
|
): Promise<boolean> {
|
|
82
98
|
let executionFailed = true //failed til we say no!
|
|
83
99
|
//safe execution handler
|