@graphql-markdown/printer-legacy 1.14.0 → 1.15.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.
Files changed (49) hide show
  1. package/dist/const/options.d.ts +15 -2
  2. package/dist/const/options.d.ts.map +1 -1
  3. package/dist/const/options.js +19 -6
  4. package/dist/directive.d.ts +3 -3
  5. package/dist/directive.d.ts.map +1 -1
  6. package/dist/directive.js +8 -4
  7. package/dist/events.d.ts +77 -0
  8. package/dist/events.d.ts.map +1 -0
  9. package/dist/events.js +85 -0
  10. package/dist/example.d.ts.map +1 -1
  11. package/dist/example.js +12 -7
  12. package/dist/format-helpers.d.ts +9 -0
  13. package/dist/format-helpers.d.ts.map +1 -1
  14. package/dist/format-helpers.js +10 -1
  15. package/dist/formatter.js +1 -1
  16. package/dist/graphql/directive.d.ts +3 -3
  17. package/dist/graphql/directive.d.ts.map +1 -1
  18. package/dist/graphql/directive.js +3 -3
  19. package/dist/graphql/enum.d.ts +3 -3
  20. package/dist/graphql/enum.d.ts.map +1 -1
  21. package/dist/graphql/enum.js +2 -2
  22. package/dist/graphql/object.d.ts +3 -3
  23. package/dist/graphql/object.d.ts.map +1 -1
  24. package/dist/graphql/object.js +4 -4
  25. package/dist/graphql/operation.d.ts +6 -7
  26. package/dist/graphql/operation.d.ts.map +1 -1
  27. package/dist/graphql/operation.js +41 -8
  28. package/dist/graphql/scalar.d.ts +5 -5
  29. package/dist/graphql/scalar.d.ts.map +1 -1
  30. package/dist/graphql/scalar.js +7 -7
  31. package/dist/graphql/union.d.ts +3 -3
  32. package/dist/graphql/union.d.ts.map +1 -1
  33. package/dist/graphql/union.js +2 -2
  34. package/dist/group.d.ts.map +1 -1
  35. package/dist/group.js +7 -6
  36. package/dist/index.d.ts +2 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +5 -1
  39. package/dist/link.d.ts +1 -1
  40. package/dist/link.d.ts.map +1 -1
  41. package/dist/link.js +7 -6
  42. package/dist/mdx/index.js +2 -2
  43. package/dist/printer.d.ts +65 -21
  44. package/dist/printer.d.ts.map +1 -1
  45. package/dist/printer.js +268 -117
  46. package/dist/section.d.ts +3 -3
  47. package/dist/section.d.ts.map +1 -1
  48. package/dist/section.js +26 -11
  49. package/package.json +17 -6
@@ -7,16 +7,18 @@
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.printCodeOperation = exports.printOperationMetadata = exports.printOperationType = void 0;
9
9
  const graphql_1 = require("@graphql-markdown/graphql");
10
+ const strings_1 = require("../const/strings");
11
+ const code_1 = require("../code");
10
12
  const section_1 = require("../section");
11
13
  /**
12
14
  * Prints the operation type information.
13
15
  * @param type - The operation type to print
14
16
  * @param options - Print type options for customizing output
15
- * @returns Formatted string representation of the operation type or empty string if invalid
17
+ * @returns A "Type" PageSection, or undefined when `type` is not an operation
16
18
  */
