@stainless-api/docs-ui 0.1.0-beta.14 → 0.1.0-beta.15
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/breadcrumbs-Z-hEqjcp.d.ts +19 -0
- package/dist/chunk-Bp6m_JJh.js +13 -0
- package/dist/component-generics-DzI21jRn.js +35 -0
- package/dist/component-generics-q5Dqiu2D.d.ts +30 -0
- package/dist/components/breadcrumbs.d.ts +2 -0
- package/dist/components/breadcrumbs.js +16 -0
- package/dist/components/chat.d.ts +14 -0
- package/dist/components/chat.js +144 -0
- package/dist/components/dropdown.d.ts +2 -0
- package/dist/components/dropdown.js +4 -0
- package/dist/components/icons.d.ts +50 -0
- package/dist/components/icons.js +3 -0
- package/dist/components/index.d.ts +12 -0
- package/dist/components/index.js +16 -0
- package/dist/components/method.d.ts +2 -0
- package/dist/components/method.js +16 -0
- package/dist/components/overview.d.ts +2 -0
- package/dist/components/overview.js +16 -0
- package/dist/components/primitives.d.ts +2 -0
- package/dist/components/primitives.js +16 -0
- package/dist/components/properties.d.ts +2 -0
- package/dist/components/properties.js +16 -0
- package/dist/components/scripts/dropdown.d.ts +12 -0
- package/dist/components/scripts/dropdown.js +50 -0
- package/dist/components/sdk.d.ts +3 -0
- package/dist/components/sdk.js +16 -0
- package/dist/components/sidebar.d.ts +2 -0
- package/dist/components/sidebar.js +16 -0
- package/dist/components/snippets.d.ts +4 -0
- package/dist/components/snippets.js +16 -0
- package/dist/contexts/component-generics.d.ts +2 -0
- package/dist/contexts/component-generics.js +3 -0
- package/dist/contexts/component-types.d.ts +18 -0
- package/dist/contexts/component-types.js +1 -0
- package/dist/contexts/component.d.ts +31 -0
- package/dist/contexts/component.js +16 -0
- package/dist/contexts/docs.d.ts +2 -0
- package/dist/contexts/docs.js +3 -0
- package/dist/contexts/index.d.ts +20 -0
- package/dist/contexts/index.js +16 -0
- package/dist/contexts/markdown.d.ts +2 -0
- package/dist/contexts/markdown.js +4 -0
- package/dist/contexts/navigation.d.ts +3 -0
- package/dist/contexts/navigation.js +3 -0
- package/dist/contexts/search.d.ts +4 -0
- package/dist/contexts/search.js +16 -0
- package/dist/contexts/use-components.d.ts +16 -0
- package/dist/contexts/use-components.js +4 -0
- package/dist/contexts-DRxRO-xO.js +3747 -0
- package/dist/docs-Dh8kE1va.js +50 -0
- package/dist/docs-EUy-wfbA.d.ts +43 -0
- package/dist/dropdown-B7VyGMOw.d.ts +43 -0
- package/dist/dropdown-DtgAi6lb.js +62 -0
- package/dist/icons-DdKM-01E.js +753 -0
- package/dist/index-AicgPYKB.d.ts +239 -0
- package/dist/index-BhwLhiWk.d.ts +14 -0
- package/dist/index-YnpUtXLB.d.ts +16 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +5276 -5873
- package/dist/languages/go.d.ts +13 -0
- package/dist/languages/go.js +16 -0
- package/dist/languages/http.d.ts +13 -0
- package/dist/languages/http.js +16 -0
- package/dist/languages/index.d.ts +13 -0
- package/dist/languages/index.js +16 -0
- package/dist/languages/java.d.ts +13 -0
- package/dist/languages/java.js +16 -0
- package/dist/languages/python.d.ts +13 -0
- package/dist/languages/python.js +16 -0
- package/dist/languages/ruby.d.ts +13 -0
- package/dist/languages/ruby.js +16 -0
- package/dist/languages/typescript.d.ts +13 -0
- package/dist/languages/typescript.js +16 -0
- package/dist/markdown/index.d.ts +11 -0
- package/dist/markdown/index.js +16 -0
- package/dist/markdown/md.d.ts +15 -0
- package/dist/markdown/md.js +3 -0
- package/dist/markdown/utils.d.ts +4 -0
- package/dist/markdown/utils.js +3 -0
- package/dist/markdown-BXfX1D7C.js +42 -0
- package/dist/markdown-nFyAEX_K.d.ts +22 -0
- package/dist/mcp.js +1720 -2298
- package/dist/md-Dg8aOyMA.js +41 -0
- package/dist/method-DpsVuzZW.d.ts +71 -0
- package/dist/navigation-aoYZ_tl4.js +24 -0
- package/dist/navigation-nyXBY-75.d.ts +29 -0
- package/dist/overview-C8e-6jGr.d.ts +38 -0
- package/dist/pagefind-ChrPfuVv.js +15 -0
- package/dist/primitives-DWz23_Ub.d.ts +99 -0
- package/dist/properties-CF71V58d.d.ts +46 -0
- package/dist/routing-DQjbRxdJ.js +189 -0
- package/dist/routing-qc0V00-j.d.ts +51 -0
- package/dist/routing.d.ts +2 -0
- package/dist/sdk-Zg3Rggk3.d.ts +118 -0
- package/dist/search/index.d.ts +26 -0
- package/dist/search/index.js +332 -0
- package/dist/search/providers/algolia.d.ts +23 -0
- package/dist/search/providers/algolia.js +16 -0
- package/dist/search/providers/fuse.d.ts +17 -0
- package/dist/search/providers/fuse.js +31 -0
- package/dist/search/providers/pagefind.d.ts +7 -0
- package/dist/search/providers/pagefind.js +3 -0
- package/dist/search/providers/walker.d.ts +8 -0
- package/dist/search/providers/walker.js +32 -0
- package/dist/search/types.d.ts +3 -0
- package/dist/search/types.js +3 -0
- package/dist/search-B6loAGmB.d.ts +21 -0
- package/dist/sidebar-C8KirYjg.d.ts +35 -0
- package/dist/snippets-EUzM4fRO.d.ts +45 -0
- package/dist/style-pN9hCoec.d.ts +181 -0
- package/dist/style-rYbbxIR_.js +182 -0
- package/dist/style.d.ts +2 -0
- package/dist/style.js +3 -0
- package/dist/styles/main.css +742 -748
- package/dist/styles/primitives.css +435 -428
- package/dist/styles/resets.css +33 -41
- package/dist/styles/search.css +247 -248
- package/dist/styles/sidebar.css +58 -60
- package/dist/styles/snippets.css +86 -88
- package/dist/styles/variables.css +86 -90
- package/dist/types-CTBDtD34.d.ts +82 -0
- package/dist/types-DFN4M1Sp.js +34 -0
- package/dist/use-components-D9E85p5x.js +7 -0
- package/dist/utils-BHwvUDKn.js +30 -0
- package/dist/utils-CJfFBNgT.js +32 -0
- package/dist/utils-DQhEbvUC.d.ts +20 -0
- package/dist/utils-nDazhti8.d.ts +11 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +4 -0
- package/package.json +13 -7
- package/src/components/breadcrumbs.tsx +1 -1
- package/src/components/chat.tsx +18 -15
- package/src/components/method.tsx +8 -9
- package/src/components/overview.tsx +26 -12
- package/src/components/primitives.tsx +36 -19
- package/src/components/properties.tsx +4 -2
- package/src/components/scripts/dropdown.ts +1 -1
- package/src/components/sdk.tsx +25 -20
- package/src/components/sidebar.tsx +3 -3
- package/src/components/snippets.tsx +26 -9
- package/src/contexts/component-generics.tsx +10 -15
- package/src/contexts/docs.tsx +15 -4
- package/src/contexts/index.tsx +8 -5
- package/src/contexts/markdown.tsx +7 -6
- package/src/contexts/search.tsx +4 -5
- package/src/hooks/use-strict-context.tsx +16 -0
- package/src/languages/go.tsx +3 -3
- package/src/languages/http.tsx +31 -23
- package/src/languages/index.ts +7 -7
- package/src/languages/java.tsx +4 -4
- package/src/languages/python.tsx +12 -9
- package/src/languages/ruby.tsx +20 -13
- package/src/languages/typescript.tsx +18 -12
- package/src/markdown/index.ts +17 -12
- package/src/markdown/utils.ts +6 -3
- package/src/routing.ts +9 -9
- package/src/search/form.tsx +26 -24
- package/src/search/indexer.ts +17 -15
- package/src/search/mcp.ts +8 -8
- package/src/search/printer.tsx +1 -1
- package/src/search/providers/algolia.ts +5 -5
- package/src/search/providers/fuse.ts +4 -4
- package/src/search/providers/pagefind.ts +1 -1
- package/src/search/providers/walker.ts +5 -3
- package/src/search/results.tsx +7 -6
- package/src/search/types.ts +2 -2
- package/src/styles/main.css +2 -1
- package/src/utils.ts +9 -8
|
@@ -4,7 +4,7 @@ import { useDeclaration, useHighlight, useLanguage, useSnippet } from '../contex
|
|
|
4
4
|
import { useComponents } from '../contexts/use-components';
|
|
5
5
|
import style from '../style';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
|
-
import type * as SDKJSON from '
|
|
7
|
+
import type * as SDKJSON from '@stainless/sdk-json';
|
|
8
8
|
import type { TransformRequestSnippetFn } from './sdk';
|
|
9
9
|
import { Button } from '@stainless-api/ui-primitives';
|
|
10
10
|
|
|
@@ -59,15 +59,24 @@ export function Snippet({ requestTitle, method, transformRequestSnippet }: Snipp
|
|
|
59
59
|
const language = useLanguage();
|
|
60
60
|
const [CopyButtonIcon, setCopyIcon] = React.useState<LucideIcon>(CopyIcon);
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const originalSnippet = useSnippet(
|
|
63
|
+
method.stainlessPath,
|
|
64
|
+
undefined,
|
|
65
|
+
language === 'http' ? 'curl' : 'default',
|
|
66
|
+
);
|
|
67
|
+
const decl = useDeclaration(method.stainlessPath, false);
|
|
68
|
+
|
|
69
|
+
if (!originalSnippet) {
|
|
70
|
+
console.warn(`Snippet not found for method '${method.stainlessPath}'`);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
64
73
|
|
|
65
|
-
const signature = 'qualified' in decl ? decl.qualified : undefined;
|
|
74
|
+
const signature = decl && 'qualified' in decl ? decl.qualified : undefined;
|
|
66
75
|
const responses = method.exampleResponses;
|
|
67
76
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
const snippet = transformRequestSnippet
|
|
78
|
+
? transformRequestSnippet({ snippet: originalSnippet, language })
|
|
79
|
+
: originalSnippet;
|
|
71
80
|
|
|
72
81
|
async function handleCopy() {
|
|
73
82
|
try {
|
|
@@ -113,9 +122,15 @@ export function SnippetResponse({ responses }: { responses: SDKJSON.Method['exam
|
|
|
113
122
|
|
|
114
123
|
const mappedResponses = Object.keys(responses)
|
|
115
124
|
.map((key) => {
|
|
125
|
+
const responseContent = responses[key];
|
|
126
|
+
if (!responseContent) return null;
|
|
127
|
+
|
|
116
128
|
// Get the first response type ie application/json or text/plain
|
|
117
|
-
const responseType = Object.keys(
|
|
118
|
-
|
|
129
|
+
const responseType = Object.keys(responseContent)[0];
|
|
130
|
+
if (!responseType) return null;
|
|
131
|
+
|
|
132
|
+
const response = responseContent[responseType];
|
|
133
|
+
if (!response) return null;
|
|
119
134
|
|
|
120
135
|
const examples = response?.examples;
|
|
121
136
|
|
|
@@ -123,6 +138,8 @@ export function SnippetResponse({ responses }: { responses: SDKJSON.Method['exam
|
|
|
123
138
|
|
|
124
139
|
// Get the first example type, ie Example or html
|
|
125
140
|
const exampleType = Object.keys(examples)[0];
|
|
141
|
+
if (!exampleType) return null;
|
|
142
|
+
|
|
126
143
|
let value = examples[exampleType]?.value;
|
|
127
144
|
|
|
128
145
|
if (!value) return null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// This file should never import from ../components or ../languages to avoid circular dependencies
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
import { createStrictContext } from '../hooks/use-strict-context';
|
|
4
5
|
|
|
5
6
|
type DeepPartialMap<L> = { [K in keyof L]?: Partial<L[K]> };
|
|
6
7
|
|
|
@@ -9,13 +10,10 @@ export type ComponentsContextType<C, L> = {
|
|
|
9
10
|
language: L;
|
|
10
11
|
};
|
|
11
12
|
|
|
12
|
-
const
|
|
13
|
-
ComponentContext.displayName = 'ComponentContext';
|
|
13
|
+
const [Provider, useComponentContext] = createStrictContext<ComponentsContextType<any, any>>('Component');
|
|
14
14
|
|
|
15
|
-
export function useComponents<C = unknown>() {
|
|
16
|
-
|
|
17
|
-
if (!ctx) throw new Error('useComponents must be used within a ComponentContext.Provider');
|
|
18
|
-
return ctx.components as C;
|
|
15
|
+
export function useComponents<C = unknown>(): C {
|
|
16
|
+
return useComponentContext().components as C;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
export function customizeComponents<C, L>(
|
|
@@ -24,13 +22,10 @@ export function customizeComponents<C, L>(
|
|
|
24
22
|
): { components: C; language: L } {
|
|
25
23
|
const mergedComponents = { ...defaults.components, ...(overrides.components ?? {}) } as C;
|
|
26
24
|
|
|
27
|
-
const mergedLanguage = Object.keys(defaults.language as Record<string, unknown>).reduce(
|
|
28
|
-
(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
{} as any as L,
|
|
33
|
-
);
|
|
25
|
+
const mergedLanguage = Object.keys(defaults.language as Record<string, unknown>).reduce((acc, key) => {
|
|
26
|
+
acc[key] = { ...(defaults.language as any)[key], ...((overrides.language as any)?.[key] ?? {}) };
|
|
27
|
+
return acc;
|
|
28
|
+
}, {} as any);
|
|
34
29
|
|
|
35
30
|
return { components: mergedComponents, language: mergedLanguage };
|
|
36
31
|
}
|
|
@@ -42,7 +37,7 @@ export function ComponentProvider<C, L>({
|
|
|
42
37
|
value: ComponentsContextType<C, L>;
|
|
43
38
|
children: React.ReactNode;
|
|
44
39
|
}) {
|
|
45
|
-
return <
|
|
40
|
+
return <Provider value={value}>{children}</Provider>;
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
export {
|
|
43
|
+
export { useComponentContext };
|
package/src/contexts/docs.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { Spec, SpecLanguage } from '
|
|
2
|
+
import type { LanguageDeclNodes, SnippetLanguage, Spec, SpecLanguage } from '@stainless/sdk-json';
|
|
3
3
|
|
|
4
4
|
export type ContentPanelLayout = 'double-pane' | 'single-pane';
|
|
5
5
|
export type PropertySettingsType = {
|
|
@@ -40,13 +40,24 @@ export function useSettings() {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export function useSnippet(stainlessPath: string, language?: SpecLanguage, variant?: string) {
|
|
43
|
-
const
|
|
43
|
+
const defaultLanguage = useLanguage();
|
|
44
|
+
const snippetLanguage = [language ?? defaultLanguage, variant ?? 'default'].join('.') as SnippetLanguage;
|
|
44
45
|
|
|
45
46
|
return useSpec()?.snippets?.[snippetLanguage]?.[stainlessPath];
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
type Declaration = LanguageDeclNodes[SpecLanguage];
|
|
50
|
+
export function useDeclaration<Required extends boolean>(
|
|
51
|
+
stainlessPath: string,
|
|
52
|
+
required: Required,
|
|
53
|
+
language?: SpecLanguage,
|
|
54
|
+
): (Required extends true ? never : undefined) | Declaration {
|
|
55
|
+
const defaultLanguage = useLanguage();
|
|
56
|
+
const decl = useSpec()?.decls?.[language ?? defaultLanguage]?.[stainlessPath];
|
|
57
|
+
if (required && !decl) {
|
|
58
|
+
throw new Error(`Declaration not found for '${stainlessPath}'`);
|
|
59
|
+
}
|
|
60
|
+
return decl!;
|
|
50
61
|
}
|
|
51
62
|
|
|
52
63
|
export function useResource(name: string) {
|
package/src/contexts/index.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { ComponentContext } from './component-generics';
|
|
3
1
|
import { useLanguage } from './docs';
|
|
4
2
|
import { LanguageComponentDefinition } from '../languages';
|
|
3
|
+
import { useComponentContext } from './component-generics';
|
|
5
4
|
|
|
6
5
|
// DO NOT re-export component contexts from here. Only export generics.
|
|
7
6
|
export * from './navigation';
|
|
@@ -10,8 +9,12 @@ export * from './component-generics';
|
|
|
10
9
|
export * from './search';
|
|
11
10
|
export * from './docs';
|
|
12
11
|
|
|
13
|
-
export function useLanguageComponents() {
|
|
12
|
+
export function useLanguageComponents(): LanguageComponentDefinition {
|
|
14
13
|
const language = useLanguage();
|
|
15
|
-
const context =
|
|
16
|
-
|
|
14
|
+
const context = useComponentContext();
|
|
15
|
+
const definition = context.language[language];
|
|
16
|
+
if (!definition) {
|
|
17
|
+
throw new Error(`Language component definition not found for language: ${language}`);
|
|
18
|
+
}
|
|
19
|
+
return definition;
|
|
17
20
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useLanguage } from './docs';
|
|
3
3
|
|
|
4
|
-
const HighlightLanguageMappings = {
|
|
4
|
+
const HighlightLanguageMappings: Record<string, string> = {
|
|
5
5
|
node: 'typescript',
|
|
6
6
|
http: 'bash',
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export type MarkdownContext = {
|
|
10
|
-
highlight
|
|
11
|
-
render
|
|
10
|
+
highlight: (content: string, language: string) => string | Promise<string>;
|
|
11
|
+
render: (content: string) => string;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export const MarkdownContext = React.createContext<MarkdownContext>({
|
|
@@ -23,15 +23,16 @@ export function useRenderMarkdown(content?: string) {
|
|
|
23
23
|
return React.useMemo(() => (content ? render(content) : undefined), [content, render]);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function useHighlight(content
|
|
26
|
+
export function useHighlight(content: string, language?: string) {
|
|
27
27
|
const { highlight } = React.useContext(MarkdownContext);
|
|
28
|
-
const
|
|
28
|
+
const defaultLanguage = useLanguage();
|
|
29
|
+
const lang = language ?? defaultLanguage;
|
|
29
30
|
|
|
30
31
|
return React.useMemo(() => {
|
|
31
32
|
const highlightLanguage = HighlightLanguageMappings[lang] ?? lang;
|
|
32
33
|
const rendered = highlight(content, highlightLanguage);
|
|
33
34
|
return typeof rendered === 'string' ? rendered : React.use(rendered);
|
|
34
|
-
}, [content,
|
|
35
|
+
}, [content, highlight, lang]);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export type MarkdownProviderProps = MarkdownContext & {
|
package/src/contexts/search.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { createStrictContext } from '../hooks/use-strict-context';
|
|
2
3
|
import { search } from '../search/providers/algolia';
|
|
3
4
|
import { SearchParams, SearchSettings } from '../search/types';
|
|
4
5
|
|
|
@@ -8,11 +9,9 @@ export type SearchContextType = {
|
|
|
8
9
|
pageFind?: string;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
const
|
|
12
|
+
const [Provider, useSearchContext] = createStrictContext<SearchContextType>('SearchContext');
|
|
12
13
|
|
|
13
|
-
export
|
|
14
|
-
return React.useContext(SearchContext);
|
|
15
|
-
}
|
|
14
|
+
export { useSearchContext };
|
|
16
15
|
|
|
17
16
|
export function useSearch() {
|
|
18
17
|
const { settings } = useSearchContext();
|
|
@@ -24,5 +23,5 @@ export type SearchProviderProps = SearchContextType & {
|
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
export function SearchProvider({ children, ...props }: SearchProviderProps) {
|
|
27
|
-
return <
|
|
26
|
+
return <Provider value={props}>{children}</Provider>;
|
|
28
27
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export function createStrictContext<T>(displayName: string) {
|
|
4
|
+
const Context = React.createContext<T | null>(null);
|
|
5
|
+
Context.displayName = displayName;
|
|
6
|
+
|
|
7
|
+
function useStrictContext(): T {
|
|
8
|
+
const context = React.useContext(Context);
|
|
9
|
+
if (context === null) {
|
|
10
|
+
throw new Error(`use${displayName} must be used within a ${displayName}Provider`);
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return [Context.Provider, useStrictContext] as const;
|
|
16
|
+
}
|
package/src/languages/go.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { GoAST as AST } from '@stainless/sdk-json';
|
|
3
3
|
|
|
4
4
|
import { useComponents } from '../contexts/use-components';
|
|
5
5
|
import { useLanguageComponents } from '../contexts';
|
|
@@ -43,7 +43,7 @@ export function Type({ type }: TypeProps) {
|
|
|
43
43
|
|
|
44
44
|
return (
|
|
45
45
|
<span className={style.Type}>
|
|
46
|
-
<SDKReference stainlessPath={type.$ref}>{type.typeName}</SDKReference>
|
|
46
|
+
{type.$ref ? <SDKReference stainlessPath={type.$ref}>{type.typeName}</SDKReference> : type.typeName}
|
|
47
47
|
{params && params.length > 0 ? (
|
|
48
48
|
<>
|
|
49
49
|
<span className={style.TypeBracket}>{'['}</span>
|
|
@@ -179,7 +179,7 @@ export function MethodSignature({ decl }: MethodSignatureProps) {
|
|
|
179
179
|
|
|
180
180
|
export type PropertyProps = {
|
|
181
181
|
decl: AST.GoDeclaration;
|
|
182
|
-
children
|
|
182
|
+
children: PropertyFn;
|
|
183
183
|
};
|
|
184
184
|
|
|
185
185
|
export function Property({ decl, children }: PropertyProps) {
|
package/src/languages/http.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { HttpAST as AST } from '@stainless/sdk-json';
|
|
2
2
|
import { useDeclaration, useLanguage, useLanguageComponents, useSpec } from '../contexts';
|
|
3
3
|
import { useComponents } from '../contexts/use-components';
|
|
4
4
|
import style from '../style';
|
|
@@ -11,7 +11,7 @@ const ComplexTypes: Partial<Record<AST.HttpType['kind'], string>> = {
|
|
|
11
11
|
HttpTypeIntersection: 'intersection',
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const constStyle = {
|
|
14
|
+
const constStyle: Record<string, string> = {
|
|
15
15
|
string: style.LiteralString,
|
|
16
16
|
number: style.LiteralNumeric,
|
|
17
17
|
boolean: style.LiteralBoolean,
|
|
@@ -34,17 +34,23 @@ function Identifier({ name }: { name: string }) {
|
|
|
34
34
|
function TypePreview({ path }: { path: string }) {
|
|
35
35
|
const spec = useSpec();
|
|
36
36
|
const language = useLanguage();
|
|
37
|
-
const decl = useDeclaration(path);
|
|
37
|
+
const decl = useDeclaration(path, false);
|
|
38
38
|
const { Join } = useComponents();
|
|
39
39
|
|
|
40
|
-
if (
|
|
40
|
+
if (
|
|
41
|
+
!(decl && 'children' in decl && decl.children && decl.children.length > 0) ||
|
|
42
|
+
('type' in decl && decl['type'] && 'kind' in decl['type'] && decl['type']['kind'] === 'HttpTypeUnion')
|
|
43
|
+
)
|
|
41
44
|
return;
|
|
42
45
|
|
|
43
|
-
const items = decl.children.map((prop, key) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const items = decl.children.map((prop, key) => {
|
|
47
|
+
const decl = spec?.decls?.[language]?.[prop];
|
|
48
|
+
return (
|
|
49
|
+
<span key={key} className={style.TypePropertyName}>
|
|
50
|
+
<span className={style.TextIdentifier}>{decl && 'key' in decl ? decl?.['key'] : null}</span>
|
|
51
|
+
</span>
|
|
52
|
+
);
|
|
53
|
+
});
|
|
48
54
|
|
|
49
55
|
return (
|
|
50
56
|
<span className={style.TypePreview} data-stldocs-type-preview="properties">
|
|
@@ -138,7 +144,7 @@ export function Type({ type }: TypeProps) {
|
|
|
138
144
|
if (
|
|
139
145
|
name === 'Record' &&
|
|
140
146
|
type.typeParameters?.length === 2 &&
|
|
141
|
-
type.typeParameters?.at(0)
|
|
147
|
+
type.typeParameters?.at(0)!.kind === 'HttpTypeString'
|
|
142
148
|
)
|
|
143
149
|
return (
|
|
144
150
|
<>
|
|
@@ -148,7 +154,7 @@ export function Type({ type }: TypeProps) {
|
|
|
148
154
|
|
|
149
155
|
return (
|
|
150
156
|
<span className={style.Type}>
|
|
151
|
-
<SDKReference stainlessPath={type.$ref}>{name}</SDKReference>
|
|
157
|
+
<SDKReference stainlessPath={type.$ref!}>{name}</SDKReference>
|
|
152
158
|
{params && params.length > 0 && (
|
|
153
159
|
<>
|
|
154
160
|
<span className={style.TypeBracket}>{'<'}</span>
|
|
@@ -158,14 +164,14 @@ export function Type({ type }: TypeProps) {
|
|
|
158
164
|
<span className={style.TypeBracket}>{'>'}</span>
|
|
159
165
|
</>
|
|
160
166
|
)}
|
|
161
|
-
<TypePreview path={type.$ref} />
|
|
167
|
+
<TypePreview path={type.$ref!} />
|
|
162
168
|
</span>
|
|
163
169
|
);
|
|
164
170
|
}
|
|
165
171
|
|
|
166
|
-
case 'HttpTypeObject':
|
|
172
|
+
case 'HttpTypeObject': {
|
|
167
173
|
const items = type.members.map(({ ident }) => (
|
|
168
|
-
<span className={style.TypePropertyName}>
|
|
174
|
+
<span className={style.TypePropertyName} key={ident}>
|
|
169
175
|
<Identifier name={ident} />
|
|
170
176
|
</span>
|
|
171
177
|
));
|
|
@@ -185,6 +191,7 @@ export function Type({ type }: TypeProps) {
|
|
|
185
191
|
</span>
|
|
186
192
|
</span>
|
|
187
193
|
);
|
|
194
|
+
}
|
|
188
195
|
}
|
|
189
196
|
}
|
|
190
197
|
|
|
@@ -193,28 +200,29 @@ export type MethodSignatureProps = {
|
|
|
193
200
|
};
|
|
194
201
|
|
|
195
202
|
export function MethodSignature({ decl }: MethodSignatureProps) {
|
|
203
|
+
void decl;
|
|
196
204
|
return null;
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
export function MethodInfo({ decl, children }: MethodSignatureProps & { children: React.ReactNode }) {
|
|
200
208
|
const Docs = useComponents();
|
|
201
209
|
|
|
202
|
-
const params = Object.entries(decl.paramsChildren)
|
|
203
|
-
.filter(([
|
|
210
|
+
const params = Object.entries(decl.paramsChildren!)
|
|
211
|
+
.filter(([, value]) => value.length)
|
|
204
212
|
.map(([location, value]) => (
|
|
205
213
|
<React.Fragment key={location}>
|
|
206
214
|
<div className={style.MethodParameters} data-stldocs-property-group={location.at(0)}>
|
|
207
215
|
<h5>
|
|
208
|
-
{location.at(0)
|
|
216
|
+
{location.at(0)!.toUpperCase()}
|
|
209
217
|
{location.slice(1)} Parameters
|
|
210
|
-
<PropertyToggle target={location.at(0)} />
|
|
218
|
+
<PropertyToggle target={location.at(0)!} />
|
|
211
219
|
</h5>
|
|
212
220
|
<Docs.SDKChildren paths={value} />
|
|
213
221
|
</div>
|
|
214
222
|
</React.Fragment>
|
|
215
223
|
));
|
|
216
224
|
|
|
217
|
-
if (decl.bodyParamsChildren?.['application/json']?.length > 0)
|
|
225
|
+
if ((decl.bodyParamsChildren?.['application/json']?.length ?? 0) > 0)
|
|
218
226
|
params.push(
|
|
219
227
|
<div className={style.MethodInfoSection}>
|
|
220
228
|
<h5>
|
|
@@ -222,7 +230,7 @@ export function MethodInfo({ decl, children }: MethodSignatureProps & { children
|
|
|
222
230
|
<PropertyToggle target="body" />
|
|
223
231
|
</h5>
|
|
224
232
|
<div className={style.MethodParameters} data-stldocs-property-group="body">
|
|
225
|
-
<Docs.SDKChildren paths={decl.bodyParamsChildren?.['application/json']} />
|
|
233
|
+
<Docs.SDKChildren paths={decl.bodyParamsChildren?.['application/json'] ?? []} />
|
|
226
234
|
</div>
|
|
227
235
|
</div>,
|
|
228
236
|
);
|
|
@@ -231,14 +239,14 @@ export function MethodInfo({ decl, children }: MethodSignatureProps & { children
|
|
|
231
239
|
<div className={style.MethodInfo}>
|
|
232
240
|
{children && <div className={style.MethodContent}>{children}</div>}
|
|
233
241
|
{params.length > 0 && params}
|
|
234
|
-
{decl.responseChildren
|
|
242
|
+
{(decl.responseChildren?.length ?? 0) > 0 && (
|
|
235
243
|
<div className={style.MethodInfoSection}>
|
|
236
244
|
<h5>
|
|
237
245
|
Returns
|
|
238
246
|
<PropertyToggle target="returns" />
|
|
239
247
|
</h5>
|
|
240
248
|
<div className={style.MethodReturns} data-stldocs-property-group="returns">
|
|
241
|
-
<Docs.SDKChildren paths={decl.responseChildren} />
|
|
249
|
+
<Docs.SDKChildren paths={decl.responseChildren ?? []} />
|
|
242
250
|
</div>
|
|
243
251
|
</div>
|
|
244
252
|
)}
|
|
@@ -256,7 +264,7 @@ function renderVariantInfo(type: AST.HttpType) {
|
|
|
256
264
|
|
|
257
265
|
export type PropertyProps = {
|
|
258
266
|
decl: AST.HttpDeclaration;
|
|
259
|
-
children
|
|
267
|
+
children: PropertyFn;
|
|
260
268
|
};
|
|
261
269
|
|
|
262
270
|
export function Property({ decl, children }: PropertyProps) {
|
package/src/languages/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import type { DeclarationNode, Type } from '
|
|
2
|
+
import type { DeclarationNode, Type } from '@stainless/sdk-json';
|
|
3
3
|
|
|
4
4
|
import * as typescript from './typescript';
|
|
5
5
|
import * as java from './java';
|
|
@@ -17,10 +17,10 @@ export const kotlin = java;
|
|
|
17
17
|
export type PropertyFn = (params: PropertyProps) => ReactNode;
|
|
18
18
|
|
|
19
19
|
export interface LanguageComponentDefinition {
|
|
20
|
-
Declaration(props: { decl: DeclarationNode });
|
|
21
|
-
Property(props: { decl: DeclarationNode; children: PropertyFn });
|
|
22
|
-
TypeName(props: { type: Type; optional?: boolean });
|
|
23
|
-
Type(props: { type: Type; optional?: boolean });
|
|
24
|
-
MethodSignature(props: { decl: DeclarationNode });
|
|
25
|
-
MethodInfo?(props: { decl: DeclarationNode; children?: ReactNode });
|
|
20
|
+
Declaration(props: { decl: DeclarationNode }): ReactNode;
|
|
21
|
+
Property(props: { decl: DeclarationNode; children: PropertyFn }): ReactNode;
|
|
22
|
+
TypeName(props: { type: Type; optional?: boolean }): ReactNode;
|
|
23
|
+
Type(props: { type: Type; optional?: boolean }): ReactNode;
|
|
24
|
+
MethodSignature(props: { decl: DeclarationNode }): ReactNode;
|
|
25
|
+
MethodInfo?(props: { decl: DeclarationNode; children?: ReactNode }): ReactNode;
|
|
26
26
|
}
|
package/src/languages/java.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { JavaAST as AST } from '@stainless/sdk-json';
|
|
3
3
|
|
|
4
4
|
import { useLanguage, useLanguageComponents } from '../contexts';
|
|
5
5
|
import { useComponents } from '../contexts/use-components';
|
|
@@ -13,7 +13,7 @@ function showFullType(type: AST.JavaType) {
|
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const constStyle = {
|
|
16
|
+
const constStyle: Record<string, string> = {
|
|
17
17
|
string: style.LiteralString,
|
|
18
18
|
number: style.LiteralNumeric,
|
|
19
19
|
boolean: style.LiteralBoolean,
|
|
@@ -46,7 +46,7 @@ export function Type({ type, optional }: TypeProps) {
|
|
|
46
46
|
|
|
47
47
|
return (
|
|
48
48
|
<span className={style.Type}>
|
|
49
|
-
<SDKReference stainlessPath={type.$ref}>{name}</SDKReference>
|
|
49
|
+
<SDKReference stainlessPath={type.$ref!}>{name}</SDKReference>
|
|
50
50
|
{params && params.length > 0 ? (
|
|
51
51
|
<>
|
|
52
52
|
<span className={style.TypeBracket}>{'<'}</span>
|
|
@@ -186,7 +186,7 @@ export function MethodSignature({ decl }: MethodSignatureProps) {
|
|
|
186
186
|
|
|
187
187
|
export type PropertyProps = {
|
|
188
188
|
decl: AST.JavaDeclaration;
|
|
189
|
-
children
|
|
189
|
+
children: PropertyFn;
|
|
190
190
|
};
|
|
191
191
|
|
|
192
192
|
export function Property({ decl, children }: PropertyProps) {
|
package/src/languages/python.tsx
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { PythonAST as AST } from '@stainless/sdk-json';
|
|
3
3
|
import { useLanguageComponents } from '../contexts';
|
|
4
4
|
import { useComponents } from '../contexts/use-components';
|
|
5
5
|
import style from '../style';
|
|
6
6
|
import { PropertyFn } from '.';
|
|
7
7
|
|
|
8
|
-
const constStyle = {
|
|
8
|
+
const constStyle: Record<string, string> = {
|
|
9
9
|
string: style.LiteralString,
|
|
10
10
|
number: style.LiteralNumeric,
|
|
11
11
|
boolean: style.LiteralBoolean,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
function showFullType(type: AST.PythonType) {
|
|
14
|
+
function showFullType(type: AST.PythonType): boolean {
|
|
15
15
|
if (type.kind !== 'PythonTypeReference') return false;
|
|
16
|
-
return type.typeName === 'Optional'
|
|
16
|
+
return type.typeName === 'Optional'
|
|
17
|
+
? showFullType(type.typeParameters![0]!)
|
|
18
|
+
: type.typeParameters!.length > 0;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
type TypeProps = {
|
|
@@ -26,7 +28,7 @@ export function TypeName({ type }: TypeProps) {
|
|
|
26
28
|
if (type.kind === 'PythonTypeReference') {
|
|
27
29
|
switch (type.typeName) {
|
|
28
30
|
case 'Optional':
|
|
29
|
-
return <Lang.TypeName type={type.typeParameters[0]} />;
|
|
31
|
+
return <Lang.TypeName type={type.typeParameters![0]!} />;
|
|
30
32
|
case 'List':
|
|
31
33
|
case 'Iterable':
|
|
32
34
|
case 'Literal':
|
|
@@ -64,7 +66,7 @@ export function Type({ type }: TypeProps) {
|
|
|
64
66
|
case 'PythonTypeLiteral':
|
|
65
67
|
return (
|
|
66
68
|
<span className={style.Type}>
|
|
67
|
-
<span className={constStyle[typeof type.literal.value]}>{JSON.stringify(type.literal.value)}</span>
|
|
69
|
+
<span className={constStyle[typeof type.literal.value]!}>{JSON.stringify(type.literal.value)}</span>
|
|
68
70
|
</span>
|
|
69
71
|
);
|
|
70
72
|
|
|
@@ -97,7 +99,7 @@ export function Type({ type }: TypeProps) {
|
|
|
97
99
|
return (
|
|
98
100
|
<span className={style.Type}>
|
|
99
101
|
<span className={type.typeName === 'Optional' ? style.TypeArray : ''}>
|
|
100
|
-
<SDKReference stainlessPath={type.$ref}>{type.typeName}</SDKReference>
|
|
102
|
+
<SDKReference stainlessPath={type.$ref!}>{type.typeName}</SDKReference>
|
|
101
103
|
</span>
|
|
102
104
|
{params && params.length > 0 && (
|
|
103
105
|
<>
|
|
@@ -166,7 +168,7 @@ export function MethodSignature({ decl }: MethodSignatureProps) {
|
|
|
166
168
|
|
|
167
169
|
export type PropertyProps = {
|
|
168
170
|
decl: AST.PythonDeclaration;
|
|
169
|
-
children
|
|
171
|
+
children: PropertyFn;
|
|
170
172
|
};
|
|
171
173
|
|
|
172
174
|
export function Property({ decl, children }: PropertyProps) {
|
|
@@ -205,7 +207,7 @@ export function Declaration({ decl }: DeclarationProps) {
|
|
|
205
207
|
if (!decl) return;
|
|
206
208
|
|
|
207
209
|
switch (decl.kind) {
|
|
208
|
-
case 'PythonDeclProperty':
|
|
210
|
+
case 'PythonDeclProperty': {
|
|
209
211
|
const nullable =
|
|
210
212
|
decl.type.kind === 'PythonTypeReference' &&
|
|
211
213
|
decl.type.typeName === 'Optional' &&
|
|
@@ -229,6 +231,7 @@ export function Declaration({ decl }: DeclarationProps) {
|
|
|
229
231
|
)}
|
|
230
232
|
</>
|
|
231
233
|
);
|
|
234
|
+
}
|
|
232
235
|
|
|
233
236
|
case 'PythonDeclClass':
|
|
234
237
|
return (
|
package/src/languages/ruby.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { RubyAST as AST } from '@stainless/sdk-json';
|
|
3
3
|
import { useDeclaration, useLanguage, useLanguageComponents, useSpec } from '../contexts';
|
|
4
4
|
import { useComponents } from '../contexts/use-components';
|
|
5
5
|
import style from '../style';
|
|
@@ -36,17 +36,23 @@ const VALID_IDENTIFIER = /^[_A-Za-z][_A-Za-z0-9]*$/;
|
|
|
36
36
|
function TypePreview({ path }: { path: string }) {
|
|
37
37
|
const spec = useSpec();
|
|
38
38
|
const language = useLanguage();
|
|
39
|
-
const decl = useDeclaration(path);
|
|
39
|
+
const decl = useDeclaration(path, false);
|
|
40
40
|
const { Join } = useComponents();
|
|
41
41
|
|
|
42
|
-
if (
|
|
42
|
+
if (
|
|
43
|
+
!(decl && 'children' in decl && decl.children && decl.children.length > 0) ||
|
|
44
|
+
('type' in decl && decl['type'] && 'kind' in decl['type'] && decl['type']?.['kind'] === 'RubyTypeUnion')
|
|
45
|
+
)
|
|
43
46
|
return;
|
|
44
47
|
|
|
45
|
-
const items = decl.children.map((prop, key) =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const items = decl.children.map((prop, key) => {
|
|
49
|
+
const p = spec?.decls?.[language]?.[prop];
|
|
50
|
+
return (
|
|
51
|
+
<span key={key} className={style.TypePropertyName}>
|
|
52
|
+
<span className={style.TextIdentifier}>{p && 'ident' in p ? p['ident'] : null}</span>
|
|
53
|
+
</span>
|
|
54
|
+
);
|
|
55
|
+
});
|
|
50
56
|
|
|
51
57
|
return (
|
|
52
58
|
<span className={style.TypePreview} data-stldocs-type-preview="properties">
|
|
@@ -110,6 +116,7 @@ export function Type({ type }: TypeProps) {
|
|
|
110
116
|
</span>
|
|
111
117
|
);
|
|
112
118
|
}
|
|
119
|
+
break;
|
|
113
120
|
|
|
114
121
|
case 'RubyTypeArray':
|
|
115
122
|
return (
|
|
@@ -139,8 +146,8 @@ export function Type({ type }: TypeProps) {
|
|
|
139
146
|
if (!type.typeParameters || type.typeParameters.length === 0)
|
|
140
147
|
return (
|
|
141
148
|
<span className={style.Type}>
|
|
142
|
-
<SDKReference stainlessPath={type.$ref}>{name}</SDKReference>
|
|
143
|
-
<TypePreview path={type.$ref} />
|
|
149
|
+
<SDKReference stainlessPath={type.$ref!}>{name}</SDKReference>
|
|
150
|
+
<TypePreview path={type.$ref!} />
|
|
144
151
|
</span>
|
|
145
152
|
);
|
|
146
153
|
|
|
@@ -148,13 +155,13 @@ export function Type({ type }: TypeProps) {
|
|
|
148
155
|
|
|
149
156
|
return (
|
|
150
157
|
<span className={style.Type}>
|
|
151
|
-
<SDKReference stainlessPath={type.$ref}>{name}</SDKReference>
|
|
158
|
+
<SDKReference stainlessPath={type.$ref!}>{name}</SDKReference>
|
|
152
159
|
<span className={style.TypeBracket}>{'<'}</span>
|
|
153
160
|
<Join items={typeParameters}>
|
|
154
161
|
<span className={style.TextOperator}>, </span>
|
|
155
162
|
</Join>
|
|
156
163
|
<span className={style.TypeBracket}>{'>'}</span>
|
|
157
|
-
<TypePreview path={type.$ref} />
|
|
164
|
+
<TypePreview path={type.$ref!} />
|
|
158
165
|
</span>
|
|
159
166
|
);
|
|
160
167
|
}
|
|
@@ -248,7 +255,7 @@ export function MethodSignature({ decl }: MethodSignatureProps) {
|
|
|
248
255
|
|
|
249
256
|
export type PropertyProps = {
|
|
250
257
|
decl: AST.RubyDeclaration;
|
|
251
|
-
children
|
|
258
|
+
children: PropertyFn;
|
|
252
259
|
};
|
|
253
260
|
|
|
254
261
|
export function Property({ decl, children }: PropertyProps) {
|