@graphql-markdown/core 1.17.0 → 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.
Files changed (60) hide show
  1. package/dist/event-emitter.d.ts.map +1 -1
  2. package/dist/event-emitter.js +1 -3
  3. package/dist/event-handlers.d.ts +6 -3
  4. package/dist/event-handlers.d.ts.map +1 -1
  5. package/dist/event-handlers.js +10 -7
  6. package/dist/event-map.d.ts +7 -0
  7. package/dist/event-map.d.ts.map +1 -1
  8. package/dist/event-map.js +8 -0
  9. package/dist/events/base.d.ts +8 -3
  10. package/dist/events/base.d.ts.map +1 -1
  11. package/dist/events/base.js +6 -5
  12. package/dist/events/diff-check.d.ts +11 -11
  13. package/dist/events/diff-check.d.ts.map +1 -1
  14. package/dist/events/diff-check.js +5 -8
  15. package/dist/events/generate-index-metafile.d.ts +8 -11
  16. package/dist/events/generate-index-metafile.d.ts.map +1 -1
  17. package/dist/events/generate-index-metafile.js +5 -11
  18. package/dist/events/index.d.ts +4 -1
  19. package/dist/events/index.d.ts.map +1 -1
  20. package/dist/events/index.js +7 -2
  21. package/dist/events/print-type-events.d.ts +33 -0
  22. package/dist/events/print-type-events.d.ts.map +1 -0
  23. package/dist/events/print-type-events.js +35 -0
  24. package/dist/events/print-type.d.ts +84 -0
  25. package/dist/events/print-type.d.ts.map +1 -0
  26. package/dist/events/print-type.js +73 -0
  27. package/dist/events/render-homepage.d.ts +6 -7
  28. package/dist/events/render-homepage.d.ts.map +1 -1
  29. package/dist/events/render-homepage.js +5 -5
  30. package/dist/events/render-root-types.d.ts +6 -7
  31. package/dist/events/render-root-types.d.ts.map +1 -1
  32. package/dist/events/render-root-types.js +5 -5
  33. package/dist/events/render-type-entities.d.ts +7 -9
  34. package/dist/events/render-type-entities.d.ts.map +1 -1
  35. package/dist/events/render-type-entities.js +5 -8
  36. package/dist/events/schema-events.d.ts +4 -0
  37. package/dist/events/schema-events.d.ts.map +1 -1
  38. package/dist/events/schema-events.js +4 -0
  39. package/dist/events/schema-load.d.ts +13 -9
  40. package/dist/events/schema-load.d.ts.map +1 -1
  41. package/dist/events/schema-load.js +8 -8
  42. package/dist/generator.d.ts +79 -1
  43. package/dist/generator.d.ts.map +1 -1
  44. package/dist/generator.js +222 -49
  45. package/dist/index.d.ts +9 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +16 -1
  48. package/dist/printer.d.ts +3 -3
  49. package/dist/printer.d.ts.map +1 -1
  50. package/dist/printer.js +3 -3
  51. package/dist/renderer.d.ts +10 -10
  52. package/dist/renderer.d.ts.map +1 -1
  53. package/dist/renderer.js +12 -22
  54. package/package.json +9 -9
  55. package/dist/event-types.d.ts +0 -313
  56. package/dist/event-types.d.ts.map +0 -1
  57. package/dist/event-types.js +0 -309
  58. package/dist/hooks.d.ts +0 -10
  59. package/dist/hooks.d.ts.map +0 -1
  60. package/dist/hooks.js +0 -33
