@graphql-markdown/core 1.26.1 → 1.28.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 +3 -3
- package/dist/config.d.ts +22 -34
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +122 -70
- package/dist/generator.d.ts +3 -3
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +25 -33
- package/dist/optional-dependencies.js +1 -1
- package/dist/renderer.d.ts +7 -39
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +65 -193
- package/dist/rendererHelpers.d.ts +134 -0
- package/dist/rendererHelpers.d.ts.map +1 -0
- package/dist/rendererHelpers.js +153 -0
- package/dist/version.js +1 -1
- package/package.json +9 -9
package/dist/renderer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRenderer = exports.Renderer = exports.logHandlerErrors = exports.getApiGroupFolder = exports.API_GROUPS = void 0;
|
|
3
|
+
exports.getRenderer = exports.Renderer = exports.logHandlerErrors = exports.isHierarchy = exports.stripNumericPrefix = exports.getApiGroupFolder = exports.API_GROUPS = exports.SidebarPosition = exports.CATEGORY_STYLE_CLASS = exports.DEPRECATED = void 0;
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
6
6
|
const utils_1 = require("@graphql-markdown/utils");
|
|
@@ -10,154 +10,17 @@ const homepage_ts_1 = require("./const/homepage.js");
|
|
|
10
10
|
const validation_ts_1 = require("./directives/validation.js");
|
|
11
11
|
const event_emitter_ts_1 = require("./event-emitter.js");
|
|
12
12
|
const index_ts_1 = require("./events/index.js");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
const DEPRECATED = "deprecated";
|
|
27
|
-
/**
|
|
28
|
-
* CSS class names used for styling different categories in the generated documentation.
|
|
29
|
-
* These are applied to the generated index metafiles for different section types.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* // When generating API section metafiles
|
|
34
|
-
* await generateIndexMetafile(dirPath, typeCat, {
|
|
35
|
-
* styleClass: CATEGORY_STYLE_CLASS.API
|
|
36
|
-
* });
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
var CATEGORY_STYLE_CLASS;
|
|
40
|
-
(function (CATEGORY_STYLE_CLASS) {
|
|
41
|
-
/**
|
|
42
|
-
* CSS class applied to API sections (operations)
|
|
43
|
-
*/
|
|
44
|
-
CATEGORY_STYLE_CLASS["API"] = "graphql-markdown-api-section";
|
|
45
|
-
/**
|
|
46
|
-
* CSS class applied to deprecated entity sections
|
|
47
|
-
*/
|
|
48
|
-
CATEGORY_STYLE_CLASS["DEPRECATED"] = "graphql-markdown-deprecated-section";
|
|
49
|
-
})(CATEGORY_STYLE_CLASS || (CATEGORY_STYLE_CLASS = {}));
|
|
50
|
-
/**
|
|
51
|
-
* Enum defining sidebar position values for ordering categories in the documentation sidebar.
|
|
52
|
-
* Used to control the relative position of categories in the navigation.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* // Position deprecated entities at the end of the sidebar
|
|
57
|
-
* await generateIndexMetafile(dirPath, DEPRECATED, {
|
|
58
|
-
* sidebarPosition: SidebarPosition.LAST
|
|
59
|
-
* });
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
var SidebarPosition;
|
|
63
|
-
(function (SidebarPosition) {
|
|
64
|
-
/**
|
|
65
|
-
* Position at the beginning of the sidebar
|
|
66
|
-
*/
|
|
67
|
-
SidebarPosition[SidebarPosition["FIRST"] = 1] = "FIRST";
|
|
68
|
-
/**
|
|
69
|
-
* Position at the end of the sidebar
|
|
70
|
-
*/
|
|
71
|
-
SidebarPosition[SidebarPosition["LAST"] = 999] = "LAST";
|
|
72
|
-
})(SidebarPosition || (SidebarPosition = {}));
|
|
73
|
-
/**
|
|
74
|
-
* Default group names for API types and non-API types.
|
|
75
|
-
* This constant provides the base folder structure for organizing GraphQL schema entities.
|
|
76
|
-
* Can be overridden via ApiGroupOverrideType in configuration.
|
|
77
|
-
*
|
|
78
|
-
* @property operations Folder name for GraphQL operations (queries, mutations, subscriptions)
|
|
79
|
-
* @property types Folder name for GraphQL type definitions
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* // Default structure
|
|
84
|
-
* const defaultGroups = API_GROUPS;
|
|
85
|
-
* // { operations: "operations", types: "types" }
|
|
86
|
-
*
|
|
87
|
-
* // With custom override
|
|
88
|
-
* const customGroups = { ...API_GROUPS, operations: "queries-and-mutations" };
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* @see {@link getApiGroupFolder} For usage with type categorization
|
|
92
|
-
*/
|
|
93
|
-
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
94
|
-
exports.API_GROUPS = {
|
|
95
|
-
operations: "operations",
|
|
96
|
-
types: "types",
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Determines the appropriate folder for a GraphQL schema entity based on its type.
|
|
100
|
-
*
|
|
101
|
-
* @param type - The GraphQL schema entity to categorize
|
|
102
|
-
* @param groups - Optional custom group naming configuration
|
|
103
|
-
* @returns The folder name where the entity should be placed
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* // With default groups
|
|
108
|
-
* const folder = getApiGroupFolder(queryType); // Returns "operations"
|
|
109
|
-
*
|
|
110
|
-
* // With custom groups
|
|
111
|
-
* const folder = getApiGroupFolder(objectType, { operations: "queries" }); // Returns appropriate folder
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
// Used only by unit tests for direct whitebox coverage; not part of the production public API.
|
|
115
|
-
const getApiGroupFolder = (type, groups) => {
|
|
116
|
-
let folderNames = exports.API_GROUPS;
|
|
117
|
-
if ((0, validation_ts_1.isGroupsObject)(groups)) {
|
|
118
|
-
folderNames = { ...exports.API_GROUPS, ...groups };
|
|
119
|
-
}
|
|
120
|
-
return (0, graphql_1.isApiType)(type) ? folderNames.operations : folderNames.types;
|
|
121
|
-
};
|
|
122
|
-
exports.getApiGroupFolder = getApiGroupFolder;
|
|
123
|
-
/**
|
|
124
|
-
* Strips numeric prefix from a folder name if categorySort is enabled.
|
|
125
|
-
* Converts folder names like "01-query" back to "query" for category identification.
|
|
126
|
-
*
|
|
127
|
-
* This is needed when extracting category names from file paths that were created
|
|
128
|
-
* with categorySort enabled. The regex matches leading two-digit numbers
|
|
129
|
-
* followed by a hyphen.
|
|
130
|
-
*
|
|
131
|
-
* @param folderName - The folder name to strip (e.g., "01-query", "02-mutations")
|
|
132
|
-
* @returns The folder name without prefix (e.g., "query", "mutations")
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```typescript
|
|
136
|
-
* stripNumericPrefix("01-query"); // Returns "query"
|
|
137
|
-
* stripNumericPrefix("02-mutations"); // Returns "mutations"
|
|
138
|
-
* stripNumericPrefix("objects"); // Returns "objects" (no prefix to strip)
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
const stripNumericPrefix = (folderName) => {
|
|
142
|
-
return folderName.replace(/^\d{2}-/, "");
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Type guard function that checks if the provided options include a specific hierarchy configuration.
|
|
146
|
-
*
|
|
147
|
-
* @param options - The renderer options to check
|
|
148
|
-
* @param hierarchy - The hierarchy type to check for
|
|
149
|
-
* @returns True if the options contain the specified hierarchy configuration
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```typescript
|
|
153
|
-
* if (isHierarchy(options, TypeHierarchy.FLAT)) {
|
|
154
|
-
* // Handle flat hierarchy structure
|
|
155
|
-
* }
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
const isHierarchy = (options, hierarchy) => {
|
|
159
|
-
return options?.hierarchy?.[hierarchy] !== undefined;
|
|
160
|
-
};
|
|
13
|
+
// Re-exported only for unit tests (direct whitebox coverage); not part of the
|
|
14
|
+
// production public API.
|
|
15
|
+
var rendererHelpers_ts_1 = require("./rendererHelpers.js");
|
|
16
|
+
Object.defineProperty(exports, "DEPRECATED", { enumerable: true, get: function () { return rendererHelpers_ts_1.DEPRECATED; } });
|
|
17
|
+
Object.defineProperty(exports, "CATEGORY_STYLE_CLASS", { enumerable: true, get: function () { return rendererHelpers_ts_1.CATEGORY_STYLE_CLASS; } });
|
|
18
|
+
Object.defineProperty(exports, "SidebarPosition", { enumerable: true, get: function () { return rendererHelpers_ts_1.SidebarPosition; } });
|
|
19
|
+
Object.defineProperty(exports, "API_GROUPS", { enumerable: true, get: function () { return rendererHelpers_ts_1.API_GROUPS; } });
|
|
20
|
+
Object.defineProperty(exports, "getApiGroupFolder", { enumerable: true, get: function () { return rendererHelpers_ts_1.getApiGroupFolder; } });
|
|
21
|
+
Object.defineProperty(exports, "stripNumericPrefix", { enumerable: true, get: function () { return rendererHelpers_ts_1.stripNumericPrefix; } });
|
|
22
|
+
Object.defineProperty(exports, "isHierarchy", { enumerable: true, get: function () { return rendererHelpers_ts_1.isHierarchy; } });
|
|
23
|
+
const rendererHelpers_ts_2 = require("./rendererHelpers.js");
|
|
161
24
|
/**
|
|
162
25
|
* Default natural sorting function for categories.
|
|
163
26
|
* Sorts categories alphabetically using localeCompare.
|
|
@@ -373,16 +236,16 @@ class Renderer {
|
|
|
373
236
|
if (!(0, validation_ts_1.isPath)(dirPath)) {
|
|
374
237
|
throw new Error("Output directory is empty or not specified");
|
|
375
238
|
}
|
|
376
|
-
if (isHierarchy(this.options, config_ts_1.TypeHierarchy.FLAT)) {
|
|
239
|
+
if ((0, rendererHelpers_ts_2.isHierarchy)(this.options, config_ts_1.TypeHierarchy.FLAT)) {
|
|
377
240
|
return dirPath;
|
|
378
241
|
}
|
|
379
242
|
// Deprecated gets highest priority - at ROOT level before even custom groups
|
|
380
243
|
if (this.options?.deprecated === "group" && (0, graphql_1.isDeprecated)(type)) {
|
|
381
|
-
const formattedDeprecated = this.formatCategoryFolderName(DEPRECATED, true);
|
|
244
|
+
const formattedDeprecated = this.formatCategoryFolderName(rendererHelpers_ts_2.DEPRECATED, true);
|
|
382
245
|
dirPath = (0, node_path_1.join)(dirPath, formattedDeprecated);
|
|
383
|
-
await this.generateIndexMetafile(dirPath, DEPRECATED, {
|
|
384
|
-
sidebarPosition: SidebarPosition.LAST,
|
|
385
|
-
styleClass: CATEGORY_STYLE_CLASS.DEPRECATED,
|
|
246
|
+
await this.generateIndexMetafile(dirPath, rendererHelpers_ts_2.DEPRECATED, {
|
|
247
|
+
sidebarPosition: rendererHelpers_ts_2.SidebarPosition.LAST,
|
|
248
|
+
styleClass: rendererHelpers_ts_2.CATEGORY_STYLE_CLASS.DEPRECATED,
|
|
386
249
|
});
|
|
387
250
|
}
|
|
388
251
|
// Custom groups come after deprecated but before hierarchy levels
|
|
@@ -395,11 +258,11 @@ class Renderer {
|
|
|
395
258
|
dirPath = (0, node_path_1.join)(dirPath, formattedRootGroup);
|
|
396
259
|
await this.generateIndexMetafile(dirPath, rootGroup);
|
|
397
260
|
}
|
|
398
|
-
const useApiGroup = isHierarchy(this.options, config_ts_1.TypeHierarchy.API)
|
|
261
|
+
const useApiGroup = (0, rendererHelpers_ts_2.isHierarchy)(this.options, config_ts_1.TypeHierarchy.API)
|
|
399
262
|
? this.options.hierarchy[config_ts_1.TypeHierarchy.API]
|
|
400
|
-
: !isHierarchy(this.options, config_ts_1.TypeHierarchy.ENTITY);
|
|
263
|
+
: !(0, rendererHelpers_ts_2.isHierarchy)(this.options, config_ts_1.TypeHierarchy.ENTITY);
|
|
401
264
|
if (useApiGroup) {
|
|
402
|
-
const typeCat = (0,
|
|
265
|
+
const typeCat = (0, rendererHelpers_ts_2.getApiGroupFolder)(type, useApiGroup);
|
|
403
266
|
// API groups are root-level if no custom groups exist, nested if custom groups exist
|
|
404
267
|
const isApiGroupRootLevel = !this.group;
|
|
405
268
|
const formattedTypeCat = this.formatCategoryFolderName(typeCat, isApiGroupRootLevel);
|
|
@@ -407,7 +270,7 @@ class Renderer {
|
|
|
407
270
|
await this.generateIndexMetafile(dirPath, typeCat, {
|
|
408
271
|
collapsible: false,
|
|
409
272
|
collapsed: false,
|
|
410
|
-
styleClass: CATEGORY_STYLE_CLASS.API,
|
|
273
|
+
styleClass: rendererHelpers_ts_2.CATEGORY_STYLE_CLASS.API,
|
|
411
274
|
});
|
|
412
275
|
}
|
|
413
276
|
// Entity categories are:
|
|
@@ -432,34 +295,12 @@ class Renderer {
|
|
|
432
295
|
if (typeof type !== "object" || type === null) {
|
|
433
296
|
return undefined;
|
|
434
297
|
}
|
|
435
|
-
const isFlat = isHierarchy(this.options, config_ts_1.TypeHierarchy.FLAT);
|
|
298
|
+
const isFlat = (0, rendererHelpers_ts_2.isHierarchy)(this.options, config_ts_1.TypeHierarchy.FLAT);
|
|
436
299
|
const isOperationRootType = rootTypeName === "queries" ||
|
|
437
300
|
rootTypeName === "mutations" ||
|
|
438
301
|
rootTypeName === "subscriptions";
|
|
439
302
|
return Promise.all(Object.keys(type).map(async (name) => {
|
|
440
|
-
|
|
441
|
-
let entityName = name;
|
|
442
|
-
let operationNamespaceParts;
|
|
443
|
-
if (isOperationRootType && name.includes(".")) {
|
|
444
|
-
const namespaceParts = name.split(".").filter(Boolean);
|
|
445
|
-
if (namespaceParts.length > 1) {
|
|
446
|
-
operationNamespaceParts = namespaceParts.slice(0, -1);
|
|
447
|
-
if (!isFlat) {
|
|
448
|
-
entityName = namespaceParts.at(-1) ?? entityName;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
if (!isFlat) {
|
|
453
|
-
dirPath = await this.generateCategoryMetafileType(type[name], name, rootTypeName);
|
|
454
|
-
if (operationNamespaceParts && operationNamespaceParts.length > 0) {
|
|
455
|
-
for (const namespace of operationNamespaceParts) {
|
|
456
|
-
const formattedNamespace = (0, utils_1.slugify)(namespace);
|
|
457
|
-
dirPath = (0, node_path_1.join)(dirPath, formattedNamespace);
|
|
458
|
-
await this.generateIndexMetafile(dirPath, namespace);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
return this.renderTypeEntities(dirPath, entityName, type[name], operationNamespaceParts, rootTypeName);
|
|
303
|
+
return this.renderRootTypeItem(name, type, isFlat, isOperationRootType, rootTypeName);
|
|
463
304
|
}));
|
|
464
305
|
}
|
|
465
306
|
/**
|
|
@@ -483,7 +324,7 @@ class Renderer {
|
|
|
483
324
|
// NOSONAR - pattern is safe, hyphen in character class doesn't cause backtracking
|
|
484
325
|
const PageRegex = /(?<category>[a-z0-9-]+)[\\/]+(?<pageId>[a-z0-9-]+)\.mdx?$/i; // NOSONAR
|
|
485
326
|
const PageRegexFlat = /(?<pageId>[a-z0-9-]+)\.mdx?$/i; // NOSONAR
|
|
486
|
-
const isFlat = isHierarchy(this.options, config_ts_1.TypeHierarchy.FLAT);
|
|
327
|
+
const isFlat = (0, rendererHelpers_ts_2.isHierarchy)(this.options, config_ts_1.TypeHierarchy.FLAT);
|
|
487
328
|
// Flat hierarchy has no folders to keep same-named entities of different
|
|
488
329
|
// kinds apart (a `type User` and a `Query.user` field both slugify to
|
|
489
330
|
// "user") — prefixing with `entity` (the `SchemaEntity` root type this
|
|
@@ -546,7 +387,7 @@ class Renderer {
|
|
|
546
387
|
// Strip numeric prefix from category if it was applied when categorySort is enabled
|
|
547
388
|
const extractedCategory = isFlat
|
|
548
389
|
? page.groups.pageId
|
|
549
|
-
: stripNumericPrefix(page.groups.category);
|
|
390
|
+
: (0, rendererHelpers_ts_2.stripNumericPrefix)(page.groups.category);
|
|
550
391
|
const category = isFlat ? "schema" : (0, utils_1.startCase)(extractedCategory);
|
|
551
392
|
const events = (0, event_emitter_ts_1.getEvents)();
|
|
552
393
|
const event = new index_ts_1.RenderTypeEntitiesEvent({
|
|
@@ -572,7 +413,7 @@ class Renderer {
|
|
|
572
413
|
* @param rootTypes - Map of schema entity names to their generated types
|
|
573
414
|
*/
|
|
574
415
|
preCollectGeneratedDocPaths(rootTypes) {
|
|
575
|
-
if (!isHierarchy(this.options, config_ts_1.TypeHierarchy.FLAT)) {
|
|
416
|
+
if (!(0, rendererHelpers_ts_2.isHierarchy)(this.options, config_ts_1.TypeHierarchy.FLAT)) {
|
|
576
417
|
return;
|
|
577
418
|
}
|
|
578
419
|
for (const [entity, type] of Object.entries(rootTypes)) {
|
|
@@ -606,13 +447,13 @@ class Renderer {
|
|
|
606
447
|
const rootCategories = new Set();
|
|
607
448
|
const nestedCategories = new Set();
|
|
608
449
|
// Skip if flat hierarchy
|
|
609
|
-
if (isHierarchy(this.options, config_ts_1.TypeHierarchy.FLAT)) {
|
|
450
|
+
if ((0, rendererHelpers_ts_2.isHierarchy)(this.options, config_ts_1.TypeHierarchy.FLAT)) {
|
|
610
451
|
return;
|
|
611
452
|
}
|
|
612
453
|
// Determine if using API hierarchy
|
|
613
|
-
const useApiGroup = isHierarchy(this.options, config_ts_1.TypeHierarchy.API)
|
|
454
|
+
const useApiGroup = (0, rendererHelpers_ts_2.isHierarchy)(this.options, config_ts_1.TypeHierarchy.API)
|
|
614
455
|
? this.options.hierarchy[config_ts_1.TypeHierarchy.API]
|
|
615
|
-
: !isHierarchy(this.options, config_ts_1.TypeHierarchy.ENTITY);
|
|
456
|
+
: !(0, rendererHelpers_ts_2.isHierarchy)(this.options, config_ts_1.TypeHierarchy.ENTITY);
|
|
616
457
|
// Register custom groups at root level
|
|
617
458
|
this.registerCustomGroups(rootCategories);
|
|
618
459
|
// Register categories based on hierarchy type
|
|
@@ -624,7 +465,7 @@ class Renderer {
|
|
|
624
465
|
}
|
|
625
466
|
// Deprecated category - when grouped, it goes to root level
|
|
626
467
|
if (this.options?.deprecated === "group") {
|
|
627
|
-
rootCategories.add(DEPRECATED);
|
|
468
|
+
rootCategories.add(rendererHelpers_ts_2.DEPRECATED);
|
|
628
469
|
}
|
|
629
470
|
// Register collected categories with position managers
|
|
630
471
|
this.registerCategoriesWithManagers(rootCategories, nestedCategories);
|
|
@@ -671,6 +512,37 @@ class Renderer {
|
|
|
671
512
|
(0, logger_1.log)(`An error occurred while processing the homepage ${String(homepageLocation)}: ${error}`, logger_1.LogLevel.warn);
|
|
672
513
|
}
|
|
673
514
|
}
|
|
515
|
+
/**
|
|
516
|
+
* Handles rendering of a single root type entry.
|
|
517
|
+
* Extracted from `renderRootTypes` for clarity.
|
|
518
|
+
*/
|
|
519
|
+
async renderRootTypeItem(name, type, isFlat, isOperationRootType, rootTypeName) {
|
|
520
|
+
let dirPath = this.outputDir;
|
|
521
|
+
let entityName = name;
|
|
522
|
+
let operationNamespaceParts;
|
|
523
|
+
const SEPARATOR = ".";
|
|
524
|
+
if (isOperationRootType && name.includes(SEPARATOR)) {
|
|
525
|
+
const namespaceParts = name.split(SEPARATOR).filter(Boolean);
|
|
526
|
+
if (namespaceParts.length > 1) {
|
|
527
|
+
operationNamespaceParts = namespaceParts.slice(0, -1);
|
|
528
|
+
if (!isFlat) {
|
|
529
|
+
entityName = namespaceParts.at(-1) ?? entityName;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (!isFlat) {
|
|
534
|
+
dirPath = await this.generateCategoryMetafileType(type[name], name, rootTypeName);
|
|
535
|
+
if (operationNamespaceParts && operationNamespaceParts.length > 0) {
|
|
536
|
+
// Sequential on purpose: write each parent namespace index before its
|
|
537
|
+
// child, so output adapters and event handlers see folders in order.
|
|
538
|
+
for (const namespace of operationNamespaceParts) {
|
|
539
|
+
dirPath = (0, node_path_1.join)(dirPath, (0, utils_1.slugify)(namespace));
|
|
540
|
+
await this.generateIndexMetafile(dirPath, namespace); // NOSONAR: S9382
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return this.renderTypeEntities(dirPath, entityName, type[name], operationNamespaceParts, rootTypeName);
|
|
545
|
+
}
|
|
674
546
|
/**
|
|
675
547
|
* Registers custom group names from the current group configuration.
|
|
676
548
|
* Custom groups are always registered at the ROOT level.
|
|
@@ -700,13 +572,13 @@ class Renderer {
|
|
|
700
572
|
registerApiGroupCategories(rootCategories, nestedCategories, hasCustomGroups) {
|
|
701
573
|
if (hasCustomGroups) {
|
|
702
574
|
// Custom groups exist: operations/types are nested
|
|
703
|
-
nestedCategories.add(
|
|
704
|
-
nestedCategories.add(
|
|
575
|
+
nestedCategories.add(rendererHelpers_ts_2.API_GROUPS.operations);
|
|
576
|
+
nestedCategories.add(rendererHelpers_ts_2.API_GROUPS.types);
|
|
705
577
|
}
|
|
706
578
|
else {
|
|
707
579
|
// No custom groups: operations/types are at ROOT level
|
|
708
|
-
rootCategories.add(
|
|
709
|
-
rootCategories.add(
|
|
580
|
+
rootCategories.add(rendererHelpers_ts_2.API_GROUPS.operations);
|
|
581
|
+
rootCategories.add(rendererHelpers_ts_2.API_GROUPS.types);
|
|
710
582
|
}
|
|
711
583
|
// Entity categories for API group - plural forms from ROOT_TYPE_LOCALE
|
|
712
584
|
const entityCategoryNames = [
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { ApiGroupOverrideType, Maybe, RendererDocOptions, TypeHierarchyObjectType, TypeHierarchyValueType } from "@graphql-markdown/types";
|
|
2
|
+
/**
|
|
3
|
+
* Constant representing the string literal for deprecated entities.
|
|
4
|
+
* Used for grouping deprecated schema entities when the deprecated option is set to "group".
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // When using the deprecated grouping option
|
|
9
|
+
* if (isDeprecated(type)) {
|
|
10
|
+
* const groupName = DEPRECATED;
|
|
11
|
+
* // Handle deprecated type
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEPRECATED: "deprecated";
|
|
16
|
+
/**
|
|
17
|
+
* CSS class names used for styling different categories in the generated documentation.
|
|
18
|
+
* These are applied to the generated index metafiles for different section types.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // When generating API section metafiles
|
|
23
|
+
* await generateIndexMetafile(dirPath, typeCat, {
|
|
24
|
+
* styleClass: CATEGORY_STYLE_CLASS.API
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare enum CATEGORY_STYLE_CLASS {
|
|
29
|
+
/**
|
|
30
|
+
* CSS class applied to API sections (operations)
|
|
31
|
+
*/
|
|
32
|
+
API = "graphql-markdown-api-section",
|
|
33
|
+
/**
|
|
34
|
+
* CSS class applied to deprecated entity sections
|
|
35
|
+
*/
|
|
36
|
+
DEPRECATED = "graphql-markdown-deprecated-section"
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Enum defining sidebar position values for ordering categories in the documentation sidebar.
|
|
40
|
+
* Used to control the relative position of categories in the navigation.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Position deprecated entities at the end of the sidebar
|
|
45
|
+
* await generateIndexMetafile(dirPath, DEPRECATED, {
|
|
46
|
+
* sidebarPosition: SidebarPosition.LAST
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare enum SidebarPosition {
|
|
51
|
+
/**
|
|
52
|
+
* Position at the beginning of the sidebar
|
|
53
|
+
*/
|
|
54
|
+
FIRST = 1,
|
|
55
|
+
/**
|
|
56
|
+
* Position at the end of the sidebar
|
|
57
|
+
*/
|
|
58
|
+
LAST = 999
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Default group names for API types and non-API types.
|
|
62
|
+
* This constant provides the base folder structure for organizing GraphQL schema entities.
|
|
63
|
+
* Can be overridden via ApiGroupOverrideType in configuration.
|
|
64
|
+
*
|
|
65
|
+
* @property operations Folder name for GraphQL operations (queries, mutations, subscriptions)
|
|
66
|
+
* @property types Folder name for GraphQL type definitions
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Default structure
|
|
71
|
+
* const defaultGroups = API_GROUPS;
|
|
72
|
+
* // { operations: "operations", types: "types" }
|
|
73
|
+
*
|
|
74
|
+
* // With custom override
|
|
75
|
+
* const customGroups = { ...API_GROUPS, operations: "queries-and-mutations" };
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @see {@link getApiGroupFolder} For usage with type categorization
|
|
79
|
+
*/
|
|
80
|
+
export declare const API_GROUPS: Required<ApiGroupOverrideType>;
|
|
81
|
+
/**
|
|
82
|
+
* Determines the appropriate folder for a GraphQL schema entity based on its type.
|
|
83
|
+
*
|
|
84
|
+
* @param type - The GraphQL schema entity to categorize
|
|
85
|
+
* @param groups - Optional custom group naming configuration
|
|
86
|
+
* @returns The folder name where the entity should be placed
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* // With default groups
|
|
91
|
+
* const folder = getApiGroupFolder(queryType); // Returns "operations"
|
|
92
|
+
*
|
|
93
|
+
* // With custom groups
|
|
94
|
+
* const folder = getApiGroupFolder(objectType, { operations: "queries" }); // Returns appropriate folder
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare const getApiGroupFolder: (type: unknown, groups?: Maybe<ApiGroupOverrideType | boolean>) => string;
|
|
98
|
+
/**
|
|
99
|
+
* Strips numeric prefix from a folder name if categorySort is enabled.
|
|
100
|
+
* Converts folder names like "01-query" back to "query" for category identification.
|
|
101
|
+
*
|
|
102
|
+
* This is needed when extracting category names from file paths that were created
|
|
103
|
+
* with categorySort enabled. The regex matches leading two-digit numbers
|
|
104
|
+
* followed by a hyphen.
|
|
105
|
+
*
|
|
106
|
+
* @param folderName - The folder name to strip (e.g., "01-query", "02-mutations")
|
|
107
|
+
* @returns The folder name without prefix (e.g., "query", "mutations")
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* stripNumericPrefix("01-query"); // Returns "query"
|
|
112
|
+
* stripNumericPrefix("02-mutations"); // Returns "mutations"
|
|
113
|
+
* stripNumericPrefix("objects"); // Returns "objects" (no prefix to strip)
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare const stripNumericPrefix: (folderName: string) => string;
|
|
117
|
+
/**
|
|
118
|
+
* Type guard function that checks if the provided options include a specific hierarchy configuration.
|
|
119
|
+
*
|
|
120
|
+
* @param options - The renderer options to check
|
|
121
|
+
* @param hierarchy - The hierarchy type to check for
|
|
122
|
+
* @returns True if the options contain the specified hierarchy configuration
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* if (isHierarchy(options, TypeHierarchy.FLAT)) {
|
|
127
|
+
* // Handle flat hierarchy structure
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare const isHierarchy: (options: Maybe<RendererDocOptions>, hierarchy: TypeHierarchyValueType) => options is RendererDocOptions & {
|
|
132
|
+
hierarchy: TypeHierarchyObjectType;
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=rendererHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rendererHelpers.d.ts","sourceRoot":"","sources":["../src/rendererHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,KAAK,EACL,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,yBAAyB,CAAC;AAIjC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,EAAG,YAAqB,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,oBAAY,oBAAoB;IAC9B;;OAEG;IACH,GAAG,iCAAiC;IAEpC;;OAEG;IACH,UAAU,wCAAwC;CACnD;AAED;;;;;;;;;;;GAWG;AACH,oBAAY,eAAe;IACzB;;OAEG;IACH,KAAK,IAAI;IAET;;OAEG;IACH,IAAI,MAAM;CACX;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,oBAAoB,CAG5C,CAAC;AAEX;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,SACtB,OAAO,WACJ,KAAK,CAAC,oBAAoB,GAAG,OAAO,CAAC,KAC7C,MAMF,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,kBAAkB,eAAgB,MAAM,KAAG,MAEvD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,YACb,KAAK,CAAC,kBAAkB,CAAC,aACvB,sBAAsB,KAChC,OAAO,IAAI,kBAAkB,GAAG;IAAE,SAAS,EAAE,uBAAuB,CAAA;CAEtE,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isHierarchy = exports.stripNumericPrefix = exports.getApiGroupFolder = exports.API_GROUPS = exports.SidebarPosition = exports.CATEGORY_STYLE_CLASS = exports.DEPRECATED = void 0;
|
|
4
|
+
const graphql_1 = require("@graphql-markdown/graphql");
|
|
5
|
+
const validation_ts_1 = require("./directives/validation.js");
|
|
6
|
+
/**
|
|
7
|
+
* Constant representing the string literal for deprecated entities.
|
|
8
|
+
* Used for grouping deprecated schema entities when the deprecated option is set to "group".
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // When using the deprecated grouping option
|
|
13
|
+
* if (isDeprecated(type)) {
|
|
14
|
+
* const groupName = DEPRECATED;
|
|
15
|
+
* // Handle deprecated type
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
exports.DEPRECATED = "deprecated";
|
|
20
|
+
/**
|
|
21
|
+
* CSS class names used for styling different categories in the generated documentation.
|
|
22
|
+
* These are applied to the generated index metafiles for different section types.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // When generating API section metafiles
|
|
27
|
+
* await generateIndexMetafile(dirPath, typeCat, {
|
|
28
|
+
* styleClass: CATEGORY_STYLE_CLASS.API
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
var CATEGORY_STYLE_CLASS;
|
|
33
|
+
(function (CATEGORY_STYLE_CLASS) {
|
|
34
|
+
/**
|
|
35
|
+
* CSS class applied to API sections (operations)
|
|
36
|
+
*/
|
|
37
|
+
CATEGORY_STYLE_CLASS["API"] = "graphql-markdown-api-section";
|
|
38
|
+
/**
|
|
39
|
+
* CSS class applied to deprecated entity sections
|
|
40
|
+
*/
|
|
41
|
+
CATEGORY_STYLE_CLASS["DEPRECATED"] = "graphql-markdown-deprecated-section";
|
|
42
|
+
})(CATEGORY_STYLE_CLASS || (exports.CATEGORY_STYLE_CLASS = CATEGORY_STYLE_CLASS = {}));
|
|
43
|
+
/**
|
|
44
|
+
* Enum defining sidebar position values for ordering categories in the documentation sidebar.
|
|
45
|
+
* Used to control the relative position of categories in the navigation.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Position deprecated entities at the end of the sidebar
|
|
50
|
+
* await generateIndexMetafile(dirPath, DEPRECATED, {
|
|
51
|
+
* sidebarPosition: SidebarPosition.LAST
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
var SidebarPosition;
|
|
56
|
+
(function (SidebarPosition) {
|
|
57
|
+
/**
|
|
58
|
+
* Position at the beginning of the sidebar
|
|
59
|
+
*/
|
|
60
|
+
SidebarPosition[SidebarPosition["FIRST"] = 1] = "FIRST";
|
|
61
|
+
/**
|
|
62
|
+
* Position at the end of the sidebar
|
|
63
|
+
*/
|
|
64
|
+
SidebarPosition[SidebarPosition["LAST"] = 999] = "LAST";
|
|
65
|
+
})(SidebarPosition || (exports.SidebarPosition = SidebarPosition = {}));
|
|
66
|
+
/**
|
|
67
|
+
* Default group names for API types and non-API types.
|
|
68
|
+
* This constant provides the base folder structure for organizing GraphQL schema entities.
|
|
69
|
+
* Can be overridden via ApiGroupOverrideType in configuration.
|
|
70
|
+
*
|
|
71
|
+
* @property operations Folder name for GraphQL operations (queries, mutations, subscriptions)
|
|
72
|
+
* @property types Folder name for GraphQL type definitions
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Default structure
|
|
77
|
+
* const defaultGroups = API_GROUPS;
|
|
78
|
+
* // { operations: "operations", types: "types" }
|
|
79
|
+
*
|
|
80
|
+
* // With custom override
|
|
81
|
+
* const customGroups = { ...API_GROUPS, operations: "queries-and-mutations" };
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @see {@link getApiGroupFolder} For usage with type categorization
|
|
85
|
+
*/
|
|
86
|
+
exports.API_GROUPS = {
|
|
87
|
+
operations: "operations",
|
|
88
|
+
types: "types",
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Determines the appropriate folder for a GraphQL schema entity based on its type.
|
|
92
|
+
*
|
|
93
|
+
* @param type - The GraphQL schema entity to categorize
|
|
94
|
+
* @param groups - Optional custom group naming configuration
|
|
95
|
+
* @returns The folder name where the entity should be placed
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* // With default groups
|
|
100
|
+
* const folder = getApiGroupFolder(queryType); // Returns "operations"
|
|
101
|
+
*
|
|
102
|
+
* // With custom groups
|
|
103
|
+
* const folder = getApiGroupFolder(objectType, { operations: "queries" }); // Returns appropriate folder
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
const getApiGroupFolder = (type, groups) => {
|
|
107
|
+
let folderNames = exports.API_GROUPS;
|
|
108
|
+
if ((0, validation_ts_1.isGroupsObject)(groups)) {
|
|
109
|
+
folderNames = { ...exports.API_GROUPS, ...groups };
|
|
110
|
+
}
|
|
111
|
+
return (0, graphql_1.isApiType)(type) ? folderNames.operations : folderNames.types;
|
|
112
|
+
};
|
|
113
|
+
exports.getApiGroupFolder = getApiGroupFolder;
|
|
114
|
+
/**
|
|
115
|
+
* Strips numeric prefix from a folder name if categorySort is enabled.
|
|
116
|
+
* Converts folder names like "01-query" back to "query" for category identification.
|
|
117
|
+
*
|
|
118
|
+
* This is needed when extracting category names from file paths that were created
|
|
119
|
+
* with categorySort enabled. The regex matches leading two-digit numbers
|
|
120
|
+
* followed by a hyphen.
|
|
121
|
+
*
|
|
122
|
+
* @param folderName - The folder name to strip (e.g., "01-query", "02-mutations")
|
|
123
|
+
* @returns The folder name without prefix (e.g., "query", "mutations")
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* stripNumericPrefix("01-query"); // Returns "query"
|
|
128
|
+
* stripNumericPrefix("02-mutations"); // Returns "mutations"
|
|
129
|
+
* stripNumericPrefix("objects"); // Returns "objects" (no prefix to strip)
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
const stripNumericPrefix = (folderName) => {
|
|
133
|
+
return folderName.replace(/^\d{2}-/, "");
|
|
134
|
+
};
|
|
135
|
+
exports.stripNumericPrefix = stripNumericPrefix;
|
|
136
|
+
/**
|
|
137
|
+
* Type guard function that checks if the provided options include a specific hierarchy configuration.
|
|
138
|
+
*
|
|
139
|
+
* @param options - The renderer options to check
|
|
140
|
+
* @param hierarchy - The hierarchy type to check for
|
|
141
|
+
* @returns True if the options contain the specified hierarchy configuration
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* if (isHierarchy(options, TypeHierarchy.FLAT)) {
|
|
146
|
+
* // Handle flat hierarchy structure
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
const isHierarchy = (options, hierarchy) => {
|
|
151
|
+
return options?.hierarchy?.[hierarchy] !== undefined;
|
|
152
|
+
};
|
|
153
|
+
exports.isHierarchy = isHierarchy;
|
package/dist/version.js
CHANGED