Skip to content

Commit b29edf5

Browse files
committed
bulk entitites methods
1 parent bd816ff commit b29edf5

5 files changed

Lines changed: 257 additions & 34 deletions

File tree

scripts/mintlify-post-processing/file-processing/file-processing.js

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const APPENDED_ARTICLES_PATH = path.join(
3030
__dirname,
3131
"../appended-articles.json"
3232
);
33+
const METHOD_ORDER_PATH = path.join(__dirname, "..", "method-order.json");
3334

3435
// Controlled via env var so we can re-enable Panel injection when needed.
3536
const PANELS_ENABLED = process.env.MINTLIFY_INCLUDE_PANELS === "true";
@@ -1959,6 +1960,40 @@ function cleanupSortFieldSignature(dir) {
19591960
}
19601961
}
19611962

1963+
/**
1964+
* Fix truncated intersection types in ParamField type attributes.
1965+
* TypeDoc renders (Partial<T> & { id: string })[] as "Partial<...> & object[]".
1966+
*/
1967+
function cleanupTruncatedParamTypes(dir) {
1968+
if (!fs.existsSync(dir)) return;
1969+
const entries = fs.readdirSync(dir, { withFileTypes: true });
1970+
for (const entry of entries) {
1971+
const entryPath = path.join(dir, entry.name);
1972+
if (entry.isDirectory()) {
1973+
cleanupTruncatedParamTypes(entryPath);
1974+
} else if (
1975+
entry.isFile() &&
1976+
(entry.name.endsWith(".mdx") || entry.name.endsWith(".md"))
1977+
) {
1978+
let content = fs.readFileSync(entryPath, "utf-8");
1979+
let modified = false;
1980+
1981+
if (content.includes('type="Partial<...> & object[]"')) {
1982+
content = content.replace(
1983+
/type="Partial<\.\.\.> & object\[\]"/g,
1984+
'type="(Partial<T> & { id: string })[]"'
1985+
);
1986+
modified = true;
1987+
}
1988+
1989+
if (modified) {
1990+
fs.writeFileSync(entryPath, content, "utf-8");
1991+
console.log(`Cleaned truncated param type: ${path.relative(DOCS_DIR, entryPath)}`);
1992+
}
1993+
}
1994+
}
1995+
}
1996+
19621997
/**
19631998
* Main function
19641999
*/
@@ -2004,6 +2039,127 @@ function deleteTypesAfterProcessing(docsDir) {
20042039
}
20052040
}
20062041

