@tstdl/base 0.85.22 → 0.85.23

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.
@@ -0,0 +1 @@
1
+ export * from './log.js';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var decorators_exports = {};
17
+ module.exports = __toCommonJS(decorators_exports);
18
+ __reExport(decorators_exports, require("./log.js"), module.exports);
@@ -0,0 +1,2 @@
1
+ import type { Decorator } from '../reflection/types.js';
2
+ export declare function Log(): Decorator<'class' | 'method'>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var log_exports = {};
20
+ __export(log_exports, {
21
+ Log: () => Log
22
+ });
23
+ module.exports = __toCommonJS(log_exports);
24
+ var import_log = require("../function/log.js");
25
+ var import_registry = require("../reflection/registry.js");
26
+ var import_utils = require("../reflection/utils.js");
27
+ var import_object = require("../utils/object/object.js");
28
+ var import_type_guards = require("../utils/type-guards.js");
29
+ const logWrapped = Symbol("logged wrapped");
30
+ function Log() {
31
+ return (0, import_utils.createDecorator)({ class: true, method: true }, (data, metadata) => {
32
+ if (metadata.data.has(logWrapped)) {
33
+ return void 0;
34
+ }
35
+ metadata.data.set(logWrapped, true);
36
+ if (data.type == "method") {
37
+ return { value: (0, import_log.wrapLog)(data.descriptor.value) };
38
+ }
39
+ const staticProperties = (0, import_object.objectKeys)(data.constructor).filter((property) => property != "length" && property != "name" && property != "prototype" && (0, import_type_guards.isFunction)(data.constructor[property]) && !(import_registry.reflectionRegistry.getMetadata(data.constructor)?.staticMethods.get(property)?.data.has(logWrapped) ?? false));
40
+ const instanceProperties = (0, import_object.objectKeys)(data.prototype).filter((property) => property != "constructor" && (0, import_type_guards.isFunction)(data.prototype[property]) && !(import_registry.reflectionRegistry.getMetadata(data.constructor)?.methods.get(property)?.data.has(logWrapped) ?? false));
41
+ for (const property of staticProperties) {
42
+ data.constructor[property] = (0, import_log.wrapLog)(data.constructor[property], property);
43
+ }
44
+ for (const property of instanceProperties) {
45
+ data.prototype[property] = (0, import_log.wrapLog)(data.prototype[property], property);
46
+ }
47
+ return void 0;
48
+ });
49
+ }
@@ -0,0 +1 @@
1
+ export * from './log.js';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var function_exports = {};
17
+ module.exports = __toCommonJS(function_exports);
18
+ __reExport(function_exports, require("./log.js"), module.exports);
@@ -0,0 +1,6 @@
1
+ import type { Logger } from '../logger/logger.js';
2
+ export type WrapLogOptions = {
3
+ fnName?: string;
4
+ logger?: Logger;
5
+ };
6
+ export declare function wrapLog(fn: Function, options?: WrapLogOptions): Function;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var log_exports = {};
20
+ __export(log_exports, {
21
+ wrapLog: () => wrapLog
22
+ });
23
+ module.exports = __toCommonJS(log_exports);
24
+ var import_type_guards = require("../utils/type-guards.js");
25
+ var import_type_of = require("../utils/type-of.js");
26
+ function wrapLog(fn, options) {
27
+ const fnName = options?.fnName ?? fn.name;
28
+ const log = options?.logger?.trace.bind(options.logger) ?? console.log.bind(console);
29
+ const wrapped = {
30
+ [fnName](...args) {
31
+ const argString = args.map((arg) => (0, import_type_guards.isPrimitive)(arg) ? arg : (0, import_type_of.typeOf)(arg)).join(", ");
32
+ log(`[call: ${fnName}(${argString})]`);
33
+ return Reflect.apply(fn, this, args);
34
+ }
35
+ };
36
+ return wrapped[fnName];
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.85.22",
3
+ "version": "0.85.23",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"