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