@graphql-markdown/printer-legacy 1.16.2 → 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/badge.d.ts.map +1 -1
- package/dist/badge.js +0 -1
- package/dist/common.d.ts +0 -8
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +10 -34
- package/dist/const/options.d.ts +3 -1
- package/dist/const/options.d.ts.map +1 -1
- package/dist/const/options.js +3 -3
- package/dist/decorator.d.ts +174 -0
- package/dist/decorator.d.ts.map +1 -0
- package/dist/decorator.js +494 -0
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +0 -1
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +1 -0
- package/dist/graphql/scalar.d.ts.map +1 -1
- package/dist/graphql/scalar.js +0 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +0 -6
- package/dist/printer.d.ts +26 -11
- package/dist/printer.d.ts.map +1 -1
- package/dist/printer.js +55 -28
- package/dist/relation.d.ts.map +1 -1
- package/dist/relation.js +0 -2
- package/dist/section.d.ts.map +1 -1
- package/dist/section.js +43 -9
- 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 -112
|
@@ -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/example.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAIV,KAAK,EACL,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAwBjC;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAIV,KAAK,EACL,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAwBjC;;;;;GAKG;AAEH,eAAO,MAAM,yBAAyB,gCAGnC,gBAAgB,KAAG,KAAK,CAAC,oBAAoB,CA6B/C,CAAC;AAiKF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,SACjB,OAAO,WACJ,gBAAgB,KACxB,KAAK,CAAC,MAAM,CAgBd,CAAC"}
|
package/dist/example.js
CHANGED
|
@@ -16,7 +16,6 @@ const link_1 = require("./link");
|
|
|
16
16
|
* @returns The directive example configuration if valid, otherwise `undefined`
|
|
17
17
|
*/
|
|
18
18
|
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
19
|
-
// fallow-ignore-next-line unused-export
|
|
20
19
|
const getDirectiveExampleOption = ({ exampleSection, schema, }) => {
|
|
21
20
|
let directiveName = "example", argName = "value", parserFunc = undefined;
|
|
22
21
|
if (exampleSection && typeof exampleSection === "object") {
|
package/dist/formatter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAczD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,QAAO,SAYzC,CAAC"}
|
package/dist/formatter.js
CHANGED
|
@@ -36,6 +36,7 @@ const createDefaultFormatter = () => {
|
|
|
36
36
|
formatMDXFrontmatter: defaults_1.formatMDXFrontmatter,
|
|
37
37
|
formatMDXLink: defaults_1.formatMDXLink,
|
|
38
38
|
formatMDXNameEntity: defaults_1.formatMDXNameEntity,
|
|
39
|
+
formatMDXPermalink: defaults_1.formatMDXPermalink,
|
|
39
40
|
formatMDXSpecifiedByLink: defaults_1.formatMDXSpecifiedByLink,
|
|
40
41
|
};
|
|
41
42
|
};
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAEH,eAAO,MAAM,kBAAkB,SACvB,OAAO,WACJ,gBAAgB,KACxB,KAAK,CAAC,WAAW,CAgBnB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,SACxB,OAAO,WACJ,gBAAgB,KACxB,KAAK,CAAC,WAAW,CAEnB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,SACpB,OAAO,YACH,gBAAgB,KACzB,MAEF,CAAC"}
|
package/dist/graphql/scalar.js
CHANGED
|
@@ -9,7 +9,6 @@ const graphql_1 = require("@graphql-markdown/graphql");
|
|
|
9
9
|
* @returns A specification PageSection, or undefined when no URL exists
|
|
10
10
|
*/
|
|
11
11
|
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
12
|
-
// fallow-ignore-next-line unused-export
|
|
13
12
|
const printSpecification = (type, options) => {
|
|
14
13
|
if (typeof type !== "object" ||
|
|
15
14
|
type === null ||
|
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/link.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAKhB,QAAQ,EACR,UAAU,EACX,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../src/link.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAKhB,QAAQ,EACR,UAAU,EACX,MAAM,yBAAyB,CAAC;AAiCjC,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,oBAAoB,CAG5C,CAAC;AAEX;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,SAC1B,OAAO,YACH,IAAI,CACZ,gBAAgB,EAChB,YAAY,GAAG,mBAAmB,GAAG,mBAAmB,CACzD,KACA,OAyBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,SAAU,OAAO,KAAG,KAAK,CAAC,UAAU,CAoBjE,CAAC;AAEF;;;;;;GAMG;AAEH,eAAO,MAAM,qBAAqB,SAC1B,OAAO,oBACK,KAAK,CAAC,UAAU,CAAC,KAClC,KAAK,CAAC,MAAM,CAoBd,CAAC;AAEF;;;;;GAKG;AAEH,eAAO,MAAM,uBAAuB,YAAa,gBAAgB,KAAG,OAEnE,CAAC;AAEF;;;;;GAKG;AAEH,eAAO,MAAM,mBAAmB,YAAa,gBAAgB,KAAG,OAO/D,CAAC;AAEF;;;;;;GAMG;AAEH,eAAO,MAAM,qBAAqB,SAC1B,OAAO,WACJ,KAAK,CAAC,oBAAoB,GAAG,OAAO,CAAC,KAC7C,MAMF,CAAC;AAuBF;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,SACX,OAAO,QACP,MAAM,aACD,KAAK,CAAC,UAAU,CAAC,WACnB,gBAAgB,KACxB,QAkFF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,aAChB,KAAK,CAAC,UAAU,CAAC,QACrB,OAAO,WACJ,gBAAgB,KACxB,KAAK,CAAC,QAAQ,CAUhB,CAAC;AAEF;;;;;;GAMG;AAEH,eAAO,MAAM,mBAAmB,SACxB,OAAO,SACP,KAAK,CAAC,MAAM,CAAC,KAClB,MAkBF,CAAC;AAoBF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,OACpB,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,WACf,gBAAgB,KACxB,MAgCF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,SACpB,OAAO,WACJ,gBAAgB,KACxB,SAAS,GAAG,MAWd,CAAC"}
|
package/dist/link.js
CHANGED
|
@@ -12,7 +12,6 @@ const group_1 = require("./group");
|
|
|
12
12
|
const strings_1 = require("./const/strings");
|
|
13
13
|
const options_1 = require("./const/options");
|
|
14
14
|
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
15
|
-
// fallow-ignore-next-line unused-export
|
|
16
15
|
exports.API_GROUPS = {
|
|
17
16
|
operations: "operations",
|
|
18
17
|
types: "types",
|
|
@@ -79,7 +78,6 @@ exports.getCategoryLocale = getCategoryLocale;
|
|
|
79
78
|
* @returns The folder name for the link category, or `undefined` if not found
|
|
80
79
|
*/
|
|
81
80
|
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
82
|
-
// fallow-ignore-next-line unused-export
|
|
83
81
|
const getLinkCategoryFolder = (type, operationLocale) => {
|
|
84
82
|
const categoryLocale = (0, exports.getCategoryLocale)(type);
|
|
85
83
|
if (!categoryLocale) {
|
|
@@ -106,7 +104,6 @@ exports.getLinkCategoryFolder = getLinkCategoryFolder;
|
|
|
106
104
|
* @returns `true` if the options include `withAttributes`, `false` otherwise
|
|
107
105
|
*/
|
|
108
106
|
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
109
|
-
// fallow-ignore-next-line unused-export
|
|
110
107
|
const hasOptionWithAttributes = (options) => {
|
|
111
108
|
return "withAttributes" in options && options.withAttributes === true;
|
|
112
109
|
};
|
|
@@ -118,7 +115,6 @@ exports.hasOptionWithAttributes = hasOptionWithAttributes;
|
|
|
118
115
|
* @returns `true` if the options include `parentTypePrefix`, `false` otherwise
|
|
119
116
|
*/
|
|
120
117
|
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
121
|
-
// fallow-ignore-next-line unused-export
|
|
122
118
|
const hasOptionParentType = (options) => {
|
|
123
119
|
return ("parentTypePrefix" in options &&
|
|
124
120
|
options.parentTypePrefix === true &&
|
|
@@ -134,7 +130,6 @@ exports.hasOptionParentType = hasOptionParentType;
|
|
|
134
130
|
* @returns The folder name for the API group
|
|
135
131
|
*/
|
|
136
132
|
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
137
|
-
// fallow-ignore-next-line unused-export
|
|
138
133
|
const getLinkApiGroupFolder = (type, groups) => {
|
|
139
134
|
let folderNames = exports.API_GROUPS;
|
|
140
135
|
if (groups && typeof groups === "object") {
|
|
@@ -251,7 +246,6 @@ exports.getRelationLink = getRelationLink;
|
|
|
251
246
|
* @returns The text with appended attributes
|
|
252
247
|
*/
|
|
253
248
|
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
254
|
-
// fallow-ignore-next-line unused-export
|
|
255
249
|
const printLinkAttributes = (type, text = "") => {
|
|
256
250
|
if (typeof type !== "object" || type === null) {
|
|
257
251
|
return text ?? "";
|