@graphql-markdown/logger 1.0.5 → 1.0.7

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Logger singleton module.
3
3
  *
4
+ * @module Logger
4
5
  * @packageDocumentation
5
6
  */
6
7
  import type { LoggerType, Maybe } from "@graphql-markdown/types";
@@ -8,7 +9,11 @@ declare global {
8
9
  var logger: Maybe<LoggerType>;
9
10
  }
10
11
  /**
11
- * Log levels.
12
+ * Log levels supported by the logger.
13
+ *
14
+ * @remarks
15
+ * The logger supports standard console methods plus custom 'success' level
16
+ * for framework-specific integrations like Docusaurus.
12
17
  *
13
18
  */
14
19
  export declare enum LogLevel {
@@ -21,13 +26,13 @@ export declare enum LogLevel {
21
26
  }
22
27
  /**
23
28
  * Instantiate a logger module.
24
- * By default, the logger module uses `global.console`
29
+ * By default, the logger module uses `globalThis.console`
25
30
  *
26
31
  * @param moduleName - optional name of the logger package.
27
32
  *
28
33
  * @example
29
34
  * ```js
30
- * import Logger, { log } from "@graphql-markdown/utils/logger";
35
+ * import Logger, { log } from "@graphql-markdown/logger";
31
36
  *
32
37
  * log("Info message"); // Expected console output "Info message"
33
38
  *
@@ -48,12 +53,26 @@ export declare const Logger: (moduleName?: string) => Promise<void>;
48
53
  *
49
54
  * @example
50
55
  * ```js
51
- * import { log } from "@graphql-markdown/utils/logger";
56
+ * import { log } from "@graphql-markdown/logger";
52
57
  *
53
58
  * log("Info message"); // Expected console output "Info message"
54
59
  * ```
55
60
  *
56
61
  */
57
62
  export declare const log: (message: string, level?: LogLevel | keyof typeof LogLevel) => void;
63
+ /**
64
+ * Internal helpers exported for testing purposes only.
65
+ * Not part of the public API — do not use in application code.
66
+ *
67
+ * @internal
68
+ */
69
+ export declare const __internal: {
70
+ hasLogMethod: (instance: unknown, level: LogLevel | keyof typeof LogLevel) => instance is Record<string, (...args: unknown[]) => unknown>;
71
+ resolveLoggerInstance: (instance: unknown) => LoggerType["instance"] | undefined;
72
+ };
73
+ /**
74
+ * @see log
75
+ */
58
76
  /** @alias */
59
77
  export default Logger;
78
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,oBAAY,QAAQ;IAClB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAgED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,MAAM,gBAAuB,MAAM,KAAG,OAAO,CAAC,IAAI,CAsC9D,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,GAAG,YACL,MAAM,UAER,QAAQ,GAAG,MAAM,OAAO,QAAQ,KACtC,IAGF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU;6BA/IX,OAAO,SACV,QAAQ,GAAG,MAAM,OAAO,QAAQ,KACtC,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;sCAqBlD,OAAO,KAChB,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS;CAuH4B,CAAC;AAElE;;GAEG;AACH,aAAa;eACE,MAAM"}
package/dist/index.js CHANGED
@@ -1,36 +1,19 @@
1
1
  "use strict";
2
+ // index.ts
2
3
  /**
3
4
  * Logger singleton module.
4
5
  *
6
+ * @module Logger
5
7
  * @packageDocumentation
6
8
  */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || function (mod) {
24
- if (mod && mod.__esModule) return mod;
25
- var result = {};
26
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
- __setModuleDefault(result, mod);
28
- return result;
29
- };
30
9
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.log = exports.Logger = exports.LogLevel = void 0;
10
+ exports.__internal = exports.log = exports.Logger = exports.LogLevel = void 0;
32
11
  /**
33
- * Log levels.
12
+ * Log levels supported by the logger.
13
+ *
14
+ * @remarks
15
+ * The logger supports standard console methods plus custom 'success' level
16
+ * for framework-specific integrations like Docusaurus.
34
17
  *
35
18
  */
36
19
  var LogLevel;
@@ -42,15 +25,61 @@ var LogLevel;
42
25
  LogLevel["success"] = "success";
43
26
  LogLevel["warn"] = "warn";
44
27
  })(LogLevel || (exports.LogLevel = LogLevel = {}));
