@creator.co/wapi 1.5.8 → 1.5.9-alpha.2
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/README.md +3 -0
- package/dist/package.json +1 -1
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/API/Utils.d.ts +42 -0
- package/dist/src/API/Utils.js +83 -0
- package/dist/src/API/Utils.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +2 -2
- package/dist/src/BaseEvent/Transaction.js +0 -1
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/package.json +1 -1
- package/src/API/Response.ts +1 -1
- package/src/BaseEvent/Transaction.ts +3 -4
- package/tests/BaseEvent/Transaction.test.ts +127 -0
- package/tests/Config/Config.test.ts +18 -6
- package/tests/Test.utils.ts +3 -25
- package/tsconfig.json +2 -1
package/README.md
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
-    
|
|
6
6
|
- 
|
|
7
7
|
- 
|
|
8
|
+
- 
|
|
9
|
+
- 
|
|
10
|
+
|
|
8
11
|
|
|
9
12
|
## 📖 Table of Contents
|
|
10
13
|
- [📖 Table of Contents](#-table-of-contents)
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sCAAgC;AAEhC;;;;;;;GAOG;AACH;IAA0B,+BAAK;IAC7B,qBAAY,IAAS;QACnB,YAAA,MAAK,YAAC,IAAI,CAAC,OAAO,IAAI,gBAAgB,CAAC,SAAA;QACvC,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,cAAc,CAAA;;IAC1C,CAAC;IACH,kBAAC;AAAD,CAAC,AALD,CAA0B,KAAK,GAK9B;AAaD;;;GAGG;AACH;IA4CE;;;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;IACW,8BAAqB,GAAnC,UAAoC,MAAW,EAAE,WAAmB;QAClE,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE;YACrC,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;IAED;;;;;OAKG;IACW,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,AAtUD,IAsUC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class containing various static methods for common operations.
|
|
3
|
+
*/
|
|
4
|
+
export default class Utils {
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the application is running in a hybridless container.
|
|
7
|
+
* @returns {boolean} - True if the application is running in a hybridless container, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
static isHybridlessContainer(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a given string is valid.
|
|
12
|
+
* @param {string} string - The string to check.
|
|
13
|
+
* @returns {boolean} - True if the string is valid, false otherwise.
|
|
14
|
+
*/
|
|
15
|
+
static isValidString(string: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Parses a string into an integer and returns null if the string is not a valid number.
|
|
18
|
+
* @param {string} str - The string to parse into an integer.
|
|
19
|
+
* @returns {number | null} - The parsed integer or null if the string is not a valid number.
|
|
20
|
+
*/
|
|
21
|
+
static parseIntNullIfNaN(str?: string): number | null;
|
|
22
|
+
/**
|
|
23
|
+
* Parses a JSON string and returns the resulting object. If the string is empty or
|
|
24
|
+
* cannot be parsed, null is returned.
|
|
25
|
+
* @param {string} string - The JSON string to parse.
|
|
26
|
+
* @returns {any | null} - The parsed object or null if the string is empty or invalid.
|
|
27
|
+
*/
|
|
28
|
+
static parseObjectNullIfEmpty(string: string | undefined): any | null;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a given value is a valid number.
|
|
31
|
+
* @param {string} number - The value to be checked.
|
|
32
|
+
* @returns {boolean} - True if the value is a valid number, false otherwise.
|
|
33
|
+
*/
|
|
34
|
+
static isValidNumber(number: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves the value from an object using a case-insensitive key lookup.
|
|
37
|
+
* @param {any} obj - The object to search for the key.
|
|
38
|
+
* @param {string} key - The key to search for in the object.
|
|
39
|
+
* @returns {any | null} The value associated with the key, or null if the key is not found.
|
|
40
|
+
*/
|
|
41
|
+
static caseInsensitiveObjectForKey(obj: any, key: string): any | null;
|
|
42
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Utility class containing various static methods for common operations.
|
|
5
|
+
*/
|
|
6
|
+
var Utils = /** @class */ (function () {
|
|
7
|
+
function Utils() {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the application is running in a hybridless container.
|
|
11
|
+
* @returns {boolean} - True if the application is running in a hybridless container, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
Utils.isHybridlessContainer = function () {
|
|
14
|
+
return process.env.HYBRIDLESS_RUNTIME == 'true';
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a given string is valid.
|
|
18
|
+
* @param {string} string - The string to check.
|
|
19
|
+
* @returns {boolean} - True if the string is valid, false otherwise.
|
|
20
|
+
*/
|
|
21
|
+
Utils.isValidString = function (string) {
|
|
22
|
+
return (string === null || string === void 0 ? void 0 : string.length) > 0 && !Array.isArray(string);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Parses a string into an integer and returns null if the string is not a valid number.
|
|
26
|
+
* @param {string} str - The string to parse into an integer.
|
|
27
|
+
* @returns {number | null} - The parsed integer or null if the string is not a valid number.
|
|
28
|
+
*/
|
|
29
|
+
Utils.parseIntNullIfNaN = function (str) {
|
|
30
|
+
var n = parseInt(str || '');
|
|
31
|
+
return isNaN(n) ? null : n;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Parses a JSON string and returns the resulting object. If the string is empty or
|
|
35
|
+
* cannot be parsed, null is returned.
|
|
36
|
+
* @param {string} string - The JSON string to parse.
|
|
37
|
+
* @returns {any | null} - The parsed object or null if the string is empty or invalid.
|
|
38
|
+
*/
|
|
39
|
+
Utils.parseObjectNullIfEmpty = function (string) {
|
|
40
|
+
var o = null;
|
|
41
|
+
try {
|
|
42
|
+
o = string ? JSON.parse(string) : null;
|
|
43
|
+
if (o && Object.keys(o).length <= 0)
|
|
44
|
+
o = null;
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
/* empty */
|
|
48
|
+
}
|
|
49
|
+
return o;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a given value is a valid number.
|
|
53
|
+
* @param {string} number - The value to be checked.
|
|
54
|
+
* @returns {boolean} - True if the value is a valid number, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
Utils.isValidNumber = function (number) {
|
|
57
|
+
var validNumb = NaN;
|
|
58
|
+
try {
|
|
59
|
+
validNumb = parseInt(number + '');
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.error('Error while validating number', e);
|
|
63
|
+
}
|
|
64
|
+
return !isNaN(validNumb) && !Array.isArray(number);
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves the value from an object using a case-insensitive key lookup.
|
|
68
|
+
* @param {any} obj - The object to search for the key.
|
|
69
|
+
* @param {string} key - The key to search for in the object.
|
|
70
|
+
* @returns {any | null} The value associated with the key, or null if the key is not found.
|
|
71
|
+
*/
|
|
72
|
+
Utils.caseInsensitiveObjectForKey = function (obj, key) {
|
|
73
|
+
if (!obj)
|
|
74
|
+
return null;
|
|
75
|
+
var insensitiveKey = Object.keys(obj).find(function (k) { return k.toLowerCase() === key.toLowerCase(); });
|
|
76
|
+
if (insensitiveKey && insensitiveKey != '')
|
|
77
|
+
return obj[insensitiveKey];
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
80
|
+
return Utils;
|
|
81
|
+
}());
|
|
82
|
+
exports.default = Utils;
|
|
83
|
+
//# sourceMappingURL=Utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/API/Utils.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH;IAAA;IAwEA,CAAC;IAvEC;;;OAGG;IACW,2BAAqB,GAAnC;QACE,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,MAAM,CAAA;IACjD,CAAC;IAED;;;;OAIG;IACW,mBAAa,GAA3B,UAA4B,MAAc;QACxC,OAAO,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,IAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACrD,CAAC;IAED;;;;OAIG;IACW,uBAAiB,GAA/B,UAAgC,GAAY;QAC1C,IAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC,CAAA;QAC7B,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IAC5B,CAAC;IAED;;;;;OAKG;IACW,4BAAsB,GAApC,UAAqC,MAA0B;QAC7D,IAAI,CAAC,GAAG,IAAI,CAAA;QACZ,IAAI;YACF,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YACtC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC;gBAAE,CAAC,GAAG,IAAI,CAAA;SAC9C;QAAC,OAAO,CAAC,EAAE;YACV,WAAW;SACZ;QACD,OAAO,CAAC,CAAA;IACV,CAAC;IAED;;;;OAIG;IACW,mBAAa,GAA3B,UAA4B,MAAc;QACxC,IAAI,SAAS,GAAG,GAAG,CAAA;QACnB,IAAI;YACF,SAAS,GAAG,QAAQ,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;SAClC;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAA;SAClD;QACD,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACpD,CAAC;IAED;;;;;OAKG;IACW,iCAA2B,GAAzC,UAA0C,GAAQ,EAAE,GAAW;QAC7D,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAA;QACrB,IAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE,EAArC,CAAqC,CAAC,CAAA;QACxF,IAAI,cAAc,IAAI,cAAc,IAAI,EAAE;YAAE,OAAO,GAAG,CAAC,cAAc,CAAC,CAAA;QACtE,OAAO,IAAI,CAAA;IACb,CAAC;IACH,YAAC;AAAD,CAAC,AAxED,IAwEC"}
|
|
@@ -9,7 +9,7 @@ import Publisher, { PublisherConfig } from '../Publisher/Publisher';
|
|
|
9
9
|
* @param {TransactionType} transaction - The transaction to execute.
|
|
10
10
|
* @returns A promise that resolves to the response of the transaction.
|
|
11
11
|
*/
|
|
12
|
-
export type TransactionExecution<TransactionType, ResponseInnerType, MiscRespType =
|
|
12
|
+
export type TransactionExecution<TransactionType, ResponseInnerType, MiscRespType = never> = (transaction: TransactionType) => Promise<Response<ResponseInnerType> | Response<ResponseErrorType> | MiscRespType>;
|
|
13
13
|
/**
|
|
14
14
|
* Represents the configuration options for a transaction.
|
|
15
15
|
* @typedef {Object} TransactionConfig
|
|
@@ -36,7 +36,7 @@ export type StringMap = {
|
|
|
36
36
|
* @template ResponseInnerType - The type of the inner response data for the transaction.
|
|
37
37
|
* @template MiscRespType - The type of miscellaneous response data for the transaction.
|
|
38
38
|
*/
|
|
39
|
-
export default class Transaction<InputType = object, ResponseInnerType = null, MiscRespType =
|
|
39
|
+
export default class Transaction<InputType = object, ResponseInnerType = null, MiscRespType = never, PathParamsType = StringMap, QueryParamsType = StringMap> {
|
|
40
40
|
/**
|
|
41
41
|
* The instance of the DatabaseManager class used for managing the database.
|
|
42
42
|
*/
|
|
@@ -110,7 +110,6 @@ var Transaction = /** @class */ (function () {
|
|
|
110
110
|
// transaction ctx
|
|
111
111
|
this.event = event;
|
|
112
112
|
this.context = context;
|
|
113
|
-
this.response = null;
|
|
114
113
|
// when set, this will be called with the response context right before calling the context suceed/fail - useful for writing the resp for example.
|
|
115
114
|
this.responseProxy = null;
|
|
116
115
|
// transaction flags
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../src/BaseEvent/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,0CAAoC;AACpC,4CAA6D;AAC7D,+DAA6D;AAQ7D,sCAAgC;AAChC,2CAAuD;AACvD,oDAAmE;AAgCnE;;;;;GAKG;AACH;IA8DE;;;;;;OAMG;IACH,qBAAY,KAAiC,EAAE,OAAgB,EAAE,MAA0B;QA9D3F;;WAEG;QACK,oBAAe,GAAoB,iCAAe,CAAC,QAAQ,CAAA;QACnE;;;WAGG;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212
212
|
* @param {Transaction<null, BodyType>} transaction - The transaction object.
|
|
213
213
|
* @returns None
|
|
214
214
|
*/
|
|
215
|
-
private rawContext(context: Context, transaction: Transaction<null, BodyType>): void {
|
|
215
|
+
private rawContext(context: Context, transaction: Transaction<null, BodyType, any>): void {
|
|
216
216
|
//log response and respond to context
|
|
217
217
|
transaction.logger.debug(this.body)
|
|
218
218
|
if (this.getCode() <= 200 && this.getCode() <= 299) context.succeed(this.body)
|
|
@@ -19,7 +19,7 @@ import Publisher, { PublisherConfig } from '../Publisher/Publisher'
|
|
|
19
19
|
* @param {TransactionType} transaction - The transaction to execute.
|
|
20
20
|
* @returns A promise that resolves to the response of the transaction.
|
|
21
21
|
*/
|
|
22
|
-
export type TransactionExecution<TransactionType, ResponseInnerType, MiscRespType =
|
|
22
|
+
export type TransactionExecution<TransactionType, ResponseInnerType, MiscRespType = never> = (
|
|
23
23
|
transaction: TransactionType
|
|
24
24
|
) => Promise<Response<ResponseInnerType> | Response<ResponseErrorType> | MiscRespType>
|
|
25
25
|
|
|
@@ -53,7 +53,7 @@ export type StringMap = { [key: string]: string | null }
|
|
|
53
53
|
export default class Transaction<
|
|
54
54
|
InputType = object,
|
|
55
55
|
ResponseInnerType = null,
|
|
56
|
-
MiscRespType =
|
|
56
|
+
MiscRespType = never,
|
|
57
57
|
PathParamsType = StringMap,
|
|
58
58
|
QueryParamsType = StringMap,
|
|
59
59
|
> {
|
|
@@ -80,7 +80,7 @@ export default class Transaction<
|
|
|
80
80
|
* The response object that can hold different types of responses.
|
|
81
81
|
* @type {Response<ResponseInnerType | ResponseErrorType> | MiscRespType | null}
|
|
82
82
|
*/
|
|
83
|
-
private response: Response<ResponseInnerType | ResponseErrorType> | MiscRespType
|
|
83
|
+
private response: Response<ResponseInnerType | ResponseErrorType> | MiscRespType
|
|
84
84
|
/**
|
|
85
85
|
* A private boolean variable indicating whether the return value of a synchronous operation
|
|
86
86
|
* should be synchronized with the calling thread.
|
|
@@ -128,7 +128,6 @@ export default class Transaction<
|
|
|
128
128
|
// transaction ctx
|
|
129
129
|
this.event = event
|
|
130
130
|
this.context = context
|
|
131
|
-
this.response = null
|
|
132
131
|
// when set, this will be called with the response context right before calling the context suceed/fail - useful for writing the resp for example.
|
|
133
132
|
this.responseProxy = null
|
|
134
133
|
// transaction flags
|
|
@@ -56,6 +56,7 @@ describe('Transaction error invocation path without response', () => {
|
|
|
56
56
|
}
|
|
57
57
|
const context = observableContext({ awsRequestId: '123' })
|
|
58
58
|
const transaction = new Transaction<null, typeof b>(emptyEvent(), context)
|
|
59
|
+
// @ts-expect-error
|
|
59
60
|
const handlerResp = await transaction.execute(async () => {
|
|
60
61
|
return null
|
|
61
62
|
})
|
|
@@ -88,6 +89,7 @@ describe('Transaction error invocation path without response', () => {
|
|
|
88
89
|
syncReturn: true,
|
|
89
90
|
}
|
|
90
91
|
)
|
|
92
|
+
// @ts-expect-error
|
|
91
93
|
const handlerResp = await transaction.execute(async () => {
|
|
92
94
|
return null
|
|
93
95
|
})
|
|
@@ -277,4 +279,129 @@ describe('Transaction - db integration', () => {
|
|
|
277
279
|
})
|
|
278
280
|
})
|
|
279
281
|
|
|
282
|
+
describe('Transaction response types', () => {
|
|
283
|
+
test('Non-response return', async () => {
|
|
284
|
+
const b = { name: '123' }
|
|
285
|
+
const b2 = {
|
|
286
|
+
err: Globals.ErrorResponseInvalidServerResponse,
|
|
287
|
+
rollback: true,
|
|
288
|
+
errCode: Globals.ErrorCode_APIError,
|
|
289
|
+
transactionID: 'unknown',
|
|
290
|
+
}
|
|
291
|
+
const context = observableContext()
|
|
292
|
+
const transaction = new Transaction<null, typeof b>(emptyEvent(), context)
|
|
293
|
+
// @ts-expect-error
|
|
294
|
+
const handlerResp = await transaction.execute(async () => {
|
|
295
|
+
return { d: 1 }
|
|
296
|
+
})
|
|
297
|
+
// check resp
|
|
298
|
+
c_expect(handlerResp).to.be.null
|
|
299
|
+
// ctx
|
|
300
|
+
expect(context.fail).not.toBeCalled()
|
|
301
|
+
expect(context.done).not.toBeCalled()
|
|
302
|
+
expect(context.succeed).toBeCalledWith({
|
|
303
|
+
statusCode: 400,
|
|
304
|
+
body: JSON.stringify(b2),
|
|
305
|
+
headers: defaultHeaders,
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
test('Null return', async () => {
|
|
310
|
+
const b = { name: '123' }
|
|
311
|
+
const b2 = {
|
|
312
|
+
err: Globals.ErrorResponseInvalidServerResponse,
|
|
313
|
+
rollback: true,
|
|
314
|
+
errCode: Globals.ErrorCode_APIError,
|
|
315
|
+
transactionID: 'unknown',
|
|
316
|
+
}
|
|
317
|
+
const context = observableContext()
|
|
318
|
+
const transaction = new Transaction<null, typeof b>(emptyEvent(), context)
|
|
319
|
+
// @ts-expect-error
|
|
320
|
+
const handlerResp = await transaction.execute(async () => {
|
|
321
|
+
return null
|
|
322
|
+
})
|
|
323
|
+
// check resp
|
|
324
|
+
c_expect(handlerResp).to.be.null
|
|
325
|
+
// ctx
|
|
326
|
+
expect(context.fail).not.toBeCalled()
|
|
327
|
+
expect(context.done).not.toBeCalled()
|
|
328
|
+
expect(context.succeed).toBeCalledWith({
|
|
329
|
+
statusCode: 400,
|
|
330
|
+
body: JSON.stringify(b2),
|
|
331
|
+
headers: defaultHeaders,
|
|
332
|
+
})
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
test('Undefined return', async () => {
|
|
336
|
+
const b = { name: '123' }
|
|
337
|
+
const b2 = {
|
|
338
|
+
err: Globals.ErrorResponseInvalidServerResponse,
|
|
339
|
+
rollback: true,
|
|
340
|
+
errCode: Globals.ErrorCode_APIError,
|
|
341
|
+
transactionID: 'unknown',
|
|
342
|
+
}
|
|
343
|
+
const context = observableContext()
|
|
344
|
+
const transaction = new Transaction<null, typeof b>(emptyEvent(), context)
|
|
345
|
+
// @ts-expect-error
|
|
346
|
+
const handlerResp = await transaction.execute(async () => {
|
|
347
|
+
return
|
|
348
|
+
})
|
|
349
|
+
// check resp
|
|
350
|
+
c_expect(handlerResp).to.be.null
|
|
351
|
+
// ctx
|
|
352
|
+
expect(context.fail).not.toBeCalled()
|
|
353
|
+
expect(context.done).not.toBeCalled()
|
|
354
|
+
expect(context.succeed).toBeCalledWith({
|
|
355
|
+
statusCode: 400,
|
|
356
|
+
body: JSON.stringify(b2),
|
|
357
|
+
headers: defaultHeaders,
|
|
358
|
+
})
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
test('Null inner-response return', async () => {
|
|
362
|
+
const b = { name: '123' }
|
|
363
|
+
const b2 = { transactionID: 'unknown' }
|
|
364
|
+
const context = observableContext()
|
|
365
|
+
const transaction = new Transaction<null, typeof b>(emptyEvent(), context)
|
|
366
|
+
// @ts-expect-error
|
|
367
|
+
const handlerResp = await transaction.execute(async () => {
|
|
368
|
+
return Response.SuccessResponse(null)
|
|
369
|
+
})
|
|
370
|
+
// check resp
|
|
371
|
+
c_expect(handlerResp).to.be.null
|
|
372
|
+
// ctx
|
|
373
|
+
expect(context.fail).not.toBeCalled()
|
|
374
|
+
expect(context.done).not.toBeCalled()
|
|
375
|
+
expect(context.succeed).toBeCalledWith({
|
|
376
|
+
statusCode: 200,
|
|
377
|
+
body: JSON.stringify(b2),
|
|
378
|
+
headers: defaultHeaders,
|
|
379
|
+
})
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
test('Wrong keys inner-response return', async () => {
|
|
383
|
+
const b = { name: '123' }
|
|
384
|
+
const b2 = {
|
|
385
|
+
notName: '123',
|
|
386
|
+
transactionID: 'unknown',
|
|
387
|
+
}
|
|
388
|
+
const context = observableContext()
|
|
389
|
+
const transaction = new Transaction<null, typeof b>(emptyEvent(), context)
|
|
390
|
+
// @ts-expect-error
|
|
391
|
+
const handlerResp = await transaction.execute(async () => {
|
|
392
|
+
return Response.SuccessResponse({ notName: '123' })
|
|
393
|
+
})
|
|
394
|
+
// check resp
|
|
395
|
+
c_expect(handlerResp).to.be.null
|
|
396
|
+
// ctx
|
|
397
|
+
expect(context.fail).not.toBeCalled()
|
|
398
|
+
expect(context.done).not.toBeCalled()
|
|
399
|
+
expect(context.succeed).toBeCalledWith({
|
|
400
|
+
statusCode: 200,
|
|
401
|
+
body: JSON.stringify(b2),
|
|
402
|
+
headers: defaultHeaders,
|
|
403
|
+
})
|
|
404
|
+
})
|
|
405
|
+
})
|
|
406
|
+
|
|
280
407
|
export {}
|
|
@@ -3,10 +3,10 @@ import { mockClient } from 'aws-sdk-client-mock'
|
|
|
3
3
|
import { expect as c_expect } from 'chai'
|
|
4
4
|
|
|
5
5
|
import Configuration from '../../src/Config/Configuration'
|
|
6
|
-
import { SampleConfig
|
|
6
|
+
import { SampleConfig } from '../Test.utils'
|
|
7
7
|
|
|
8
8
|
const SSMMock = mockClient(SSMClient)
|
|
9
|
-
const config = new Configuration<
|
|
9
|
+
const config = new Configuration<typeof SampleConfig>(SampleConfig, 'my-prefix')
|
|
10
10
|
describe(`Optional remote environment`, () => {
|
|
11
11
|
// reset mock
|
|
12
12
|
beforeEach(() => {
|
|
@@ -14,10 +14,10 @@ describe(`Optional remote environment`, () => {
|
|
|
14
14
|
config['resetCache']()
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
test('Does not accept sync get', async () => {
|
|
17
|
+
test('Does not accept sync get (+ compiler error)', async () => {
|
|
18
18
|
let err = null
|
|
19
19
|
try {
|
|
20
|
-
// @ts-
|
|
20
|
+
// @ts-expect-error
|
|
21
21
|
config.get('TOKEN_SECRET')
|
|
22
22
|
} catch (e) {
|
|
23
23
|
err = e
|
|
@@ -68,10 +68,10 @@ describe(`Required remote environment`, () => {
|
|
|
68
68
|
config['resetCache']()
|
|
69
69
|
})
|
|
70
70
|
|
|
71
|
-
test('Does not accept sync get', async () => {
|
|
71
|
+
test('Does not accept sync get (+ compiler error)', async () => {
|
|
72
72
|
let err = null
|
|
73
73
|
try {
|
|
74
|
-
// @ts-
|
|
74
|
+
// @ts-expect-error
|
|
75
75
|
config.get('TOKEN_SECRET')
|
|
76
76
|
} catch (e) {
|
|
77
77
|
err = e
|
|
@@ -149,6 +149,18 @@ describe(`Required local environment`, () => {
|
|
|
149
149
|
config['resetCache']()
|
|
150
150
|
})
|
|
151
151
|
|
|
152
|
+
test('Test compiler error', async () => {
|
|
153
|
+
let err = null
|
|
154
|
+
try {
|
|
155
|
+
// @ts-expect-error
|
|
156
|
+
await config.asyncGet('PATH')
|
|
157
|
+
} catch (e) {
|
|
158
|
+
err = e
|
|
159
|
+
}
|
|
160
|
+
c_expect(err).is.not.null
|
|
161
|
+
c_expect(err?.['message']).is.not.null
|
|
162
|
+
})
|
|
163
|
+
|
|
152
164
|
test('Required value with null value', async () => {
|
|
153
165
|
let err = null
|
|
154
166
|
try {
|
package/tests/Test.utils.ts
CHANGED
|
@@ -12,30 +12,7 @@ export const defaultHeaders = {
|
|
|
12
12
|
|
|
13
13
|
export const defaultUrl = `localhost:${Globals.Listener_HTTP_DefaultPort}`
|
|
14
14
|
|
|
15
|
-
export
|
|
16
|
-
PATH: {
|
|
17
|
-
isLocal: true
|
|
18
|
-
required: true
|
|
19
|
-
}
|
|
20
|
-
PATH_FALSY: {
|
|
21
|
-
isLocal: true
|
|
22
|
-
required: true
|
|
23
|
-
}
|
|
24
|
-
PATH123: {
|
|
25
|
-
isLocal: true
|
|
26
|
-
required: false
|
|
27
|
-
}
|
|
28
|
-
TOKEN_SECRET: {
|
|
29
|
-
isRemote: true
|
|
30
|
-
required: true
|
|
31
|
-
}
|
|
32
|
-
TOKEN_SECRET_FALSY: {
|
|
33
|
-
isRemote: true
|
|
34
|
-
required: false
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const SampleConfig: SampleConfigSchema = {
|
|
15
|
+
export const SampleConfig = {
|
|
39
16
|
PATH: {
|
|
40
17
|
isLocal: true,
|
|
41
18
|
required: true,
|
|
@@ -56,7 +33,8 @@ export const SampleConfig: SampleConfigSchema = {
|
|
|
56
33
|
isRemote: true,
|
|
57
34
|
required: false,
|
|
58
35
|
},
|
|
59
|
-
}
|
|
36
|
+
} as const
|
|
37
|
+
|
|
60
38
|
export function observableContext(data?: any) {
|
|
61
39
|
return <Context>(<unknown>{
|
|
62
40
|
done: jest.fn(),
|