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