@jaypie/testkit 1.1.26 → 1.1.28

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.
Files changed (49) hide show
  1. package/dist/index.d.ts +241 -5
  2. package/dist/index.js +34 -16
  3. package/dist/index.js.map +1 -1
  4. package/dist/matchers/toBeMockFunction.matcher.d.ts +10 -0
  5. package/dist/matchers.module.d.ts +2 -0
  6. package/dist/mock/aws.d.ts +22 -0
  7. package/dist/mock/constants.d.ts +19 -0
  8. package/dist/mock/core.d.ts +307 -0
  9. package/dist/mock/datadog.d.ts +4 -0
  10. package/dist/mock/express.d.ts +32 -0
  11. package/dist/mock/index.d.ts +472 -0
  12. package/dist/mock/index.js +820 -0
  13. package/dist/mock/index.js.map +1 -0
  14. package/dist/mock/jsonApiSchema.module.d.ts +61 -0
  15. package/dist/mock/lambda.d.ts +15 -0
  16. package/dist/mock/llm.d.ts +67 -0
  17. package/dist/mock/matchers/toBeCalledAboveTrace.matcher.d.ts +3 -0
  18. package/dist/mock/matchers/toBeCalledWithInitialParams.matcher.d.ts +4 -0
  19. package/dist/mock/matchers/toBeClass.matcher.d.ts +3 -0
  20. package/dist/mock/matchers/toBeJaypieError.matcher.d.ts +3 -0
  21. package/dist/mock/matchers/toBeMockFunction.matcher.d.ts +10 -0
  22. package/dist/mock/matchers/toMatch.matcher.d.ts +12 -0
  23. package/dist/mock/matchers/toThrowError.matcher.d.ts +4 -0
  24. package/dist/mock/matchers/toThrowJaypieError.matcher.d.ts +16 -0
  25. package/dist/mock/matchers.module.d.ts +97 -0
  26. package/dist/mock/mock/aws.d.ts +22 -0
  27. package/dist/mock/mock/core.d.ts +307 -0
  28. package/dist/mock/mock/datadog.d.ts +4 -0
  29. package/dist/mock/mock/express.d.ts +32 -0
  30. package/dist/mock/mock/index.d.ts +10 -0
  31. package/dist/mock/mock/lambda.d.ts +15 -0
  32. package/dist/mock/mock/llm.d.ts +67 -0
  33. package/dist/mock/mock/mongoose.d.ts +4 -0
  34. package/dist/mock/mock/original.d.ts +19 -0
  35. package/dist/mock/mock/textract.d.ts +14 -0
  36. package/dist/mock/mock/utils.d.ts +42 -0
  37. package/dist/mock/mockLog.module.d.ts +5 -0
  38. package/dist/mock/mongoose.d.ts +4 -0
  39. package/dist/mock/original.d.ts +19 -0
  40. package/dist/mock/placeholders.d.ts +9 -0
  41. package/dist/mock/sqsTestRecords.function.d.ts +14 -0
  42. package/dist/mock/textract.d.ts +14 -0
  43. package/dist/mock/utils.d.ts +42 -0
  44. package/dist/mockLog.module.d.ts +3 -3
  45. package/dist/mockTextract.json +87 -752
  46. package/package.json +16 -8
  47. package/dist/jaypie.mock.d.ts +0 -70
  48. package/dist/jaypie.mock.js +0 -693
  49. package/dist/jaypie.mock.js.map +0 -1