17
19
  const printOperationType = (type, options) => {
18
20
  if (!(0, graphql_1.isOperation)(type)) {
19
- return "";
21
+ return undefined;
20
22
  }
21
23
  const queryType = (0, graphql_1.getTypeName)(type.type).replaceAll(/[![\]]*/g, "");
22
24
  return (0, section_1.printSection)([options.schema.getType(queryType)], "Type", {
@@ -29,20 +31,51 @@ exports.printOperationType = printOperationType;
29
31
  * Prints the operation metadata including arguments and type information.
30
32
  * @param type - The operation type to print metadata for
31
33
  * @param options - Print type options for customizing output
32
- * @returns Formatted string containing operation metadata or empty string if invalid
34
+ * @returns Ordered operation metadata sections, or undefined when `type` is not an operation
33
35
  */
34
36
  const printOperationMetadata = (type, options) => {
35
37
  if (!(0, graphql_1.isOperation)(type)) {
36
- return "";
38
+ return undefined;
37
39
  }
38
40
  const response = (0, exports.printOperationType)(type, options);
39
41
  const metadata = (0, section_1.printMetadataSection)(type, type.args, "Arguments", options);
40
- return `${metadata}${response}`;
42
+ return [metadata, response].filter(Boolean);
41
43
  };
42
44
  exports.printOperationMetadata = printOperationMetadata;
45
+ /**
46
+ * Wraps a GraphQL operation snippet in one or more namespace blocks.
47
+ */
48
+ const wrapOperationCodeWithNamespaces = (operationCode, operationNamespaceParts) => {
49
+ if (operationNamespaceParts.length === 0 || operationCode.trim() === "") {
50
+ return operationCode;
51
+ }
52
+ let lines = operationCode
53
+ .trimEnd()
54
+ .split(strings_1.MARKDOWN_EOL)
55
+ .filter((line) => {
56
+ return line.length > 0;
57
+ });
58
+ for (let i = operationNamespaceParts.length - 1; i >= 0; i -= 1) {
59
+ const namespace = operationNamespaceParts[i];
60
+ lines = [
61
+ `${namespace} {`,
62
+ ...lines.map((line) => {
63
+ return `${strings_1.MARKDOWN_CODE_INDENTATION}${line}`;
64
+ }),
65
+ `}`,
66
+ ];
67
+ }
68
+ return `${lines.join(strings_1.MARKDOWN_EOL)}${strings_1.MARKDOWN_EOL}`;
69
+ };
43
70
  /**
44
71
  * Prints the code representation of an operation.
45
- * @see printCodeField
46
72
  */
47
- const code_1 = require("../code");
48
- Object.defineProperty(exports, "printCodeOperation", { enumerable: true, get: function () { return code_1.printCodeField; } });
73
+ const printCodeOperation = (type, options) => {
74
+ const code = (0, code_1.printCodeField)(type, options);
75
+ if (!Array.isArray(options?.operationNamespaceParts) ||
76
+ options.operationNamespaceParts.length === 0) {
77
+ return code;
78
+ }
79
+ return wrapOperationCodeWithNamespaces(code, options.operationNamespaceParts);
80
+ };
81
+ exports.printCodeOperation = printCodeOperation;
@@ -2,22 +2,22 @@
2
2
  * Provides utility functions for handling GraphQL scalar types in markdown generation.
3
3
  * @module
4
4
  */
5
- import type { PrintTypeOptions, MDXString } from "@graphql-markdown/types";
5
+ import type { PrintTypeOptions, PageSection, Maybe } from "@graphql-markdown/types";
6
6
  /**
7
7
  * Generates markdown documentation for a scalar type's specification URL.
8
8
  * @param type - The GraphQL scalar type object
9
9
  * @param options - Options for printing type information
10
- * @returns Markdown string containing the specification link, or empty string if no URL exists
10
+ * @returns A specification PageSection, or undefined when no URL exists
11
11
  */
12
- export declare const printSpecification: (type: unknown, options: PrintTypeOptions) => string | MDXString;
12
+ export declare const printSpecification: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
13
13
  /**
14
14
  * Prints metadata information for a scalar type.
15
15
  * Currently only includes the specification URL if available.
16
16
  * @param type - The GraphQL scalar type object
17
17
  * @param options - Options for printing type information
18
- * @returns Markdown string containing the scalar metadata
18
+ * @returns A scalar metadata PageSection, or undefined when not available
19
19
  */
20
- export declare const printScalarMetadata: (type: unknown, options: PrintTypeOptions) => string | MDXString;
20
+ export declare const printScalarMetadata: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
21
21
  /**
22
22
  * Generates the GraphQL SDL representation of a scalar type.
23
23
  * @param type - The GraphQL scalar type object
@@ -1 +1 @@
1
- {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/graphql/scalar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAO3E;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAiB9B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,kEAK/B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,mEAK3B,CAAC"}
1
+ {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../../src/graphql/scalar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,KAAK,EACN,MAAM,yBAAyB,CAAC;AAIjC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAmB9B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,kEAK/B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,mEAK3B,CAAC"}
@@ -2,24 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printCodeScalar = exports.printScalarMetadata = exports.printSpecification = void 0;
4
4
  const graphql_1 = require("@graphql-markdown/graphql");
5
- const strings_1 = require("../const/strings");
6
- const options_1 = require("../const/options");
7
5
  /**
8
6
  * Generates markdown documentation for a scalar type's specification URL.
9
7
  * @param type - The GraphQL scalar type object
10
8
  * @param options - Options for printing type information
11
- * @returns Markdown string containing the specification link, or empty string if no URL exists
9
+ * @returns A specification PageSection, or undefined when no URL exists
12
10
  */
13
11
  const printSpecification = (type, options) => {
14
12
  if (typeof type !== "object" ||
15
13
  type === null ||
16
14
  !("specifiedByURL" in type) ||
17
15
  typeof type.specifiedByURL !== "string") {
18
- return "";
16
+ return undefined;
19
17
  }
20
18
  const url = type.specifiedByURL;
21
- // Needs newline between "export const specifiedByLinkCss" and markdown header to prevent compilation error in docusaurus
22
- return `${options_1.SectionLevels.LEVEL.repeat(3)} ${options.formatMDXSpecifiedByLink(url)}${strings_1.MARKDOWN_EOP}`;
19
+ return {
20
+ title: options.formatMDXSpecifiedByLink(url),
21
+ level: 3,
22
+ };
23
23
  };
24
24
  exports.printSpecification = printSpecification;
25
25
  /**
@@ -27,7 +27,7 @@ exports.printSpecification = printSpecification;
27
27
  * Currently only includes the specification URL if available.
28
28
  * @param type - The GraphQL scalar type object
29
29
  * @param options - Options for printing type information
30
- * @returns Markdown string containing the scalar metadata
30
+ * @returns A scalar metadata PageSection, or undefined when not available
31
31
  */
32
32
  const printScalarMetadata = (type, options) => {
33
33
  return (0, exports.printSpecification)(type, options);
@@ -2,14 +2,14 @@
2
2
  * Module for handling GraphQL Union type printing operations.
3
3
  * @module
4
4
  */
5
- import type { PrintTypeOptions, MDXString } from "@graphql-markdown/types";
5
+ import type { PrintTypeOptions, PageSection, Maybe } from "@graphql-markdown/types";
6
6
  /**
7
7
  * Generates metadata documentation for a GraphQL Union type.
8
8
  * @param type - The GraphQL type to process
9
9
  * @param options - Configuration options for printing
10
- * @returns Formatted MDX string containing the union type's possible types
10
+ * @returns A "Possible types" PageSection, or undefined when `type` is not a union
11
11
  */
12
- export declare const printUnionMetadata: (type: unknown, options: PrintTypeOptions) => string | MDXString;
12
+ export declare const printUnionMetadata: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
13
13
  /**
14
14
  * Generates GraphQL SDL code representation of a Union type.
15
15
  * @param type - The GraphQL type to process
@@ -1 +1 @@
1
- {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/graphql/union.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,SAAS,EAEV,MAAM,yBAAyB,CAAC;AAMjC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAY9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,mEAiB1B,CAAC"}
1
+ {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/graphql/union.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAEhB,WAAW,EACX,KAAK,EACN,MAAM,yBAAyB,CAAC;AAMjC;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,kEAY9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,mEAiB1B,CAAC"}
@@ -11,11 +11,11 @@ const section_1 = require("../section");
11
11
  * Generates metadata documentation for a GraphQL Union type.
12
12
  * @param type - The GraphQL type to process
13
13
  * @param options - Configuration options for printing
14
- * @returns Formatted MDX string containing the union type's possible types
14
+ * @returns A "Possible types" PageSection, or undefined when `type` is not a union
15
15
  */
16
16
  const printUnionMetadata = (type, options) => {
17
17
  if (!(0, graphql_1.isUnionType)(type)) {
18
- return "";
18
+ return undefined;
19
19
  }
20
20
  return (0, section_1.printSection)(type.getTypes(), "Possible types", {
21
21
  ...options,
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAEV,YAAY,EAEZ,KAAK,EACN,MAAM,yBAAyB,CAAC;AAMjC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,2IA+BpB,CAAC"}
1
+ {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAEV,YAAY,EAEZ,KAAK,EACN,MAAM,yBAAyB,CAAC;AAMjC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,2IA6BpB,CAAC"}
package/dist/group.js CHANGED
@@ -20,15 +20,16 @@ const getGroup = (type, groups, typeCategory) => {
20
20
  return "";
21
21
  }
22
22
  const graphQLNamedType = (0, graphql_1.getNamedType)(type);
23
- if (!graphQLNamedType) {
23
+ const typeName = (0, utils_1.hasStringProperty)(graphQLNamedType, "name")
24
+ ? graphQLNamedType.name
25
+ : "";
26
+ if (!typeName) {
24
27
  return "";
25
28
  }
26
- const typeName = "name" in graphQLNamedType
27
- ? graphQLNamedType.name
28
- : String(graphQLNamedType);
29
- if (!(typeCategory in groups && typeName in groups[typeCategory])) {
29
+ const categoryGroups = groups[typeCategory];
30
+ if (!categoryGroups || !(typeName in categoryGroups)) {
30
31
  return "";
31
32
  }
32
- return (0, utils_1.slugify)(groups[typeCategory][typeName]);
33
+ return (0, utils_1.slugify)(categoryGroups[typeName]);
33
34
  };
34
35
  exports.getGroup = getGroup;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { Printer } from "./printer";
2
+ export { PrintCodeEvent, PrintTypeEvent, BeforeComposePageTypeEvent, } from "./events";
3
+ export type { PageSection, PageSections, PrintCodeEventData, PrintTypeEventData, ComposePageTypeEventData, } from "./events";
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,cAAc,EACd,cAAc,EACd,0BAA0B,GAC3B,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Printer = void 0;
3
+ exports.BeforeComposePageTypeEvent = exports.PrintTypeEvent = exports.PrintCodeEvent = exports.Printer = void 0;
4
4
  const printer_1 = require("./printer");
5
5
  Object.defineProperty(exports, "Printer", { enumerable: true, get: function () { return printer_1.Printer; } });
6
+ const events_1 = require("./events");
7
+ Object.defineProperty(exports, "PrintCodeEvent", { enumerable: true, get: function () { return events_1.PrintCodeEvent; } });
8
+ Object.defineProperty(exports, "PrintTypeEvent", { enumerable: true, get: function () { return events_1.PrintTypeEvent; } });
9
+ Object.defineProperty(exports, "BeforeComposePageTypeEvent", { enumerable: true, get: function () { return events_1.BeforeComposePageTypeEvent; } });
package/dist/link.d.ts CHANGED
@@ -88,7 +88,7 @@ export declare const printLinkAttributes: (type: unknown, text?: Maybe<string>)
88
88
  /**
89
89
  * Prints a link for a GraphQL type based on the provided options.
90
90
  *
91
- * @param type - The GraphQL type to print a link for
91
+ * @param arg - The GraphQL type or link object to print a link for
92
92
  * @param options - Configuration options for link generation
93
93
  * @returns The formatted link as a string
94
94
  */
@@ -1 +1 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EAGpB,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAEhB,oBAAoB,EAGpB,QAAQ,EACR,UAAU,EACX,MAAM,yBAAyB,CAAC;AAgCjC,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,oBAAoB,CAG5C,CAAC;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;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,wCAO/B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,2EASjC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gEAKnC,CAAC;AASF;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,oGAuFlB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,4FAc3B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,iDAqB/B,CAAC;AAoBF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,gEAmC1B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,kEAc3B,CAAC"}
package/dist/link.js CHANGED
@@ -38,7 +38,7 @@ const hasPrintableDirective = (type, options) => {
38
38
  const onlyDirective = "onlyDocDirectives" in options && options.onlyDocDirectives
39
39
  ? (0, graphql_1.hasDirective)(type, options.onlyDocDirectives, true)
40
40
  : true;
41
- return !(skipDirective || skipDeprecated) && onlyDirective;
41
+ return !skipDirective && !skipDeprecated && onlyDirective;
42
42
  };
43
43
  exports.hasPrintableDirective = hasPrintableDirective;
44
44
  /**
@@ -168,10 +168,9 @@ const toLink = (type, name, operation, options) => {
168
168
  if (typeof type !== "object" || !(0, exports.hasPrintableDirective)(type, options)) {
169
169
  return fallback;
170
170
  }
171
+ // GraphQL overload resolution can include a void branch in this monorepo; runtime value is a named type here.
172
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
171
173
  const graphQLNamedType = (0, graphql_1.getNamedType)(type);
172
- if (!graphQLNamedType) {
173
- return fallback;
174
- }
175
174
  let category = "";
176
175
  let deprecatedFolder = "";
177
176
  let groupFolder = "";
@@ -191,7 +190,9 @@ const toLink = (type, name, operation, options) => {
191
190
  ? (0, exports.getLinkApiGroupFolder)(type)
192
191
  : "";
193
192
  }
194
- const text = graphQLNamedType.name || graphQLNamedType.toString();
193
+ const text = (0, utils_1.hasStringProperty)(graphQLNamedType, "name")
194
+ ? graphQLNamedType.name
195
+ : (0, utils_1.toString)(graphQLNamedType);
195
196
  const formatFolder = (folder) => {
196
197
  return folder && options.formatCategoryFolderName
197
198
  ? options.formatCategoryFolderName(folder)
@@ -274,7 +275,7 @@ const isLinkType = (arg) => {
274
275
  /**
275
276
  * Prints a link for a GraphQL type based on the provided options.
276
277
  *
277
- * @param type - The GraphQL type to print a link for
278
+ * @param arg - The GraphQL type or link object to print a link for
278
279
  * @param options - Configuration options for link generation
279
280
  * @returns The formatted link as a string
280
281
  */
package/dist/mdx/index.js CHANGED
@@ -79,13 +79,13 @@ const formatMDXBullet = (text = "") => {
79
79
  * ```typescript
80
80
  * const options = { dataOpen: "More Info" };
81
81
  * formatMDXDetails(options);
82
- * // '\n\n<details class="gqlmd-mdx-details">\n<summary class="gqlmd-mdx-details-summary"><span className="gqlmd-mdx-details-summary-open">MORE INFO</span></summary>\n</details>\n\n'
82
+ * // '\n\n<details class="gqlmd-mdx-details">\n<summary class="gqlmd-mdx-details-summary"><span className="gqlmd-mdx-details-summary-open">MORE INFO</span></summary>\n\r\n</details>\n\n'
83
83
  * ```
84
84
  * @see {@link mdxModule.formatMDXDetails} for the equivalent function in the MDX module.
85
85
  * @see {@link printer.formatDetails} for usage in the printer module.
86
86
  */
87
87
  const formatMDXDetails = ({ dataOpen }) => {
88
- return `${strings_1.MARKDOWN_EOP}<details class="gqlmd-mdx-details">${strings_1.MARKDOWN_EOL}<summary class="gqlmd-mdx-details-summary"><span className="gqlmd-mdx-details-summary-open">${dataOpen.toUpperCase()}</span></summary>${strings_1.MARKDOWN_EOL}</details>${strings_1.MARKDOWN_EOP}`;
88
+ return `${strings_1.MARKDOWN_EOP}<details class="gqlmd-mdx-details">${strings_1.MARKDOWN_EOL}<summary class="gqlmd-mdx-details-summary"><span className="gqlmd-mdx-details-summary-open">${dataOpen.toUpperCase()}</span></summary>${strings_1.MARKDOWN_EOL}\r${strings_1.MARKDOWN_EOL}</details>${strings_1.MARKDOWN_EOP}`;
89
89
  };
90
90
  /**
91
91
  * Formats a "Specified By" link into an MDX string.
package/dist/printer.d.ts CHANGED
@@ -7,7 +7,10 @@
7
7
  * @module printer
8
8
  * @packageDocumentation
9
9
  */
10
- import type { CustomDirectiveMap, Formatter, GraphQLDirective, GraphQLSchema, IPrinter, MDXString, Maybe, MetaInfo, PrinterEventEmitter, PrintTypeOptions, PrinterConfigPrintTypeOptions, SchemaEntitiesGroupMap, TypeDeprecatedOption } from "@graphql-markdown/types";
10
+ import type { CustomDirectiveMap, DeprecatedPrintTypeOptions, Formatter, GraphQLDirective, GraphQLSchema, IPrinter, Maybe, MDXString, MetaInfo, PageSection, PrinterConfigPrintTypeOptions, PrinterEventEmitter, PrintTypeOptions, SchemaEntitiesGroupMap, TypeDeprecatedOption } from "@graphql-markdown/types";
11
+ type InitPrintTypeOptions = DeprecatedPrintTypeOptions & Omit<PrinterConfigPrintTypeOptions, "exampleSection"> & {
12
+ exampleSection?: DeprecatedPrintTypeOptions["exampleSection"] | PrinterConfigPrintTypeOptions["exampleSection"];
13
+ };
11
14
  /**
12
15
  * The Printer class implements the core functionality for generating Markdown documentation
13
16
  * from GraphQL schema types.
@@ -27,16 +30,6 @@ import type { CustomDirectiveMap, Formatter, GraphQLDirective, GraphQLSchema, IP
27
30
  * ```
28
31
  */
29
32
  export declare class Printer implements IPrinter {
30
- /**
31
- * Global printer configuration options
32
- */
33
- static options: Readonly<Maybe<PrintTypeOptions>>;
34
- /**
35
- * Optional event emitter for print events.
36
- * When set, the printer will emit events before/after printCode and printType,
37
- * allowing external code to intercept and modify the output.
38
- */
39
- static eventEmitter: Maybe<PrinterEventEmitter>;
40
33
  /**
41
34
  * Prints type descriptions
42
35
  */
@@ -44,15 +37,38 @@ export declare class Printer implements IPrinter {
44
37
  /**
45
38
  * Prints custom directives
46
39
  */
47
- static readonly printCustomDirectives: (type: unknown, options: PrintTypeOptions) => string;
40
+ static readonly printCustomDirectives: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
48
41
  /**
49
42
  * Prints custom tags
50
43
  */
51
44
  static readonly printCustomTags: (type: unknown, options: PrintTypeOptions) => string | MDXString;
45
+ private static _eventEmitter;
46
+ private static _options;
47
+ private static _deprecatedOptions;
48
+ private static _mdxDeclaration;
49
+ /**
50
+ * Global printer configuration options
51
+ */
52
+ static get options(): Readonly<Maybe<PrintTypeOptions>>;
53
+ /**
54
+ * Backward-compat section toggles extracted from legacy config options.
55
+ *
56
+ * These flags are applied only during section order composition.
57
+ */
58
+ static get deprecatedOptions(): Readonly<Maybe<DeprecatedPrintTypeOptions>>;
59
+ /**
60
+ * Optional event emitter for print events.
61
+ * When set, the printer will emit events before/after printCode and printType,
62
+ * allowing external code to intercept and modify the output.
63
+ */
64
+ static get eventEmitter(): Maybe<PrinterEventEmitter>;
52
65
  /**
53
66
  * Prints mdx modules import declaration
54
67
  */
55
- static mdxDeclaration: Readonly<Maybe<string>>;
68
+ static get mdxDeclaration(): Readonly<Maybe<string>>;
69
+ static set options(options: Readonly<Maybe<PrintTypeOptions>>);
70
+ static set eventEmitter(eventEmitter: Maybe<PrinterEventEmitter>);
71
+ static set mdxDeclaration(mdxDeclaration: Readonly<Maybe<string>>);
56
72
  /**
57
73
  * Initializes the printer with the given schema and configuration.
58
74
  *
@@ -71,7 +87,7 @@ export declare class Printer implements IPrinter {
71
87
  meta?: Maybe<MetaInfo>;
72
88
  metatags?: Record<string, string>[];
73
89
  onlyDocDirectives?: GraphQLDirective[];
74
- printTypeOptions?: PrinterConfigPrintTypeOptions;
90
+ printTypeOptions?: InitPrintTypeOptions;
75
91
  skipDocDirectives?: GraphQLDirective[];
76
92
  sectionHeaderId?: boolean;
77
93
  }, formatter?: Partial<Formatter>, mdxDeclaration?: Maybe<string>, eventEmitter?: Maybe<PrinterEventEmitter>): Promise<void>;
@@ -116,18 +132,17 @@ export declare class Printer implements IPrinter {
116
132
  *
117
133
  * @param type - GraphQL type to generate example for
118
134
  * @param options - Printer configuration options
119
- * @returns Formatted example section string or empty string if no example
135
+ * @returns Example page section or undefined when no example is available
120
136
  */
121
- static readonly printExample: (type: unknown, options: PrintTypeOptions) => string;
137
+ static readonly printExample: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
122
138
  /**
123
139
  * Prints metadata information for a GraphQL type
124
140
  *
125
141
  * @param type - GraphQL type to print metadata for
126
142
  * @param options - Printer configuration options
127
- * @returns Formatted metadata string as MDX or plain string
128
- * @throws When type is not supported
143
+ * @returns Metadata section (or section list) for supported types, otherwise undefined
129
144
  */
130
- static readonly printTypeMetadata: (type: unknown, options: PrintTypeOptions) => string | MDXString;
145
+ static readonly printTypeMetadata: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection[] | PageSection>;
131
146
  /**
132
147
  * Prints related type information
133
148
  *
@@ -155,8 +170,7 @@ export declare class Printer implements IPrinter {
155
170
  * @example
156
171
  * ```typescript
157
172
  * const doc = await Printer.printType('User', UserType, {
158
- * frontMatter: true,
159
- * codeSection: true
173
+ * frontMatter: true
160
174
  * });
161
175
  * ```
162
176
  *
@@ -173,8 +187,38 @@ export declare class Printer implements IPrinter {
173
187
  *
174
188
  * When an event emitter is configured, emits events:
175
189
  * - `print:beforePrintType` - Before generating documentation
190
+ * - `print:beforeComposePageType` - Before composing section order and final page output
176
191
  * - `print:afterPrintType` - After generating documentation (output can be modified)
177
192
  */
178
193
  static readonly printType: (name: Maybe<string>, type: unknown, options?: Maybe<Partial<PrintTypeOptions>>) => Promise<Maybe<MDXString>>;
194
+ /**
195
+ * Renders a page section, optionally prefixing a heading when a title is present.
196
+ */
197
+ private static readonly renderPageSection;
198
+ /**
199
+ * Returns the default content section order for type pages.
200
+ *
201
+ * Applies backward-compatibility toggles from deprecated section flags.
202
+ */
203
+ private static readonly getDeprecatedTypePageSectionOrder;
204
+ /**
205
+ * Runtime guard for built-in page content section keys.
206
+ */
207
+ private static readonly isTypePageContentSection;
208
+ /**
209
+ * Runtime guard for header-only page section keys.
210
+ */
211
+ private static readonly isTypePageHeaderSection;
212
+ /**
213
+ * Normalizes event-driven section order, allowing built-in section keys and
214
+ * any custom keys that were added to the sections map by an event handler.
215
+ * Keys that are neither built-in nor present in the sections map are dropped.
216
+ */
217
+ private static readonly sanitizeTypePageSectionOrder;
218
+ /**
219
+ * Normalizes mixed section value shapes to the internal PageSection format.
220
+ */
221
+ private static readonly normalizePageSection;
179
222
  }
223
+ export {};
180
224
  //# sourceMappingURL=printer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../src/printer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAEhB,aAAa,EACb,QAAQ,EACR,SAAS,EACT,KAAK,EACL,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AA2EjC;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,OAAQ,YAAW,QAAQ;IACtC;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAElD;;;;OAIG;IACH,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAEhD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,gBAAgB,gGAAoB;IAEpD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,qBAAqB,uDAAyB;IAE9D;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,eAAe,mEAAmB;IAElD;;OAEG;IACH,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAE/C;;;;;;;;;;OAUG;IACH,OAAa,IAAI,CACf,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,EAC5B,OAAO,GAA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