autoreggol
Advanced tools
Comparing version 0.3.0 to 0.3.1-next
@@ -1,3 +0,3 @@ | ||
export declare type Level = "fatal" | "error" | "warn" | "info" | "debug" | "trace"; | ||
export declare type ConstructorType = { | ||
export type Level = "fatal" | "error" | "warn" | "info" | "debug" | "trace"; | ||
export type ConstructorType = { | ||
new (...args: any[]): {}; | ||
@@ -15,2 +15,2 @@ }; | ||
} | ||
export declare type LogFunction = (ctr: ConstructorType, targetKey: string | symbol, targetValue: any, level: Level) => void; | ||
export type LogFunction = (ctr: ConstructorType, targetKey: string | symbol, targetValue: any, level: Level) => void; |
@@ -5,3 +5,3 @@ "use strict"; | ||
function AutoLogBypassClass(constructor) { | ||
Reflect.defineMetadata("BYPASS_LOGGING" /* BYPASS_LOGGING */, true, constructor); | ||
Reflect.defineMetadata("BYPASS_LOGGING" /* MetadataKey.BYPASS_LOGGING */, true, constructor); | ||
return constructor; | ||
@@ -8,0 +8,0 @@ } |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -14,2 +18,3 @@ if (k2 === undefined) k2 = k; | ||
exports.AutoLog = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
require("reflect-metadata"); | ||
@@ -19,3 +24,3 @@ function AutoLog({ logger, level = "info", enablePropertyLoging = false, enableLogging = true, }) { | ||
var _a; | ||
const shouldBypass = (_a = Reflect.getMetadata("BYPASS_LOGGING" /* BYPASS_LOGGING */, constructor)) !== null && _a !== void 0 ? _a : false; | ||
const shouldBypass = (_a = Reflect.getMetadata("BYPASS_LOGGING" /* MetadataKey.BYPASS_LOGGING */, constructor)) !== null && _a !== void 0 ? _a : false; | ||
if (!shouldBypass) { | ||
@@ -27,6 +32,12 @@ const proxy = new Proxy(constructor, { | ||
const targetValue = Reflect.get(target, propKey, receiver); | ||
const bypassLogging = Reflect.getMetadata("BYPASS_LOGGING" /* BYPASS_LOGGING */, target, propKey); | ||
const logLevel = Reflect.getMetadata("LOG_LEVEL" /* LOG_LEVEL */, target, propKey); | ||
const bypassLogging = Reflect.getMetadata("BYPASS_LOGGING" /* MetadataKey.BYPASS_LOGGING */, target, propKey); | ||
const logLevel = Reflect.getMetadata("LOG_LEVEL" /* MetadataKey.LOG_LEVEL */, target, propKey); | ||
const LEVEL = logLevel !== null && logLevel !== void 0 ? logLevel : level; | ||
if (typeof targetValue === "function" && !bypassLogging) { | ||
/** :facepalm: This is awful. | ||
* The reason this is needed is because _something_ in jest-mock _really_ doesn't like it when a wrapper on the function is returned. With Vitest's `spyOn` this doesn't seem to be a problem. | ||
*/ | ||
if (targetValue._isMockFunction) { | ||
return targetValue; | ||
} | ||
return function _function(...args) { | ||
@@ -33,0 +44,0 @@ logger(constructor, propKey, args, LEVEL); |
@@ -5,3 +5,3 @@ "use strict"; | ||
function AutoLogBypass(target, propertyKey, _descriptor) { | ||
Reflect.defineMetadata("BYPASS_LOGGING" /* BYPASS_LOGGING */, true, target, propertyKey); | ||
Reflect.defineMetadata("BYPASS_LOGGING" /* MetadataKey.BYPASS_LOGGING */, true, target, propertyKey); | ||
} | ||
@@ -11,3 +11,3 @@ exports.AutoLogBypass = AutoLogBypass; | ||
return function _loglevel(target, propertyKey, _descriptor) { | ||
Reflect.defineMetadata("LOG_LEVEL" /* LOG_LEVEL */, level, target, propertyKey); | ||
Reflect.defineMetadata("LOG_LEVEL" /* MetadataKey.LOG_LEVEL */, level, target, propertyKey); | ||
}; | ||
@@ -14,0 +14,0 @@ } |
@@ -5,3 +5,3 @@ "use strict"; | ||
function AutoLogPropBypass(target, propertyKey) { | ||
Reflect.defineMetadata("BYPASS_LOGGING" /* BYPASS_LOGGING */, true, target, propertyKey); | ||
Reflect.defineMetadata("BYPASS_LOGGING" /* MetadataKey.BYPASS_LOGGING */, true, target, propertyKey); | ||
} | ||
@@ -11,3 +11,3 @@ exports.AutoLogPropBypass = AutoLogPropBypass; | ||
return function _loglevel(target, propertyKey) { | ||
Reflect.defineMetadata("LOG_LEVEL" /* LOG_LEVEL */, level, target, propertyKey); | ||
Reflect.defineMetadata("LOG_LEVEL" /* MetadataKey.LOG_LEVEL */, level, target, propertyKey); | ||
}; | ||
@@ -14,0 +14,0 @@ } |
{ | ||
"name": "autoreggol", | ||
"version": "0.3.0", | ||
"version": "0.3.1-next", | ||
"description": "A collection of handy auto logging decorators.", | ||
@@ -27,3 +27,3 @@ "author": "Ronnie Magatti <ronniemagatti@gmail.com>", | ||
"engines": { | ||
"node": ">=10.0.0" | ||
"node": ">=18.0.0" | ||
}, | ||
@@ -35,3 +35,5 @@ "scripts": { | ||
"prepublishOnly": "rimraf build && tsc", | ||
"test": "NODE_ENV=test vitest", | ||
"test": "NODE_ENV=test vitest run && jest", | ||
"test-vitest": "NODE_ENV=test vitest run", | ||
"test-jest": "NODE_ENV=test jest", | ||
"coverage": "NODE_ENV=test vitest run --coverage" | ||
@@ -49,6 +51,13 @@ }, | ||
"devDependencies": { | ||
"@types/jest": "^29.4.0", | ||
"@typescript-eslint/eslint-plugin": "^5.52.0", | ||
"@typescript-eslint/parser": "^5.52.0", | ||
"eslint": "^8.34.0", | ||
"jest": "^29.4.3", | ||
"ts-jest": "^29.0.5", | ||
"ts-node": "^10.9.1", | ||
"ts-node-dev": "^1.1.1", | ||
"typescript": "^4.2.2", | ||
"vitest": "^0.23.4" | ||
"typescript": "^4.9.5", | ||
"vitest": "^0.28.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15383
147
10