@stainless-api/docs-ui 0.1.0-beta.5 → 0.1.0-beta.51
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-BdYnaHA8.d.ts +20 -0
- package/dist/breadcrumbs-CA7GmW_8.d.ts +20 -0
- package/dist/breadcrumbs-nSFZO5Gf.js +63 -0
- package/dist/chunk-DRcLgZ1e.js +18 -0
- package/dist/component-DRO8kQSp.js +23 -0
- package/dist/component-generics-B6Fn47Mz.js +45 -0
- package/dist/component-generics-BHFUK06s.d.ts +30 -0
- package/dist/component-generics-BJSyydZ-.d.ts +30 -0
- package/dist/components/MaskedInput.d.ts +14 -0
- package/dist/components/MaskedInput.js +76 -0
- package/dist/components/breadcrumbs.d.ts +2 -0
- package/dist/components/breadcrumbs.js +9 -0
- package/dist/components/icons.d.ts +55 -0
- package/dist/components/icons.js +3 -0
- package/dist/components/index.d.ts +10 -0
- package/dist/components/index.js +18 -0
- package/dist/components/method.d.ts +2 -0
- package/dist/components/method.js +10 -0
- package/dist/components/overview.d.ts +2 -0
- package/dist/components/overview.js +11 -0
- package/dist/components/primitives.d.ts +2 -0
- package/dist/components/primitives.js +8 -0
- package/dist/components/properties.d.ts +2 -0
- package/dist/components/properties.js +9 -0
- package/dist/components/sdk.d.ts +2 -0
- package/dist/components/sdk.js +10 -0
- package/dist/components/sidebar.d.ts +2 -0
- package/dist/components/sidebar.js +11 -0
- package/dist/components/snippets.d.ts +3 -0
- package/dist/components/snippets.js +9 -0
- package/dist/components-D7M-BwNI.js +71 -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 +16 -0
- package/dist/contexts/component-types.js +0 -0
- package/dist/contexts/component.d.ts +29 -0
- package/dist/contexts/component.js +27 -0
- package/dist/contexts/docs.d.ts +2 -0
- package/dist/contexts/docs.js +3 -0
- package/dist/contexts/index.d.ts +16 -0
- package/dist/contexts/index.js +7 -0
- package/dist/contexts/markdown.d.ts +2 -0
- package/dist/contexts/markdown.js +4 -0
- package/dist/contexts/navigation.d.ts +2 -0
- package/dist/contexts/navigation.js +3 -0
- package/dist/contexts/use-components.d.ts +14 -0
- package/dist/contexts/use-components.js +4 -0
- package/dist/contexts-p3rRZDlM.js +39 -0
- package/dist/csharp-CDSxfCZE.js +283 -0
- package/dist/docs-BUS__I1m.d.ts +47 -0
- package/dist/docs-CXqi26jB.js +54 -0
- package/dist/docs-fKyo35eI.d.ts +47 -0
- package/dist/go-1c3S5ETL.js +303 -0
- package/dist/http-2QNWXH9t.js +330 -0
- package/dist/icons-Ckod9aod.js +869 -0
- package/dist/index-5Yl-BBg3.d.ts +15 -0
- package/dist/index-9LRO8R1a.d.ts +274 -0
- package/dist/index-CBIJwoyp.d.ts +13 -0
- package/dist/index-ClCZKGcw.d.ts +274 -0
- package/dist/index-pMKpm2Jk.d.ts +13 -0
- package/dist/index-q3bZhNWj.d.ts +15 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +29 -7542
- package/dist/java-BbjF_oUI.js +403 -0
- package/dist/languages/csharp.d.ts +11 -0
- package/dist/languages/csharp.js +9 -0
- package/dist/languages/go.d.ts +11 -0
- package/dist/languages/go.js +9 -0
- package/dist/languages/http.d.ts +11 -0
- package/dist/languages/http.js +19 -0
- package/dist/languages/index.d.ts +11 -0
- package/dist/languages/index.js +26 -0
- package/dist/languages/java.d.ts +11 -0
- package/dist/languages/java.js +9 -0
- package/dist/languages/python.d.ts +11 -0
- package/dist/languages/python.js +9 -0
- package/dist/languages/ruby.d.ts +11 -0
- package/dist/languages/ruby.js +9 -0
- package/dist/languages/typescript.d.ts +11 -0
- package/dist/languages/typescript.js +9 -0
- package/dist/languages-BCYZjzuS.js +26 -0
- package/dist/markdown/index.d.ts +12 -0
- package/dist/markdown/index.js +104 -0
- package/dist/markdown/md.d.ts +15 -0
- package/dist/markdown/md.js +3 -0
- package/dist/markdown/printer.d.ts +2 -0
- package/dist/markdown/printer.js +28 -0
- package/dist/markdown/utils.d.ts +3 -0
- package/dist/markdown/utils.js +3 -0
- package/dist/markdown-C8o8WrwG.d.ts +22 -0
- package/dist/markdown-CqJohZei.d.ts +22 -0
- package/dist/markdown-CxdeWgjV.js +48 -0
- package/dist/md-oM2tUaCA.js +41 -0
- package/dist/method-CE08mUME.js +115 -0
- package/dist/method-CMt6uyix.d.ts +71 -0
- package/dist/method-r5UAB40b.d.ts +71 -0
- package/dist/navigation-9_4wRkcT.d.ts +29 -0
- package/dist/navigation-C5TN0SgC.js +24 -0
- package/dist/navigation-zuoWsXzh.d.ts +29 -0
- package/dist/overview-DXmLmmr7.d.ts +39 -0
- package/dist/overview-S2hUqPXA.js +139 -0
- package/dist/overview-ixhAhHj8.d.ts +39 -0
- package/dist/primitives-BIWfwN5L.js +258 -0
- package/dist/primitives-BVXfSSiS.d.ts +97 -0
- package/dist/primitives-Bl0wzAGo.d.ts +97 -0
- package/dist/printer-DBw4S_Jn.d.ts +13 -0
- package/dist/printer-bNxiG6UB.js +74 -0
- package/dist/properties-C-NU_ghj.d.ts +54 -0
- package/dist/properties-GT9ixNTg.d.ts +54 -0
- package/dist/properties-jlGW3USi.js +131 -0
- package/dist/python-USOwFDv_.js +279 -0
- package/dist/routing-CMqh1cTZ.d.ts +54 -0
- package/dist/routing-Wbb7YECB.js +194 -0
- package/dist/routing.d.ts +2 -0
- package/dist/routing.js +3 -180
- package/dist/ruby-CSvGbSLe.js +387 -0
- package/dist/sdk-B5W3VipN.d.ts +118 -0
- package/dist/sdk-CS6A3HW3.d.ts +118 -0
- package/dist/sdk-CSCbbn3O.js +336 -0
- package/dist/sidebar-C3fZrgmP.d.ts +36 -0
- package/dist/sidebar-CWyvCrJ0.js +81 -0
- package/dist/sidebar-CbCLUteD.d.ts +36 -0
- package/dist/snippets-BQLXEIf6.js +161 -0
- package/dist/snippets-C72s2IwS.d.ts +51 -0
- package/dist/snippets-DcFph7ir.d.ts +51 -0
- package/dist/spec.d.ts +65 -0
- package/dist/spec.js +167 -0
- package/dist/style-D7RO5ymE.d.ts +168 -0
- package/dist/style-gnVEeXFj.js +169 -0
- package/dist/style.d.ts +2 -0
- package/dist/style.js +3 -0
- package/dist/styles/main.css +727 -754
- package/dist/styles/main.js +0 -0
- package/dist/styles/primitives.css +317 -461
- package/dist/styles/primitives.js +0 -0
- package/dist/styles/resets.css +32 -41
- package/dist/styles/resets.js +0 -0
- package/dist/styles/search.css +175 -274
- package/dist/styles/search.js +0 -0
- package/dist/styles/sidebar.css +59 -60
- package/dist/styles/sidebar.js +0 -0
- package/dist/styles/variables.css +26 -89
- package/dist/styles/variables.js +0 -0
- package/dist/styles.css +2910 -0
- package/dist/styles.mjs +1 -0
- package/dist/typescript-DXG9psK3.js +449 -0
- package/dist/use-components-RWQbviGq.js +7 -0
- package/dist/utils-CqnL9Fc3.js +31 -0
- package/dist/utils-DGnJ6mcU.d.ts +21 -0
- package/dist/utils-D_1AWSRX.js +32 -0
- package/dist/utils-d8paVwKN.d.ts +14 -0
- package/dist/utils-uQbtk0-_.d.ts +21 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +3 -0
- package/package.json +73 -21
- package/dist/mcp.js +0 -16003
- package/dist/styles/snippets.css +0 -132
- package/src/components/breadcrumbs.tsx +0 -94
- package/src/components/chat.tsx +0 -154
- package/src/components/dropdown.tsx +0 -91
- package/src/components/icons.tsx +0 -584
- package/src/components/index.ts +0 -9
- package/src/components/method.tsx +0 -144
- package/src/components/overview.tsx +0 -159
- package/src/components/primitives.tsx +0 -284
- package/src/components/properties.tsx +0 -130
- package/src/components/scripts/dropdown.ts +0 -78
- package/src/components/sdk.tsx +0 -402
- package/src/components/sidebar.tsx +0 -99
- package/src/components/snippets.tsx +0 -179
- package/src/contexts/component-generics.tsx +0 -48
- package/src/contexts/component-types.tsx +0 -5
- package/src/contexts/component.tsx +0 -32
- package/src/contexts/docs.tsx +0 -75
- package/src/contexts/index.tsx +0 -17
- package/src/contexts/markdown.tsx +0 -43
- package/src/contexts/navigation.tsx +0 -44
- package/src/contexts/search.tsx +0 -28
- package/src/contexts/use-components.tsx +0 -4
- package/src/index.ts +0 -6
- package/src/languages/go.tsx +0 -281
- package/src/languages/http.tsx +0 -321
- package/src/languages/index.ts +0 -26
- package/src/languages/java.tsx +0 -358
- package/src/languages/python.tsx +0 -255
- package/src/languages/ruby.tsx +0 -320
- package/src/languages/typescript.tsx +0 -393
- package/src/markdown/index.ts +0 -107
- package/src/markdown/md.ts +0 -45
- package/src/markdown/utils.ts +0 -49
- package/src/routing.ts +0 -238
- package/src/search/form.tsx +0 -127
- package/src/search/index.tsx +0 -1
- package/src/search/indexer.ts +0 -246
- package/src/search/mcp.ts +0 -61
- package/src/search/printer.tsx +0 -86
- package/src/search/providers/algolia.ts +0 -88
- package/src/search/providers/fuse.ts +0 -19
- package/src/search/providers/pagefind.ts +0 -17
- package/src/search/providers/walker.ts +0 -30
- package/src/search/results.tsx +0 -181
- package/src/search/state.ts +0 -64
- package/src/search/types.ts +0 -116
- package/src/style.ts +0 -197
- package/src/styles/main.css +0 -993
- package/src/styles/primitives.css +0 -573
- package/src/styles/resets.css +0 -47
- package/src/styles/search.css +0 -342
- package/src/styles/sidebar.css +0 -87
- package/src/styles/snippets.css +0 -132
- package/src/styles/variables.css +0 -90
- package/src/utils.ts +0 -41
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type * as TSAST from '~/lib/json-spec-v2/TSAST';
|
|
3
|
-
import { useDeclaration, useLanguage, useLanguageComponents, useSpec } from '../contexts';
|
|
4
|
-
import { useComponents } from '../contexts/use-components';
|
|
5
|
-
import style from '../style';
|
|
6
|
-
import { PropertyFn } from '.';
|
|
7
|
-
|
|
8
|
-
const ComplexTypes: Record<string, string> = {
|
|
9
|
-
TSTypeObject: 'object',
|
|
10
|
-
TSTypeUnion: 'union',
|
|
11
|
-
TSTypeInterface: 'interface',
|
|
12
|
-
TSTypeIntersection: 'intersection',
|
|
13
|
-
TSTypeArray: 'array',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const constStyle = {
|
|
17
|
-
string: style.LiteralString,
|
|
18
|
-
number: style.LiteralNumeric,
|
|
19
|
-
boolean: style.LiteralBoolean,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type TypeProps = {
|
|
23
|
-
type: TSAST.TSType;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function Identifier({ name, optional }: { name: string; optional?: boolean }) {
|
|
27
|
-
return (
|
|
28
|
-
<>
|
|
29
|
-
<span className={style.TextIdentifier}>
|
|
30
|
-
{/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(name) ? name : JSON.stringify(name)}
|
|
31
|
-
</span>
|
|
32
|
-
{optional && <span className={style.TextPunctuation}>?</span>}
|
|
33
|
-
</>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function TypeParams({ params }: { params?: TSAST.TSTypeParameter[] }) {
|
|
38
|
-
const Lang = useLanguageComponents();
|
|
39
|
-
const { Join } = useComponents();
|
|
40
|
-
|
|
41
|
-
if (!params?.length) return null;
|
|
42
|
-
|
|
43
|
-
const typeParams = params?.map((param, key) =>
|
|
44
|
-
param.constraint ? (
|
|
45
|
-
<React.Fragment key={key}>
|
|
46
|
-
<span className={style.TypeReference}>{param.name}</span>
|
|
47
|
-
<span className={style.TextKeyword}>extends </span>
|
|
48
|
-
<Lang.Type type={param.constraint} />
|
|
49
|
-
</React.Fragment>
|
|
50
|
-
) : (
|
|
51
|
-
<React.Fragment key={key}>param.name</React.Fragment>
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<>
|
|
57
|
-
<span className={style.TypeBracket}>{'<'}</span>
|
|
58
|
-
<Join items={typeParams} limit={3}>
|
|
59
|
-
<span className={style.TextOperator}>, </span>
|
|
60
|
-
</Join>
|
|
61
|
-
<span className={style.TypeBracket}>{'>'}</span>
|
|
62
|
-
</>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function TypePreview({ path }: { path: string }) {
|
|
67
|
-
const spec = useSpec();
|
|
68
|
-
const language = useLanguage();
|
|
69
|
-
const decl = useDeclaration(path);
|
|
70
|
-
const { Join } = useComponents();
|
|
71
|
-
|
|
72
|
-
if (!(decl && 'children' in decl && decl.children.length > 0) || decl['type']?.['kind'] === 'TSTypeUnion')
|
|
73
|
-
return;
|
|
74
|
-
|
|
75
|
-
const items = decl.children.map((prop, key) => (
|
|
76
|
-
<span key={key} className={style.TypePropertyName}>
|
|
77
|
-
<span className={style.TextIdentifier}>{spec?.decls?.[language]?.[prop]?.['key']}</span>
|
|
78
|
-
</span>
|
|
79
|
-
));
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<span className={style.TypePreview} data-stldocs-type-preview="properties">
|
|
83
|
-
<span className={style.TypeBrace}>{' {'}</span>
|
|
84
|
-
<span className={style.TypePreviewContent}>
|
|
85
|
-
{' '}
|
|
86
|
-
<Join items={items} limit={3}>
|
|
87
|
-
<span className={style.TextOperator}>, </span>
|
|
88
|
-
</Join>{' '}
|
|
89
|
-
</span>
|
|
90
|
-
<span className={style.TypeBrace}>{'} '}</span>
|
|
91
|
-
</span>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function TypeName({ type }: TypeProps) {
|
|
96
|
-
const Lang = useLanguageComponents();
|
|
97
|
-
return ComplexTypes[type.kind] ?? <Lang.Type type={type} />;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function Type({ type }: TypeProps) {
|
|
101
|
-
const Lang = useLanguageComponents();
|
|
102
|
-
const { Join, SDKReference } = useComponents();
|
|
103
|
-
|
|
104
|
-
switch (type.kind) {
|
|
105
|
-
case 'TSTypeUnknown':
|
|
106
|
-
case 'TSTypeUndefined':
|
|
107
|
-
case 'TSTypeNever':
|
|
108
|
-
case 'TSTypeVoid':
|
|
109
|
-
case 'TSTypeNull':
|
|
110
|
-
case 'TSTypeAny':
|
|
111
|
-
case 'TSTypeBoolean':
|
|
112
|
-
case 'TSTypeNumber':
|
|
113
|
-
return (
|
|
114
|
-
<span className={style.Type}>
|
|
115
|
-
<span className={style.TypeKeyword}>{type.kind.slice(6).toLowerCase()}</span>
|
|
116
|
-
</span>
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
case 'TSTypeString':
|
|
120
|
-
return (
|
|
121
|
-
<span className={style.Type}>
|
|
122
|
-
<span className={style.TypeString}>string</span>
|
|
123
|
-
</span>
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
case 'TSTypeLiteral':
|
|
127
|
-
return (
|
|
128
|
-
<span className={style.Type}>
|
|
129
|
-
<span className={constStyle[typeof type.literal]}>{JSON.stringify(type.literal)}</span>
|
|
130
|
-
</span>
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
case 'TSTypeArray': {
|
|
134
|
-
return (
|
|
135
|
-
<span className={style.Type}>
|
|
136
|
-
<span className={style.TypeArray}>{'Array<'}</span>
|
|
137
|
-
<Lang.Type type={type.elementType} />
|
|
138
|
-
<span className={style.TypeArray}>{'>'}</span>
|
|
139
|
-
</span>
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
case 'TSTypeReference': {
|
|
144
|
-
const name = type.ident.split('.').at(-1);
|
|
145
|
-
const params = type.typeParameters?.map((param, key) => <Lang.Type key={key} type={param} />);
|
|
146
|
-
|
|
147
|
-
return (
|
|
148
|
-
<span className={style.Type}>
|
|
149
|
-
<SDKReference stainlessPath={type.$ref}>{name}</SDKReference>
|
|
150
|
-
{params && params.length > 0 && (
|
|
151
|
-
<>
|
|
152
|
-
<span className={style.TypeBracket}>{'<'}</span>
|
|
153
|
-
<Join items={params} limit={3}>
|
|
154
|
-
<span className={style.TextOperator}>, </span>
|
|
155
|
-
</Join>
|
|
156
|
-
<span className={style.TypeBracket}>{'>'}</span>
|
|
157
|
-
</>
|
|
158
|
-
)}
|
|
159
|
-
<TypePreview path={type.$ref} />
|
|
160
|
-
</span>
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
case 'TSTypeIntersection':
|
|
165
|
-
case 'TSTypeUnion': {
|
|
166
|
-
const items = type.types.map((t, key) => <Lang.Type key={key} type={t} />);
|
|
167
|
-
|
|
168
|
-
const delimiter = type.kind === 'TSTypeUnion' ? '|' : '&';
|
|
169
|
-
|
|
170
|
-
return (
|
|
171
|
-
<span className={style.Type}>
|
|
172
|
-
<span className={style.TypePreview} data-stldocs-type-preview="union">
|
|
173
|
-
<span className={style.TypePreviewContent}>
|
|
174
|
-
<Join items={items} limit={3}>
|
|
175
|
-
<span className={style.TextOperator}> {delimiter} </span>
|
|
176
|
-
</Join>
|
|
177
|
-
</span>
|
|
178
|
-
</span>
|
|
179
|
-
</span>
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
case 'TSTypeObject':
|
|
184
|
-
case 'TSTypeInterface': {
|
|
185
|
-
const extend =
|
|
186
|
-
type.kind === 'TSTypeObject'
|
|
187
|
-
? null
|
|
188
|
-
: type.extends?.map((ref, key) => <Lang.Type key={key} type={ref} />);
|
|
189
|
-
|
|
190
|
-
const items = type.members.map((prop, key) => (
|
|
191
|
-
<React.Fragment key={key}>
|
|
192
|
-
<span className={style.TypePropertyName}>
|
|
193
|
-
<Identifier name={prop.ident} optional={prop.optional} />
|
|
194
|
-
</span>
|
|
195
|
-
<span className={style.TextPunctuation}>: </span>
|
|
196
|
-
<Lang.Type type={prop.type} />
|
|
197
|
-
</React.Fragment>
|
|
198
|
-
));
|
|
199
|
-
|
|
200
|
-
return (
|
|
201
|
-
<span className={style.Type}>
|
|
202
|
-
{extend?.length && (
|
|
203
|
-
<>
|
|
204
|
-
<span className={style.TypeKeyword}> extends </span>
|
|
205
|
-
<Join items={extend} limit={3}>
|
|
206
|
-
<span className={style.TextOperator}>, </span>
|
|
207
|
-
</Join>
|
|
208
|
-
</>
|
|
209
|
-
)}
|
|
210
|
-
<span className={style.TypePreview} data-stldocs-type-preview="properties">
|
|
211
|
-
<span className={style.TypeBrace}>{'{ '}</span>
|
|
212
|
-
<span className={style.TypePreviewContent}>
|
|
213
|
-
<Join items={items} limit={3}>
|
|
214
|
-
<span className={style.TextOperator}>, </span>
|
|
215
|
-
</Join>
|
|
216
|
-
</span>
|
|
217
|
-
<span className={style.TypeBrace}>{'} '}</span>
|
|
218
|
-
</span>
|
|
219
|
-
</span>
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export type MethodSignatureProps = {
|
|
226
|
-
decl: TSAST.TSDeclFunction;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
export function MethodSignature({ decl }: MethodSignatureProps) {
|
|
230
|
-
const Lang = useLanguageComponents();
|
|
231
|
-
const { Join, Tooltip } = useComponents();
|
|
232
|
-
|
|
233
|
-
const params = decl.signature.parameters.map((param, i) => (
|
|
234
|
-
<React.Fragment key={i}>
|
|
235
|
-
<Tooltip content={<Lang.Type type={param.type} />}>
|
|
236
|
-
<span className={style.TextIdentifier}>{param.ident}</span>
|
|
237
|
-
</Tooltip>
|
|
238
|
-
{param.optional && <span className={style.TextPunctuation}>?</span>}
|
|
239
|
-
</React.Fragment>
|
|
240
|
-
));
|
|
241
|
-
|
|
242
|
-
return (
|
|
243
|
-
<div className={style.MethodSignature}>
|
|
244
|
-
<span className={style.SignatureTitle}>
|
|
245
|
-
{decl.signature.async && <span className={style.TextKeyword}>async </span>}
|
|
246
|
-
<span className={style.SignatureQualified}>
|
|
247
|
-
<span className={style.TextIdentifier}>{decl.qualified?.slice(0, -decl.ident.length)}</span>
|
|
248
|
-
</span>
|
|
249
|
-
<span className={style.SignatureName}>
|
|
250
|
-
<span className={style.TextIdentifier}>{decl.ident}</span>
|
|
251
|
-
</span>
|
|
252
|
-
<span className={style.MethodSignature}>
|
|
253
|
-
{decl.signature.typeParameters && <TypeParams params={decl.signature.typeParameters} />}
|
|
254
|
-
<span className={style.SignatureParen}>{'('}</span>
|
|
255
|
-
|
|
256
|
-
<span className={style.SignatureParams}>
|
|
257
|
-
<Join items={params}>
|
|
258
|
-
<span className={style.TextOperator}>{', '}</span>
|
|
259
|
-
</Join>
|
|
260
|
-
</span>
|
|
261
|
-
|
|
262
|
-
<span className={style.SignatureParen}>{')'}</span>
|
|
263
|
-
{decl.signature.returns && (
|
|
264
|
-
<>
|
|
265
|
-
<span className={style.TextPunctuation}>: </span>
|
|
266
|
-
<Lang.Type type={decl.signature.returns} />
|
|
267
|
-
</>
|
|
268
|
-
)}
|
|
269
|
-
</span>
|
|
270
|
-
</span>
|
|
271
|
-
</div>
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export type PropertyProps = {
|
|
276
|
-
decl: TSAST.TSDeclaration;
|
|
277
|
-
children?: PropertyFn;
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
export function Property({ decl, children }: PropertyProps) {
|
|
281
|
-
const Lang = useLanguageComponents();
|
|
282
|
-
|
|
283
|
-
if (!decl) return;
|
|
284
|
-
|
|
285
|
-
switch (decl.kind) {
|
|
286
|
-
case 'TSDeclProperty':
|
|
287
|
-
return children({
|
|
288
|
-
name: decl.key,
|
|
289
|
-
typeName: <Lang.TypeName type={decl.type} />,
|
|
290
|
-
type: decl.type.kind in ComplexTypes && <Lang.Type type={decl.type} />,
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
case 'TSDeclTypeAlias':
|
|
294
|
-
return children({
|
|
295
|
-
name: decl.ident,
|
|
296
|
-
typeName: 'alias',
|
|
297
|
-
type: <Lang.Type type={decl.type} />,
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
case 'TSDeclReference':
|
|
301
|
-
return children({ type: <Lang.Type type={decl.type} /> });
|
|
302
|
-
|
|
303
|
-
case 'TSDeclInterface':
|
|
304
|
-
return children({
|
|
305
|
-
type: (
|
|
306
|
-
<>
|
|
307
|
-
<span className={style.TextIdentifier}>{decl.ident}</span>
|
|
308
|
-
{decl.typeParameters && <TypeParams params={decl.typeParameters} />}
|
|
309
|
-
{decl.extends?.flatMap((t, key) => (
|
|
310
|
-
<React.Fragment key={`extends:${key}`}>
|
|
311
|
-
<span className={style.TextKeyword}> extends </span>
|
|
312
|
-
<Lang.Type type={t} />
|
|
313
|
-
</React.Fragment>
|
|
314
|
-
))}
|
|
315
|
-
</>
|
|
316
|
-
),
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export type DeclarationProps = { decl: TSAST.TSDeclaration };
|
|
322
|
-
|
|
323
|
-
export function Declaration({ decl }: DeclarationProps) {
|
|
324
|
-
const Lang = useLanguageComponents();
|
|
325
|
-
|
|
326
|
-
if (!decl) return;
|
|
327
|
-
|
|
328
|
-
switch (decl.kind) {
|
|
329
|
-
case 'TSDeclProperty':
|
|
330
|
-
return (
|
|
331
|
-
<>
|
|
332
|
-
{decl.declare && <span className={style.TextKeyword}>declare </span>}
|
|
333
|
-
<span className={style.TypePropertyName}>
|
|
334
|
-
<Identifier name={decl.key} optional={decl.optional} />
|
|
335
|
-
</span>
|
|
336
|
-
<span className={style.TextPunctuation}>: </span>
|
|
337
|
-
<Lang.Type type={decl.type} />
|
|
338
|
-
</>
|
|
339
|
-
);
|
|
340
|
-
|
|
341
|
-
case 'TSDeclFunction':
|
|
342
|
-
return <Lang.MethodSignature decl={decl} />;
|
|
343
|
-
|
|
344
|
-
case 'TSDeclTypeAlias':
|
|
345
|
-
return (
|
|
346
|
-
<>
|
|
347
|
-
<Identifier name={decl.ident} />
|
|
348
|
-
<TypeParams params={decl.typeParameters} />
|
|
349
|
-
<span className={style.TextOperator}> = </span>
|
|
350
|
-
<Lang.Type type={decl.type} />
|
|
351
|
-
</>
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
case 'TSDeclReference':
|
|
355
|
-
return <Lang.Type type={decl.type} />;
|
|
356
|
-
|
|
357
|
-
case 'TSDeclInterface':
|
|
358
|
-
return (
|
|
359
|
-
<>
|
|
360
|
-
<span className={style.TextIdentifier}>{decl.ident}</span>
|
|
361
|
-
<TypeParams params={decl.typeParameters} />
|
|
362
|
-
{decl.extends?.map((t, index) => (
|
|
363
|
-
<React.Fragment key={index}>
|
|
364
|
-
<span className={style.TextKeyword}> extends </span>
|
|
365
|
-
<Lang.Type type={t} />
|
|
366
|
-
</React.Fragment>
|
|
367
|
-
))}
|
|
368
|
-
<TypePreview path={decl.stainlessPath} />
|
|
369
|
-
</>
|
|
370
|
-
);
|
|
371
|
-
|
|
372
|
-
case 'TSDeclClass':
|
|
373
|
-
return (
|
|
374
|
-
<>
|
|
375
|
-
<span className={style.TextKeyword}>class </span>
|
|
376
|
-
<span className={style.TextIdentifier}>{decl.ident}</span>
|
|
377
|
-
<TypeParams params={decl.typeParameters} />
|
|
378
|
-
{decl.superClass ? (
|
|
379
|
-
<>
|
|
380
|
-
<span className={style.TextKeyword}> extends </span>
|
|
381
|
-
<Lang.Type type={decl.superClass} />
|
|
382
|
-
</>
|
|
383
|
-
) : null}
|
|
384
|
-
{decl.implements?.map((t, index) => (
|
|
385
|
-
<React.Fragment key={index}>
|
|
386
|
-
<span className={style.TextKeyword}> implements </span>
|
|
387
|
-
<Lang.Type type={t} />
|
|
388
|
-
</React.Fragment>
|
|
389
|
-
))}
|
|
390
|
-
</>
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
}
|
package/src/markdown/index.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import Markdoc from '@markdoc/markdoc';
|
|
2
|
-
import * as md from './md';
|
|
3
|
-
import { EnvironmentType, getDecl, getSnippet, stripMarkup } from './utils';
|
|
4
|
-
import * as printer from '../search/printer';
|
|
5
|
-
import type * as SDKJSON from '~/lib/json-spec-v2/types';
|
|
6
|
-
import type { Node } from '@markdoc/markdoc';
|
|
7
|
-
|
|
8
|
-
export function declaration(env: EnvironmentType, decl: SDKJSON.DeclarationNode) {
|
|
9
|
-
const content = printer.declaration(env.language, decl);
|
|
10
|
-
return md.paragraph(md.code(stripMarkup(content)));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function renderChildren(env: EnvironmentType, children: SDKJSON.ID[], nesting: string[] = []) {
|
|
14
|
-
return md.list(...children.map((child) => renderDecl(env, child, nesting)));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function renderDecl(env: EnvironmentType, path: string, nesting: string[] = []) {
|
|
18
|
-
const decl = getDecl(env, path);
|
|
19
|
-
const item = md.item(declaration(env, decl));
|
|
20
|
-
|
|
21
|
-
const hasChildren = 'children' in decl && decl.children.length > 0;
|
|
22
|
-
const showModelProps = !decl['modelPath'] || env.options.includeModelProperties;
|
|
23
|
-
|
|
24
|
-
if ('docstring' in decl && decl.docstring) item.children.push(...md.parse(decl.docstring));
|
|
25
|
-
if (hasChildren && showModelProps && !nesting.includes(path))
|
|
26
|
-
item.push(renderChildren(env, decl.children, [...nesting, path]));
|
|
27
|
-
|
|
28
|
-
return item;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function renderMethod(env: EnvironmentType, method: SDKJSON.Method) {
|
|
32
|
-
const decl = getDecl(env, method.stainlessPath);
|
|
33
|
-
|
|
34
|
-
if (!decl)
|
|
35
|
-
return [
|
|
36
|
-
md.paragraph(
|
|
37
|
-
md.text('The method '),
|
|
38
|
-
md.code(method.name),
|
|
39
|
-
md.text(' is not available in this language.'),
|
|
40
|
-
),
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
const signature = printer.methodSignature(env.language, decl);
|
|
44
|
-
const [httpMethod, endpoint] = method.endpoint.split(' ');
|
|
45
|
-
|
|
46
|
-
const output = [
|
|
47
|
-
md.heading(2, method.title),
|
|
48
|
-
env.language === 'http' ? null : md.paragraph(md.code(stripMarkup(signature))),
|
|
49
|
-
md.paragraph(md.strong(md.text(httpMethod)), md.text(' '), md.code(endpoint)),
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
if (method.description) output.push(...md.parse(method.description));
|
|
53
|
-
|
|
54
|
-
if ('paramsChildren' in decl && Array.isArray(decl.paramsChildren) && decl.paramsChildren.length > 0)
|
|
55
|
-
output.push(md.heading(3, 'Parameters'), renderChildren(env, decl.paramsChildren));
|
|
56
|
-
|
|
57
|
-
if ('responseChildren' in decl && decl.responseChildren.length > 0)
|
|
58
|
-
output.push(md.heading(3, 'Returns'), renderChildren(env, decl.responseChildren));
|
|
59
|
-
|
|
60
|
-
const snippet = getSnippet(env, method.stainlessPath);
|
|
61
|
-
if (snippet) output.push(md.heading(3, 'Example'), md.fence(env.language, snippet));
|
|
62
|
-
|
|
63
|
-
return output;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function renderModel(env: EnvironmentType, model: SDKJSON.Model) {
|
|
67
|
-
return [md.heading(3, model.title), md.list(renderDecl(env, `${model.stainlessPath} > (schema)`))];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function renderResource(env: EnvironmentType, resource: SDKJSON.Resource) {
|
|
71
|
-
const methods = Object.values(resource.methods)
|
|
72
|
-
.filter((method) => getDecl(env, method.stainlessPath))
|
|
73
|
-
.flatMap((method) => renderMethod(env, method));
|
|
74
|
-
|
|
75
|
-
const models = Object.values(resource.models)
|
|
76
|
-
.filter((model) => getDecl(env, `${model.stainlessPath} > (schema)`))
|
|
77
|
-
.flatMap((model) => renderModel(env, model));
|
|
78
|
-
|
|
79
|
-
const doc: Node[] = [md.heading(1, resource.title), ...methods];
|
|
80
|
-
|
|
81
|
-
if (models.length > 0) doc.push(md.heading(2, 'Domain Types'), ...models);
|
|
82
|
-
|
|
83
|
-
if (!env.options.renderNestedResources) return doc;
|
|
84
|
-
|
|
85
|
-
const children = Object.values(resource.subresources).map((resource) => renderResource(env, resource));
|
|
86
|
-
return [...doc, ...children];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function render(env: EnvironmentType, node: SDKJSON.Resource | SDKJSON.Method | SDKJSON.Model) {
|
|
90
|
-
switch (node.kind) {
|
|
91
|
-
case 'resource':
|
|
92
|
-
return renderResource(env, node);
|
|
93
|
-
case 'http_method':
|
|
94
|
-
return renderMethod(env, node);
|
|
95
|
-
case 'model':
|
|
96
|
-
return renderModel(env, node);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function renderMarkdown(
|
|
101
|
-
env: EnvironmentType,
|
|
102
|
-
node: SDKJSON.Resource | SDKJSON.Method | SDKJSON.Model,
|
|
103
|
-
) {
|
|
104
|
-
const content = render(env, node);
|
|
105
|
-
const doc = new Markdoc.Ast.Node('document', {}, content);
|
|
106
|
-
return Markdoc.format(doc);
|
|
107
|
-
}
|
package/src/markdown/md.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import Markdoc from '@markdoc/markdoc';
|
|
2
|
-
import type { Node } from '@markdoc/markdoc';
|
|
3
|
-
|
|
4
|
-
export function heading(level: number, children: string | Node[]) {
|
|
5
|
-
const content = inline(...(typeof children === 'string' ? [text(children)] : children));
|
|
6
|
-
|
|
7
|
-
return new Markdoc.Ast.Node('heading', { level }, [content]);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function text(content: string) {
|
|
11
|
-
return new Markdoc.Ast.Node('text', { content });
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function code(content: string) {
|
|
15
|
-
return new Markdoc.Ast.Node('code', { content });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function paragraph(...children: Node[]) {
|
|
19
|
-
const inline = new Markdoc.Ast.Node('inline', {}, children);
|
|
20
|
-
return new Markdoc.Ast.Node('paragraph', {}, [inline]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function list(...children: Node[]) {
|
|
24
|
-
return new Markdoc.Ast.Node('list', { ordered: false }, children);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function item(...children: Node[]) {
|
|
28
|
-
return new Markdoc.Ast.Node('item', {}, children);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function strong(...children: Node[]) {
|
|
32
|
-
return new Markdoc.Ast.Node('strong', {}, children);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function inline(...children: Node[]) {
|
|
36
|
-
return new Markdoc.Ast.Node('inline', {}, children);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function fence(language: string, content: string) {
|
|
40
|
-
return new Markdoc.Ast.Node('fence', { language, content });
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function parse(content: string) {
|
|
44
|
-
return Markdoc.parse(content).children;
|
|
45
|
-
}
|
package/src/markdown/utils.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Parser } from 'htmlparser2';
|
|
2
|
-
import type { DocsLanguage } from '../routing';
|
|
3
|
-
import type * as SDKJSON from '~/lib/json-spec-v2/types';
|
|
4
|
-
import type { TransformRequestSnippetFn } from '../components/sdk';
|
|
5
|
-
|
|
6
|
-
export type EnvironmentType = {
|
|
7
|
-
spec: SDKJSON.Spec;
|
|
8
|
-
language: DocsLanguage;
|
|
9
|
-
transforms?: {
|
|
10
|
-
transformRequestSnippet?: TransformRequestSnippetFn;
|
|
11
|
-
};
|
|
12
|
-
options: {
|
|
13
|
-
renderNestedResources?: boolean;
|
|
14
|
-
includeModelProperties?: boolean;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function getDecl(env: EnvironmentType, path: string) {
|
|
19
|
-
const decl = env.spec?.decls?.[env.language]?.[path];
|
|
20
|
-
|
|
21
|
-
if (decl?.kind?.endsWith('Reference')) {
|
|
22
|
-
const refId = decl['type']['$ref'];
|
|
23
|
-
if (refId === path) return decl;
|
|
24
|
-
if (refId) return getDecl(env, refId);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return decl;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function getSnippet(env: EnvironmentType, path: string) {
|
|
31
|
-
let snippet = env.spec?.snippets?.[`${env.language}.default`]?.[path];
|
|
32
|
-
if (typeof snippet === 'string' && env.transforms?.transformRequestSnippet) {
|
|
33
|
-
snippet = env.transforms.transformRequestSnippet({ snippet, language: env.language });
|
|
34
|
-
}
|
|
35
|
-
return snippet;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function stripMarkup(content: string) {
|
|
39
|
-
let output = '';
|
|
40
|
-
|
|
41
|
-
const parser = new Parser({
|
|
42
|
-
ontext(content) {
|
|
43
|
-
output += content;
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
parser.parseComplete(content);
|
|
48
|
-
return output;
|
|
49
|
-
}
|