@graphql-markdown/printer-legacy 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common.d.ts +1 -0
- package/dist/common.js +22 -8
- package/dist/const/options.js +1 -1
- package/dist/const/strings.d.ts +1 -1
- package/dist/const/strings.js +2 -2
- package/dist/frontmatter.d.ts +3 -0
- package/dist/frontmatter.js +64 -0
- package/dist/printer.js +3 -13
- package/dist/section.js +1 -1
- package/package.json +4 -4
package/dist/common.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PrintTypeOptions, MDXString, Maybe } from "@graphql-markdown/types";
|
|
2
2
|
export declare const printCustomDirectives: (type: unknown, options?: PrintTypeOptions) => string;
|
|
3
3
|
export declare const formatDescription: (type: unknown, replacement?: Maybe<string>) => MDXString | string;
|
|
4
|
+
export declare const printWarning: (text?: string, title?: string) => string;
|
|
4
5
|
export declare const printDeprecation: (type: unknown) => string;
|
|
5
6
|
export declare const printDescription: (type: unknown, options?: PrintTypeOptions, noText?: string) => MDXString | string;
|
|
6
7
|
export declare const hasPrintableDirective: (type: unknown, options?: Pick<PrintTypeOptions, "deprecated" | "onlyDocDirectives" | "skipDocDirectives">) => boolean;
|
package/dist/common.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasPrintableDirective = exports.printDescription = exports.printDeprecation = exports.formatDescription = exports.printCustomDirectives = void 0;
|
|
4
|
-
const utils_1 = require("@
|
|
3
|
+
exports.hasPrintableDirective = exports.printDescription = exports.printDeprecation = exports.printWarning = exports.formatDescription = exports.printCustomDirectives = void 0;
|
|
4
|
+
const utils_1 = require("@docusaurus/utils");
|
|
5
|
+
const utils_2 = require("@graphql-markdown/utils");
|
|
5
6
|
const graphql_1 = require("@graphql-markdown/graphql");
|
|
6
7
|
const directive_1 = require("./directive");
|
|
7
8
|
const strings_1 = require("./const/strings");
|
|
8
9
|
const printCustomDirectives = (type, options) => {
|
|
9
10
|
const constDirectiveMap = (0, graphql_1.getConstDirectiveMap)(type, options?.customDirectives);
|
|
10
|
-
if (!constDirectiveMap || (0,
|
|
11
|
+
if (!constDirectiveMap || (0, utils_2.isEmpty)(constDirectiveMap)) {
|
|
11
12
|
return "";
|
|
12
13
|
}
|
|
13
14
|
const content = Object.values(constDirectiveMap)
|
|
@@ -16,6 +17,9 @@ const printCustomDirectives = (type, options) => {
|
|
|
16
17
|
})
|
|
17
18
|
.filter((text) => {
|
|
18
19
|
return typeof text === "string" && text.length > 0;
|
|
20
|
+
})
|
|
21
|
+
.map((text) => {
|
|
22
|
+
return (0, utils_2.escapeMDX)(text);
|
|
19
23
|
})
|
|
20
24
|
.join(strings_1.MARKDOWN_EOP);
|
|
21
25
|
return `${strings_1.MARKDOWN_EOP}${content}`;
|
|
@@ -23,22 +27,32 @@ const printCustomDirectives = (type, options) => {
|
|
|
23
27
|
exports.printCustomDirectives = printCustomDirectives;
|
|
24
28
|
const formatDescription = (type, replacement = strings_1.NO_DESCRIPTION_TEXT) => {
|
|
25
29
|
if (typeof type !== "object" || type === null) {
|
|
26
|
-
return `${strings_1.MARKDOWN_EOP}${replacement}`;
|
|
30
|
+
return `${strings_1.MARKDOWN_EOP}${(0, utils_2.escapeMDX)(replacement)}`;
|
|
27
31
|
}
|
|
28
32
|
const description = "description" in type && typeof type.description === "string"
|
|
29
|
-
?
|
|
33
|
+
? type.description
|
|
30
34
|
: replacement;
|
|
31
|
-
return `${strings_1.MARKDOWN_EOP}${description}`;
|
|
35
|
+
return `${strings_1.MARKDOWN_EOP}${(0, utils_2.escapeMDX)(description)}`;
|
|
32
36
|
};
|
|
33
37
|
exports.formatDescription = formatDescription;
|
|
38
|
+
const printWarning = (text, title) => {
|
|
39
|
+
const formattedText = typeof text !== "string" || text.trim() === ""
|
|
40
|
+
? strings_1.MARKDOWN_EOP
|
|
41
|
+
: `${strings_1.MARKDOWN_EOP}${text}${strings_1.MARKDOWN_EOP}`;
|
|
42
|
+
if (utils_1.DOCUSAURUS_VERSION.startsWith("2")) {
|
|
43
|
+
return `${strings_1.MARKDOWN_EOP}:::caution ${title}${formattedText}:::`;
|
|
44
|
+
}
|
|
45
|
+
return `${strings_1.MARKDOWN_EOP}:::warning[${title}]${formattedText}:::`;
|
|
46
|
+
};
|
|
47
|
+
exports.printWarning = printWarning;
|
|
34
48
|
const printDeprecation = (type) => {
|
|
35
49
|
if (typeof type !== "object" || type === null || !(0, graphql_1.isDeprecated)(type)) {
|
|
36
50
|
return "";
|
|
37
51
|
}
|
|
38
52
|
const reason = "deprecationReason" in type && typeof type.deprecationReason === "string"
|
|
39
|
-
? type.deprecationReason
|
|
53
|
+
? (0, utils_2.escapeMDX)(type.deprecationReason)
|
|
40
54
|
: "";
|
|
41
|
-
return
|
|
55
|
+
return (0, exports.printWarning)(reason, strings_1.DEPRECATED.toUpperCase());
|
|
42
56
|
};
|
|
43
57
|
exports.printDeprecation = printDeprecation;
|
|
44
58
|
const printDescription = (type, options, noText) => {
|
package/dist/const/options.js
CHANGED
package/dist/const/strings.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RootTypeLocale } from "@graphql-markdown/types";
|
|
2
2
|
export declare const ROOT_TYPE_LOCALE: RootTypeLocale;
|
|
3
3
|
export declare const NO_DESCRIPTION_TEXT: "No description";
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const FRONT_MATTER_DELIMITER: "---";
|
|
5
5
|
export declare const MARKDOWN_CODE_INDENTATION: " ";
|
|
6
6
|
export declare const MARKDOWN_EOL: "\n";
|
|
7
7
|
export declare const MARKDOWN_EOP: "\n\n";
|
package/dist/const/strings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SHOW_DEPRECATED = exports.HIDE_DEPRECATED = exports.DEPRECATED = exports.MARKDOWN_SOC = exports.MARKDOWN_EOC = exports.MARKDOWN_EOP = exports.MARKDOWN_EOL = exports.MARKDOWN_CODE_INDENTATION = exports.
|
|
3
|
+
exports.SHOW_DEPRECATED = exports.HIDE_DEPRECATED = exports.DEPRECATED = exports.MARKDOWN_SOC = exports.MARKDOWN_EOC = exports.MARKDOWN_EOP = exports.MARKDOWN_EOL = exports.MARKDOWN_CODE_INDENTATION = exports.FRONT_MATTER_DELIMITER = exports.NO_DESCRIPTION_TEXT = exports.ROOT_TYPE_LOCALE = void 0;
|
|
4
4
|
exports.ROOT_TYPE_LOCALE = {
|
|
5
5
|
DIRECTIVE: { singular: "directive", plural: "directives" },
|
|
6
6
|
ENUM: { singular: "enum", plural: "enums" },
|
|
@@ -15,7 +15,7 @@ exports.ROOT_TYPE_LOCALE = {
|
|
|
15
15
|
UNION: { singular: "union", plural: "unions" },
|
|
16
16
|
};
|
|
17
17
|
exports.NO_DESCRIPTION_TEXT = "No description";
|
|
18
|
-
exports.
|
|
18
|
+
exports.FRONT_MATTER_DELIMITER = "---";
|
|
19
19
|
exports.MARKDOWN_CODE_INDENTATION = " ";
|
|
20
20
|
exports.MARKDOWN_EOL = "\n";
|
|
21
21
|
exports.MARKDOWN_EOP = "\n\n";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FrontMatterOptions, Maybe } from "@graphql-markdown/types";
|
|
2
|
+
export declare const formatFrontMatterProp: (prop: unknown, indentation?: number, prefix?: string) => string[];
|
|
3
|
+
export declare const printFrontMatter: (id: string, title: string, props?: Maybe<FrontMatterOptions>) => string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printFrontMatter = exports.formatFrontMatterProp = void 0;
|
|
4
|
+
const strings_1 = require("./const/strings");
|
|
5
|
+
const tabs = (indentation = 0) => {
|
|
6
|
+
return strings_1.MARKDOWN_CODE_INDENTATION.repeat(indentation);
|
|
7
|
+
};
|
|
8
|
+
const formatFrontMatterObject = (props, indentation = 0, prefix) => {
|
|
9
|
+
const frontMatter = [];
|
|
10
|
+
if (!props || typeof props !== "object") {
|
|
11
|
+
return frontMatter;
|
|
12
|
+
}
|
|
13
|
+
for (const [key, value] of Object.entries(props)) {
|
|
14
|
+
frontMatter.push(
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
16
|
+
...(0, exports.formatFrontMatterProp)({ [key]: value }, indentation + 1, prefix));
|
|
17
|
+
prefix = " ".repeat(prefix?.length ?? 0);
|
|
18
|
+
}
|
|
19
|
+
return frontMatter;
|
|
20
|
+
};
|
|
21
|
+
const formatFrontMatterList = (prop, indentation = 0, prefix = "- ") => {
|
|
22
|
+
const frontMatter = [];
|
|
23
|
+
if (!Array.isArray(prop)) {
|
|
24
|
+
return frontMatter;
|
|
25
|
+
}
|
|
26
|
+
prop.forEach((entry) => {
|
|
27
|
+
if (typeof entry === "object") {
|
|
28
|
+
frontMatter.push(...formatFrontMatterObject(entry, -1, prefix).map((item) => {
|
|
29
|
+
return `${tabs(indentation)}${item}`;
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
frontMatter.push(`${tabs(indentation)}- ${entry}`);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return frontMatter;
|
|
37
|
+
};
|
|
38
|
+
const formatFrontMatterProp = (prop, indentation = 0, prefix) => {
|
|
39
|
+
if (typeof prop === "undefined" || prop === null) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
const tabs = strings_1.MARKDOWN_CODE_INDENTATION.repeat(indentation);
|
|
43
|
+
const [key, value] = Object.entries(prop)[0];
|
|
44
|
+
const index = `${tabs}${prefix ?? ""}${key}:`;
|
|
45
|
+
switch (true) {
|
|
46
|
+
case typeof value !== "string" && Array.isArray(value):
|
|
47
|
+
return [index, ...formatFrontMatterList(value, indentation + 1, prefix)];
|
|
48
|
+
case typeof value === "object" && value !== null:
|
|
49
|
+
return [index, ...formatFrontMatterObject(value, indentation, prefix)];
|
|
50
|
+
default:
|
|
51
|
+
return [`${index} ${value}`];
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.formatFrontMatterProp = formatFrontMatterProp;
|
|
55
|
+
const printFrontMatter = (id, title, props) => {
|
|
56
|
+
const frontMatter = formatFrontMatterObject({ ...props, id, title }, -1);
|
|
57
|
+
const header = [
|
|
58
|
+
strings_1.FRONT_MATTER_DELIMITER,
|
|
59
|
+
...frontMatter,
|
|
60
|
+
strings_1.FRONT_MATTER_DELIMITER,
|
|
61
|
+
];
|
|
62
|
+
return header.join(strings_1.MARKDOWN_EOL);
|
|
63
|
+
};
|
|
64
|
+
exports.printFrontMatter = printFrontMatter;
|
package/dist/printer.js
CHANGED
|
@@ -6,6 +6,7 @@ const utils_1 = require("@graphql-markdown/utils");
|
|
|
6
6
|
const relation_1 = require("./relation");
|
|
7
7
|
const common_1 = require("./common");
|
|
8
8
|
const directive_1 = require("./directive");
|
|
9
|
+
const frontmatter_1 = require("./frontmatter");
|
|
9
10
|
const graphql_2 = require("./graphql");
|
|
10
11
|
const strings_1 = require("./const/strings");
|
|
11
12
|
const mdx_1 = require("./const/mdx");
|
|
@@ -45,19 +46,8 @@ class Printer {
|
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
static printHeader = (id, title, options) => {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
? []
|
|
51
|
-
: ["pagination_next: null", "pagination_prev: null"];
|
|
52
|
-
const header = [
|
|
53
|
-
strings_1.FRONT_MATTER,
|
|
54
|
-
`id: ${id}`,
|
|
55
|
-
`title: ${title}`,
|
|
56
|
-
`hide_table_of_contents: ${!toc}`,
|
|
57
|
-
...paginationButtons,
|
|
58
|
-
strings_1.FRONT_MATTER,
|
|
59
|
-
];
|
|
60
|
-
return header.join(strings_1.MARKDOWN_EOL);
|
|
49
|
+
const fmOptions = options.frontMatter ?? options_1.DEFAULT_OPTIONS.frontMatter;
|
|
50
|
+
return (0, frontmatter_1.printFrontMatter)(id, title, fmOptions);
|
|
61
51
|
};
|
|
62
52
|
static printCode = (type, options) => {
|
|
63
53
|
let code = "";
|
package/dist/section.js
CHANGED
|
@@ -80,7 +80,7 @@ const printSection = (values, section, options) => {
|
|
|
80
80
|
})();
|
|
81
81
|
const items = (0, exports.printSectionItems)(values, {
|
|
82
82
|
...options,
|
|
83
|
-
collapsible: undefined,
|
|
83
|
+
collapsible: undefined, // do not propagate collapsible
|
|
84
84
|
level: (levelPosition > -1
|
|
85
85
|
? exports.sectionLevels[levelPosition + 1]
|
|
86
86
|
: undefined),
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/graphql-markdown/graphql-markdown/issues"
|
|
7
7
|
},
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.6.0",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@docusaurus/utils": ">=2.0.0",
|
|
59
|
-
"@graphql-markdown/graphql": "^1.0.
|
|
60
|
-
"@graphql-markdown/utils": "^1.6.
|
|
59
|
+
"@graphql-markdown/graphql": "^1.0.2",
|
|
60
|
+
"@graphql-markdown/utils": "^1.6.2"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@graphql-markdown/types": "^1.0.
|
|
63
|
+
"@graphql-markdown/types": "^1.0.1"
|
|
64
64
|
},
|
|
65
65
|
"directories": {
|
|
66
66
|
"test": "tests"
|