@mintlify/common 1.0.903 → 1.0.905

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.
@@ -1,4 +1,21 @@
1
1
  import { getEnumValues } from '../getEnumValues.js';
2
+ const combinationKeys = ['oneOf', 'anyOf', 'allOf'];
3
+ const getCombinationKey = (value) => {
4
+ return combinationKeys.find((key) => key in value && Array.isArray(value[key]));
5
+ };
6
+ const getTypeFromCombination = (value, combKey) => {
7
+ var _a;
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ const schemas = value[combKey];
10
+ const types = [
11
+ ...new Set(schemas
12
+ .map((s) => (typeof s === 'object' ? s.type : undefined))
13
+ .filter((t) => typeof t === 'string' && t !== 'null')),
14
+ ];
15
+ if (types.length === 1)
16
+ return (_a = types[0]) !== null && _a !== void 0 ? _a : combKey;
17
+ return combKey;
18
+ };
2
19
  const getSchemaType = (value, keys) => {
3
20
  if ('type' in value) {
4
21
  return value.type;
@@ -61,18 +78,93 @@ export const extractSchemaProperties = (schema) => {
61
78
  const prop = {
62
79
  name: name,
63
80
  type,
81
+ title: value.title,
64
82
  description: value.description || value['const'],
65
83
  enumValues: getEnumValues(value),
84
+ examples: value.examples,
66
85
  deprecated: value.deprecated,
67
86
  required: requiredFields.has(name),
68
87
  };
69
88
  if (value.properties) {
70
89
  prop.properties = extractSchemaProperties(value.properties);
71
90
  }
91
+ else if (type === 'array' &&
92
+ value.items &&
93
+ typeof value.items === 'object' &&
94
+ !Array.isArray(value.items)) {
95
+ if (value.items.properties) {
96
+ const itemSchemaWithRequired = Object.assign(Object.assign({}, value.items.properties), { required: value.items.required });
97
+ prop.properties = extractSchemaProperties(itemSchemaWithRequired);
98
+ }
99
+ else {
100
+ const itemProps = extractSchemaProperties({ item: value.items });
101
+ if (itemProps.length > 0) {
102
+ prop.properties = itemProps;
103
+ }
104
+ }
105
+ }
72
106
  properties.push(prop);
73
107
  }
74
108
  else {
75
- properties.push(...extractSchemaProperties(value));
109
+ const combKey = getCombinationKey(value);
110
+ if (combKey) {
111
+ const inferredType = getTypeFromCombination(value, combKey);
112
+ const prop = {
113
+ name,
114
+ type: inferredType,
115
+ title: value.title,
116
+ description: value.description,
117
+ enumValues: getEnumValues(value),
118
+ examples: value.examples,
119
+ deprecated: value.deprecated,
120
+ required: requiredFields.has(name),
121
+ };
122
+ // Extract child properties from combination schemas
123
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
+ const combSchemas = value[combKey];
125
+ if (combKey === 'allOf') {
126
+ // allOf: merge all sub-schema properties together
127
+ const mergedProps = combSchemas.flatMap(
128
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
+ (item) => {
130
+ if (item.properties) {
131
+ const schemaWithRequired = Object.assign(Object.assign({}, item.properties), { required: item.required });
132
+ return extractSchemaProperties(schemaWithRequired);
133
+ }
134
+ return [];
135
+ });
136
+ if (mergedProps.length > 0) {
137
+ prop.properties = mergedProps;
138
+ if (inferredType === 'allOf')
139
+ prop.type = 'object';
140
+ }
141
+ }
142
+ else {
143
+ // oneOf/anyOf: extract properties from sub-schemas that have them
144
+ const subProps = combSchemas.flatMap(
145
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
146
+ (item) => {
147
+ if (item.properties) {
148
+ const schemaWithRequired = Object.assign(Object.assign({}, item.properties), { required: item.required });
149
+ return extractSchemaProperties(schemaWithRequired);
150
+ }
151
+ if (item.items && typeof item.items === 'object') {
152
+ if (item.items.properties) {
153
+ const schemaWithRequired = Object.assign(Object.assign({}, item.items.properties), { required: item.items.required });
154
+ return extractSchemaProperties(schemaWithRequired);
155
+ }
156
+ }
157
+ return [];
158
+ });
159
+ if (subProps.length > 0) {
160
+ prop.properties = subProps;
161
+ }
162
+ }
163
+ properties.push(prop);
164
+ }
165
+ else {
166
+ properties.push(...extractSchemaProperties(value));
167
+ }
76
168
  }
77
169
  }
78
170
  else {
@@ -12,10 +12,11 @@ type MDXOptionsData = {
12
12
  tailwindSelectors?: string[];
13
13
  path?: string;
14
14
  };
15
- export declare const getMDXOptions: ({ data, remarkPlugins, rehypePlugins, mdxExtracts, }: {
15
+ export declare const getMDXOptions: ({ data, remarkPlugins, rehypePlugins, mdxExtracts, allowedComponents, }: {
16
16
  data: MDXOptionsData;
17
17
  remarkPlugins?: PluggableList;
18
18
  rehypePlugins?: PluggableList;
19
19
  mdxExtracts?: MdxExtracts;
20
+ allowedComponents?: string[];
20
21
  }) => SerializeOptions["mdxOptions"];
21
22
  export {};
@@ -10,7 +10,7 @@ const rehypeExtractors = (mdxExtracts, data) => {
10
10
  [rehypeMdxExtractEndpoint, data.pageMetadata, data.config, mdxExtracts],
11
11
  ];
12
12
  };
13
- export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], mdxExtracts, }) => {
13
+ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], mdxExtracts, allowedComponents = [], }) => {
14
14
  return {
15
15
  remarkPlugins: [
16
16
  [remarkMdxInjectSnippets, data.snippetTreeMap],
@@ -28,7 +28,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
28
28
  remarkMermaid,
29
29
  remarkVideo,
30
30
  ...remarkPlugins,
31
- remarkMdxRemoveUnknownJsx,
31
+ [remarkMdxRemoveUnknownJsx, { allowlist: allowedComponents }],
32
32
  ],
33
33
  rehypePlugins: [
34
34
  rehypeCodeBlocks,
@@ -1,2 +1,4 @@
1
1
  import type { Root } from 'mdast';
2
- export declare const remarkMdxRemoveUnknownJsx: () => (tree: Root) => Root | import("mdast").Link | import("mdast").Delete | import("mdast").Code | import("mdast").Blockquote | import("mdast").Break | import("mdast").Definition | import("mdast").Emphasis | import("mdast").FootnoteDefinition | import("mdast").FootnoteReference | import("mdast").Heading | import("mdast").Html | import("mdast").Image | import("mdast").ImageReference | import("mdast").InlineCode | import("mdast").LinkReference | import("mdast").List | import("mdast").ListItem | import("mdast").Paragraph | import("mdast").Strong | import("mdast").Table | import("mdast").TableCell | import("mdast").TableRow | import("mdast").Text | import("mdast").ThematicBreak | import("mdast").Yaml | import("mdast-util-math").InlineMath | import("mdast-util-math").Math | import("mdast-util-mdx-expression").MdxTextExpression | import("mdast-util-mdx-expression").MdxFlowExpression | import("mdast-util-mdx").MdxJsxFlowElement | import("mdast-util-mdx").MdxJsxTextElement | import("mdast-util-mdxjs-esm").MdxjsEsm;
2
+ export declare const remarkMdxRemoveUnknownJsx: ({ allowlist }?: {
3
+ allowlist?: string[];
4
+ }) => (tree: Root) => Root | import("mdast").Link | import("mdast").Delete | import("mdast").Code | import("mdast").Blockquote | import("mdast").Break | import("mdast").Definition | import("mdast").Emphasis | import("mdast").FootnoteDefinition | import("mdast").FootnoteReference | import("mdast").Heading | import("mdast").Html | import("mdast").Image | import("mdast").ImageReference | import("mdast").InlineCode | import("mdast").LinkReference | import("mdast").List | import("mdast").ListItem | import("mdast").Paragraph | import("mdast").Strong | import("mdast").Table | import("mdast").TableCell | import("mdast").TableRow | import("mdast").Text | import("mdast").ThematicBreak | import("mdast").Yaml | import("mdast-util-math").InlineMath | import("mdast-util-math").Math | import("mdast-util-mdx-expression").MdxTextExpression | import("mdast-util-mdx-expression").MdxFlowExpression | import("mdast-util-mdx").MdxJsxFlowElement | import("mdast-util-mdx").MdxJsxTextElement | import("mdast-util-mdxjs-esm").MdxjsEsm;
@@ -2,14 +2,15 @@ import { map } from 'unist-util-map';
2
2
  import { allowedComponents } from '../../../index.js';
3
3
  import { findExportedNodes, isMdxJsxFlowElementHast } from '../../../lib/index.js';
4
4
  import { createCommentNode } from './createCommentNode.js';
5
- export const remarkMdxRemoveUnknownJsx = () => (tree) => {
5
+ export const remarkMdxRemoveUnknownJsx = ({ allowlist } = {}) => (tree) => {
6
6
  const exportedComponentNames = findExportedNodes(tree, 'ArrowFunctionExpression');
7
7
  return map(tree, (node) => {
8
8
  if (isMdxJsxFlowElementHast(node)) {
9
9
  if (node.name &&
10
10
  Array.isArray(allowedComponents) &&
11
11
  !allowedComponents.includes(node.name) &&
12
- !exportedComponentNames.includes(node.name)) {
12
+ !exportedComponentNames.includes(node.name) &&
13
+ !(allowlist === null || allowlist === void 0 ? void 0 : allowlist.includes(node.name))) {
13
14
  return createCommentNode(node.name);
14
15
  }
15
16
  }
@@ -12,7 +12,7 @@ export type GetMdxType = {
12
12
  panelMdxSource?: SerializeSuccess;
13
13
  panelMdxSourceWithNoJs?: SerializeSuccess;
14
14
  };
15
- export declare function getMdx({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors, pageType, trace, customLanguages, variables, rehypePlugins, remarkPlugins, }: {
15
+ export declare function getMdx({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors, pageType, trace, customLanguages, variables, rehypePlugins, remarkPlugins, allowedComponents, }: {
16
16
  path: string;
17
17
  content: string;
18
18
  metadata: PageMetaTags;
@@ -27,5 +27,6 @@ export declare function getMdx({ path, content, metadata, snippets, subdomain, c
27
27
  variables?: Record<string, string>;
28
28
  rehypePlugins?: PluggableList;
29
29
  remarkPlugins?: PluggableList;
30
+ allowedComponents?: string[];
30
31
  }): Promise<GetMdxType>;
31
32
  export { createSnippetTreeMap, type Snippet };
@@ -15,7 +15,7 @@ import { preprocessCustomHeadingIds } from '../preprocessCustomHeadingIds.js';
15
15
  import { replaceVariables } from '../replaceVariables.js';
16
16
  import { createSnippetTreeMap } from './getMdx/snippets.js';
17
17
  export function getMdx(_a) {
18
- return __awaiter(this, arguments, void 0, function* ({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors = undefined, pageType = 'default', trace = undefined, customLanguages = [], variables = undefined, rehypePlugins = [], remarkPlugins = [], }) {
18
+ return __awaiter(this, arguments, void 0, function* ({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors = undefined, pageType = 'default', trace = undefined, customLanguages = [], variables = undefined, rehypePlugins = [], remarkPlugins = [], allowedComponents = [], }) {
19
19
  const traceFn = trace !== null && trace !== void 0 ? trace : ((_name, fn) => fn());
20
20
  const processedContent = preprocessCustomHeadingIds(replaceVariables(content, variables));
21
21
  const processedSnippets = snippets.map((snippet) => (Object.assign(Object.assign({}, snippet), { content: preprocessCustomHeadingIds(replaceVariables(snippet.content, variables)) })));
@@ -41,11 +41,13 @@ export function getMdx(_a) {
41
41
  remarkPlugins: plugins,
42
42
  rehypePlugins,
43
43
  mdxExtracts,
44
+ allowedComponents,
44
45
  });
45
46
  const mdxOptionsNoJs = getMDXOptions({
46
47
  data: mdxOptionsData,
47
48
  remarkPlugins: [remarkMdxRemoveJs, ...plugins],
48
49
  rehypePlugins,
50
+ allowedComponents,
49
51
  });
50
52
  const scope = {
51
53
  codeStyling,