2042+
/**
2043+
* Load method-order.json config.
2044+
* Keys are MDX base filenames (e.g. "entities"), values are ordered method name arrays.
2045+
*/
2046+
function loadMethodOrderConfig() {
2047+
if (!fs.existsSync(METHOD_ORDER_PATH)) return {};
2048+
return JSON.parse(fs.readFileSync(METHOD_ORDER_PATH, "utf-8"));
2049+
}
2050+
2051+
/**
2052+
* Reorder method blocks inside an MDX file according to a given ordered list.
2053+
*
2054+
* The file is split on `***` horizontal-rule separators into sections. Sections
2055+
* whose first `### name()` heading matches an entry in `orderedNames` are
2056+
* reordered accordingly; unlisted method sections keep their relative order
2057+
* and appear after explicitly ordered ones.
2058+
*
2059+
* Type-definition sections that are displaced between the `## ... Methods`
2060+
* heading and the first method are relocated to after the footer (where
2061+
* `## Type Definitions` lives), so they appear under the correct TOC group.
2062+
*/
2063+
function reorderMethods(content, orderedNames) {
2064+
const sections = content.split(/\n*\*{3}\n*/);
2065+
const HR = "\n\n***\n\n";
2066+
2067+
const methodRe = /^### (\w+)\(\)/m;
2068+
const methodsHeadingRe = /^## .+ Methods$/m;
2069+
2070+
const tagged = sections.map((text) => ({
2071+
text,
2072+
methodName: (text.match(methodRe) || [])[1] || null,
2073+
hasMethodsHeading: methodsHeadingRe.test(text),
2074+
}));
2075+
2076+
const firstMethodIdx = tagged.findIndex((t) => t.methodName);
2077+
if (firstMethodIdx === -1) return { content, modified: false };
2078+
2079+
let lastMethodIdx = -1;
2080+
for (let i = tagged.length - 1; i >= 0; i--) {
2081+
if (tagged[i].methodName) {
2082+
lastMethodIdx = i;
2083+
break;
2084+
}
2085+
}
2086+
2087+
const headingIdx = tagged.findIndex((t) => t.hasMethodsHeading);
2088+
const displacedStart = headingIdx !== -1 ? headingIdx + 1 : firstMethodIdx;
2089+
2090+
const header = tagged.slice(0, displacedStart);
2091+
const displaced = tagged.slice(displacedStart, firstMethodIdx);
2092+
const middle = tagged.slice(firstMethodIdx, lastMethodIdx + 1);
2093+
const footer = tagged.slice(lastMethodIdx + 1);
2094+
2095+
const methods = middle.filter((t) => t.methodName);
2096+
const stray = middle.filter((t) => !t.methodName);
2097+
2098+
const orderMap = new Map(orderedNames.map((n, i) => [n, i]));
2099+
const origOrder = methods.map((m) => m.methodName).join(",");
2100+
2101+
methods.sort((a, b) => {
2102+
const ai = orderMap.has(a.methodName)
2103+
? orderMap.get(a.methodName)
2104+
: orderedNames.length + methods.indexOf(a);
2105+
const bi = orderMap.has(b.methodName)
2106+
? orderMap.get(b.methodName)
2107+
: orderedNames.length + methods.indexOf(b);
2108+
return ai - bi;
2109+
});
2110+
2111+
const newOrder = methods.map((m) => m.methodName).join(",");
2112+
if (origOrder === newOrder && displaced.length === 0 && stray.length === 0) {
2113+
return { content, modified: false };
2114+
}
2115+
2116+
const ordered = [
2117+
...header,
2118+
...methods,
2119+
...footer,
2120+
...displaced,
2121+
...stray,
2122+
];
2123+
2124+
return { content: ordered.map((t) => t.text).join(HR), modified: true };
2125+
}
2126+
2127+
/**
2128+
* Apply method ordering to MDX files whose base name matches a key in method-order.json.
2129+
*/
2130+
function applyMethodOrdering(dir) {
2131+
const config = loadMethodOrderConfig();
2132+
if (Object.keys(config).length === 0) return;
2133+
2134+
if (!fs.existsSync(dir)) return;
2135+
const entries = fs.readdirSync(dir, { withFileTypes: true });
2136+
for (const entry of entries) {
2137+
const entryPath = path.join(dir, entry.name);
2138+
if (entry.isDirectory()) {
2139+
applyMethodOrdering(entryPath);
2140+
} else if (
2141+
entry.isFile() &&
2142+
(entry.name.endsWith(".mdx") || entry.name.endsWith(".md"))
2143+
) {
2144+
const baseName = path.basename(entry.name, path.extname(entry.name));
2145+
const orderedNames = config[baseName];
2146+
if (!orderedNames) continue;
2147+
2148+
const content = fs.readFileSync(entryPath, "utf-8");
2149+
const { content: updated, modified } = reorderMethods(
2150+
content,
2151+
orderedNames
2152+
);
2153+
if (modified) {
2154+
fs.writeFileSync(entryPath, updated, "utf-8");
2155+
console.log(
2156+
`Reordered methods: ${path.relative(DOCS_DIR, entryPath)}`
2157+
);
2158+
}
2159+
}
2160+
}
2161+
}
2162+
20072163
function main() {
20082164
console.log("Processing TypeDoc MDX files for Mintlify...\n");
20092165

@@ -2033,6 +2189,9 @@ function main() {
20332189
// Clean up SortField signature specifically (before general signature cleanup)
20342190
cleanupSortFieldSignature(DOCS_DIR);
20352191

2192+
// Fix truncated intersection types in ParamField type attributes
2193+
cleanupTruncatedParamTypes(DOCS_DIR);
2194+
20362195
// Clean up signatures: fix truncated generics, simplify keyof constraints, break long lines
20372196
applySignatureCleanup(DOCS_DIR);
20382197

@@ -2050,6 +2209,9 @@ function main() {
20502209
// Group type definitions under a parent heading
20512210
applyTypeDefinitionGrouping(DOCS_DIR);
20522211

2212+
// Reorder methods according to method-order.json
2213+
applyMethodOrdering(DOCS_DIR);
2214+
20532215
// Link type names in Type Declarations sections to their corresponding headings
20542216
applyTypeDeclarationLinking(DOCS_DIR);
20552217

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"entities": [
3+
"get",
4+
"list",
5+
"filter",
6+
"create",
7+
"bulkCreate",
8+
"importEntities",
9+
"update",
10+
"updateMany",
11+
"bulkUpdate",
12+
"delete",
13+
"deleteMany",
14+
"subscribe"
15+
]
16+
}

scripts/mintlify-post-processing/types-to-delete-after-processing.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"DeleteManyResult",
33
"DeleteResult",
44
"ImportResult",
5-
"SortField"
5+
"SortField",
6+
"UpdateManyResult"
67
]

scripts/mintlify-post-processing/types-to-expose.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
"IntegrationsModule",
2323
"CoreIntegrations",
2424
"SortField",
25-
"SsoModule"
25+
"SsoModule",
26+
"UpdateManyResult"
2627
]

0 commit comments

Comments
 (0)