28
+ /**
29
+ * Type guard to check if an object has a log method for a given level.
30
+ *
31
+ * @param instance - The object to check
32
+ * @param level - The log level to verify
33
+ * @returns `true` if the instance has a function at the given level, `false` otherwise
34
+ */
35
+ const hasLogMethod = (instance, level) => {
36
+ return (typeof instance === "object" &&
37
+ instance !== null &&
38
+ typeof instance[level] === "function");
39
+ };
40
+ /**
41
+ * Resolve a logger instance from a module export.
42
+ *
43
+ * @remarks
44
+ * Handles various module export patterns:
45
+ * - Direct logger instance: `{ info: () => {}, ... }`
46
+ * - Default export: `{ default: { info: () => {}, ... } }`
47
+ * - Named export: `{ logger: { info: () => {}, ... } }`
48
+ *
49
+ * @param instance - The module export or object to resolve
50
+ * @returns The logger instance if found, or `undefined` if no valid logger is detected (the caller is responsible for falling back to `globalThis.console`)
51
+ */
52
+ const resolveLoggerInstance = (instance) => {
53
+ if (hasLogMethod(instance, LogLevel.info)) {
54
+ return instance;
55
+ }
56
+ if (typeof instance === "object" &&
57
+ instance !== null &&
58
+ "default" in instance) {
59
+ const nestedDefault = instance.default;
60
+ if (hasLogMethod(nestedDefault, LogLevel.info)) {
61
+ return nestedDefault;
62
+ }
63
+ }
64
+ if (typeof instance === "object" &&
65
+ instance !== null &&
66
+ "logger" in instance) {
67
+ const nestedLogger = instance.logger;
68
+ if (hasLogMethod(nestedLogger, LogLevel.info)) {
69
+ return nestedLogger;
70
+ }
71
+ }
72
+ return undefined;
73
+ };
45
74
  /**
46
75
  * Instantiate a logger module.
47
- * By default, the logger module uses `global.console`
76
+ * By default, the logger module uses `globalThis.console`
48
77
  *
49
78
  * @param moduleName - optional name of the logger package.
50
79
  *
51
80
  * @example
52
81
  * ```js
53
- * import Logger, { log } from "@graphql-markdown/utils/logger";
82
+ * import Logger, { log } from "@graphql-markdown/logger";
54
83
  *
55
84
  * log("Info message"); // Expected console output "Info message"
56
85
  *
@@ -60,18 +89,29 @@ var LogLevel;
60
89
  *
61
90
  */
62
91
  const Logger = async (moduleName) => {
63
- if (global.logger?.instance && typeof moduleName === "undefined") {
92
+ if (globalThis.logger?.instance && moduleName === undefined) {
64
93
  return;
65
94
  }
66
- const instance = typeof moduleName === "string" && moduleName !== ""
67
- ? (await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)))).default
68
- : global.console;
95
+ const moduleExports = typeof moduleName === "string" && moduleName !== ""
96
+ ? await import(moduleName)
97
+ : undefined;
98
+ const instance = resolveLoggerInstance(moduleExports) ??
99
+ resolveLoggerInstance(moduleExports?.default) ??
100
+ globalThis.console;
101
+ const getCallbackForLevel = (instanceObj, requestedLevel) => {
102
+ if (hasLogMethod(instanceObj, requestedLevel)) {
103
+ return instanceObj[requestedLevel];
104
+ }
105
+ if (hasLogMethod(instanceObj, LogLevel.info)) {
106
+ return instanceObj[LogLevel.info];
107
+ }
108
+ return undefined;
109
+ };
69
110
  const _log = (message, level = LogLevel.info) => {
70
- const fallback = instance[LogLevel.info];
71
- const callback = typeof instance[level] === "function" ? instance[level] : fallback;
111
+ const callback = getCallbackForLevel(instance, level);
72
112
  callback?.apply(this, [message]);
73
113
  };
