@mintlify/common 1.0.1284 → 1.0.1286

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,2 +1,3 @@
1
1
  export * from './parseGraphqlSelector.js';
2
+ export * from './pickGraphqlReferenceData.js';
2
3
  export * from './resolveGraphqlOperation.js';
@@ -1,2 +1,3 @@
1
1
  export * from './parseGraphqlSelector.js';
2
+ export * from './pickGraphqlReferenceData.js';
2
3
  export * from './resolveGraphqlOperation.js';
@@ -0,0 +1,2 @@
1
+ import type { GraphqlReferenceData } from '@mintlify/models';
2
+ export declare const pickGraphqlReferenceData: (data: GraphqlReferenceData) => GraphqlReferenceData;
@@ -0,0 +1,70 @@
1
+ import { getNamedGraphqlType, resolveGraphqlOperation } from './resolveGraphqlOperation.js';
2
+ const referencedTypeNames = (type) => {
3
+ const names = [];
4
+ if ('fields' in type) {
5
+ for (const field of type.fields) {
6
+ names.push(getNamedGraphqlType(field.type));
7
+ if ('arguments' in field) {
8
+ names.push(...field.arguments.map((arg) => getNamedGraphqlType(arg.type)));
9
+ }
10
+ }
11
+ }
12
+ if ('interfaces' in type)
13
+ names.push(...type.interfaces);
14
+ if ('possibleTypes' in type)
15
+ names.push(...type.possibleTypes);
16
+ return names;
17
+ };
18
+ const pickRoutes = (routes, names) => Object.fromEntries(Object.entries(routes).filter(([name]) => names.has(name)));
19
+ export const pickGraphqlReferenceData = (data) => {
20
+ var _a;
21
+ const { reference, target, routes } = data;
22
+ const typesByName = new Map(reference.types.map((type) => [type.name, type]));
23
+ if (target.kind === 'type') {
24
+ const type = typesByName.get(target.name);
25
+ if (!type)
26
+ return data;
27
+ return {
28
+ reference: Object.assign(Object.assign({}, reference), { types: [type] }),
29
+ target,
30
+ routes: pickRoutes(routes, new Set(referencedTypeNames(type))),
31
+ };
32
+ }
33
+ const resolved = resolveGraphqlOperation(reference, target);
34
+ if (!resolved)
35
+ return data;
36
+ const reachable = new Set();
37
+ const pending = [
38
+ getNamedGraphqlType(resolved.field.type),
39
+ ...[resolved.field, ...resolved.parents].flatMap((field) => field.arguments.map((arg) => getNamedGraphqlType(arg.type))),
40
+ ];
41
+ while (pending.length > 0) {
42
+ const name = pending.pop();
43
+ if (name === undefined || reachable.has(name))
44
+ continue;
45
+ reachable.add(name);
46
+ const type = typesByName.get(name);
47
+ if (type)
48
+ pending.push(...referencedTypeNames(type));
49
+ }
50
+ const pathFields = new Map();
51
+ let typeName = target.kind === 'query' ? reference.queryType : reference.mutationType;
52
+ for (const field of [...resolved.parents, resolved.field]) {
53
+ if (typeName !== undefined && !reachable.has(typeName)) {
54
+ pathFields.set(typeName, ((_a = pathFields.get(typeName)) !== null && _a !== void 0 ? _a : new Set()).add(field.name));
55
+ }
56
+ typeName = getNamedGraphqlType(field.type);
57
+ }
58
+ return {
59
+ reference: Object.assign(Object.assign({}, reference), { types: reference.types.flatMap((type) => {
60
+ if (reachable.has(type.name))
61
+ return [type];
62
+ const fields = pathFields.get(type.name);
63
+ if (!fields || !('fields' in type) || type.kind === 'input')
64
+ return [];
65
+ return [Object.assign(Object.assign({}, type), { fields: type.fields.filter(({ name }) => fields.has(name)) })];
66
+ }) }),
67
+ target,
68
+ routes: pickRoutes(routes, reachable),
69
+ };
70
+ };
@@ -55,9 +55,12 @@ function sanitizeNodes(nodes, source) {
55
55
  }
56
56
  return sanitized;
57
57
  }
58
+ const MARKDOWN_SYNTAX = /[\\&*_`[\]!<>~@\0\t\n\r]|:\/\/|www\.|\s$/i;
58
59
  export function parseTitleMarkdown(value) {
59
60
  if (!value)
60
61
  return [];
62
+ if (!MARKDOWN_SYNTAX.test(value))
63
+ return [{ type: 'text', value }];
61
64
  try {
62
65
  const prefix = 'title: ';
63
66
  const source = `${prefix}${value.replace(/\n/g, ' ')}`;