cls-proxify
Version:
Logging on steroids with CLS and Proxy. Integrated with express, koa, fastify.
34 lines (33 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.clsProxify = void 0;
const cls_1 = require("./cls");
exports.clsProxify = (targetToProxify) => {
const proxified = new Proxy(targetToProxify, {
get(target, property, receiver) {
target = cls_1.getClsHookedStorage().get() || target;
return Reflect.get(target, property, receiver);
},
apply(target, thisArg, args) {
target = cls_1.getClsHookedStorage().get() || target;
return Reflect.apply(target, thisArg, args);
},
construct(target, args) {
target = cls_1.getClsHookedStorage().get() || target;
return Reflect.construct(target, args);
},
has(target, key) {
target = cls_1.getClsHookedStorage().get() || target;
return Reflect.has(target, key);
},
ownKeys(target) {
target = cls_1.getClsHookedStorage().get() || target;
return Reflect.ownKeys(target);
},
getOwnPropertyDescriptor(target, key) {
target = cls_1.getClsHookedStorage().get() || target;
return Reflect.getOwnPropertyDescriptor(target, key);
},
});
return proxified;
};