@graphql-markdown/core 1.17.1 → 1.18.0
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/event-emitter.d.ts +2 -2
- package/dist/event-emitter.d.ts.map +1 -1
- package/dist/event-emitter.js +19 -9
- package/dist/event-handlers.d.ts.map +1 -1
- package/dist/event-handlers.js +9 -3
- package/dist/events/base.d.ts +2 -2
- package/dist/events/base.d.ts.map +1 -1
- package/dist/generator.d.ts +12 -0
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +36 -12
- package/package.json +9 -9
package/dist/event-emitter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ICancellableEvent, PrinterEvent } from "@graphql-markdown/types";
|
|
3
3
|
/**
|
|
4
4
|
* Result object returned when emitting a cancellable event.
|
|
5
5
|
*
|
|
@@ -61,7 +61,7 @@ declare class CancellableEventEmitter extends EventEmitter {
|
|
|
61
61
|
* }
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
|
-
emitAsync(eventName: string, event:
|
|
64
|
+
emitAsync(eventName: string, event: ICancellableEvent | PrinterEvent): Promise<EmitResult>;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Get the singleton event emitter instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../src/event-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../src/event-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE/E;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB;;;OAGG;IACH,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,cAAM,uBAAwB,SAAQ,YAAY;IAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,SAAS,CACb,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,iBAAiB,GAAG,YAAY,GACtC,OAAO,CAAC,UAAU,CAAC,CAiDrB;CACF;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,SAAS,+BAGrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,YAKvB,CAAC"}
|
package/dist/event-emitter.js
CHANGED
|
@@ -50,13 +50,17 @@ class CancellableEventEmitter extends node_events_1.EventEmitter {
|
|
|
50
50
|
const errors = [];
|
|
51
51
|
// Get all registered listeners for this event
|
|
52
52
|
const listeners = this.listeners(eventName);
|
|
53
|
+
// Check if event is a full cancellable event (has propagationStopped property)
|
|
54
|
+
const isCancellable = "propagationStopped" in event;
|
|
53
55
|
// Execute each handler sequentially
|
|
54
56
|
for (const listener of listeners) {
|
|
55
57
|
try {
|
|
56
58
|
// Call the handler - await to support async handlers
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
57
60
|
await listener(event);
|
|
58
61
|
// Check if handler stopped propagation to remaining handlers
|
|
59
|
-
if (
|
|
62
|
+
if (isCancellable &&
|
|
63
|
+
event.propagationStopped) {
|
|
60
64
|
break; // Exit the loop, skipping remaining handlers
|
|
61
65
|
}
|
|
62
66
|
}
|
|
@@ -66,15 +70,21 @@ class CancellableEventEmitter extends node_events_1.EventEmitter {
|
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
// Execute default action if not prevented and event has one
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
if ("runDefaultAction" in event) {
|
|
74
|
+
try {
|
|
75
|
+
// Call defaultAction - await to support async
|
|
76
|
+
await event.runDefaultAction();
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
// Collect error from default action
|
|
80
|
+
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
81
|
+
}
|
|
76
82
|
}
|
|
77
|
-
|
|
83
|
+
// Check defaultPrevented - simple events may have this property
|
|
84
|
+
const defaultPrevented = "defaultPrevented" in event
|
|
85
|
+
? !!event.defaultPrevented
|
|
86
|
+
: false;
|
|
87
|
+
return { errors, defaultPrevented };
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handlers.d.ts","sourceRoot":"","sources":["../src/event-handlers.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"event-handlers.d.ts","sourceRoot":"","sources":["../src/event-handlers.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,wBAAwB,8BAwCpC,CAAC"}
|
package/dist/event-handlers.js
CHANGED
|
@@ -40,12 +40,18 @@ const registerMDXEventHandlers = (mdxModule) => {
|
|
|
40
40
|
(0, event_emitter_1.resetEvents)(); // reset event to avoid duplicate registrations
|
|
41
41
|
const events = (0, event_emitter_1.getEvents)();
|
|
42
42
|
const registeredHandlers = new Set();
|
|
43
|
+
// Get the actual module object, handling ESM default export wrapping
|
|
44
|
+
// When using dynamic import() on a CommonJS module, exports may be under .default
|
|
45
|
+
const module = mdxModule;
|
|
46
|
+
const effectiveModule = module.default && typeof module.default === "object"
|
|
47
|
+
? module.default
|
|
48
|
+
: module;
|
|
43
49
|
// Iterate through event callback mappings (lifecycle hooks only)
|
|
44
50
|
for (const [eventName, callbackName] of Object.entries(event_map_1.EVENT_CALLBACK_MAP)) {
|
|
45
51
|
// Check if mdxModule has this callback function
|
|
46
|
-
if (callbackName in
|
|
47
|
-
typeof
|
|
48
|
-
const mdxFunction =
|
|
52
|
+
if (callbackName in effectiveModule &&
|
|
53
|
+
typeof effectiveModule[callbackName] === "function") {
|
|
54
|
+
const mdxFunction = effectiveModule[callbackName];
|
|
49
55
|
events.on(eventName, mdxFunction);
|
|
50
56
|
registeredHandlers.add(callbackName);
|
|
51
57
|
}
|
package/dist/events/base.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
|
-
import type { DefaultAction } from "@graphql-markdown/types";
|
|
6
|
+
import type { DefaultAction, ICancellableEvent } from "@graphql-markdown/types";
|
|
7
7
|
/**
|
|
8
8
|
* Deep freezes an object to make it immutable at runtime.
|
|
9
9
|
* Recursively freezes all nested objects and arrays.
|
|
@@ -34,7 +34,7 @@ export interface CancellableEventOptions {
|
|
|
34
34
|
*
|
|
35
35
|
* @category Events
|
|
36
36
|
*/
|
|
37
|
-
export declare abstract class CancellableEvent {
|
|
37
|
+
export declare abstract class CancellableEvent implements ICancellableEvent {
|
|
38
38
|
/**
|
|
39
39
|
* Whether the default action has been prevented.
|
|
40
40
|
* Set to true when preventDefault() is called.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/events/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/events/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEhF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,+CAc3B,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;;;;GAUG;AACH,8BAAsB,gBAAiB,YAAW,iBAAiB;IACjE;;;OAGG;IACH,OAAO,CAAC,iBAAiB,CAAS;IAElC;;;OAGG;IACH,OAAO,CAAC,mBAAmB,CAAS;IAEpC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IAEvC;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAgB;IAEhD;;;;;;OAMG;IACH,YAAY,OAAO,CAAC,EAAE,uBAAuB,EAG5C;IAED;;OAEG;IACH,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAED;;OAEG;IACH,IAAI,kBAAkB,IAAI,OAAO,CAEhC;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,aAAa,GAAG,SAAS,CAE7C;IAED;;;;;;;;;;;;;OAaG;IACH,cAAc,IAAI,IAAI,CAIrB;IAED;;;;;;;;;;;;OAYG;IACH,eAAe,IAAI,IAAI,CAEtB;IAED;;;;;;;;;OASG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAKtC;CACF"}
|
package/dist/generator.d.ts
CHANGED
|
@@ -30,6 +30,18 @@ export declare const FILE_EXTENSION: {
|
|
|
30
30
|
* @internal
|
|
31
31
|
*/
|
|
32
32
|
export declare const loadMDXModule: (mdxParser: Maybe<string | PackageName>) => Promise<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Gets a property from an MDX module, checking both the module directly and `module.default`.
|
|
35
|
+
*
|
|
36
|
+
* This handles the differences between ESM and CommonJS module exports when dynamically importing.
|
|
37
|
+
*
|
|
38
|
+
* @param mdxModule - The loaded MDX module
|
|
39
|
+
* @param propertyName - The name of the property to extract
|
|
40
|
+
* @returns The property value if found, otherwise undefined
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export declare const getMDXModuleProperty: <T>(mdxModule: unknown, propertyName: string) => T | undefined;
|
|
33
45
|
/**
|
|
34
46
|
* Extracts a formatter from an MDX module.
|
|
35
47
|
*
|
package/dist/generator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAEV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,WAAW,EAEX,cAAc,EAEf,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAEV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,WAAW,EAEX,cAAc,EAEf,MAAM,yBAAyB,CAAC;AA+BjC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;CAGjB,CAAC;AAgBX;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,8DAczB,CAAC;AAgBF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,4DAsBrC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,yEAkDrC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,6FAe7B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,wHAgBlC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,4BAA4B,qKA0BxC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,qUAuNjC,CAAC"}
|
package/dist/generator.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.generateDocFromSchema = exports.resolveSkipAndOnlyDirectives = exports.checkSchemaDifferences = exports.loadGraphqlSchema = exports.getFormatterFromMDXModule = exports.loadMDXModule = exports.FILE_EXTENSION = void 0;
|
|
36
|
+
exports.generateDocFromSchema = exports.resolveSkipAndOnlyDirectives = exports.checkSchemaDifferences = exports.loadGraphqlSchema = exports.getFormatterFromMDXModule = exports.getMDXModuleProperty = exports.loadMDXModule = exports.FILE_EXTENSION = void 0;
|
|
37
37
|
const logger_1 = __importStar(require("@graphql-markdown/logger"));
|
|
38
38
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
39
39
|
const utils_1 = require("@graphql-markdown/utils");
|
|
@@ -80,9 +80,9 @@ const SEC_DECIMALS = 3;
|
|
|
80
80
|
*/
|
|
81
81
|
const loadMDXModule = async (mdxParser) => {
|
|
82
82
|
return mdxParser !== undefined && mdxParser !== null
|
|
83
|
-
? Promise.resolve(`${mdxParser}`).then(s => __importStar(require(s))).catch((
|
|
84
|
-
const errorMessage =
|
|
85
|
-
(0, logger_1.log)(`An error occurred while loading MDX formatter "${mdxParser}"
|
|
83
|
+
? Promise.resolve(`${mdxParser}`).then(s => __importStar(require(s))).catch((error) => {
|
|
84
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
85
|
+
(0, logger_1.log)(`An error occurred while loading MDX formatter "${mdxParser}": ${errorMessage}`, logger_1.LogLevel.warn);
|
|
86
86
|
return undefined;
|
|
87
87
|
})
|
|
88
88
|
: undefined;
|
|
@@ -101,6 +101,34 @@ const FORMATTER_FUNCTION_NAMES = [
|
|
|
101
101
|
"formatMDXNameEntity",
|
|
102
102
|
"formatMDXSpecifiedByLink",
|
|
103
103
|
];
|
|
104
|
+
/**
|
|
105
|
+
* Gets a property from an MDX module, checking both the module directly and `module.default`.
|
|
106
|
+
*
|
|
107
|
+
* This handles the differences between ESM and CommonJS module exports when dynamically importing.
|
|
108
|
+
*
|
|
109
|
+
* @param mdxModule - The loaded MDX module
|
|
110
|
+
* @param propertyName - The name of the property to extract
|
|
111
|
+
* @returns The property value if found, otherwise undefined
|
|
112
|
+
*
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
const getMDXModuleProperty = (mdxModule, propertyName) => {
|
|
116
|
+
if (!mdxModule || typeof mdxModule !== "object") {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
const module = mdxModule;
|
|
120
|
+
// Check for property directly on the module
|
|
121
|
+
if (propertyName in module) {
|
|
122
|
+
return module[propertyName];
|
|
123
|
+
}
|
|
124
|
+
// Check for property on module.default (ESM default export)
|
|
125
|
+
const defaultExport = module.default;
|
|
126
|
+
if (defaultExport && propertyName in defaultExport) {
|
|
127
|
+
return defaultExport[propertyName];
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
};
|
|
131
|
+
exports.getMDXModuleProperty = getMDXModuleProperty;
|
|
104
132
|
/**
|
|
105
133
|
* Extracts a formatter from an MDX module.
|
|
106
134
|
*
|
|
@@ -281,9 +309,7 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
|
|
|
281
309
|
// Extract formatter from the MDX module (for direct function calls)
|
|
282
310
|
const formatter = (0, exports.getFormatterFromMDXModule)(mdxModule, docOptions);
|
|
283
311
|
// Extract mdxDeclaration from the MDX module (if available)
|
|
284
|
-
const mdxDeclaration =
|
|
285
|
-
? mdxModule.mdxDeclaration
|
|
286
|
-
: undefined;
|
|
312
|
+
const mdxDeclaration = (0, exports.getMDXModuleProperty)(mdxModule, "mdxDeclaration");
|
|
287
313
|
const printer = await (0, printer_1.getPrinter)(
|
|
288
314
|
// module mandatory
|
|
289
315
|
printerModule,
|
|
@@ -309,12 +335,10 @@ const generateDocFromSchema = async ({ baseURL, customDirective, diffMethod, doc
|
|
|
309
335
|
// Pass event emitter to enable print events
|
|
310
336
|
events);
|
|
311
337
|
// allow mdxModule to specify custom extension
|
|
338
|
+
const mdxExtensionFromModule = (0, exports.getMDXModuleProperty)(mdxModule, "mdxExtension");
|
|
312
339
|
let mdxExtension;
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
"mdxExtension" in mdxModule) {
|
|
316
|
-
mdxExtension = mdxModule
|
|
317
|
-
.mdxExtension;
|
|
340
|
+
if (mdxExtensionFromModule) {
|
|
341
|
+
mdxExtension = mdxExtensionFromModule;
|
|
318
342
|
}
|
|
319
343
|
else if (mdxModule) {
|
|
320
344
|
mdxExtension = exports.FILE_EXTENSION.MDX;
|
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.
|
|
8
|
+
"version": "1.18.0",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -63,18 +63,18 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@fastify/deepmerge": "^3.2.0",
|
|
66
|
-
"@graphql-markdown/graphql": "
|
|
67
|
-
"@graphql-markdown/logger": "
|
|
68
|
-
"@graphql-markdown/utils": "
|
|
66
|
+
"@graphql-markdown/graphql": "workspace:^",
|
|
67
|
+
"@graphql-markdown/logger": "workspace:^",
|
|
68
|
+
"@graphql-markdown/utils": "workspace:^"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@graphql-markdown/diff": "
|
|
72
|
-
"@graphql-markdown/helpers": "
|
|
73
|
-
"@graphql-markdown/printer-legacy": "
|
|
74
|
-
"graphql-config": "
|
|
71
|
+
"@graphql-markdown/diff": "workspace:^",
|
|
72
|
+
"@graphql-markdown/helpers": "workspace:^",
|
|
73
|
+
"@graphql-markdown/printer-legacy": "workspace:^",
|
|
74
|
+
"graphql-config": "catalog:"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@graphql-markdown/types": "
|
|
77
|
+
"@graphql-markdown/types": "workspace:^"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"@graphql-markdown/printer-legacy": {
|