@tstdl/base 0.85.24 → 0.85.25
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/decorators/log.js +16 -12
- package/package.json +1 -1
package/decorators/log.js
CHANGED
|
@@ -25,27 +25,31 @@ var import_log = require("../function/log.js");
|
|
|
25
25
|
var import_utils = require("../reflection/utils.js");
|
|
26
26
|
var import_object = require("../utils/object/object.js");
|
|
27
27
|
var import_type_guards = require("../utils/type-guards.js");
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return wrapped;
|
|
28
|
+
const wrappedStaticMethods = /* @__PURE__ */ new WeakMap();
|
|
29
|
+
const wrappedInstanceMethods = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
function isWrapped(constructor, property, isStatic) {
|
|
31
|
+
return (isStatic ? wrappedStaticMethods : wrappedInstanceMethods).get(constructor)?.has(property) ?? false;
|
|
33
32
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
33
|
+
function setWrapped(constructor, property, isStatic) {
|
|
34
|
+
const map = isStatic ? wrappedStaticMethods : wrappedInstanceMethods;
|
|
35
|
+
if (!map.has(constructor)) {
|
|
36
|
+
map.set(constructor, /* @__PURE__ */ new Set());
|
|
37
|
+
}
|
|
38
|
+
map.get(constructor).add(property);
|
|
36
39
|
}
|
|
37
40
|
function Log() {
|
|
38
41
|
return (0, import_utils.createDecorator)({ class: true, method: true }, (data) => {
|
|
39
42
|
if (data.type == "method") {
|
|
40
|
-
|
|
43
|
+
setWrapped(data.constructor, data.methodKey, data.static);
|
|
44
|
+
return { value: (0, import_log.wrapLog)(data.descriptor.value) };
|
|
41
45
|
}
|
|
42
|
-
const staticProperties = (0, import_object.objectKeys)(data.constructor).filter((property) => property != "length" && property != "name" && property != "prototype" && (0, import_type_guards.isFunction)(data.constructor[property]) && !isWrapped(data.constructor
|
|
43
|
-
const instanceProperties = (0, import_object.objectKeys)(data.prototype).filter((property) => property != "constructor" && (0, import_type_guards.isFunction)(data.prototype[property]) && !isWrapped(data.
|
|
46
|
+
const staticProperties = (0, import_object.objectKeys)(data.constructor).filter((property) => property != "length" && property != "name" && property != "prototype" && (0, import_type_guards.isFunction)(data.constructor[property]) && !isWrapped(data.constructor, property, true));
|
|
47
|
+
const instanceProperties = (0, import_object.objectKeys)(data.prototype).filter((property) => property != "constructor" && (0, import_type_guards.isFunction)(data.prototype[property]) && !isWrapped(data.constructor, property, false));
|
|
44
48
|
for (const property of staticProperties) {
|
|
45
|
-
data.constructor[property] =
|
|
49
|
+
data.constructor[property] = (0, import_log.wrapLog)(data.constructor[property], property);
|
|
46
50
|
}
|
|
47
51
|
for (const property of instanceProperties) {
|
|
48
|
-
data.prototype[property] =
|
|
52
|
+
data.prototype[property] = (0, import_log.wrapLog)(data.prototype[property], property);
|
|
49
53
|
}
|
|
50
54
|
return void 0;
|
|
51
55
|
});
|