aws-sdk-vitest-mock 0.2.0 → 0.2.1
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 +1 -1
- package/index.js +18 -7
- package/lib/matchers.d.ts +14 -14
- package/lib/mock-client.d.ts +12 -13
- package/{matchers-_zpN1oru.js → matchers-DdPGAOsD.js} +2 -6
- package/package.json +1 -1
- package/vitest-setup.js +1 -1
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("vitest"),P=require("node:fs"),R=require("node:path"),N=require("node:stream"),W=require("./matchers-G36N2DNa.cjs");class d extends Error{constructor(e,s,c,n){super(e),this.name="AwsError",this.code=s,this.statusCode=c,this.retryable=n}}const C=t=>{const e=t?`The specified key does not exist. Key: ${t}`:"The specified key does not exist.";return new d(e,"NoSuchKey",404,!1)},M=t=>{const e=t?`The specified bucket does not exist. Bucket: ${t}`:"The specified bucket does not exist.";return new d(e,"NoSuchBucket",404,!1)},$=t=>{const e=t?`Access Denied for resource: ${t}`:"Access Denied";return new d(e,"AccessDenied",403,!1)},D=t=>{const e=t?`Requested resource not found: ${t}`:"Requested resource not found";return new d(e,"ResourceNotFoundException",400,!1)},I=()=>new d("The conditional request failed","ConditionalCheckFailedException",400,!1),O=()=>new d("Rate exceeded","Throttling",400,!0),T=()=>new d("We encountered an internal error. Please try again.","InternalServerError",500,!0);function k(){return{enabled:!1,log(t,e){this.enabled&&(e===void 0?console.log(`[aws-sdk-vitest-mock](Debug) ${t}`):console.log(`[aws-sdk-vitest-mock](Debug) ${t}`,e))}}}function y(t){t.enabled=!0}function v(t){t.enabled=!1}function F(t){const e=R.resolve(t),s=P.readFileSync(e,"utf8");return t.endsWith(".json")?JSON.parse(s):s}function L(t,e={}){const{pageSize:s=10,tokenKey:c="NextToken",itemsKey:n="Items"}=e;if(t.length===0)return[{[n]:[]}];const o=[];for(let r=0;r<t.length;r+=s){const u=t.slice(r,r+s),i=r+s<t.length,l={[n]:u};if(i){const a=l;a[c]=`token-${r+s}`}o.push(l)}return o}function A(){return typeof process<"u"&&process.versions?.node?"node":typeof process<"u"&&process.versions?.bun?"bun":"browser"}function K(t){const e=typeof t=="string"?Buffer.from(t,"utf8"):Buffer.from(t);return new N.Readable({read(){this.push(e),this.push(void 0)}})}function q(t){let e;return typeof t=="string"?e=new TextEncoder().encode(t):t instanceof Buffer?e=new Uint8Array(t):e=t,new ReadableStream({start(s){s.enqueue(e),s.close()}})}function m(t){const e=A();return e==="node"||e==="bun"?K(t):q(t)}function w(t,e){return Object.keys(e).every(s=>{const c=e[s],n=t[s];return c&&typeof c=="object"&&!Array.isArray(c)?typeof n!="object"||n===null?!1:w(n,c):n===c})}function j(t,e){if(t===e)return!0;if(typeof t!="object"||t===null||typeof e!="object"||e===null)return t===e;const s=Object.keys(t),c=Object.keys(e);return s.length!==c.length?!1:c.every(n=>{if(!Object.prototype.hasOwnProperty.call(t,n))return!1;const o=t,r=e,u=o[n],i=r[n];return typeof u=="object"&&u!==null&&typeof i=="object"&&i!==null?j(u,i):u===i})}function S(t){return async function(e){const s=()=>this;t.debugLogger.log(`Received command: ${e.constructor.name}`,e.input);const c=t.map.get(e.constructor);if(c){t.debugLogger.log(`Found ${c.length} mock(s) for ${e.constructor.name}`);const n=c.findIndex(o=>o.strict?o.matcher&&j(e.input,o.matcher):!o.matcher||w(e.input,o.matcher));if(n===-1)t.debugLogger.log(`No matching mock found for ${e.constructor.name}`,e.input);else{const o=c[n];if(!o)throw new Error(`Mock at index ${n} not found`);return t.debugLogger.log(`Using mock at index ${n} for ${e.constructor.name}`),o.once&&(c.splice(n,1),t.debugLogger.log(`Removed one-time mock for ${e.constructor.name}`)),o.handler(e.input,s)}}else t.debugLogger.log(`No mocks configured for ${e.constructor.name}`);throw new Error(`No mock configured for command: ${e.constructor.name}`)}}function x(t,e,s,c={}){const n=(r,u)=>{const i={matcher:s,handler:r,once:u,strict:!!c.strict},l=t.map.get(e)??[];if(u){const a=l.findIndex(f=>!f.once);a===-1?l.push(i):l.splice(a,0,i),t.map.set(e,l)}else{const a=l.filter(f=>f.once||JSON.stringify(f.matcher)!==JSON.stringify(s));a.push(i),t.map.set(e,a)}},o={resolves(r){return n(()=>Promise.resolve(r),!1),o},rejects(r){return n(()=>{const u=typeof r=="string"?new Error(r):r;return Promise.reject(u)},!1),o},callsFake(r){return n(r,!1),o},resolvesOnce(r){return n(()=>Promise.resolve(r),!0),o},rejectsOnce(r){return n(()=>{const u=typeof r=="string"?new Error(r):r;return Promise.reject(u)},!0),o},callsFakeOnce(r){return n(r,!0),o},resolvesStream(r){return n(()=>Promise.resolve({Body:m(r)}),!1),o},resolvesStreamOnce(r){return n(()=>Promise.resolve({Body:m(r)}),!0),o},resolvesWithDelay(r,u){const i=l=>{setTimeout(()=>l(r),u)};return n(()=>new Promise(i),!1),o},rejectsWithDelay(r,u){const i=typeof r=="string"?new Error(r):r,l=(a,f)=>{setTimeout(()=>f(i),u)};return n(()=>new Promise(l),!1),o},rejectsWithNoSuchKey(r){return n(()=>Promise.reject(C(r)),!1),o},rejectsWithNoSuchBucket(r){return n(()=>Promise.reject(M(r)),!1),o},rejectsWithAccessDenied(r){return n(()=>Promise.reject($(r)),!1),o},rejectsWithResourceNotFound(r){return n(()=>Promise.reject(D(r)),!1),o},rejectsWithConditionalCheckFailed(){return n(()=>Promise.reject(I()),!1),o},rejectsWithThrottling(){return n(()=>Promise.reject(O()),!1),o},rejectsWithInternalServerError(){return n(()=>Promise.reject(T()),!1),o},resolvesPaginated(r,u={}){const i=L(r,u);let l=0;return n(a=>{const f=u.tokenKey||"NextToken",p=a[f];if(p){const g=/token-(\d+)/.exec(p);if(g&&g[1]){const E=g[1];l=Math.floor(Number.parseInt(E,10)/(u.pageSize||10))}}else l=0;const h=i[l]||i[i.length-1]||i[0];if(!h)throw new Error("No paginated responses available");return l=Math.min(l+1,i.length-1),Promise.resolve(h)},!1),o},resolvesFromFile(r){return n(()=>{const u=F(r);return Promise.resolve(u)},!1),o}};return o}const B=t=>{const e={map:new WeakMap,debugLogger:k()},s=t.prototype,c=b.vi.spyOn(s,"send").mockImplementation(S(e));return{client:void 0,on:(o,r,u)=>x(e,o,r,u),reset:()=>{c.mockClear(),e.map=new WeakMap},restore:()=>{c.mockRestore(),e.map=new WeakMap},calls:()=>c.mock.calls,enableDebug:()=>{y(e.debugLogger)},disableDebug:()=>{v(e.debugLogger)}}},V=t=>{const e={map:new WeakMap,debugLogger:k()},s=b.vi.spyOn(t,"send").mockImplementation(S(e));return{client:t,on:(n,o,r)=>x(e,n,o,r),reset:()=>{s.mockClear(),e.map=new WeakMap},restore:()=>{s.mockRestore(),e.map=new WeakMap},calls:()=>s.mock.calls,enableDebug:()=>{y(e.debugLogger)},disableDebug:()=>{v(e.debugLogger)}}};exports.matchers=W.matchers;exports.mockClient=B;exports.mockClientInstance=V;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("vitest"),P=require("node:fs"),R=require("node:path"),N=require("node:stream"),W=require("./matchers-G36N2DNa.cjs");class d extends Error{constructor(e,s,c,n){super(e),this.name="AwsError",this.code=s,this.statusCode=c,this.retryable=n}}const C=t=>{const e=t?`The specified key does not exist. Key: ${t}`:"The specified key does not exist.";return new d(e,"NoSuchKey",404,!1)},M=t=>{const e=t?`The specified bucket does not exist. Bucket: ${t}`:"The specified bucket does not exist.";return new d(e,"NoSuchBucket",404,!1)},$=t=>{const e=t?`Access Denied for resource: ${t}`:"Access Denied";return new d(e,"AccessDenied",403,!1)},D=t=>{const e=t?`Requested resource not found: ${t}`:"Requested resource not found";return new d(e,"ResourceNotFoundException",400,!1)},I=()=>new d("The conditional request failed","ConditionalCheckFailedException",400,!1),O=()=>new d("Rate exceeded","Throttling",400,!0),T=()=>new d("We encountered an internal error. Please try again.","InternalServerError",500,!0);function k(){return{enabled:!1,log(t,e){this.enabled&&(e===void 0?console.log(`[aws-sdk-vitest-mock](Debug) ${t}`):console.log(`[aws-sdk-vitest-mock](Debug) ${t}`,e))}}}function y(t){t.enabled=!0}function v(t){t.enabled=!1}function F(t){const e=R.resolve(t),s=P.readFileSync(e,"utf8");return t.endsWith(".json")?JSON.parse(s):s}function L(t,e={}){const{pageSize:s=10,tokenKey:c="NextToken",itemsKey:n="Items"}=e;if(t.length===0)return[{[n]:[]}];const o=[];for(let r=0;r<t.length;r+=s){const u=t.slice(r,r+s),i=r+s<t.length,l={[n]:u};if(i){const a=l;a[c]=`token-${r+s}`}o.push(l)}return o}function A(){return typeof process<"u"&&process.versions?.node?"node":typeof process<"u"&&process.versions?.bun?"bun":"browser"}function K(t){const e=typeof t=="string"?Buffer.from(t,"utf8"):Buffer.from(t);return new N.Readable({read(){this.push(e),this.push(void 0)}})}function q(t){let e;return typeof t=="string"?e=new TextEncoder().encode(t):t instanceof Buffer?e=new Uint8Array(t):e=t,new ReadableStream({start(s){s.enqueue(e),s.close()}})}function m(t){const e=A();return e==="node"||e==="bun"?K(t):q(t)}function w(t,e){return Object.keys(e).every(s=>{const c=e[s],n=t[s];return c&&typeof c=="object"&&!Array.isArray(c)?typeof n!="object"||n===null?!1:w(n,c):n===c})}function j(t,e){if(t===e)return!0;if(typeof t!="object"||t===null||typeof e!="object"||e===null)return t===e;const s=Object.keys(t),c=Object.keys(e);return s.length!==c.length?!1:c.every(n=>{if(!Object.prototype.hasOwnProperty.call(t,n))return!1;const o=t,r=e,u=o[n],i=r[n];return typeof u=="object"&&u!==null&&typeof i=="object"&&i!==null?j(u,i):u===i})}function S(t){return async function(e){const s=()=>this;t.debugLogger.log(`Received command: ${e.constructor.name}`,e.input);const c=t.map.get(e.constructor);if(c){t.debugLogger.log(`Found ${c.length} mock(s) for ${e.constructor.name}`);const n=c.findIndex(o=>o.strict?o.matcher&&j(e.input,o.matcher):!o.matcher||w(e.input,o.matcher));if(n===-1)t.debugLogger.log(`No matching mock found for ${e.constructor.name}`,e.input);else{const o=c[n];if(!o)throw new Error(`Mock at index ${n} not found`);return t.debugLogger.log(`Using mock at index ${n} for ${e.constructor.name}`),o.once&&(c.splice(n,1),t.debugLogger.log(`Removed one-time mock for ${e.constructor.name}`)),o.handler(e.input,s())}}else t.debugLogger.log(`No mocks configured for ${e.constructor.name}`);throw new Error(`No mock configured for command: ${e.constructor.name}`)}}function x(t,e,s,c={}){const n=(r,u)=>{const i={matcher:s,handler:r,once:u,strict:!!c.strict},l=t.map.get(e)??[];if(u){const a=l.findIndex(f=>!f.once);a===-1?l.push(i):l.splice(a,0,i),t.map.set(e,l)}else{const a=l.filter(f=>f.once||JSON.stringify(f.matcher)!==JSON.stringify(s));a.push(i),t.map.set(e,a)}},o={resolves(r){return n(()=>Promise.resolve(r),!1),o},rejects(r){return n(()=>{const u=typeof r=="string"?new Error(r):r;return Promise.reject(u)},!1),o},callsFake(r){return n(r,!1),o},resolvesOnce(r){return n(()=>Promise.resolve(r),!0),o},rejectsOnce(r){return n(()=>{const u=typeof r=="string"?new Error(r):r;return Promise.reject(u)},!0),o},callsFakeOnce(r){return n(r,!0),o},resolvesStream(r){return n(()=>Promise.resolve({Body:m(r)}),!1),o},resolvesStreamOnce(r){return n(()=>Promise.resolve({Body:m(r)}),!0),o},resolvesWithDelay(r,u){const i=l=>{setTimeout(()=>l(r),u)};return n(()=>new Promise(i),!1),o},rejectsWithDelay(r,u){const i=typeof r=="string"?new Error(r):r,l=(a,f)=>{setTimeout(()=>f(i),u)};return n(()=>new Promise(l),!1),o},rejectsWithNoSuchKey(r){return n(()=>Promise.reject(C(r)),!1),o},rejectsWithNoSuchBucket(r){return n(()=>Promise.reject(M(r)),!1),o},rejectsWithAccessDenied(r){return n(()=>Promise.reject($(r)),!1),o},rejectsWithResourceNotFound(r){return n(()=>Promise.reject(D(r)),!1),o},rejectsWithConditionalCheckFailed(){return n(()=>Promise.reject(I()),!1),o},rejectsWithThrottling(){return n(()=>Promise.reject(O()),!1),o},rejectsWithInternalServerError(){return n(()=>Promise.reject(T()),!1),o},resolvesPaginated(r,u={}){const i=L(r,u);let l=0;return n(a=>{const f=u.tokenKey||"NextToken",p=a[f];if(p){const g=/token-(\d+)/.exec(p);if(g&&g[1]){const E=g[1];l=Math.floor(Number.parseInt(E,10)/(u.pageSize||10))}}else l=0;const h=i[l]||i[i.length-1]||i[0];if(!h)throw new Error("No paginated responses available");return l=Math.min(l+1,i.length-1),Promise.resolve(h)},!1),o},resolvesFromFile(r){return n(()=>{const u=F(r);return Promise.resolve(u)},!1),o}};return o}const B=t=>{const e={map:new WeakMap,debugLogger:k()},s=t.prototype,c=b.vi.spyOn(s,"send").mockImplementation(S(e));return{client:void 0,on:(o,r,u)=>x(e,o,r,u),reset:()=>{c.mockClear(),e.map=new WeakMap},restore:()=>{c.mockRestore(),e.map=new WeakMap},calls:()=>c.mock.calls,enableDebug:()=>{y(e.debugLogger)},disableDebug:()=>{v(e.debugLogger)}}},V=t=>{const e={map:new WeakMap,debugLogger:k()},s=b.vi.spyOn(t,"send").mockImplementation(S(e));return{client:t,on:(n,o,r)=>x(e,n,o,r),reset:()=>{s.mockClear(),e.map=new WeakMap},restore:()=>{s.mockRestore(),e.map=new WeakMap},calls:()=>s.mock.calls,enableDebug:()=>{y(e.debugLogger)},disableDebug:()=>{v(e.debugLogger)}}};exports.matchers=W.matchers;exports.mockClient=B;exports.mockClientInstance=V;
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { vi as b } from "vitest";
|
|
|
2
2
|
import { readFileSync as P } from "node:fs";
|
|
3
3
|
import R from "node:path";
|
|
4
4
|
import { Readable as N } from "node:stream";
|
|
5
|
-
import { m as X } from "./matchers-
|
|
5
|
+
import { m as X } from "./matchers-DdPGAOsD.js";
|
|
6
6
|
class d extends Error {
|
|
7
7
|
constructor(e, s, c, n) {
|
|
8
8
|
super(e), this.name = "AwsError", this.code = s, this.statusCode = c, this.retryable = n;
|
|
@@ -135,7 +135,10 @@ function x(t) {
|
|
|
135
135
|
`Using mock at index ${n} for ${e.constructor.name}`
|
|
136
136
|
), o.once && (c.splice(n, 1), t.debugLogger.log(
|
|
137
137
|
`Removed one-time mock for ${e.constructor.name}`
|
|
138
|
-
)), o.handler(
|
|
138
|
+
)), o.handler(
|
|
139
|
+
e.input,
|
|
140
|
+
s()
|
|
141
|
+
);
|
|
139
142
|
}
|
|
140
143
|
} else
|
|
141
144
|
t.debugLogger.log(
|
|
@@ -153,9 +156,7 @@ function S(t, e, s, c = {}) {
|
|
|
153
156
|
handler: r,
|
|
154
157
|
once: u,
|
|
155
158
|
strict: !!c.strict
|
|
156
|
-
}, l = t.map.get(
|
|
157
|
-
e
|
|
158
|
-
) ?? [];
|
|
159
|
+
}, l = t.map.get(e) ?? [];
|
|
159
160
|
if (u) {
|
|
160
161
|
const a = l.findIndex((f) => !f.once);
|
|
161
162
|
a === -1 ? l.push(i) : l.splice(a, 0, i), t.map.set(
|
|
@@ -288,7 +289,12 @@ const _ = (t) => {
|
|
|
288
289
|
}, s = t.prototype, c = b.spyOn(s, "send").mockImplementation(x(e));
|
|
289
290
|
return {
|
|
290
291
|
client: void 0,
|
|
291
|
-
on: (o, r, u) => S(
|
|
292
|
+
on: (o, r, u) => S(
|
|
293
|
+
e,
|
|
294
|
+
o,
|
|
295
|
+
r,
|
|
296
|
+
u
|
|
297
|
+
),
|
|
292
298
|
reset: () => {
|
|
293
299
|
c.mockClear(), e.map = /* @__PURE__ */ new WeakMap();
|
|
294
300
|
},
|
|
@@ -310,7 +316,12 @@ const _ = (t) => {
|
|
|
310
316
|
}, s = b.spyOn(t, "send").mockImplementation(x(e));
|
|
311
317
|
return {
|
|
312
318
|
client: t,
|
|
313
|
-
on: (n, o, r) => S(
|
|
319
|
+
on: (n, o, r) => S(
|
|
320
|
+
e,
|
|
321
|
+
n,
|
|
322
|
+
o,
|
|
323
|
+
r
|
|
324
|
+
),
|
|
314
325
|
reset: () => {
|
|
315
326
|
s.mockClear(), e.map = /* @__PURE__ */ new WeakMap();
|
|
316
327
|
},
|
package/lib/matchers.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { MetadataBearer } from '@smithy/types';
|
|
2
|
+
import { AwsClientStub, CommandConstructor } from './mock-client.js';
|
|
3
3
|
interface MatcherResult {
|
|
4
4
|
pass: boolean;
|
|
5
5
|
message: () => string;
|
|
6
6
|
}
|
|
7
7
|
export declare const matchers: {
|
|
8
|
-
toHaveReceivedCommand(received: AwsClientStub, command: CommandConstructor): MatcherResult;
|
|
9
|
-
toHaveReceivedCommandTimes(received: AwsClientStub, command: CommandConstructor, times: number): MatcherResult;
|
|
10
|
-
toHaveReceivedCommandWith(this: {
|
|
8
|
+
toHaveReceivedCommand<TInput extends object, TOutput extends MetadataBearer>(received: AwsClientStub, command: CommandConstructor<TInput, TOutput>): MatcherResult;
|
|
9
|
+
toHaveReceivedCommandTimes<TInput extends object, TOutput extends MetadataBearer>(received: AwsClientStub, command: CommandConstructor<TInput, TOutput>, times: number): MatcherResult;
|
|
10
|
+
toHaveReceivedCommandWith<TInput extends object, TOutput extends MetadataBearer>(this: {
|
|
11
11
|
equals: (a: unknown, b: unknown) => boolean;
|
|
12
|
-
}, received: AwsClientStub, command: CommandConstructor, input:
|
|
13
|
-
toHaveReceivedNthCommandWith(this: {
|
|
12
|
+
}, received: AwsClientStub, command: CommandConstructor<TInput, TOutput>, input: TInput): MatcherResult;
|
|
13
|
+
toHaveReceivedNthCommandWith<TInput extends object, TOutput extends MetadataBearer>(this: {
|
|
14
14
|
equals: (a: unknown, b: unknown) => boolean;
|
|
15
|
-
}, received: AwsClientStub, n: number, command: CommandConstructor, input:
|
|
16
|
-
toHaveReceivedNoOtherCommands(received: AwsClientStub, expectedCommands?: CommandConstructor[]): MatcherResult;
|
|
15
|
+
}, received: AwsClientStub, n: number, command: CommandConstructor<TInput, TOutput>, input: TInput): MatcherResult;
|
|
16
|
+
toHaveReceivedNoOtherCommands<TInput extends object, TOutput extends MetadataBearer>(received: AwsClientStub, expectedCommands?: CommandConstructor<TInput, TOutput>[]): MatcherResult;
|
|
17
17
|
};
|
|
18
18
|
export interface AwsSdkMatchers<R = unknown> {
|
|
19
|
-
toHaveReceivedCommand(command: CommandConstructor): R;
|
|
20
|
-
toHaveReceivedCommandTimes(command: CommandConstructor, times: number): R;
|
|
21
|
-
toHaveReceivedCommandWith(command: CommandConstructor, input:
|
|
22
|
-
toHaveReceivedNthCommandWith(n: number, command: CommandConstructor, input:
|
|
23
|
-
toHaveReceivedNoOtherCommands(expectedCommands?: CommandConstructor[]): R;
|
|
19
|
+
toHaveReceivedCommand<TInput extends object, TOutput extends MetadataBearer>(command: CommandConstructor<TInput, TOutput>): R;
|
|
20
|
+
toHaveReceivedCommandTimes<TInput extends object, TOutput extends MetadataBearer>(command: CommandConstructor<TInput, TOutput>, times: number): R;
|
|
21
|
+
toHaveReceivedCommandWith<TInput extends object, TOutput extends MetadataBearer>(command: CommandConstructor<TInput, TOutput>, input: TInput): R;
|
|
22
|
+
toHaveReceivedNthCommandWith<TInput extends object, TOutput extends MetadataBearer>(n: number, command: CommandConstructor<TInput, TOutput>, input: TInput): R;
|
|
23
|
+
toHaveReceivedNoOtherCommands<TInput extends object, TOutput extends MetadataBearer>(expectedCommands?: CommandConstructor<TInput, TOutput>[]): R;
|
|
24
24
|
}
|
|
25
25
|
export type { MatcherResult };
|
|
26
26
|
declare module "vitest" {
|
package/lib/mock-client.d.ts
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import { SmithyResolvedConfiguration } from '@smithy/smithy-client';
|
|
2
|
-
import {
|
|
1
|
+
import { Command as SmithyCommand, SmithyResolvedConfiguration } from '@smithy/smithy-client';
|
|
2
|
+
import { HttpHandlerOptions, MetadataBearer } from '@smithy/types';
|
|
3
3
|
import { Mock } from 'vitest';
|
|
4
4
|
import { PaginatorOptions } from './utils/paginator-helpers.js';
|
|
5
5
|
import { StreamInput } from './utils/stream-helpers.js';
|
|
6
|
-
export
|
|
7
|
-
$metadata?: unknown;
|
|
8
|
-
}
|
|
9
|
-
export interface StructuralCommand<TInput extends object, TOutput extends MetadataBearer> {
|
|
6
|
+
export type StructuralCommand<TInput extends object, TOutput extends MetadataBearer> = SmithyCommand<TInput, TOutput, any, any, any> | {
|
|
10
7
|
readonly input: TInput;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
8
|
+
readonly __awsSdkVitestMockOutput?: TOutput;
|
|
9
|
+
};
|
|
14
10
|
export type CommandConstructor<TInput extends object, TOutput extends MetadataBearer> = new (input: TInput) => StructuralCommand<TInput, TOutput>;
|
|
11
|
+
type AwsCommandConstructor = CommandConstructor<any, MetadataBearer>;
|
|
12
|
+
export type CommandInputType<TCtor extends AwsCommandConstructor> = ConstructorParameters<TCtor>[0];
|
|
13
|
+
export type CommandOutputType<TCtor extends AwsCommandConstructor> = InstanceType<TCtor> extends StructuralCommand<any, infer TOutput> ? TOutput : MetadataBearer;
|
|
15
14
|
export type AnyClient = {
|
|
16
15
|
send(command: AnyCommand): Promise<MetadataBearer>;
|
|
17
|
-
config: SmithyResolvedConfiguration<unknown>;
|
|
16
|
+
config: SmithyResolvedConfiguration<HttpHandlerOptions> | Record<string, unknown>;
|
|
18
17
|
};
|
|
19
18
|
export type AnyCommand = StructuralCommand<object, MetadataBearer>;
|
|
20
|
-
export type ClientConstructor<TClient extends AnyClient> = (abstract new (
|
|
19
|
+
export type ClientConstructor<TClient extends AnyClient> = (abstract new (...args: unknown[]) => TClient) | {
|
|
21
20
|
prototype: TClient;
|
|
22
21
|
};
|
|
23
|
-
type CommandHandler<TInput extends object = object, TOutput extends MetadataBearer = MetadataBearer, TClient extends AnyClient = AnyClient> = (input: TInput,
|
|
22
|
+
type CommandHandler<TInput extends object = object, TOutput extends MetadataBearer = MetadataBearer, TClient extends AnyClient = AnyClient> = (input: TInput, clientInstance: TClient | undefined) => Promise<Partial<TOutput>>;
|
|
24
23
|
interface MockOptions {
|
|
25
24
|
strict?: boolean;
|
|
26
25
|
}
|
|
27
26
|
export interface AwsClientStub<TClient extends AnyClient = AnyClient> {
|
|
28
27
|
readonly client: TClient | undefined;
|
|
29
|
-
on: <
|
|
28
|
+
on: <TCtor extends AwsCommandConstructor>(command: TCtor, request?: Partial<CommandInputType<TCtor>>, options?: MockOptions) => AwsCommandStub<CommandInputType<TCtor>, CommandOutputType<TCtor>, TClient>;
|
|
30
29
|
reset: () => void;
|
|
31
30
|
restore: () => void;
|
|
32
31
|
calls: () => ReturnType<Mock["mock"]["calls"]["slice"]>;
|
|
@@ -37,9 +37,7 @@ const e = {
|
|
|
37
37
|
toHaveReceivedCommandWith(t, c, a) {
|
|
38
38
|
const r = $(t).filter(
|
|
39
39
|
(n) => n[0] instanceof c
|
|
40
|
-
), m = r.some(
|
|
41
|
-
(n) => this.equals(n[0].input, a)
|
|
42
|
-
), o = c.name;
|
|
40
|
+
), m = r.some((n) => this.equals(n[0].input, a)), o = c.name;
|
|
43
41
|
return {
|
|
44
42
|
pass: m,
|
|
45
43
|
message: () => {
|
|
@@ -59,9 +57,7 @@ ${u}
|
|
|
59
57
|
|
|
60
58
|
But ${i}`;
|
|
61
59
|
}
|
|
62
|
-
const n = r.map(
|
|
63
|
-
(s) => s[0].input
|
|
64
|
-
), 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(
|
|
60
|
+
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(
|
|
65
61
|
n.map((s) => JSON.stringify(s, void 0, 2)).join(`
|
|
66
62
|
|
|
67
63
|
`)
|
package/package.json
CHANGED
package/vitest-setup.js
CHANGED