@creator.co/wapi 1.2.0-beta13 → 1.2.0-beta15
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/dist/src/Config/Configuration.d.ts +18 -12
- package/dist/src/Config/Configuration.js +11 -11
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Server/Router.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/src/Config/Configuration.ts +38 -23
- package/src/Server/Router.ts +6 -0
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sCAAgC;AAChC,EAAE;AACF;IAA0B,+BAAK;IAC7B,qBAAY,IAAS;QAArB,iBAIC;QAHC,IAAM,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAA;gBAClE,kBAAM,GAAG,CAAC;QACV,KAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAA;;IAC9D,CAAC;IACH,kBAAC;AAAD,CAAC,AAND,CAA0B,KAAK,GAM9B;AAMD,EAAE;AACF;IASE,EAAE;IACF,kBACE,UAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sCAAgC;AAChC,EAAE;AACF;IAA0B,+BAAK;IAC7B,qBAAY,IAAS;QAArB,iBAIC;QAHC,IAAM,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAA;gBAClE,kBAAM,GAAG,CAAC;QACV,KAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAA;;IAC9D,CAAC;IACH,kBAAC;AAA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A9B,UAA+B,GAAW;QACxC,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;QAC1C,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;QAClC,OAAO,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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../src/BaseEvent/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,0CAAoC;AACpC,4CAA6D;AAC7D,sCAAgC;AAChC,2CAAuD;AACvD,oDAAmE;AAqBnE;IAkBE,EAAE;IACF,qBACE,KAAiC,EACjC,OAAgB,EAChB,MAA0B;QAE1B,IAAM,aAAa,GAAG,OAAO,CAAC,YAAY;YACxC,CAAC,CAAC,OAAO,CAAC,YAAY;YACtB,CAAC,CAAmB,KAAM,CAAC,cAAc;gBACzC,CAAC,CAAmB,KAAM,CAAC,cAAc,CAAC,SAAS;gBACnD,CAAC,CAAC,SAAS,CAAA;QACb,kBAAkB;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,kJAAkJ;QAClJ,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QACzB,oBAAoB;QACpB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAA,CAAA;QACtC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,CAAA,CAAA,CAAC,4BAA4B;QACxE,aAAa;QACb,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE,aAAa,CAAC,CAAA;QACvD,IAAI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Q,CAAC,8BAA8B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IAC7D,CAAC;IACH,kBAAC;AAAD,CAAC,AA5JD,IA4JC"}
|
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
import { EnvironmentType } from "./EnvironmentVar";
|
|
2
1
|
export type ConfigurationSchema = {
|
|
3
2
|
[name: string]: {
|
|
4
|
-
|
|
3
|
+
isLocal?: boolean;
|
|
4
|
+
isRemote?: boolean;
|
|
5
5
|
required?: boolean;
|
|
6
6
|
cachingPolicy?: string;
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
type ExtractRemote<Type> =
|
|
10
|
-
[Property in keyof Type]
|
|
11
|
-
|
|
12
|
-
} ? Property :
|
|
9
|
+
type ExtractRemote<Type> = {
|
|
10
|
+
[Property in keyof Type]-?: Type[Property] extends {
|
|
11
|
+
isRemote: true;
|
|
12
|
+
} ? Property : null;
|
|
13
13
|
};
|
|
14
|
-
type ExtractLocal<Type> =
|
|
15
|
-
[Property in keyof Type]
|
|
16
|
-
|
|
17
|
-
} ? Property :
|
|
14
|
+
type ExtractLocal<Type> = {
|
|
15
|
+
[Property in keyof Type]-?: Type[Property] extends {
|
|
16
|
+
isLocal: true;
|
|
17
|
+
} ? Property : null;
|
|
18
18
|
};
|
|
19
|
+
type OmitKeysByValueType<T, U> = {
|
|
20
|
+
[P in keyof T]: T[P] extends U ? never : P;
|
|
21
|
+
}[keyof T];
|
|
22
|
+
type OmitByValueType<T, V> = T extends infer _ ? {
|
|
23
|
+
[key in OmitKeysByValueType<T, V>]: T[key];
|
|
24
|
+
} : never;
|
|
19
25
|
export default class Configuration<T extends ConfigurationSchema> {
|
|
20
26
|
private readonly schema;
|
|
21
27
|
private readonly remotePrefix;
|
|
22
28
|
constructor(schema: T, remotePrefix: string);
|
|
23
|
-
get(propName: ExtractLocal<T>): any;
|
|
24
|
-
asyncGet(propName: ExtractRemote<T>): Promise<any>;
|
|
29
|
+
get(propName: keyof OmitByValueType<ExtractLocal<T>, null>): any;
|
|
30
|
+
asyncGet(propName: keyof OmitByValueType<ExtractRemote<T>, null>): Promise<any>;
|
|
25
31
|
private getCachedValue;
|
|
26
32
|
private cacheValue;
|
|
27
33
|
}
|
|
@@ -47,33 +47,33 @@ var Configuration = /** @class */ (function () {
|
|
|
47
47
|
this.remotePrefix = remotePrefix;
|
|
48
48
|
}
|
|
49
49
|
Configuration.prototype.get = function (propName) {
|
|
50
|
-
|
|
51
|
-
var propSchema = this.schema[
|
|
52
|
-
var v = this.getCachedValue(
|
|
50
|
+
var propString = propName;
|
|
51
|
+
var propSchema = this.schema[propString];
|
|
52
|
+
var v = this.getCachedValue(propString);
|
|
53
53
|
v =
|
|
54
54
|
v ||
|
|
55
|
-
new EnvironmentVar_1.default(
|
|
56
|
-
this.cacheValue(
|
|
55
|
+
new EnvironmentVar_1.default(propString, EnvironmentVar_1.EnvironmentType.Local, propSchema.required, this.remotePrefix).syncResolve();
|
|
56
|
+
this.cacheValue(propString, v, propSchema.cachingPolicy);
|
|
57
57
|
return v;
|
|
58
58
|
};
|
|
59
59
|
Configuration.prototype.asyncGet = function (propName) {
|
|
60
60
|
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
-
var propSchema, v, _a;
|
|
61
|
+
var propString, propSchema, v, _a;
|
|
62
62
|
return __generator(this, function (_b) {
|
|
63
63
|
switch (_b.label) {
|
|
64
64
|
case 0:
|
|
65
|
-
|
|
66
|
-
propSchema = this.schema[
|
|
67
|
-
v = this.getCachedValue(
|
|
65
|
+
propString = propName;
|
|
66
|
+
propSchema = this.schema[propString];
|
|
67
|
+
v = this.getCachedValue(propString);
|
|
68
68
|
_a = v;
|
|
69
69
|
if (_a) return [3 /*break*/, 2];
|
|
70
|
-
return [4 /*yield*/, new EnvironmentVar_1.default(
|
|
70
|
+
return [4 /*yield*/, new EnvironmentVar_1.default(propString, EnvironmentVar_1.EnvironmentType.PlainRemote, propSchema.required, this.remotePrefix).resolve()];
|
|
71
71
|
case 1:
|
|
72
72
|
_a = (_b.sent());
|
|
73
73
|
_b.label = 2;
|
|
74
74
|
case 2:
|
|
75
75
|
v = _a;
|
|
76
|
-
this.cacheValue(
|
|
76
|
+
this.cacheValue(propString, v, propSchema.cachingPolicy);
|
|
77
77
|
return [2 /*return*/, v];
|
|
78
78
|
}
|
|
79
79
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/Config/Configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAsC;AACtC,+CAAgD;AAEhD,mDAAkE;AAElE,qCAAqC;AACrC,IAAM,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/Config/Configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAsC;AACtC,+CAAgD;AAEhD,mDAAkE;AAElE,qCAAqC;AACrC,IAAM,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAA;AAwCjC;IAGE,uBAAY,MAAS,EAAE,YAAoB;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAEM,2BAAG,GAAV,UAAW,QAAsD;QAC/D,IAAM,UAAU,GAAG,QAAkB,CAAA;QACrC,IAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QAC1C,IAAI,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;QACvC,CAAC;YACC,CAAC;gBACD,IAAI,wBAAc,CAChB,UAAU,EACV,gCAAe,CAAC,KAAK,EACrB,UAAU,CAAC,QAAQ,EACnB,IAAI,CAAC,YAAY,CAClB,CAAC,WAAW,EAAE,CAAA;QACjB,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;QACxD,OAAO,CAAC,CAAA;IACV,CAAC;IACY,gCAAQ,GAArB,UACE,QAAuD;;;;;;wBAEjD,UAAU,GAAG,QAAkB,CAAA;wBAC/B,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;wBACtC,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;wBAErC,KAAA,CAAC,CAAA;gCAAD,wBAAC;wBACA,qBAAM,IAAI,wBAAc,CACvB,UAAU,EACV,gCAAe,CAAC,WAAW,EAC3B,UAAU,CAAC,QAAQ,EACnB,IAAI,CAAC,YAAY,CAClB,CAAC,OAAO,EAAE,EAAA;;wBALX,KAAA,CAAC,SAKU,CAAC,CAAA;;;wBAPd,CAAC,KAOa,CAAA;wBACd,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;wBACxD,sBAAO,CAAC,EAAA;;;;KACT;IACD,gBAAgB;IACR,sCAAc,GAAtB,UAAuB,QAAgB;QACrC,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACjC,CAAC;IACO,kCAAU,GAAlB,UACE,QAAgB,EAChB,KAAU,EACV,MAAqB;QAArB,uBAAA,EAAA,aAAqB;QAErB,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;IAC9D,CAAC;IACH,oBAAC;AAAD,CAAC,AAnDD,IAmDC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":";;AAEA,yDAAmD;AACnD,uCAAiC;AAEjC,sCAAgC;
|
|
1
|
+
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":";;AAEA,yDAAmD;AACnD,uCAAiC;AAEjC,sCAAgC;AAqChC;IAGE,gBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE;YAC9B,CAAC,CAAC,IAAI,yBAAe,CAAC,MAAM,CAAC;YAC7B,CAAC,CAAC,IAAI,gBAAM,CAAC,MAAM,CAAC,CAAA;IACxB,CAAC;IACM,0BAAS,GAAhB;QACE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IAChC,CAAC;IACO,4BAAW,GAAnB;QACE,OAAO,eAAK,CAAC,qBAAqB,EAAE,CAAA;IACtC,CAAC;IACH,aAAC;AAAD,CAAC,AAfD,IAeC"}
|
package/package.json
CHANGED
package/src/API/Request.ts
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
|
@@ -8,29 +8,42 @@ const cacheStore = new MemCache()
|
|
|
8
8
|
|
|
9
9
|
export type ConfigurationSchema = {
|
|
10
10
|
[name: string]: {
|
|
11
|
-
|
|
11
|
+
isLocal?: boolean
|
|
12
|
+
isRemote?: boolean
|
|
12
13
|
required?: boolean
|
|
13
14
|
cachingPolicy?: string
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
// runtime type infer to ConfigurationSchema keys, which type is remote
|
|
18
|
-
type ExtractRemote<Type> =
|
|
19
|
-
[Property in keyof Type]
|
|
20
|
-
|
|
19
|
+
type ExtractRemote<Type> = {
|
|
20
|
+
[Property in keyof Type]-?: Type[Property] extends {
|
|
21
|
+
isRemote: true
|
|
21
22
|
}
|
|
22
23
|
? Property
|
|
23
|
-
:
|
|
24
|
+
: null
|
|
24
25
|
}
|
|
25
26
|
// runtime type infer to ConfigurationSchema keys, which type is local
|
|
26
|
-
type ExtractLocal<Type> =
|
|
27
|
-
[Property in keyof Type]
|
|
28
|
-
|
|
27
|
+
type ExtractLocal<Type> = {
|
|
28
|
+
[Property in keyof Type]-?: Type[Property] extends {
|
|
29
|
+
isLocal: true
|
|
29
30
|
}
|
|
30
31
|
? Property
|
|
31
|
-
:
|
|
32
|
+
: null
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
// Helpers to filter null keys
|
|
36
|
+
type OmitKeysByValueType<T, U> = {
|
|
37
|
+
[P in keyof T]: T[P] extends U ? never : P
|
|
38
|
+
}[keyof T]
|
|
39
|
+
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
|
+
type OmitByValueType<T, V> = T extends infer _
|
|
42
|
+
? {
|
|
43
|
+
[key in OmitKeysByValueType<T, V>]: T[key]
|
|
44
|
+
}
|
|
45
|
+
: never
|
|
46
|
+
|
|
34
47
|
export default class Configuration<T extends ConfigurationSchema> {
|
|
35
48
|
private readonly schema: T
|
|
36
49
|
private readonly remotePrefix: string
|
|
@@ -39,34 +52,36 @@ export default class Configuration<T extends ConfigurationSchema> {
|
|
|
39
52
|
this.remotePrefix = remotePrefix
|
|
40
53
|
}
|
|
41
54
|
|
|
42
|
-
public get(propName: ExtractLocal<T>): any {
|
|
43
|
-
|
|
44
|
-
const propSchema = this.schema[
|
|
45
|
-
let v = this.getCachedValue(
|
|
55
|
+
public get(propName: keyof OmitByValueType<ExtractLocal<T>, null>): any {
|
|
56
|
+
const propString = propName as string
|
|
57
|
+
const propSchema = this.schema[propString]
|
|
58
|
+
let v = this.getCachedValue(propString)
|
|
46
59
|
v =
|
|
47
60
|
v ||
|
|
48
61
|
new EnvironmentVar<string>(
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
propString,
|
|
63
|
+
EnvironmentType.Local,
|
|
51
64
|
propSchema.required,
|
|
52
65
|
this.remotePrefix,
|
|
53
66
|
).syncResolve()
|
|
54
|
-
this.cacheValue(
|
|
67
|
+
this.cacheValue(propString, v, propSchema.cachingPolicy)
|
|
55
68
|
return v
|
|
56
69
|
}
|
|
57
|
-
public async asyncGet(
|
|
58
|
-
propName
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
public async asyncGet(
|
|
71
|
+
propName: keyof OmitByValueType<ExtractRemote<T>, null>,
|
|
72
|
+
): Promise<any> {
|
|
73
|
+
const propString = propName as string
|
|
74
|
+
const propSchema = this.schema[propString]
|
|
75
|
+
let v = this.getCachedValue(propString)
|
|
61
76
|
v =
|
|
62
77
|
v ||
|
|
63
78
|
(await new EnvironmentVar<string>(
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
propString,
|
|
80
|
+
EnvironmentType.PlainRemote,
|
|
66
81
|
propSchema.required,
|
|
67
82
|
this.remotePrefix,
|
|
68
83
|
).resolve())
|
|
69
|
-
this.cacheValue(
|
|
84
|
+
this.cacheValue(propString, v, propSchema.cachingPolicy)
|
|
70
85
|
return v
|
|
71
86
|
}
|
|
72
87
|
// caching layer
|
package/src/Server/Router.ts
CHANGED
|
@@ -13,6 +13,12 @@ import Transaction, {
|
|
|
13
13
|
export interface Route<InputType = any, OutputType = any> {
|
|
14
14
|
path: string
|
|
15
15
|
method: string
|
|
16
|
+
/* If you are here to know why implementing this method
|
|
17
|
+
does not auto infer the param type, check long discussion on TS
|
|
18
|
+
- https://github.com/Microsoft/TypeScript/issues/1373
|
|
19
|
+
- https://github.com/microsoft/TypeScript/issues/23911#issuecomment-1351020050 (proposed solution)
|
|
20
|
+
- https://github.com/microsoft/TypeScript/issues/10570
|
|
21
|
+
*/
|
|
16
22
|
handler: TransactionExecution<
|
|
17
23
|
Transaction<InputType, OutputType | ResponseErrorType>,
|
|
18
24
|
OutputType | ResponseErrorType
|