@graphql-markdown/printer-legacy 1.17.0 → 1.18.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/README.md +37 -0
- package/dist/common.d.ts +0 -8
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +10 -31
- package/dist/const/options.d.ts +3 -1
- package/dist/const/options.d.ts.map +1 -1
- package/dist/const/options.js +2 -1
- package/dist/decorator.d.ts +174 -0
- package/dist/decorator.d.ts.map +1 -0
- package/dist/decorator.js +494 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/printer.d.ts +4 -8
- package/dist/printer.d.ts.map +1 -1
- package/dist/printer.js +19 -25
- package/dist/section.d.ts.map +1 -1
- package/dist/section.js +27 -5
- package/package.json +1 -1
- package/dist/directive.d.ts +0 -44
- package/dist/directive.d.ts.map +0 -1
- package/dist/directive.js +0 -110
package/README.md
CHANGED
|
@@ -5,3 +5,40 @@
|
|
|
5
5
|
[](https://sonarcloud.io/summary/new_code?id=graphql-markdown_printer-legacy)
|
|
6
6
|
[](https://sonarcloud.io/summary/new_code?id=graphql-markdown_printer-legacy)
|
|
7
7
|
[](https://dashboard.stryker-mutator.io/reports/github.com/graphql-markdown/graphql-markdown/main?module=printer-legacy)
|
|
8
|
+
|
|
9
|
+
Legacy Docusaurus-flavored MDX printer for GraphQL-Markdown. Converts GraphQL schema types into MDX pages, and is the printer used by default when no `formatter` is configured. New setups should prefer a formatter preset from [`@graphql-markdown/formatters`](https://www.npmjs.com/package/@graphql-markdown/formatters); this package is kept for backward compatibility with existing Docusaurus configurations and for `customDirective`-based decorators.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm install @graphql-markdown/printer-legacy
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
`printer-legacy` is typically consumed indirectly through [`@graphql-markdown/core`](https://www.npmjs.com/package/@graphql-markdown/core), which builds a `Printer` instance from the resolved configuration. It can also be used directly:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { Printer } from "@graphql-markdown/printer-legacy";
|
|
23
|
+
|
|
24
|
+
await Printer.init(schema, baseURL, options);
|
|
25
|
+
const page = await Printer.printType("query", queryType, options);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Custom directive decorators
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { buildCustomDirectiveDecorators } from "@graphql-markdown/printer-legacy";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
- [Configuration Options](https://graphql-markdown.dev/docs/settings)
|
|
37
|
+
- [Custom Directives](https://graphql-markdown.dev/docs/advanced/custom-directive)
|
|
38
|
+
- [Integration with Frameworks](https://graphql-markdown.dev/docs/advanced/integration-with-frameworks)
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
GraphQL-Markdown packages are 100% free and open-source, under the [MIT license](https://github.com/graphql-markdown/graphql-markdown/blob/main/LICENSE).
|
|
43
|
+
|
|
44
|
+
This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/graphql-markdown/graphql-markdown) to thank us for our work. By contributing to the Treeware forest, you'll be creating employment for local families and restoring wildlife habitats.
|
package/dist/common.d.ts
CHANGED
|
@@ -3,14 +3,6 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
import type { MDXString, PrintTypeOptions } from "@graphql-markdown/types";
|
|
6
|
-
/**
|
|
7
|
-
* Prints documentation for custom directives applied to a type.
|
|
8
|
-
*
|
|
9
|
-
* @param type - GraphQL type to get directives from
|
|
10
|
-
* @param options - Printer configuration options
|
|
11
|
-
* @returns Formatted directive documentation string
|
|
12
|
-
*/
|
|
13
|
-
export declare const getCustomDirectivesText: (type: unknown, options?: PrintTypeOptions) => string;
|
|
14
6
|
/**
|
|
15
7
|
* Generates a warning message block in MDX format.
|
|
16
8
|
* @param warningConfig - Warning configuration object with `text` and optional `title` properties
|
package/dist/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAEV,SAAS,EACT,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAkCjC;;;;;GAKG;AAEH,eAAO,MAAM,YAAY,oBACN;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,WACzC,gBAAgB,KACxB,MAUF,CAAC;AAEF;;;;;GAKG;AAEH,eAAO,MAAM,gBAAgB,SACrB,OAAO,WACJ,gBAAgB,KACxB,MAcF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,SACrB,OAAO,WACJ,gBAAgB,WAChB,MAAM,KACd,SAAS,GAAG,MAYd,CAAC"}
|
package/dist/common.js
CHANGED
|
@@ -4,38 +4,11 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.printDescription = exports.printDeprecation = exports.printWarning =
|
|
7
|
+
exports.printDescription = exports.printDeprecation = exports.printWarning = void 0;
|
|
8
8
|
const utils_1 = require("@graphql-markdown/utils");
|
|
9
9
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
10
10
|
const strings_1 = require("./const/strings");
|
|
11
|
-
const
|
|
12
|
-
/**
|
|
13
|
-
* Prints documentation for custom directives applied to a type.
|
|
14
|
-
*
|
|
15
|
-
* @param type - GraphQL type to get directives from
|
|
16
|
-
* @param options - Printer configuration options
|
|
17
|
-
* @returns Formatted directive documentation string
|
|
18
|
-
*/
|
|
19
|
-
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
20
|
-
const getCustomDirectivesText = (type, options) => {
|
|
21
|
-
const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options?.customDirectives);
|
|
22
|
-
if ((0, utils_1.isEmpty)(constDirectiveMap)) {
|
|
23
|
-
return "";
|
|
24
|
-
}
|
|
25
|
-
const content = Object.values(constDirectiveMap)
|
|
26
|
-
.map((constDirectiveOption) => {
|
|
27
|
-
return (0, directive_1.getCustomDirectiveResolver)("descriptor", type, constDirectiveOption, "");
|
|
28
|
-
})
|
|
29
|
-
.filter((text) => {
|
|
30
|
-
return typeof text === "string" && text.length > 0;
|
|
31
|
-
})
|
|
32
|
-
.map((text) => {
|
|
33
|
-
return (0, utils_1.escapeMDX)(text);
|
|
34
|
-
})
|
|
35
|
-
.join(strings_1.MARKDOWN_EOP);
|
|
36
|
-
return `${strings_1.MARKDOWN_EOP}${content}`;
|
|
37
|
-
};
|
|
38
|
-
exports.getCustomDirectivesText = getCustomDirectivesText;
|
|
11
|
+
const decorator_1 = require("./decorator");
|
|
39
12
|
/**
|
|
40
13
|
* Formats a GraphQL type description or falls back to a default message.
|
|
41
14
|
*
|
|
@@ -92,8 +65,14 @@ exports.printDeprecation = printDeprecation;
|
|
|
92
65
|
*/
|
|
93
66
|
const printDescription = (type, options, noText) => {
|
|
94
67
|
const description = formatDescription(type, noText);
|
|
95
|
-
const customDirectives = (0, exports.getCustomDirectivesText)(type, options);
|
|
96
68
|
const deprecation = (0, exports.printDeprecation)(type, options);
|
|
97
|
-
|
|
69
|
+
// `customDirective`'s `descriptor` handlers reach this line via the
|
|
70
|
+
// decorators pipeline (`printSlotDecorators`), not a dedicated call — see
|
|
71
|
+
// `buildCustomDirectiveDecorators` in `./decorator`.
|
|
72
|
+
const decoratorContent = (0, decorator_1.printSlotDecorators)("description", type, options);
|
|
73
|
+
const decorators = decoratorContent.length > 0
|
|
74
|
+
? `${strings_1.MARKDOWN_EOP}${decoratorContent.join(strings_1.MARKDOWN_EOP)}`
|
|
75
|
+
: "";
|
|
76
|
+
return `${deprecation}${description}${decorators}`;
|
|
98
77
|
};
|
|
99
78
|
exports.printDescription = printDescription;
|
package/dist/const/options.d.ts
CHANGED
|
@@ -17,8 +17,10 @@ export declare const PRINT_TYPE_DEFAULT_OPTIONS: Required<Omit<PrinterConfigPrin
|
|
|
17
17
|
/**
|
|
18
18
|
* Clean runtime options passed through the printer.
|
|
19
19
|
*/
|
|
20
|
-
export declare const DEFAULT_OPTIONS: Required<Omit<PrintTypeOptions, "collapsible" | "exampleSection" | "formatCategoryFolderName" | "groups" | "level" | "meta" | "onlyDocDirectives" | "parentType" | "schema" | "skipDocDirectives">> & {
|
|
20
|
+
export declare const DEFAULT_OPTIONS: Required<Omit<PrintTypeOptions, "collapsible" | "decorators" | "entity" | "exampleSection" | "formatCategoryFolderName" | "groups" | "level" | "meta" | "onlyDocDirectives" | "parentType" | "schema" | "skipDocDirectives">> & {
|
|
21
21
|
collapsible: Maybe<CollapsibleOption>;
|
|
22
|
+
decorators: PrintTypeOptions["decorators"];
|
|
23
|
+
entity: PrintTypeOptions["entity"];
|
|
22
24
|
exampleSection: PrintTypeOptions["exampleSection"];
|
|
23
25
|
groups: Maybe<SchemaEntitiesGroupMap>;
|
|
24
26
|
level: Maybe<SectionLevelValue>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/const/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,KAAK,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,yBAAyB,CAAC;AAcjC,oBAAY,aAAa;IACvB,GAAG,QAAQ;IAEX,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,oBAAY,aAAa;IACvB;;OAEG;IAEH,IAAI,KAAK;IACT,KAAK,MAAM;CACZ;AAED,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAC/C,IAAI,CAAC,6BAA6B,EAAE,gBAAgB,CAAC,CACtD,GAAG;IACF,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAQpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CACpC,IAAI,CACF,gBAAgB,EACd,aAAa,GACb,gBAAgB,GAChB,0BAA0B,GAC1B,QAAQ,GACR,OAAO,GACP,MAAM,GACN,mBAAmB,GACnB,YAAY,GACZ,QAAQ,GACR,mBAAmB,CACtB,CACF,GAAG;IACF,WAAW,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACtC,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACnD,MAAM,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACtC,KAAK,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAC7B,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/const/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,KAAK,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,yBAAyB,CAAC;AAcjC,oBAAY,aAAa;IACvB,GAAG,QAAQ;IAEX,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,oBAAY,aAAa;IACvB;;OAEG;IAEH,IAAI,KAAK;IACT,KAAK,MAAM;CACZ;AAED,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAC/C,IAAI,CAAC,6BAA6B,EAAE,gBAAgB,CAAC,CACtD,GAAG;IACF,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAQpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CACpC,IAAI,CACF,gBAAgB,EACd,aAAa,GACb,YAAY,GACZ,QAAQ,GACR,gBAAgB,GAChB,0BAA0B,GAC1B,QAAQ,GACR,OAAO,GACP,MAAM,GACN,mBAAmB,GACnB,YAAY,GACZ,QAAQ,GACR,mBAAmB,CACtB,CACF,GAAG;IACF,WAAW,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACtC,UAAU,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC3C,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACnC,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACnD,MAAM,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACtC,KAAK,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChC,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IACtC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAC7B,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;CA+BvC,CAAC"}
|
package/dist/const/options.js
CHANGED
|
@@ -33,7 +33,8 @@ exports.DEFAULT_OPTIONS = {
|
|
|
33
33
|
deprecated: exports.PRINT_TYPE_DEFAULT_OPTIONS.deprecated,
|
|
34
34
|
basePath: "/",
|
|
35
35
|
collapsible: undefined,
|
|
36
|
-
|
|
36
|
+
decorators: undefined,
|
|
37
|
+
entity: undefined,
|
|
37
38
|
exampleSection: undefined,
|
|
38
39
|
groups: undefined,
|
|
39
40
|
frontMatter: {},
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module providing predicate-driven decorators for type pages.
|
|
3
|
+
*
|
|
4
|
+
* A decorator (declared in the top-level `decorators` option) is selected by a
|
|
5
|
+
* predicate over the node being printed — by default, every node — and
|
|
6
|
+
* renders its resolved values through a user callback. There is no built-in
|
|
7
|
+
* notion of "this decorator's own directive": a directive-driven decorator
|
|
8
|
+
* selects its nodes with `predicate: hasDirectiveNamed("name")` and reads
|
|
9
|
+
* that directive's argument values, if any, from `resolve` via
|
|
10
|
+
* `@graphql-markdown/graphql`'s `getDirectiveFromSchema` combined with
|
|
11
|
+
* `getTypeDirectiveValues`/`getTypeDirectiveValuesList` — the same public
|
|
12
|
+
* helpers this module uses internally. A decorator with a title becomes a top-level
|
|
13
|
+
* section of the type page; one without renders bare content, placed relative
|
|
14
|
+
* to the built-in sections, or into a named slot such as the heading's
|
|
15
|
+
* metadata line or a member's description.
|
|
16
|
+
*
|
|
17
|
+
* `customDirective` is the deprecated predecessor of this module. It never
|
|
18
|
+
* reaches this module, or any other part of the printer: `@graphql-markdown/core`
|
|
19
|
+
* converts its schema-resolved directive map into decorator declarations
|
|
20
|
+
* (see {@link buildCustomDirectiveDecorators}) once, before the printer is
|
|
21
|
+
* ever invoked, so both options flow through the exact same resolve/render
|
|
22
|
+
* pipeline below — there is one code path for "select nodes by directive,
|
|
23
|
+
* render descriptor text, a badge, or a section", not two.
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
import type { CustomDirectiveMap, DecoratorDefinition, Decorators, Maybe, PageSection, PageSections, PrintTypeOptions } from "@graphql-markdown/types";
|
|
28
|
+
import { getSchemaEntity } from "@graphql-markdown/graphql";
|
|
29
|
+
export { getSchemaEntity };
|
|
30
|
+
/**
|
|
31
|
+
* A decorator, resolved from its declaration under `decorators`.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export type ResolvedDecorator = DecoratorDefinition & {
|
|
36
|
+
/** The decorator id — the key under which it was declared. */
|
|
37
|
+
id: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Section/decorator keys owned by the printer, which a decorator cannot claim.
|
|
41
|
+
*
|
|
42
|
+
* Re-exported from the package root: `@graphql-markdown/core`'s
|
|
43
|
+
* `getDecoratorsOption` validates against this same list (plus `"__proto__"`,
|
|
44
|
+
* reserved only there — see that package's own copy of this comment) so the
|
|
45
|
+
* two entry points, config-file validation and building a decorators map
|
|
46
|
+
* directly against the printer API, can't silently drift apart on which
|
|
47
|
+
* names are reserved.
|
|
48
|
+
*/
|
|
49
|
+
export declare const RESERVED_SECTION_NAMES: readonly string[];
|
|
50
|
+
/**
|
|
51
|
+
* Converts the deprecated `customDirective` option's schema-resolved
|
|
52
|
+
* directive map into decorator declarations, so it flows through the exact
|
|
53
|
+
* same resolve/render pipeline as everything declared under `decorators`.
|
|
54
|
+
*
|
|
55
|
+
* Called once by `@graphql-markdown/core`, right after `customDirectives` is
|
|
56
|
+
* schema-resolved, and merged directly into the top-level `decorators`
|
|
57
|
+
* option before it reaches the printer — `customDirective`/`CustomDirectiveMap`
|
|
58
|
+
* never reach this printer package otherwise; only the three decorators
|
|
59
|
+
* built here do, indistinguishable from any other `decorators` entry except
|
|
60
|
+
* for their reserved ids (see {@link CUSTOM_DIRECTIVE_DECORATOR_IDS}).
|
|
61
|
+
*
|
|
62
|
+
* Returns three entries:
|
|
63
|
+
* - `customDirectives`: the built-in "Directives" section, listing every
|
|
64
|
+
* custom directive declared on a type, positioned right after `code`
|
|
65
|
+
* (its fixed position in the pre-decorators built-in section order).
|
|
66
|
+
* - `customDirective:description`: `customDirective`'s `descriptor`
|
|
67
|
+
* handlers, appended as description text (`position: { into: "description" }`).
|
|
68
|
+
* - `customDirective:tags`: `customDirective`'s `tag` handlers, rendered as
|
|
69
|
+
* badges in the metadata line (`position: { into: "tags" }`).
|
|
70
|
+
*
|
|
71
|
+
* All three share one `resolve`, reading every custom directive matched on
|
|
72
|
+
* a node, in schema declaration order. Matching (including wildcard `"*"`
|
|
73
|
+
* precedence — a named handler wins over `"*"`) is already resolved by
|
|
74
|
+
* `getConstDirectiveMap` (fed by `@graphql-markdown/graphql`'s
|
|
75
|
+
* `getCustomDirectives`, which expands a wildcard into concrete
|
|
76
|
+
* per-directive entries upstream), so this reuses that resolution rather
|
|
77
|
+
* than re-implementing it against the generic predicate system.
|
|
78
|
+
*
|
|
79
|
+
* @param customDirectives - the schema-resolved `customDirective` map, or
|
|
80
|
+
* `undefined`/empty when the option is not in use.
|
|
81
|
+
*
|
|
82
|
+
* @returns the three decorators, or `{}` when `customDirectives` is empty.
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
export declare const buildCustomDirectiveDecorators: (customDirectives: Maybe<CustomDirectiveMap>) => Decorators;
|
|
86
|
+
/**
|
|
87
|
+
* Builds the example section as a decorator definition.
|
|
88
|
+
*
|
|
89
|
+
* The example section is a specialized decorator: it is driven by a schema
|
|
90
|
+
* directive, named by [`printTypeOptions.exampleSection`](https://graphql-markdown.dev/docs/settings#printtypeoptions),
|
|
91
|
+
* and rendered as a code block.
|
|
92
|
+
*
|
|
93
|
+
* It resolves its own value rather than gating on a directive by name,
|
|
94
|
+
* because an example is also derived from the fields of a type carrying no
|
|
95
|
+
* example directive itself — the directive lookup (which schema directive
|
|
96
|
+
* name to use, from `printTypeOptions.exampleSection`) belongs to
|
|
97
|
+
* {@link printExample} alone.
|
|
98
|
+
*
|
|
99
|
+
* @param options - the print options in effect.
|
|
100
|
+
*
|
|
101
|
+
* @returns the example decorator definition.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const section = getExampleSectionDefinition(options);
|
|
106
|
+
* const example = printDecorator(type, section, options);
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
export declare const getExampleSectionDefinition: () => ResolvedDecorator;
|
|
111
|
+
/**
|
|
112
|
+
* Prints a single decorator for a type, as a titled page section.
|
|
113
|
+
*
|
|
114
|
+
* Reserved ids are filtered by `getDeclaredDecorators`, not here: the built-in
|
|
115
|
+
* sections are themselves declared with a reserved id.
|
|
116
|
+
*
|
|
117
|
+
* @param type - the GraphQL type being printed.
|
|
118
|
+
* @param decorator - the resolved decorator declaration.
|
|
119
|
+
* @param options - the print options in effect.
|
|
120
|
+
*
|
|
121
|
+
* @returns the rendered page section, or `undefined` when nothing to print.
|
|
122
|
+
*
|
|
123
|
+
*/
|
|
124
|
+
export declare const printDecorator: (type: unknown, decorator: ResolvedDecorator, options: PrintTypeOptions) => Maybe<PageSection>;
|
|
125
|
+
/**
|
|
126
|
+
* Prints every decorator declared in the print options, excluding those
|
|
127
|
+
* targeting a named slot (`position: { into }`) — those are not part of the
|
|
128
|
+
* page's section order and are printed separately, into their slot.
|
|
129
|
+
*
|
|
130
|
+
* Every declared decorator yields an entry, so that composition hooks can
|
|
131
|
+
* restore one which rendered no content. Decorators with a reserved or
|
|
132
|
+
* repeated id are dropped.
|
|
133
|
+
*
|
|
134
|
+
* @param type - the GraphQL type being printed.
|
|
135
|
+
* @param options - the print options in effect.
|
|
136
|
+
*
|
|
137
|
+
* @returns a map of decorator id to rendered section, empty when none is declared.
|
|
138
|
+
*
|
|
139
|
+
*/
|
|
140
|
+
export declare const printDecorators: (type: unknown, options: PrintTypeOptions) => PageSections;
|
|
141
|
+
/**
|
|
142
|
+
* Prints every decorator declared for a named slot (`position: { into: slot }`),
|
|
143
|
+
* as raw content rather than a page section — used to splice decorator output
|
|
144
|
+
* into a slot outside the page's section order, such as the metadata line of a
|
|
145
|
+
* type or field heading, or a member's description.
|
|
146
|
+
*
|
|
147
|
+
* @param slot - the slot name (matches a decorator's `position.into`).
|
|
148
|
+
* @param type - the GraphQL type being printed.
|
|
149
|
+
* @param options - the print options in effect.
|
|
150
|
+
*
|
|
151
|
+
* @returns the rendered content for every decorator targeting `slot`, in
|
|
152
|
+
* declaration order; empty when none target it or render no content.
|
|
153
|
+
*
|
|
154
|
+
*/
|
|
155
|
+
export declare const printSlotDecorators: (slot: string, type: unknown, options: PrintTypeOptions) => string[];
|
|
156
|
+
/**
|
|
157
|
+
* Splices the decorators into the built-in section order.
|
|
158
|
+
*
|
|
159
|
+
* A decorator is placed after or before the section named by its `position`,
|
|
160
|
+
* and appended last when `position` is absent or names an unknown section.
|
|
161
|
+
* A decorator using `into` (a named slot outside the page section order — see
|
|
162
|
+
* {@link DecoratorPosition}) is excluded entirely: it is not part of the page
|
|
163
|
+
* section order and is printed separately, into its slot. Decorators are
|
|
164
|
+
* placed in declaration order, so a decorator may target a previously placed
|
|
165
|
+
* one.
|
|
166
|
+
*
|
|
167
|
+
* @param sectionOrder - the built-in section order.
|
|
168
|
+
* @param options - the print options in effect.
|
|
169
|
+
*
|
|
170
|
+
* @returns the section order including the decorators.
|
|
171
|
+
*
|
|
172
|
+
*/
|
|
173
|
+
export declare const getDecoratorsOrder: (sectionOrder: readonly string[], options: PrintTypeOptions) => string[];
|
|
174
|
+
//# sourceMappingURL=decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.d.ts","sourceRoot":"","sources":["../src/decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAEV,kBAAkB,EAIlB,mBAAmB,EACnB,UAAU,EAEV,KAAK,EACL,WAAW,EACX,YAAY,EACZ,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAGL,eAAe,EAChB,MAAM,2BAA2B,CAAC;AAgBnC,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,GAAG;IACpD,8DAA8D;IAC9D,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAa1C,CAAC;AA8EX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,8BAA8B,qBACvB,KAAK,CAAC,kBAAkB,CAAC,KAC1C,UAqFF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,2BAA2B,QAAO,iBAe9C,CAAC;AA4FF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,SACnB,OAAO,aACF,iBAAiB,WACnB,gBAAgB,KACxB,KAAK,CAAC,WAAW,CAcnB,CAAC;AAyDF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,eAAe,SACpB,OAAO,WACJ,gBAAgB,KACxB,YAgBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,SACxB,MAAM,QACN,OAAO,WACJ,gBAAgB,KACxB,MAAM,EAcR,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,iBACf,SAAS,MAAM,EAAE,WACtB,gBAAgB,KACxB,MAAM,EAuBR,CAAC"}
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Module providing predicate-driven decorators for type pages.
|
|
4
|
+
*
|
|
5
|
+
* A decorator (declared in the top-level `decorators` option) is selected by a
|
|
6
|
+
* predicate over the node being printed — by default, every node — and
|
|
7
|
+
* renders its resolved values through a user callback. There is no built-in
|
|
8
|
+
* notion of "this decorator's own directive": a directive-driven decorator
|
|
9
|
+
* selects its nodes with `predicate: hasDirectiveNamed("name")` and reads
|
|
10
|
+
* that directive's argument values, if any, from `resolve` via
|
|
11
|
+
* `@graphql-markdown/graphql`'s `getDirectiveFromSchema` combined with
|
|
12
|
+
* `getTypeDirectiveValues`/`getTypeDirectiveValuesList` — the same public
|
|
13
|
+
* helpers this module uses internally. A decorator with a title becomes a top-level
|
|
14
|
+
* section of the type page; one without renders bare content, placed relative
|
|
15
|
+
* to the built-in sections, or into a named slot such as the heading's
|
|
16
|
+
* metadata line or a member's description.
|
|
17
|
+
*
|
|
18
|
+
* `customDirective` is the deprecated predecessor of this module. It never
|
|
19
|
+
* reaches this module, or any other part of the printer: `@graphql-markdown/core`
|
|
20
|
+
* converts its schema-resolved directive map into decorator declarations
|
|
21
|
+
* (see {@link buildCustomDirectiveDecorators}) once, before the printer is
|
|
22
|
+
* ever invoked, so both options flow through the exact same resolve/render
|
|
23
|
+
* pipeline below — there is one code path for "select nodes by directive,
|
|
24
|
+
* render descriptor text, a badge, or a section", not two.
|
|
25
|
+
*
|
|
26
|
+
* @packageDocumentation
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getDecoratorsOrder = exports.printSlotDecorators = exports.printDecorators = exports.printDecorator = exports.getExampleSectionDefinition = exports.buildCustomDirectiveDecorators = exports.RESERVED_SECTION_NAMES = exports.getSchemaEntity = void 0;
|
|
30
|
+
const graphql_1 = require("@graphql-markdown/graphql");
|
|
31
|
+
Object.defineProperty(exports, "getSchemaEntity", { enumerable: true, get: function () { return graphql_1.getSchemaEntity; } });
|
|
32
|
+
const utils_1 = require("@graphql-markdown/utils");
|
|
33
|
+
const badge_1 = require("./badge");
|
|
34
|
+
const example_1 = require("./example");
|
|
35
|
+
const link_1 = require("./link");
|
|
36
|
+
const strings_1 = require("./const/strings");
|
|
37
|
+
const options_1 = require("./const/options");
|
|
38
|
+
/**
|
|
39
|
+
* Section/decorator keys owned by the printer, which a decorator cannot claim.
|
|
40
|
+
*
|
|
41
|
+
* Re-exported from the package root: `@graphql-markdown/core`'s
|
|
42
|
+
* `getDecoratorsOption` validates against this same list (plus `"__proto__"`,
|
|
43
|
+
* reserved only there — see that package's own copy of this comment) so the
|
|
44
|
+
* two entry points, config-file validation and building a decorators map
|
|
45
|
+
* directly against the printer API, can't silently drift apart on which
|
|
46
|
+
* names are reserved.
|
|
47
|
+
*/
|
|
48
|
+
exports.RESERVED_SECTION_NAMES = [
|
|
49
|
+
"header",
|
|
50
|
+
"metatags",
|
|
51
|
+
"mdxDeclaration",
|
|
52
|
+
"tags",
|
|
53
|
+
"description",
|
|
54
|
+
"code",
|
|
55
|
+
"customDirectives",
|
|
56
|
+
"customDirective:description",
|
|
57
|
+
"customDirective:tags",
|
|
58
|
+
"metadata",
|
|
59
|
+
"example",
|
|
60
|
+
"relations",
|
|
61
|
+
];
|
|
62
|
+
/**
|
|
63
|
+
* Ids {@link buildCustomDirectiveDecorators} assigns to its three adapter
|
|
64
|
+
* decorators. Reserved above so a user's own `decorators` config can't claim
|
|
65
|
+
* them, but exempted from `getDeclaredDecorators`'s reserved-id filter so
|
|
66
|
+
* `@graphql-markdown/core` can merge the converter's own output for these
|
|
67
|
+
* ids directly into `options.decorators`.
|
|
68
|
+
*
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
const CUSTOM_DIRECTIVE_DECORATOR_IDS = [
|
|
72
|
+
"customDirectives",
|
|
73
|
+
"customDirective:description",
|
|
74
|
+
"customDirective:tags",
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* Resolves a custom directive handler's return value.
|
|
78
|
+
*
|
|
79
|
+
* Internal to {@link buildCustomDirectiveDecorators}'s render closures; not
|
|
80
|
+
* itself user-facing — see `ConfigOptions.customDirective` for the setting.
|
|
81
|
+
*
|
|
82
|
+
* @param resolver - The resolver function name to execute
|
|
83
|
+
* @param type - The GraphQL type to resolve the directive for
|
|
84
|
+
* @param constDirectiveOption - The directive configuration options
|
|
85
|
+
* @param fallback - Optional fallback value if resolution fails
|
|
86
|
+
* @returns The resolved directive value or `fallback`/`undefined`
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
const getCustomDirectiveResolver = (resolver, type, constDirectiveOption, fallback) => {
|
|
91
|
+
if (typeof constDirectiveOption.type !== "object" ||
|
|
92
|
+
typeof constDirectiveOption[resolver] !== "function") {
|
|
93
|
+
return fallback;
|
|
94
|
+
}
|
|
95
|
+
return constDirectiveOption[resolver](constDirectiveOption.type, type);
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Prints a single custom directive entry as a Markdown string, for the
|
|
99
|
+
* built-in "Directives" section.
|
|
100
|
+
*
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
const printCustomDirective = (type, constDirectiveOption, options) => {
|
|
104
|
+
const typeNameLink = (0, link_1.printLink)(constDirectiveOption.type, {
|
|
105
|
+
...options,
|
|
106
|
+
withAttributes: false,
|
|
107
|
+
});
|
|
108
|
+
const description = getCustomDirectiveResolver("descriptor", type, constDirectiveOption);
|
|
109
|
+
if (typeof description !== "string") {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
return `${options_1.SectionLevels.LEVEL.repeat(4)} ${typeNameLink}${strings_1.MARKDOWN_EOL} ${description}${strings_1.MARKDOWN_EOL} `;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Converts the deprecated `customDirective` option's schema-resolved
|
|
116
|
+
* directive map into decorator declarations, so it flows through the exact
|
|
117
|
+
* same resolve/render pipeline as everything declared under `decorators`.
|
|
118
|
+
*
|
|
119
|
+
* Called once by `@graphql-markdown/core`, right after `customDirectives` is
|
|
120
|
+
* schema-resolved, and merged directly into the top-level `decorators`
|
|
121
|
+
* option before it reaches the printer — `customDirective`/`CustomDirectiveMap`
|
|
122
|
+
* never reach this printer package otherwise; only the three decorators
|
|
123
|
+
* built here do, indistinguishable from any other `decorators` entry except
|
|
124
|
+
* for their reserved ids (see {@link CUSTOM_DIRECTIVE_DECORATOR_IDS}).
|
|
125
|
+
*
|
|
126
|
+
* Returns three entries:
|
|
127
|
+
* - `customDirectives`: the built-in "Directives" section, listing every
|
|
128
|
+
* custom directive declared on a type, positioned right after `code`
|
|
129
|
+
* (its fixed position in the pre-decorators built-in section order).
|
|
130
|
+
* - `customDirective:description`: `customDirective`'s `descriptor`
|
|
131
|
+
* handlers, appended as description text (`position: { into: "description" }`).
|
|
132
|
+
* - `customDirective:tags`: `customDirective`'s `tag` handlers, rendered as
|
|
133
|
+
* badges in the metadata line (`position: { into: "tags" }`).
|
|
134
|
+
*
|
|
135
|
+
* All three share one `resolve`, reading every custom directive matched on
|
|
136
|
+
* a node, in schema declaration order. Matching (including wildcard `"*"`
|
|
137
|
+
* precedence — a named handler wins over `"*"`) is already resolved by
|
|
138
|
+
* `getConstDirectiveMap` (fed by `@graphql-markdown/graphql`'s
|
|
139
|
+
* `getCustomDirectives`, which expands a wildcard into concrete
|
|
140
|
+
* per-directive entries upstream), so this reuses that resolution rather
|
|
141
|
+
* than re-implementing it against the generic predicate system.
|
|
142
|
+
*
|
|
143
|
+
* @param customDirectives - the schema-resolved `customDirective` map, or
|
|
144
|
+
* `undefined`/empty when the option is not in use.
|
|
145
|
+
*
|
|
146
|
+
* @returns the three decorators, or `{}` when `customDirectives` is empty.
|
|
147
|
+
*
|
|
148
|
+
*/
|
|
149
|
+
const buildCustomDirectiveDecorators = (customDirectives) => {
|
|
150
|
+
if (typeof customDirectives !== "object" ||
|
|
151
|
+
customDirectives === null ||
|
|
152
|
+
Object.keys(customDirectives).length === 0) {
|
|
153
|
+
return {};
|
|
154
|
+
}
|
|
155
|
+
const resolve = (type) => {
|
|
156
|
+
const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, customDirectives);
|
|
157
|
+
return constDirectiveMap
|
|
158
|
+
? Object.values(constDirectiveMap)
|
|
159
|
+
: [];
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
customDirectives: {
|
|
163
|
+
title: "Directives",
|
|
164
|
+
predicate: (0, graphql_1.always)(),
|
|
165
|
+
resolve,
|
|
166
|
+
position: { after: "code" },
|
|
167
|
+
render: (values, options, context) => {
|
|
168
|
+
const directives = values
|
|
169
|
+
.map((item) => {
|
|
170
|
+
return printCustomDirective(context.type, item, options);
|
|
171
|
+
})
|
|
172
|
+
.filter((value) => {
|
|
173
|
+
return value !== undefined;
|
|
174
|
+
});
|
|
175
|
+
return directives.length > 0
|
|
176
|
+
? directives.join(strings_1.MARKDOWN_EOP)
|
|
177
|
+
: undefined;
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
"customDirective:description": {
|
|
181
|
+
predicate: (0, graphql_1.always)(),
|
|
182
|
+
resolve,
|
|
183
|
+
position: { into: "description" },
|
|
184
|
+
render: (values, _options, context) => {
|
|
185
|
+
const parts = values
|
|
186
|
+
.map((item) => {
|
|
187
|
+
return getCustomDirectiveResolver("descriptor", context.type, item, "");
|
|
188
|
+
})
|
|
189
|
+
.filter((text) => {
|
|
190
|
+
return typeof text === "string" && text.length > 0;
|
|
191
|
+
})
|
|
192
|
+
.map((text) => {
|
|
193
|
+
return (0, utils_1.escapeMDX)(text);
|
|
194
|
+
});
|
|
195
|
+
return parts.length > 0 ? parts.join(strings_1.MARKDOWN_EOP) : undefined;
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
"customDirective:tags": {
|
|
199
|
+
predicate: (0, graphql_1.always)(),
|
|
200
|
+
resolve,
|
|
201
|
+
position: { into: "tags" },
|
|
202
|
+
render: (values, options, context) => {
|
|
203
|
+
const badges = values
|
|
204
|
+
.map((item) => {
|
|
205
|
+
return getCustomDirectiveResolver("tag", context.type, item);
|
|
206
|
+
})
|
|
207
|
+
.filter((value) => {
|
|
208
|
+
return value !== undefined;
|
|
209
|
+
});
|
|
210
|
+
return badges.length > 0
|
|
211
|
+
? (0, badge_1.formatBadges)(badges, options)
|
|
212
|
+
: undefined;
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
exports.buildCustomDirectiveDecorators = buildCustomDirectiveDecorators;
|
|
218
|
+
/**
|
|
219
|
+
* Builds the example section as a decorator definition.
|
|
220
|
+
*
|
|
221
|
+
* The example section is a specialized decorator: it is driven by a schema
|
|
222
|
+
* directive, named by [`printTypeOptions.exampleSection`](https://graphql-markdown.dev/docs/settings#printtypeoptions),
|
|
223
|
+
* and rendered as a code block.
|
|
224
|
+
*
|
|
225
|
+
* It resolves its own value rather than gating on a directive by name,
|
|
226
|
+
* because an example is also derived from the fields of a type carrying no
|
|
227
|
+
* example directive itself — the directive lookup (which schema directive
|
|
228
|
+
* name to use, from `printTypeOptions.exampleSection`) belongs to
|
|
229
|
+
* {@link printExample} alone.
|
|
230
|
+
*
|
|
231
|
+
* @param options - the print options in effect.
|
|
232
|
+
*
|
|
233
|
+
* @returns the example decorator definition.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* const section = getExampleSectionDefinition(options);
|
|
238
|
+
* const example = printDecorator(type, section, options);
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
*/
|
|
242
|
+
const getExampleSectionDefinition = () => {
|
|
243
|
+
return {
|
|
244
|
+
id: "example",
|
|
245
|
+
title: "Example",
|
|
246
|
+
resolve: (type, printOptions) => {
|
|
247
|
+
const example = (0, example_1.printExample)(type, printOptions);
|
|
248
|
+
return example ? [{ example }] : [];
|
|
249
|
+
},
|
|
250
|
+
render: (values) => {
|
|
251
|
+
return `${strings_1.MARKDOWN_SOC}${values[0].example}${strings_1.MARKDOWN_EOC}`;
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
exports.getExampleSectionDefinition = getExampleSectionDefinition;
|
|
256
|
+
/**
|
|
257
|
+
* Resolves the values a decorator renders, applying the marker-decorator
|
|
258
|
+
* substitution rule.
|
|
259
|
+
*
|
|
260
|
+
* `undefined` means "skip this decorator": either its resolver returned a
|
|
261
|
+
* non-array, or it resolved no values with nothing asking for the
|
|
262
|
+
* marker-decorator substitution below. A decorator with an explicit
|
|
263
|
+
* `predicate` and no `resolve` renders once, with an empty record, whenever
|
|
264
|
+
* its predicate matches — a pure marker decorator, useful for a directive
|
|
265
|
+
* whose mere presence is the content (see the module doc for how to also
|
|
266
|
+
* gate on, and read, a specific directive). A `resolve` returning `[]` is
|
|
267
|
+
* never ambiguous with that case — it means "nothing to render this time"
|
|
268
|
+
* — so it is not substituted; nor is the no-`predicate`-no-`resolve` case,
|
|
269
|
+
* which is a no-op by construction (`predicate` defaults to matching every
|
|
270
|
+
* node, `resolve` to producing nothing).
|
|
271
|
+
*
|
|
272
|
+
* @internal
|
|
273
|
+
*/
|
|
274
|
+
const resolveDecoratorValues = (type, decorator, options) => {
|
|
275
|
+
const resolved = decorator.resolve ? decorator.resolve(type, options) : [];
|
|
276
|
+
if (!Array.isArray(resolved)) {
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
if (resolved.length === 0) {
|
|
280
|
+
return !decorator.predicate || decorator.resolve ? undefined : [{}];
|
|
281
|
+
}
|
|
282
|
+
return resolved;
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Resolves and renders a single decorator's raw content for a type.
|
|
286
|
+
*
|
|
287
|
+
* The decorator is skipped, returning `undefined`, when its predicate does
|
|
288
|
+
* not match, no value is resolved for it, or the render callback returns no
|
|
289
|
+
* content. Shared by {@link printDecorator}
|
|
290
|
+
* (which wraps this into a titled page section) and {@link printSlotDecorators}
|
|
291
|
+
* (which collects this raw content for a named slot, such as the metadata line).
|
|
292
|
+
*
|
|
293
|
+
* @internal
|
|
294
|
+
*
|
|
295
|
+
* @param type - the GraphQL type being printed.
|
|
296
|
+
* @param decorator - the resolved decorator declaration.
|
|
297
|
+
* @param options - the print options in effect.
|
|
298
|
+
*
|
|
299
|
+
* @returns the decorator's rendered content, or `undefined` when nothing to print.
|
|
300
|
+
*
|
|
301
|
+
*/
|
|
302
|
+
const renderDecoratorContent = (type, decorator, options) => {
|
|
303
|
+
if (typeof decorator.render !== "function") {
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
const predicate = decorator.predicate ?? (0, graphql_1.always)();
|
|
307
|
+
if (!predicate(type, options)) {
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
const values = resolveDecoratorValues(type, decorator, options);
|
|
311
|
+
if (values === undefined || values === null) {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
const context = {
|
|
315
|
+
id: decorator.id,
|
|
316
|
+
type,
|
|
317
|
+
entity: (0, graphql_1.getSchemaEntity)(type, options),
|
|
318
|
+
};
|
|
319
|
+
const content = decorator.render(values, options, context);
|
|
320
|
+
if (typeof content !== "string" || content.trim().length === 0) {
|
|
321
|
+
return undefined;
|
|
322
|
+
}
|
|
323
|
+
return content;
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Prints a single decorator for a type, as a titled page section.
|
|
327
|
+
*
|
|
328
|
+
* Reserved ids are filtered by `getDeclaredDecorators`, not here: the built-in
|
|
329
|
+
* sections are themselves declared with a reserved id.
|
|
330
|
+
*
|
|
331
|
+
* @param type - the GraphQL type being printed.
|
|
332
|
+
* @param decorator - the resolved decorator declaration.
|
|
333
|
+
* @param options - the print options in effect.
|
|
334
|
+
*
|
|
335
|
+
* @returns the rendered page section, or `undefined` when nothing to print.
|
|
336
|
+
*
|
|
337
|
+
*/
|
|
338
|
+
const printDecorator = (type, decorator, options) => {
|
|
339
|
+
const content = renderDecoratorContent(type, decorator, options);
|
|
340
|
+
if (content === undefined) {
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
title: decorator.title ?? undefined,
|
|
345
|
+
// The render callback owns its Markdown: trimming here would alter content
|
|
346
|
+
// whose leading whitespace is significant, such as an indented code block.
|
|
347
|
+
content: `${content}${strings_1.MARKDOWN_EOP}`,
|
|
348
|
+
level: decorator.level ?? 3,
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
exports.printDecorator = printDecorator;
|
|
352
|
+
/**
|
|
353
|
+
* Returns the decorators to build, in declaration order, from the top-level
|
|
354
|
+
* `decorators` option. `@graphql-markdown/core` merges `customDirective`'s
|
|
355
|
+
* adapter decorators (see {@link buildCustomDirectiveDecorators}) into this
|
|
356
|
+
* same option before it reaches the printer, so this reads a single source,
|
|
357
|
+
* with no separate customDirective-specific path.
|
|
358
|
+
*
|
|
359
|
+
* Every entry is filtered against reserved ids, except the adapter's own —
|
|
360
|
+
* see {@link CUSTOM_DIRECTIVE_DECORATOR_IDS} — since those are assigned by
|
|
361
|
+
* the converter, not user config, and are reserved specifically to keep user
|
|
362
|
+
* config from claiming them. A user-declared decorator claiming any other
|
|
363
|
+
* reserved id is still dropped: the printer is reachable directly through
|
|
364
|
+
* its public API, bypassing configuration validation, and such a decorator
|
|
365
|
+
* would otherwise overwrite a built-in section.
|
|
366
|
+
*
|
|
367
|
+
* @internal
|
|
368
|
+
*
|
|
369
|
+
* @param options - the print options in effect.
|
|
370
|
+
*
|
|
371
|
+
* @returns the decorators to build.
|
|
372
|
+
*
|
|
373
|
+
*/
|
|
374
|
+
const getDeclaredDecorators = (options) => {
|
|
375
|
+
const decorators = typeof options.decorators === "object" && options.decorators !== null
|
|
376
|
+
? options.decorators
|
|
377
|
+
: undefined;
|
|
378
|
+
return decorators
|
|
379
|
+
? Object.entries(decorators)
|
|
380
|
+
.filter(([id]) => {
|
|
381
|
+
return (!exports.RESERVED_SECTION_NAMES.includes(id) ||
|
|
382
|
+
CUSTOM_DIRECTIVE_DECORATOR_IDS.includes(id));
|
|
383
|
+
})
|
|
384
|
+
.map(([id, decorator]) => {
|
|
385
|
+
return { ...decorator, id };
|
|
386
|
+
})
|
|
387
|
+
: [];
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* Checks whether a decorator targets a named slot (`position: { into }`)
|
|
391
|
+
* rather than the page's section order.
|
|
392
|
+
*
|
|
393
|
+
* @internal
|
|
394
|
+
*/
|
|
395
|
+
const targetsSlot = (decorator) => {
|
|
396
|
+
const position = decorator.position;
|
|
397
|
+
return !!position && typeof position === "object" && "into" in position;
|
|
398
|
+
};
|
|
399
|
+
/**
|
|
400
|
+
* Prints every decorator declared in the print options, excluding those
|
|
401
|
+
* targeting a named slot (`position: { into }`) — those are not part of the
|
|
402
|
+
* page's section order and are printed separately, into their slot.
|
|
403
|
+
*
|
|
404
|
+
* Every declared decorator yields an entry, so that composition hooks can
|
|
405
|
+
* restore one which rendered no content. Decorators with a reserved or
|
|
406
|
+
* repeated id are dropped.
|
|
407
|
+
*
|
|
408
|
+
* @param type - the GraphQL type being printed.
|
|
409
|
+
* @param options - the print options in effect.
|
|
410
|
+
*
|
|
411
|
+
* @returns a map of decorator id to rendered section, empty when none is declared.
|
|
412
|
+
*
|
|
413
|
+
*/
|
|
414
|
+
const printDecorators = (type, options) => {
|
|
415
|
+
// Null-prototype map: a decorator named `__proto__` would otherwise reach the
|
|
416
|
+
// prototype setter of an object literal and never become an own property.
|
|
417
|
+
// An object literal cannot declare that key, but the printer is also reachable
|
|
418
|
+
// directly, with a declaration built any other way.
|
|
419
|
+
const sections = Object.create(null);
|
|
420
|
+
getDeclaredDecorators(options)
|
|
421
|
+
.filter((decorator) => {
|
|
422
|
+
return !targetsSlot(decorator);
|
|
423
|
+
})
|
|
424
|
+
.forEach((decorator) => {
|
|
425
|
+
sections[decorator.id] = (0, exports.printDecorator)(type, decorator, options);
|
|
426
|
+
});
|
|
427
|
+
return sections;
|
|
428
|
+
};
|
|
429
|
+
exports.printDecorators = printDecorators;
|
|
430
|
+
/**
|
|
431
|
+
* Prints every decorator declared for a named slot (`position: { into: slot }`),
|
|
432
|
+
* as raw content rather than a page section — used to splice decorator output
|
|
433
|
+
* into a slot outside the page's section order, such as the metadata line of a
|
|
434
|
+
* type or field heading, or a member's description.
|
|
435
|
+
*
|
|
436
|
+
* @param slot - the slot name (matches a decorator's `position.into`).
|
|
437
|
+
* @param type - the GraphQL type being printed.
|
|
438
|
+
* @param options - the print options in effect.
|
|
439
|
+
*
|
|
440
|
+
* @returns the rendered content for every decorator targeting `slot`, in
|
|
441
|
+
* declaration order; empty when none target it or render no content.
|
|
442
|
+
*
|
|
443
|
+
*/
|
|
444
|
+
const printSlotDecorators = (slot, type, options) => {
|
|
445
|
+
return getDeclaredDecorators(options)
|
|
446
|
+
.filter((decorator) => {
|
|
447
|
+
return (targetsSlot(decorator) &&
|
|
448
|
+
decorator.position.into === slot);
|
|
449
|
+
})
|
|
450
|
+
.map((decorator) => {
|
|
451
|
+
return renderDecoratorContent(type, decorator, options);
|
|
452
|
+
})
|
|
453
|
+
.filter((content) => {
|
|
454
|
+
return typeof content === "string";
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
exports.printSlotDecorators = printSlotDecorators;
|
|
458
|
+
/**
|
|
459
|
+
* Splices the decorators into the built-in section order.
|
|
460
|
+
*
|
|
461
|
+
* A decorator is placed after or before the section named by its `position`,
|
|
462
|
+
* and appended last when `position` is absent or names an unknown section.
|
|
463
|
+
* A decorator using `into` (a named slot outside the page section order — see
|
|
464
|
+
* {@link DecoratorPosition}) is excluded entirely: it is not part of the page
|
|
465
|
+
* section order and is printed separately, into its slot. Decorators are
|
|
466
|
+
* placed in declaration order, so a decorator may target a previously placed
|
|
467
|
+
* one.
|
|
468
|
+
*
|
|
469
|
+
* @param sectionOrder - the built-in section order.
|
|
470
|
+
* @param options - the print options in effect.
|
|
471
|
+
*
|
|
472
|
+
* @returns the section order including the decorators.
|
|
473
|
+
*
|
|
474
|
+
*/
|
|
475
|
+
const getDecoratorsOrder = (sectionOrder, options) => {
|
|
476
|
+
return getDeclaredDecorators(options)
|
|
477
|
+
.filter((decorator) => {
|
|
478
|
+
return !targetsSlot(decorator);
|
|
479
|
+
})
|
|
480
|
+
.reduce((order, decorator) => {
|
|
481
|
+
const position = decorator.position;
|
|
482
|
+
const anchor = position
|
|
483
|
+
? (position.after ?? position.before)
|
|
484
|
+
: undefined;
|
|
485
|
+
const index = anchor ? order.indexOf(anchor) : -1;
|
|
486
|
+
if (index === -1) {
|
|
487
|
+
order.push(decorator.id);
|
|
488
|
+
return order;
|
|
489
|
+
}
|
|
490
|
+
order.splice(position?.after ? index + 1 : index, 0, decorator.id);
|
|
491
|
+
return order;
|
|
492
|
+
}, [...sectionOrder]);
|
|
493
|
+
};
|
|
494
|
+
exports.getDecoratorsOrder = getDecoratorsOrder;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Printer } from "./printer";
|
|
2
|
+
export { buildCustomDirectiveDecorators, RESERVED_SECTION_NAMES, } from "./decorator";
|
|
2
3
|
export { PrintCodeEvent, PrintTypeEvent, BeforeComposePageTypeEvent, } from "./events";
|
|
3
4
|
export type { PageSection, PageSections, PrintCodeEventData, PrintTypeEventData, ComposePageTypeEventData, } from "./events";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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"}
|
|
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,8BAA8B,EAC9B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,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,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BeforeComposePageTypeEvent = exports.PrintTypeEvent = exports.PrintCodeEvent = exports.Printer = void 0;
|
|
3
|
+
exports.BeforeComposePageTypeEvent = exports.PrintTypeEvent = exports.PrintCodeEvent = exports.RESERVED_SECTION_NAMES = exports.buildCustomDirectiveDecorators = exports.Printer = void 0;
|
|
4
4
|
var printer_1 = require("./printer");
|
|
5
5
|
Object.defineProperty(exports, "Printer", { enumerable: true, get: function () { return printer_1.Printer; } });
|
|
6
|
+
var decorator_1 = require("./decorator");
|
|
7
|
+
Object.defineProperty(exports, "buildCustomDirectiveDecorators", { enumerable: true, get: function () { return decorator_1.buildCustomDirectiveDecorators; } });
|
|
8
|
+
Object.defineProperty(exports, "RESERVED_SECTION_NAMES", { enumerable: true, get: function () { return decorator_1.RESERVED_SECTION_NAMES; } });
|
|
6
9
|
var events_1 = require("./events");
|
|
7
10
|
Object.defineProperty(exports, "PrintCodeEvent", { enumerable: true, get: function () { return events_1.PrintCodeEvent; } });
|
|
8
11
|
Object.defineProperty(exports, "PrintTypeEvent", { enumerable: true, get: function () { return events_1.PrintTypeEvent; } });
|
package/dist/printer.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { Formatter, GraphQLSchema, IPrinter, Maybe, MDXString, PageSection, PrinterEventEmitter, PrinterInitOptions, PrintTypeOptions } from "@graphql-markdown/types";
|
|
11
11
|
import { printDescription } from "./common";
|
|
12
|
-
import {
|
|
12
|
+
import { printDecorators } from "./decorator";
|
|
13
13
|
/**
|
|
14
14
|
* The Printer class implements the core functionality for generating Markdown documentation
|
|
15
15
|
* from GraphQL schema types.
|
|
@@ -34,13 +34,9 @@ export declare class Printer implements IPrinter {
|
|
|
34
34
|
*/
|
|
35
35
|
static readonly printDescription: typeof printDescription;
|
|
36
36
|
/**
|
|
37
|
-
* Prints
|
|
37
|
+
* Prints predicate-driven decorators
|
|
38
38
|
*/
|
|
39
|
-
static readonly
|
|
40
|
-
/**
|
|
41
|
-
* Prints custom tags
|
|
42
|
-
*/
|
|
43
|
-
static readonly printCustomTags: typeof printCustomTags;
|
|
39
|
+
static readonly printDecorators: typeof printDecorators;
|
|
44
40
|
private static _eventEmitter;
|
|
45
41
|
private static _options;
|
|
46
42
|
private static _mdxDeclaration;
|
|
@@ -72,7 +68,7 @@ export declare class Printer implements IPrinter {
|
|
|
72
68
|
* @param mdxDeclaration - Optional MDX import declaration
|
|
73
69
|
* @param eventEmitter - Optional event emitter for print events interception
|
|
74
70
|
*/
|
|
75
|
-
static init(schema: Maybe<GraphQLSchema>, baseURL?: Maybe<string>, linkRoot?: Maybe<string>, {
|
|
71
|
+
static init(schema: Maybe<GraphQLSchema>, baseURL?: Maybe<string>, linkRoot?: Maybe<string>, { decorators, deprecated, groups, meta, metatags, onlyDocDirectives, printTypeOptions, skipDocDirectives, sectionHeaderId, }?: PrinterInitOptions, formatter?: Partial<Formatter>, mdxDeclaration?: Maybe<string>, eventEmitter?: Maybe<PrinterEventEmitter>): Promise<void>;
|
|
76
72
|
/**
|
|
77
73
|
* Prints the header section of a type documentation
|
|
78
74
|
*
|
package/dist/printer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../src/printer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAEV,SAAS,EACT,aAAa,EACb,QAAQ,EACR,KAAK,EACL,SAAS,EACT,WAAW,EAEX,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAGjB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../src/printer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAEV,SAAS,EACT,aAAa,EACb,QAAQ,EACR,KAAK,EACL,SAAS,EACT,WAAW,EAEX,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAGjB,MAAM,yBAAyB,CAAC;AAgDjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAIL,eAAe,EAEhB,MAAM,aAAa,CAAC;AAsFrB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,OAAQ,YAAW,QAAQ;IACtC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,gBAAgB,0BAAoB;IAEpD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,eAAe,yBAAmB;IAElD,OAAO,CAAC,MAAM,CAAC,aAAa,CAA6B;IAEzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAoC;IAE3D,OAAO,CAAC,MAAM,CAAC,eAAe,CAA0B;IAExD;;OAEG;IACH,MAAM,KAAK,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAEtD;IAED;;;;OAIG;IACH,MAAM,KAAK,YAAY,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAEpD;IAED;;OAEG;IACH,MAAM,KAAK,cAAc,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAEnD;IAED,MAAM,KAAK,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,EAE5D;IAED,MAAM,KAAK,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,mBAAmB,CAAC,EAE/D;IAED,MAAM,KAAK,cAAc,CAAC,cAAc,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAEhE;IAED;;;;;;;;;;OAUG;IACH,OAAa,IAAI,CACf,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,EAC5B,OAAO,GAAE,KAAK,CAAC,MAAM,CAAY,EACjC,QAAQ,GAAE,KAAK,CAAC,MAAM,CAAO,EAC7B,EACE,UAAU,EACV,UAAU,EACV,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAChB,GAAE,kBAAyC,EAC5C,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,EAC9B,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EAC9B,YAAY,CAAC,EAAE,KAAK,CAAC,mBAAmB,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC,CAuCf;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,CAAC,WAAW,OACrB,MAAM,SACH,MAAM,WACJ,gBAAgB,KACxB,MAAM,CAQP;IAEF;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,SACjB,OAAO,WACJ,gBAAgB,KACxB,MAAM,CAiCP;IAEF;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,SACtB,OAAO,YACH,MAAM,WACP,gBAAgB,KACxB,OAAO,CAAC,MAAM,CAAC,CAgChB;IAEF;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,YAAY,SACpB,OAAO,WACJ,gBAAgB,KACxB,KAAK,CAAC,WAAW,CAAC,CAEnB;IAEF;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,iBAAiB,SACzB,OAAO,WACJ,gBAAgB,KACxB,KAAK,CAAC,WAAW,GAAG,WAAW,EAAE,CAAC,CAqBnC;IAEF;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,SACtB,OAAO,WACJ,gBAAgB,KACxB,SAAS,GAAG,MAAM,CAEnB;IAEF;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,UACpB,OAAO,gBACA,gBAAgB,KAC7B,SAAS,GAAG,MAAM,CAcnB;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,SACjB,KAAK,CAAC,MAAM,CAAC,QACb,OAAO,YACH,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,KACzC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAqH1B;IAEF;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAsDvC;IAEF;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAO9C;IAEF;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAO7C;IAEF;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,4BAA4B,CAgBlD;IAEF;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAY1C;CACH"}
|
package/dist/printer.js
CHANGED
|
@@ -31,7 +31,6 @@ const TYPE_PAGE_SECTION_ORDER = [
|
|
|
31
31
|
"tags",
|
|
32
32
|
"description",
|
|
33
33
|
"code",
|
|
34
|
-
"customDirectives",
|
|
35
34
|
"metadata",
|
|
36
35
|
"example",
|
|
37
36
|
"relations",
|
|
@@ -40,21 +39,19 @@ const graphql_1 = require("@graphql-markdown/graphql");
|
|
|
40
39
|
const utils_1 = require("@graphql-markdown/utils");
|
|
41
40
|
const relation_1 = require("./relation");
|
|
42
41
|
const common_1 = require("./common");
|
|
43
|
-
const
|
|
42
|
+
const decorator_1 = require("./decorator");
|
|
44
43
|
const frontmatter_1 = require("./frontmatter");
|
|
45
44
|
const graphql_2 = require("./graphql");
|
|
46
45
|
const link_1 = require("./link");
|
|
47
46
|
const strings_1 = require("./const/strings");
|
|
48
47
|
const formatter_1 = require("./formatter");
|
|
49
48
|
const options_1 = require("./const/options");
|
|
50
|
-
const example_1 = require("./example");
|
|
51
49
|
const events_1 = require("./events");
|
|
52
50
|
/**
|
|
53
51
|
* Default initialization options for the Printer class.
|
|
54
52
|
* @internal
|
|
55
53
|
*/
|
|
56
54
|
const DEFAULT_INIT_OPTIONS = {
|
|
57
|
-
customDirectives: undefined,
|
|
58
55
|
groups: undefined,
|
|
59
56
|
sectionHeaderId: true,
|
|
60
57
|
};
|
|
@@ -114,13 +111,9 @@ class Printer {
|
|
|
114
111
|
*/
|
|
115
112
|
static printDescription = common_1.printDescription;
|
|
116
113
|
/**
|
|
117
|
-
* Prints
|
|
114
|
+
* Prints predicate-driven decorators
|
|
118
115
|
*/
|
|
119
|
-
static
|
|
120
|
-
/**
|
|
121
|
-
* Prints custom tags
|
|
122
|
-
*/
|
|
123
|
-
static printCustomTags = directive_1.printCustomTags;
|
|
116
|
+
static printDecorators = decorator_1.printDecorators;
|
|
124
117
|
static _eventEmitter;
|
|
125
118
|
static _options;
|
|
126
119
|
static _mdxDeclaration;
|
|
@@ -164,14 +157,14 @@ class Printer {
|
|
|
164
157
|
* @param mdxDeclaration - Optional MDX import declaration
|
|
165
158
|
* @param eventEmitter - Optional event emitter for print events interception
|
|
166
159
|
*/
|
|
167
|
-
static async init(schema, baseURL = "schema", linkRoot = "/", {
|
|
160
|
+
static async init(schema, baseURL = "schema", linkRoot = "/", { decorators, deprecated, groups, meta, metatags, onlyDocDirectives, printTypeOptions, skipDocDirectives, sectionHeaderId, } = DEFAULT_INIT_OPTIONS, formatter, mdxDeclaration, eventEmitter) {
|
|
168
161
|
// Always update eventEmitter regardless of initialization state
|
|
169
162
|
Printer.eventEmitter = eventEmitter ?? null;
|
|
170
163
|
if (Printer.options === undefined) {
|
|
171
164
|
Printer.options = {
|
|
172
165
|
...options_1.DEFAULT_OPTIONS,
|
|
173
166
|
basePath: utils_1.pathUrl.join(linkRoot ?? "", baseURL ?? ""),
|
|
174
|
-
|
|
167
|
+
decorators,
|
|
175
168
|
exampleSection: typeof printTypeOptions?.exampleSection === "object"
|
|
176
169
|
? printTypeOptions.exampleSection
|
|
177
170
|
: undefined,
|
|
@@ -298,14 +291,7 @@ class Printer {
|
|
|
298
291
|
* @returns Example page section or undefined when no example is available
|
|
299
292
|
*/
|
|
300
293
|
static printExample = (type, options) => {
|
|
301
|
-
|
|
302
|
-
if (!example) {
|
|
303
|
-
return undefined;
|
|
304
|
-
}
|
|
305
|
-
return {
|
|
306
|
-
content: `${strings_1.MARKDOWN_SOC}${example}${strings_1.MARKDOWN_EOC}${strings_1.MARKDOWN_EOP}`,
|
|
307
|
-
title: "Example",
|
|
308
|
-
};
|
|
294
|
+
return (0, decorator_1.printDecorator)(type, (0, decorator_1.getExampleSectionDefinition)(), options);
|
|
309
295
|
};
|
|
310
296
|
/**
|
|
311
297
|
* Prints metadata information for a GraphQL type
|
|
@@ -423,12 +409,20 @@ class Printer {
|
|
|
423
409
|
// can add, remove, or reorder them at will.
|
|
424
410
|
// See: https://github.com/graphql-markdown/graphql-markdown/issues/2954
|
|
425
411
|
const code = await Printer.printCodeAsync(type, name, printTypeOptions);
|
|
426
|
-
|
|
427
|
-
|
|
412
|
+
// `customDirective`'s `tag` handlers reach this line via the decorators
|
|
413
|
+
// pipeline (`printSlotDecorators`, not a dedicated call) — see
|
|
414
|
+
// `buildCustomDirectiveDecorators` in `./decorator`.
|
|
415
|
+
const tags = (0, decorator_1.printSlotDecorators)("tags", type, printTypeOptions)
|
|
416
|
+
.filter(Boolean)
|
|
417
|
+
.join(" ");
|
|
428
418
|
const metadata = Printer.printTypeMetadata(type, printTypeOptions);
|
|
429
419
|
const relations = Printer.printRelations(type, printTypeOptions);
|
|
430
420
|
const example = Printer.printExample(type, printTypeOptions);
|
|
431
|
-
// Create sections map for composition events
|
|
421
|
+
// Create sections map for composition events. The built-in "Directives"
|
|
422
|
+
// section reaches this map via the `...Printer.printDecorators(...)`
|
|
423
|
+
// spread below (it is `customDirective`'s adapter, unconditionally
|
|
424
|
+
// present under the reserved `customDirectives` id — see
|
|
425
|
+
// `buildCustomDirectiveDecorators`), not a dedicated field here.
|
|
432
426
|
const sections = {
|
|
433
427
|
header: { content: header },
|
|
434
428
|
metatags: { content: metatags },
|
|
@@ -436,12 +430,12 @@ class Printer {
|
|
|
436
430
|
tags: Printer.normalizePageSection(tags),
|
|
437
431
|
description: Printer.normalizePageSection(description),
|
|
438
432
|
code: Printer.normalizePageSection(code),
|
|
439
|
-
customDirectives: Printer.normalizePageSection(customDirectives),
|
|
440
433
|
metadata: Printer.normalizePageSection(metadata),
|
|
441
434
|
example: Printer.normalizePageSection(example),
|
|
442
435
|
relations: Printer.normalizePageSection(relations),
|
|
436
|
+
...Printer.printDecorators(type, printTypeOptions),
|
|
443
437
|
};
|
|
444
|
-
let sectionOrder =
|
|
438
|
+
let sectionOrder = (0, decorator_1.getDecoratorsOrder)(TYPE_PAGE_SECTION_ORDER, printTypeOptions);
|
|
445
439
|
// Emit BEFORE_COMPOSE_PAGE_TYPE event if emitter is configured
|
|
446
440
|
if (Printer.eventEmitter) {
|
|
447
441
|
const beforeComposeEvent = new events_1.BeforeComposePageTypeEvent({ type, name, options: printTypeOptions, sections }, sectionOrder);
|
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,KAAK,EACL,SAAS,EACT,WAAW,EACX,gBAAgB,EAEjB,MAAM,yBAAyB,CAAC;AA8CjC;;;;;;;;GAQG;AAEH,eAAO,MAAM,gBAAgB,GAAI,CAAC,QAC1B,CAAC,WACE,gBAAgB,KACxB,SAAS,GAAG,
|
|
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;AA8CjC;;;;;;;;GAQG;AAEH,eAAO,MAAM,gBAAgB,GAAI,CAAC,QAC1B,CAAC,WACE,gBAAgB,KACxB,SAAS,GAAG,MAmEd,CAAC;AAEF;;;;;;;;GAQG;AAEH,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
|
@@ -10,8 +10,8 @@ const utils_1 = require("@graphql-markdown/utils");
|
|
|
10
10
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
11
11
|
const common_1 = require("./common");
|
|
12
12
|
const badge_1 = require("./badge");
|
|
13
|
+
const decorator_1 = require("./decorator");
|
|
13
14
|
const link_1 = require("./link");
|
|
14
|
-
const directive_1 = require("./directive");
|
|
15
15
|
const strings_1 = require("./const/strings");
|
|
16
16
|
const options_1 = require("./const/options");
|
|
17
17
|
/**
|
|
@@ -50,11 +50,33 @@ const printSectionItem = (type, options) => {
|
|
|
50
50
|
...options,
|
|
51
51
|
withAttributes: false,
|
|
52
52
|
});
|
|
53
|
-
const badges =
|
|
54
|
-
|
|
53
|
+
const badges = [
|
|
54
|
+
(0, badge_1.printBadges)(type, options),
|
|
55
|
+
...(0, decorator_1.printSlotDecorators)("badges", type, options),
|
|
56
|
+
]
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join(" ");
|
|
59
|
+
// `customDirective`'s `tag` handlers reach this line via the decorators
|
|
60
|
+
// pipeline (`printSlotDecorators`), not a dedicated call — see
|
|
61
|
+
// `buildCustomDirectiveDecorators` in `./decorator`.
|
|
62
|
+
const tags = (0, decorator_1.printSlotDecorators)("tags", type, options)
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
.join(" ");
|
|
55
65
|
const parentTypeLink = (0, link_1.printParentLink)(type, options);
|
|
56
|
-
const permalink =
|
|
57
|
-
|
|
66
|
+
const permalink = [
|
|
67
|
+
printPermalink(link.id, options),
|
|
68
|
+
...(0, decorator_1.printSlotDecorators)("permalink", type, options),
|
|
69
|
+
]
|
|
70
|
+
.filter(Boolean)
|
|
71
|
+
.join(" ");
|
|
72
|
+
const metadata = [
|
|
73
|
+
badges,
|
|
74
|
+
tags,
|
|
75
|
+
permalink,
|
|
76
|
+
...(0, decorator_1.printSlotDecorators)("metadata", type, options),
|
|
77
|
+
]
|
|
78
|
+
.filter(Boolean)
|
|
79
|
+
.join(" ");
|
|
58
80
|
const title = `${options_1.SectionLevels.LEVEL.repeat(level)} ${typeNameLink}${parentTypeLink} ${metadata} ${strings_1.MARKDOWN_EOL}`;
|
|
59
81
|
const description = (0, common_1.printDescription)(type, options, "")
|
|
60
82
|
.trim()
|
package/package.json
CHANGED
package/dist/directive.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides utilities for handling and printing GraphQL directives in Markdown format
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
import type { Badge, PrintTypeOptions, MDXString, CustomDirectiveMapItem, CustomDirectiveResolver, Maybe, PageSection } from "@graphql-markdown/types";
|
|
6
|
-
/**
|
|
7
|
-
* Resolves a custom directive using the provided resolver function
|
|
8
|
-
* @param resolver - The resolver function name to execute
|
|
9
|
-
* @param type - The GraphQL type to resolve the directive for
|
|
10
|
-
* @param constDirectiveOption - The directive configuration options
|
|
11
|
-
* @param fallback - Optional fallback value if resolution fails
|
|
12
|
-
* @returns The resolved directive value or `fallback`/`undefined`
|
|
13
|
-
*/
|
|
14
|
-
export declare const getCustomDirectiveResolver: (resolver: CustomDirectiveResolver, type: unknown, constDirectiveOption: CustomDirectiveMapItem, fallback?: Maybe<string>) => Maybe<string>;
|
|
15
|
-
/**
|
|
16
|
-
* Prints a custom directive as a Markdown string
|
|
17
|
-
* @param type - The GraphQL type to print the directive for
|
|
18
|
-
* @param constDirectiveOption - The directive configuration options
|
|
19
|
-
* @param options - General printing options
|
|
20
|
-
* @returns Formatted Markdown string for the directive or `undefined`
|
|
21
|
-
*/
|
|
22
|
-
export declare const printCustomDirective: (type: unknown, constDirectiveOption: CustomDirectiveMapItem, options: PrintTypeOptions) => Maybe<string>;
|
|
23
|
-
/**
|
|
24
|
-
* Prints all custom directives for a type as a Markdown section
|
|
25
|
-
* @param type - The GraphQL type to print directives for
|
|
26
|
-
* @param options - General printing options
|
|
27
|
-
* @returns A "Directives" PageSection, or undefined when no directives are printable
|
|
28
|
-
*/
|
|
29
|
-
export declare const printCustomDirectives: (type: unknown, options: PrintTypeOptions) => Maybe<PageSection>;
|
|
30
|
-
/**
|
|
31
|
-
* Extracts custom tags from directives for a given type
|
|
32
|
-
* @param type - The GraphQL type to get tags for
|
|
33
|
-
* @param options - General printing options
|
|
34
|
-
* @returns Array of badge configurations from directive tags
|
|
35
|
-
*/
|
|
36
|
-
export declare const getCustomTags: (type: unknown, options: PrintTypeOptions) => Badge[];
|
|
37
|
-
/**
|
|
38
|
-
* Prints custom directive tags as Markdown badges
|
|
39
|
-
* @param type - The GraphQL type to print tags for
|
|
40
|
-
* @param options - General printing options
|
|
41
|
-
* @returns Formatted Markdown string of badges or empty string
|
|
42
|
-
*/
|
|
43
|
-
export declare const printCustomTags: (type: unknown, options: PrintTypeOptions) => MDXString | string;
|
|
44
|
-
//# sourceMappingURL=directive.d.ts.map
|
package/dist/directive.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"directive.d.ts","sourceRoot":"","sources":["../src/directive.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,KAAK,EACL,gBAAgB,EAChB,SAAS,EACT,sBAAsB,EACtB,uBAAuB,EACvB,KAAK,EACL,WAAW,EACZ,MAAM,yBAAyB,CAAC;AASjC;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,aAC3B,uBAAuB,QAC3B,OAAO,wBACS,sBAAsB,aACjC,KAAK,CAAC,MAAM,CAAC,KACvB,KAAK,CAAC,MAAM,CAYd,CAAC;AAEF;;;;;;GAMG;AAEH,eAAO,MAAM,oBAAoB,SACzB,OAAO,wBACS,sBAAsB,WACnC,gBAAgB,KACxB,KAAK,CAAC,MAAM,CAgBd,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,SAC1B,OAAO,WACJ,gBAAgB,KACxB,KAAK,CAAC,WAAW,CA6BnB,CAAC;AAEF;;;;;GAKG;AAEH,eAAO,MAAM,aAAa,SAClB,OAAO,WACJ,gBAAgB,KACxB,KAAK,EAqBP,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,SACpB,OAAO,WACJ,gBAAgB,KACxB,SAAS,GAAG,MAEd,CAAC"}
|
package/dist/directive.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Provides utilities for handling and printing GraphQL directives in Markdown format
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.printCustomTags = exports.getCustomTags = exports.printCustomDirectives = exports.printCustomDirective = exports.getCustomDirectiveResolver = void 0;
|
|
8
|
-
const graphql_1 = require("@graphql-markdown/graphql");
|
|
9
|
-
const strings_1 = require("./const/strings");
|
|
10
|
-
const options_1 = require("./const/options");
|
|
11
|
-
const link_1 = require("./link");
|
|
12
|
-
const badge_1 = require("./badge");
|
|
13
|
-
/**
|
|
14
|
-
* Resolves a custom directive using the provided resolver function
|
|
15
|
-
* @param resolver - The resolver function name to execute
|
|
16
|
-
* @param type - The GraphQL type to resolve the directive for
|
|
17
|
-
* @param constDirectiveOption - The directive configuration options
|
|
18
|
-
* @param fallback - Optional fallback value if resolution fails
|
|
19
|
-
* @returns The resolved directive value or `fallback`/`undefined`
|
|
20
|
-
*/
|
|
21
|
-
const getCustomDirectiveResolver = (resolver, type, constDirectiveOption, fallback) => {
|
|
22
|
-
if (typeof constDirectiveOption.type !== "object" ||
|
|
23
|
-
typeof constDirectiveOption[resolver] !== "function") {
|
|
24
|
-
return fallback;
|
|
25
|
-
}
|
|
26
|
-
return constDirectiveOption[resolver](constDirectiveOption.type, type);
|
|
27
|
-
};
|
|
28
|
-
exports.getCustomDirectiveResolver = getCustomDirectiveResolver;
|
|
29
|
-
/**
|
|
30
|
-
* Prints a custom directive as a Markdown string
|
|
31
|
-
* @param type - The GraphQL type to print the directive for
|
|
32
|
-
* @param constDirectiveOption - The directive configuration options
|
|
33
|
-
* @param options - General printing options
|
|
34
|
-
* @returns Formatted Markdown string for the directive or `undefined`
|
|
35
|
-
*/
|
|
36
|
-
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
37
|
-
const printCustomDirective = (type, constDirectiveOption, options) => {
|
|
38
|
-
const typeNameLink = (0, link_1.printLink)(constDirectiveOption.type, {
|
|
39
|
-
...options,
|
|
40
|
-
withAttributes: false,
|
|
41
|
-
});
|
|
42
|
-
const description = (0, exports.getCustomDirectiveResolver)("descriptor", type, constDirectiveOption);
|
|
43
|
-
if (typeof description !== "string") {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
return `${options_1.SectionLevels.LEVEL.repeat(4)} ${typeNameLink}${strings_1.MARKDOWN_EOL} ${description}${strings_1.MARKDOWN_EOL} `;
|
|
47
|
-
};
|
|
48
|
-
exports.printCustomDirective = printCustomDirective;
|
|
49
|
-
/**
|
|
50
|
-
* Prints all custom directives for a type as a Markdown section
|
|
51
|
-
* @param type - The GraphQL type to print directives for
|
|
52
|
-
* @param options - General printing options
|
|
53
|
-
* @returns A "Directives" PageSection, or undefined when no directives are printable
|
|
54
|
-
*/
|
|
55
|
-
const printCustomDirectives = (type, options) => {
|
|
56
|
-
const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options.customDirectives);
|
|
57
|
-
if (!constDirectiveMap || Object.keys(constDirectiveMap).length === 0) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
const directives = Object.values(constDirectiveMap)
|
|
61
|
-
.map((constDirectiveOption) => {
|
|
62
|
-
return (0, exports.printCustomDirective)(type, constDirectiveOption, options);
|
|
63
|
-
})
|
|
64
|
-
.filter((value) => {
|
|
65
|
-
return value !== undefined;
|
|
66
|
-
});
|
|
67
|
-
if (directives.length === 0) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
const content = directives.join(strings_1.MARKDOWN_EOP);
|
|
71
|
-
return {
|
|
72
|
-
title: "Directives",
|
|
73
|
-
content: `${content}${strings_1.MARKDOWN_EOP}`,
|
|
74
|
-
level: 3,
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
exports.printCustomDirectives = printCustomDirectives;
|
|
78
|
-
/**
|
|
79
|
-
* Extracts custom tags from directives for a given type
|
|
80
|
-
* @param type - The GraphQL type to get tags for
|
|
81
|
-
* @param options - General printing options
|
|
82
|
-
* @returns Array of badge configurations from directive tags
|
|
83
|
-
*/
|
|
84
|
-
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
85
|
-
const getCustomTags = (type, options) => {
|
|
86
|
-
const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options.customDirectives);
|
|
87
|
-
if (typeof constDirectiveMap !== "object" ||
|
|
88
|
-
constDirectiveMap === null ||
|
|
89
|
-
Object.keys(constDirectiveMap).length === 0) {
|
|
90
|
-
return [];
|
|
91
|
-
}
|
|
92
|
-
return Object.values(constDirectiveMap)
|
|
93
|
-
.map((constDirectiveOption) => {
|
|
94
|
-
return (0, exports.getCustomDirectiveResolver)("tag", type, constDirectiveOption);
|
|
95
|
-
})
|
|
96
|
-
.filter((value) => {
|
|
97
|
-
return value !== undefined;
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
exports.getCustomTags = getCustomTags;
|
|
101
|
-
/**
|
|
102
|
-
* Prints custom directive tags as Markdown badges
|
|
103
|
-
* @param type - The GraphQL type to print tags for
|
|
104
|
-
* @param options - General printing options
|
|
105
|
-
* @returns Formatted Markdown string of badges or empty string
|
|
106
|
-
*/
|
|
107
|
-
const printCustomTags = (type, options) => {
|
|
108
|
-
return (0, badge_1.formatBadges)((0, exports.getCustomTags)(type, options), options);
|
|
109
|
-
};
|
|
110
|
-
exports.printCustomTags = printCustomTags;
|