aws-sdk-vitest-mock 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/matchers.d.ts CHANGED
@@ -4,22 +4,163 @@ interface MatcherResult {
4
4
  pass: boolean;
5
5
  message: () => string;
6
6
  }
7
+ /**
8
+ * Custom Vitest matchers for asserting AWS SDK command calls.
9
+ *
10
+ * @category Matchers
11
+ *
12
+ * @example Setup matchers in your test setup file
13
+ * ```typescript
14
+ * import { expect } from 'vitest';
15
+ * import { matchers } from 'aws-sdk-vitest-mock';
16
+ *
17
+ * expect.extend(matchers);
18
+ * ```
19
+ */
7
20
  export declare const matchers: {
21
+ /**
22
+ * Assert that a command was received at least once.
23
+ *
24
+ * @param received - The AWS client stub
25
+ * @param command - The command constructor to check for
26
+ * @returns Matcher result
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const s3Mock = mockClient(S3Client);
31
+ * const client = new S3Client({});
32
+ *
33
+ * await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file.txt' }));
34
+ *
35
+ * expect(s3Mock).toHaveReceivedCommand(GetObjectCommand);
36
+ * ```
37
+ */
8
38
  toHaveReceivedCommand<TInput extends object, TOutput extends MetadataBearer>(received: AwsClientStub, command: CommandConstructor<TInput, TOutput>): MatcherResult;
39
+ /**
40
+ * Assert that a command was received exactly N times.
41
+ *
42
+ * @param received - The AWS client stub
43
+ * @param command - The command constructor to check for
44
+ * @param times - The exact number of times the command should have been received
45
+ * @returns Matcher result
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const s3Mock = mockClient(S3Client);
50
+ * const client = new S3Client({});
51
+ *
52
+ * await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file1.txt' }));
53
+ * await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file2.txt' }));
54
+ *
55
+ * expect(s3Mock).toHaveReceivedCommandTimes(GetObjectCommand, 2);
56
+ * ```
57
+ */
9
58
  toHaveReceivedCommandTimes<TInput extends object, TOutput extends MetadataBearer>(received: AwsClientStub, command: CommandConstructor<TInput, TOutput>, times: number): MatcherResult;
59
+ /**
60
+ * Assert that a command was received with specific input parameters.
61
+ *
62
+ * @param received - The AWS client stub
63
+ * @param command - The command constructor to check for
64
+ * @param input - The expected input parameters
65
+ * @returns Matcher result
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const s3Mock = mockClient(S3Client);
70
+ * const client = new S3Client({});
71
+ *
72
+ * await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file.txt' }));
73
+ *
74
+ * expect(s3Mock).toHaveReceivedCommandWith(GetObjectCommand, {
75
+ * Bucket: 'test',
76
+ * Key: 'file.txt'
77
+ * });
78
+ * ```
79
+ */
10
80
  toHaveReceivedCommandWith<TInput extends object, TOutput extends MetadataBearer>(this: {
11
81
  equals: (a: unknown, b: unknown) => boolean;
12
82
  }, received: AwsClientStub, command: CommandConstructor<TInput, TOutput>, input: TInput): MatcherResult;
83
+ /**
84
+ * Assert that the Nth command call was a specific command with specific input.
85
+ *
86
+ * @param received - The AWS client stub
87
+ * @param n - The call number (1-indexed)
88
+ * @param command - The command constructor to check for
89
+ * @param input - The expected input parameters
90
+ * @returns Matcher result
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const s3Mock = mockClient(S3Client);
95
+ * const client = new S3Client({});
96
+ *
97
+ * await client.send(new PutObjectCommand({ Bucket: 'test', Key: 'file1.txt' }));
98
+ * await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file2.txt' }));
99
+ *
100
+ * expect(s3Mock).toHaveReceivedNthCommandWith(2, GetObjectCommand, {
101
+ * Bucket: 'test',
102
+ * Key: 'file2.txt'
103
+ * });
104
+ * ```
105
+ */
13
106
  toHaveReceivedNthCommandWith<TInput extends object, TOutput extends MetadataBearer>(this: {
14
107
  equals: (a: unknown, b: unknown) => boolean;
15
108
  }, received: AwsClientStub, n: number, command: CommandConstructor<TInput, TOutput>, input: TInput): MatcherResult;
109
+ /**
110
+ * Assert that no commands other than the expected ones were received.
111
+ *
112
+ * @param received - The AWS client stub
113
+ * @param expectedCommands - Array of command constructors that are allowed
114
+ * @returns Matcher result
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const s3Mock = mockClient(S3Client);
119
+ * const client = new S3Client({});
120
+ *
121
+ * await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file.txt' }));
122
+ * await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'other.txt' }));
123
+ *
124
+ * expect(s3Mock).toHaveReceivedNoOtherCommands([GetObjectCommand]);
125
+ * ```
126
+ */
16
127
  toHaveReceivedNoOtherCommands<TInput extends object, TOutput extends MetadataBearer>(received: AwsClientStub, expectedCommands?: CommandConstructor<TInput, TOutput>[]): MatcherResult;
17
128
  };
