@juit/lib-aws-mock 1.0.5 → 1.0.7
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/index.cjs +24 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +24 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +36 -19
package/dist/index.cjs
CHANGED
|
@@ -38,23 +38,33 @@ var AWSMock = class {
|
|
|
38
38
|
"[Unknown Command]";
|
|
39
39
|
const lastArgument = _args.pop();
|
|
40
40
|
const cb = typeof lastArgument === "function" ? lastArgument : void 0;
|
|
41
|
-
const
|
|
41
|
+
const input = JSON.parse(JSON.stringify(_command.input));
|
|
42
|
+
const promise = new Promise((resolve, reject) => setImmediate(async () => {
|
|
42
43
|
const handler = this._handlers.get(commandConstuctor);
|
|
43
|
-
if (!handler)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
if (!handler) {
|
|
45
|
+
const error = new Error(`No mock for "${clientName}.${commandName}"`);
|
|
46
|
+
return reject(error);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const output = await handler(input, this._state);
|
|
50
|
+
if (!output) {
|
|
51
|
+
const error = new Error(`Mock for "${clientName}.${commandName}" returned no result`);
|
|
52
|
+
return reject(error);
|
|
53
|
+
}
|
|
54
|
+
const result = JSON.parse(JSON.stringify(output));
|
|
55
|
+
if (!result.$metadata)
|
|
56
|
+
result.$metadata = { httpStatusCode: 200 };
|
|
57
|
+
if (!result.$metadata.requestId)
|
|
58
|
+
result.$metadata.requestId = (0, import_node_crypto.randomUUID)();
|
|
59
|
+
resolve(result);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
reject(error);
|
|
62
|
+
}
|
|
63
|
+
})).then((result) => {
|
|
64
|
+
this._calls.push({ command: commandName, input, success: true });
|
|
55
65
|
return result;
|
|
56
66
|
}, (error) => {
|
|
57
|
-
this._calls.push({ command: commandName, input
|
|
67
|
+
this._calls.push({ command: commandName, input, success: false });
|
|
58
68
|
throw error;
|
|
59
69
|
});
|
|
60
70
|
if (cb)
|
package/dist/index.cjs.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA2B;AAmCpB,IAAM,UAAN,MAA2B;AAAA;AAAA,EAahC,YAAoB,SAAiC;AAAjC;AAElB,SAAK,QAAQ,QAAQ,UAAU;AAG/B,UAAM,aAAa,QAAQ;AAAA,IAAmC;AAG9D,YAAQ,UAAU,OAAO,CAAC,aAAyB,UAA+B;AAChF,YAAM,eAAe,OAAO,eAAe,QAAQ;AACnD,YAAM,oBAAoB,aAAa;AACvC,YAAM,cAAc,mBAAmB;AAAA,MAAmC;AAG1E,YAAM,eAAe,MAAM,IAAI;AAC/B,YAAM,KACJ,OAAO,iBAAiB,aAAa,eAAe;AAGtD,YAAM,UAAU,
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA2B;AAmCpB,IAAM,UAAN,MAA2B;AAAA;AAAA,EAahC,YAAoB,SAAiC;AAAjC;AAElB,SAAK,QAAQ,QAAQ,UAAU;AAG/B,UAAM,aAAa,QAAQ;AAAA,IAAmC;AAG9D,YAAQ,UAAU,OAAO,CAAC,aAAyB,UAA+B;AAChF,YAAM,eAAe,OAAO,eAAe,QAAQ;AACnD,YAAM,oBAAoB,aAAa;AACvC,YAAM,cAAc,mBAAmB;AAAA,MAAmC;AAG1E,YAAM,eAAe,MAAM,IAAI;AAC/B,YAAM,KACJ,OAAO,iBAAiB,aAAa,eAAe;AAGtD,YA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C,SAAS,OAAgC;AACvC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGA,WAAmC;AACjC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAuB;AACrB,UAAM,QAAQ,KAAK;AACnB,WAAO,KAAK;AACZ,SAAK,SAAS,CAAC;AACf,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,UAAgB;AACd,SAAK,QAAQ,UAAU,OAAO,KAAK;AAAA,EACrC;AAAA;AAAA,EAGA,GACI,SACA,SACI;AACN,SAAK,UAAU,IAAI,SAAS,OAAO;AACnC,WAAO;AAAA,EACT;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -14,23 +14,33 @@ var AWSMock = class {
|
|
|
14
14
|
"[Unknown Command]";
|
|
15
15
|
const lastArgument = _args.pop();
|
|
16
16
|
const cb = typeof lastArgument === "function" ? lastArgument : void 0;
|
|
17
|
-
const
|
|
17
|
+
const input = JSON.parse(JSON.stringify(_command.input));
|
|
18
|
+
const promise = new Promise((resolve, reject) => setImmediate(async () => {
|
|
18
19
|
const handler = this._handlers.get(commandConstuctor);
|
|
19
|
-
if (!handler)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
if (!handler) {
|
|
21
|
+
const error = new Error(`No mock for "${clientName}.${commandName}"`);
|
|
22
|
+
return reject(error);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const output = await handler(input, this._state);
|
|
26
|
+
if (!output) {
|
|
27
|
+
const error = new Error(`Mock for "${clientName}.${commandName}" returned no result`);
|
|
28
|
+
return reject(error);
|
|
29
|
+
}
|
|
30
|
+
const result = JSON.parse(JSON.stringify(output));
|
|
31
|
+
if (!result.$metadata)
|
|
32
|
+
result.$metadata = { httpStatusCode: 200 };
|
|
33
|
+
if (!result.$metadata.requestId)
|
|
34
|
+
result.$metadata.requestId = randomUUID();
|
|
35
|
+
resolve(result);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
reject(error);
|
|
38
|
+
}
|
|
39
|
+
})).then((result) => {
|
|
40
|
+
this._calls.push({ command: commandName, input, success: true });
|
|
31
41
|
return result;
|
|
32
42
|
}, (error) => {
|
|
33
|
-
this._calls.push({ command: commandName, input
|
|
43
|
+
this._calls.push({ command: commandName, input, success: false });
|
|
34
44
|
throw error;
|
|
35
45
|
});
|
|
36
46
|
if (cb)
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"mappings": ";AAAA,SAAS,kBAAkB;AAmCpB,IAAM,UAAN,MAA2B;AAAA;AAAA,EAahC,YAAoB,SAAiC;AAAjC;AAElB,SAAK,QAAQ,QAAQ,UAAU;AAG/B,UAAM,aAAa,QAAQ;AAAA,IAAmC;AAG9D,YAAQ,UAAU,OAAO,CAAC,aAAyB,UAA+B;AAChF,YAAM,eAAe,OAAO,eAAe,QAAQ;AACnD,YAAM,oBAAoB,aAAa;AACvC,YAAM,cAAc,mBAAmB;AAAA,MAAmC;AAG1E,YAAM,eAAe,MAAM,IAAI;AAC/B,YAAM,KACJ,OAAO,iBAAiB,aAAa,eAAe;AAGtD,YAAM,UAAU,
|
|
4
|
+
"mappings": ";AAAA,SAAS,kBAAkB;AAmCpB,IAAM,UAAN,MAA2B;AAAA;AAAA,EAahC,YAAoB,SAAiC;AAAjC;AAElB,SAAK,QAAQ,QAAQ,UAAU;AAG/B,UAAM,aAAa,QAAQ;AAAA,IAAmC;AAG9D,YAAQ,UAAU,OAAO,CAAC,aAAyB,UAA+B;AAChF,YAAM,eAAe,OAAO,eAAe,QAAQ;AACnD,YAAM,oBAAoB,aAAa;AACvC,YAAM,cAAc,m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I,IAAuD;AAAA;AAAA,EAEvE;AAAA;AAAA,EAEA,SAAwB,CAAC;AAAA;AAAA,EAEzB,SAA4B;AAAA;AAAA,EA2EpC,SAAS,OAAgC;AACvC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGA,WAAmC;AACjC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,QAAuB;AACrB,UAAM,QAAQ,KAAK;AACnB,WAAO,KAAK;AACZ,SAAK,SAAS,CAAC;AACf,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,UAAgB;AACd,SAAK,QAAQ,UAAU,OAAO,KAAK;AAAA,EACrC;AAAA;AAAA,EAGA,GACI,SACA,SACI;AACN,SAAK,UAAU,IAAI,SAAS,OAAO;AACnC,WAAO;AAAA,EACT;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -64,31 +64,48 @@ export class AWSMock<State = any> {
|
|
|
64
64
|
const cb: ((err: any, data?: any) => void) | undefined =
|
|
65
65
|
typeof lastArgument === 'function' ? lastArgument : undefined
|
|
66
66
|
|
|
67
|
-
//
|
|
68
|
-
const
|
|
67
|
+
// Clone input for every call
|
|
68
|
+
const input = JSON.parse(JSON.stringify(_command.input))
|
|
69
|
+
|
|
70
|
+
// Always work with promises, decoupling from event loop
|
|
71
|
+
const promise = new Promise((resolve, reject) => setImmediate(async () => {
|
|
69
72
|
// Get the handler for the method and verify it
|
|
70
73
|
const handler = this._handlers.get(commandConstuctor)
|
|
71
|
-
if (! handler)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
if (! handler) {
|
|
75
|
+
const error = new Error(`No mock for "${clientName}.${commandName}"`)
|
|
76
|
+
return reject(error)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Call the mocked handler
|
|
80
|
+
try {
|
|
81
|
+
// Call the handler and get the result
|
|
82
|
+
const output: MetadataBearer = await handler(input, this._state)
|
|
83
|
+
|
|
84
|
+
// If no result (null loose check) then simply return a 404
|
|
85
|
+
if (! output) {
|
|
86
|
+
const error = new Error(`Mock for "${clientName}.${commandName}" returned no result`)
|
|
87
|
+
return reject(error)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Clone the output as we did for the input
|
|
91
|
+
const result = JSON.parse(JSON.stringify(output))
|
|
92
|
+
|
|
93
|
+
// If we don't have some metadata, inject some fake stuff
|
|
94
|
+
if (! result.$metadata) result.$metadata = { httpStatusCode: 200 }
|
|
95
|
+
if (! result.$metadata.requestId) result.$metadata.requestId = randomUUID()
|
|
96
|
+
|
|
97
|
+
// All done!
|
|
98
|
+
resolve(result)
|
|
99
|
+
} catch (error) {
|
|
100
|
+
reject(error)
|
|
101
|
+
}
|
|
102
|
+
})).then((result) => {
|
|
86
103
|
// On success, record the call and return the result
|
|
87
|
-
this._calls.push({ command: commandName, input:
|
|
104
|
+
this._calls.push({ command: commandName, input: input, success: true })
|
|
88
105
|
return result
|
|
89
106
|
}, (error) => {
|
|
90
107
|
// On failure, record the call and throw the error
|
|
91
|
-
this._calls.push({ command: commandName, input:
|
|
108
|
+
this._calls.push({ command: commandName, input: input, success: false })
|
|
92
109
|
throw error
|
|
93
110
|
})
|
|
94
111
|
|