@mintlify/common 1.0.1085 → 1.0.1086

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/index.d.ts CHANGED
@@ -39,3 +39,4 @@ export * from './isAllowedRedirectUri.js';
39
39
  export * from './knownMcpClients.js';
40
40
  export * from './live-preview.js';
41
41
  export * from './paths/isEqualIgnoringLeadingSlash.js';
42
+ export * from './sdk/index.js';
package/dist/index.js CHANGED
@@ -39,3 +39,4 @@ export * from './isAllowedRedirectUri.js';
39
39
  export * from './knownMcpClients.js';
40
40
  export * from './live-preview.js';
41
41
  export * from './paths/isEqualIgnoringLeadingSlash.js';
42
+ export * from './sdk/index.js';
@@ -0,0 +1 @@
1
+ export { parseSdkString, potentiallyParseSdkString, parseSdkTargetFromMetadata, resolveSdkTarget, } from './parseSdkString.js';
@@ -0,0 +1 @@
1
+ export { parseSdkString, potentiallyParseSdkString, parseSdkTargetFromMetadata, resolveSdkTarget, } from './parseSdkString.js';
@@ -0,0 +1,13 @@
1
+ import type { ResolvedSdkTarget, SdkFormat, SdkTarget } from '@mintlify/models';
2
+ export declare const potentiallyParseSdkString: (str: string) => SdkTarget | undefined;
3
+ export declare const parseSdkString: (str: string) => SdkTarget;
4
+ export declare const parseSdkTargetFromMetadata: (metadata: {
5
+ sdk?: unknown;
6
+ }, inherited?: {
7
+ format?: SdkFormat;
8
+ source?: string;
9
+ }) => ResolvedSdkTarget | undefined;
10
+ export declare const resolveSdkTarget: (target: SdkTarget, inherited?: {
11
+ format?: SdkFormat;
12
+ source?: string;
13
+ }) => ResolvedSdkTarget | undefined;
@@ -0,0 +1,105 @@
1
+ import { SDK_FORMATS, SDK_SYMBOL_KINDS } from '@mintlify/models';
2
+ const MEMBER_KINDS = new Set(['method', 'property']);
3
+ function isSdkFormat(value) {
4
+ return SDK_FORMATS.includes(value);
5
+ }
6
+ function isSdkSymbolKind(value) {
7
+ return SDK_SYMBOL_KINDS.includes(value);
8
+ }
9
+ function parseQualifiedName(kind, rawName) {
10
+ if (!MEMBER_KINDS.has(kind) || !rawName.includes('.')) {
11
+ return { name: rawName };
12
+ }
13
+ const lastDot = rawName.lastIndexOf('.');
14
+ const parent = rawName.slice(0, lastDot);
15
+ const name = rawName.slice(lastDot + 1);
16
+ if (!parent || !name) {
17
+ throw new Error('improperly formatted sdk string');
18
+ }
19
+ return { name, parent };
20
+ }
21
+ export const potentiallyParseSdkString = (str) => {
22
+ try {
23
+ return parseSdkString(str);
24
+ }
25
+ catch (_a) {
26
+ return undefined;
27
+ }
28
+ };
29
+ export const parseSdkString = (str) => {
30
+ const components = str.trim().split(/\s+/);
31
+ if (components.length < 2 || components.length > 3) {
32
+ throw new Error('improperly formatted sdk string');
33
+ }
34
+ let source;
35
+ let kindRaw;
36
+ let nameRaw;
37
+ if (components.length === 3) {
38
+ const [sourcePart, kindPart, namePart] = components;
39
+ if (!sourcePart || !kindPart || !namePart) {
40
+ throw new Error('improperly formatted sdk string');
41
+ }
42
+ source = sourcePart;
43
+ kindRaw = kindPart;
44
+ nameRaw = namePart;
45
+ }
46
+ else {
47
+ const [kindPart, namePart] = components;
48
+ if (!kindPart || !namePart) {
49
+ throw new Error('improperly formatted sdk string');
50
+ }
51
+ kindRaw = kindPart;
52
+ nameRaw = namePart;
53
+ }
54
+ if (!isSdkSymbolKind(kindRaw)) {
55
+ throw new Error('invalid sdk symbol kind');
56
+ }
57
+ const { name, parent } = parseQualifiedName(kindRaw, nameRaw);
58
+ return Object.assign(Object.assign(Object.assign({}, (source ? { source } : {})), { kind: kindRaw, name }), (parent ? { parent } : {}));
59
+ };
60
+ function isRecord(value) {
61
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
62
+ }
63
+ export const parseSdkTargetFromMetadata = (metadata, inherited) => {
64
+ const raw = metadata.sdk;
65
+ if (raw === undefined || raw === null || raw === '')
66
+ return undefined;
67
+ let target;
68
+ if (typeof raw === 'string') {
69
+ try {
70
+ target = parseSdkString(raw);
71
+ }
72
+ catch (error) {
73
+ console.error(`unable to parse value "${raw}" for field "sdk":`, error);
74
+ return undefined;
75
+ }
76
+ }
77
+ else if (isRecord(raw)) {
78
+ const kind = raw.kind;
79
+ const name = raw.name;
80
+ if (typeof kind !== 'string' || !isSdkSymbolKind(kind) || typeof name !== 'string' || !name) {
81
+ return undefined;
82
+ }
83
+ const format = typeof raw.format === 'string' && isSdkFormat(raw.format) ? raw.format : undefined;
84
+ const source = typeof raw.source === 'string' && raw.source.length > 0 ? raw.source : undefined;
85
+ const parent = typeof raw.parent === 'string' && raw.parent.length > 0 ? raw.parent : undefined;
86
+ target = Object.assign(Object.assign(Object.assign(Object.assign({}, (format ? { format } : {})), (source ? { source } : {})), { kind,
87
+ name }), (parent ? { parent } : {}));
88
+ }
89
+ else {
90
+ return undefined;
91
+ }
92
+ return resolveSdkTarget(target, inherited);
93
+ };
94
+ export const resolveSdkTarget = (target, inherited) => {
95
+ var _a, _b;
96
+ const format = (_a = target.format) !== null && _a !== void 0 ? _a : inherited === null || inherited === void 0 ? void 0 : inherited.format;
97
+ const source = (_b = target.source) !== null && _b !== void 0 ? _b : inherited === null || inherited === void 0 ? void 0 : inherited.source;
98
+ if (!format || !source)
99
+ return undefined;
100
+ if (MEMBER_KINDS.has(target.kind) && !target.parent) {
101
+ return undefined;
102
+ }
103
+ return Object.assign({ format,
104
+ source, kind: target.kind, name: target.name }, (target.parent ? { parent: target.parent } : {}));
105
+ };