aws-sdk-vitest-mock 1.0.49 → 1.0.50

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