@mintlify/scraping 4.0.1033 → 4.0.1035

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/scraping",
3
- "version": "4.0.1033",
3
+ "version": "4.0.1035",
4
4
  "description": "Scrape documentation frameworks to Mintlify docs",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -43,7 +43,7 @@
43
43
  "format:check": "oxfmt --check"
44
44
  },
45
45
  "dependencies": {
46
- "@mintlify/common": "1.0.1165",
46
+ "@mintlify/common": "1.0.1166",
47
47
  "fast-xml-parser": "5.7.3",
48
48
  "fs-extra": "11.1.1",
49
49
  "graphql": "16.11.0",
@@ -65,7 +65,7 @@
65
65
  "devDependencies": {
66
66
  "@mintlify/models": "0.0.361",
67
67
  "@mintlify/ts-config": "2.0.2",
68
- "@mintlify/validation": "0.1.868",
68
+ "@mintlify/validation": "0.1.869",
69
69
  "@tsconfig/recommended": "1.0.2",
70
70
  "@types/hast": "3.0.4",
71
71
  "@types/mdast": "4.0.4",
@@ -79,5 +79,5 @@
79
79
  "typescript": "5.5.3",
80
80
  "vitest": "2.1.9"
81
81
  },
82
- "gitHead": "8915b9a07e0f69a40ccb9395d8d0514157c710d3"
82
+ "gitHead": "5273fce0f218cb475e78a9db77622d699cfb0ecd"
83
83
  }
@@ -69,6 +69,7 @@ type TypedocNode = {
69
69
  implementedTypes?: TypedocType[];
70
70
  inheritedFrom?: { name: string };
71
71
  };
72
+ type TypeToken = { text: string; href?: string };
72
73
 