129
+ /**
130
+ * TypeScript interface for AWS SDK Vitest matchers.
131
+ * This interface is used to extend Vitest's assertion types.
132
+ *
133
+ * @category Matchers
134
+ */
18
135
  export interface AwsSdkMatchers<R = unknown> {
136
+ /**
137
+ * Assert that a command was received at least once.
138
+ * @param command - The command constructor to check for
139
+ */
19
140
  toHaveReceivedCommand<TInput extends object, TOutput extends MetadataBearer>(command: CommandConstructor<TInput, TOutput>): R;
141
+ /**
142
+ * Assert that a command was received exactly N times.
143
+ * @param command - The command constructor to check for
144
+ * @param times - The exact number of times
145
+ */
20
146
  toHaveReceivedCommandTimes<TInput extends object, TOutput extends MetadataBearer>(command: CommandConstructor<TInput, TOutput>, times: number): R;
147
+ /**
148
+ * Assert that a command was received with specific input.
149
+ * @param command - The command constructor to check for
150
+ * @param input - The expected input parameters
151
+ */
21
152
  toHaveReceivedCommandWith<TInput extends object, TOutput extends MetadataBearer>(command: CommandConstructor<TInput, TOutput>, input: TInput): R;
153
+ /**
154
+ * Assert that the Nth command call matches expectations.
155
+ * @param n - The call number (1-indexed)
156
+ * @param command - The command constructor to check for
157
+ * @param input - The expected input parameters
158
+ */
22
159
  toHaveReceivedNthCommandWith<TInput extends object, TOutput extends MetadataBearer>(n: number, command: CommandConstructor<TInput, TOutput>, input: TInput): R;
160
+ /**
161
+ * Assert that only expected commands were received.
162
+ * @param expectedCommands - Array of allowed command constructors
163
+ */
23
164
  toHaveReceivedNoOtherCommands<TInput extends object, TOutput extends MetadataBearer>(expectedCommands?: CommandConstructor<TInput, TOutput>[]): R;
24
165
  }
25
166
  export type { MatcherResult };