@@ -0,0 +1,820 @@
1
+ import * as original from '@jaypie/aws';
2
+ import { vi, beforeAll } from 'vitest';
3
+ import * as original$1 from '@jaypie/core';
4
+ import { log, BadRequestError as BadRequestError$1, UnhandledError as UnhandledError$1 } from '@jaypie/core';
5
+ export { log } from '@jaypie/core';
6
+ import * as original$2 from '@jaypie/datadog';
7
+ import * as original$3 from '@jaypie/express';
8
+ import * as original$4 from '@jaypie/llm';
9
+ import { mongoose as mongoose$1 } from '@jaypie/mongoose';
10
+ export { mongoose } from '@jaypie/mongoose';
11
+ import { readFile } from 'fs/promises';
12
+ import { dirname, join } from 'path';
13
+ import { fileURLToPath } from 'url';
14
+ import { TextractDocument } from 'amazon-textract-response-parser';
15
+ import * as original$5 from '@jaypie/textract';
16
+
17
+ /**
18
+ * Internal wrapper for vi.fn() that adds _jaypie: true to all mocks
19
+ */
20
+ function _createJaypieMock(implementation) {
21
+ const mock = vi.fn(implementation);
22
+ Object.defineProperty(mock, "_jaypie", { value: true });
23
+ return mock;
24
+ }
25
+ /**
26
+ * Creates function mocks with proper typing
27
+ * Internal utility to create properly typed mocks
28
+ */
29
+ function createMockFunction(implementation) {
30
+ // Use a more specific type conversion to avoid TypeScript error
31
+ return _createJaypieMock(implementation);
32
+ }
33
+ /**
34
+ * Creates a mock function that resolves to a value when awaited
35
+ * Internal utility to create async mock functions
36
+ */
37
+ function createMockResolvedFunction(value) {
38
+ return _createJaypieMock().mockResolvedValue(value);
39
+ }
40
+ /**
41
+ * Creates a mock function that returns a value
42
+ * Internal utility to create mock functions that return a value
43
+ */
44
+ function createMockReturnedFunction(value) {
45
+ return _createJaypieMock().mockReturnValue(value);
46
+ }
47
+ /**
48
+ * Creates a mock function that wraps another function
49
+ * Internal utility to create mock functions that wrap another function
50
+ */
51
+ function createMockWrappedFunction(fn, fallbackOrOptions = "_MOCK_WRAPPED_RESULT") {
52
+ // Determine if we have a direct fallback or options object
53
+ const options = typeof fallbackOrOptions === "object" &&
54
+ fallbackOrOptions !== null &&
55
+ ("fallback" in fallbackOrOptions ||
56
+ "throws" in fallbackOrOptions ||
57
+ "class" in fallbackOrOptions)
58
+ ? fallbackOrOptions
59
+ : { fallback: fallbackOrOptions };
60
+ // Extract values with defaults
61
+ const fallback = options.fallback ?? "_MOCK_WRAPPED_RESULT";
62
+ const throws = options.throws ?? false;
63
+ const isClass = options.class ?? false;
64
+ return _createJaypieMock().mockImplementation((...args) => {
65
+ try {
66
+ return isClass ? new fn(...args) : fn(...args);
67
+ }
68
+ catch (error) {
69
+ if (throws) {
70
+ throw error;
71
+ }
72
+ console.warn(`[@jaypie/testkit] Actual implementation failed. To suppress this warning, manually mock the response with mockReturnValue`);
73
+ if (error instanceof Error) {
74
+ console.warn(`[@jaypie/testkit] ${error.message}`);
75
+ }
76
+ // If fallback is a function, call it
77
+ if (typeof fallback === "function") {
78
+ try {
79
+ return fallback(...args);
80
+ }
81
+ catch (fallbackError) {
82
+ console.warn(`[@jaypie/testkit] Fallback function failed: ${fallbackError instanceof Error ? fallbackError.message : fallbackError}`);
83
+ return "_MOCK_WRAPPED_RESULT";
84
+ }
85
+ }
86
+ return fallback;
87
+ }
88
+ });
89
+ }
90
+ function createMockWrappedObject(object, fallbackOrOptions = "_MOCK_WRAPPED_RESULT") {
91
+ let returnMock = {};
92
+ // Extract values with defaults for the top-level call
93
+ const options = typeof fallbackOrOptions === "object" &&
94
+ fallbackOrOptions !== null &&
95
+ ("fallback" in fallbackOrOptions ||
96
+ "throws" in fallbackOrOptions ||
97
+ "class" in fallbackOrOptions)
98
+ ? fallbackOrOptions
99
+ : { fallback: fallbackOrOptions };
100
+ const fallback = options.fallback ?? "_MOCK_WRAPPED_RESULT";
101
+ const throws = options.throws ?? false;
102
+ const isClass = options.class ?? false;
103
+ // Create options for recursive calls
104
+ // Do not pass down class=true to nested objects
105
+ const recursiveOptions = {
106
+ fallback,
107
+ throws,
108
+ class: false, // Always pass class=false to nested objects
109
+ };
110
+ if (typeof object === "function") {
111
+ returnMock = createMockWrappedFunction(object, {
112
+ fallback,
113
+ throws,
114
+ class: isClass,
115
+ });
116
+ }
117
+ for (const key of Object.keys(object)) {
118
+ const value = object[key];
119
+ if (typeof value === "function") {
120
+ returnMock[key] = createMockWrappedFunction(value, {
121
+ fallback,
122
+ throws,
123
+ class: isClass,
124
+ });
125
+ }
126
+ else if (typeof value === "object" && value !== null) {
127
+ returnMock[key] = createMockWrappedObject(value, recursiveOptions);
128
+ }
129
+ else {
130
+ returnMock[key] = value;
131
+ }
132
+ }
133
+ return returnMock;
134
+ }
135
+ /**
136
+ * Utility to create a mock error constructor from an error class
137
+ */
138
+ function createMockError(ErrorClass) {
139
+ // Create a mock constructor that returns a new instance of ErrorClass
140
+ const mockConstructor = _createJaypieMock(function (...args) {
141
+ return new ErrorClass(...args);
142
+ });
143
+ return mockConstructor;
144
+ }
145
+
146
+ // Constants for mock values
147
+ const TAG$4 = "AWS";
148
+ const getMessages = createMockWrappedFunction(original.getMessages, []);
149
+ const getSecret = createMockResolvedFunction("mock-secret-value");
150
+ const sendMessage = createMockResolvedFunction({
151
+ MessageId: "mock-message-id",
152
+ });
153
+ // Add missing functions from original implementation
154
+ const getEnvSecret = createMockFunction(async (key) => `_MOCK_ENV_SECRET_[${TAG$4}][${key}]`);
155
+ const getSingletonMessage = createMockWrappedFunction(original.getSingletonMessage, { value: "_MOCK_SINGLETON_MESSAGE_" });
156
+ const getTextractJob = createMockFunction(async (job) => ({ value: `_MOCK_TEXTRACT_JOB_[${job}]` }));
157
+ const sendBatchMessages = createMockResolvedFunction(true);
158
+ const sendTextractJob = createMockFunction(async ({ bucket, key, featureTypes = [] }) => {
159
+ // Basic validation to mimic original behavior
160
+ if (!bucket || !key) {
161
+ throw new Error("Bucket and key are required");
162
+ }
163
+ return [`_MOCK_TEXTRACT_JOB_ID_[${TAG$4}]_${bucket}_${key}`];
164
+ });
165
+
166
+ var aws = /*#__PURE__*/Object.freeze({
167
+ __proto__: null,
168
+ getEnvSecret: getEnvSecret,
169
+ getMessages: getMessages,
170
+ getSecret: getSecret,
171
+ getSingletonMessage: getSingletonMessage,
172
+ getTextractJob: getTextractJob,
173
+ sendBatchMessages: sendBatchMessages,
174
+ sendMessage: sendMessage,
175
+ sendTextractJob: sendTextractJob
176
+ });
177
+
178
+ function mockLogFactory() {
179
+ // Create skeleton of mock objects
180
+ const mock = {
181
+ debug: vi.fn(),
182
+ error: vi.fn(),
183
+ fatal: vi.fn(),
184
+ info: vi.fn(),
185
+ init: vi.fn(),
186
+ lib: vi.fn(),
187
+ tag: vi.fn(),
188
+ trace: vi.fn(),
189
+ untag: vi.fn(),
190
+ var: vi.fn(),
191
+ warn: vi.fn(),
192
+ with: vi.fn(),
193
+ };
194
+ // Fill out nested mocks
195
+ mock.debug.var = mock.var;
196
+ mock.error.var = mock.var;
197
+ mock.fatal.var = mock.var;
198
+ mock.info.var = mock.var;
199
+ mock.trace.var = mock.var;
200
+ mock.warn.var = mock.var;
201
+ // Have modules return correct objects
202
+ mock.init.mockReturnValue(null);
203
+ mock.lib.mockReturnValue(mock);
204
+ mock.with.mockReturnValue(mock);
205
+ // Pin mocks to the module
206
+ mock.mock = {
207
+ debug: mock.debug,
208
+ error: mock.error,
209
+ fatal: mock.fatal,
210
+ info: mock.info,
211
+ init: mock.init,
212
+ lib: mock.lib,
213
+ tag: mock.tag,
214
+ trace: mock.trace,
215
+ untag: mock.untag,
216
+ var: mock.var,
217
+ warn: mock.warn,
218
+ with: mock.with,
219
+ };
220
+ return mock;
221
+ }
222
+ const LOG_METHOD_NAMES = [
223
+ "debug",
224
+ "error",
225
+ "fatal",
226
+ "info",
227
+ "init",
228
+ "lib",
229
+ "tag",
230
+ "trace",
231
+ "untag",
232
+ "var",
233
+ "warn",
234
+ "with",
235
+ ];
236
+ // Use Record type for more flexible access pattern
237
+ const originalLogMethods = new WeakMap();
238
+ function spyLog(logInstance) {
239
+ if (!originalLogMethods.has(logInstance)) {
240
+ const mockLog = mockLogFactory();
241
+ const originalMethods = {};
242
+ // Save only methods that actually exist on the log instance
243
+ LOG_METHOD_NAMES.forEach((method) => {
244
+ if (method in logInstance) {
245
+ originalMethods[method] =
246
+ logInstance[method];
247
+ // Use type assertion after checking existence
248
+ logInstance[method] = mockLog[method];
249
+ }
250
+ });
251
+ originalLogMethods.set(logInstance, originalMethods);
252
+ }
253
+ }
254
+
255
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
256
+ // Constants for mock values
257
+ const TAG$3 = "CORE";
258
+ const BadGatewayError = createMockError(original$1.BadGatewayError);
259
+ const BadRequestError = createMockError(original$1.BadRequestError);
260
+ const ConfigurationError = createMockError(original$1.ConfigurationError);
261
+ const ForbiddenError = createMockError(original$1.ForbiddenError);
262
+ const GatewayTimeoutError = createMockError(original$1.GatewayTimeoutError);
263
+ const GoneError = createMockError(original$1.GoneError);
264
+ const IllogicalError = createMockError(original$1.IllogicalError);
265
+ const InternalError = createMockError(original$1.InternalError);
266
+ const MethodNotAllowedError = createMockError(original$1.MethodNotAllowedError);
267
+ const MultiError = createMockError(original$1.MultiError);
268
+ const NotFoundError = createMockError(original$1.NotFoundError);
269
+ const NotImplementedError = createMockError(original$1.NotImplementedError);
270
+ const ProjectError = createMockError(original$1.ProjectError);
271
+ const ProjectMultiError = createMockError(original$1.ProjectMultiError);
272
+ const RejectedError = createMockError(original$1.RejectedError);
273
+ const TeapotError = createMockError(original$1.TeapotError);
274
+ const UnauthorizedError = createMockError(original$1.UnauthorizedError);
275
+ const UnavailableError = createMockError(original$1.UnavailableError);
276
+ const UnhandledError = createMockError(original$1.UnhandledError);
277
+ const UnreachableCodeError = createMockError(original$1.UnreachableCodeError);
278
+ // Mock core functions
279
+ const validate = createMockWrappedObject(original$1.validate, {
280
+ fallback: false,
281
+ throws: true,
282
+ });
283
+ beforeAll(async () => {
284
+ spyLog(log);
285
+ });
286
+ // Add missing core functions
287
+ const cloneDeep = createMockWrappedFunction(original$1.cloneDeep, {
288
+ throws: true,
289
+ });
290
+ const envBoolean = createMockReturnedFunction(true);
291
+ const envsKey = createMockWrappedFunction(original$1.envsKey, `_MOCK_ENVS_KEY_[${TAG$3}]`);
292
+ const errorFromStatusCode = createMockFunction((statusCode, message = `Mock error for status code ${statusCode}`) => {
293
+ try {
294
+ // Try to mimic original implementation
295
+ switch (statusCode) {
296
+ case 400:
297
+ return new BadRequestError(message);
298
+ case 401:
299
+ return new UnauthorizedError(message);
300
+ case 403:
301
+ return new ForbiddenError(message);
302
+ case 404:
303
+ return new NotFoundError(message);
304
+ case 405:
305
+ return new MethodNotAllowedError(message);
306
+ case 410:
307
+ return new GoneError(message);
308
+ case 418:
309
+ return new TeapotError(message);
310
+ case 500:
311
+ return new InternalError(message);
312
+ case 501:
313
+ return new NotImplementedError(message);
314
+ case 502:
315
+ return new BadGatewayError(message);
316
+ case 503:
317
+ return new UnavailableError(message);
318
+ case 504:
319
+ return new GatewayTimeoutError(message);
320
+ default:
321
+ return new Error(message);
322
+ }
323
+ }
324
+ catch (error) {
325
+ return new Error(`_MOCK_ERROR_FROM_STATUS_CODE_[${TAG$3}][${statusCode}]`);
326
+ }
327
+ });
328
+ const formatError = createMockWrappedFunction(original$1.formatError, `_MOCK_FORMAT_ERROR_[${TAG$3}]`);
329
+ const getHeaderFrom = createMockWrappedFunction(original$1.getHeaderFrom, `_MOCK_GET_HEADER_FROM_[${TAG$3}]`);
330
+ const getObjectKeyCaseInsensitive = createMockWrappedFunction(original$1.getObjectKeyCaseInsensitive, `_MOCK_GET_OBJECT_KEY_CASE_INSENSITIVE_[${TAG$3}]`);
331
+ const isClass = createMockWrappedFunction(original$1.isClass, `_MOCK_IS_CLASS_[${TAG$3}]`);
332
+ const isJaypieError = createMockWrappedFunction(original$1.isJaypieError, false);
333
+ // Optional/Required validation functions
334
+ const optional = createMockWrappedObject(original$1.optional, {
335
+ fallback: true,
336
+ throws: true,
337
+ });
338
+ const required = createMockWrappedObject(original$1.required, {
339
+ fallback: true,
340
+ throws: true,
341
+ });
342
+ const resolveValue = createMockWrappedFunction(original$1.resolveValue, `_MOCK_RESOLVE_VALUE_[${TAG$3}]`);
343
+ const safeParseFloat = createMockWrappedFunction(original$1.safeParseFloat, `_MOCK_SAFE_PARSE_FLOAT_[${TAG$3}]`);
344
+ const placeholders = createMockWrappedFunction(original$1.placeholders, `_MOCK_PLACEHOLDERS_[${TAG$3}]`);
345
+ // Add force utilities to help with jaypieHandler implementation
346
+ const force = createMockWrappedObject(original$1.force);
347
+ const jaypieHandler = createMockFunction((handler, options = {}) => {
348
+ return async (...args) => {
349
+ let result;
350
+ let thrownError;
351
+ // Destructure options with defaults
352
+ const { setup = [], teardown = [], unavailable = original$1.force.boolean(process.env.PROJECT_UNAVAILABLE), validate = [], } = options;
353
+ // Check if service is unavailable
354
+ if (unavailable)
355
+ throw new UnavailableError("Service unavailable");
356
+ // Run validation functions
357
+ const validateFunctions = original$1.force.array(validate);
358
+ for (const validator of validateFunctions) {
359
+ if (typeof validator === "function") {
360
+ const valid = await validator(...args);
361
+ if (valid === false) {
362
+ throw new BadRequestError("Validation failed");
363
+ }
364
+ }
365
+ }
366
+ try {
367
+ // Run setup functions
368
+ const setupFunctions = original$1.force.array(setup);
369
+ for (const setupFunction of setupFunctions) {
370
+ if (typeof setupFunction === "function") {
371
+ await setupFunction(...args);
372
+ }
373
+ }
374
+ // Execute the handler
375
+ result = await handler(...args);
376
+ }
377
+ catch (error) {
378
+ thrownError = error;
379
+ }
380
+ // Run teardown functions (always run even if there was an error)
381
+ const teardownFunctions = original$1.force.array(teardown);
382
+ for (const teardownFunction of teardownFunctions) {
383
+ if (typeof teardownFunction === "function") {
384
+ try {
385
+ await teardownFunction(...args);
386
+ }
387
+ catch (error) {
388
+ // Swallow teardown errors, but log them
389
+ console.error(error);
390
+ }
391
+ }
392
+ }
393
+ // If there was an error in the handler, throw it after teardown
394
+ if (thrownError) {
395
+ throw thrownError;
396
+ }
397
+ return result;
398
+ };
399
+ });
400
+ const sleep = createMockResolvedFunction(true);
401
+ const uuid = createMockWrappedFunction(original$1.uuid, `00000000-0000-0000-0000-000000000000`);
402
+ const ERROR = original$1.ERROR;
403
+ const HTTP$1 = original$1.HTTP;
404
+ const JAYPIE = original$1.JAYPIE;
405
+ const PROJECT = original$1.PROJECT;
406
+ const VALIDATE = original$1.VALIDATE;
407
+
408
+ var core = /*#__PURE__*/Object.freeze({
409
+ __proto__: null,
410
+ BadGatewayError: BadGatewayError,
411
+ BadRequestError: BadRequestError,
412
+ ConfigurationError: ConfigurationError,
413
+ ERROR: ERROR,
414
+ ForbiddenError: ForbiddenError,
415
+ GatewayTimeoutError: GatewayTimeoutError,
416
+ GoneError: GoneError,
417
+ HTTP: HTTP$1,
418
+ IllogicalError: IllogicalError,
419
+ InternalError: InternalError,
420
+ JAYPIE: JAYPIE,
421
+ MethodNotAllowedError: MethodNotAllowedError,
422
+ MultiError: MultiError,
423
+ NotFoundError: NotFoundError,
424
+ NotImplementedError: NotImplementedError,
425
+ PROJECT: PROJECT,
426
+ ProjectError: ProjectError,
427
+ ProjectMultiError: ProjectMultiError,
428
+ RejectedError: RejectedError,
429
+ TeapotError: TeapotError,
430
+ UnauthorizedError: UnauthorizedError,
431
+ UnavailableError: UnavailableError,
432
+ UnhandledError: UnhandledError,
433
+ UnreachableCodeError: UnreachableCodeError,
434
+ VALIDATE: VALIDATE,
435
+ cloneDeep: cloneDeep,
436
+ envBoolean: envBoolean,
437
+ envsKey: envsKey,
438
+ errorFromStatusCode: errorFromStatusCode,
439
+ force: force,
440
+ formatError: formatError,
441
+ getHeaderFrom: getHeaderFrom,
442
+ getObjectKeyCaseInsensitive: getObjectKeyCaseInsensitive,
443
+ isClass: isClass,
444
+ isJaypieError: isJaypieError,
445
+ jaypieHandler: jaypieHandler,
446
+ log: log,
447
+ optional: optional,
448
+ placeholders: placeholders,
449
+ required: required,
450
+ resolveValue: resolveValue,
451
+ safeParseFloat: safeParseFloat,
452
+ sleep: sleep,
453
+ uuid: uuid,
454
+ validate: validate
455
+ });
456
+
457
+ const DATADOG = original$2.DATADOG;
458
+ const submitMetric = createMockResolvedFunction(true);
459
+ const submitMetricSet = createMockResolvedFunction(true);
460
+
461
+ var datadog = /*#__PURE__*/Object.freeze({
462
+ __proto__: null,
463
+ DATADOG: DATADOG,
464
+ submitMetric: submitMetric,
465
+ submitMetricSet: submitMetricSet
466
+ });
467
+
468
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
469
+ // Constants for mock values
470
+ const TAG$2 = "EXPRESS";
471
+ const HTTP = {
472
+ CODE: { OK: 200, CREATED: 201, NO_CONTENT: 204, INTERNAL_ERROR: 500 },
473
+ };
474
+ const EXPRESS = original$3.EXPRESS;
475
+ // Add Express route functions
476
+ const badRequestRoute = createMockWrappedFunction(original$3.badRequestRoute, { error: `_MOCK_BAD_REQUEST_ROUTE_[${TAG$2}]` });
477
+ const echoRoute = createMockWrappedFunction(original$3.echoRoute, (req) => req);
478
+ const forbiddenRoute = createMockWrappedFunction(original$3.forbiddenRoute, { error: `_MOCK_FORBIDDEN_ROUTE_[${TAG$2}]` });
479
+ const goneRoute = createMockWrappedFunction(original$3.goneRoute, {
480
+ error: `_MOCK_GONE_ROUTE_[${TAG$2}]`,
481
+ });
482
+ const methodNotAllowedRoute = createMockWrappedFunction(original$3.methodNotAllowedRoute, { error: `_MOCK_METHOD_NOT_ALLOWED_ROUTE_[${TAG$2}]` });
483
+ const noContentRoute = createMockWrappedFunction(original$3.noContentRoute, { status: 204 });
484
+ const notFoundRoute = createMockWrappedFunction(original$3.notFoundRoute, {
485
+ error: `_MOCK_NOT_FOUND_ROUTE_[${TAG$2}]`,
486
+ });
487
+ const notImplementedRoute = createMockWrappedFunction(original$3.notImplementedRoute, { error: `_MOCK_NOT_IMPLEMENTED_ROUTE_[${TAG$2}]` });
488
+ const expressHttpCodeHandler = createMockWrappedFunction(original$3.expressHttpCodeHandler, (...args) => {
489
+ const [req, res, next] = args;
490
+ return res.status(200).send();
491
+ });
492
+ const cors = createMockWrappedFunction(original$3.cors);
493
+ const expressHandler = createMockFunction((handlerOrProps, propsOrHandler) => {
494
+ let handler;
495
+ let props;
496
+ if (typeof handlerOrProps === "object" &&
497
+ typeof propsOrHandler === "function") {
498
+ handler = propsOrHandler;
499
+ props = handlerOrProps;
500
+ }
501
+ else if (typeof handlerOrProps === "function") {
502
+ handler = handlerOrProps;
503
+ props = (propsOrHandler || {});
504
+ }
505
+ else {
506
+ throw new BadRequestError$1("handler must be a function");
507
+ }
508
+ // Add locals setup if needed
509
+ if (props.locals &&
510
+ typeof props.locals === "object" &&
511
+ !Array.isArray(props.locals)) {
512
+ const keys = Object.keys(props.locals);
513
+ if (!props.setup)
514
+ props.setup = [];
515
+ props.setup = force.array(props.setup);
516
+ // @ts-expect-error TODO: cannot resolve; fix when JaypieHandler moves to TypeScript
517
+ props.setup.unshift((req) => {
518
+ if (!req || typeof req !== "object") {
519
+ throw new BadRequestError$1("req must be an object");
520
+ }
521
+ // Set req.locals if it doesn't exist
522
+ if (!req.locals)
523
+ req.locals = {};
524
+ if (typeof req.locals !== "object" || Array.isArray(req.locals)) {
525
+ throw new BadRequestError$1("req.locals must be an object");
526
+ }
527
+ if (!req.locals._jaypie)
528
+ req.locals._jaypie = {};
529
+ });
530
+ const localsSetup = async (localsReq, localsRes) => {
531
+ for (let i = 0; i < keys.length; i += 1) {
532
+ const key = keys[i];
533
+ if (typeof props.locals[key] === "function") {
534
+ localsReq.locals[key] = await props.locals[key](localsReq, localsRes);
535
+ }
536
+ else {
537
+ localsReq.locals[key] = props.locals[key];
538
+ }
539
+ }
540
+ };
541
+ props.setup.push(localsSetup);
542
+ }
543
+ if (props.locals && typeof props.locals !== "object") {
544
+ throw new BadRequestError$1("props.locals must be an object");
545
+ }
546
+ if (props.locals && Array.isArray(props.locals)) {
547
+ throw new BadRequestError$1("props.locals must be an object");
548
+ }
549
+ if (props.locals === null) {
550
+ throw new BadRequestError$1("props.locals must be an object");
551
+ }
552
+ const jaypieFunction = jaypieHandler(handler, props);
553
+ return async (req = {}, res = {}, ...extra) => {
554
+ const status = HTTP.CODE.OK;
555
+ let response;
556
+ let supertestMode = false;
557
+ if (res &&
558
+ typeof res === "object" &&
559
+ "socket" in res &&
560
+ res.constructor.name === "ServerResponse") {
561
+ // Use the response object in supertest mode
562
+ supertestMode = true;
563
+ }
564
+ try {
565
+ response = await jaypieFunction(req, res, ...extra);
566
+ }
567
+ catch (error) {
568
+ // In the mock context, if status is a function we are in a "supertest"
569
+ if (supertestMode && typeof res.status === "function") {
570
+ // In theory jaypieFunction has handled all errors
571
+ const errorStatus = error.status || HTTP.CODE.INTERNAL_ERROR;
572
+ let errorResponse;
573
+ if (typeof error.json === "function") {
574
+ errorResponse = error.json();
575
+ }
576
+ else {
577
+ // This should never happen
578
+ errorResponse = new UnhandledError$1().json();
579
+ }
580
+ res.status(errorStatus).json(errorResponse);
581
+ return;
582
+ }
583
+ else {
584
+ // else, res.status is not a function, throw the error
585
+ throw error;
586
+ }
587
+ }
588
+ if (supertestMode && typeof res.status === "function") {
589
+ if (response) {
590
+ if (typeof response === "object") {
591
+ if (typeof response.json === "function") {
592
+ res.json(response.json());
593
+ }
594
+ else {
595
+ res.status(status).json(response);
596
+ }
597
+ }
598
+ else if (typeof response === "string") {
599
+ try {
600
+ res.status(status).json(JSON.parse(response));
601
+ }
602
+ catch (error) {
603
+ res.status(status).send(response);
604
+ }
605
+ }
606
+ else if (response === true) {
607
+ res.status(HTTP.CODE.CREATED).send();
608
+ }
609
+ else {
610
+ res.status(status).send(response);
611
+ }
612
+ }
613
+ else {
614
+ res.status(HTTP.CODE.NO_CONTENT).send();
615
+ }
616
+ }
617
+ else {
618
+ return response;
619
+ }
620
+ };
621
+ });
622
+
623
+ var express = /*#__PURE__*/Object.freeze({
624
+ __proto__: null,
625
+ EXPRESS: EXPRESS,
626
+ badRequestRoute: badRequestRoute,
627
+ cors: cors,
628
+ echoRoute: echoRoute,
629
+ expressHandler: expressHandler,
630
+ expressHttpCodeHandler: expressHttpCodeHandler,
631
+ forbiddenRoute: forbiddenRoute,
632
+ goneRoute: goneRoute,
633
+ methodNotAllowedRoute: methodNotAllowedRoute,
634
+ noContentRoute: noContentRoute,
635
+ notFoundRoute: notFoundRoute,
636
+ notImplementedRoute: notImplementedRoute
637
+ });
638
+
639
+ // Mock implementation of lambdaHandler that follows the original implementation pattern
640
+ const lambdaHandler = createMockFunction((handler, props = {}) => {
641
+ // If handler is an object and options is a function, swap them
642
+ if (typeof handler === "object" && typeof props === "function") {
643
+ const temp = handler;
644
+ handler = props;
645
+ props = temp;
646
+ }
647
+ return async (event, context, ...extra) => {
648
+ return jaypieHandler(handler, props)(event, context, ...extra);
649
+ };
650
+ });
651
+
652
+ var lambda = /*#__PURE__*/Object.freeze({
653
+ __proto__: null,
654
+ lambdaHandler: lambdaHandler
655
+ });
656
+
657
+ // Constants for mock values
658
+ const TAG$1 = "LLM";
659
+ const LLM = original$4.LLM;
660
+ const mockOperate = createMockResolvedFunction({
661
+ history: [
662
+ {
663
+ content: "_MOCK_USER_INPUT",
664
+ role: "user",
665
+ type: "message",
666
+ },
667
+ {
668
+ id: "_MOCK_MESSAGE_ID",
669
+ type: "message",
670
+ status: "completed",
671
+ content: "_MOCK_CONTENT",
672
+ role: "assistant",
673
+ },
674
+ ],
675
+ output: [
676
+ {
677
+ id: "_MOCK_MESSAGE_ID",
678
+ type: "message",
679
+ status: "completed",
680
+ content: "_MOCK_CONTENT",
681
+ role: "assistant",
682
+ },
683
+ ],
684
+ responses: [
685
+ {
686
+ id: "_MOCK_RESPONSE_ID",
687
+ object: "response",
688
+ created_at: Date.now() / 1000,
689
+ status: "completed",
690
+ error: null,
691
+ output_text: "_MOCK_OUTPUT_TEXT",
692
+ },
693
+ ],
694
+ status: "completed",
695
+ usage: { input: 100, output: 20, reasoning: 0, total: 120 },
696
+ content: "_MOCK_OUTPUT_TEXT",
697
+ });
698
+ const mockSend = createMockResolvedFunction("_MOCK_LLM_RESPONSE");
699
+ const Llm = Object.assign(vi.fn().mockImplementation((providerName = "_MOCK_LLM_PROVIDER") => ({
700
+ _provider: providerName,
701
+ _llm: {
702
+ operate: mockOperate,
703
+ send: mockSend,
704
+ },
705
+ operate: mockOperate,
706
+ send: mockSend,
707
+ })), {
708
+ operate: mockOperate,
709
+ send: mockSend,
710
+ });
711
+ // Tool implementations - always return mock values
712
+ const random = createMockReturnedFunction(0.5);
713
+ const roll = createMockReturnedFunction(6);
714
+ const time = createMockReturnedFunction(`_MOCK_TIME_[${TAG$1}]`);
715
+ const weather = createMockResolvedFunction({
716
+ location: `_MOCK_WEATHER_LOCATION_[${TAG$1}]`,
717
+ forecast: Array(7)
718
+ .fill(0)
719
+ .map((_, i) => ({
720
+ date: `2025-05-${i + 1}`,
721
+ temperature: 72,
722
+ condition: "Sunny",
723
+ precipitation: 0,
724
+ })),
725
+ });
726
+ // Tool collections
727
+ const toolkit = {
728
+ random,
729
+ roll,
730
+ time,
731
+ weather,
732
+ };
733
+ const Toolkit = createMockWrappedObject(original$4.Toolkit, {
734
+ isClass: true,
735
+ });
736
+ const tools = Object.values(toolkit);
737
+
738
+ var llm = /*#__PURE__*/Object.freeze({
739
+ __proto__: null,
740
+ LLM: LLM,
741
+ Llm: Llm,
742
+ Toolkit: Toolkit,
743
+ toolkit: toolkit,
744
+ tools: tools
745
+ });
746
+
747
+ // Mongoose mock functions
748
+ const connect = createMockReturnedFunction(true);
749
+ const connectFromSecretEnv = createMockReturnedFunction(true);
750
+ const disconnect = createMockReturnedFunction(true);
751
+
752
+ var mongoose = /*#__PURE__*/Object.freeze({
753
+ __proto__: null,
754
+ connect: connect,
755
+ connectFromSecretEnv: connectFromSecretEnv,
756
+ disconnect: disconnect,
757
+ mongoose: mongoose$1
758
+ });
759
+
760
+ // Constants for mock values
761
+ const TAG = "TEXTRACT";
762
+ const __filename = fileURLToPath(import.meta.url);
763
+ const __dirname = dirname(__filename);
764
+ const MOCK_TEXTRACT_DOCUMENT_PATH = join(__dirname, "..", "mockTextract.json");
765
+ // Setup
766
+ let mockTextractContents;
767
+ beforeAll(async () => {
768
+ mockTextractContents = await readFile(MOCK_TEXTRACT_DOCUMENT_PATH, "utf-8");
769
+ });
770
+ /**
771
+ * Mock for MarkdownPage class from @jaypie/textract
772
+ */
773
+ const MarkdownPage = createMockWrappedObject(original$5.MarkdownPage, {
774
+ class: true,
775
+ fallback: () => {
776
+ const mockDocument = new TextractDocument(JSON.parse(mockTextractContents));
777
+ // Double type assertion needed to bridge incompatible types
778
+ return new original$5.MarkdownPage(mockDocument.pageNumber(1));
779
+ },
780
+ });
781
+ /**
782
+ * Mock for textractJsonToMarkdown function from @jaypie/textract
783
+ */
784
+ const textractJsonToMarkdown = createMockWrappedFunction(original$5.textractJsonToMarkdown, `_MOCK_TEXTRACT_JSON_TO_MARKDOWN_[${TAG}]`);
785
+ // Export default for convenience
786
+ var textract = {
787
+ MarkdownPage,
788
+ textractJsonToMarkdown,
789
+ };
790
+
791
+ var textract$1 = /*#__PURE__*/Object.freeze({
792
+ __proto__: null,
793
+ MarkdownPage: MarkdownPage,
794
+ default: textract,
795
+ textractJsonToMarkdown: textractJsonToMarkdown
796
+ });
797
+
798
+ // Import all mocks
799
+ // Export default object with all mocks
800
+ var index = {
801
+ // AWS module
802
+ ...aws,
803
+ // Core module
804
+ ...core,
805
+ // Datadog module
806
+ ...datadog,
807
+ // Express module
808
+ ...express,
809
+ // Lambda module
810
+ ...lambda,
811
+ // LLM module
812
+ ...llm,
813
+ // Mongoose module (now empty)
814
+ ...mongoose,
815
+ // Textract module
816
+ ...textract$1,
817
+ };
818
+
819
+ export { BadGatewayError, BadRequestError, ConfigurationError, DATADOG, ERROR, EXPRESS, ForbiddenError, GatewayTimeoutError, GoneError, HTTP$1 as HTTP, IllogicalError, InternalError, JAYPIE, LLM, Llm, MarkdownPage, MethodNotAllowedError, MultiError, NotFoundError, NotImplementedError, PROJECT, ProjectError, ProjectMultiError, RejectedError, TeapotError, Toolkit, UnauthorizedError, UnavailableError, UnhandledError, UnreachableCodeError, VALIDATE, badRequestRoute, cloneDeep, connect, connectFromSecretEnv, cors, index as default, disconnect, echoRoute, envBoolean, envsKey, errorFromStatusCode, expressHandler, expressHttpCodeHandler, forbiddenRoute, force, formatError, getEnvSecret, getHeaderFrom, getMessages, getObjectKeyCaseInsensitive, getSecret, getSingletonMessage, getTextractJob, goneRoute, isClass, isJaypieError, jaypieHandler, lambdaHandler, methodNotAllowedRoute, noContentRoute, notFoundRoute, notImplementedRoute, optional, placeholders, required, resolveValue, safeParseFloat, sendBatchMessages, sendMessage, sendTextractJob, sleep, submitMetric, submitMetricSet, textractJsonToMarkdown, toolkit, tools, uuid, validate };
820
+ //# sourceMappingURL=index.js.map