@graphql-markdown/printer-legacy 1.14.0 → 1.16.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/badge.d.ts +10 -3
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +19 -9
- package/dist/code.d.ts +1 -1
- package/dist/code.d.ts.map +1 -1
- package/dist/common.d.ts +5 -13
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +5 -6
- package/dist/const/options.d.ts +11 -2
- package/dist/const/options.d.ts.map +1 -1
- package/dist/const/options.js +27 -10
- package/dist/const/strings.d.ts +1 -3
- package/dist/const/strings.d.ts.map +1 -1
- package/dist/const/strings.js +4 -6
- package/dist/directive.d.ts +4 -4
- package/dist/directive.d.ts.map +1 -1
- package/dist/directive.js +9 -12
- package/dist/events.d.ts +77 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +85 -0
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +12 -7
- package/dist/format-helpers.d.ts +9 -0
- package/dist/format-helpers.d.ts.map +1 -1
- package/dist/format-helpers.js +10 -1
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +9 -30
- package/dist/frontmatter.d.ts.map +1 -1
- package/dist/graphql/directive.d.ts +4 -4
- package/dist/graphql/directive.d.ts.map +1 -1
- package/dist/graphql/directive.js +3 -3
- package/dist/graphql/enum.d.ts +4 -4
- package/dist/graphql/enum.d.ts.map +1 -1
- package/dist/graphql/enum.js +2 -2
- package/dist/graphql/input.d.ts.map +1 -1
- package/dist/graphql/input.js +1 -1
- package/dist/graphql/interface.d.ts.map +1 -1
- package/dist/graphql/interface.js +1 -1
- package/dist/graphql/object.d.ts +3 -3
- package/dist/graphql/object.d.ts.map +1 -1
- package/dist/graphql/object.js +4 -4
- package/dist/graphql/operation.d.ts +4 -12
- package/dist/graphql/operation.d.ts.map +1 -1
- package/dist/graphql/operation.js +43 -11
- package/dist/graphql/scalar.d.ts +6 -6
- package/dist/graphql/scalar.d.ts.map +1 -1
- package/dist/graphql/scalar.js +7 -7
- package/dist/graphql/union.d.ts +4 -4
- package/dist/graphql/union.d.ts.map +1 -1
- package/dist/graphql/union.js +2 -2
- package/dist/group.d.ts +2 -2
- package/dist/group.d.ts.map +1 -1
- package/dist/group.js +7 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/link.d.ts +6 -14
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +9 -9
- package/dist/mdx/index.d.ts +1 -1
- package/dist/mdx/index.d.ts.map +1 -1
- package/dist/mdx/index.js +2 -2
- package/dist/printer.d.ts +51 -34
- package/dist/printer.d.ts.map +1 -1
- package/dist/printer.js +234 -118
- package/dist/relation.d.ts +2 -2
- package/dist/relation.d.ts.map +1 -1
- package/dist/section.d.ts +5 -5
- package/dist/section.d.ts.map +1 -1
- package/dist/section.js +26 -11
- package/package.json +18 -6
package/dist/printer.js
CHANGED
|
@@ -20,7 +20,22 @@ const PrintTypeEvents = {
|
|
|
20
20
|
AFTER_PRINT_CODE: "print:afterPrintCode",
|
|
21
21
|
BEFORE_PRINT_TYPE: "print:beforePrintType",
|
|
22
22
|
AFTER_PRINT_TYPE: "print:afterPrintType",
|
|
23
|
+
BEFORE_COMPOSE_PAGE_TYPE: "print:beforeComposePageType",
|
|
23
24
|
};
|
|
25
|
+
const TYPE_PAGE_HEADER_ORDER = [
|
|
26
|
+
"header",
|
|
27
|
+
"metatags",
|
|
28
|
+
"mdxDeclaration",
|
|
29
|
+
];
|
|
30
|
+
const TYPE_PAGE_SECTION_ORDER = [
|
|
31
|
+
"tags",
|
|
32
|
+
"description",
|
|
33
|
+
"code",
|
|
34
|
+
"customDirectives",
|
|
35
|
+
"metadata",
|
|
36
|
+
"example",
|
|
37
|
+
"relations",
|
|
38
|
+
];
|
|
24
39
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
25
40
|
const utils_1 = require("@graphql-markdown/utils");
|
|
26
41
|
const relation_1 = require("./relation");
|
|
@@ -33,6 +48,7 @@ const strings_1 = require("./const/strings");
|
|
|
33
48
|
const formatter_1 = require("./formatter");
|
|
34
49
|
const options_1 = require("./const/options");
|
|
35
50
|
const example_1 = require("./example");
|
|
51
|
+
const events_1 = require("./events");
|
|
36
52
|
/**
|
|
37
53
|
* Default initialization options for the Printer class.
|
|
38
54
|
* @internal
|
|
@@ -42,6 +58,24 @@ const DEFAULT_INIT_OPTIONS = {
|
|
|
42
58
|
groups: undefined,
|
|
43
59
|
sectionHeaderId: true,
|
|
44
60
|
};
|
|
61
|
+
const normalizeHierarchy = (hierarchy) => {
|
|
62
|
+
if (!hierarchy) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
if (typeof hierarchy !== "string") {
|
|
66
|
+
return hierarchy;
|
|
67
|
+
}
|
|
68
|
+
switch (hierarchy.toLowerCase()) {
|
|
69
|
+
case "entity":
|
|
70
|
+
return { entity: {} };
|
|
71
|
+
case "flat":
|
|
72
|
+
return { flat: {} };
|
|
73
|
+
case "api":
|
|
74
|
+
return { api: {} };
|
|
75
|
+
default:
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
45
79
|
/**
|
|
46
80
|
* The Printer class implements the core functionality for generating Markdown documentation
|
|
47
81
|
* from GraphQL schema types.
|
|
@@ -61,16 +95,6 @@ const DEFAULT_INIT_OPTIONS = {
|
|
|
61
95
|
* ```
|
|
62
96
|
*/
|
|
63
97
|
class Printer {
|
|
64
|
-
/**
|
|
65
|
-
* Global printer configuration options
|
|
66
|
-
*/
|
|
67
|
-
static options;
|
|
68
|
-
/**
|
|
69
|
-
* Optional event emitter for print events.
|
|
70
|
-
* When set, the printer will emit events before/after printCode and printType,
|
|
71
|
-
* allowing external code to intercept and modify the output.
|
|
72
|
-
*/
|
|
73
|
-
static eventEmitter;
|
|
74
98
|
/**
|
|
75
99
|
* Prints type descriptions
|
|
76
100
|
*/
|
|
@@ -83,10 +107,38 @@ class Printer {
|
|
|
83
107
|
* Prints custom tags
|
|
84
108
|
*/
|
|
85
109
|
static printCustomTags = directive_1.printCustomTags;
|
|
110
|
+
static _eventEmitter;
|
|
111
|
+
static _options;
|
|
112
|
+
static _mdxDeclaration;
|
|
113
|
+
/**
|
|
114
|
+
* Global printer configuration options
|
|
115
|
+
*/
|
|
116
|
+
static get options() {
|
|
117
|
+
return Printer._options;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Optional event emitter for print events.
|
|
121
|
+
* When set, the printer will emit events before/after printCode and printType,
|
|
122
|
+
* allowing external code to intercept and modify the output.
|
|
123
|
+
*/
|
|
124
|
+
static get eventEmitter() {
|
|
125
|
+
return Printer._eventEmitter;
|
|
126
|
+
}
|
|
86
127
|
/**
|
|
87
128
|
* Prints mdx modules import declaration
|
|
88
129
|
*/
|
|
89
|
-
static mdxDeclaration
|
|
130
|
+
static get mdxDeclaration() {
|
|
131
|
+
return Printer._mdxDeclaration;
|
|
132
|
+
}
|
|
133
|
+
static set options(options) {
|
|
134
|
+
Printer._options = options;
|
|
135
|
+
}
|
|
136
|
+
static set eventEmitter(eventEmitter) {
|
|
137
|
+
Printer._eventEmitter = eventEmitter;
|
|
138
|
+
}
|
|
139
|
+
static set mdxDeclaration(mdxDeclaration) {
|
|
140
|
+
Printer._mdxDeclaration = mdxDeclaration;
|
|
141
|
+
}
|
|
90
142
|
/**
|
|
91
143
|
* Initializes the printer with the given schema and configuration.
|
|
92
144
|
*
|
|
@@ -98,38 +150,38 @@ class Printer {
|
|
|
98
150
|
* @param mdxDeclaration - Optional MDX import declaration
|
|
99
151
|
* @param eventEmitter - Optional event emitter for print events interception
|
|
100
152
|
*/
|
|
101
|
-
static async init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, groups, meta, metatags, onlyDocDirectives, printTypeOptions, skipDocDirectives, sectionHeaderId, } = DEFAULT_INIT_OPTIONS, formatter, mdxDeclaration, eventEmitter) {
|
|
153
|
+
static async init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, deprecated, groups, meta, metatags, onlyDocDirectives, printTypeOptions, skipDocDirectives, sectionHeaderId, } = DEFAULT_INIT_OPTIONS, formatter, mdxDeclaration, eventEmitter) {
|
|
102
154
|
// Always update eventEmitter regardless of initialization state
|
|
103
155
|
Printer.eventEmitter = eventEmitter ?? null;
|
|
104
|
-
if (Printer.options
|
|
105
|
-
|
|
156
|
+
if (Printer.options === undefined) {
|
|
157
|
+
Printer.options = {
|
|
158
|
+
...options_1.DEFAULT_OPTIONS,
|
|
159
|
+
basePath: utils_1.pathUrl.join(linkRoot ?? "", baseURL ?? ""),
|
|
160
|
+
customDirectives,
|
|
161
|
+
exampleSection: typeof printTypeOptions?.exampleSection === "object"
|
|
162
|
+
? printTypeOptions.exampleSection
|
|
163
|
+
: undefined,
|
|
164
|
+
groups,
|
|
165
|
+
parentTypePrefix: printTypeOptions?.parentTypePrefix ??
|
|
166
|
+
options_1.PRINT_TYPE_DEFAULT_OPTIONS.parentTypePrefix,
|
|
167
|
+
deprecated: printTypeOptions?.deprecated ??
|
|
168
|
+
deprecated ??
|
|
169
|
+
options_1.PRINT_TYPE_DEFAULT_OPTIONS.deprecated,
|
|
170
|
+
schema,
|
|
171
|
+
onlyDocDirectives: onlyDocDirectives ?? [],
|
|
172
|
+
skipDocDirectives: skipDocDirectives ?? [],
|
|
173
|
+
sectionHeaderId: sectionHeaderId ?? options_1.DEFAULT_OPTIONS.sectionHeaderId,
|
|
174
|
+
typeBadges: printTypeOptions?.typeBadges ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.typeBadges,
|
|
175
|
+
metatags: metatags ?? [],
|
|
176
|
+
hierarchy: normalizeHierarchy(printTypeOptions?.hierarchy) ??
|
|
177
|
+
options_1.PRINT_TYPE_DEFAULT_OPTIONS.hierarchy,
|
|
178
|
+
meta: meta,
|
|
179
|
+
// Merge formatter functions: default formatter with any overrides
|
|
180
|
+
...(0, formatter_1.createDefaultFormatter)(),
|
|
181
|
+
...formatter,
|
|
182
|
+
};
|
|
183
|
+
Printer.mdxDeclaration = mdxDeclaration ?? "";
|
|
106
184
|
}
|
|
107
|
-
Printer.options = {
|
|
108
|
-
...options_1.DEFAULT_OPTIONS,
|
|
109
|
-
basePath: utils_1.pathUrl.join(linkRoot ?? "", baseURL ?? ""),
|
|
110
|
-
codeSection: printTypeOptions?.codeSection ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.codeSection,
|
|
111
|
-
customDirectives,
|
|
112
|
-
exampleSection: printTypeOptions?.exampleSection ??
|
|
113
|
-
options_1.PRINT_TYPE_DEFAULT_OPTIONS.exampleSection,
|
|
114
|
-
groups,
|
|
115
|
-
parentTypePrefix: printTypeOptions?.parentTypePrefix ??
|
|
116
|
-
options_1.PRINT_TYPE_DEFAULT_OPTIONS.parentTypePrefix,
|
|
117
|
-
deprecated: printTypeOptions?.deprecated ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.deprecated,
|
|
118
|
-
relatedTypeSection: printTypeOptions?.relatedTypeSection ??
|
|
119
|
-
options_1.PRINT_TYPE_DEFAULT_OPTIONS.relatedTypeSection,
|
|
120
|
-
schema,
|
|
121
|
-
onlyDocDirectives: onlyDocDirectives ?? [],
|
|
122
|
-
skipDocDirectives: skipDocDirectives ?? [],
|
|
123
|
-
sectionHeaderId: sectionHeaderId ?? options_1.DEFAULT_OPTIONS.sectionHeaderId,
|
|
124
|
-
typeBadges: printTypeOptions?.typeBadges ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.typeBadges,
|
|
125
|
-
metatags: metatags ?? [],
|
|
126
|
-
hierarchy: printTypeOptions?.hierarchy ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.hierarchy,
|
|
127
|
-
meta: meta,
|
|
128
|
-
// Merge formatter functions: default formatter with any overrides
|
|
129
|
-
...(0, formatter_1.createDefaultFormatter)(),
|
|
130
|
-
...formatter,
|
|
131
|
-
};
|
|
132
|
-
Printer.mdxDeclaration = mdxDeclaration ?? "";
|
|
133
185
|
}
|
|
134
186
|
/**
|
|
135
187
|
* Prints the header section of a type documentation
|
|
@@ -154,9 +206,6 @@ class Printer {
|
|
|
154
206
|
* @returns Formatted code block string with type definition
|
|
155
207
|
*/
|
|
156
208
|
static printCode = (type, options) => {
|
|
157
|
-
if (options.codeSection === undefined || options.codeSection !== true) {
|
|
158
|
-
return "";
|
|
159
|
-
}
|
|
160
209
|
let code = "";
|
|
161
210
|
switch (true) {
|
|
162
211
|
case (0, graphql_1.isOperation)(type):
|
|
@@ -214,14 +263,7 @@ class Printer {
|
|
|
214
263
|
// Create mutable event data - handlers can modify options
|
|
215
264
|
const eventData = { type, typeName, options: { ...options } };
|
|
216
265
|
// Emit BEFORE event - handlers can modify inputs or prevent default
|
|
217
|
-
const beforeEvent =
|
|
218
|
-
data: eventData,
|
|
219
|
-
output: "",
|
|
220
|
-
defaultPrevented: false,
|
|
221
|
-
preventDefault() {
|
|
222
|
-
this.defaultPrevented = true;
|
|
223
|
-
},
|
|
224
|
-
};
|
|
266
|
+
const beforeEvent = new events_1.PrintCodeEvent(eventData, "");
|
|
225
267
|
await Printer.eventEmitter.emitAsync(PrintTypeEvents.BEFORE_PRINT_CODE, beforeEvent);
|
|
226
268
|
// If prevented, handlers should have set the output they want
|
|
227
269
|
if (beforeEvent.defaultPrevented) {
|
|
@@ -230,10 +272,7 @@ class Printer {
|
|
|
230
272
|
// Generate code using the (potentially modified) options from event data
|
|
231
273
|
const output = Printer.printCode(type, eventData.options);
|
|
232
274
|
// Emit AFTER event - handlers can modify the output
|
|
233
|
-
const afterEvent =
|
|
234
|
-
data: eventData,
|
|
235
|
-
output,
|
|
236
|
-
};
|
|
275
|
+
const afterEvent = new events_1.PrintCodeEvent(eventData, output);
|
|
237
276
|
await Printer.eventEmitter.emitAsync(PrintTypeEvents.AFTER_PRINT_CODE, afterEvent);
|
|
238
277
|
return afterEvent.output;
|
|
239
278
|
};
|
|
@@ -242,27 +281,24 @@ class Printer {
|
|
|
242
281
|
*
|
|
243
282
|
* @param type - GraphQL type to generate example for
|
|
244
283
|
* @param options - Printer configuration options
|
|
245
|
-
* @returns
|
|
284
|
+
* @returns Example page section or undefined when no example is available
|
|
246
285
|
*/
|
|
247
286
|
static printExample = (type, options) => {
|
|
248
|
-
if (options.exampleSection === undefined ||
|
|
249
|
-
options.exampleSection === null ||
|
|
250
|
-
options.exampleSection === false) {
|
|
251
|
-
return "";
|
|
252
|
-
}
|
|
253
287
|
const example = (0, example_1.printExample)(type, options);
|
|
254
288
|
if (!example) {
|
|
255
|
-
return
|
|
289
|
+
return undefined;
|
|
256
290
|
}
|
|
257
|
-
return
|
|
291
|
+
return {
|
|
292
|
+
content: `${strings_1.MARKDOWN_SOC}${example}${strings_1.MARKDOWN_EOC}${strings_1.MARKDOWN_EOP}`,
|
|
293
|
+
title: "Example",
|
|
294
|
+
};
|
|
258
295
|
};
|
|
259
296
|
/**
|
|
260
297
|
* Prints metadata information for a GraphQL type
|
|
261
298
|
*
|
|
262
299
|
* @param type - GraphQL type to print metadata for
|
|
263
300
|
* @param options - Printer configuration options
|
|
264
|
-
* @returns
|
|
265
|
-
* @throws When type is not supported
|
|
301
|
+
* @returns Metadata section (or section list) for supported types, otherwise undefined
|
|
266
302
|
*/
|
|
267
303
|
static printTypeMetadata = (type, options) => {
|
|
268
304
|
switch (true) {
|
|
@@ -283,7 +319,7 @@ class Printer {
|
|
|
283
319
|
case (0, graphql_1.isOperation)(type):
|
|
284
320
|
return (0, graphql_2.printOperationMetadata)(type, options);
|
|
285
321
|
default:
|
|
286
|
-
return
|
|
322
|
+
return undefined;
|
|
287
323
|
}
|
|
288
324
|
};
|
|
289
325
|
/**
|
|
@@ -294,9 +330,6 @@ class Printer {
|
|
|
294
330
|
* @returns Formatted relations section as MDX or plain string
|
|
295
331
|
*/
|
|
296
332
|
static printRelations = (type, options) => {
|
|
297
|
-
if (options.relatedTypeSection !== true) {
|
|
298
|
-
return "";
|
|
299
|
-
}
|
|
300
333
|
return (0, relation_1.printRelations)(type, options);
|
|
301
334
|
};
|
|
302
335
|
/**
|
|
@@ -329,8 +362,7 @@ class Printer {
|
|
|
329
362
|
* @example
|
|
330
363
|
* ```typescript
|
|
331
364
|
* const doc = await Printer.printType('User', UserType, {
|
|
332
|
-
* frontMatter: true
|
|
333
|
-
* codeSection: true
|
|
365
|
+
* frontMatter: true
|
|
334
366
|
* });
|
|
335
367
|
* ```
|
|
336
368
|
*
|
|
@@ -347,6 +379,7 @@ class Printer {
|
|
|
347
379
|
*
|
|
348
380
|
* When an event emitter is configured, emits events:
|
|
349
381
|
* - `print:beforePrintType` - Before generating documentation
|
|
382
|
+
* - `print:beforeComposePageType` - Before composing section order and final page output
|
|
350
383
|
* - `print:afterPrintType` - After generating documentation (output can be modified)
|
|
351
384
|
*/
|
|
352
385
|
static printType = async (name, type, options) => {
|
|
@@ -362,21 +395,7 @@ class Printer {
|
|
|
362
395
|
const eventData = { type, name, options: printTypeOptions };
|
|
363
396
|
// Emit BEFORE_PRINT_TYPE event if emitter is configured
|
|
364
397
|
if (Printer.eventEmitter) {
|
|
365
|
-
const beforeEvent =
|
|
366
|
-
data: eventData,
|
|
367
|
-
output: undefined,
|
|
368
|
-
defaultPrevented: false,
|
|
369
|
-
propagationStopped: false,
|
|
370
|
-
preventDefault() {
|
|
371
|
-
this.defaultPrevented = true;
|
|
372
|
-
},
|
|
373
|
-
stopPropagation() {
|
|
374
|
-
this.propagationStopped = true;
|
|
375
|
-
},
|
|
376
|
-
async runDefaultAction() {
|
|
377
|
-
return void 0;
|
|
378
|
-
},
|
|
379
|
-
};
|
|
398
|
+
const beforeEvent = new events_1.PrintTypeEvent(eventData, undefined);
|
|
380
399
|
await Printer.eventEmitter.emitAsync(PrintTypeEvents.BEFORE_PRINT_TYPE, beforeEvent);
|
|
381
400
|
// If prevented, return the output set by handlers (or undefined)
|
|
382
401
|
if (beforeEvent.defaultPrevented) {
|
|
@@ -386,50 +405,147 @@ class Printer {
|
|
|
386
405
|
const header = Printer.printHeader(name, (0, graphql_1.getTypeName)(type), printTypeOptions);
|
|
387
406
|
const metatags = Printer.printMetaTags(type, printTypeOptions);
|
|
388
407
|
const description = Printer.printDescription(type, printTypeOptions);
|
|
389
|
-
//
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
408
|
+
// Generate all sections unconditionally so that BEFORE_COMPOSE_PAGE_TYPE hooks
|
|
409
|
+
// can add, remove, or reorder them at will.
|
|
410
|
+
// See: https://github.com/graphql-markdown/graphql-markdown/issues/2954
|
|
411
|
+
const code = await Printer.printCodeAsync(type, name, printTypeOptions);
|
|
393
412
|
const customDirectives = Printer.printCustomDirectives(type, printTypeOptions);
|
|
394
413
|
const tags = Printer.printCustomTags(type, printTypeOptions);
|
|
395
414
|
const metadata = Printer.printTypeMetadata(type, printTypeOptions);
|
|
396
415
|
const relations = Printer.printRelations(type, printTypeOptions);
|
|
397
416
|
const example = Printer.printExample(type, printTypeOptions);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
417
|
+
// Create sections map for composition events
|
|
418
|
+
const sections = {
|
|
419
|
+
header: { content: header },
|
|
420
|
+
metatags: { content: metatags },
|
|
421
|
+
mdxDeclaration: { content: Printer.mdxDeclaration ?? "" },
|
|
422
|
+
tags: Printer.normalizePageSection(tags),
|
|
423
|
+
description: Printer.normalizePageSection(description),
|
|
424
|
+
code: Printer.normalizePageSection(code),
|
|
425
|
+
customDirectives: Printer.normalizePageSection(customDirectives),
|
|
426
|
+
metadata: Printer.normalizePageSection(metadata),
|
|
427
|
+
example: Printer.normalizePageSection(example),
|
|
428
|
+
relations: Printer.normalizePageSection(relations),
|
|
429
|
+
};
|
|
430
|
+
let sectionOrder = [...TYPE_PAGE_SECTION_ORDER];
|
|
431
|
+
// Emit BEFORE_COMPOSE_PAGE_TYPE event if emitter is configured
|
|
432
|
+
if (Printer.eventEmitter) {
|
|
433
|
+
const beforeComposeEvent = new events_1.BeforeComposePageTypeEvent({ type, name, options: printTypeOptions, sections }, sectionOrder);
|
|
434
|
+
await Printer.eventEmitter.emitAsync(PrintTypeEvents.BEFORE_COMPOSE_PAGE_TYPE, beforeComposeEvent);
|
|
435
|
+
sectionOrder = Printer.sanitizeTypePageSectionOrder(beforeComposeEvent.output, sections);
|
|
436
|
+
}
|
|
437
|
+
// Compose output based on section order
|
|
438
|
+
const pageSections = [
|
|
439
|
+
...TYPE_PAGE_HEADER_ORDER,
|
|
440
|
+
...sectionOrder,
|
|
441
|
+
];
|
|
442
|
+
let output = pageSections
|
|
443
|
+
.map((key) => {
|
|
444
|
+
return Printer.renderPageSection(sections[key]);
|
|
445
|
+
})
|
|
446
|
+
.filter((section) => {
|
|
447
|
+
return section.length > 0;
|
|
448
|
+
})
|
|
410
449
|
.join(strings_1.MARKDOWN_EOP)
|
|
411
450
|
.trim();
|
|
412
451
|
// Emit AFTER_PRINT_TYPE event if emitter is configured
|
|
413
452
|
if (Printer.eventEmitter) {
|
|
414
|
-
const afterEvent =
|
|
415
|
-
data: eventData,
|
|
416
|
-
output,
|
|
417
|
-
defaultPrevented: false,
|
|
418
|
-
propagationStopped: false,
|
|
419
|
-
preventDefault() {
|
|
420
|
-
this.defaultPrevented = true;
|
|
421
|
-
},
|
|
422
|
-
stopPropagation() {
|
|
423
|
-
this.propagationStopped = true;
|
|
424
|
-
},
|
|
425
|
-
async runDefaultAction() {
|
|
426
|
-
return void 0;
|
|
427
|
-
},
|
|
428
|
-
};
|
|
453
|
+
const afterEvent = new events_1.PrintTypeEvent(eventData, output);
|
|
429
454
|
await Printer.eventEmitter.emitAsync(PrintTypeEvents.AFTER_PRINT_TYPE, afterEvent);
|
|
430
|
-
output = afterEvent.output;
|
|
455
|
+
output = afterEvent.output ?? output;
|
|
431
456
|
}
|
|
432
457
|
return output;
|
|
433
458
|
};
|
|
459
|
+
/**
|
|
460
|
+
* Renders a page section, optionally prefixing a heading when a title is present.
|
|
461
|
+
*/
|
|
462
|
+
static renderPageSection = (section) => {
|
|
463
|
+
if (!section ||
|
|
464
|
+
typeof section !== "object" ||
|
|
465
|
+
Array.isArray(section) ||
|
|
466
|
+
(!("content" in section) && !("title" in section))) {
|
|
467
|
+
return "";
|
|
468
|
+
}
|
|
469
|
+
let content;
|
|
470
|
+
if (!("content" in section) || !section.content) {
|
|
471
|
+
content = "";
|
|
472
|
+
}
|
|
473
|
+
else if (Array.isArray(section.content)) {
|
|
474
|
+
content = section.content
|
|
475
|
+
.map((entry) => {
|
|
476
|
+
return Printer.renderPageSection(entry);
|
|
477
|
+
})
|
|
478
|
+
.filter((entry) => {
|
|
479
|
+
return entry.length > 0;
|
|
480
|
+
})
|
|
481
|
+
.join(strings_1.MARKDOWN_EOP);
|
|
482
|
+
}
|
|
483
|
+
else if (typeof section.content === "string") {
|
|
484
|
+
content = section.content;
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
content = Printer.renderPageSection(section.content);
|
|
488
|
+
}
|
|
489
|
+
if (!("title" in section) || typeof section.title !== "string") {
|
|
490
|
+
if (!content || content.trim().length === 0) {
|
|
491
|
+
return "";
|
|
492
|
+
}
|
|
493
|
+
return content;
|
|
494
|
+
}
|
|
495
|
+
if (!section.title || section.title.trim().length === 0) {
|
|
496
|
+
if (!content || content.trim().length === 0) {
|
|
497
|
+
return "";
|
|
498
|
+
}
|
|
499
|
+
return content;
|
|
500
|
+
}
|
|
501
|
+
const level = Math.max(1, section.level ?? 3);
|
|
502
|
+
const title = `${options_1.SectionLevels.LEVEL.repeat(level)} ${section.title}${strings_1.MARKDOWN_EOP}`;
|
|
503
|
+
if (!content || content.trim().length === 0) {
|
|
504
|
+
return title;
|
|
505
|
+
}
|
|
506
|
+
return `${title}${content}`;
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
509
|
+
* Runtime guard for built-in page content section keys.
|
|
510
|
+
*/
|
|
511
|
+
static isTypePageContentSection = (section) => {
|
|
512
|
+
return (typeof section === "string" &&
|
|
513
|
+
TYPE_PAGE_SECTION_ORDER.includes(section));
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* Runtime guard for header-only page section keys.
|
|
517
|
+
*/
|
|
518
|
+
static isTypePageHeaderSection = (section) => {
|
|
519
|
+
return (typeof section === "string" &&
|
|
520
|
+
TYPE_PAGE_HEADER_ORDER.includes(section));
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* Normalizes event-driven section order, allowing built-in section keys and
|
|
524
|
+
* any custom keys that were added to the sections map by an event handler.
|
|
525
|
+
* Keys that are neither built-in nor present in the sections map are dropped.
|
|
526
|
+
*/
|
|
527
|
+
static sanitizeTypePageSectionOrder = (sectionOrder, sections) => {
|
|
528
|
+
if (!Array.isArray(sectionOrder)) {
|
|
529
|
+
return [];
|
|
530
|
+
}
|
|
531
|
+
return sectionOrder.filter((section) => {
|
|
532
|
+
return (typeof section === "string" &&
|
|
533
|
+
!Printer.isTypePageHeaderSection(section) &&
|
|
534
|
+
(Printer.isTypePageContentSection(section) ||
|
|
535
|
+
Object.hasOwn(sections, section)));
|
|
536
|
+
});
|
|
537
|
+
};
|
|
538
|
+
/**
|
|
539
|
+
* Normalizes mixed section value shapes to the internal PageSection format.
|
|
540
|
+
*/
|
|
541
|
+
static normalizePageSection = (section) => {
|
|
542
|
+
if (!section) {
|
|
543
|
+
return undefined;
|
|
544
|
+
}
|
|
545
|
+
if (typeof section === "string" || Array.isArray(section)) {
|
|
546
|
+
return { content: section };
|
|
547
|
+
}
|
|
548
|
+
return section;
|
|
549
|
+
};
|
|
434
550
|
}
|
|
435
551
|
exports.Printer = Printer;
|
package/dist/relation.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare const getRootTypeLocaleFromString: (text: string) => Maybe<TypeLo
|
|
|
28
28
|
* const mdx = printRelationOf(type, "Member Of", getRelationOfField, options);
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export declare const printRelationOf: <T>(type: unknown, section: unknown, getRelation: Maybe<IGetRelation<T>>, options: PrintTypeOptions) =>
|
|
31
|
+
export declare const printRelationOf: <T>(type: unknown, section: unknown, getRelation: Maybe<IGetRelation<T>>, options: PrintTypeOptions) => MDXString | string;
|
|
32
32
|
/**
|
|
33
33
|
* Prints all relations (return types, member fields, and implementations) for a given type
|
|
34
34
|
* @param type - The GraphQL type to get all relations for
|
|
@@ -40,5 +40,5 @@ export declare const printRelationOf: <T>(type: unknown, section: unknown, getRe
|
|
|
40
40
|
* const relations = printRelations(myType, { schema, formatMDXBullet: () => "* " });
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
export declare const printRelations: (type: unknown, options: PrintTypeOptions) =>
|
|
43
|
+
export declare const printRelations: (type: unknown, options: PrintTypeOptions) => MDXString | string;
|
|
44
44
|
//# sourceMappingURL=relation.d.ts.map
|
package/dist/relation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation.d.ts","sourceRoot":"","sources":["../src/relation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,KAAK,EACL,gBAAgB,EAGhB,UAAU,EACX,MAAM,yBAAyB,CAAC;AAgBjC;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,
|
|
1
|
+
{"version":3,"file":"relation.d.ts","sourceRoot":"","sources":["../src/relation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,KAAK,EACL,gBAAgB,EAGhB,UAAU,EACX,MAAM,yBAAyB,CAAC;AAgBjC;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,SAChC,MAAM,KACX,KAAK,CAAC,UAAU,CAOlB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,QACzB,OAAO,WACJ,OAAO,eACH,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,WAC1B,gBAAgB,KACxB,SAAS,GAAG,MAmDd,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,SACnB,OAAO,WACJ,gBAAgB,KACxB,SAAS,GAAG,MAgBd,CAAC"}
|
package/dist/section.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Handles the printing of section items, metadata, and structured documentation content.
|
|
4
4
|
* @module section
|
|
5
5
|
*/
|
|
6
|
-
import type { MDXString, PrintTypeOptions } from "@graphql-markdown/types";
|
|
6
|
+
import type { Maybe, MDXString, PageSection, PrintTypeOptions } from "@graphql-markdown/types";
|
|
7
7
|
/**
|
|
8
8
|
* Prints a single section item with its associated metadata.
|
|
9
9
|
*
|
|
@@ -13,7 +13,7 @@ import type { MDXString, PrintTypeOptions } from "@graphql-markdown/types";
|
|
|
13
13
|
*
|
|
14
14
|
* @template T - Type of the GraphQL element being printed
|
|
15
15
|
*/
|
|
16
|
-
export declare const printSectionItem: <T>(type: T, options: PrintTypeOptions) =>
|
|
16
|
+
export declare const printSectionItem: <T>(type: T, options: PrintTypeOptions) => MDXString | string;
|
|
17
17
|
/**
|
|
18
18
|
* Prints an array of section items with consistent formatting.
|
|
19
19
|
*
|
|
@@ -23,7 +23,7 @@ export declare const printSectionItem: <T>(type: T, options: PrintTypeOptions) =
|
|
|
23
23
|
*
|
|
24
24
|
* @template V - Type of the values being printed
|
|
25
25
|
*/
|
|
26
|
-
export declare const printSectionItems: <V>(values: V | V[], options: PrintTypeOptions) =>
|
|
26
|
+
export declare const printSectionItems: <V>(values: V | V[], options: PrintTypeOptions) => MDXString | string;
|
|
27
27
|
/**
|
|
28
28
|
* Prints a complete section with title and content.
|
|
29
29
|
*
|
|
@@ -34,7 +34,7 @@ export declare const printSectionItems: <V>(values: V | V[], options: PrintTypeO
|
|
|
34
34
|
*
|
|
35
35
|
* @template V - Type of the values being printed
|
|
36
36
|
*/
|
|
37
|
-
export declare const printSection: <V>(values: V[] | readonly V[], section: string, options: PrintTypeOptions) =>
|
|
37
|
+
export declare const printSection: <V>(values: V[] | readonly V[], section: string, options: PrintTypeOptions) => Maybe<PageSection>;
|
|
38
38
|
/**
|
|
39
39
|
* Prints a metadata section with special handling for deprecated items.
|
|
40
40
|
*
|
|
@@ -47,5 +47,5 @@ export declare const printSection: <V>(values: V[] | readonly V[], section: stri
|
|
|
47
47
|
* @template T - Type of the parent element
|
|
48
48
|
* @template V - Type of the values being printed
|
|
49
49
|
*/
|
|
50
|
-
export declare const printMetadataSection: <T, V>(type: T, values: V | V[] | readonly V[], section: string, options: PrintTypeOptions) =>
|
|
50
|
+
export declare const printMetadataSection: <T, V>(type: T, values: V | V[] | readonly V[], section: string, options: PrintTypeOptions) => Maybe<PageSection>;
|
|
51
51
|
//# sourceMappingURL=section.d.ts.map
|
package/dist/section.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section.d.ts","sourceRoot":"","sources":["../src/section.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,SAAS,EACT,gBAAgB,EAEjB,MAAM,yBAAyB,CAAC;AAuBjC;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"section.d.ts","sourceRoot":"","sources":["../src/section.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,KAAK,EACL,SAAS,EACT,WAAW,EACX,gBAAgB,EAEjB,MAAM,yBAAyB,CAAC;AAuBjC;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,QAC1B,CAAC,WACE,gBAAgB,KACxB,SAAS,GAAG,MAgDd,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,UACzB,CAAC,GAAG,CAAC,EAAE,WACN,gBAAgB,KACxB,SAAS,GAAG,MAiBd,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,UACpB,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,WACjB,MAAM,WACN,gBAAgB,KACxB,KAAK,CAAC,WAAW,CAmCnB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,EAAE,CAAC,QACjC,CAAC,UACC,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,WACrB,MAAM,WACN,gBAAgB,KACxB,KAAK,CAAC,WAAW,CAqEnB,CAAC"}
|
package/dist/section.js
CHANGED
|
@@ -72,11 +72,7 @@ const printSectionItems = (values, options) => {
|
|
|
72
72
|
return "";
|
|
73
73
|
}
|
|
74
74
|
const level = ("level" in options && typeof options.level === "number" ? options.level : 4);
|
|
75
|
-
const items = values
|
|
76
|
-
.filter((v) => {
|
|
77
|
-
return v;
|
|
78
|
-
})
|
|
79
|
-
.map((v) => {
|
|
75
|
+
const items = values.filter(Boolean).map((v) => {
|
|
80
76
|
return (0, exports.printSectionItem)(v, {
|
|
81
77
|
...options,
|
|
82
78
|
level,
|
|
@@ -97,7 +93,7 @@ exports.printSectionItems = printSectionItems;
|
|
|
97
93
|
*/
|
|
98
94
|
const printSection = (values, section, options) => {
|
|
99
95
|
if (!Array.isArray(values) || values.length === 0) {
|
|
100
|
-
return
|
|
96
|
+
return undefined;
|
|
101
97
|
}
|
|
102
98
|
const level = ("level" in options && typeof options.level === "number" ? options.level : 3);
|
|
103
99
|
const [openSection, closeSection] = (() => {
|
|
@@ -105,7 +101,7 @@ const printSection = (values, section, options) => {
|
|
|
105
101
|
typeof options.collapsible.dataClose === "string") {
|
|
106
102
|
return options.formatMDXDetails(options.collapsible).split(`\r`);
|
|
107
103
|
}
|
|
108
|
-
return [
|
|
104
|
+
return ["", strings_1.MARKDOWN_EOP];
|
|
109
105
|
})();
|
|
110
106
|
const items = (0, exports.printSectionItems)(values, {
|
|
111
107
|
...options,
|
|
@@ -113,9 +109,13 @@ const printSection = (values, section, options) => {
|
|
|
113
109
|
level: level >= 3 && level <= 5 ? (level + 1) : undefined,
|
|
114
110
|
});
|
|
115
111
|
if (items === "") {
|
|
116
|
-
return
|
|
112
|
+
return undefined; // do not print section is no items printed
|
|
117
113
|
}
|
|
118
|
-
return
|
|
114
|
+
return {
|
|
115
|
+
title: section,
|
|
116
|
+
content: `${openSection}${items}${closeSection}`,
|
|
117
|
+
level,
|
|
118
|
+
};
|
|
119
119
|
};
|
|
120
120
|
exports.printSection = printSection;
|
|
121
121
|
/**
|
|
@@ -136,7 +136,7 @@ const printMetadataSection = (type, values, section, options) => {
|
|
|
136
136
|
!("name" in type) ||
|
|
137
137
|
!Array.isArray(values) ||
|
|
138
138
|
values.length === 0) {
|
|
139
|
-
return
|
|
139
|
+
return undefined;
|
|
140
140
|
}
|
|
141
141
|
switch (options.deprecated) {
|
|
142
142
|
case "group": {
|
|
@@ -162,7 +162,22 @@ const printMetadataSection = (type, values, section, options) => {
|
|
|
162
162
|
dataClose: strings_1.DEPRECATED,
|
|
163
163
|
},
|
|
164
164
|
});
|
|
165
|
-
|
|
165
|
+
const content = [meta?.content, deprecatedMeta?.content]
|
|
166
|
+
.filter((entry) => {
|
|
167
|
+
return typeof entry === "string";
|
|
168
|
+
})
|
|
169
|
+
.join("");
|
|
170
|
+
if (content.trim().length === 0) {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
const level = ("level" in options && typeof options.level === "number"
|
|
174
|
+
? options.level
|
|
175
|
+
: 3);
|
|
176
|
+
return {
|
|
177
|
+
title: section,
|
|
178
|
+
content,
|
|
179
|
+
level,
|
|
180
|
+
};
|
|
166
181
|
}
|
|
167
182
|
case "default":
|
|
168
183
|
default:
|