aws-sdk-vitest-mock 0.4.0 → 0.6.0
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 +225 -42
- package/index.cjs +18 -1
- package/index.d.ts +46 -1
- package/index.js +350 -236
- package/lib/matchers.d.ts +141 -0
- package/lib/mock-client.d.ts +457 -19
- package/lib/utils/debug-logger.d.ts +5 -3
- package/lib/utils/file-helpers.d.ts +1 -1
- package/lib/utils/paginator-helpers.d.ts +85 -1
- package/lib/utils/stream-helpers.d.ts +1 -1
- package/{matchers-Rq18z2C7.cjs → matchers-CNhdB_9q.cjs} +2 -2
- package/{matchers-C6AtmwWz.js → matchers-DmTtFk31.js} +101 -2
- package/package.json +11 -2
- package/vitest-setup.cjs +1 -1
- package/vitest-setup.js +1 -1
package/index.js
CHANGED
|
@@ -1,347 +1,461 @@
|
|
|
1
|
-
import { vi as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import { vi as j } from "vitest";
|
|
2
|
+
import { c as F } from "./matchers-DmTtFk31.js";
|
|
3
|
+
import { m as ge } from "./matchers-DmTtFk31.js";
|
|
4
|
+
import { readFileSync as O } from "node:fs";
|
|
5
|
+
import I from "node:path";
|
|
6
|
+
import { Readable as M } from "node:stream";
|
|
6
7
|
class d extends Error {
|
|
7
|
-
constructor(
|
|
8
|
-
super(
|
|
8
|
+
constructor(t, o, i, n) {
|
|
9
|
+
super(t), this.name = "AwsError", this.code = o, this.statusCode = i, this.retryable = n;
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
const T = (e) => new d(
|
|
13
|
+
e ? `The specified key does not exist. Key: ${e}` : "The specified key does not exist.",
|
|
14
|
+
"NoSuchKey",
|
|
15
|
+
404,
|
|
16
|
+
!1
|
|
17
|
+
), K = (e) => new d(
|
|
18
|
+
e ? `The specified bucket does not exist. Bucket: ${e}` : "The specified bucket does not exist.",
|
|
19
|
+
"NoSuchBucket",
|
|
20
|
+
404,
|
|
21
|
+
!1
|
|
22
|
+
), A = (e) => new d(
|
|
23
|
+
e ? `Access Denied for resource: ${e}` : "Access Denied",
|
|
24
|
+
"AccessDenied",
|
|
25
|
+
403,
|
|
26
|
+
!1
|
|
27
|
+
), B = (e) => new d(
|
|
28
|
+
e ? `Requested resource not found: ${e}` : "Requested resource not found",
|
|
29
|
+
"ResourceNotFoundException",
|
|
30
|
+
400,
|
|
31
|
+
!1
|
|
32
|
+
), J = () => new d(
|
|
24
33
|
"The conditional request failed",
|
|
25
34
|
"ConditionalCheckFailedException",
|
|
26
35
|
400,
|
|
27
36
|
!1
|
|
28
|
-
),
|
|
37
|
+
), _ = () => new d("Rate exceeded", "Throttling", 400, !0), q = () => new d(
|
|
29
38
|
"We encountered an internal error. Please try again.",
|
|
30
39
|
"InternalServerError",
|
|
31
40
|
500,
|
|
32
41
|
!0
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
), z = (e) => {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.stringify(e, void 0, 2);
|
|
45
|
+
} catch {
|
|
46
|
+
return typeof e == "object" && e !== null ? "[Complex Object]" : typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : "[Non-serializable value]";
|
|
47
|
+
}
|
|
48
|
+
}, v = (e, t) => {
|
|
49
|
+
const o = F.magenta("aws-sdk-vitest-mock(debug):");
|
|
50
|
+
if (t === void 0)
|
|
51
|
+
console.log(`${o} ${e}`);
|
|
52
|
+
else {
|
|
53
|
+
const i = z(t);
|
|
54
|
+
console.log(`${o} ${e}
|
|
55
|
+
${i}`);
|
|
56
|
+
}
|
|
57
|
+
}, L = (e = !1) => ({
|
|
58
|
+
enabled: e,
|
|
59
|
+
explicitlySet: !1,
|
|
60
|
+
log(t, o) {
|
|
61
|
+
this.enabled && v(t, o);
|
|
62
|
+
},
|
|
63
|
+
logDirect(t, o) {
|
|
64
|
+
v(t, o);
|
|
65
|
+
}
|
|
66
|
+
}), w = (e) => {
|
|
67
|
+
e.enabled = !0, e.explicitlySet = !0;
|
|
68
|
+
}, D = (e) => {
|
|
69
|
+
e.enabled = !1, e.explicitlySet = !0;
|
|
70
|
+
}, V = (e) => {
|
|
71
|
+
const t = I.resolve(e), o = O(t, "utf8");
|
|
72
|
+
return e.endsWith(".json") ? JSON.parse(o) : o;
|
|
73
|
+
}, U = (e, t = {}) => {
|
|
74
|
+
const { pageSize: o = 10, tokenKey: i = "NextToken", itemsKey: n = "Items" } = t;
|
|
75
|
+
if (e.length === 0)
|
|
55
76
|
return [{ [n]: [] }];
|
|
56
|
-
const
|
|
57
|
-
for (let r = 0; r <
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
const a =
|
|
61
|
-
a[
|
|
77
|
+
const s = [];
|
|
78
|
+
for (let r = 0; r < e.length; r += o) {
|
|
79
|
+
const c = e.slice(r, r + o), l = r + o < e.length, u = { [n]: c };
|
|
80
|
+
if (l) {
|
|
81
|
+
const a = u, g = c[c.length - 1];
|
|
82
|
+
a[i] = g;
|
|
62
83
|
}
|
|
63
|
-
|
|
84
|
+
s.push(u);
|
|
64
85
|
}
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
function A(t) {
|
|
71
|
-
const e = typeof t == "string" ? Buffer.from(t, "utf8") : Buffer.from(t);
|
|
72
|
-
let s = !1;
|
|
73
|
-
return new W({
|
|
86
|
+
return s;
|
|
87
|
+
}, G = () => typeof process < "u" && process.versions?.node ? "node" : typeof process < "u" && process.versions?.bun ? "bun" : "browser", H = (e) => {
|
|
88
|
+
const t = typeof e == "string" ? Buffer.from(e, "utf8") : Buffer.from(e);
|
|
89
|
+
let o = !1;
|
|
90
|
+
return new M({
|
|
74
91
|
read() {
|
|
75
|
-
|
|
92
|
+
o || (this.push(t), this.push(null), o = !0);
|
|
76
93
|
}
|
|
77
94
|
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
s.enqueue(e), s.close();
|
|
95
|
+
}, Q = (e) => {
|
|
96
|
+
let t;
|
|
97
|
+
return typeof e == "string" ? t = new TextEncoder().encode(e) : e instanceof Buffer ? t = new Uint8Array(e) : t = e, new ReadableStream({
|
|
98
|
+
start(o) {
|
|
99
|
+
o.enqueue(t), o.close();
|
|
84
100
|
}
|
|
85
101
|
});
|
|
102
|
+
}, S = (e) => {
|
|
103
|
+
const t = G();
|
|
104
|
+
return t === "node" || t === "bun" ? H(e) : Q(e);
|
|
105
|
+
};
|
|
106
|
+
let $ = !1;
|
|
107
|
+
function ce(e) {
|
|
108
|
+
$ = e;
|
|
86
109
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
return e === "node" || e === "bun" ? A(t) : B(t);
|
|
110
|
+
function p(e) {
|
|
111
|
+
return e.explicitlySet ? e.enabled : $;
|
|
90
112
|
}
|
|
91
|
-
function
|
|
92
|
-
return Object.keys(
|
|
93
|
-
const
|
|
94
|
-
return
|
|
113
|
+
function N(e, t) {
|
|
114
|
+
return Object.keys(t).every((o) => {
|
|
115
|
+
const i = t[o], n = e[o];
|
|
116
|
+
return i && typeof i == "object" && !Array.isArray(i) ? typeof n != "object" || n === null ? !1 : N(
|
|
95
117
|
n,
|
|
96
|
-
|
|
97
|
-
) : n ===
|
|
118
|
+
i
|
|
119
|
+
) : n === i;
|
|
98
120
|
});
|
|
99
121
|
}
|
|
100
|
-
function
|
|
101
|
-
if (
|
|
102
|
-
if (typeof
|
|
103
|
-
return
|
|
104
|
-
const
|
|
105
|
-
return
|
|
106
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
107
|
-
const
|
|
108
|
-
return typeof
|
|
122
|
+
function x(e, t) {
|
|
123
|
+
if (e === t) return !0;
|
|
124
|
+
if (typeof e != "object" || e === null || typeof t != "object" || t === null)
|
|
125
|
+
return e === t;
|
|
126
|
+
const o = Object.keys(e), i = Object.keys(t);
|
|
127
|
+
return o.length !== i.length ? !1 : i.every((n) => {
|
|
128
|
+
if (!Object.prototype.hasOwnProperty.call(e, n)) return !1;
|
|
129
|
+
const s = e, r = t, c = s[n], l = r[n];
|
|
130
|
+
return typeof c == "object" && c !== null && typeof l == "object" && l !== null ? x(c, l) : c === l;
|
|
109
131
|
});
|
|
110
132
|
}
|
|
111
|
-
function
|
|
112
|
-
|
|
113
|
-
const s = ()
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
133
|
+
function X(e, t, o) {
|
|
134
|
+
const i = t.map((s, r) => {
|
|
135
|
+
const c = s.matcher ? JSON.stringify(s.matcher, void 0, 2) : "any input", l = s.strict ? " (strict mode)" : "";
|
|
136
|
+
return ` Mock #${r + 1}: ${c}${l}`;
|
|
137
|
+
}).join(`
|
|
138
|
+
`), n = JSON.stringify(o, void 0, 2);
|
|
139
|
+
return new Error(
|
|
140
|
+
`No matching mock found for ${e}.
|
|
141
|
+
|
|
142
|
+
Found ${t.length} mock(s) but none matched the input.
|
|
143
|
+
|
|
144
|
+
Configured mocks:
|
|
145
|
+
${i}
|
|
146
|
+
|
|
147
|
+
Received input:
|
|
148
|
+
${n}
|
|
149
|
+
|
|
150
|
+
Tip: Enable debug mode with enableDebug() for detailed matching information.`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
function Y(e, t) {
|
|
154
|
+
const o = JSON.stringify(t, void 0, 2);
|
|
155
|
+
return new Error(
|
|
156
|
+
`No mock configured for command: ${e}.
|
|
157
|
+
|
|
158
|
+
Received input:
|
|
159
|
+
${o}
|
|
160
|
+
|
|
161
|
+
Did you forget to call mockClient.on(${e})?`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
function Z(e, t) {
|
|
165
|
+
return e.findIndex((o) => o.strict ? o.matcher && x(t, o.matcher) : !o.matcher || N(t, o.matcher));
|
|
166
|
+
}
|
|
167
|
+
function E(e) {
|
|
168
|
+
return async function(t) {
|
|
169
|
+
const o = () => this, i = p(e.debugLogger), n = t.constructor.name;
|
|
170
|
+
i && e.debugLogger.logDirect(
|
|
171
|
+
`Received command: ${n}`,
|
|
172
|
+
t.input
|
|
117
173
|
);
|
|
118
|
-
const
|
|
119
|
-
|
|
174
|
+
const s = e.map.get(
|
|
175
|
+
t.constructor
|
|
120
176
|
);
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
`
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
t.debugLogger.log(
|
|
128
|
-
`No matching mock found for ${e.constructor.name}`,
|
|
129
|
-
e.input
|
|
130
|
-
);
|
|
131
|
-
else {
|
|
132
|
-
const o = c[n];
|
|
133
|
-
if (!o)
|
|
134
|
-
throw new Error(`Mock at index ${n} not found`);
|
|
135
|
-
return t.debugLogger.log(
|
|
136
|
-
`Using mock at index ${n} for ${e.constructor.name}`
|
|
137
|
-
), o.once && (c.splice(n, 1), t.debugLogger.log(
|
|
138
|
-
`Removed one-time mock for ${e.constructor.name}`
|
|
139
|
-
)), o.handler(
|
|
140
|
-
e.input,
|
|
141
|
-
s()
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
} else
|
|
145
|
-
t.debugLogger.log(
|
|
146
|
-
`No mocks configured for ${e.constructor.name}`
|
|
147
|
-
);
|
|
148
|
-
throw new Error(
|
|
149
|
-
`No mock configured for command: ${e.constructor.name}`
|
|
177
|
+
if (!s)
|
|
178
|
+
throw i && e.debugLogger.logDirect(
|
|
179
|
+
`No mocks configured for ${n}`
|
|
180
|
+
), Y(n, t.input);
|
|
181
|
+
i && e.debugLogger.logDirect(
|
|
182
|
+
`Found ${s.length} mock(s) for ${n}`
|
|
150
183
|
);
|
|
184
|
+
const r = Z(s, t.input);
|
|
185
|
+
if (r === -1)
|
|
186
|
+
throw i && e.debugLogger.logDirect(
|
|
187
|
+
`No matching mock found for ${n}`,
|
|
188
|
+
t.input
|
|
189
|
+
), X(n, s, t.input);
|
|
190
|
+
const c = s[r];
|
|
191
|
+
if (!c)
|
|
192
|
+
throw new Error(`Mock at index ${r} not found`);
|
|
193
|
+
return i && e.debugLogger.logDirect(
|
|
194
|
+
`Using mock at index ${r} for ${n}`
|
|
195
|
+
), c.once && (s.splice(r, 1), i && e.debugLogger.logDirect(
|
|
196
|
+
`Removed one-time mock for ${n}`
|
|
197
|
+
)), c.handler(t.input, o());
|
|
151
198
|
};
|
|
152
199
|
}
|
|
153
|
-
function
|
|
154
|
-
const n = (r,
|
|
155
|
-
const
|
|
156
|
-
matcher:
|
|
200
|
+
function C(e, t, o, i = {}) {
|
|
201
|
+
const n = (r, c, l) => {
|
|
202
|
+
const u = {
|
|
203
|
+
matcher: o,
|
|
157
204
|
handler: r,
|
|
158
|
-
once:
|
|
159
|
-
strict: !!
|
|
160
|
-
},
|
|
161
|
-
if (
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
205
|
+
once: c,
|
|
206
|
+
strict: !!i.strict
|
|
207
|
+
}, a = e.map.get(t) ?? [], g = p(e.debugLogger);
|
|
208
|
+
if (c) {
|
|
209
|
+
const f = a.findIndex((h) => !h.once);
|
|
210
|
+
f === -1 ? a.push(u) : a.splice(f, 0, u), e.map.set(
|
|
211
|
+
t,
|
|
212
|
+
a
|
|
213
|
+
), g && e.debugLogger.logDirect(
|
|
214
|
+
`Configured ${l}Once for ${t.name}`,
|
|
215
|
+
o ? { matcher: o, strict: !!i.strict } : void 0
|
|
166
216
|
);
|
|
167
217
|
} else {
|
|
168
|
-
const
|
|
169
|
-
(
|
|
218
|
+
const f = a.filter(
|
|
219
|
+
(h) => h.once || JSON.stringify(h.matcher) !== JSON.stringify(o)
|
|
170
220
|
);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
221
|
+
f.push(u), e.map.set(
|
|
222
|
+
t,
|
|
223
|
+
f
|
|
224
|
+
), g && e.debugLogger.logDirect(
|
|
225
|
+
`Configured ${l} for ${t.name}`,
|
|
226
|
+
o ? { matcher: o, strict: !!i.strict } : void 0
|
|
174
227
|
);
|
|
175
228
|
}
|
|
176
|
-
},
|
|
229
|
+
}, s = {
|
|
177
230
|
resolves(r) {
|
|
178
|
-
return n(() => Promise.resolve(r), !1),
|
|
231
|
+
return n(() => Promise.resolve(r), !1, "resolves"), s;
|
|
179
232
|
},
|
|
180
233
|
rejects(r) {
|
|
181
|
-
return n(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
234
|
+
return n(
|
|
235
|
+
() => {
|
|
236
|
+
const c = typeof r == "string" ? new Error(r) : r;
|
|
237
|
+
return Promise.reject(c);
|
|
238
|
+
},
|
|
239
|
+
!1,
|
|
240
|
+
"rejects"
|
|
241
|
+
), s;
|
|
185
242
|
},
|
|
186
243
|
callsFake(r) {
|
|
187
|
-
return n(r, !1),
|
|
244
|
+
return n(r, !1, "callsFake"), s;
|
|
188
245
|
},
|
|
189
246
|
resolvesOnce(r) {
|
|
190
|
-
return n(() => Promise.resolve(r), !0),
|
|
247
|
+
return n(() => Promise.resolve(r), !0, "resolves"), s;
|
|
191
248
|
},
|
|
192
249
|
rejectsOnce(r) {
|
|
193
|
-
return n(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
250
|
+
return n(
|
|
251
|
+
() => {
|
|
252
|
+
const c = typeof r == "string" ? new Error(r) : r;
|
|
253
|
+
return Promise.reject(c);
|
|
254
|
+
},
|
|
255
|
+
!0,
|
|
256
|
+
"rejects"
|
|
257
|
+
), s;
|
|
197
258
|
},
|
|
198
259
|
callsFakeOnce(r) {
|
|
199
|
-
return n(r, !0),
|
|
260
|
+
return n(r, !0, "callsFake"), s;
|
|
200
261
|
},
|
|
201
262
|
resolvesStream(r) {
|
|
202
263
|
return n(
|
|
203
|
-
() => Promise.resolve({ Body:
|
|
204
|
-
!1
|
|
205
|
-
|
|
264
|
+
() => Promise.resolve({ Body: S(r) }),
|
|
265
|
+
!1,
|
|
266
|
+
"resolvesStream"
|
|
267
|
+
), s;
|
|
206
268
|
},
|
|
207
269
|
resolvesStreamOnce(r) {
|
|
208
270
|
return n(
|
|
209
|
-
() => Promise.resolve({ Body:
|
|
210
|
-
!0
|
|
211
|
-
|
|
271
|
+
() => Promise.resolve({ Body: S(r) }),
|
|
272
|
+
!0,
|
|
273
|
+
"resolvesStream"
|
|
274
|
+
), s;
|
|
212
275
|
},
|
|
213
|
-
resolvesWithDelay(r,
|
|
214
|
-
const
|
|
215
|
-
setTimeout(() =>
|
|
276
|
+
resolvesWithDelay(r, c) {
|
|
277
|
+
const l = (u) => {
|
|
278
|
+
setTimeout(() => u(r), c);
|
|
216
279
|
};
|
|
217
|
-
return n(() => new Promise(
|
|
280
|
+
return n(() => new Promise(l), !1, "resolvesWithDelay"), s;
|
|
218
281
|
},
|
|
219
|
-
rejectsWithDelay(r,
|
|
220
|
-
const
|
|
221
|
-
setTimeout(() =>
|
|
282
|
+
rejectsWithDelay(r, c) {
|
|
283
|
+
const l = typeof r == "string" ? new Error(r) : r, u = (a, g) => {
|
|
284
|
+
setTimeout(() => g(l), c);
|
|
222
285
|
};
|
|
223
|
-
return n(() => new Promise(
|
|
286
|
+
return n(() => new Promise(u), !1, "rejectsWithDelay"), s;
|
|
224
287
|
},
|
|
225
288
|
rejectsWithNoSuchKey(r) {
|
|
226
|
-
return n(
|
|
289
|
+
return n(
|
|
290
|
+
() => Promise.reject(T(r)),
|
|
291
|
+
!1,
|
|
292
|
+
"rejectsWithNoSuchKey"
|
|
293
|
+
), s;
|
|
227
294
|
},
|
|
228
295
|
rejectsWithNoSuchBucket(r) {
|
|
229
|
-
return n(
|
|
296
|
+
return n(
|
|
297
|
+
() => Promise.reject(K(r)),
|
|
298
|
+
!1,
|
|
299
|
+
"rejectsWithNoSuchBucket"
|
|
300
|
+
), s;
|
|
230
301
|
},
|
|
231
302
|
rejectsWithAccessDenied(r) {
|
|
232
|
-
return n(
|
|
303
|
+
return n(
|
|
304
|
+
() => Promise.reject(A(r)),
|
|
305
|
+
!1,
|
|
306
|
+
"rejectsWithAccessDenied"
|
|
307
|
+
), s;
|
|
233
308
|
},
|
|
234
309
|
rejectsWithResourceNotFound(r) {
|
|
235
310
|
return n(
|
|
236
|
-
() => Promise.reject(
|
|
237
|
-
!1
|
|
238
|
-
|
|
311
|
+
() => Promise.reject(B(r)),
|
|
312
|
+
!1,
|
|
313
|
+
"rejectsWithResourceNotFound"
|
|
314
|
+
), s;
|
|
239
315
|
},
|
|
240
316
|
rejectsWithConditionalCheckFailed() {
|
|
241
317
|
return n(
|
|
242
|
-
() => Promise.reject(
|
|
243
|
-
!1
|
|
244
|
-
|
|
318
|
+
() => Promise.reject(J()),
|
|
319
|
+
!1,
|
|
320
|
+
"rejectsWithConditionalCheckFailed"
|
|
321
|
+
), s;
|
|
245
322
|
},
|
|
246
323
|
rejectsWithThrottling() {
|
|
247
|
-
return n(
|
|
324
|
+
return n(
|
|
325
|
+
() => Promise.reject(_()),
|
|
326
|
+
!1,
|
|
327
|
+
"rejectsWithThrottling"
|
|
328
|
+
), s;
|
|
248
329
|
},
|
|
249
330
|
rejectsWithInternalServerError() {
|
|
250
|
-
return n(
|
|
331
|
+
return n(
|
|
332
|
+
() => Promise.reject(q()),
|
|
333
|
+
!1,
|
|
334
|
+
"rejectsWithInternalServerError"
|
|
335
|
+
), s;
|
|
251
336
|
},
|
|
252
|
-
resolvesPaginated(r,
|
|
253
|
-
const
|
|
254
|
-
let
|
|
255
|
-
return
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
337
|
+
resolvesPaginated(r, c = {}) {
|
|
338
|
+
const l = U(r, c);
|
|
339
|
+
let u = 0;
|
|
340
|
+
return e.debugLogger.log(
|
|
341
|
+
`Configured resolvesPaginated for ${t.name}`,
|
|
342
|
+
{ pageSize: c.pageSize, itemsCount: r.length }
|
|
343
|
+
), n(
|
|
344
|
+
(a) => {
|
|
345
|
+
const g = c.tokenKey || "NextToken", f = c.inputTokenKey || g, b = a[f];
|
|
346
|
+
if (b != null) {
|
|
347
|
+
const R = c.itemsKey || "Items";
|
|
348
|
+
let k = 0;
|
|
349
|
+
for (const W of l) {
|
|
350
|
+
const m = W[R];
|
|
351
|
+
if (m && m.length > 0) {
|
|
352
|
+
const P = m[m.length - 1];
|
|
353
|
+
if (JSON.stringify(P) === JSON.stringify(b)) {
|
|
354
|
+
u = k + 1;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
k++;
|
|
359
|
+
}
|
|
360
|
+
} else
|
|
361
|
+
u = 0;
|
|
362
|
+
const y = (
|
|
363
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
364
|
+
l[u] || // eslint-disable-next-line unicorn/prefer-at -- TypeScript target doesn't support Array.at() method
|
|
365
|
+
l[l.length - 1] || l[0]
|
|
366
|
+
);
|
|
367
|
+
if (!y)
|
|
368
|
+
throw new Error("No paginated responses available");
|
|
369
|
+
return u = Math.min(u + 1, l.length - 1), Promise.resolve(y);
|
|
370
|
+
},
|
|
371
|
+
!1,
|
|
372
|
+
"resolvesPaginated"
|
|
373
|
+
), s;
|
|
276
374
|
},
|
|
277
375
|
resolvesFromFile(r) {
|
|
278
|
-
return
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
376
|
+
return e.debugLogger.log(
|
|
377
|
+
`Configured resolvesFromFile for ${t.name}`,
|
|
378
|
+
{ filePath: r }
|
|
379
|
+
), n(
|
|
380
|
+
() => {
|
|
381
|
+
const c = V(r);
|
|
382
|
+
return Promise.resolve(c);
|
|
383
|
+
},
|
|
384
|
+
!1,
|
|
385
|
+
"resolvesFromFile"
|
|
386
|
+
), s;
|
|
282
387
|
}
|
|
283
388
|
};
|
|
284
|
-
return
|
|
389
|
+
return s;
|
|
285
390
|
}
|
|
286
|
-
const
|
|
287
|
-
const
|
|
391
|
+
const ie = (e) => {
|
|
392
|
+
const t = {
|
|
288
393
|
map: /* @__PURE__ */ new WeakMap(),
|
|
289
|
-
debugLogger:
|
|
290
|
-
},
|
|
394
|
+
debugLogger: L()
|
|
395
|
+
}, o = e.prototype, i = j.spyOn(o, "send").mockImplementation(E(t));
|
|
291
396
|
return {
|
|
292
397
|
client: void 0,
|
|
293
|
-
on: (
|
|
294
|
-
|
|
295
|
-
|
|
398
|
+
on: (s, r, c) => C(
|
|
399
|
+
t,
|
|
400
|
+
s,
|
|
296
401
|
r,
|
|
297
|
-
|
|
402
|
+
c
|
|
298
403
|
),
|
|
299
404
|
reset: () => {
|
|
300
|
-
|
|
405
|
+
p(t.debugLogger) && t.debugLogger.logDirect(
|
|
406
|
+
"Clearing call history (mocks preserved)"
|
|
407
|
+
), i.mockClear();
|
|
301
408
|
},
|
|
302
409
|
restore: () => {
|
|
303
|
-
|
|
410
|
+
p(t.debugLogger) && t.debugLogger.logDirect(
|
|
411
|
+
"Restoring original client behavior and clearing all mocks"
|
|
412
|
+
), i.mockRestore(), t.map = /* @__PURE__ */ new WeakMap();
|
|
304
413
|
},
|
|
305
|
-
calls: () =>
|
|
306
|
-
__rawCalls: () =>
|
|
414
|
+
calls: () => i.mock.calls.map((s) => s[0]),
|
|
415
|
+
__rawCalls: () => i.mock.calls,
|
|
307
416
|
enableDebug: () => {
|
|
308
|
-
|
|
417
|
+
w(t.debugLogger);
|
|
309
418
|
},
|
|
310
419
|
disableDebug: () => {
|
|
311
|
-
|
|
420
|
+
D(t.debugLogger);
|
|
312
421
|
}
|
|
313
422
|
};
|
|
314
|
-
},
|
|
315
|
-
const
|
|
423
|
+
}, le = (e) => {
|
|
424
|
+
const t = {
|
|
316
425
|
map: /* @__PURE__ */ new WeakMap(),
|
|
317
|
-
debugLogger:
|
|
318
|
-
},
|
|
426
|
+
debugLogger: L()
|
|
427
|
+
}, o = j.spyOn(e, "send").mockImplementation(E(t));
|
|
319
428
|
return {
|
|
320
|
-
client:
|
|
321
|
-
on: (n,
|
|
322
|
-
|
|
429
|
+
client: e,
|
|
430
|
+
on: (n, s, r) => C(
|
|
431
|
+
t,
|
|
323
432
|
n,
|
|
324
|
-
|
|
433
|
+
s,
|
|
325
434
|
r
|
|
326
435
|
),
|
|
327
436
|
reset: () => {
|
|
328
|
-
|
|
437
|
+
p(t.debugLogger) && t.debugLogger.logDirect(
|
|
438
|
+
"Clearing call history (mocks preserved) for client instance"
|
|
439
|
+
), o.mockClear();
|
|
329
440
|
},
|
|
330
441
|
restore: () => {
|
|
331
|
-
|
|
442
|
+
p(t.debugLogger) && t.debugLogger.logDirect(
|
|
443
|
+
"Restoring original client behavior and clearing all mocks for client instance"
|
|
444
|
+
), o.mockRestore(), t.map = /* @__PURE__ */ new WeakMap();
|
|
332
445
|
},
|
|
333
|
-
calls: () =>
|
|
334
|
-
__rawCalls: () =>
|
|
446
|
+
calls: () => o.mock.calls.map((n) => n[0]),
|
|
447
|
+
__rawCalls: () => o.mock.calls,
|
|
335
448
|
enableDebug: () => {
|
|
336
|
-
|
|
449
|
+
w(t.debugLogger);
|
|
337
450
|
},
|
|
338
451
|
disableDebug: () => {
|
|
339
|
-
|
|
452
|
+
D(t.debugLogger);
|
|
340
453
|
}
|
|
341
454
|
};
|
|
342
455
|
};
|
|
343
456
|
export {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
457
|
+
ge as matchers,
|
|
458
|
+
ie as mockClient,
|
|
459
|
+
le as mockClientInstance,
|
|
460
|
+
ce as setGlobalDebug
|
|
347
461
|
};
|