@jaypie/testkit 1.1.36 → 1.2.0-rc.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/dist/index.d.ts +4 -105
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/matchers/toThrowJaypieError.matcher.d.ts +4 -3
- package/dist/matchers.module.d.ts +1 -96
- package/dist/mock/core.d.ts +165 -267
- package/dist/mock/datadog.d.ts +18 -2
- package/dist/mock/index.d.ts +196 -283
- package/dist/mock/index.js +92 -695
- package/dist/mock/index.js.map +1 -1
- package/dist/mock/matchers/toThrowJaypieError.matcher.d.ts +4 -3
- package/dist/mock/matchers.module.d.ts +1 -96
- package/dist/mock/mock/core.d.ts +165 -267
- package/dist/mock/mock/datadog.d.ts +18 -2
- package/dist/mock/mock/original.d.ts +9 -16
- package/dist/mock/mockLog.module.d.ts +1 -1
- package/dist/mock/original.d.ts +9 -16
- package/dist/mockLog.module.d.ts +1 -1
- package/package.json +21 -15
package/dist/mock/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import * as original from '@jaypie/aws';
|
|
2
2
|
import { vi, beforeAll } from 'vitest';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import * as
|
|
8
|
-
import * as original$
|
|
3
|
+
import { log, createLogger as createLogger$1, FORMAT, LEVEL, Logger } from '@jaypie/logger';
|
|
4
|
+
export { FORMAT, LEVEL, Logger, log } from '@jaypie/logger';
|
|
5
|
+
import * as errors from '@jaypie/errors';
|
|
6
|
+
import { BadRequestError as BadRequestError$1, UnhandledError as UnhandledError$1 } from '@jaypie/errors';
|
|
7
|
+
import * as kit$1 from '@jaypie/kit';
|
|
8
|
+
import * as original$1 from '@jaypie/datadog';
|
|
9
|
+
import * as original$2 from '@jaypie/express';
|
|
10
|
+
import * as original$3 from '@jaypie/llm';
|
|
9
11
|
import { mongoose as mongoose$1 } from '@jaypie/mongoose';
|
|
10
12
|
export { mongoose } from '@jaypie/mongoose';
|
|
11
13
|
import { readFile } from 'fs/promises';
|
|
12
14
|
import { dirname, join } from 'path';
|
|
13
15
|
import { fileURLToPath } from 'url';
|
|
14
16
|
import { TextractDocument } from 'amazon-textract-response-parser';
|
|
15
|
-
import * as original$
|
|
17
|
+
import * as original$4 from '@jaypie/textract';
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Internal wrapper for vi.fn() that adds _jaypie: true to all mocks
|
|
@@ -308,7 +310,8 @@ function spyLog(logInstance) {
|
|
|
308
310
|
originalMethods[method] =
|
|
309
311
|
logInstance[method];
|
|
310
312
|
// Use type assertion after checking existence
|
|
311
|
-
logInstance[method] =
|
|
313
|
+
logInstance[method] =
|
|
314
|
+
mockLog[method];
|
|
312
315
|
}
|
|
313
316
|
});
|
|
314
317
|
originalLogMethods.set(logInstance, originalMethods);
|
|
@@ -318,40 +321,40 @@ function spyLog(logInstance) {
|
|
|
318
321
|
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
319
322
|
// Constants for mock values
|
|
320
323
|
const TAG$2 = "CORE";
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
const
|
|
325
|
-
const
|
|
326
|
-
const
|
|
327
|
-
const
|
|
328
|
-
const
|
|
329
|
-
const
|
|
330
|
-
const
|
|
331
|
-
const
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
const
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
324
|
+
// JaypieError is the base class - export it directly from errors
|
|
325
|
+
const JaypieError = errors.JaypieError;
|
|
326
|
+
const BadGatewayError = createMockError(errors.BadGatewayError);
|
|
327
|
+
const BadRequestError = createMockError(errors.BadRequestError);
|
|
328
|
+
const ConfigurationError = createMockError(errors.ConfigurationError);
|
|
329
|
+
const CorsError = createMockError(errors.CorsError);
|
|
330
|
+
const ForbiddenError = createMockError(errors.ForbiddenError);
|
|
331
|
+
const GatewayTimeoutError = createMockError(errors.GatewayTimeoutError);
|
|
332
|
+
const GoneError = createMockError(errors.GoneError);
|
|
333
|
+
const IllogicalError = createMockError(errors.IllogicalError);
|
|
334
|
+
const InternalError = createMockError(errors.InternalError);
|
|
335
|
+
const MethodNotAllowedError = createMockError(errors.MethodNotAllowedError);
|
|
336
|
+
// Backwards compatibility aliases
|
|
337
|
+
const MultiError = createMockError(errors.InternalError);
|
|
338
|
+
const NotFoundError = createMockError(errors.NotFoundError);
|
|
339
|
+
const NotImplementedError = createMockError(errors.NotImplementedError);
|
|
340
|
+
const ProjectError = createMockError(errors.InternalError);
|
|
341
|
+
const ProjectMultiError = createMockError(errors.InternalError);
|
|
342
|
+
const RejectedError = createMockError(errors.RejectedError);
|
|
343
|
+
const TeapotError = createMockError(errors.TeapotError);
|
|
344
|
+
const TooManyRequestsError = createMockError(errors.TooManyRequestsError);
|
|
345
|
+
const UnauthorizedError = createMockError(errors.UnauthorizedError);
|
|
346
|
+
const UnavailableError = createMockError(errors.UnavailableError);
|
|
347
|
+
const UnhandledError = createMockError(errors.UnhandledError);
|
|
348
|
+
const UnreachableCodeError = createMockError(errors.UnreachableCodeError);
|
|
346
349
|
beforeAll(async () => {
|
|
347
350
|
spyLog(log);
|
|
348
351
|
});
|
|
349
352
|
// Add missing core functions
|
|
350
|
-
const cloneDeep = createMockWrappedFunction(
|
|
353
|
+
const cloneDeep = createMockWrappedFunction(kit$1.cloneDeep, {
|
|
351
354
|
throws: true,
|
|
352
355
|
});
|
|
353
|
-
const envBoolean
|
|
354
|
-
const envsKey = createMockWrappedFunction(
|
|
356
|
+
const envBoolean = createMockReturnedFunction(true);
|
|
357
|
+
const envsKey = createMockWrappedFunction(kit$1.envsKey, `_MOCK_ENVS_KEY_[${TAG$2}]`);
|
|
355
358
|
const errorFromStatusCode = createMockFunction((statusCode, message = `Mock error for status code ${statusCode}`) => {
|
|
356
359
|
try {
|
|
357
360
|
// Try to mimic original implementation
|
|
@@ -388,36 +391,29 @@ const errorFromStatusCode = createMockFunction((statusCode, message = `Mock erro
|
|
|
388
391
|
return new Error(`_MOCK_ERROR_FROM_STATUS_CODE_[${TAG$2}][${statusCode}]`);
|
|
389
392
|
}
|
|
390
393
|
});
|
|
391
|
-
const formatError = createMockWrappedFunction(
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
});
|
|
401
|
-
const required = createMockWrappedObject(original$1.required, {
|
|
402
|
-
fallback: true,
|
|
403
|
-
throws: true,
|
|
404
|
-
});
|
|
405
|
-
const resolveValue = createMockWrappedFunction(original$1.resolveValue, `_MOCK_RESOLVE_VALUE_[${TAG$2}]`);
|
|
406
|
-
const safeParseFloat = createMockWrappedFunction(original$1.safeParseFloat, `_MOCK_SAFE_PARSE_FLOAT_[${TAG$2}]`);
|
|
407
|
-
const placeholders = createMockWrappedFunction(original$1.placeholders, `_MOCK_PLACEHOLDERS_[${TAG$2}]`);
|
|
394
|
+
const formatError = createMockWrappedFunction(kit$1.formatError, `_MOCK_FORMAT_ERROR_[${TAG$2}]`);
|
|
395
|
+
// Alias for errorFromStatusCode (exported from @jaypie/errors as jaypieErrorFromStatus)
|
|
396
|
+
const jaypieErrorFromStatus = errorFromStatusCode;
|
|
397
|
+
const getHeaderFrom = createMockWrappedFunction(kit$1.getHeaderFrom, `_MOCK_GET_HEADER_FROM_[${TAG$2}]`);
|
|
398
|
+
const getObjectKeyCaseInsensitive = createMockWrappedFunction(kit$1.getObjectKeyCaseInsensitive, `_MOCK_GET_OBJECT_KEY_CASE_INSENSITIVE_[${TAG$2}]`);
|
|
399
|
+
const isClass = createMockWrappedFunction(kit$1.isClass, `_MOCK_IS_CLASS_[${TAG$2}]`);
|
|
400
|
+
const isJaypieError = createMockWrappedFunction(errors.isJaypieError, false);
|
|
401
|
+
const resolveValue = createMockWrappedFunction(kit$1.resolveValue, `_MOCK_RESOLVE_VALUE_[${TAG$2}]`);
|
|
402
|
+
const safeParseFloat = createMockWrappedFunction(kit$1.safeParseFloat, `_MOCK_SAFE_PARSE_FLOAT_[${TAG$2}]`);
|
|
403
|
+
const placeholders = createMockWrappedFunction(kit$1.placeholders, `_MOCK_PLACEHOLDERS_[${TAG$2}]`);
|
|
408
404
|
// Add force utilities to help with jaypieHandler implementation
|
|
409
|
-
const force = createMockWrappedObject(
|
|
405
|
+
const force = createMockWrappedObject(kit$1.force);
|
|
410
406
|
const jaypieHandler = createMockFunction((handler, options = {}) => {
|
|
411
407
|
return async (...args) => {
|
|
412
408
|
let result;
|
|
413
409
|
let thrownError;
|
|
414
410
|
// Destructure options with defaults
|
|
415
|
-
const { setup = [], teardown = [], unavailable =
|
|
411
|
+
const { setup = [], teardown = [], unavailable = kit$1.force.boolean(process.env.PROJECT_UNAVAILABLE), validate = [], } = options;
|
|
416
412
|
// Check if service is unavailable
|
|
417
413
|
if (unavailable)
|
|
418
414
|
throw new UnavailableError("Service unavailable");
|
|
419
415
|
// Run validation functions
|
|
420
|
-
const validateFunctions =
|
|
416
|
+
const validateFunctions = kit$1.force.array(validate);
|
|
421
417
|
for (const validator of validateFunctions) {
|
|
422
418
|
if (typeof validator === "function") {
|
|
423
419
|
const valid = await validator(...args);
|
|
@@ -428,7 +424,7 @@ const jaypieHandler = createMockFunction((handler, options = {}) => {
|
|
|
428
424
|
}
|
|
429
425
|
try {
|
|
430
426
|
// Run setup functions
|
|
431
|
-
const setupFunctions =
|
|
427
|
+
const setupFunctions = kit$1.force.array(setup);
|
|
432
428
|
for (const setupFunction of setupFunctions) {
|
|
433
429
|
if (typeof setupFunction === "function") {
|
|
434
430
|
await setupFunction(...args);
|
|
@@ -441,7 +437,7 @@ const jaypieHandler = createMockFunction((handler, options = {}) => {
|
|
|
441
437
|
thrownError = error;
|
|
442
438
|
}
|
|
443
439
|
// Run teardown functions (always run even if there was an error)
|
|
444
|
-
const teardownFunctions =
|
|
440
|
+
const teardownFunctions = kit$1.force.array(teardown);
|
|
445
441
|
for (const teardownFunction of teardownFunctions) {
|
|
446
442
|
if (typeof teardownFunction === "function") {
|
|
447
443
|
try {
|
|
@@ -461,19 +457,17 @@ const jaypieHandler = createMockFunction((handler, options = {}) => {
|
|
|
461
457
|
};
|
|
462
458
|
});
|
|
463
459
|
const sleep = createMockResolvedFunction(true);
|
|
464
|
-
const uuid = createMockWrappedFunction(
|
|
465
|
-
const
|
|
466
|
-
const
|
|
467
|
-
const
|
|
468
|
-
const PROJECT = original$1.PROJECT;
|
|
469
|
-
const VALIDATE = original$1.VALIDATE;
|
|
460
|
+
const uuid = createMockWrappedFunction(() => "00000000-0000-0000-0000-000000000000", `00000000-0000-0000-0000-000000000000`);
|
|
461
|
+
const HTTP$1 = kit$1.HTTP;
|
|
462
|
+
const JAYPIE = kit$1.JAYPIE;
|
|
463
|
+
const PROJECT = kit$1.PROJECT;
|
|
470
464
|
|
|
471
465
|
var core = /*#__PURE__*/Object.freeze({
|
|
472
466
|
__proto__: null,
|
|
473
467
|
BadGatewayError: BadGatewayError,
|
|
474
468
|
BadRequestError: BadRequestError,
|
|
475
469
|
ConfigurationError: ConfigurationError,
|
|
476
|
-
|
|
470
|
+
CorsError: CorsError,
|
|
477
471
|
ForbiddenError: ForbiddenError,
|
|
478
472
|
GatewayTimeoutError: GatewayTimeoutError,
|
|
479
473
|
GoneError: GoneError,
|
|
@@ -481,6 +475,7 @@ var core = /*#__PURE__*/Object.freeze({
|
|
|
481
475
|
IllogicalError: IllogicalError,
|
|
482
476
|
InternalError: InternalError,
|
|
483
477
|
JAYPIE: JAYPIE,
|
|
478
|
+
JaypieError: JaypieError,
|
|
484
479
|
MethodNotAllowedError: MethodNotAllowedError,
|
|
485
480
|
MultiError: MultiError,
|
|
486
481
|
NotFoundError: NotFoundError,
|
|
@@ -490,13 +485,13 @@ var core = /*#__PURE__*/Object.freeze({
|
|
|
490
485
|
ProjectMultiError: ProjectMultiError,
|
|
491
486
|
RejectedError: RejectedError,
|
|
492
487
|
TeapotError: TeapotError,
|
|
488
|
+
TooManyRequestsError: TooManyRequestsError,
|
|
493
489
|
UnauthorizedError: UnauthorizedError,
|
|
494
490
|
UnavailableError: UnavailableError,
|
|
495
491
|
UnhandledError: UnhandledError,
|
|
496
492
|
UnreachableCodeError: UnreachableCodeError,
|
|
497
|
-
VALIDATE: VALIDATE,
|
|
498
493
|
cloneDeep: cloneDeep,
|
|
499
|
-
envBoolean: envBoolean
|
|
494
|
+
envBoolean: envBoolean,
|
|
500
495
|
envsKey: envsKey,
|
|
501
496
|
errorFromStatusCode: errorFromStatusCode,
|
|
502
497
|
force: force,
|
|
@@ -505,20 +500,18 @@ var core = /*#__PURE__*/Object.freeze({
|
|
|
505
500
|
getObjectKeyCaseInsensitive: getObjectKeyCaseInsensitive,
|
|
506
501
|
isClass: isClass,
|
|
507
502
|
isJaypieError: isJaypieError,
|
|
503
|
+
jaypieErrorFromStatus: jaypieErrorFromStatus,
|
|
508
504
|
jaypieHandler: jaypieHandler,
|
|
509
505
|
log: log,
|
|
510
|
-
optional: optional,
|
|
511
506
|
placeholders: placeholders,
|
|
512
|
-
required: required,
|
|
513
507
|
resolveValue: resolveValue,
|
|
514
508
|
safeParseFloat: safeParseFloat,
|
|
515
509
|
sleep: sleep,
|
|
516
|
-
uuid: uuid
|
|
517
|
-
validate: validate
|
|
510
|
+
uuid: uuid
|
|
518
511
|
});
|
|
519
512
|
|
|
520
|
-
const DATADOG = original$
|
|
521
|
-
const hasDatadogEnv = createMockWrappedFunction(original$
|
|
513
|
+
const DATADOG = original$1.DATADOG;
|
|
514
|
+
const hasDatadogEnv = createMockWrappedFunction(original$1.hasDatadogEnv, false);
|
|
522
515
|
const submitDistribution = createMockResolvedFunction(true);
|
|
523
516
|
const submitMetric = createMockResolvedFunction(true);
|
|
524
517
|
const submitMetricSet = createMockResolvedFunction(true);
|
|
@@ -538,25 +531,25 @@ const TAG$1 = "EXPRESS";
|
|
|
538
531
|
const HTTP = {
|
|
539
532
|
CODE: { OK: 200, CREATED: 201, NO_CONTENT: 204, INTERNAL_ERROR: 500 },
|
|
540
533
|
};
|
|
541
|
-
const EXPRESS = original$
|
|
534
|
+
const EXPRESS = original$2.EXPRESS;
|
|
542
535
|
// Add Express route functions
|
|
543
|
-
const badRequestRoute = createMockWrappedFunction(original$
|
|
544
|
-
const echoRoute = createMockWrappedFunction(original$
|
|
545
|
-
const forbiddenRoute = createMockWrappedFunction(original$
|
|
546
|
-
const goneRoute = createMockWrappedFunction(original$
|
|
536
|
+
const badRequestRoute = createMockWrappedFunction(original$2.badRequestRoute, { error: `_MOCK_BAD_REQUEST_ROUTE_[${TAG$1}]` });
|
|
537
|
+
const echoRoute = createMockWrappedFunction(original$2.echoRoute, (req) => req);
|
|
538
|
+
const forbiddenRoute = createMockWrappedFunction(original$2.forbiddenRoute, { error: `_MOCK_FORBIDDEN_ROUTE_[${TAG$1}]` });
|
|
539
|
+
const goneRoute = createMockWrappedFunction(original$2.goneRoute, {
|
|
547
540
|
error: `_MOCK_GONE_ROUTE_[${TAG$1}]`,
|
|
548
541
|
});
|
|
549
|
-
const methodNotAllowedRoute = createMockWrappedFunction(original$
|
|
550
|
-
const noContentRoute = createMockWrappedFunction(original$
|
|
551
|
-
const notFoundRoute = createMockWrappedFunction(original$
|
|
542
|
+
const methodNotAllowedRoute = createMockWrappedFunction(original$2.methodNotAllowedRoute, { error: `_MOCK_METHOD_NOT_ALLOWED_ROUTE_[${TAG$1}]` });
|
|
543
|
+
const noContentRoute = createMockWrappedFunction(original$2.noContentRoute, { status: 204 });
|
|
544
|
+
const notFoundRoute = createMockWrappedFunction(original$2.notFoundRoute, {
|
|
552
545
|
error: `_MOCK_NOT_FOUND_ROUTE_[${TAG$1}]`,
|
|
553
546
|
});
|
|
554
|
-
const notImplementedRoute = createMockWrappedFunction(original$
|
|
555
|
-
const expressHttpCodeHandler = createMockWrappedFunction(original$
|
|
547
|
+
const notImplementedRoute = createMockWrappedFunction(original$2.notImplementedRoute, { error: `_MOCK_NOT_IMPLEMENTED_ROUTE_[${TAG$1}]` });
|
|
548
|
+
const expressHttpCodeHandler = createMockWrappedFunction(original$2.expressHttpCodeHandler, (...args) => {
|
|
556
549
|
const [req, res, next] = args;
|
|
557
550
|
return res.status(200).send();
|
|
558
551
|
});
|
|
559
|
-
const cors = createMockWrappedFunction(original$
|
|
552
|
+
const cors = createMockWrappedFunction(original$2.cors);
|
|
560
553
|
const expressHandler = createMockFunction((handlerOrProps, propsOrHandler) => {
|
|
561
554
|
let handler;
|
|
562
555
|
let props;
|
|
@@ -729,7 +722,7 @@ var lambda = /*#__PURE__*/Object.freeze({
|
|
|
729
722
|
lambdaHandler: lambdaHandler
|
|
730
723
|
});
|
|
731
724
|
|
|
732
|
-
const LLM = original$
|
|
725
|
+
const LLM = original$3.LLM;
|
|
733
726
|
const mockOperate = createMockResolvedFunction({
|
|
734
727
|
history: [
|
|
735
728
|
{
|
|
@@ -800,27 +793,27 @@ const weather = createMockTool("weather", createMockResolvedFunction({
|
|
|
800
793
|
location: `_MOCK_WEATHER_LOCATION`,
|
|
801
794
|
forecast: [{ conditions: "good" }],
|
|
802
795
|
}));
|
|
803
|
-
const Toolkit = createMockWrappedObject(original$
|
|
796
|
+
const Toolkit = createMockWrappedObject(original$3.Toolkit, {
|
|
804
797
|
isClass: true,
|
|
805
798
|
});
|
|
806
|
-
const JaypieToolkit = createMockWrappedObject(original$
|
|
799
|
+
const JaypieToolkit = createMockWrappedObject(original$3.JaypieToolkit, {
|
|
807
800
|
isClass: true,
|
|
808
801
|
});
|
|
809
|
-
const LlmMessageRole = createMockWrappedObject(original$
|
|
802
|
+
const LlmMessageRole = createMockWrappedObject(original$3.LlmMessageRole, {
|
|
810
803
|
isClass: true,
|
|
811
804
|
});
|
|
812
|
-
const LlmMessageType = createMockWrappedObject(original$
|
|
805
|
+
const LlmMessageType = createMockWrappedObject(original$3.LlmMessageType, {
|
|
813
806
|
isClass: true,
|
|
814
807
|
});
|
|
815
808
|
// Provider mocks
|
|
816
|
-
const GeminiProvider = createMockWrappedObject(original$
|
|
809
|
+
const GeminiProvider = createMockWrappedObject(original$3.GeminiProvider, {
|
|
817
810
|
isClass: true,
|
|
818
811
|
});
|
|
819
|
-
const OpenRouterProvider = createMockWrappedObject(original$
|
|
812
|
+
const OpenRouterProvider = createMockWrappedObject(original$3.OpenRouterProvider, {
|
|
820
813
|
isClass: true,
|
|
821
814
|
});
|
|
822
815
|
// Tool collections
|
|
823
|
-
const toolkit = new original$
|
|
816
|
+
const toolkit = new original$3.JaypieToolkit([
|
|
824
817
|
random,
|
|
825
818
|
roll,
|
|
826
819
|
time,
|
|
@@ -842,602 +835,6 @@ var llm = /*#__PURE__*/Object.freeze({
|
|
|
842
835
|
tools: tools
|
|
843
836
|
});
|
|
844
837
|
|
|
845
|
-
const DEFAULT = {
|
|
846
|
-
LEVEL: "debug",
|
|
847
|
-
VAR_LEVEL: "debug",
|
|
848
|
-
};
|
|
849
|
-
const ERROR_PREFIX = "[logger]";
|
|
850
|
-
const ERROR = {
|
|
851
|
-
VAR: {
|
|
852
|
-
EMPTY_OBJECT: `${ERROR_PREFIX} Logger.var() called with empty object`,
|
|
853
|
-
MULTIPLE_KEYS: `${ERROR_PREFIX} Logger.var() called with multiple keys`,
|
|
854
|
-
NULL_OBJECT: `${ERROR_PREFIX} Logger.var() called with null`,
|
|
855
|
-
UNDEFINED_MESSAGE: `${ERROR_PREFIX} Logger.var() called with \`undefined\` message`,
|
|
856
|
-
},
|
|
857
|
-
};
|
|
858
|
-
const FORMAT = {
|
|
859
|
-
JSON: "json",
|
|
860
|
-
TEXT: "text",
|
|
861
|
-
};
|
|
862
|
-
const LEVEL = {
|
|
863
|
-
ALL: "all",
|
|
864
|
-
DEBUG: "debug",
|
|
865
|
-
ERROR: "error",
|
|
866
|
-
FATAL: "fatal",
|
|
867
|
-
INFO: "info",
|
|
868
|
-
SILENT: "silent",
|
|
869
|
-
TRACE: "trace",
|
|
870
|
-
WARN: "warn",
|
|
871
|
-
};
|
|
872
|
-
const LEVEL_VALUES = {
|
|
873
|
-
all: 100,
|
|
874
|
-
debug: 70,
|
|
875
|
-
error: 10,
|
|
876
|
-
fatal: 1,
|
|
877
|
-
info: 50,
|
|
878
|
-
none: 0,
|
|
879
|
-
silent: 0,
|
|
880
|
-
trace: 90,
|
|
881
|
-
warn: 30,
|
|
882
|
-
};
|
|
883
|
-
|
|
884
|
-
function forceString(value, defaultValue = "") {
|
|
885
|
-
if (value === null)
|
|
886
|
-
return "null";
|
|
887
|
-
if (value === undefined)
|
|
888
|
-
return String(defaultValue);
|
|
889
|
-
if (typeof value === "object")
|
|
890
|
-
return JSON.stringify(value);
|
|
891
|
-
return String(value);
|
|
892
|
-
}
|
|
893
|
-
function formatAsJsonString(subject) {
|
|
894
|
-
const SPACES = 0;
|
|
895
|
-
const UNUSED_PARAM = null;
|
|
896
|
-
switch (typeof subject) {
|
|
897
|
-
case "string":
|
|
898
|
-
if (subject === "")
|
|
899
|
-
return `""`;
|
|
900
|
-
try {
|
|
901
|
-
return JSON.stringify(JSON.parse(subject), UNUSED_PARAM, SPACES);
|
|
902
|
-
}
|
|
903
|
-
catch {
|
|
904
|
-
return subject;
|
|
905
|
-
}
|
|
906
|
-
case "object":
|
|
907
|
-
try {
|
|
908
|
-
if (subject &&
|
|
909
|
-
subject instanceof Object &&
|
|
910
|
-
!Array.isArray(subject) &&
|
|
911
|
-
subject.constructor &&
|
|
912
|
-
subject.constructor !== Object &&
|
|
913
|
-
"toString" in subject &&
|
|
914
|
-
typeof subject.toString === "function") {
|
|
915
|
-
return subject.toString();
|
|
916
|
-
}
|
|
917
|
-
return JSON.stringify(subject, UNUSED_PARAM, SPACES);
|
|
918
|
-
}
|
|
919
|
-
catch (error) {
|
|
920
|
-
if (error instanceof TypeError) {
|
|
921
|
-
const truncatedSubject = Object.keys(subject).reduce((newSubject, key) => {
|
|
922
|
-
const nextSubject = { ...newSubject };
|
|
923
|
-
nextSubject[key] = String(subject[key]);
|
|
924
|
-
return nextSubject;
|
|
925
|
-
}, {});
|
|
926
|
-
return formatAsJsonString(truncatedSubject);
|
|
927
|
-
}
|
|
928
|
-
throw error;
|
|
929
|
-
}
|
|
930
|
-
default:
|
|
931
|
-
return String(subject);
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
function stringify(...params) {
|
|
935
|
-
if (params.length === 0)
|
|
936
|
-
return "";
|
|
937
|
-
if (params.length === 1) {
|
|
938
|
-
return formatAsJsonString(params[0]);
|
|
939
|
-
}
|
|
940
|
-
const formatted = params.map(formatAsJsonString);
|
|
941
|
-
return formatted.join(" ");
|
|
942
|
-
}
|
|
943
|
-
function out(line, { level = "debug" } = {}) {
|
|
944
|
-
let lineStr;
|
|
945
|
-
if (typeof line !== "string") {
|
|
946
|
-
lineStr = stringify(line);
|
|
947
|
-
}
|
|
948
|
-
else {
|
|
949
|
-
lineStr = line;
|
|
950
|
-
}
|
|
951
|
-
let outputFunction;
|
|
952
|
-
switch (level) {
|
|
953
|
-
case LEVEL.INFO:
|
|
954
|
-
outputFunction = console.info;
|
|
955
|
-
break;
|
|
956
|
-
case LEVEL.WARN:
|
|
957
|
-
outputFunction = console.warn;
|
|
958
|
-
break;
|
|
959
|
-
case LEVEL.ERROR:
|
|
960
|
-
case LEVEL.FATAL:
|
|
961
|
-
outputFunction = console.error;
|
|
962
|
-
break;
|
|
963
|
-
case LEVEL.TRACE:
|
|
964
|
-
case LEVEL.DEBUG:
|
|
965
|
-
outputFunction = console.debug;
|
|
966
|
-
break;
|
|
967
|
-
default:
|
|
968
|
-
outputFunction = console.log;
|
|
969
|
-
break;
|
|
970
|
-
}
|
|
971
|
-
try {
|
|
972
|
-
outputFunction(lineStr);
|
|
973
|
-
}
|
|
974
|
-
catch (error) {
|
|
975
|
-
console.warn(error);
|
|
976
|
-
console.log(lineStr);
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
function parse(message) {
|
|
980
|
-
if (typeof message !== "string") {
|
|
981
|
-
return message;
|
|
982
|
-
}
|
|
983
|
-
try {
|
|
984
|
-
return JSON.parse(message);
|
|
985
|
-
}
|
|
986
|
-
catch {
|
|
987
|
-
return message;
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
function parsesTo(message) {
|
|
991
|
-
if (typeof message !== "string") {
|
|
992
|
-
return {
|
|
993
|
-
parses: false,
|
|
994
|
-
message,
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
try {
|
|
998
|
-
return {
|
|
999
|
-
parses: true,
|
|
1000
|
-
message: JSON.parse(message),
|
|
1001
|
-
};
|
|
1002
|
-
}
|
|
1003
|
-
catch {
|
|
1004
|
-
return {
|
|
1005
|
-
parses: false,
|
|
1006
|
-
message,
|
|
1007
|
-
};
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
class Logger {
|
|
1012
|
-
constructor({ format = process.env.LOG_FORMAT || DEFAULT.LEVEL, level = process.env.LOG_LEVEL || DEFAULT.LEVEL, tags = {}, varLevel = process.env.LOG_VAR_LEVEL || DEFAULT.VAR_LEVEL, } = {}) {
|
|
1013
|
-
this.options = {
|
|
1014
|
-
format,
|
|
1015
|
-
level,
|
|
1016
|
-
varLevel,
|
|
1017
|
-
};
|
|
1018
|
-
this.tags = {};
|
|
1019
|
-
Object.keys(tags).forEach((key) => {
|
|
1020
|
-
this.tags[key] = forceString(tags[key]);
|
|
1021
|
-
});
|
|
1022
|
-
this.debug = this.createLogMethod(LEVEL.DEBUG, format, level);
|
|
1023
|
-
this.error = this.createLogMethod(LEVEL.ERROR, format, level);
|
|
1024
|
-
this.fatal = this.createLogMethod(LEVEL.FATAL, format, level);
|
|
1025
|
-
this.info = this.createLogMethod(LEVEL.INFO, format, level);
|
|
1026
|
-
this.trace = this.createLogMethod(LEVEL.TRACE, format, level);
|
|
1027
|
-
this.warn = this.createLogMethod(LEVEL.WARN, format, level);
|
|
1028
|
-
const varLevelMethod = this[varLevel];
|
|
1029
|
-
this.var = varLevelMethod?.var || this.debug.var;
|
|
1030
|
-
}
|
|
1031
|
-
createLogMethod(logLevel, format, checkLevel) {
|
|
1032
|
-
const logFn = (...messages) => {
|
|
1033
|
-
if (LEVEL_VALUES[logLevel] <= LEVEL_VALUES[checkLevel]) {
|
|
1034
|
-
if (format === FORMAT.JSON) {
|
|
1035
|
-
const message = stringify(...messages);
|
|
1036
|
-
const parses = parsesTo(message);
|
|
1037
|
-
const json = {
|
|
1038
|
-
log: logLevel,
|
|
1039
|
-
message,
|
|
1040
|
-
...this.tags,
|
|
1041
|
-
};
|
|
1042
|
-
if (parses.parses) {
|
|
1043
|
-
json.data = parses.message;
|
|
1044
|
-
}
|
|
1045
|
-
out(json, { level: logLevel });
|
|
1046
|
-
}
|
|
1047
|
-
else {
|
|
1048
|
-
const message = stringify(...messages);
|
|
1049
|
-
out(message, { level: logLevel });
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
};
|
|
1053
|
-
logFn.var = (messageObject, messageValue) => {
|
|
1054
|
-
if (messageObject === undefined) {
|
|
1055
|
-
this.warn(ERROR.VAR.UNDEFINED_MESSAGE);
|
|
1056
|
-
}
|
|
1057
|
-
let msgObj;
|
|
1058
|
-
if (typeof messageObject !== "object" || messageObject === null) {
|
|
1059
|
-
if (typeof messageObject !== "object") {
|
|
1060
|
-
if (messageValue === undefined)
|
|
1061
|
-
messageValue = "undefined";
|
|
1062
|
-
msgObj = { [String(messageObject)]: messageValue };
|
|
1063
|
-
}
|
|
1064
|
-
else {
|
|
1065
|
-
this.warn(ERROR.VAR.NULL_OBJECT);
|
|
1066
|
-
return logFn(messageObject);
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
else {
|
|
1070
|
-
msgObj = messageObject;
|
|
1071
|
-
}
|
|
1072
|
-
const keys = Object.keys(msgObj);
|
|
1073
|
-
if (keys.length === 0) {
|
|
1074
|
-
this.warn(ERROR.VAR.EMPTY_OBJECT);
|
|
1075
|
-
return logFn(msgObj);
|
|
1076
|
-
}
|
|
1077
|
-
if (keys.length > 1) {
|
|
1078
|
-
this.warn(ERROR.VAR.MULTIPLE_KEYS);
|
|
1079
|
-
return logFn(msgObj);
|
|
1080
|
-
}
|
|
1081
|
-
if (format === FORMAT.JSON) {
|
|
1082
|
-
const messageKey = keys[0];
|
|
1083
|
-
const messageVal = msgObj[messageKey];
|
|
1084
|
-
const json = {
|
|
1085
|
-
data: parse(messageVal),
|
|
1086
|
-
dataType: typeof messageVal,
|
|
1087
|
-
log: logLevel,
|
|
1088
|
-
message: stringify(messageVal),
|
|
1089
|
-
var: messageKey,
|
|
1090
|
-
...this.tags,
|
|
1091
|
-
};
|
|
1092
|
-
if (LEVEL_VALUES[logLevel] <= LEVEL_VALUES[checkLevel]) {
|
|
1093
|
-
out(json, { level: logLevel });
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
else {
|
|
1097
|
-
return logFn(msgObj);
|
|
1098
|
-
}
|
|
1099
|
-
};
|
|
1100
|
-
return logFn;
|
|
1101
|
-
}
|
|
1102
|
-
tag(key, value) {
|
|
1103
|
-
if (value) {
|
|
1104
|
-
this.tags[forceString(key)] = forceString(value);
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
|
-
if (Array.isArray(key)) {
|
|
1108
|
-
key.forEach((k) => {
|
|
1109
|
-
this.tags[forceString(k)] = "";
|
|
1110
|
-
});
|
|
1111
|
-
return;
|
|
1112
|
-
}
|
|
1113
|
-
if (key === null) {
|
|
1114
|
-
this.tags.null = "";
|
|
1115
|
-
return;
|
|
1116
|
-
}
|
|
1117
|
-
if (typeof key === "object") {
|
|
1118
|
-
Object.keys(key).forEach((k) => {
|
|
1119
|
-
this.tags[forceString(k)] = forceString(key[k]);
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
else {
|
|
1123
|
-
this.tags[forceString(key)] = "";
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
untag(key) {
|
|
1127
|
-
if (Array.isArray(key)) {
|
|
1128
|
-
key.forEach((k) => {
|
|
1129
|
-
delete this.tags[forceString(k)];
|
|
1130
|
-
});
|
|
1131
|
-
return;
|
|
1132
|
-
}
|
|
1133
|
-
if (key === null) {
|
|
1134
|
-
delete this.tags.null;
|
|
1135
|
-
return;
|
|
1136
|
-
}
|
|
1137
|
-
if (typeof key === "object") {
|
|
1138
|
-
Object.keys(key).forEach((k) => {
|
|
1139
|
-
delete this.tags[forceString(k)];
|
|
1140
|
-
});
|
|
1141
|
-
}
|
|
1142
|
-
else {
|
|
1143
|
-
delete this.tags[forceString(key)];
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
with(key, value) {
|
|
1147
|
-
const logger = new Logger(this.options);
|
|
1148
|
-
logger.tag(this.tags);
|
|
1149
|
-
logger.tag(key, value);
|
|
1150
|
-
return logger;
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
function logTags(withTags) {
|
|
1155
|
-
const { PROJECT_COMMIT, PROJECT_ENV, PROJECT_KEY, PROJECT_SERVICE, PROJECT_SPONSOR, PROJECT_VERSION, } = process.env;
|
|
1156
|
-
const tags = {};
|
|
1157
|
-
if (PROJECT_COMMIT) {
|
|
1158
|
-
tags.commit = PROJECT_COMMIT;
|
|
1159
|
-
}
|
|
1160
|
-
if (PROJECT_ENV) {
|
|
1161
|
-
tags.env = PROJECT_ENV;
|
|
1162
|
-
}
|
|
1163
|
-
if (PROJECT_KEY) {
|
|
1164
|
-
tags.project = PROJECT_KEY;
|
|
1165
|
-
}
|
|
1166
|
-
if (PROJECT_SERVICE) {
|
|
1167
|
-
tags.service = PROJECT_SERVICE;
|
|
1168
|
-
}
|
|
1169
|
-
if (PROJECT_SPONSOR) {
|
|
1170
|
-
tags.sponsor = PROJECT_SPONSOR;
|
|
1171
|
-
}
|
|
1172
|
-
if (process.env.npm_package_version || PROJECT_VERSION) {
|
|
1173
|
-
tags.version = (process.env.npm_package_version ||
|
|
1174
|
-
PROJECT_VERSION);
|
|
1175
|
-
}
|
|
1176
|
-
return {
|
|
1177
|
-
...tags,
|
|
1178
|
-
...withTags,
|
|
1179
|
-
};
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
function forceVar(key, value) {
|
|
1183
|
-
if (typeof key === "undefined") {
|
|
1184
|
-
return {};
|
|
1185
|
-
}
|
|
1186
|
-
if (typeof key === "object" && key !== null) {
|
|
1187
|
-
if (Object.keys(key).length === 1) {
|
|
1188
|
-
return key;
|
|
1189
|
-
}
|
|
1190
|
-
else {
|
|
1191
|
-
return { value: key };
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
const keyStr = forceString(key);
|
|
1195
|
-
if (typeof value === "undefined") {
|
|
1196
|
-
return { [keyStr]: "" };
|
|
1197
|
-
}
|
|
1198
|
-
else {
|
|
1199
|
-
return { [keyStr]: value };
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
function isAxiosResponse(response) {
|
|
1204
|
-
if (typeof response !== "object" || response === null) {
|
|
1205
|
-
return false;
|
|
1206
|
-
}
|
|
1207
|
-
const r = response;
|
|
1208
|
-
return !!(r &&
|
|
1209
|
-
r.config &&
|
|
1210
|
-
r.data &&
|
|
1211
|
-
r.headers &&
|
|
1212
|
-
r.request &&
|
|
1213
|
-
r.status &&
|
|
1214
|
-
r.statusText);
|
|
1215
|
-
}
|
|
1216
|
-
function filterAxiosResponse(response) {
|
|
1217
|
-
if (!isAxiosResponse(response)) {
|
|
1218
|
-
return response;
|
|
1219
|
-
}
|
|
1220
|
-
const r = response;
|
|
1221
|
-
const newResponse = {
|
|
1222
|
-
data: r.data,
|
|
1223
|
-
headers: r.headers,
|
|
1224
|
-
status: r.status,
|
|
1225
|
-
statusText: r.statusText,
|
|
1226
|
-
};
|
|
1227
|
-
if (r.isAxiosError) {
|
|
1228
|
-
newResponse.isAxiosError = r.isAxiosError;
|
|
1229
|
-
}
|
|
1230
|
-
return newResponse;
|
|
1231
|
-
}
|
|
1232
|
-
const axiosResponseVarPipeline = {
|
|
1233
|
-
filter: filterAxiosResponse,
|
|
1234
|
-
key: "response",
|
|
1235
|
-
};
|
|
1236
|
-
function isError(item) {
|
|
1237
|
-
if (typeof item !== "object" || item === null) {
|
|
1238
|
-
return false;
|
|
1239
|
-
}
|
|
1240
|
-
if (item instanceof Error) {
|
|
1241
|
-
return true;
|
|
1242
|
-
}
|
|
1243
|
-
const i = item;
|
|
1244
|
-
if (i.isProjectError) {
|
|
1245
|
-
return true;
|
|
1246
|
-
}
|
|
1247
|
-
return false;
|
|
1248
|
-
}
|
|
1249
|
-
function filterErrorVar(item) {
|
|
1250
|
-
if (!isError(item)) {
|
|
1251
|
-
return item;
|
|
1252
|
-
}
|
|
1253
|
-
const e = item;
|
|
1254
|
-
const newItem = {
|
|
1255
|
-
message: e.message,
|
|
1256
|
-
name: e.name,
|
|
1257
|
-
};
|
|
1258
|
-
if (e.cause) {
|
|
1259
|
-
newItem.cause = e.cause;
|
|
1260
|
-
}
|
|
1261
|
-
if (e.stack) {
|
|
1262
|
-
newItem.stack = e.stack;
|
|
1263
|
-
}
|
|
1264
|
-
if (e.isProjectError) {
|
|
1265
|
-
newItem.isProjectError = e.isProjectError;
|
|
1266
|
-
newItem.title = e.title;
|
|
1267
|
-
newItem.detail = e.detail;
|
|
1268
|
-
newItem.status = e.status;
|
|
1269
|
-
}
|
|
1270
|
-
return newItem;
|
|
1271
|
-
}
|
|
1272
|
-
const errorVarPipeline = {
|
|
1273
|
-
filter: filterErrorVar,
|
|
1274
|
-
key: "error",
|
|
1275
|
-
};
|
|
1276
|
-
const pipelines = [axiosResponseVarPipeline, errorVarPipeline];
|
|
1277
|
-
|
|
1278
|
-
function keyValueToArray(keyValue) {
|
|
1279
|
-
const key = Object.keys(keyValue)[0];
|
|
1280
|
-
return [key, keyValue[key]];
|
|
1281
|
-
}
|
|
1282
|
-
function logVar(key, value) {
|
|
1283
|
-
let [k, v] = keyValueToArray(forceVar(key, value));
|
|
1284
|
-
for (const pipeline of pipelines) {
|
|
1285
|
-
if (k === pipeline.key) {
|
|
1286
|
-
v = pipeline.filter(v);
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
return { [k]: v };
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
function envBoolean(key, { defaultValue }) {
|
|
1293
|
-
const value = process.env[key];
|
|
1294
|
-
if (value === undefined)
|
|
1295
|
-
return defaultValue;
|
|
1296
|
-
const lower = value.toLowerCase();
|
|
1297
|
-
return !(lower === "" ||
|
|
1298
|
-
lower === "0" ||
|
|
1299
|
-
lower === "f" ||
|
|
1300
|
-
lower === "false" ||
|
|
1301
|
-
lower === "n" ||
|
|
1302
|
-
lower === "no");
|
|
1303
|
-
}
|
|
1304
|
-
class JaypieLogger {
|
|
1305
|
-
constructor({ level = process.env.LOG_LEVEL, tags = {}, } = {}) {
|
|
1306
|
-
this._params = { level, tags };
|
|
1307
|
-
this._loggers = [];
|
|
1308
|
-
this._tags = {};
|
|
1309
|
-
this._withLoggers = {};
|
|
1310
|
-
this.level = level || DEFAULT.LEVEL;
|
|
1311
|
-
this._tags = { ...logTags(), ...tags };
|
|
1312
|
-
this._logger = new Logger({
|
|
1313
|
-
format: FORMAT.JSON,
|
|
1314
|
-
level: this.level,
|
|
1315
|
-
tags: this._tags,
|
|
1316
|
-
});
|
|
1317
|
-
this._loggers = [this._logger];
|
|
1318
|
-
this.debug = ((...args) => this._logger.debug(...args));
|
|
1319
|
-
this.debug.var = (messageObject, messageValue) => this._logger.debug.var(messageObject, messageValue);
|
|
1320
|
-
this.error = ((...args) => this._logger.error(...args));
|
|
1321
|
-
this.error.var = (messageObject, messageValue) => this._logger.error.var(messageObject, messageValue);
|
|
1322
|
-
this.fatal = ((...args) => this._logger.fatal(...args));
|
|
1323
|
-
this.fatal.var = (messageObject, messageValue) => this._logger.fatal.var(messageObject, messageValue);
|
|
1324
|
-
this.info = ((...args) => this._logger.info(...args));
|
|
1325
|
-
this.info.var = (messageObject, messageValue) => this._logger.info.var(messageObject, messageValue);
|
|
1326
|
-
this.trace = ((...args) => this._logger.trace(...args));
|
|
1327
|
-
this.trace.var = (messageObject, messageValue) => this._logger.trace.var(messageObject, messageValue);
|
|
1328
|
-
this.warn = ((...args) => this._logger.warn(...args));
|
|
1329
|
-
this.warn.var = (messageObject, messageValue) => this._logger.warn.var(messageObject, messageValue);
|
|
1330
|
-
this.var = (messageObject, messageValue) => this._logger.var(logVar(messageObject, messageValue));
|
|
1331
|
-
}
|
|
1332
|
-
init() {
|
|
1333
|
-
for (const logger of this._loggers) {
|
|
1334
|
-
if ("init" in logger && typeof logger.init === "function") {
|
|
1335
|
-
logger.init();
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
const level = this._params.level;
|
|
1339
|
-
const tags = this._params.tags;
|
|
1340
|
-
this.level = level || DEFAULT.LEVEL;
|
|
1341
|
-
this._tags = { ...logTags(), ...tags };
|
|
1342
|
-
this._logger = new Logger({
|
|
1343
|
-
format: FORMAT.JSON,
|
|
1344
|
-
level: this.level,
|
|
1345
|
-
tags: this._tags,
|
|
1346
|
-
});
|
|
1347
|
-
this._loggers = [this._logger];
|
|
1348
|
-
this._withLoggers = {};
|
|
1349
|
-
const levels = [
|
|
1350
|
-
"debug",
|
|
1351
|
-
"error",
|
|
1352
|
-
"fatal",
|
|
1353
|
-
"info",
|
|
1354
|
-
"trace",
|
|
1355
|
-
"warn",
|
|
1356
|
-
];
|
|
1357
|
-
levels.forEach((lvl) => {
|
|
1358
|
-
this[lvl] = ((...args) => {
|
|
1359
|
-
this._logger[lvl](...args);
|
|
1360
|
-
});
|
|
1361
|
-
this[lvl].var = (messageObject, messageValue) => {
|
|
1362
|
-
this._logger[lvl].var(messageObject, messageValue);
|
|
1363
|
-
};
|
|
1364
|
-
});
|
|
1365
|
-
}
|
|
1366
|
-
lib({ level, lib, tags = {}, } = {}) {
|
|
1367
|
-
const newTags = Object.assign({}, this._tags, tags);
|
|
1368
|
-
if (lib) {
|
|
1369
|
-
newTags.lib = lib;
|
|
1370
|
-
}
|
|
1371
|
-
const logger = new JaypieLogger({
|
|
1372
|
-
level: (() => {
|
|
1373
|
-
if (level) {
|
|
1374
|
-
return level;
|
|
1375
|
-
}
|
|
1376
|
-
if (process.env.MODULE_LOG_LEVEL) {
|
|
1377
|
-
return process.env.MODULE_LOG_LEVEL;
|
|
1378
|
-
}
|
|
1379
|
-
if (envBoolean("MODULE_LOGGER", { defaultValue: false })) {
|
|
1380
|
-
return process.env.LOG_LEVEL;
|
|
1381
|
-
}
|
|
1382
|
-
return LEVEL.SILENT;
|
|
1383
|
-
})(),
|
|
1384
|
-
tags: newTags,
|
|
1385
|
-
});
|
|
1386
|
-
this._loggers.push(logger._logger);
|
|
1387
|
-
return logger;
|
|
1388
|
-
}
|
|
1389
|
-
tag(tags) {
|
|
1390
|
-
for (const logger of this._loggers) {
|
|
1391
|
-
logger.tag(tags);
|
|
1392
|
-
}
|
|
1393
|
-
Object.assign(this._tags, tags);
|
|
1394
|
-
}
|
|
1395
|
-
untag(key) {
|
|
1396
|
-
for (const logger of this._loggers) {
|
|
1397
|
-
logger.untag(key);
|
|
1398
|
-
}
|
|
1399
|
-
if (Array.isArray(key)) {
|
|
1400
|
-
key.forEach((k) => {
|
|
1401
|
-
delete this._tags[String(k)];
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
else if (typeof key === "object" && key !== null) {
|
|
1405
|
-
Object.keys(key).forEach((k) => {
|
|
1406
|
-
delete this._tags[k];
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
|
-
else {
|
|
1410
|
-
delete this._tags[String(key)];
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
with(key, value) {
|
|
1414
|
-
if (!key || (typeof key !== "object" && value === undefined)) {
|
|
1415
|
-
throw new Error("ConfigurationError: with() requires an object argument or key-value pair");
|
|
1416
|
-
}
|
|
1417
|
-
const loggerKey = JSON.stringify([key, value]);
|
|
1418
|
-
if (Object.keys(this._withLoggers).includes(loggerKey)) {
|
|
1419
|
-
return this._withLoggers[loggerKey];
|
|
1420
|
-
}
|
|
1421
|
-
const logger = new JaypieLogger({
|
|
1422
|
-
level: this.level,
|
|
1423
|
-
tags: { ...this._tags },
|
|
1424
|
-
});
|
|
1425
|
-
logger._logger = this._logger.with(key, value);
|
|
1426
|
-
logger._loggers = [logger._logger];
|
|
1427
|
-
this._withLoggers[loggerKey] = logger;
|
|
1428
|
-
this._loggers.push(logger._logger);
|
|
1429
|
-
return logger;
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
function createLogger$1(tags = {}) {
|
|
1433
|
-
const jaypieLogger = new JaypieLogger({
|
|
1434
|
-
tags,
|
|
1435
|
-
});
|
|
1436
|
-
return jaypieLogger;
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
createLogger$1();
|
|
1440
|
-
|
|
1441
838
|
const mockLog = mockLogFactory();
|
|
1442
839
|
const createLogger = createMockWrappedFunction(createLogger$1, mockLog);
|
|
1443
840
|
|
|
@@ -1465,9 +862,9 @@ var mongoose = /*#__PURE__*/Object.freeze({
|
|
|
1465
862
|
|
|
1466
863
|
// Constants for mock values
|
|
1467
864
|
const TAG = "TEXTRACT";
|
|
1468
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
1469
|
-
const __dirname = dirname(__filename);
|
|
1470
|
-
const MOCK_TEXTRACT_DOCUMENT_PATH = join(__dirname, "..", "mockTextract.json");
|
|
865
|
+
const __filename$1 = fileURLToPath(import.meta.url);
|
|
866
|
+
const __dirname$1 = dirname(__filename$1);
|
|
867
|
+
const MOCK_TEXTRACT_DOCUMENT_PATH = join(__dirname$1, "..", "mockTextract.json");
|
|
1471
868
|
// Setup
|
|
1472
869
|
let mockTextractContents;
|
|
1473
870
|
beforeAll(async () => {
|
|
@@ -1476,18 +873,18 @@ beforeAll(async () => {
|
|
|
1476
873
|
/**
|
|
1477
874
|
* Mock for MarkdownPage class from @jaypie/textract
|
|
1478
875
|
*/
|
|
1479
|
-
const MarkdownPage = createMockWrappedObject(original$
|
|
876
|
+
const MarkdownPage = createMockWrappedObject(original$4.MarkdownPage, {
|
|
1480
877
|
class: true,
|
|
1481
878
|
fallback: () => {
|
|
1482
879
|
const mockDocument = new TextractDocument(JSON.parse(mockTextractContents));
|
|
1483
880
|
// Double type assertion needed to bridge incompatible types
|
|
1484
|
-
return new original$
|
|
881
|
+
return new original$4.MarkdownPage(mockDocument.pageNumber(1));
|
|
1485
882
|
},
|
|
1486
883
|
});
|
|
1487
884
|
/**
|
|
1488
885
|
* Mock for textractJsonToMarkdown function from @jaypie/textract
|
|
1489
886
|
*/
|
|
1490
|
-
const textractJsonToMarkdown = createMockWrappedFunction(original$
|
|
887
|
+
const textractJsonToMarkdown = createMockWrappedFunction(original$4.textractJsonToMarkdown, `_MOCK_TEXTRACT_JSON_TO_MARKDOWN_[${TAG}]`);
|
|
1491
888
|
// Export default for convenience
|
|
1492
889
|
var textract = {
|
|
1493
890
|
MarkdownPage,
|
|
@@ -1524,5 +921,5 @@ const mock = {
|
|
|
1524
921
|
...textract$1,
|
|
1525
922
|
};
|
|
1526
923
|
|
|
1527
|
-
export { BadGatewayError, BadRequestError, ConfigurationError,
|
|
924
|
+
export { BadGatewayError, BadRequestError, ConfigurationError, CorsError, DATADOG, EXPRESS, ForbiddenError, GatewayTimeoutError, GeminiProvider, GoneError, HTTP$1 as HTTP, IllogicalError, InternalError, JAYPIE, JaypieError, JaypieToolkit, LLM, Llm, LlmMessageRole, LlmMessageType, MarkdownPage, MethodNotAllowedError, MultiError, NotFoundError, NotImplementedError, OpenRouterProvider, PROJECT, ProjectError, ProjectMultiError, RejectedError, TeapotError, TooManyRequestsError, Toolkit, UnauthorizedError, UnavailableError, UnhandledError, UnreachableCodeError, badRequestRoute, cloneDeep, connect, connectFromSecretEnv, cors, createLogger, mock as default, disconnect, echoRoute, envBoolean, envsKey, errorFromStatusCode, expressHandler, expressHttpCodeHandler, forbiddenRoute, force, formatError, getEnvSecret, getHeaderFrom, getMessages, getObjectKeyCaseInsensitive, getSecret, getSingletonMessage, getTextractJob, goneRoute, hasDatadogEnv, isClass, isJaypieError, isNodeTestEnv, isProductionEnv, jaypieErrorFromStatus, jaypieHandler, lambdaHandler, methodNotAllowedRoute, noContentRoute, notFoundRoute, notImplementedRoute, placeholders, resolveValue, safeParseFloat, sendBatchMessages, sendMessage, sendTextractJob, sleep, submitDistribution, submitMetric, submitMetricSet, textractJsonToMarkdown, toolkit, tools, uuid };
|
|
1528
925
|
//# sourceMappingURL=index.js.map
|