@graphql-markdown/core 1.16.3 → 1.17.1
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/config.d.ts +17 -55
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +80 -89
- package/dist/const/patterns.d.ts +114 -0
- package/dist/const/patterns.d.ts.map +1 -0
- package/dist/const/patterns.js +116 -0
- package/dist/diff.d.ts +1 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/directives/normalize.d.ts +79 -0
- package/dist/directives/normalize.d.ts.map +1 -0
- package/dist/directives/normalize.js +91 -0
- package/dist/directives/validation.d.ts +146 -0
- package/dist/directives/validation.d.ts.map +1 -0
- package/dist/directives/validation.js +188 -0
- package/dist/event-emitter.d.ts +109 -0
- package/dist/event-emitter.d.ts.map +1 -0
- package/dist/event-emitter.js +136 -0
- package/dist/event-handlers.d.ts +22 -0
- package/dist/event-handlers.d.ts.map +1 -0
- package/dist/event-handlers.js +57 -0
- package/dist/event-map.d.ts +26 -0
- package/dist/event-map.d.ts.map +1 -0
- package/dist/event-map.js +43 -0
- package/dist/events/base.d.ts +119 -0
- package/dist/events/base.d.ts.map +1 -0
- package/dist/events/base.js +149 -0
- package/dist/events/diff-check.d.ts +25 -0
- package/dist/events/diff-check.d.ts.map +1 -0
- package/dist/events/diff-check.js +23 -0
- package/dist/events/diff-events.d.ts +15 -0
- package/dist/events/diff-events.d.ts.map +1 -0
- package/dist/events/diff-events.js +17 -0
- package/dist/events/generate-index-metafile-events.d.ts +15 -0
- package/dist/events/generate-index-metafile-events.d.ts.map +1 -0
- package/dist/events/generate-index-metafile-events.js +17 -0
- package/dist/events/generate-index-metafile.d.ts +25 -0
- package/dist/events/generate-index-metafile.d.ts.map +1 -0
- package/dist/events/generate-index-metafile.js +23 -0
- package/dist/events/index.d.ts +22 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +43 -0
- package/dist/events/print-type-events.d.ts +33 -0
- package/dist/events/print-type-events.d.ts.map +1 -0
- package/dist/events/print-type-events.js +35 -0
- package/dist/events/print-type.d.ts +84 -0
- package/dist/events/print-type.d.ts.map +1 -0
- package/dist/events/print-type.js +73 -0
- package/dist/events/render-homepage-events.d.ts +15 -0
- package/dist/events/render-homepage-events.d.ts.map +1 -0
- package/dist/events/render-homepage-events.js +17 -0
- package/dist/events/render-homepage.d.ts +21 -0
- package/dist/events/render-homepage.d.ts.map +1 -0
- package/dist/events/render-homepage.js +23 -0
- package/dist/events/render-root-types-events.d.ts +15 -0
- package/dist/events/render-root-types-events.d.ts.map +1 -0
- package/dist/events/render-root-types-events.js +17 -0
- package/dist/events/render-root-types.d.ts +21 -0
- package/dist/events/render-root-types.d.ts.map +1 -0
- package/dist/events/render-root-types.js +23 -0
- package/dist/events/render-type-entities-events.d.ts +15 -0
- package/dist/events/render-type-entities-events.d.ts.map +1 -0
- package/dist/events/render-type-entities-events.js +17 -0
- package/dist/events/render-type-entities.d.ts +23 -0
- package/dist/events/render-type-entities.d.ts.map +1 -0
- package/dist/events/render-type-entities.js +23 -0
- package/dist/events/schema-events.d.ts +19 -0
- package/dist/events/schema-events.d.ts.map +1 -0
- package/dist/events/schema-events.js +21 -0
- package/dist/events/schema-load.d.ts +26 -0
- package/dist/events/schema-load.d.ts.map +1 -0
- package/dist/events/schema-load.js +23 -0
- package/dist/generator.d.ts +80 -1
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +244 -29
- package/dist/graphql-config.d.ts +2 -1
- package/dist/graphql-config.d.ts.map +1 -0
- package/dist/graphql-config.js +16 -10
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -3
- package/dist/options/builder.d.ts +157 -0
- package/dist/options/builder.d.ts.map +1 -0
- package/dist/options/builder.js +215 -0
- package/dist/printer.d.ts +4 -3
- package/dist/printer.d.ts.map +1 -0
- package/dist/printer.js +4 -4
- package/dist/renderer.d.ts +85 -32
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +411 -77
- package/package.json +11 -12
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetEvents = exports.getEvents = void 0;
|
|
4
|
+
const node_events_1 = require("node:events");
|
|
5
|
+
/**
|
|
6
|
+
* Custom EventEmitter that supports cancellable events with sequential handler execution.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Executes async handlers sequentially (one after another)
|
|
10
|
+
* - Collects errors without stopping handler execution
|
|
11
|
+
* - Supports stopPropagation to halt handler chain
|
|
12
|
+
* - Returns execution results to emitters
|
|
13
|
+
*
|
|
14
|
+
* @category Events
|
|
15
|
+
*/
|
|
16
|
+
class CancellableEventEmitter extends node_events_1.EventEmitter {
|
|
17
|
+
/**
|
|
18
|
+
* Emit an event asynchronously with cancellable event support.
|
|
19
|
+
*
|
|
20
|
+
* Handlers are executed sequentially in registration order.
|
|
21
|
+
* If a handler throws an error, it's collected but execution continues.
|
|
22
|
+
* If event.propagationStopped becomes true, remaining handlers are skipped.
|
|
23
|
+
*
|
|
24
|
+
* After all handlers execute, if the event has a defaultAction function and
|
|
25
|
+
* preventDefault() was not called, the default action is automatically executed.
|
|
26
|
+
*
|
|
27
|
+
* @param eventName - Name of the event to emit
|
|
28
|
+
* @param event - Cancellable event object with preventDefault() and stopPropagation() methods
|
|
29
|
+
* @returns Promise resolving to EmitResult with errors and cancellation status
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const events = getEvents();
|
|
34
|
+
* const event = new SchemaLoadEvent({
|
|
35
|
+
* schemaLocation: '/path/to/schema',
|
|
36
|
+
* defaultAction: async () => {
|
|
37
|
+
* // This runs automatically if not prevented
|
|
38
|
+
* await loadSchema('/path/to/schema');
|
|
39
|
+
* }
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* const { errors, defaultPrevented } = await events.emitAsync('beforeLoadSchema', event);
|
|
43
|
+
*
|
|
44
|
+
* if (errors.length > 0) {
|
|
45
|
+
* console.error('Errors occurred:', errors);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
async emitAsync(eventName, event) {
|
|
50
|
+
const errors = [];
|
|
51
|
+
// Get all registered listeners for this event
|
|
52
|
+
const listeners = this.listeners(eventName);
|
|
53
|
+
// Execute each handler sequentially
|
|
54
|
+
for (const listener of listeners) {
|
|
55
|
+
try {
|
|
56
|
+
// Call the handler - await to support async handlers
|
|
57
|
+
await listener(event);
|
|
58
|
+
// Check if handler stopped propagation to remaining handlers
|
|
59
|
+
if (event.propagationStopped) {
|
|
60
|
+
break; // Exit the loop, skipping remaining handlers
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
// Collect error but continue executing remaining handlers
|
|
65
|
+
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Execute default action if not prevented and event has one
|
|
69
|
+
try {
|
|
70
|
+
// Call defaultAction - await to support async
|
|
71
|
+
await event.runDefaultAction();
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
// Collect error from default action
|
|
75
|
+
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
76
|
+
}
|
|
77
|
+
return { errors, defaultPrevented: event.defaultPrevented };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Singleton instance of the CancellableEventEmitter.
|
|
82
|
+
* Shared across the entire application.
|
|
83
|
+
*/
|
|
84
|
+
let instance = null;
|
|
85
|
+
/**
|
|
86
|
+
* Get the singleton event emitter instance.
|
|
87
|
+
*
|
|
88
|
+
* Creates the instance on first call, then returns the same instance on subsequent calls.
|
|
89
|
+
* This ensures all parts of the application share the same event bus.
|
|
90
|
+
*
|
|
91
|
+
* @returns The singleton CancellableEventEmitter instance
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // In generator.ts
|
|
96
|
+
* const events = getEvents();
|
|
97
|
+
* events.on('beforeLoadSchema', handler);
|
|
98
|
+
*
|
|
99
|
+
* // In renderer.ts - same instance!
|
|
100
|
+
* const events = getEvents();
|
|
101
|
+
* await events.emitAsync('beforeLoadSchema', event);
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @category Events
|
|
105
|
+
*/
|
|
106
|
+
const getEvents = () => {
|
|
107
|
+
instance ??= new CancellableEventEmitter();
|
|
108
|
+
return instance;
|
|
109
|
+
};
|
|
110
|
+
exports.getEvents = getEvents;
|
|
111
|
+
/**
|
|
112
|
+
* Reset the event emitter singleton.
|
|
113
|
+
*
|
|
114
|
+
* Removes all event listeners and clears the instance.
|
|
115
|
+
* The next call to getEvents() will create a fresh instance.
|
|
116
|
+
*
|
|
117
|
+
* **Important:** This should only be used in tests to ensure test isolation.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // In test setup
|
|
122
|
+
* afterEach(() => {
|
|
123
|
+
* resetEvents();
|
|
124
|
+
* jest.restoreAllMocks();
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @category Events
|
|
129
|
+
*/
|
|
130
|
+
const resetEvents = () => {
|
|
131
|
+
if (instance) {
|
|
132
|
+
instance.removeAllListeners();
|
|
133
|
+
}
|
|
134
|
+
instance = null;
|
|
135
|
+
};
|
|
136
|
+
exports.resetEvents = resetEvents;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers MDX module lifecycle event handlers with the event emitter.
|
|
3
|
+
*
|
|
4
|
+
* Automatically detects and registers any lifecycle hook functions defined in the mdxModule
|
|
5
|
+
* that match the event callback naming convention. Logs registered handlers at debug level.
|
|
6
|
+
*
|
|
7
|
+
* Note: Format functions (formatMDXBadge, etc.) are NOT registered as events.
|
|
8
|
+
* They are pure transformations handled via the Formatter interface directly.
|
|
9
|
+
*
|
|
10
|
+
* @param mdxModule - The MDX module that may contain event callback functions
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const mdxModule = {
|
|
15
|
+
* beforeLoadSchemaHook: async (event) => { console.log('Loading schema...'); },
|
|
16
|
+
* afterRenderTypeEntitiesHook: async (event) => { console.log('Rendered:', event.data.name); }
|
|
17
|
+
* };
|
|
18
|
+
* registerMDXEventHandlers(mdxModule);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const registerMDXEventHandlers: (mdxModule: unknown) => void;
|
|
22
|
+
//# sourceMappingURL=event-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-handlers.d.ts","sourceRoot":"","sources":["../src/event-handlers.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,wBAAwB,8BAgCpC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerMDXEventHandlers = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* MDX event handler registration functionality.
|
|
6
|
+
*
|
|
7
|
+
* This module provides utilities for registering MDX module event handlers
|
|
8
|
+
* with the event emitter system. It maps event names to callback names and
|
|
9
|
+
* automatically detects and registers matching callbacks from MDX modules.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
const logger_1 = require("@graphql-markdown/logger");
|
|
14
|
+
const event_emitter_1 = require("./event-emitter");
|
|
15
|
+
const event_map_1 = require("./event-map");
|
|
16
|
+
/**
|
|
17
|
+
* Registers MDX module lifecycle event handlers with the event emitter.
|
|
18
|
+
*
|
|
19
|
+
* Automatically detects and registers any lifecycle hook functions defined in the mdxModule
|
|
20
|
+
* that match the event callback naming convention. Logs registered handlers at debug level.
|
|
21
|
+
*
|
|
22
|
+
* Note: Format functions (formatMDXBadge, etc.) are NOT registered as events.
|
|
23
|
+
* They are pure transformations handled via the Formatter interface directly.
|
|
24
|
+
*
|
|
25
|
+
* @param mdxModule - The MDX module that may contain event callback functions
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const mdxModule = {
|
|
30
|
+
* beforeLoadSchemaHook: async (event) => { console.log('Loading schema...'); },
|
|
31
|
+
* afterRenderTypeEntitiesHook: async (event) => { console.log('Rendered:', event.data.name); }
|
|
32
|
+
* };
|
|
33
|
+
* registerMDXEventHandlers(mdxModule);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
const registerMDXEventHandlers = (mdxModule) => {
|
|
37
|
+
if (!mdxModule || typeof mdxModule !== "object") {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
(0, event_emitter_1.resetEvents)(); // reset event to avoid duplicate registrations
|
|
41
|
+
const events = (0, event_emitter_1.getEvents)();
|
|
42
|
+
const registeredHandlers = new Set();
|
|
43
|
+
// Iterate through event callback mappings (lifecycle hooks only)
|
|
44
|
+
for (const [eventName, callbackName] of Object.entries(event_map_1.EVENT_CALLBACK_MAP)) {
|
|
45
|
+
// Check if mdxModule has this callback function
|
|
46
|
+
if (callbackName in mdxModule &&
|
|
47
|
+
typeof mdxModule[callbackName] === "function") {
|
|
48
|
+
const mdxFunction = mdxModule[callbackName];
|
|
49
|
+
events.on(eventName, mdxFunction);
|
|
50
|
+
registeredHandlers.add(callbackName);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (registeredHandlers.size > 0) {
|
|
54
|
+
(0, logger_1.log)(`Registered MDX lifecycle handlers: ${[...registeredHandlers].join(", ")}`, logger_1.LogLevel.debug);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.registerMDXEventHandlers = registerMDXEventHandlers;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event callback mapping configuration.
|
|
3
|
+
* Maps event names to their corresponding callback names in mdxModule.
|
|
4
|
+
*
|
|
5
|
+
* Note: Format functions (formatMDXBadge, formatMDXAdmonition, etc.) are NOT included here.
|
|
6
|
+
* They are pure transformations handled via the Formatter interface, not events.
|
|
7
|
+
*/
|
|
8
|
+
export declare const EVENT_CALLBACK_MAP: {
|
|
9
|
+
readonly "schema:beforeLoad": "beforeLoadSchemaHook";
|
|
10
|
+
readonly "schema:afterLoad": "afterLoadSchemaHook";
|
|
11
|
+
readonly "diff:beforeCheck": "beforeCheckDiffHook";
|
|
12
|
+
readonly "diff:afterCheck": "afterCheckDiffHook";
|
|
13
|
+
readonly "render:beforeRenderRootTypes": "beforeRenderRootTypesHook";
|
|
14
|
+
readonly "render:afterRenderRootTypes": "afterRenderRootTypesHook";
|
|
15
|
+
readonly "render:beforeRenderHomepage": "beforeRenderHomepageHook";
|
|
16
|
+
readonly "render:afterRenderHomepage": "afterRenderHomepageHook";
|
|
17
|
+
readonly "render:beforeRenderTypeEntities": "beforeRenderTypeEntitiesHook";
|
|
18
|
+
readonly "render:afterRenderTypeEntities": "afterRenderTypeEntitiesHook";
|
|
19
|
+
readonly "render:beforeGenerateIndexMetafile": "beforeGenerateIndexMetafileHook";
|
|
20
|
+
readonly "render:afterGenerateIndexMetafile": "afterGenerateIndexMetafileHook";
|
|
21
|
+
readonly "print:beforePrintCode": "beforePrintCodeHook";
|
|
22
|
+
readonly "print:afterPrintCode": "afterPrintCodeHook";
|
|
23
|
+
readonly "print:beforePrintType": "beforePrintTypeHook";
|
|
24
|
+
readonly "print:afterPrintType": "afterPrintTypeHook";
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=event-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-map.d.ts","sourceRoot":"","sources":["../src/event-map.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;CAmBrB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVENT_CALLBACK_MAP = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Event callback mapping configuration.
|
|
6
|
+
*
|
|
7
|
+
* This module defines the mappings between event names and their corresponding
|
|
8
|
+
* callback names in MDX modules. Kept separate to avoid circular dependencies.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
const schema_events_1 = require("./events/schema-events");
|
|
13
|
+
const diff_events_1 = require("./events/diff-events");
|
|
14
|
+
const render_root_types_events_1 = require("./events/render-root-types-events");
|
|
15
|
+
const render_homepage_events_1 = require("./events/render-homepage-events");
|
|
16
|
+
const render_type_entities_events_1 = require("./events/render-type-entities-events");
|
|
17
|
+
const generate_index_metafile_events_1 = require("./events/generate-index-metafile-events");
|
|
18
|
+
const print_type_events_1 = require("./events/print-type-events");
|
|
19
|
+
/**
|
|
20
|
+
* Event callback mapping configuration.
|
|
21
|
+
* Maps event names to their corresponding callback names in mdxModule.
|
|
22
|
+
*
|
|
23
|
+
* Note: Format functions (formatMDXBadge, formatMDXAdmonition, etc.) are NOT included here.
|
|
24
|
+
* They are pure transformations handled via the Formatter interface, not events.
|
|
25
|
+
*/
|
|
26
|
+
exports.EVENT_CALLBACK_MAP = {
|
|
27
|
+
[schema_events_1.SchemaEvents.BEFORE_LOAD]: "beforeLoadSchemaHook",
|
|
28
|
+
[schema_events_1.SchemaEvents.AFTER_LOAD]: "afterLoadSchemaHook",
|
|
29
|
+
[diff_events_1.DiffEvents.BEFORE_CHECK]: "beforeCheckDiffHook",
|
|
30
|
+
[diff_events_1.DiffEvents.AFTER_CHECK]: "afterCheckDiffHook",
|
|
31
|
+
[render_root_types_events_1.RenderRootTypesEvents.BEFORE_RENDER]: "beforeRenderRootTypesHook",
|
|
32
|
+
[render_root_types_events_1.RenderRootTypesEvents.AFTER_RENDER]: "afterRenderRootTypesHook",
|
|
33
|
+
[render_homepage_events_1.RenderHomepageEvents.BEFORE_RENDER]: "beforeRenderHomepageHook",
|
|
34
|
+
[render_homepage_events_1.RenderHomepageEvents.AFTER_RENDER]: "afterRenderHomepageHook",
|
|
35
|
+
[render_type_entities_events_1.RenderTypeEntitiesEvents.BEFORE_RENDER]: "beforeRenderTypeEntitiesHook",
|
|
36
|
+
[render_type_entities_events_1.RenderTypeEntitiesEvents.AFTER_RENDER]: "afterRenderTypeEntitiesHook",
|
|
37
|
+
[generate_index_metafile_events_1.GenerateIndexMetafileEvents.BEFORE_GENERATE]: "beforeGenerateIndexMetafileHook",
|
|
38
|
+
[generate_index_metafile_events_1.GenerateIndexMetafileEvents.AFTER_GENERATE]: "afterGenerateIndexMetafileHook",
|
|
39
|
+
[print_type_events_1.PrintTypeEvents.BEFORE_PRINT_CODE]: "beforePrintCodeHook",
|
|
40
|
+
[print_type_events_1.PrintTypeEvents.AFTER_PRINT_CODE]: "afterPrintCodeHook",
|
|
41
|
+
[print_type_events_1.PrintTypeEvents.BEFORE_PRINT_TYPE]: "beforePrintTypeHook",
|
|
42
|
+
[print_type_events_1.PrintTypeEvents.AFTER_PRINT_TYPE]: "afterPrintTypeHook",
|
|
43
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base event class and utilities for GraphQL-Markdown events.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import type { DefaultAction } from "@graphql-markdown/types";
|
|
7
|
+
/**
|
|
8
|
+
* Deep freezes an object to make it immutable at runtime.
|
|
9
|
+
* Recursively freezes all nested objects and arrays.
|
|
10
|
+
*
|
|
11
|
+
* @param obj - The object to freeze
|
|
12
|
+
* @returns The frozen object (same reference)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const data = { user: { name: 'John' } };
|
|
17
|
+
* deepFreeze(data);
|
|
18
|
+
* data.user.name = 'Jane'; // Throws error in strict mode
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const deepFreeze: <T extends Record<PropertyKey, any>>(obj: T) => T;
|
|
22
|
+
export interface CancellableEventOptions {
|
|
23
|
+
defaultAction?: DefaultAction;
|
|
24
|
+
cancellable?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Base class for all cancellable events in GraphQL-Markdown.
|
|
28
|
+
*
|
|
29
|
+
* Provides common functionality:
|
|
30
|
+
* - preventDefault() to cancel default actions
|
|
31
|
+
* - stopPropagation() to halt handler chain
|
|
32
|
+
* - Configurable cancellability
|
|
33
|
+
* - Optional default action function
|
|
34
|
+
*
|
|
35
|
+
* @category Events
|
|
36
|
+
*/
|
|
37
|
+
export declare abstract class CancellableEvent {
|
|
38
|
+
/**
|
|
39
|
+
* Whether the default action has been prevented.
|
|
40
|
+
* Set to true when preventDefault() is called.
|
|
41
|
+
*/
|
|
42
|
+
private _defaultPrevented;
|
|
43
|
+
/**
|
|
44
|
+
* Whether propagation to remaining handlers has been stopped.
|
|
45
|
+
* Set to true when stopPropagation() is called.
|
|
46
|
+
*/
|
|
47
|
+
private _propagationStopped;
|
|
48
|
+
/**
|
|
49
|
+
* Whether this event can be cancelled.
|
|
50
|
+
* If false, preventDefault() has no effect.
|
|
51
|
+
*/
|
|
52
|
+
private readonly _cancellable;
|
|
53
|
+
/**
|
|
54
|
+
* Optional function to execute as the default action.
|
|
55
|
+
* Only runs if preventDefault() was not called.
|
|
56
|
+
*/
|
|
57
|
+
private readonly _defaultAction?;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new CancellableEvent.
|
|
60
|
+
*
|
|
61
|
+
* @param options - Configuration options for the event
|
|
62
|
+
* @param options.cancellable - Whether this event can be cancelled (default: true)
|
|
63
|
+
* @param options.defaultAction - Optional function to execute as default action
|
|
64
|
+
*/
|
|
65
|
+
constructor(options?: CancellableEventOptions);
|
|
66
|
+
/**
|
|
67
|
+
* Gets whether the default action has been prevented.
|
|
68
|
+
*/
|
|
69
|
+
get defaultPrevented(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Gets whether propagation has been stopped.
|
|
72
|
+
*/
|
|
73
|
+
get propagationStopped(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Gets the default action function if one was provided.
|
|
76
|
+
*/
|
|
77
|
+
get defaultAction(): DefaultAction | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Prevents the default action from executing.
|
|
80
|
+
* Only works if the event is cancellable.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* events.on('beforeLoadSchema', (event) => {
|
|
85
|
+
* if (shouldUseCustomLoader) {
|
|
86
|
+
* event.preventDefault(); // Stops default schema loading
|
|
87
|
+
* // Custom logic here
|
|
88
|
+
* }
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
preventDefault(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Stops propagation to remaining event handlers.
|
|
95
|
+
* Handlers registered after the current one will not execute.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* events.on('beforeLoadSchema', (event) => {
|
|
100
|
+
* if (criticalError) {
|
|
101
|
+
* event.stopPropagation(); // No more handlers run
|
|
102
|
+
* }
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
stopPropagation(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Executes the default action for an event if it hasn't been prevented.
|
|
109
|
+
*
|
|
110
|
+
* @returns A promise that resolves when the default action completes, or void if the action was prevented or no default action is defined
|
|
111
|
+
*
|
|
112
|
+
* @remarks
|
|
113
|
+
* This method will only execute the `_defaultAction` if:
|
|
114
|
+
* - The event's default has not been prevented (`_defaultPrevented` is false)
|
|
115
|
+
* - A default action function has been defined (`_defaultAction` is a function)
|
|
116
|
+
*/
|
|
117
|
+
runDefaultAction(): Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +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;AAE7D;;;;;;;;;;;;;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,gBAAgB;IACpC;;;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"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base event class and utilities for GraphQL-Markdown events.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CancellableEvent = exports.deepFreeze = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Deep freezes an object to make it immutable at runtime.
|
|
11
|
+
* Recursively freezes all nested objects and arrays.
|
|
12
|
+
*
|
|
13
|
+
* @param obj - The object to freeze
|
|
14
|
+
* @returns The frozen object (same reference)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const data = { user: { name: 'John' } };
|
|
19
|
+
* deepFreeze(data);
|
|
20
|
+
* data.user.name = 'Jane'; // Throws error in strict mode
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const deepFreeze = (obj) => {
|
|
24
|
+
// Get all property names including symbols
|
|
25
|
+
const propNames = Reflect.ownKeys(obj);
|
|
26
|
+
// Freeze properties before freezing self
|
|
27
|
+
for (const name of propNames) {
|
|
28
|
+
const value = obj[name];
|
|
29
|
+
if ((value && typeof value === "object") || typeof value === "function") {
|
|
30
|
+
(0, exports.deepFreeze)(value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Object.freeze(obj);
|
|
34
|
+
};
|
|
35
|
+
exports.deepFreeze = deepFreeze;
|
|
36
|
+
/**
|
|
37
|
+
* Base class for all cancellable events in GraphQL-Markdown.
|
|
38
|
+
*
|
|
39
|
+
* Provides common functionality:
|
|
40
|
+
* - preventDefault() to cancel default actions
|
|
41
|
+
* - stopPropagation() to halt handler chain
|
|
42
|
+
* - Configurable cancellability
|
|
43
|
+
* - Optional default action function
|
|
44
|
+
*
|
|
45
|
+
* @category Events
|
|
46
|
+
*/
|
|
47
|
+
class CancellableEvent {
|
|
48
|
+
/**
|
|
49
|
+
* Whether the default action has been prevented.
|
|
50
|
+
* Set to true when preventDefault() is called.
|
|
51
|
+
*/
|
|
52
|
+
_defaultPrevented = false;
|
|
53
|
+
/**
|
|
54
|
+
* Whether propagation to remaining handlers has been stopped.
|
|
55
|
+
* Set to true when stopPropagation() is called.
|
|
56
|
+
*/
|
|
57
|
+
_propagationStopped = false;
|
|
58
|
+
/**
|
|
59
|
+
* Whether this event can be cancelled.
|
|
60
|
+
* If false, preventDefault() has no effect.
|
|
61
|
+
*/
|
|
62
|
+
_cancellable;
|
|
63
|
+
/**
|
|
64
|
+
* Optional function to execute as the default action.
|
|
65
|
+
* Only runs if preventDefault() was not called.
|
|
66
|
+
*/
|
|
67
|
+
_defaultAction;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new CancellableEvent.
|
|
70
|
+
*
|
|
71
|
+
* @param options - Configuration options for the event
|
|
72
|
+
* @param options.cancellable - Whether this event can be cancelled (default: true)
|
|
73
|
+
* @param options.defaultAction - Optional function to execute as default action
|
|
74
|
+
*/
|
|
75
|
+
constructor(options) {
|
|
76
|
+
this._cancellable = options?.cancellable ?? true;
|
|
77
|
+
this._defaultAction = options?.defaultAction;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Gets whether the default action has been prevented.
|
|
81
|
+
*/
|
|
82
|
+
get defaultPrevented() {
|
|
83
|
+
return this._defaultPrevented;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets whether propagation has been stopped.
|
|
87
|
+
*/
|
|
88
|
+
get propagationStopped() {
|
|
89
|
+
return this._propagationStopped;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Gets the default action function if one was provided.
|
|
93
|
+
*/
|
|
94
|
+
get defaultAction() {
|
|
95
|
+
return this._defaultAction;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Prevents the default action from executing.
|
|
99
|
+
* Only works if the event is cancellable.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* events.on('beforeLoadSchema', (event) => {
|
|
104
|
+
* if (shouldUseCustomLoader) {
|
|
105
|
+
* event.preventDefault(); // Stops default schema loading
|
|
106
|
+
* // Custom logic here
|
|
107
|
+
* }
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
preventDefault() {
|
|
112
|
+
if (this._cancellable) {
|
|
113
|
+
this._defaultPrevented = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Stops propagation to remaining event handlers.
|
|
118
|
+
* Handlers registered after the current one will not execute.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* events.on('beforeLoadSchema', (event) => {
|
|
123
|
+
* if (criticalError) {
|
|
124
|
+
* event.stopPropagation(); // No more handlers run
|
|
125
|
+
* }
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
stopPropagation() {
|
|
130
|
+
this._propagationStopped = true;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Executes the default action for an event if it hasn't been prevented.
|
|
134
|
+
*
|
|
135
|
+
* @returns A promise that resolves when the default action completes, or void if the action was prevented or no default action is defined
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* This method will only execute the `_defaultAction` if:
|
|
139
|
+
* - The event's default has not been prevented (`_defaultPrevented` is false)
|
|
140
|
+
* - A default action function has been defined (`_defaultAction` is a function)
|
|
141
|
+
*/
|
|
142
|
+
async runDefaultAction() {
|
|
143
|
+
if (!this._defaultPrevented && typeof this._defaultAction === "function") {
|
|
144
|
+
return this._defaultAction();
|
|
145
|
+
}
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.CancellableEvent = CancellableEvent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff checking event class.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import { CancellableEvent, CancellableEventOptions } from "./base";
|
|
7
|
+
/**
|
|
8
|
+
* Event emitted before/after checking schema differences.
|
|
9
|
+
*
|
|
10
|
+
* @category Events
|
|
11
|
+
*/
|
|
12
|
+
export declare class DiffCheckEvent extends CancellableEvent {
|
|
13
|
+
/** Event data containing schema, output directory, and change status */
|
|
14
|
+
readonly data: {
|
|
15
|
+
schema?: unknown;
|
|
16
|
+
outputDir?: string;
|
|
17
|
+
schemaHasChanges?: boolean;
|
|
18
|
+
};
|
|
19
|
+
constructor(data: {
|
|
20
|
+
schema?: unknown;
|
|
21
|
+
outputDir?: string;
|
|
22
|
+
schemaHasChanges?: boolean;
|
|
23
|
+
}, options?: CancellableEventOptions);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=diff-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-check.d.ts","sourceRoot":"","sources":["../../src/events/diff-check.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AAEnE;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,gBAAgB;IAClD,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE;QACb,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,CAAC;IAEF,YACE,IAAI,EAAE;QACJ,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;KAC5B,EACD,OAAO,CAAC,EAAE,uBAAuB,EAIlC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Diff checking event class.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.DiffCheckEvent = void 0;
|
|
9
|
+
const base_1 = require("./base");
|
|
10
|
+
/**
|
|
11
|
+
* Event emitted before/after checking schema differences.
|
|
12
|
+
*
|
|
13
|
+
* @category Events
|
|
14
|
+
*/
|
|
15
|
+
class DiffCheckEvent extends base_1.CancellableEvent {
|
|
16
|
+
/** Event data containing schema, output directory, and change status */
|
|
17
|
+
data;
|
|
18
|
+
constructor(data, options) {
|
|
19
|
+
super(options);
|
|
20
|
+
this.data = data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.DiffCheckEvent = DiffCheckEvent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff checking event constants.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Event names for diff checking lifecycle.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DiffEvents: {
|
|
10
|
+
/** Emitted before checking schema differences */
|
|
11
|
+
readonly BEFORE_CHECK: "diff:beforeCheck";
|
|
12
|
+
/** Emitted after checking schema differences */
|
|
13
|
+
readonly AFTER_CHECK: "diff:afterCheck";
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=diff-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-events.d.ts","sourceRoot":"","sources":["../../src/events/diff-events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU;IACrB,iDAAiD;;IAEjD,gDAAgD;;CAExC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Diff checking event constants.
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.DiffEvents = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Event names for diff checking lifecycle.
|
|
11
|
+
*/
|
|
12
|
+
exports.DiffEvents = {
|
|
13
|
+
/** Emitted before checking schema differences */
|
|
14
|
+
BEFORE_CHECK: "diff:beforeCheck",
|
|
15
|
+
/** Emitted after checking schema differences */
|
|
16
|
+
AFTER_CHECK: "diff:afterCheck",
|
|
17
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate index metafile event constants.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Event names for generating index metafile.
|
|
8
|
+
*/
|
|
9
|
+
export declare const GenerateIndexMetafileEvents: {
|
|
10
|
+
/** Emitted before generating index metafile */
|
|
11
|
+
readonly BEFORE_GENERATE: "render:beforeGenerateIndexMetafile";
|
|
12
|
+
/** Emitted after generating index metafile */
|
|
13
|
+
readonly AFTER_GENERATE: "render:afterGenerateIndexMetafile";
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=generate-index-metafile-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-index-metafile-events.d.ts","sourceRoot":"","sources":["../../src/events/generate-index-metafile-events.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,2BAA2B;IACtC,+CAA+C;;IAE/C,8CAA8C;;CAEtC,CAAC"}
|