@graphql-markdown/printer-legacy 1.12.3 → 1.13.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 +5 -4
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +15 -13
- package/dist/code.d.ts +2 -1
- package/dist/code.d.ts.map +1 -0
- package/dist/code.js +24 -22
- package/dist/common.d.ts +7 -8
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +3 -5
- package/dist/const/options.d.ts +2 -1
- package/dist/const/options.d.ts.map +1 -0
- package/dist/const/strings.d.ts +2 -5
- package/dist/const/strings.d.ts.map +1 -0
- package/dist/const/strings.js +10 -8
- package/dist/directive.d.ts +4 -3
- package/dist/directive.d.ts.map +1 -0
- package/dist/directive.js +10 -12
- package/dist/example.d.ts +1 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/format-helpers.d.ts +42 -0
- package/dist/format-helpers.d.ts.map +1 -0
- package/dist/format-helpers.js +74 -0
- package/dist/formatter.d.ts +28 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +63 -0
- package/dist/frontmatter.d.ts +1 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/graphql/directive.d.ts +3 -2
- package/dist/graphql/directive.d.ts.map +1 -0
- package/dist/graphql/directive.js +1 -1
- package/dist/graphql/enum.d.ts +3 -2
- package/dist/graphql/enum.d.ts.map +1 -0
- package/dist/graphql/index.d.ts +1 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/input.d.ts +2 -1
- package/dist/graphql/input.d.ts.map +1 -0
- package/dist/graphql/input.js +2 -1
- package/dist/graphql/interface.d.ts +2 -1
- package/dist/graphql/interface.d.ts.map +1 -0
- package/dist/graphql/interface.js +2 -1
- package/dist/graphql/object.d.ts +1 -0
- package/dist/graphql/object.d.ts.map +1 -0
- package/dist/graphql/operation.d.ts +4 -3
- package/dist/graphql/operation.d.ts.map +1 -0
- package/dist/graphql/operation.js +3 -3
- package/dist/graphql/scalar.d.ts +4 -3
- package/dist/graphql/scalar.d.ts.map +1 -0
- package/dist/graphql/union.d.ts +3 -2
- package/dist/graphql/union.d.ts.map +1 -0
- package/dist/group.d.ts +3 -2
- package/dist/group.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/link.d.ts +5 -7
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +12 -13
- package/dist/mdx/index.d.ts +2 -1
- package/dist/mdx/index.d.ts.map +1 -0
- package/dist/mdx/index.js +2 -2
- package/dist/printer.d.ts +47 -20
- package/dist/printer.d.ts.map +1 -0
- package/dist/printer.js +160 -36
- package/dist/relation.d.ts +8 -7
- package/dist/relation.d.ts.map +1 -0
- package/dist/relation.js +13 -14
- package/dist/section.d.ts +5 -4
- package/dist/section.d.ts.map +1 -0
- package/dist/section.js +11 -9
- package/package.json +10 -10
package/dist/printer.js
CHANGED
|
@@ -10,6 +10,17 @@
|
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Printer = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Print type event constants.
|
|
15
|
+
* Duplicated here to avoid circular dependency with \@graphql-markdown/core.
|
|
16
|
+
* These must match the values in core/src/events/print-type-events.ts
|
|
17
|
+
*/
|
|
18
|
+
const PrintTypeEvents = {
|
|
19
|
+
BEFORE_PRINT_CODE: "print:beforePrintCode",
|
|
20
|
+
AFTER_PRINT_CODE: "print:afterPrintCode",
|
|
21
|
+
BEFORE_PRINT_TYPE: "print:beforePrintType",
|
|
22
|
+
AFTER_PRINT_TYPE: "print:afterPrintType",
|
|
23
|
+
};
|
|
13
24
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
14
25
|
const utils_1 = require("@graphql-markdown/utils");
|
|
15
26
|
const relation_1 = require("./relation");
|
|
@@ -19,9 +30,17 @@ const frontmatter_1 = require("./frontmatter");
|
|
|
19
30
|
const graphql_2 = require("./graphql");
|
|
20
31
|
const link_1 = require("./link");
|
|
21
32
|
const strings_1 = require("./const/strings");
|
|
22
|
-
const
|
|
33
|
+
const formatter_1 = require("./formatter");
|
|
23
34
|
const options_1 = require("./const/options");
|
|
24
35
|
const example_1 = require("./example");
|
|
36
|
+
/**
|
|
37
|
+
* Default initialization options for the Printer class.
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
const DEFAULT_INIT_OPTIONS = {
|
|
41
|
+
customDirectives: undefined,
|
|
42
|
+
groups: undefined,
|
|
43
|
+
};
|
|
25
44
|
/**
|
|
26
45
|
* The Printer class implements the core functionality for generating Markdown documentation
|
|
27
46
|
* from GraphQL schema types.
|
|
@@ -43,29 +62,30 @@ const example_1 = require("./example");
|
|
|
43
62
|
class Printer {
|
|
44
63
|
/**
|
|
45
64
|
* Global printer configuration options
|
|
46
|
-
* @static
|
|
47
65
|
*/
|
|
48
66
|
static options;
|
|
67
|
+
/**
|
|
68
|
+
* Optional event emitter for print events.
|
|
69
|
+
* When set, the printer will emit events before/after printCode and printType,
|
|
70
|
+
* allowing external code to intercept and modify the output.
|
|
71
|
+
*/
|
|
72
|
+
static eventEmitter;
|
|
49
73
|
/**
|
|
50
74
|
* Prints type descriptions
|
|
51
|
-
* @static
|
|
52
75
|
*/
|
|
53
76
|
static printDescription = common_1.printDescription;
|
|
54
77
|
/**
|
|
55
78
|
* Prints custom directives
|
|
56
|
-
* @static
|
|
57
79
|
*/
|
|
58
80
|
static printCustomDirectives = directive_1.printCustomDirectives;
|
|
59
81
|
/**
|
|
60
82
|
* Prints custom tags
|
|
61
|
-
* @static
|
|
62
83
|
*/
|
|
63
84
|
static printCustomTags = directive_1.printCustomTags;
|
|
64
85
|
/**
|
|
65
|
-
*
|
|
66
|
-
* @static
|
|
86
|
+
* Prints mdx modules import declaration
|
|
67
87
|
*/
|
|
68
|
-
static
|
|
88
|
+
static mdxDeclaration;
|
|
69
89
|
/**
|
|
70
90
|
* Initializes the printer with the given schema and configuration.
|
|
71
91
|
*
|
|
@@ -73,13 +93,14 @@ class Printer {
|
|
|
73
93
|
* @param baseURL - Base URL path for documentation, e.g. '/docs'
|
|
74
94
|
* @param linkRoot - Root path for generating links between types
|
|
75
95
|
* @param options - Configuration options for the printer
|
|
76
|
-
* @param
|
|
96
|
+
* @param formatter - Optional formatter functions for customizing output format
|
|
97
|
+
* @param mdxDeclaration - Optional MDX import declaration
|
|
98
|
+
* @param eventEmitter - Optional event emitter for print events interception
|
|
77
99
|
*/
|
|
78
|
-
static async init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, groups, meta, metatags, onlyDocDirectives, printTypeOptions, skipDocDirectives, } = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (typeof Printer.options !== "undefined") {
|
|
100
|
+
static async init(schema, baseURL = "schema", linkRoot = "/", { customDirectives, groups, meta, metatags, onlyDocDirectives, printTypeOptions, skipDocDirectives, } = DEFAULT_INIT_OPTIONS, formatter, mdxDeclaration, eventEmitter) {
|
|
101
|
+
// Always update eventEmitter regardless of initialization state
|
|
102
|
+
Printer.eventEmitter = eventEmitter ?? null;
|
|
103
|
+
if (Printer.options !== undefined) {
|
|
83
104
|
return;
|
|
84
105
|
}
|
|
85
106
|
Printer.options = {
|
|
@@ -102,8 +123,11 @@ class Printer {
|
|
|
102
123
|
metatags: metatags ?? [],
|
|
103
124
|
hierarchy: printTypeOptions?.hierarchy ?? options_1.PRINT_TYPE_DEFAULT_OPTIONS.hierarchy,
|
|
104
125
|
meta: meta,
|
|
126
|
+
// Merge formatter functions: default formatter with any overrides
|
|
127
|
+
...(0, formatter_1.createDefaultFormatter)(),
|
|
128
|
+
...formatter,
|
|
105
129
|
};
|
|
106
|
-
Printer.
|
|
130
|
+
Printer.mdxDeclaration = mdxDeclaration ?? "";
|
|
107
131
|
}
|
|
108
132
|
/**
|
|
109
133
|
* Prints the header section of a type documentation
|
|
@@ -128,41 +152,89 @@ class Printer {
|
|
|
128
152
|
* @returns Formatted code block string with type definition
|
|
129
153
|
*/
|
|
130
154
|
static printCode = (type, options) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
options.codeSection !== true) {
|
|
134
|
-
return code;
|
|
155
|
+
if (options.codeSection === undefined || options.codeSection !== true) {
|
|
156
|
+
return "";
|
|
135
157
|
}
|
|
158
|
+
let code = "";
|
|
136
159
|
switch (true) {
|
|
137
160
|
case (0, graphql_1.isOperation)(type):
|
|
138
|
-
code
|
|
161
|
+
code = (0, graphql_2.printCodeOperation)(type, options);
|
|
139
162
|
break;
|
|
140
163
|
case (0, graphql_1.isEnumType)(type):
|
|
141
|
-
code
|
|
164
|
+
code = (0, graphql_2.printCodeEnum)(type, options);
|
|
142
165
|
break;
|
|
143
166
|
case (0, graphql_1.isUnionType)(type):
|
|
144
|
-
code
|
|
167
|
+
code = (0, graphql_2.printCodeUnion)(type, options);
|
|
145
168
|
break;
|
|
146
169
|
case (0, graphql_1.isInterfaceType)(type):
|
|
147
|
-
code
|
|
170
|
+
code = (0, graphql_2.printCodeInterface)(type, options);
|
|
148
171
|
break;
|
|
149
172
|
case (0, graphql_1.isObjectType)(type):
|
|
150
|
-
code
|
|
173
|
+
code = (0, graphql_2.printCodeObject)(type, options);
|
|
151
174
|
break;
|
|
152
175
|
case (0, graphql_1.isInputType)(type):
|
|
153
|
-
code
|
|
176
|
+
code = (0, graphql_2.printCodeInput)(type, options);
|
|
154
177
|
break;
|
|
155
178
|
case (0, graphql_1.isScalarType)(type):
|
|
156
|
-
code
|
|
179
|
+
code = (0, graphql_2.printCodeScalar)(type, options);
|
|
157
180
|
break;
|
|
158
181
|
case (0, graphql_1.isDirectiveType)(type):
|
|
159
|
-
code
|
|
182
|
+
code = (0, graphql_2.printCodeDirective)(type, options);
|
|
160
183
|
break;
|
|
161
184
|
default:
|
|
162
|
-
code
|
|
185
|
+
code = `"${(0, graphql_1.getTypeName)(type)}" not supported`;
|
|
163
186
|
}
|
|
164
187
|
return strings_1.MARKDOWN_SOC + code.trim() + strings_1.MARKDOWN_EOC;
|
|
165
188
|
};
|
|
189
|
+
/**
|
|
190
|
+
* Prints the GraphQL type definition as code block with event emission support.
|
|
191
|
+
*
|
|
192
|
+
* @param type - GraphQL type to print
|
|
193
|
+
* @param typeName - Name of the type being printed
|
|
194
|
+
* @param options - Printer configuration options
|
|
195
|
+
* @returns Promise resolving to formatted code block string with type definition
|
|
196
|
+
*
|
|
197
|
+
* @remarks
|
|
198
|
+
* This async version emits events before and after code generation:
|
|
199
|
+
* - `print:beforePrintCode` - Emitted before generating code (can modify inputs or prevent default)
|
|
200
|
+
* - `print:afterPrintCode` - Emitted after generating code (can modify output)
|
|
201
|
+
*
|
|
202
|
+
* Event handlers can:
|
|
203
|
+
* - Modify `event.data.options` in BEFORE to affect code generation
|
|
204
|
+
* - Call `event.preventDefault()` in BEFORE to skip default generation and provide custom output
|
|
205
|
+
* - Modify `event.output` in AFTER to change the final result
|
|
206
|
+
*/
|
|
207
|
+
static printCodeAsync = async (type, typeName, options) => {
|
|
208
|
+
// If no event emitter, just run sync method
|
|
209
|
+
if (!Printer.eventEmitter) {
|
|
210
|
+
return Printer.printCode(type, options);
|
|
211
|
+
}
|
|
212
|
+
// Create mutable event data - handlers can modify options
|
|
213
|
+
const eventData = { type, typeName, options: { ...options } };
|
|
214
|
+
// Emit BEFORE event - handlers can modify inputs or prevent default
|
|
215
|
+
const beforeEvent = {
|
|
216
|
+
data: eventData,
|
|
217
|
+
output: "",
|
|
218
|
+
defaultPrevented: false,
|
|
219
|
+
preventDefault() {
|
|
220
|
+
this.defaultPrevented = true;
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
await Printer.eventEmitter.emitAsync(PrintTypeEvents.BEFORE_PRINT_CODE, beforeEvent);
|
|
224
|
+
// If prevented, handlers should have set the output they want
|
|
225
|
+
if (beforeEvent.defaultPrevented) {
|
|
226
|
+
return beforeEvent.output;
|
|
227
|
+
}
|
|
228
|
+
// Generate code using the (potentially modified) options from event data
|
|
229
|
+
const output = Printer.printCode(type, eventData.options);
|
|
230
|
+
// Emit AFTER event - handlers can modify the output
|
|
231
|
+
const afterEvent = {
|
|
232
|
+
data: eventData,
|
|
233
|
+
output,
|
|
234
|
+
};
|
|
235
|
+
await Printer.eventEmitter.emitAsync(PrintTypeEvents.AFTER_PRINT_CODE, afterEvent);
|
|
236
|
+
return afterEvent.output;
|
|
237
|
+
};
|
|
166
238
|
/**
|
|
167
239
|
* Prints example usage of the type if available
|
|
168
240
|
*
|
|
@@ -171,7 +243,7 @@ class Printer {
|
|
|
171
243
|
* @returns Formatted example section string or empty string if no example
|
|
172
244
|
*/
|
|
173
245
|
static printExample = (type, options) => {
|
|
174
|
-
if (
|
|
246
|
+
if (options.exampleSection === undefined ||
|
|
175
247
|
options.exampleSection === null ||
|
|
176
248
|
options.exampleSection === false) {
|
|
177
249
|
return "";
|
|
@@ -188,7 +260,7 @@ class Printer {
|
|
|
188
260
|
* @param type - GraphQL type to print metadata for
|
|
189
261
|
* @param options - Printer configuration options
|
|
190
262
|
* @returns Formatted metadata string as MDX or plain string
|
|
191
|
-
* @throws
|
|
263
|
+
* @throws When type is not supported
|
|
192
264
|
*/
|
|
193
265
|
static printTypeMetadata = (type, options) => {
|
|
194
266
|
switch (true) {
|
|
@@ -254,7 +326,7 @@ class Printer {
|
|
|
254
326
|
*
|
|
255
327
|
* @example
|
|
256
328
|
* ```typescript
|
|
257
|
-
* const doc = Printer.printType('User', UserType, {
|
|
329
|
+
* const doc = await Printer.printType('User', UserType, {
|
|
258
330
|
* frontMatter: true,
|
|
259
331
|
* codeSection: true
|
|
260
332
|
* });
|
|
@@ -270,30 +342,61 @@ class Printer {
|
|
|
270
342
|
* - Type metadata
|
|
271
343
|
* - Example usage
|
|
272
344
|
* - Related types
|
|
345
|
+
*
|
|
346
|
+
* When an event emitter is configured, emits events:
|
|
347
|
+
* - `print:beforePrintType` - Before generating documentation
|
|
348
|
+
* - `print:afterPrintType` - After generating documentation (output can be modified)
|
|
273
349
|
*/
|
|
274
|
-
static printType = (name, type, options) => {
|
|
350
|
+
static printType = async (name, type, options) => {
|
|
275
351
|
const printTypeOptions = {
|
|
276
352
|
...options_1.DEFAULT_OPTIONS,
|
|
277
353
|
...Printer.options,
|
|
278
354
|
...options,
|
|
279
|
-
...Printer.printMDXModule,
|
|
280
355
|
};
|
|
281
356
|
if (!name || !(0, link_1.hasPrintableDirective)(type, printTypeOptions)) {
|
|
282
357
|
return undefined;
|
|
283
358
|
}
|
|
359
|
+
// Create event data for potential before event
|
|
360
|
+
const eventData = { type, name, options: printTypeOptions };
|
|
361
|
+
// Emit BEFORE_PRINT_TYPE event if emitter is configured
|
|
362
|
+
if (Printer.eventEmitter) {
|
|
363
|
+
const beforeEvent = {
|
|
364
|
+
data: eventData,
|
|
365
|
+
output: undefined,
|
|
366
|
+
defaultPrevented: false,
|
|
367
|
+
propagationStopped: false,
|
|
368
|
+
preventDefault() {
|
|
369
|
+
this.defaultPrevented = true;
|
|
370
|
+
},
|
|
371
|
+
stopPropagation() {
|
|
372
|
+
this.propagationStopped = true;
|
|
373
|
+
},
|
|
374
|
+
async runDefaultAction() {
|
|
375
|
+
return void 0;
|
|
376
|
+
},
|
|
377
|
+
};
|
|
378
|
+
await Printer.eventEmitter.emitAsync(PrintTypeEvents.BEFORE_PRINT_TYPE, beforeEvent);
|
|
379
|
+
// If prevented, return the output set by handlers (or undefined)
|
|
380
|
+
if (beforeEvent.defaultPrevented) {
|
|
381
|
+
return beforeEvent.output;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
284
384
|
const header = Printer.printHeader(name, (0, graphql_1.getTypeName)(type), printTypeOptions);
|
|
285
385
|
const metatags = Printer.printMetaTags(type, printTypeOptions);
|
|
286
386
|
const description = Printer.printDescription(type, printTypeOptions);
|
|
287
|
-
|
|
387
|
+
// Use async code printing when event emitter is configured
|
|
388
|
+
const code = Printer.eventEmitter
|
|
389
|
+
? await Printer.printCodeAsync(type, name, printTypeOptions)
|
|
390
|
+
: Printer.printCode(type, printTypeOptions);
|
|
288
391
|
const customDirectives = Printer.printCustomDirectives(type, printTypeOptions);
|
|
289
392
|
const tags = Printer.printCustomTags(type, printTypeOptions);
|
|
290
393
|
const metadata = Printer.printTypeMetadata(type, printTypeOptions);
|
|
291
394
|
const relations = Printer.printRelations(type, printTypeOptions);
|
|
292
395
|
const example = Printer.printExample(type, printTypeOptions);
|
|
293
|
-
|
|
396
|
+
let output = [
|
|
294
397
|
header,
|
|
295
398
|
metatags,
|
|
296
|
-
Printer.
|
|
399
|
+
Printer.mdxDeclaration,
|
|
297
400
|
tags,
|
|
298
401
|
description,
|
|
299
402
|
code,
|
|
@@ -304,6 +407,27 @@ class Printer {
|
|
|
304
407
|
]
|
|
305
408
|
.join(strings_1.MARKDOWN_EOP)
|
|
306
409
|
.trim();
|
|
410
|
+
// Emit AFTER_PRINT_TYPE event if emitter is configured
|
|
411
|
+
if (Printer.eventEmitter) {
|
|
412
|
+
const afterEvent = {
|
|
413
|
+
data: eventData,
|
|
414
|
+
output,
|
|
415
|
+
defaultPrevented: false,
|
|
416
|
+
propagationStopped: false,
|
|
417
|
+
preventDefault() {
|
|
418
|
+
this.defaultPrevented = true;
|
|
419
|
+
},
|
|
420
|
+
stopPropagation() {
|
|
421
|
+
this.propagationStopped = true;
|
|
422
|
+
},
|
|
423
|
+
async runDefaultAction() {
|
|
424
|
+
return void 0;
|
|
425
|
+
},
|
|
426
|
+
};
|
|
427
|
+
await Printer.eventEmitter.emitAsync(PrintTypeEvents.AFTER_PRINT_TYPE, afterEvent);
|
|
428
|
+
output = afterEvent.output;
|
|
429
|
+
}
|
|
430
|
+
return output;
|
|
307
431
|
};
|
|
308
432
|
}
|
|
309
433
|
exports.Printer = Printer;
|
package/dist/relation.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { IGetRelation, MDXString, Maybe, PrintTypeOptions, TypeLocale } from "@graphql-markdown/types";
|
|
7
7
|
/**
|
|
8
|
-
* Converts a string representation of a root type to its corresponding TypeLocale
|
|
9
|
-
* @param text - The string to convert to a TypeLocale
|
|
10
|
-
* @returns The matching TypeLocale if found, undefined otherwise
|
|
8
|
+
* Converts a string representation of a root type to its corresponding `TypeLocale`
|
|
9
|
+
* @param text - The string to convert to a `TypeLocale`
|
|
10
|
+
* @returns The matching `TypeLocale` if found, `undefined` otherwise
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
13
13
|
* const locale = getRootTypeLocaleFromString('Query');
|
|
@@ -21,14 +21,14 @@ export declare const getRootTypeLocaleFromString: (text: string) => Maybe<TypeLo
|
|
|
21
21
|
* @param section - The section title for the relation
|
|
22
22
|
* @param getRelation - Function to retrieve relations of type T
|
|
23
23
|
* @param options - Printing options for type formatting
|
|
24
|
-
* @returns
|
|
25
|
-
* @throws
|
|
24
|
+
* @returns Formatted MDX string containing the relations or empty string if no relations found
|
|
25
|
+
* @throws If the schema is not provided in options
|
|
26
26
|
* @example
|
|
27
27
|
* ```ts
|
|
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) => string | MDXString;
|
|
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,4 +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) => string | MDXString;
|
|
44
|
+
//# sourceMappingURL=relation.d.ts.map
|
|
@@ -0,0 +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,qCASvC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,wHAwDhC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,kEAmB1B,CAAC"}
|
package/dist/relation.js
CHANGED
|
@@ -12,9 +12,9 @@ const badge_1 = require("./badge");
|
|
|
12
12
|
const strings_1 = require("./const/strings");
|
|
13
13
|
const options_1 = require("./const/options");
|
|
14
14
|
/**
|
|
15
|
-
* Converts a string representation of a root type to its corresponding TypeLocale
|
|
16
|
-
* @param text - The string to convert to a TypeLocale
|
|
17
|
-
* @returns The matching TypeLocale if found, undefined otherwise
|
|
15
|
+
* Converts a string representation of a root type to its corresponding `TypeLocale`
|
|
16
|
+
* @param text - The string to convert to a `TypeLocale`
|
|
17
|
+
* @returns The matching `TypeLocale` if found, `undefined` otherwise
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
20
20
|
* const locale = getRootTypeLocaleFromString('Query');
|
|
@@ -36,8 +36,8 @@ exports.getRootTypeLocaleFromString = getRootTypeLocaleFromString;
|
|
|
36
36
|
* @param section - The section title for the relation
|
|
37
37
|
* @param getRelation - Function to retrieve relations of type T
|
|
38
38
|
* @param options - Printing options for type formatting
|
|
39
|
-
* @returns
|
|
40
|
-
* @throws
|
|
39
|
+
* @returns Formatted MDX string containing the relations or empty string if no relations found
|
|
40
|
+
* @throws If the schema is not provided in options
|
|
41
41
|
* @example
|
|
42
42
|
* ```ts
|
|
43
43
|
* const mdx = printRelationOf(type, "Member Of", getRelationOfField, options);
|
|
@@ -55,7 +55,7 @@ const printRelationOf = (type, section, getRelation, options) => {
|
|
|
55
55
|
if (!relations) {
|
|
56
56
|
return "";
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
const data = [];
|
|
59
59
|
for (const [relation, types] of Object.entries(relations)) {
|
|
60
60
|
if (types.length === 0) {
|
|
61
61
|
continue;
|
|
@@ -65,7 +65,7 @@ const printRelationOf = (type, section, getRelation, options) => {
|
|
|
65
65
|
text: category,
|
|
66
66
|
classname: badge_1.CSS_BADGE_CLASSNAME.RELATION,
|
|
67
67
|
}, options);
|
|
68
|
-
data
|
|
68
|
+
data.push(...types.map((t) => {
|
|
69
69
|
const link = (0, link_1.getRelationLink)(category, t, options);
|
|
70
70
|
return link ? `[\`${link.text}\`](${link.url}) ${badge}` : "";
|
|
71
71
|
}));
|
|
@@ -73,8 +73,8 @@ const printRelationOf = (type, section, getRelation, options) => {
|
|
|
73
73
|
if (data.length === 0) {
|
|
74
74
|
return "";
|
|
75
75
|
}
|
|
76
|
-
const content =
|
|
77
|
-
.
|
|
76
|
+
const content = data
|
|
77
|
+
.toSorted((a, b) => {
|
|
78
78
|
return a.localeCompare(b);
|
|
79
79
|
})
|
|
80
80
|
.join(options.formatMDXBullet());
|
|
@@ -101,10 +101,9 @@ const printRelations = (type, options) => {
|
|
|
101
101
|
getRelation: graphql_1.getRelationOfImplementation,
|
|
102
102
|
},
|
|
103
103
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return data;
|
|
104
|
+
const relationResults = Object.values(relations).map(({ section, getRelation }) => {
|
|
105
|
+
return (0, exports.printRelationOf)(type, section, getRelation, options);
|
|
106
|
+
});
|
|
107
|
+
return relationResults.join("");
|
|
109
108
|
};
|
|
110
109
|
exports.printRelations = printRelations;
|
package/dist/section.d.ts
CHANGED
|
@@ -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) => string | MDXString;
|
|
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) => string | MDXString;
|
|
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) => string | MDXString;
|
|
38
38
|
/**
|
|
39
39
|
* Prints a metadata section with special handling for deprecated items.
|
|
40
40
|
*
|
|
@@ -47,4 +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) => string | MDXString;
|
|
51
|
+
//# sourceMappingURL=section.d.ts.map
|
|
@@ -0,0 +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;AAYjC;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,2DAuCjC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,mEAwBlC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,+FAqC7B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,EAAE,CAAC,4GAsDxC,CAAC"}
|
package/dist/section.js
CHANGED
|
@@ -44,7 +44,7 @@ const printSectionItem = (type, options) => {
|
|
|
44
44
|
section += (0, exports.printSectionItems)(type.args, {
|
|
45
45
|
...options,
|
|
46
46
|
level: 5,
|
|
47
|
-
parentType:
|
|
47
|
+
parentType: options.parentType === undefined
|
|
48
48
|
? type.name
|
|
49
49
|
: `${options.parentType}.${type.name}`,
|
|
50
50
|
});
|
|
@@ -66,15 +66,17 @@ const printSectionItems = (values, options) => {
|
|
|
66
66
|
return "";
|
|
67
67
|
}
|
|
68
68
|
const level = ("level" in options && typeof options.level === "number" ? options.level : 4);
|
|
69
|
-
|
|
70
|
-
.
|
|
71
|
-
return
|
|
72
|
-
(0, exports.printSectionItem)(v, {
|
|
73
|
-
...options,
|
|
74
|
-
level,
|
|
75
|
-
}));
|
|
69
|
+
const items = values
|
|
70
|
+
.filter((v) => {
|
|
71
|
+
return v;
|
|
76
72
|
})
|
|
77
|
-
.
|
|
73
|
+
.map((v) => {
|
|
74
|
+
return (0, exports.printSectionItem)(v, {
|
|
75
|
+
...options,
|
|
76
|
+
level,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
return items.join(strings_1.MARKDOWN_EOP);
|
|
78
80
|
};
|
|
79
81
|
exports.printSectionItems = printSectionItems;
|
|
80
82
|
/**
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.13.0",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -49,18 +49,17 @@
|
|
|
49
49
|
"./package.json": "./package.json"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
|
-
"prepack": "pinst --disable",
|
|
53
|
-
"postpack": "pinst --enable",
|
|
54
52
|
"stryker": "stryker run",
|
|
55
|
-
"clean": "rm -rf ./dist",
|
|
56
|
-
"docs": "typedoc"
|
|
53
|
+
"clean": "tsgo --build --clean && rm -rf ./dist",
|
|
54
|
+
"docs": "typedoc",
|
|
55
|
+
"build": "tsgo --build"
|
|
57
56
|
},
|
|
58
57
|
"dependencies": {
|
|
59
|
-
"@graphql-markdown/graphql": "
|
|
60
|
-
"@graphql-markdown/utils": "
|
|
58
|
+
"@graphql-markdown/graphql": "workspace:^",
|
|
59
|
+
"@graphql-markdown/utils": "workspace:^"
|
|
61
60
|
},
|
|
62
61
|
"devDependencies": {
|
|
63
|
-
"@graphql-markdown/types": "
|
|
62
|
+
"@graphql-markdown/types": "workspace:^"
|
|
64
63
|
},
|
|
65
64
|
"resolutions": {
|
|
66
65
|
"micromatch": "4.0.8"
|
|
@@ -69,11 +68,12 @@
|
|
|
69
68
|
"test": "tests"
|
|
70
69
|
},
|
|
71
70
|
"engines": {
|
|
72
|
-
"node": ">=
|
|
71
|
+
"node": ">=20"
|
|
73
72
|
},
|
|
74
73
|
"publishConfig": {
|
|
75
74
|
"directory": "dist",
|
|
76
|
-
"access": "public"
|
|
75
|
+
"access": "public",
|
|
76
|
+
"scripts": {}
|
|
77
77
|
},
|
|
78
78
|
"typescript": {
|
|
79
79
|
"definition": "dist/index.d.ts"
|