74
- global.logger = { instance, _log };
114
+ globalThis.logger = { instance, _log };
75
115
  };
76
116
  exports.Logger = Logger;
77
117
  /**
@@ -85,18 +125,26 @@ exports.Logger = Logger;
85
125
  *
86
126
  * @example
87
127
  * ```js
88
- * import { log } from "@graphql-markdown/utils/logger";
128
+ * import { log } from "@graphql-markdown/logger";
89
129
  *
90
130
  * log("Info message"); // Expected console output "Info message"
91
131
  * ```
92
132
  *
93
133
  */
94
134
  const log = (message, level = LogLevel.info) => {
95
- new Promise((resolve) => {
96
- resolve((0, exports.Logger)());
97
- }).catch(() => { });
98
- global.logger?._log(message, level);
135
+ Promise.resolve((0, exports.Logger)()).catch(() => { });
136
+ globalThis.logger?._log(message, level);
99
137
  };
100
138
  exports.log = log;
139
+ /**
140
+ * Internal helpers exported for testing purposes only.
141
+ * Not part of the public API — do not use in application code.
142
+ *
143
+ * @internal
144
+ */
145
+ exports.__internal = { hasLogMethod, resolveLoggerInstance };
146
+ /**
147
+ * @see log
148
+ */
101
149
  /** @alias */
102
150
  exports.default = exports.Logger;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "bugs": {
6
6
  "url": "https://github.com/graphql-markdown/graphql-markdown/issues"
7
7
  },
8
- "version": "1.0.5",
8
+ "version": "1.0.7",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -35,23 +35,35 @@
35
35
  "./package.json": "./package.json"
36
36
  },
37
37
  "scripts": {
38
- "prepack": "pinst --disable",
39
- "postpack": "pinst --enable",
40
38
  "stryker": "stryker run",
41
- "clean": "rm -rf ./dist",
42
- "docs": "typedoc"
39
+ "clean": "tsgo --build --clean && rm -rf ./dist",
40
+ "docs": "typedoc --options typedoc.config.mjs",
41
+ "build": "tsgo --build",
42
+ "lint": "eslint --config ../../packages/tooling-config/eslint/config.ts \"{src,tests}/**/*.{ts,js,json,gql}\"",
43
+ "lint:fix": "eslint --config ../../packages/tooling-config/eslint/config.ts \"{src,tests}/**/*.{ts,js,json,gql}\" --fix",
44
+ "prettier": "prettier \"{src,tests,assets}/**/*.{ts,js,json,md,gql}\" --check",
45
+ "prettier:fix": "prettier \"{src,tests,assets}/**/*.{ts,js,json,md,gql}\" --write",
46
+ "ts:check": "tsgo --noEmit",
47
+ "test": "jest",
48
+ "test:unit": "jest --passWithNoTests --testPathPatterns=tests/unit",
49
+ "test:integration": "jest --passWithNoTests --testPathPatterns=tests/integration",
50
+ "test:ci": "jest --passWithNoTests --ci --silent --randomize --runInBand",
51
+ "test:watch": "jest --watch"
52
+ },
53
+ "dependencies": {
54
+ "@graphql-markdown/types": "^1.13.0"
43
55
  },
44
56
  "devDependencies": {
45
- "@graphql-markdown/types": "^1.4.0"
57
+ "@docusaurus/logger": "*",
58
+ "@graphql-markdown/tooling-config": "^1.0.0"
46
59
  },
47
60
  "directories": {
48
61
  "test": "tests"
49
62
  },
50
63
  "engines": {
51
- "node": ">=16.14"
64
+ "node": ">=20"
52
65
  },
53
66
  "publishConfig": {
54
- "directory": "dist",
55
67
  "access": "public"
56
68
  },
57
69
  "typescript": {