73
74
  const SECTIONS: {
74
75
  kind: number;
@@ -116,7 +117,7 @@ export async function convertTypedoc(sourcePath: string): Promise<SdkReference>
116
117
  const prefix = multiModule ? slugify(module.name) : '';
117
118
  for (const { node, namespacePath } of collectDeclarations(module)) {
118
119
  const section = SECTIONS.find((entry) => entry.kind === node.kind);
119
- if (!section) continue;
120
+ if (!section || node.flags?.isPrivate) continue;
120
121
  slugById.set(
121
122
  node.id,
122
123
  path.posix.join(prefix, ...namespacePath.map(slugify), section.dir, slugify(node.name))
@@ -245,7 +246,7 @@ class TypedocRenderer {
245
246
  title: `${parentTitle}.${property.name}`,
246
247
  description: this.firstSentence(property.comment ?? property.getSignature?.comment),
247
248
  tag: 'PROPERTY',
248
- content: this.responseField(property.name, this.type(type), optional, summary),
249
+ content: this.typeField(property.name, type, optional, summary),
249
250
  target: { kind: 'property', name: property.name, parent: parent.name },
250
251
  });
251
252
  }
@@ -302,9 +303,9 @@ class TypedocRenderer {
302
303
  const type = property.kind === KIND.accessor ? property.getSignature?.type : property.type;
303
304
  const optional = property.flags?.isOptional === true;
304
305
  lines.push(
305
- this.responseField(
306
+ this.typeField(
306
307
  property.name,
307
- this.type(type),
308
+ type,
308
309
  optional,
309
310
  this.comment(property.comment ?? property.getSignature?.comment)
310
311
  )
@@ -354,9 +355,9 @@ class TypedocRenderer {
354
355
  lines.push(`${'#'.repeat(depth)} Parameters`);
355
356
  for (const param of signature.parameters) {
356
357
  lines.push(
357
- this.responseField(
358
+ this.typeField(
358
359
  param.name,
359
- this.type(param.type),
360
+ param.type,
360
361
  param.flags?.isOptional === true || param.defaultValue !== undefined,
361
362
  this.comment(param.comment)
362
363
  )
@@ -367,18 +368,38 @@ class TypedocRenderer {
367
368
  const returnType = this.type(signature.type);
368
369
  if (returnType && returnType !== 'void') {
369
370
  lines.push(`${'#'.repeat(depth)} Returns`);
370
- lines.push(
371
- `\`${escapeInlineCode(returnType)}\`${returns ? `\n\n${this.parts(returns.content)}` : ''}`
372
- );
371
+ const linked = this.linkedType(signature.type) ?? inlineCode(returnType);
372
+ lines.push(`${linked}${returns ? `\n\n${this.parts(returns.content)}` : ''}`);
373
373
  }
374
374
  }
375
375
  return lines;
376
376
  }
377
377
 
378
- private responseField(name: string, type: string, optional: boolean, body?: string): string {
378
+ private typeField(
379
+ name: string,
380
+ type: TypedocType | undefined,
381
+ optional: boolean,
382
+ body?: string
383
+ ): string {
384
+ const tokens = this.typeTokens(type);
385
+ const [only] = tokens;
386
+ const typeHref = tokens.length === 1 && only?.href ? `/${only.href}` : undefined;
387
+ const linked = typeHref ? undefined : this.linkedType(type);
388
+ const content = [linked && `**Type:** ${linked}`, body].filter(Boolean).join('\n\n');
389
+ return this.responseField(name, this.type(type), optional, content, typeHref);
390
+ }
391
+
392
+ private responseField(
393
+ name: string,
394
+ type: string,
395
+ optional: boolean,
396
+ body?: string,
397
+ typeHref?: string
398
+ ): string {
379
399
  const typeAttr = type ? ` type=${this.jsxString(truncate(type, 80))}` : '';
400
+ const typeHrefAttr = typeHref ? ` typeHref=${this.jsxString(typeHref)}` : '';
380
401
  const requiredAttr = optional ? '' : ' required';
381
- return `<ResponseField name=${this.jsxString(name)}${typeAttr}${requiredAttr}>\n${indent(body || '')}\n</ResponseField>`;
402
+ return `<ResponseField name=${this.jsxString(name)}${typeAttr}${typeHrefAttr}${requiredAttr}>\n${indent(body || '')}\n</ResponseField>`;
382
403
  }
383
404
 
384
405
  private jsxString(value: string): string {
@@ -435,56 +456,102 @@ class TypedocRenderer {
435
456
  }
436
457
 
437
458
  type(type?: TypedocType): string {
438
- if (!type) return 'void';
459
+ return this.typeTokens(type)
460
+ .map((token) => token.text)
461
+ .join('');
462
+ }
463
+
464
+ private linkedType(type?: TypedocType): string | undefined {
465
+ const tokens = this.typeTokens(type);
466
+ if (!tokens.some((token) => token.href)) return undefined;
467
+ const merged: TypeToken[] = [];
468
+ for (const token of tokens) {
469
+ const last = merged.at(-1);
470
+ if (last && !last.href && !token.href) last.text += token.text;
471
+ else merged.push({ ...token });
472
+ }
473
+ const children = merged
474
+ .map((token) => (token.href ? `[${token.text}](/${token.href})` : this.jsxString(token.text)))
475
+ .join('');
476
+ return `<code>${children}</code>`;
477
+ }
478
+
479
+ private typeTokens(type?: TypedocType): TypeToken[] {
480
+ if (!type) return [{ text: 'void' }];
439
481
  switch (type.type) {
440
482
  case 'intrinsic':
441
- return type.name ?? 'unknown';
483
+ return [{ text: type.name ?? 'unknown' }];
442
484
  case 'reference': {
443
- const args = type.typeArguments?.length
444
- ? `<${type.typeArguments.map((arg) => this.type(arg)).join(', ')}>`
445
- : '';
446
- return `${type.name ?? 'unknown'}${args}`;
485
+ const href = typeof type.target === 'number' ? this.slugById.get(type.target) : undefined;
486
+ const name: TypeToken = { text: type.name ?? 'unknown', href };
487
+ if (!type.typeArguments?.length) return [name];
488
+ return [name, { text: '<' }, ...this.joinTypes(type.typeArguments, ', '), { text: '>' }];
447
489
  }
448
490
  case 'union':
449
- return (type.types ?? []).map((entry) => this.type(entry)).join(' | ');
491
+ return this.joinTypes(type.types, ' | ');
450
492
  case 'intersection':
451
- return (type.types ?? []).map((entry) => this.type(entry)).join(' & ');
493
+ return this.joinTypes(type.types, ' & ');
452
494
  case 'array':
453
- return `${this.type(type.elementType)}[]`;
495
+ return [...this.typeTokens(type.elementType), { text: '[]' }];
454
496
  case 'literal':
455
- return JSON.stringify(type.value);
497
+ return [{ text: JSON.stringify(type.value) }];
456
498
  case 'tuple':
457
- return `[${(type.elements ?? []).map((entry) => this.type(entry)).join(', ')}]`;
499
+ return [{ text: '[' }, ...this.joinTypes(type.elements, ', '), { text: ']' }];
458
500
  case 'reflection':
459
501
  return this.reflection(type.declaration);
460
502
  case 'typeOperator':
461
- return `${type.operator} ${this.type(type.target as TypedocType)}`;
503
+ return [{ text: `${type.operator} ` }, ...this.typeTokens(type.target as TypedocType)];
462
504
  case 'indexedAccess':
463
- return `${this.type(type.objectType)}[${this.type(type.indexType)}]`;
505
+ return [
506
+ ...this.typeTokens(type.objectType),
507
+ { text: '[' },
508
+ ...this.typeTokens(type.indexType),
509
+ { text: ']' },
510
+ ];
464
511
  case 'conditional':
465
- return `${this.type(type.checkType)} extends ${this.type(type.extendsType)} ? ${this.type(type.trueType)} : ${this.type(type.falseType)}`;
512
+ return [
513
+ ...this.typeTokens(type.checkType),
514
+ { text: ' extends ' },
515
+ ...this.typeTokens(type.extendsType),
516
+ { text: ' ? ' },
517
+ ...this.typeTokens(type.trueType),
518
+ { text: ' : ' },
519
+ ...this.typeTokens(type.falseType),
520
+ ];
466
521
  case 'query':
467
- return `typeof ${this.type(type.target as TypedocType)}`;
522
+ return [{ text: 'typeof ' }, ...this.typeTokens(type.target as TypedocType)];
468
523
  case 'templateLiteral':
469
- return 'string';
524
+ return [{ text: 'string' }];
470
525
  default:
471
- return type.name ?? 'unknown';
526
+ return [{ text: type.name ?? 'unknown' }];
472
527
  }
473
528
  }
474
529
 
475
- private reflection(declaration?: TypedocNode): string {
476
- if (!declaration) return 'object';
477
- if (declaration.signatures?.length) {
478
- const signature = declaration.signatures[0]!;
479
- const params = (signature.parameters ?? [])
480
- .map((param) => `${param.name}: ${this.type(param.type)}`)
481
- .join(', ');
482
- return `(${params}) => ${this.type(signature.type)}`;
530
+ private joinTypes(types: TypedocType[] = [], separator: string): TypeToken[] {
531
+ return types.flatMap((entry, index) => [
532
+ ...(index > 0 ? [{ text: separator }] : []),
533
+ ...this.typeTokens(entry),
534
+ ]);
535
+ }
536
+
537
+ private reflection(declaration?: TypedocNode): TypeToken[] {
538
+ if (!declaration) return [{ text: 'object' }];
539
+ const signature = declaration.signatures?.[0];
540
+ if (signature) {
541
+ const params = (signature.parameters ?? []).flatMap((param, index) => [
542
+ { text: `${index > 0 ? ', ' : ''}${param.name}: ` },
543
+ ...this.typeTokens(param.type),
544
+ ]);
545
+ return [{ text: '(' }, ...params, { text: ') => ' }, ...this.typeTokens(signature.type)];
483
546
  }
484
547
  if (declaration.children?.length) {
485
- return `{ ${declaration.children.map((child) => `${child.name}: ${this.type(child.type)}`).join('; ')} }`;
548
+ const members = declaration.children.flatMap((child, index) => [
549
+ { text: `${index > 0 ? '; ' : ''}${child.name}: ` },
550
+ ...this.typeTokens(child.type),
551
+ ]);
552
+ return [{ text: '{ ' }, ...members, { text: ' }' }];
486
553
  }
487
- return 'object';
554
+ return [{ text: 'object' }];
488
555
  }
489
556
  }
490
557
 
@@ -499,6 +566,12 @@ function truncate(text: string, max: number): string {
499
566
  return text.length > max ? `${text.slice(0, max - 1)}…` : text;
500
567
  }
501
568
 
502
- function escapeInlineCode(text: string): string {
503
- return text.replace(/`/g, '');
569
+ function inlineCode(text: string): string {
570
+ const code = text.trim();
571
+ if (!code) return text;
572
+ const start = text.indexOf(code);
573
+ const longestRun = Math.max(0, ...(code.match(/`+/g) ?? []).map((run) => run.length));
574
+ const fence = '`'.repeat(longestRun + 1);
575
+ const pad = code.startsWith('`') || code.endsWith('`') ? ' ' : '';
576
+ return `${text.slice(0, start)}${fence}${pad}${code}${pad}${fence}${text.slice(start + code.length)}`;
504
577
  }