@@ -1,313 +0,0 @@
1
- /**
2
- * Event system types and base classes for GraphQL-Markdown events.
3
- *
4
- * @packageDocumentation
5
- */
6
- /**
7
- * Type for default action function that can be executed by events.
8
- * Returns a Promise to support both sync and async actions.
9
- */
10
- export type DefaultAction = () => Promise<void>;
11
- /**
12
- * Deep freezes an object to make it immutable at runtime.
13
- * Recursively freezes all nested objects and arrays.
14
- *
15
- * @param obj - The object to freeze
16
- * @returns The frozen object (same reference)
17
- *
18
- * @example
19
- * ```typescript
20
- * const data = { user: { name: 'John' } };
21
- * deepFreeze(data);
22
- * data.user.name = 'Jane'; // Throws error in strict mode
23
- * ```
24
- */
25
- export declare const deepFreeze: <T>(obj: T) => T;
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 cancellable - Whether this event can be cancelled (default: true)
62
- * @param defaultAction - Optional function to execute as default action
63
- */
64
- constructor(cancellable?: boolean, defaultAction?: DefaultAction);
65
- /**
66
- * Gets whether the default action has been prevented.
67
- */
68
- get defaultPrevented(): boolean;
69
- /**
70
- * Gets whether propagation has been stopped.
71
- */
72
- get propagationStopped(): boolean;
73
- /**
74
- * Gets the default action function if one was provided.
75
- */
76
- get defaultAction(): DefaultAction | undefined;
77
- /**
78
- * Prevents the default action from executing.
79
- * Only works if the event is cancellable.
80
- *
81
- * @example
82
- * ```typescript
83
- * events.on('beforeLoadSchema', (event) => {
84
- * if (shouldUseCustomLoader) {
85
- * event.preventDefault(); // Stops default schema loading
86
- * // Custom logic here
87
- * }
88
- * });
89
- * ```
90
- */
91
- preventDefault(): void;
92
- /**
93
- * Stops propagation to remaining event handlers.
94
- * Handlers registered after the current one will not execute.
95
- *
96
- * @example
97
- * ```typescript
98
- * events.on('beforeLoadSchema', (event) => {
99
- * if (criticalError) {
100
- * event.stopPropagation(); // No more handlers run
101
- * }
102
- * });
103
- * ```
104
- */
105
- stopPropagation(): void;
106
- }
107
- /**
108
- * Event names for schema loading lifecycle.
109
- */
110
- export declare const SchemaEvents: {
111
- /** Emitted before loading GraphQL schema */
112
- readonly BEFORE_LOAD: "beforeLoadSchema";
113
- /** Emitted after loading GraphQL schema */
114
- readonly AFTER_LOAD: "afterLoadSchema";
115
- };
116
- /**
117
- * Event names for diff checking lifecycle.
118
- */
119
- export declare const DiffEvents: {
120
- /** Emitted before checking schema differences */
121
- readonly BEFORE_CHECK: "beforeCheckDiff";
122
- /** Emitted after checking schema differences */
123
- readonly AFTER_CHECK: "afterCheckDiff";
124
- };
125
- /**
126
- * Event names for category collection lifecycle.
127
- */
128
- export declare const CategoryEvents: {
129
- /** Emitted before pre-collecting categories */
130
- readonly BEFORE_PRE_COLLECT: "beforePreCollectCategories";
131
- /** Emitted after pre-collecting categories */
132
- readonly AFTER_PRE_COLLECT: "afterPreCollectCategories";
133
- };
134
- /**
135
- * Event names for rendering lifecycle.
136
- */
137
- export declare const RenderEvents: {
138
- /** Emitted before rendering root types */
139
- readonly BEFORE_RENDER_ROOT_TYPES: "beforeRenderRootTypes";
140
- /** Emitted after rendering root types */
141
- readonly AFTER_RENDER_ROOT_TYPES: "afterRenderRootTypes";
142
- /** Emitted before rendering homepage */
143
- readonly BEFORE_RENDER_HOMEPAGE: "beforeRenderHomepage";
144
- /** Emitted after rendering homepage */
145
- readonly AFTER_RENDER_HOMEPAGE: "afterRenderHomepage";
146
- /** Emitted before rendering type entities */
147
- readonly BEFORE_RENDER_TYPE_ENTITIES: "beforeRenderTypeEntities";
148
- /** Emitted after rendering type entities */
149
- readonly AFTER_RENDER_TYPE_ENTITIES: "afterRenderTypeEntities";
150
- /** Emitted before generating index metafile */
151
- readonly BEFORE_GENERATE_INDEX_METAFILE: "beforeGenerateIndexMetafile";
152
- /** Emitted after generating index metafile */
153
- readonly AFTER_GENERATE_INDEX_METAFILE: "afterGenerateIndexMetafile";
154
- };
155
- /**
156
- * All event names combined.
157
- */
158
- export declare const EventNames: {
159
- /** Emitted before loading GraphQL schema */
160
- readonly BEFORE_LOAD: "beforeLoadSchema";
161
- /** Emitted after loading GraphQL schema */
162
- readonly AFTER_LOAD: "afterLoadSchema";
163
- /** Emitted before checking schema differences */
164
- readonly BEFORE_CHECK: "beforeCheckDiff";
165
- /** Emitted after checking schema differences */
166
- readonly AFTER_CHECK: "afterCheckDiff";
167
- /** Emitted before pre-collecting categories */
168
- readonly BEFORE_PRE_COLLECT: "beforePreCollectCategories";
169
- /** Emitted after pre-collecting categories */
170
- readonly AFTER_PRE_COLLECT: "afterPreCollectCategories";
171
- /** Emitted before rendering root types */
172
- readonly BEFORE_RENDER_ROOT_TYPES: "beforeRenderRootTypes";
173
- /** Emitted after rendering root types */
174
- readonly AFTER_RENDER_ROOT_TYPES: "afterRenderRootTypes";
175
- /** Emitted before rendering homepage */
176
- readonly BEFORE_RENDER_HOMEPAGE: "beforeRenderHomepage";
177
- /** Emitted after rendering homepage */
178
- readonly AFTER_RENDER_HOMEPAGE: "afterRenderHomepage";
179
- /** Emitted before rendering type entities */
180
- readonly BEFORE_RENDER_TYPE_ENTITIES: "beforeRenderTypeEntities";
181
- /** Emitted after rendering type entities */
182
- readonly AFTER_RENDER_TYPE_ENTITIES: "afterRenderTypeEntities";
183
- /** Emitted before generating index metafile */
184
- readonly BEFORE_GENERATE_INDEX_METAFILE: "beforeGenerateIndexMetafile";
185
- /** Emitted after generating index metafile */
186
- readonly AFTER_GENERATE_INDEX_METAFILE: "afterGenerateIndexMetafile";
187
- };
188
- /**
189
- * Event emitted before/after loading a GraphQL schema.
190
- *
191
- * @category Events
192
- */
193
- export declare class SchemaLoadEvent extends CancellableEvent {
194
- /** Path or pointer to the schema location */
195
- readonly schemaLocation: string;
196
- constructor(data: {
197
- schemaLocation: string;
198
- defaultAction?: DefaultAction;
199
- cancellable?: boolean;
200
- });
201
- }
202
- /**
203
- * Event emitted before/after checking schema differences.
204
- *
205
- * @category Events
206
- */
207
- export declare class DiffCheckEvent extends CancellableEvent {
208
- /** Current schema being checked */
209
- readonly schema: unknown;
210
- /** Path to output directory for diff results */
211
- readonly outputDir: string;
212
- constructor(data: {
213
- schema: unknown;
214
- outputDir: string;
215
- defaultAction?: DefaultAction;
216
- cancellable?: boolean;
217
- });
218
- }
219
-
220
- /**
221
- * Event emitted before/after rendering root types.
222
- *
223
- * @category Events
224
- */
225
- export declare class RenderRootTypesEvent extends CancellableEvent {
226
- /** Root types to render */
227
- readonly rootTypes: unknown;
228
- constructor(data: {
229
- rootTypes: unknown;
230
- defaultAction?: DefaultAction;
231
- cancellable?: boolean;
232
- });
233
- }
234
- /**
235
- * Event emitted before/after rendering homepage.
236
- *
237
- * @category Events
238
- */
239
- export declare class RenderHomepageEvent extends CancellableEvent {
240
- /** Output directory for homepage */
241
- readonly outputDir: string;
242
- constructor(data: {
243
- outputDir: string;
244
- defaultAction?: DefaultAction;
245
- cancellable?: boolean;
246
- });
247
- }
248
- /**
249
- * Event emitted before/after rendering type entities.
250
- *
251
- * @category Events
252
- */
253
- export declare class RenderTypeEntitiesEvent extends CancellableEvent {
254
- /** Name of the type entity */
255
- readonly name: string;
256
- /** File path where entity will be rendered */
257
- readonly filePath: string;
258
- constructor(data: {
259
- name: string;
260
- filePath: string;
261
- defaultAction?: DefaultAction;
262
- cancellable?: boolean;
263
- });
264
- }
265
- /**
266
- * Event emitted before/after generating index metafile.
267
- *
268
- * @category Events
269
- */
270
- export declare class GenerateIndexMetafileEvent extends CancellableEvent {
271
- /** Directory path for the index file */
272
- readonly dirPath: string;
273
- /** Category name */
274
- readonly category: string;
275
- /** Optional configuration options */
276
- readonly options?: Record<string, unknown>;
277
- constructor(data: {
278
- dirPath: string;
279
- category: string;
280
- options?: Record<string, unknown>;
281
- defaultAction?: DefaultAction;
282
- cancellable?: boolean;
283
- });
284
- }
285
- /**
286
- * Hook callback for schema loading events.
287
- */
288
- export type SchemaLoadHook = (event: SchemaLoadEvent) => Promise<void>;
289
- /**
290
- * Hook callback for diff check events.
291
- */
292
- export type DiffCheckHook = (event: DiffCheckEvent) => Promise<void>;
293
- /**
294
- * Hook callback for pre-collect categories events.
295
- */
296
- export type PreCollectCategoriesHook = (event: PreCollectCategoriesEvent) => Promise<void>;
297
- /**
298
- * Hook callback for render root types events.
299
- */
300
- export type RenderRootTypesHook = (event: RenderRootTypesEvent) => Promise<void>;
301
- /**
302
- * Hook callback for render homepage events.
303
- */
304
- export type RenderHomepageHook = (event: RenderHomepageEvent) => Promise<void>;
305
- /**
306
- * Hook callback for render type entities events.
307
- */
308
- export type RenderTypeEntitiesHook = (event: RenderTypeEntitiesEvent) => Promise<void>;
309
- /**
310
- * Hook callback for generate index metafile events.
311
- */
312
- export type GenerateIndexMetafileHook = (event: GenerateIndexMetafileEvent) => Promise<void>;
313
- //# sourceMappingURL=event-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-types.d.ts","sourceRoot":"","sources":["../src/event-types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,cAe3B,CAAC;AAEF;;;;;;;;;;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;;;;;OAKG;IACH,YAAY,WAAW,UAAO,EAAE,aAAa,CAAC,EAAE,aAAa,EAG5D;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;CACF;AAMD;;GAEG;AACH,eAAO,MAAM,YAAY;IACvB,4CAA4C;;IAE5C,2CAA2C;;CAEnC,CAAC;AAEX;;GAEG;AACH,eAAO,MA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
- * Event system types and base classes for GraphQL-Markdown events.
4
- *
5
- * @packageDocumentation
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.GenerateIndexMetafileEvent = exports.RenderTypeEntitiesEvent = exports.RenderHomepageEvent = exports.RenderRootTypesEvent = exports.PreCollectCategoriesEvent = exports.DiffCheckEvent = exports.SchemaLoadEvent = exports.EventNames = exports.RenderEvents = exports.CategoryEvents = exports.DiffEvents = exports.SchemaEvents = 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 = Object.getOwnPropertyNames(obj);
26
- // Freeze properties before freezing self
27
- for (const name of propNames) {
28
- const value = obj[name];
29
- // Recursively freeze nested objects
30
- if (value && typeof value === "object") {
31
- (0, exports.deepFreeze)(value);
32
- }
33
- }
34
- return Object.freeze(obj);
35
- };
36
- exports.deepFreeze = deepFreeze;
37
- /**
38
- * Base class for all cancellable events in GraphQL-Markdown.
39
- *
40
- * Provides common functionality:
41
- * - preventDefault() to cancel default actions
42
- * - stopPropagation() to halt handler chain
43
- * - Configurable cancellability
44
- * - Optional default action function
45
- *
46
- * @category Events
47
- */
48
- class CancellableEvent {
49
- /**
50
- * Whether the default action has been prevented.
51
- * Set to true when preventDefault() is called.
52
- */
53
- _defaultPrevented = false;
54
- /**
55
- * Whether propagation to remaining handlers has been stopped.
56
- * Set to true when stopPropagation() is called.
57
- */
58
- _propagationStopped = false;
59
- /**
60
- * Whether this event can be cancelled.
61
- * If false, preventDefault() has no effect.
62
- */
63
- _cancellable;
64
- /**
65
- * Optional function to execute as the default action.
66
- * Only runs if preventDefault() was not called.
67
- */
68
- _defaultAction;
69
- /**
70
- * Creates a new CancellableEvent.
71
- *
72
- * @param cancellable - Whether this event can be cancelled (default: true)
73
- * @param defaultAction - Optional function to execute as default action
74
- */
75
- constructor(cancellable = true, defaultAction) {
76
- this._cancellable = cancellable;
77
- this._defaultAction = 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
- exports.CancellableEvent = CancellableEvent;
134
- // =============================================================================
135
- // EVENT NAME CONSTANTS
136
- // =============================================================================
137
- /**
138
- * Event names for schema loading lifecycle.
139
- */
140
- exports.SchemaEvents = {
141
- /** Emitted before loading GraphQL schema */
142
- BEFORE_LOAD: "beforeLoadSchema",
143
- /** Emitted after loading GraphQL schema */
144
- AFTER_LOAD: "afterLoadSchema",
145
- };
146
- /**
147
- * Event names for diff checking lifecycle.
148
- */
149
- exports.DiffEvents = {
150
- /** Emitted before checking schema differences */
151
- BEFORE_CHECK: "beforeCheckDiff",
152
- /** Emitted after checking schema differences */
153
- AFTER_CHECK: "afterCheckDiff",
154
- };
155
- /**
156
- * Event names for category collection lifecycle.
157
- */
158
- exports.CategoryEvents = {
159
- /** Emitted before pre-collecting categories */
160
- BEFORE_PRE_COLLECT: "beforePreCollectCategories",
161
- /** Emitted after pre-collecting categories */
162
- AFTER_PRE_COLLECT: "afterPreCollectCategories",
163
- };
164
- /**
165
- * Event names for rendering lifecycle.
166
- */
167
- exports.RenderEvents = {
168
- /** Emitted before rendering root types */
169
- BEFORE_RENDER_ROOT_TYPES: "beforeRenderRootTypes",
170
- /** Emitted after rendering root types */
171
- AFTER_RENDER_ROOT_TYPES: "afterRenderRootTypes",
172
- /** Emitted before rendering homepage */
173
- BEFORE_RENDER_HOMEPAGE: "beforeRenderHomepage",
174
- /** Emitted after rendering homepage */
175
- AFTER_RENDER_HOMEPAGE: "afterRenderHomepage",
176
- /** Emitted before rendering type entities */
177
- BEFORE_RENDER_TYPE_ENTITIES: "beforeRenderTypeEntities",
178
- /** Emitted after rendering type entities */
179
- AFTER_RENDER_TYPE_ENTITIES: "afterRenderTypeEntities",
180
- /** Emitted before generating index metafile */
181
- BEFORE_GENERATE_INDEX_METAFILE: "beforeGenerateIndexMetafile",
182
- /** Emitted after generating index metafile */
183
- AFTER_GENERATE_INDEX_METAFILE: "afterGenerateIndexMetafile",
184
- };
185
- /**
186
- * All event names combined.
187
- */
188
- exports.EventNames = {
189
- ...exports.SchemaEvents,
190
- ...exports.DiffEvents,
191
- ...exports.CategoryEvents,
192
- ...exports.RenderEvents,
193
- };
194
- // =============================================================================
195
- // SPECIFIC EVENT CLASSES
196
- // =============================================================================
197
- /**
198
- * Event emitted before/after loading a GraphQL schema.
199
- *
200
- * @category Events
201
- */
202
- class SchemaLoadEvent extends CancellableEvent {
203
- /** Path or pointer to the schema location */
204
- schemaLocation;
205
- constructor(data) {
206
- super(data.cancellable, data.defaultAction);
207
- this.schemaLocation = data.schemaLocation;
208
- }
209
- }
210
- exports.SchemaLoadEvent = SchemaLoadEvent;
211
- /**
212
- * Event emitted before/after checking schema differences.
213
- *
214
- * @category Events
215
- */
216
- class DiffCheckEvent extends CancellableEvent {
217
- /** Current schema being checked */
218
- schema;
219
- /** Path to output directory for diff results */
220
- outputDir;
221
- constructor(data) {
222
- super(data.cancellable, data.defaultAction);
223
- this.schema = data.schema;
224
- this.outputDir = data.outputDir;
225
- }
226
- }
227
- exports.DiffCheckEvent = DiffCheckEvent;
228
- /**
229
- * Event emitted before/after pre-collecting categories.
230
- *
231
- * @category Events
232
- */
233
- class PreCollectCategoriesEvent extends CancellableEvent {
234
- /** Root types being processed */
235
- rootTypes;
236
- /** Base URL for documentation */
237
- baseURL;
238
- constructor(data) {
239
- super(data.cancellable, data.defaultAction);
240
- this.rootTypes = data.rootTypes;
241
- this.baseURL = data.baseURL;
242
- }
243
- }
244
- exports.PreCollectCategoriesEvent = PreCollectCategoriesEvent;
245
- /**
246
- * Event emitted before/after rendering root types.
247
- *
248
- * @category Events
249
- */
250
- class RenderRootTypesEvent extends CancellableEvent {
251
- /** Root types to render */
252
- rootTypes;
253
- constructor(data) {
254
- super(data.cancellable, data.defaultAction);
255
- this.rootTypes = data.rootTypes;
256
- }
257
- }
258
- exports.RenderRootTypesEvent = RenderRootTypesEvent;
259
- /**
260
- * Event emitted before/after rendering homepage.
261
- *
262
- * @category Events
263
- */
264
- class RenderHomepageEvent extends CancellableEvent {
265
- /** Output directory for homepage */
266
- outputDir;
267
- constructor(data) {
268
- super(data.cancellable, data.defaultAction);
269
- this.outputDir = data.outputDir;
270
- }
271
- }
272
- exports.RenderHomepageEvent = RenderHomepageEvent;
273
- /**
274
- * Event emitted before/after rendering type entities.
275
- *
276
- * @category Events
277
- */
278
- class RenderTypeEntitiesEvent extends CancellableEvent {
279
- /** Name of the type entity */
280
- name;
281
- /** File path where entity will be rendered */
282
- filePath;
283
- constructor(data) {
284
- super(data.cancellable, data.defaultAction);
285
- this.name = data.name;
286
- this.filePath = data.filePath;
287
- }
288
- }
289
- exports.RenderTypeEntitiesEvent = RenderTypeEntitiesEvent;
290
- /**
291
- * Event emitted before/after generating index metafile.
292
- *
293
- * @category Events
294
- */
295
- class GenerateIndexMetafileEvent extends CancellableEvent {
296
- /** Directory path for the index file */
297
- dirPath;
298
- /** Category name */
299
- category;
300
- /** Optional configuration options */
301
- options;
302
- constructor(data) {
303
- super(data.cancellable, data.defaultAction);
304
- this.dirPath = data.dirPath;
305
- this.category = data.category;
306
- this.options = data.options;
307
- }
308
- }
309
- exports.GenerateIndexMetafileEvent = GenerateIndexMetafileEvent;
package/dist/hooks.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export type Callback = (...args: unknown[]) => unknown;
2
- export interface Subscription {
3
- unsubscribe: () => void;
4
- }
5
- export declare abstract class Hookable {
6
- map: Map<string, Callback[]>;
7
- subscribe(hookName: string, callback: Callback): Subscription;
8
- protected emit(hookName: string, args?: unknown[]): unknown[];
9
- }
10
- //# sourceMappingURL=hooks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AACvD,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AAED,8BAAsB,QAAQ;IAC5B,GAAG,0BAAiC;IAEpC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,YAAY,CAiB5D;IAED,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,EAAO,GAAG,OAAO,EAAE,CAQhE;CACF"}
package/dist/hooks.js DELETED
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Hookable = void 0;
4
- class Hookable {
5
- map = new Map();
6
- subscribe(hookName, callback) {
7
- if (!this.map.has(hookName))
8
- this.map.set(hookName, []);
9
- const arr = this.map.get(hookName) ?? [];
10
- arr.push(callback);
11
- return {
12
- unsubscribe: () => {
13
- const index = arr.indexOf(callback);
14
- if (index === -1) {
15
- return;
16
- }
17
- arr.splice(index, 1);
18
- if (arr.length === 0) {
19
- this.map.delete(hookName);
20
- }
21
- },
22
- };
23
- }
24
- emit(hookName, args = []) {
25
- const handlers = this.map.get(hookName);
26
- if (handlers)
27
- return handlers.map((handler) => {
28
- return handler(...args);
29
- });
30
- return [];
31
- }
32
- }
33
- exports.Hookable = Hookable;