@stainless-api/docs-ui 0.1.0-beta.5 → 0.1.0-beta.50
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-C6pTTw_o.d.ts +20 -0
- package/dist/breadcrumbs-DEyC9k79.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-D_yxZT6v.d.ts +30 -0
- package/dist/component-generics-DxN-MaP2.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-CXqi26jB.js +54 -0
- package/dist/docs-dNFWvk6w.d.ts +47 -0
- package/dist/docs-mMDqYdkf.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-0imEqwWy.d.ts +15 -0
- package/dist/index-BJR7MT73.d.ts +13 -0
- package/dist/index-DGWbX2x8.d.ts +13 -0
- package/dist/index-DJO7hQAU.d.ts +274 -0
- package/dist/index-DMFZJxNb.d.ts +15 -0
- package/dist/index-tw6MEWKp.d.ts +274 -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-CxdeWgjV.js +48 -0
- package/dist/markdown-DeSSIANr.d.ts +22 -0
- package/dist/markdown-OuUthjwK.d.ts +22 -0
- package/dist/md-oM2tUaCA.js +41 -0
- package/dist/method-BiXJltKa.d.ts +71 -0
- package/dist/method-CE08mUME.js +115 -0
- package/dist/method-DQ3lDoTM.d.ts +71 -0
- package/dist/navigation-BX8nuda9.d.ts +29 -0
- package/dist/navigation-C5TN0SgC.js +24 -0
- package/dist/navigation-CWDfzVoR.d.ts +29 -0
- package/dist/overview-B43BuZbK.d.ts +39 -0
- package/dist/overview-MTDgZ7Xr.d.ts +39 -0
- package/dist/overview-S2hUqPXA.js +139 -0
- package/dist/primitives-1lB1L0is.d.ts +97 -0
- package/dist/primitives-BIWfwN5L.js +258 -0
- package/dist/primitives-DLv4uMoz.d.ts +97 -0
- package/dist/printer-DBw4S_Jn.d.ts +13 -0
- package/dist/printer-bNxiG6UB.js +74 -0
- package/dist/properties-B-giMW4K.d.ts +54 -0
- package/dist/properties-BvP2WAjP.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-BwXeHS3_.d.ts +118 -0
- package/dist/sdk-CSCbbn3O.js +336 -0
- package/dist/sdk-DXdNszcC.d.ts +118 -0
- package/dist/sidebar-CWyvCrJ0.js +81 -0
- package/dist/sidebar-DGGt5gik.d.ts +36 -0
- package/dist/sidebar-DfS6SWQz.d.ts +36 -0
- package/dist/snippets-BQLXEIf6.js +161 -0
- package/dist/snippets-BRs_4F1I.d.ts +51 -0
- package/dist/snippets-DxSMK50g.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-BaLi5Bed.d.ts +21 -0
- package/dist/utils-CqnL9Fc3.js +31 -0
- package/dist/utils-D_1AWSRX.js +32 -0
- package/dist/utils-_AEBNJhG.d.ts +21 -0
- package/dist/utils-d8paVwKN.d.ts +14 -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
package/src/languages/go.tsx
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type * as AST from '~/lib/json-spec-v2/GoAST';
|
|
3
|
-
|
|
4
|
-
import { useComponents } from '../contexts/use-components';
|
|
5
|
-
import { useLanguageComponents } from '../contexts';
|
|
6
|
-
import style from '../style';
|
|
7
|
-
import { PropertyFn } from '.';
|
|
8
|
-
|
|
9
|
-
const ComplexTypes: Record<string, string> = {
|
|
10
|
-
GoTypeMap: 'map',
|
|
11
|
-
GoTypeArray: 'array',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const Keywords = {
|
|
15
|
-
GoTypeAny: 'any',
|
|
16
|
-
GoTypeUnknown: 'unknown',
|
|
17
|
-
GoTypeInt: 'int64',
|
|
18
|
-
GoTypeFloat: 'float64',
|
|
19
|
-
GoTypeBool: 'bool',
|
|
20
|
-
GoTypeError: 'error',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
function isField(type: AST.GoType) {
|
|
24
|
-
return type.kind === 'GoTypeReference' && type.typeName === 'param.Field';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type TypeProps = {
|
|
28
|
-
type: AST.GoType;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export function TypeName({ type }: TypeProps) {
|
|
32
|
-
const Lang = useLanguageComponents();
|
|
33
|
-
return isField(type) ? 'field' : (ComplexTypes[type.kind] ?? <Lang.Type type={type} />);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function Type({ type }: TypeProps) {
|
|
37
|
-
const Lang = useLanguageComponents();
|
|
38
|
-
const { Join, SDKReference } = useComponents();
|
|
39
|
-
|
|
40
|
-
switch (type.kind) {
|
|
41
|
-
case 'GoTypeReference': {
|
|
42
|
-
const params = type.typeParameters?.map((param, key) => <Lang.Type key={key} type={param} />);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<span className={style.Type}>
|
|
46
|
-
<SDKReference stainlessPath={type.$ref}>{type.typeName}</SDKReference>
|
|
47
|
-
{params && params.length > 0 ? (
|
|
48
|
-
<>
|
|
49
|
-
<span className={style.TypeBracket}>{'['}</span>
|
|
50
|
-
<Join items={params} limit={3}>
|
|
51
|
-
<span className={style.TextOperator}>, </span>
|
|
52
|
-
</Join>
|
|
53
|
-
<span className={style.TypeBracket}>{']'}</span>
|
|
54
|
-
</>
|
|
55
|
-
) : null}
|
|
56
|
-
</span>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
case 'GoTypeAny':
|
|
61
|
-
case 'GoTypeUnknown':
|
|
62
|
-
case 'GoTypeInt':
|
|
63
|
-
case 'GoTypeFloat':
|
|
64
|
-
case 'GoTypeBool':
|
|
65
|
-
case 'GoTypeError':
|
|
66
|
-
return (
|
|
67
|
-
<span className={style.Type}>
|
|
68
|
-
<span className={style.TypeKeyword}>{Keywords[type.kind]}</span>
|
|
69
|
-
</span>
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
case 'GoTypeString':
|
|
73
|
-
return (
|
|
74
|
-
<span className={style.Type}>
|
|
75
|
-
<span className={style.TypeString}>string</span>
|
|
76
|
-
</span>
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
case 'GoTypeArray':
|
|
80
|
-
return (
|
|
81
|
-
<span className={style.Type}>
|
|
82
|
-
<span className={style.TextOperator}>[]</span>
|
|
83
|
-
<Lang.Type type={type.elementType} />
|
|
84
|
-
</span>
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
case 'GoTypeStruct':
|
|
88
|
-
return (
|
|
89
|
-
<span className={style.Type}>
|
|
90
|
-
<span className={style.TypeKeyword}>{'struct{…}'}</span>
|
|
91
|
-
</span>
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
case 'GoTypeInterface':
|
|
95
|
-
return (
|
|
96
|
-
<span className={style.Type}>
|
|
97
|
-
<span className={style.TypeKeyword}>{'interface{…}'}</span>
|
|
98
|
-
</span>
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
case 'GoTypeMap':
|
|
102
|
-
return (
|
|
103
|
-
<span className={style.Type}>
|
|
104
|
-
<span className={style.TypeKeyword}>map</span>
|
|
105
|
-
<span className={style.TypeBracket}>[</span>
|
|
106
|
-
<Lang.Type type={type.indexType} />
|
|
107
|
-
<span className={style.TextPunctuation}>,</span> <Lang.Type type={type.itemType} />
|
|
108
|
-
<span className={style.TypeBracket}>]</span>
|
|
109
|
-
</span>
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
case 'GoTypePointer':
|
|
113
|
-
return (
|
|
114
|
-
<span className={style.Type}>
|
|
115
|
-
<span className={style.TextOperator}>*</span>
|
|
116
|
-
<Lang.Type type={type.inner} />
|
|
117
|
-
</span>
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export type MethodSignatureProps = {
|
|
123
|
-
decl: AST.GoDeclFunction;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export function MethodSignature({ decl }: MethodSignatureProps) {
|
|
127
|
-
const Lang = useLanguageComponents();
|
|
128
|
-
const { Join } = useComponents();
|
|
129
|
-
|
|
130
|
-
const params = decl.parameters.map((param, i) => (
|
|
131
|
-
<React.Fragment key={i}>
|
|
132
|
-
<span className={style.TextIdentifier}>{param.ident}</span>
|
|
133
|
-
{param.optional && <span className={style.TextPunctuation}>?</span>}
|
|
134
|
-
</React.Fragment>
|
|
135
|
-
));
|
|
136
|
-
|
|
137
|
-
const returns = decl.returnType.map((t, key) => <Lang.Type key={key} type={t} />);
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<div className={style.MethodSignature}>
|
|
141
|
-
<span className={style.SignatureTitle}>
|
|
142
|
-
{decl.async && <span className={style.TextKeyword}>async </span>}
|
|
143
|
-
{decl.qualified && (
|
|
144
|
-
<span className={style.SignatureQualified}>
|
|
145
|
-
<span className={style.TextIdentifier}>{decl.qualified?.slice(0, -decl.ident.length)}</span>
|
|
146
|
-
</span>
|
|
147
|
-
)}
|
|
148
|
-
{decl.kind === 'GoDeclFunction' && (
|
|
149
|
-
<span className={style.SignatureName}>
|
|
150
|
-
<span className={style.TextIdentifier}>{decl.ident}</span>
|
|
151
|
-
</span>
|
|
152
|
-
)}
|
|
153
|
-
<span className={style.MethodSignature}>
|
|
154
|
-
<span className={style.SignatureParen}>{'('}</span>
|
|
155
|
-
|
|
156
|
-
<span className={style.SignatureParams}>
|
|
157
|
-
<Join items={params}>
|
|
158
|
-
<span className={style.TextOperator}>{', '}</span>
|
|
159
|
-
</Join>
|
|
160
|
-
</span>
|
|
161
|
-
|
|
162
|
-
<span className={style.SignatureParen}>{')'} </span>
|
|
163
|
-
{decl.returnType.length === 1 ? (
|
|
164
|
-
returns
|
|
165
|
-
) : (
|
|
166
|
-
<>
|
|
167
|
-
<span className={style.SignatureParen}>{'('}</span>
|
|
168
|
-
<Join items={returns}>
|
|
169
|
-
<span className={style.TextOperator}>, </span>
|
|
170
|
-
</Join>
|
|
171
|
-
<span className={style.SignatureParen}>{')'}</span>
|
|
172
|
-
</>
|
|
173
|
-
)}
|
|
174
|
-
</span>
|
|
175
|
-
</span>
|
|
176
|
-
</div>
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export type PropertyProps = {
|
|
181
|
-
decl: AST.GoDeclaration;
|
|
182
|
-
children?: PropertyFn;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
export function Property({ decl, children }: PropertyProps) {
|
|
186
|
-
const Docs = useComponents();
|
|
187
|
-
const Lang = useLanguageComponents();
|
|
188
|
-
|
|
189
|
-
if (!decl) return null;
|
|
190
|
-
|
|
191
|
-
switch (decl.kind) {
|
|
192
|
-
case 'GoDeclProperty':
|
|
193
|
-
return children({
|
|
194
|
-
name: decl.ident,
|
|
195
|
-
typeName: <Lang.TypeName type={decl.type} />,
|
|
196
|
-
badges: decl.optional && <Docs.Badge id="optional" />,
|
|
197
|
-
type: (isField(decl.type) || decl.type.kind in ComplexTypes) && <Lang.Type type={decl.type} />,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
case 'GoDeclConst':
|
|
201
|
-
return children({
|
|
202
|
-
name: decl.ident,
|
|
203
|
-
typeName: 'const',
|
|
204
|
-
type: <Lang.Type type={decl.type} />,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
case 'GoDeclReference':
|
|
208
|
-
return children({ type: <Lang.Type type={decl.type} /> });
|
|
209
|
-
|
|
210
|
-
case 'GoDeclType':
|
|
211
|
-
case 'GoDeclTypeAlias': {
|
|
212
|
-
const typeName =
|
|
213
|
-
decl.type.kind === 'GoTypeStruct'
|
|
214
|
-
? 'struct'
|
|
215
|
-
: decl.type.kind === 'GoTypeInterface'
|
|
216
|
-
? 'interface'
|
|
217
|
-
: decl.kind === 'GoDeclTypeAlias'
|
|
218
|
-
? 'alias'
|
|
219
|
-
: 'type';
|
|
220
|
-
|
|
221
|
-
return children({
|
|
222
|
-
name: decl.ident,
|
|
223
|
-
typeName,
|
|
224
|
-
type: ['GoTypeStruct', 'GoTypeInterface'].includes(decl.type.kind) || <Lang.Type type={decl.type} />,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export type DeclarationProps = { decl: AST.GoDeclaration };
|
|
231
|
-
|
|
232
|
-
export function Declaration({ decl }: DeclarationProps) {
|
|
233
|
-
const Lang = useLanguageComponents();
|
|
234
|
-
|
|
235
|
-
if (!decl) return;
|
|
236
|
-
|
|
237
|
-
switch (decl.kind) {
|
|
238
|
-
case 'GoDeclType':
|
|
239
|
-
return (
|
|
240
|
-
<>
|
|
241
|
-
<span className={style.TextKeyword}>type </span>
|
|
242
|
-
<span className={style.TextIdentifier}>{decl.ident} </span>
|
|
243
|
-
<Lang.Type type={decl.type} />
|
|
244
|
-
</>
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
case 'GoDeclTypeAlias':
|
|
248
|
-
return (
|
|
249
|
-
<>
|
|
250
|
-
<span className={style.TextKeyword}>type </span>
|
|
251
|
-
<span className={style.TextIdentifier}>{decl.ident} </span>
|
|
252
|
-
<span className={style.TextOperator}>= </span>
|
|
253
|
-
<Lang.Type type={decl.type} />
|
|
254
|
-
</>
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
case 'GoDeclProperty':
|
|
258
|
-
return (
|
|
259
|
-
<>
|
|
260
|
-
<span className={style.TypePropertyName}>
|
|
261
|
-
<span className={style.TextIdentifier}>{decl.ident} </span>
|
|
262
|
-
</span>
|
|
263
|
-
<Lang.Type type={decl.type} />
|
|
264
|
-
</>
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
case 'GoDeclReference':
|
|
268
|
-
return <Lang.Type type={decl.type} />;
|
|
269
|
-
|
|
270
|
-
case 'GoDeclConst':
|
|
271
|
-
return (
|
|
272
|
-
<>
|
|
273
|
-
<span className={style.TextKeyword}>const </span>
|
|
274
|
-
<span className={style.TextIdentifier}>{decl.ident} </span>
|
|
275
|
-
<Lang.Type type={decl.type} />
|
|
276
|
-
<span className={style.TextOperator}> = </span>
|
|
277
|
-
{JSON.stringify(decl.value)}
|
|
278
|
-
</>
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
}
|
package/src/languages/http.tsx
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import type * as AST from '~/lib/json-spec-v2/HttpAST';
|
|
2
|
-
import { useDeclaration, useLanguage, useLanguageComponents, useSpec } from '../contexts';
|
|
3
|
-
import { useComponents } from '../contexts/use-components';
|
|
4
|
-
import style from '../style';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { PropertyFn } from '.';
|
|
7
|
-
import { PropertyToggle } from '../components';
|
|
8
|
-
|
|
9
|
-
const ComplexTypes: Partial<Record<AST.HttpType['kind'], string>> = {
|
|
10
|
-
HttpTypeUnion: 'union',
|
|
11
|
-
HttpTypeIntersection: 'intersection',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const constStyle = {
|
|
15
|
-
string: style.LiteralString,
|
|
16
|
-
number: style.LiteralNumeric,
|
|
17
|
-
boolean: style.LiteralBoolean,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type TypeProps = {
|
|
21
|
-
type: AST.HttpType;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
function Identifier({ name }: { name: string }) {
|
|
25
|
-
return (
|
|
26
|
-
<>
|
|
27
|
-
<span className={style.TextIdentifier}>
|
|
28
|
-
{/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(name) ? name : JSON.stringify(name)}
|
|
29
|
-
</span>
|
|
30
|
-
</>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function TypePreview({ path }: { path: string }) {
|
|
35
|
-
const spec = useSpec();
|
|
36
|
-
const language = useLanguage();
|
|
37
|
-
const decl = useDeclaration(path);
|
|
38
|
-
const { Join } = useComponents();
|
|
39
|
-
|
|
40
|
-
if (!(decl && 'children' in decl && decl.children.length > 0) || decl['type']?.['kind'] === 'HttpTypeUnion')
|
|
41
|
-
return;
|
|
42
|
-
|
|
43
|
-
const items = decl.children.map((prop, key) => (
|
|
44
|
-
<span key={key} className={style.TypePropertyName}>
|
|
45
|
-
<span className={style.TextIdentifier}>{spec?.decls?.[language]?.[prop]?.['key']}</span>
|
|
46
|
-
</span>
|
|
47
|
-
));
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<span className={style.TypePreview} data-stldocs-type-preview="properties">
|
|
51
|
-
<span className={style.TypeBrace}>{' { '}</span>
|
|
52
|
-
<span className={style.TypePreviewContent}>
|
|
53
|
-
<Join items={items} limit={3}>
|
|
54
|
-
<span className={style.TextOperator}>, </span>
|
|
55
|
-
</Join>
|
|
56
|
-
</span>
|
|
57
|
-
<span className={style.TypeBrace}>{' } '}</span>
|
|
58
|
-
</span>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function TypeName({ type }: TypeProps) {
|
|
63
|
-
const Lang = useLanguageComponents();
|
|
64
|
-
|
|
65
|
-
if (type.kind === 'HttpTypeArray') return <>array of {<Lang.TypeName type={type.elementType} />}</>;
|
|
66
|
-
|
|
67
|
-
if (type.kind === 'HttpTypeUnion' && type.types.every((t) => t.kind === 'HttpTypeLiteral')) return 'enum';
|
|
68
|
-
|
|
69
|
-
if (type.kind === 'HttpTypeReference' && type.ident.split('.').at(-1) === 'Record') return 'map';
|
|
70
|
-
|
|
71
|
-
return ComplexTypes[type.kind] ?? <Lang.Type type={type} />;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function Type({ type }: TypeProps) {
|
|
75
|
-
const Lang = useLanguageComponents();
|
|
76
|
-
const { Join, SDKReference } = useComponents();
|
|
77
|
-
|
|
78
|
-
switch (type.kind) {
|
|
79
|
-
case 'HttpTypeUnknown':
|
|
80
|
-
case 'HttpTypeUndefined':
|
|
81
|
-
case 'HttpTypeNull':
|
|
82
|
-
case 'HttpTypeBoolean':
|
|
83
|
-
case 'HttpTypeNumber':
|
|
84
|
-
return (
|
|
85
|
-
<span className={style.Type}>
|
|
86
|
-
<span className={style.TypePlain}>{type.kind.slice(8).toLowerCase()}</span>
|
|
87
|
-
</span>
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
case 'HttpTypeString':
|
|
91
|
-
return (
|
|
92
|
-
<span className={style.Type}>
|
|
93
|
-
<span className={style.TypePlain}>string</span>
|
|
94
|
-
</span>
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
case 'HttpTypeLiteral':
|
|
98
|
-
return (
|
|
99
|
-
<span className={style.Type}>
|
|
100
|
-
<span className={constStyle[typeof type.literal]}>{JSON.stringify(type.literal)}</span>
|
|
101
|
-
</span>
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
case 'HttpTypeArray': {
|
|
105
|
-
return (
|
|
106
|
-
<span className={style.Type}>
|
|
107
|
-
<span className={style.TypeArray}>{'array of '}</span>
|
|
108
|
-
<Lang.Type type={type.elementType} />
|
|
109
|
-
</span>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
case 'HttpTypeIntersection':
|
|
114
|
-
case 'HttpTypeUnion': {
|
|
115
|
-
const items = type.types.map((t, key) => <Lang.Type key={key} type={t} />);
|
|
116
|
-
|
|
117
|
-
const delimiter = type.kind === 'HttpTypeUnion' ? 'or' : 'and';
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<span className={style.Type}>
|
|
121
|
-
<span className={style.TypePreview} data-stldocs-type-preview="union">
|
|
122
|
-
<span className={style.TypePreviewContent}>
|
|
123
|
-
<Join items={items} limit={3}>
|
|
124
|
-
<span className={style.TextOperator}> {delimiter} </span>
|
|
125
|
-
</Join>
|
|
126
|
-
</span>
|
|
127
|
-
</span>
|
|
128
|
-
</span>
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
case 'HttpTypeReference': {
|
|
133
|
-
const name = type.ident.split('.').at(-1);
|
|
134
|
-
const params = type.typeParameters?.map((param, key) => <Lang.Type key={key} type={param} />);
|
|
135
|
-
|
|
136
|
-
// TODO: come up with an unambiguous way to identify these on the sdkjson side
|
|
137
|
-
// This is sketchy because it's possible for a user-defined type to be named "Record"
|
|
138
|
-
if (
|
|
139
|
-
name === 'Record' &&
|
|
140
|
-
type.typeParameters?.length === 2 &&
|
|
141
|
-
type.typeParameters?.at(0).kind === 'HttpTypeString'
|
|
142
|
-
)
|
|
143
|
-
return (
|
|
144
|
-
<>
|
|
145
|
-
<span className={style.TypeArray}>map</span>[{params?.[1]}]
|
|
146
|
-
</>
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<span className={style.Type}>
|
|
151
|
-
<SDKReference stainlessPath={type.$ref}>{name}</SDKReference>
|
|
152
|
-
{params && params.length > 0 && (
|
|
153
|
-
<>
|
|
154
|
-
<span className={style.TypeBracket}>{'<'}</span>
|
|
155
|
-
<Join items={params} limit={3}>
|
|
156
|
-
<span className={style.TextOperator}>, </span>
|
|
157
|
-
</Join>
|
|
158
|
-
<span className={style.TypeBracket}>{'>'}</span>
|
|
159
|
-
</>
|
|
160
|
-
)}
|
|
161
|
-
<TypePreview path={type.$ref} />
|
|
162
|
-
</span>
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
case 'HttpTypeObject':
|
|
167
|
-
const items = type.members.map(({ ident }) => (
|
|
168
|
-
<span className={style.TypePropertyName}>
|
|
169
|
-
<Identifier name={ident} />
|
|
170
|
-
</span>
|
|
171
|
-
));
|
|
172
|
-
|
|
173
|
-
return (
|
|
174
|
-
<span className={style.Type}>
|
|
175
|
-
<span className={style.TypePlain}>object</span>
|
|
176
|
-
<span className={style.TypePreview} data-stldocs-type-preview="properties">
|
|
177
|
-
<span className={style.TypeBrace}>{' {'}</span>
|
|
178
|
-
<span className={style.TypePreviewContent}>
|
|
179
|
-
{' '}
|
|
180
|
-
<Join items={items} limit={3}>
|
|
181
|
-
<span className={style.TextOperator}>, </span>
|
|
182
|
-
</Join>{' '}
|
|
183
|
-
</span>
|
|
184
|
-
<span className={style.TypeBrace}>{'} '}</span>
|
|
185
|
-
</span>
|
|
186
|
-
</span>
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export type MethodSignatureProps = {
|
|
192
|
-
decl: AST.HttpDeclFunction;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export function MethodSignature({ decl }: MethodSignatureProps) {
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export function MethodInfo({ decl, children }: MethodSignatureProps & { children: React.ReactNode }) {
|
|
200
|
-
const Docs = useComponents();
|
|
201
|
-
|
|
202
|
-
const params = Object.entries(decl.paramsChildren)
|
|
203
|
-
.filter(([_, value]) => value.length)
|
|
204
|
-
.map(([location, value]) => (
|
|
205
|
-
<React.Fragment key={location}>
|
|
206
|
-
<div className={style.MethodParameters} data-stldocs-property-group={location.at(0)}>
|
|
207
|
-
<h5>
|
|
208
|
-
{location.at(0).toUpperCase()}
|
|
209
|
-
{location.slice(1)} Parameters
|
|
210
|
-
<PropertyToggle target={location.at(0)} />
|
|
211
|
-
</h5>
|
|
212
|
-
<Docs.SDKChildren paths={value} />
|
|
213
|
-
</div>
|
|
214
|
-
</React.Fragment>
|
|
215
|
-
));
|
|
216
|
-
|
|
217
|
-
if (decl.bodyParamsChildren?.['application/json']?.length > 0)
|
|
218
|
-
params.push(
|
|
219
|
-
<div className={style.MethodInfoSection}>
|
|
220
|
-
<h5>
|
|
221
|
-
Body Parameters
|
|
222
|
-
<PropertyToggle target="body" />
|
|
223
|
-
</h5>
|
|
224
|
-
<div className={style.MethodParameters} data-stldocs-property-group="body">
|
|
225
|
-
<Docs.SDKChildren paths={decl.bodyParamsChildren?.['application/json']} />
|
|
226
|
-
</div>
|
|
227
|
-
</div>,
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
return (
|
|
231
|
-
<div className={style.MethodInfo}>
|
|
232
|
-
{children && <div className={style.MethodContent}>{children}</div>}
|
|
233
|
-
{params.length > 0 && params}
|
|
234
|
-
{decl.responseChildren.length > 0 && (
|
|
235
|
-
<div className={style.MethodInfoSection}>
|
|
236
|
-
<h5>
|
|
237
|
-
Returns
|
|
238
|
-
<PropertyToggle target="returns" />
|
|
239
|
-
</h5>
|
|
240
|
-
<div className={style.MethodReturns} data-stldocs-property-group="returns">
|
|
241
|
-
<Docs.SDKChildren paths={decl.responseChildren} />
|
|
242
|
-
</div>
|
|
243
|
-
</div>
|
|
244
|
-
)}
|
|
245
|
-
</div>
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function renderVariantInfo(type: AST.HttpType) {
|
|
250
|
-
if (
|
|
251
|
-
type.kind === 'HttpTypeUnion' &&
|
|
252
|
-
type.types.every((t) => t.kind === 'HttpTypeObject' || t.kind === 'HttpTypeReference')
|
|
253
|
-
)
|
|
254
|
-
return <>One of the following {type.types.length} object variants:</>;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export type PropertyProps = {
|
|
258
|
-
decl: AST.HttpDeclaration;
|
|
259
|
-
children?: PropertyFn;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
export function Property({ decl, children }: PropertyProps) {
|
|
263
|
-
const Lang = useLanguageComponents();
|
|
264
|
-
|
|
265
|
-
if (!decl) return;
|
|
266
|
-
|
|
267
|
-
switch (decl.kind) {
|
|
268
|
-
case 'HttpDeclProperty': {
|
|
269
|
-
const variants = renderVariantInfo(decl.type);
|
|
270
|
-
|
|
271
|
-
return children({
|
|
272
|
-
name: decl.key,
|
|
273
|
-
typeName: <Lang.TypeName type={decl.type} />,
|
|
274
|
-
type: decl.type.kind in ComplexTypes && !variants && <Lang.Type type={decl.type} />,
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
case 'HttpDeclTypeAlias':
|
|
279
|
-
return children({
|
|
280
|
-
name: decl.ident,
|
|
281
|
-
typeName: <Lang.TypeName type={decl.type} />,
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
case 'HttpDeclReference':
|
|
285
|
-
return children({ type: <Lang.Type type={decl.type} /> });
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export type DeclarationProps = { decl: AST.HttpDeclaration };
|
|
290
|
-
|
|
291
|
-
export function Declaration({ decl }: DeclarationProps) {
|
|
292
|
-
const Lang = useLanguageComponents();
|
|
293
|
-
|
|
294
|
-
if (!decl) return;
|
|
295
|
-
|
|
296
|
-
switch (decl.kind) {
|
|
297
|
-
case 'HttpDeclProperty':
|
|
298
|
-
return (
|
|
299
|
-
<>
|
|
300
|
-
<span className={style.TypePropertyName}>
|
|
301
|
-
<Identifier name={decl.key} />
|
|
302
|
-
</span>
|
|
303
|
-
<span className={style.TextPunctuation}>: </span>
|
|
304
|
-
{decl.optional && <span className={style.TextPunctuation}>optional </span>}
|
|
305
|
-
<Lang.Type type={decl.type} />
|
|
306
|
-
</>
|
|
307
|
-
);
|
|
308
|
-
|
|
309
|
-
case 'HttpDeclTypeAlias':
|
|
310
|
-
return (
|
|
311
|
-
<>
|
|
312
|
-
<Identifier name={decl.ident} />
|
|
313
|
-
<span className={style.TextOperator}> = </span>
|
|
314
|
-
<Lang.Type type={decl.type} />
|
|
315
|
-
</>
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
case 'HttpDeclReference':
|
|
319
|
-
return <Lang.Type type={decl.type} />;
|
|
320
|
-
}
|
|
321
|
-
}
|
package/src/languages/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
import type { DeclarationNode, Type } from '~/lib/json-spec-v2/types';
|
|
3
|
-
|
|
4
|
-
import * as typescript from './typescript';
|
|
5
|
-
import * as java from './java';
|
|
6
|
-
import { PropertyProps } from '../components';
|
|
7
|
-
|
|
8
|
-
export * as go from './go';
|
|
9
|
-
export * as python from './python';
|
|
10
|
-
export * as ruby from './ruby';
|
|
11
|
-
export * as http from './http';
|
|
12
|
-
|
|
13
|
-
export { typescript, java };
|
|
14
|
-
export const node = typescript;
|
|
15
|
-
export const kotlin = java;
|
|
16
|
-
|
|
17
|
-
export type PropertyFn = (params: PropertyProps) => ReactNode;
|
|
18
|
-
|
|
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 });
|
|
26
|
-
}
|