@@ -3,6 +3,27 @@ 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
+ /**
7
+ * Set global debug mode for all mocks.
8
+ * When enabled, all mocks will log debug information unless explicitly disabled at the mock level.
9
+ *
10
+ * @param enabled - Whether to enable debug logging globally
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { setGlobalDebug, mockClient } from 'aws-sdk-vitest-mock';
15
+ * import { S3Client } from '@aws-sdk/client-s3';
16
+ *
17
+ * // Enable debug for all mocks
18
+ * setGlobalDebug(true);
19
+ *
20
+ * const s3Mock = mockClient(S3Client); // Automatically has debug enabled
21
+ *
22
+ * // Disable debug for a specific mock
23
+ * s3Mock.disableDebug(); // This mock won't log, but others will
24
+ * ```
25
+ */
26
+ export declare function setGlobalDebug(enabled: boolean): void;
6
27
  export type StructuralCommand<TInput extends object, TOutput extends MetadataBearer> = SmithyCommand<TInput, TOutput, any, any, any> | {
7
28
  readonly input: TInput;
8
29
  readonly __awsSdkVitestMockOutput?: TOutput;
@@ -23,57 +44,474 @@ type CommandHandler<TInput extends object = object, TOutput extends MetadataBear
23
44
  interface MockOptions {
24
45
  strict?: boolean;
25
46
  }
47
+ /**
48
+ * Client stub for configuring and managing mock behaviors for an AWS SDK client.
49
+ *
50
+ * @category Core Functions
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const s3Mock = mockClient(S3Client);
55
+ *
56
+ * // Configure mock behavior
57
+ * s3Mock.on(GetObjectCommand).resolves({ Body: 'data' });
58
+ *
59
+ * // Mock works as configured
60
+ * await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file.txt' }));
61
+ * expect(s3Mock.calls()).toHaveLength(1);
62
+ *
63
+ * // Reset clears call history but keeps mock configuration
64
+ * s3Mock.reset();
65
+ * expect(s3Mock.calls()).toHaveLength(0);
66
+ *
67
+ * // Mock still works after reset
68
+ * await client.send(new GetObjectCommand({ Bucket: 'test', Key: 'file.txt' }));
69
+ * expect(s3Mock.calls()).toHaveLength(1);
70
+ * ```
71
+ */
26
72
  export interface AwsClientStub<TClient extends AnyClient = AnyClient> {
73
+ /**
74
+ * The client instance being mocked (undefined for class-level mocks).
75
+ * @readonly
76
+ */
27
77
  readonly client: TClient | undefined;
78
+ /**
79
+ * Configure mock behavior for a specific command.
80
+ *
81
+ * @param command - The AWS SDK command constructor to mock
82
+ * @param request - Optional partial input to match against (uses partial matching by default)
83
+ * @param options - Optional configuration for strict matching
84
+ * @returns A command stub for configuring mock responses
85
+ *
86
+ * @example Match any input
87
+ * ```typescript
88
+ * s3Mock.on(GetObjectCommand).resolves({ Body: 'data' });
89
+ * ```
90
+ *
91
+ * @example Match specific input (partial)
92
+ * ```typescript
93
+ * s3Mock.on(GetObjectCommand, { Bucket: 'my-bucket' }).resolves({ Body: 'bucket data' });
94
+ * ```
95
+ *
96
+ * @example Match exact input (strict)
97
+ * ```typescript
98
+ * s3Mock.on(GetObjectCommand, { Bucket: 'my-bucket', Key: 'file.txt' }, { strict: true })
99
+ * .resolves({ Body: 'exact match' });
100
+ * ```
101
+ */
28
102
  on: <TCtor extends AwsCommandConstructor>(command: TCtor, request?: Partial<CommandInputType<TCtor>>, options?: MockOptions) => AwsCommandStub<CommandInputType<TCtor>, CommandOutputType<TCtor>, TClient>;
103
+ /**
104
+ * Clear mock call history while preserving configured behaviors.
105
+ * Mock configurations remain active after reset, only the call history is cleared.
106
+ * Use this between tests when you want to reuse the same mock setup.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * afterEach(() => {
111
+ * s3Mock.reset();
112
+ * });
113
+ * ```
114
+ */
29
115
  reset: () => void;
116
+ /**
117
+ * Restore the original client behavior and clear all mocks.
118
+ * After calling restore, the client will no longer be mocked.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * afterAll(() => {
123
+ * s3Mock.restore();
124
+ * });
125
+ * ```
126
+ */
30
127
  restore: () => void;
128
+ /**
129
+ * Get an array of all commands that were sent to the client.
130
+ *
131
+ * @returns Array of AWS SDK commands
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const calls = s3Mock.calls();
136
+ * console.log(calls.length); // Number of commands sent
137
+ * console.log(calls[0].input); // Input of first command
138
+ * ```
139
+ */
31
140
  calls: () => AwsSdkCommand[];
32
141
  /** @internal - For use by matchers only */
33
142
  __rawCalls: () => ReturnType<Mock["mock"]["calls"]["slice"]>;
143
+ /**
144
+ * Enable debug logging to see detailed information about mock configuration and interactions.
145
+ * Logs both mock setup (when `.on()`, `.resolves()`, etc. are called) and command execution details.
146
+ * Useful for troubleshooting mock configurations and why commands aren't matching expected mocks.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * s3Mock.enableDebug();
151
+ * // Logs will appear for:
152
+ * // - Mock configuration (when .on(), .resolves(), etc. are called)
153
+ * // - Command execution (incoming commands and inputs)
154
+ * // - Mock matching results and reasons for failures
155
+ * // - Lifecycle events (reset, restore)
156
+ * ```
157
+ */
34
158
  enableDebug: () => void;
159
+ /**
160
+ * Disable debug logging for mock configuration and interactions.
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * s3Mock.disableDebug();
165
+ * ```
166
+ */
35
167
  disableDebug: () => void;
36
168
  }
169
+ /**
170
+ * Command stub for configuring mock behaviors for a specific AWS SDK command.
171
+ * Provides a fluent API for setting up various mock responses and behaviors.
172
+ *
173
+ * @category Command Stub
174
+ *
175
+ * @example Basic usage
176
+ * ```typescript
177
+ * const s3Mock = mockClient(S3Client);
178
+ * s3Mock.on(GetObjectCommand).resolves({ Body: 'data' });
179
+ * ```
180
+ *
181
+ * @example Chaining multiple behaviors
182
+ * ```typescript
183
+ * s3Mock.on(PutObjectCommand)
184
+ * .resolvesOnce({ ETag: '123' })
185
+ * .resolvesOnce({ ETag: '456' })
186
+ * .resolves({ ETag: 'default' });
187
+ * ```
188
+ */
37
189
  export interface AwsCommandStub<TInput extends object, TOutput extends MetadataBearer, TClient extends AnyClient = AnyClient> {
38
- /** Set a permanent mock response (used after all once handlers are consumed) */
190
+ /**
191
+ * Set a permanent mock response that will be used after all one-time handlers are consumed.
192
+ *
193
+ * @param output - Partial output object to return when the command is called
194
+ * @returns The command stub for chaining
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * s3Mock.on(GetObjectCommand).resolves({ Body: 'file contents' });
199
+ * ```
200
+ */
39
201
  resolves: (output: Partial<TOutput>) => AwsCommandStub<TInput, TOutput, TClient>;
40
- /** Set a permanent mock rejection (used after all once handlers are consumed) */
202
+ /**
203
+ * Set a permanent mock rejection that will be used after all one-time handlers are consumed.
204
+ *
205
+ * @param error - Error object or error message string
206
+ * @returns The command stub for chaining
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * s3Mock.on(GetObjectCommand).rejects(new Error('Access denied'));
211
+ * ```
212
+ */
41
213
  rejects: (error: Error | string) => AwsCommandStub<TInput, TOutput, TClient>;
42
- /** Set a permanent custom handler (used after all once handlers are consumed) */
214
+ /**
215
+ * Set a permanent custom handler function that will be used after all one-time handlers are consumed.
216
+ *
217
+ * @param fn - Handler function that receives input and client instance
218
+ * @returns The command stub for chaining
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * s3Mock.on(GetObjectCommand).callsFake(async (input) => {
223
+ * return { Body: `Contents of ${input.Key}` };
224
+ * });
225
+ * ```
226
+ */
43
227
  callsFake: (fn: CommandHandler<TInput, TOutput, TClient>) => AwsCommandStub<TInput, TOutput, TClient>;
44
- /** Add a one-time mock response (consumed in order) */
228
+ /**
229
+ * Add a one-time mock response that will be consumed in order.
230
+ *
231
+ * @param output - Partial output object to return
232
+ * @returns The command stub for chaining
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * s3Mock.on(GetObjectCommand)
237
+ * .resolvesOnce({ Body: 'first call' })
238
+ * .resolvesOnce({ Body: 'second call' });
239
+ * ```
240
+ */
45
241
  resolvesOnce: (output: Partial<TOutput>) => AwsCommandStub<TInput, TOutput, TClient>;
46
- /** Add a one-time mock rejection (consumed in order) */
242
+ /**
243
+ * Add a one-time mock rejection that will be consumed in order.
244
+ *
245
+ * @param error - Error object or error message string
246
+ * @returns The command stub for chaining
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * s3Mock.on(GetObjectCommand)
251
+ * .rejectsOnce('First call fails')
252
+ * .resolves({ Body: 'second call succeeds' });
253
+ * ```
254
+ */
47
255
  rejectsOnce: (error: Error | string) => AwsCommandStub<TInput, TOutput, TClient>;
48
- /** Add a one-time custom handler (consumed in order) */
256
+ /**
257
+ * Add a one-time custom handler that will be consumed in order.
258
+ *
259
+ * @param fn - Handler function that receives input and client instance
260
+ * @returns The command stub for chaining
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * s3Mock.on(GetObjectCommand)
265
+ * .callsFakeOnce(async (input) => ({ Body: 'once' }))
266
+ * .resolves({ Body: 'permanent' });
267
+ * ```
268
+ */
49
269
  callsFakeOnce: (fn: CommandHandler<TInput, TOutput, TClient>) => AwsCommandStub<TInput, TOutput, TClient>;
50
- /** Set a permanent stream response for S3-like operations */
270
+ /**
271
+ * Set a permanent stream response for S3-like operations.
272
+ *
273
+ * @param data - String, Buffer, or Readable stream
274
+ * @returns The command stub for chaining
275
+ *
276
+ * @example
277
+ * ```typescript
278
+ * s3Mock.on(GetObjectCommand).resolvesStream('file contents');
279
+ * ```
280
+ */
51
281
  resolvesStream: (data: StreamInput) => AwsCommandStub<TInput, TOutput, TClient>;
52
- /** Set a one-time stream response for S3-like operations */
282
+ /**
283
+ * Set a one-time stream response for S3-like operations.
284
+ *
285
+ * @param data - String, Buffer, or Readable stream
286
+ * @returns The command stub for chaining
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * s3Mock.on(GetObjectCommand)
291
+ * .resolvesStreamOnce('first stream')
292
+ * .resolvesStream('default stream');
293
+ * ```
294
+ */
53
295
  resolvesStreamOnce: (data: StreamInput) => AwsCommandStub<TInput, TOutput, TClient>;
54
- /** Set a permanent mock response with delay */
296
+ /**
297
+ * Set a permanent mock response with a delay in milliseconds.
298
+ *
299
+ * @param output - Partial output object to return
300
+ * @param delayMs - Delay in milliseconds before resolving
301
+ * @returns The command stub for chaining
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * s3Mock.on(GetObjectCommand).resolvesWithDelay({ Body: 'data' }, 1000);
306
+ * ```
307
+ */
55
308
  resolvesWithDelay: (output: Partial<TOutput>, delayMs: number) => AwsCommandStub<TInput, TOutput, TClient>;
56
- /** Set a permanent mock rejection with delay */
309
+ /**
310
+ * Set a permanent mock rejection with a delay in milliseconds.
311
+ *
312
+ * @param error - Error object or error message string
313
+ * @param delayMs - Delay in milliseconds before rejecting
314
+ * @returns The command stub for chaining
315
+ *
316
+ * @example
317
+ * ```typescript
318
+ * s3Mock.on(GetObjectCommand).rejectsWithDelay('Timeout', 5000);
319
+ * ```
320
+ */
57
321
  rejectsWithDelay: (error: Error | string, delayMs: number) => AwsCommandStub<TInput, TOutput, TClient>;
58
- /** Reject with S3 NoSuchKey error */
322
+ /**
323
+ * Reject with an S3 NoSuchKey error.
324
+ *
325
+ * @param key - Optional key name for error message
326
+ * @returns The command stub for chaining
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * s3Mock.on(GetObjectCommand).rejectsWithNoSuchKey('missing-file.txt');
331
+ * ```
332
+ */
59
333
  rejectsWithNoSuchKey: (key?: string) => AwsCommandStub<TInput, TOutput, TClient>;
60
- /** Reject with S3 NoSuchBucket error */
334
+ /**
335
+ * Reject with an S3 NoSuchBucket error.
336
+ *
337
+ * @param bucket - Optional bucket name for error message
338
+ * @returns The command stub for chaining
339
+ *
340
+ * @example
341
+ * ```typescript
342
+ * s3Mock.on(GetObjectCommand).rejectsWithNoSuchBucket('my-bucket');
343
+ * ```
344
+ */
61
345
  rejectsWithNoSuchBucket: (bucket?: string) => AwsCommandStub<TInput, TOutput, TClient>;
62
- /** Reject with AccessDenied error */
346
+ /**
347
+ * Reject with an AccessDenied error.
348
+ *
349
+ * @param resource - Optional resource name for error message
350
+ * @returns The command stub for chaining
351
+ *
352
+ * @example
353
+ * ```typescript
354
+ * s3Mock.on(GetObjectCommand).rejectsWithAccessDenied('private-file.txt');
355
+ * ```
356
+ */
63
357
  rejectsWithAccessDenied: (resource?: string) => AwsCommandStub<TInput, TOutput, TClient>;
64
- /** Reject with DynamoDB ResourceNotFound error */
358
+ /**
359
+ * Reject with a DynamoDB ResourceNotFound error.
360
+ *
361
+ * @param resource - Optional resource name for error message
362
+ * @returns The command stub for chaining
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * dynamoMock.on(GetItemCommand).rejectsWithResourceNotFound('MyTable');
367
+ * ```
368
+ */
65
369
  rejectsWithResourceNotFound: (resource?: string) => AwsCommandStub<TInput, TOutput, TClient>;
66
- /** Reject with DynamoDB ConditionalCheckFailed error */
370
+ /**
371
+ * Reject with a DynamoDB ConditionalCheckFailed error.
372
+ *
373
+ * @returns The command stub for chaining
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * dynamoMock.on(PutItemCommand).rejectsWithConditionalCheckFailed();
378
+ * ```
379
+ */
67
380
  rejectsWithConditionalCheckFailed: () => AwsCommandStub<TInput, TOutput, TClient>;
68
- /** Reject with Throttling error */
381
+ /**
382
+ * Reject with a Throttling error.
383
+ *
384
+ * @returns The command stub for chaining
385
+ *
386
+ * @example
387
+ * ```typescript
388
+ * s3Mock.on(GetObjectCommand).rejectsWithThrottling();
389
+ * ```
390
+ */
69
391
  rejectsWithThrottling: () => AwsCommandStub<TInput, TOutput, TClient>;
70
- /** Reject with InternalServerError */
392
+ /**
393
+ * Reject with an InternalServerError.
394
+ *
395
+ * @returns The command stub for chaining
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * s3Mock.on(GetObjectCommand).rejectsWithInternalServerError();
400
+ * ```
401
+ */
71
402
  rejectsWithInternalServerError: () => AwsCommandStub<TInput, TOutput, TClient>;
72
- /** Set paginated responses for AWS pagination */
403
+ /**
404
+ * Set paginated responses for AWS pagination patterns.
405
+ *
406
+ * Tokens are automatically set to the last item of each page, which works for both
407
+ * DynamoDB (object tokens) and S3 (object tokens).
408
+ *
409
+ * @param items - Array of items to paginate (use marshalled items for DynamoDB)
410
+ * @param options - Pagination configuration options
411
+ * @returns The command stub for chaining
412
+ *
413
+ * @example DynamoDB pagination with marshalled data
414
+ * ```typescript
415
+ * import { marshall } from '@aws-sdk/util-dynamodb';
416
+ *
417
+ * const users = [
418
+ * { id: "user-1", name: "Alice" },
419
+ * { id: "user-2", name: "Bob" }
420
+ * ];
421
+ * const marshalledUsers = users.map(u => marshall(u));
422
+ *
423
+ * dynamoMock.on(ScanCommand).resolvesPaginated(marshalledUsers, {
424
+ * pageSize: 1,
425
+ * tokenKey: "LastEvaluatedKey",
426
+ * inputTokenKey: "ExclusiveStartKey"
427
+ * });
428
+ *
429
+ * // LastEvaluatedKey will be the marshalled last item (object, not string)
430
+ * const result = await client.send(new ScanCommand({ TableName: "Users" }));
431
+ * // result.LastEvaluatedKey = { id: { S: "user-1" }, name: { S: "Alice" } }
432
+ * ```
433
+ *
434
+ * @example S3 pagination
435
+ * ```typescript
436
+ * const objects = [
437
+ * { Key: 'file1.txt', Size: 100 },
438
+ * { Key: 'file2.txt', Size: 200 }
439
+ * ];
440
+ *
441
+ * s3Mock.on(ListObjectsV2Command).resolvesPaginated(objects, {
442
+ * pageSize: 1,
443
+ * itemsKey: "Contents",
444
+ * tokenKey: "NextContinuationToken",
445
+ * inputTokenKey: "ContinuationToken"
446
+ * });
447
+ *
448
+ * // NextContinuationToken will be the last object from the page
449
+ * const result = await client.send(new ListObjectsV2Command({ Bucket: "bucket" }));
450
+ * // result.NextContinuationToken = { Key: 'file1.txt', Size: 100 }
451
+ * ```
452
+ */
73
453
  resolvesPaginated: <T = unknown>(items: T[], options?: PaginatorOptions) => AwsCommandStub<TInput, TOutput, TClient>;
74
- /** Load response from file (JSON files are parsed, others returned as strings) */
454
+ /**
455
+ * Load response from a file. JSON files are parsed, others returned as strings.
456
+ *
457
+ * @param filePath - Path to the file to load
458
+ * @returns The command stub for chaining
459
+ *
460
+ * @example
461
+ * ```typescript
462
+ * s3Mock.on(GetObjectCommand).resolvesFromFile('./fixtures/response.json');
463
+ * ```
464
+ */
75
465
  resolvesFromFile: (filePath: string) => AwsCommandStub<TInput, TOutput, TClient>;
76
466
  }
467
+ /**
468
+ * Create a mock for an AWS SDK client class.
469
+ *
470
+ * Use this function when you want to mock all instances of a client class.
471
+ *
472
+ * @category Core Functions
473
+ *
474
+ * @param clientConstructor - The AWS SDK client class to mock
475
+ * @returns A client stub for configuring mock behaviors
476
+ *
477
+ * @example
478
+ * ```typescript
479
+ * import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
480
+ * import { mockClient } from 'aws-sdk-vitest-mock';
481
+ *
482
+ * const s3Mock = mockClient(S3Client);
483
+ *
484
+ * s3Mock.on(GetObjectCommand).resolves({ Body: 'file contents' });
485
+ *
486
+ * const client = new S3Client({});
487
+ * const result = await client.send(new GetObjectCommand({ Bucket: 'my-bucket', Key: 'file.txt' }));
488
+ * // result.Body === 'file contents'
489
+ * ```
490
+ */
77
491
  export declare const mockClient: <TClient extends AnyClient>(clientConstructor: ClientConstructor<TClient>) => AwsClientStub<TClient>;
492
+ /**
493
+ * Create a mock for a specific AWS SDK client instance.
494
+ *
495
+ * Use this function when you want to mock a single client instance.
496
+ *
497
+ * @category Core Functions
498
+ *
499
+ * @param clientInstance - The AWS SDK client instance to mock
500
+ * @returns A client stub for configuring mock behaviors
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
505
+ * import { mockClientInstance } from 'aws-sdk-vitest-mock';
506
+ *
507
+ * const client = new S3Client({});
508
+ * const s3Mock = mockClientInstance(client);
509
+ *
510
+ * s3Mock.on(GetObjectCommand).resolves({ Body: 'file contents' });
511
+ *
512
+ * const result = await client.send(new GetObjectCommand({ Bucket: 'my-bucket', Key: 'file.txt' }));
513
+ * // result.Body === 'file contents'
514
+ * ```
515
+ */
78
516
  export declare const mockClientInstance: <TClient extends AnyClient>(clientInstance: TClient) => AwsClientStub<AnyClient>;
79
517
  export {};
@@ -1,7 +1,9 @@
1
1
  export interface DebugLogger {
2
2
  enabled: boolean;
3
+ explicitlySet: boolean;
3
4
  log: (message: string, data?: unknown) => void;
5
+ logDirect: (message: string, data?: unknown) => void;
4
6
  }
5
- export declare function createDebugLogger(): DebugLogger;
6
- export declare function enableDebug(logger: DebugLogger): void;
7
- export declare function disableDebug(logger: DebugLogger): void;
7
+ export declare const createDebugLogger: (initialEnabled?: boolean) => DebugLogger;
8
+ export declare const enableDebug: (logger: DebugLogger) => void;
9
+ export declare const disableDebug: (logger: DebugLogger) => void;