@stainless-api/docs-ui 0.1.0-beta.29 → 0.1.0-beta.30

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.
Files changed (194) hide show
  1. package/dist/{breadcrumbs-D5viAm7a.d.ts → breadcrumbs-wJ7A9MGt.d.ts} +2 -2
  2. package/dist/{component-generics-BnrVqdQj.d.ts → component-generics--y1IC_M-.d.ts} +2 -1
  3. package/dist/{component-generics-Df4EDvxk.js → component-generics-D3ybuN5r.js} +5 -1
  4. package/dist/components/breadcrumbs.d.ts +1 -1
  5. package/dist/components/breadcrumbs.js +13 -14
  6. package/dist/components/chat.d.ts +3 -3
  7. package/dist/components/chat.js +64 -50
  8. package/dist/components/icons.d.ts +10 -10
  9. package/dist/components/icons.js +1 -1
  10. package/dist/components/index.d.ts +11 -12
  11. package/dist/components/index.js +14 -15
  12. package/dist/components/method.d.ts +1 -1
  13. package/dist/components/method.js +13 -14
  14. package/dist/components/overview.d.ts +1 -1
  15. package/dist/components/overview.js +13 -14
  16. package/dist/components/primitives.d.ts +1 -1
  17. package/dist/components/primitives.js +13 -14
  18. package/dist/components/properties.d.ts +1 -1
  19. package/dist/components/properties.js +13 -14
  20. package/dist/components/sdk.d.ts +2 -2
  21. package/dist/components/sdk.js +13 -14
  22. package/dist/components/sidebar.d.ts +1 -1
  23. package/dist/components/sidebar.js +13 -14
  24. package/dist/components/snippets.d.ts +3 -3
  25. package/dist/components/snippets.js +13 -14
  26. package/dist/contexts/component-generics.d.ts +1 -1
  27. package/dist/contexts/component-generics.js +1 -1
  28. package/dist/contexts/component-types.d.ts +11 -12
  29. package/dist/contexts/component-types.js +0 -1
  30. package/dist/contexts/component.d.ts +14 -14
  31. package/dist/contexts/component.js +13 -14
  32. package/dist/contexts/docs.d.ts +1 -1
  33. package/dist/contexts/docs.js +1 -1
  34. package/dist/contexts/index.d.ts +18 -19
  35. package/dist/contexts/index.js +13 -14
  36. package/dist/contexts/markdown.d.ts +1 -1
  37. package/dist/contexts/markdown.js +2 -2
  38. package/dist/contexts/navigation.d.ts +2 -2
  39. package/dist/contexts/navigation.js +1 -1
  40. package/dist/contexts/search.d.ts +3 -3
  41. package/dist/contexts/search.js +13 -14
  42. package/dist/contexts/use-components.d.ts +10 -11
  43. package/dist/contexts/use-components.js +2 -2
  44. package/dist/contexts-CMNI3ctP.js +3799 -0
  45. package/dist/{docs-DhNaW0DE.d.ts → docs-BvahWQ28.d.ts} +2 -1
  46. package/dist/{docs-Cj25B-Sh.js → docs-CopwX9a7.js} +5 -1
  47. package/dist/icons-yb-Jhkmg.js +753 -0
  48. package/dist/{index-d8_VR8Z5.d.ts → index-BmPNhnpe.d.ts} +6 -6
  49. package/dist/{index-BXO3gZup.d.ts → index-D5NMSAld.d.ts} +26 -25
  50. package/dist/index-rVFBdVz8.d.ts +15 -0
  51. package/dist/index.d.ts +20 -21
  52. package/dist/index.js +15 -7700
  53. package/dist/languages/go.d.ts +11 -12
  54. package/dist/languages/go.js +13 -14
  55. package/dist/languages/http.d.ts +11 -12
  56. package/dist/languages/http.js +13 -14
  57. package/dist/languages/index.d.ts +11 -12
  58. package/dist/languages/index.js +13 -14
  59. package/dist/languages/java.d.ts +11 -12
  60. package/dist/languages/java.js +13 -14
  61. package/dist/languages/python.d.ts +11 -12
  62. package/dist/languages/python.js +13 -14
  63. package/dist/languages/ruby.d.ts +11 -12
  64. package/dist/languages/ruby.js +13 -14
  65. package/dist/languages/typescript.d.ts +11 -12
  66. package/dist/languages/typescript.js +13 -14
  67. package/dist/markdown/index.d.ts +3 -3
  68. package/dist/markdown/index.js +13 -14
  69. package/dist/markdown/md.js +1 -1
  70. package/dist/markdown/utils.d.ts +3 -3
  71. package/dist/markdown/utils.js +1 -1
  72. package/dist/{markdown-DunIdqFE.js → markdown-BmpyokB7.js} +9 -5
  73. package/dist/{markdown-DN8KaRR2.d.ts → markdown-w5UpIiGc.d.ts} +2 -1
  74. package/dist/{method-c3XDArUn.d.ts → method-CLpRObBV.d.ts} +7 -6
  75. package/dist/{navigation-BSn6PX-7.d.ts → navigation-Blr3LaES.d.ts} +3 -2
  76. package/dist/{navigation-CuCg3le8.js → navigation-CGr5_w6z.js} +5 -1
  77. package/dist/{overview-D21weqVJ.d.ts → overview-DBnqhjAg.d.ts} +6 -6
  78. package/dist/{primitives-iB9fIrMF.d.ts → primitives-BFubD3w8.d.ts} +9 -8
  79. package/dist/{properties-Ba6F_GGj.d.ts → properties-DeQRa6VK.d.ts} +4 -4
  80. package/dist/{routing-C8oZYLsf.js → routing-8itEXLx6.js} +1 -1
  81. package/dist/{routing-BE6Vrs-z.d.ts → routing-DNN8R6bZ.d.ts} +1 -1
  82. package/dist/routing.d.ts +1 -1
  83. package/dist/routing.js +3 -180
  84. package/dist/{sdk-D2x2l6JH.d.ts → sdk-BVQyp5Dw.d.ts} +14 -13
  85. package/dist/search/index.d.ts +6 -6
  86. package/dist/search/index.js +233 -110
  87. package/dist/search/providers/algolia.d.ts +2 -2
  88. package/dist/search/providers/algolia.js +13 -14
  89. package/dist/search/providers/fuse.d.ts +2 -2
  90. package/dist/search/providers/fuse.js +13 -14
  91. package/dist/search/providers/pagefind.d.ts +2 -2
  92. package/dist/search/providers/pagefind.js +1 -1
  93. package/dist/search/providers/walker.d.ts +2 -2
  94. package/dist/search/providers/walker.js +13 -14
  95. package/dist/search/types.d.ts +2 -2
  96. package/dist/search/types.js +1 -1
  97. package/dist/{search-KMqOU2tz.d.ts → search-CPp6HpUy.d.ts} +3 -2
  98. package/dist/{sidebar-B1X4gmY2.d.ts → sidebar-BoPLeaxp.d.ts} +5 -4
  99. package/dist/{snippets-BApdMOXp.d.ts → snippets-DLHH_Voi.d.ts} +7 -6
  100. package/dist/{style-BWu-Pqcm.d.ts → style-BEMLtSIK.d.ts} +0 -10
  101. package/dist/{style-CkbsakoF.js → style-CPgcT0Fw.js} +1 -11
  102. package/dist/style.d.ts +1 -1
  103. package/dist/style.js +1 -1
  104. package/dist/styles/main.css +51 -20
  105. package/dist/styles/main.js +0 -0
  106. package/dist/styles/primitives.css +1 -0
  107. package/dist/styles/primitives.js +0 -0
  108. package/dist/styles/resets.css +1 -0
  109. package/dist/styles/resets.js +0 -0
  110. package/dist/styles/search.css +1 -0
  111. package/dist/styles/search.js +0 -0
  112. package/dist/styles/sidebar.css +1 -0
  113. package/dist/styles/sidebar.js +0 -0
  114. package/dist/styles/snippets.css +1 -0
  115. package/dist/styles/snippets.js +0 -0
  116. package/dist/styles/variables.css +2 -0
  117. package/dist/styles/variables.js +0 -0
  118. package/dist/{types-BLgvxY4i.d.ts → types-DNSz4kuM.d.ts} +1 -1
  119. package/dist/{use-components-DI-AbT-D.js → use-components-BHEwm0mE.js} +1 -1
  120. package/dist/{utils-BhYTrLot.js → utils-2FmcHPHp.js} +2 -2
  121. package/dist/{utils-B9JL_XWH.d.ts → utils-DVi3gJLL.d.ts} +2 -2
  122. package/dist/utils.d.ts +1 -1
  123. package/dist/utils.js +2 -2
  124. package/package.json +63 -10
  125. package/dist/components/dropdown.d.ts +0 -2
  126. package/dist/components/dropdown.js +0 -4
  127. package/dist/components/scripts/dropdown.d.ts +0 -12
  128. package/dist/components/scripts/dropdown.js +0 -50
  129. package/dist/contexts-DO0sMzym.js +0 -2581
  130. package/dist/dropdown-Dv9VAYCW.d.ts +0 -42
  131. package/dist/dropdown-kUhwBigR.js +0 -38
  132. package/dist/icons--8QR-PrL.js +0 -222
  133. package/dist/index-BW6OPqAo.d.ts +0 -16
  134. package/dist/mcp.cjs +0 -983418
  135. package/src/components/breadcrumbs.tsx +0 -94
  136. package/src/components/chat.tsx +0 -157
  137. package/src/components/icons.tsx +0 -584
  138. package/src/components/index.ts +0 -8
  139. package/src/components/method.tsx +0 -145
  140. package/src/components/overview.tsx +0 -172
  141. package/src/components/primitives.tsx +0 -301
  142. package/src/components/properties.tsx +0 -132
  143. package/src/components/sdk.tsx +0 -408
  144. package/src/components/sidebar.tsx +0 -99
  145. package/src/components/snippets.tsx +0 -197
  146. package/src/contexts/component-generics.tsx +0 -43
  147. package/src/contexts/component-types.tsx +0 -5
  148. package/src/contexts/component.tsx +0 -32
  149. package/src/contexts/docs.tsx +0 -86
  150. package/src/contexts/index.tsx +0 -20
  151. package/src/contexts/markdown.tsx +0 -44
  152. package/src/contexts/navigation.tsx +0 -44
  153. package/src/contexts/search.tsx +0 -27
  154. package/src/contexts/use-components.tsx +0 -4
  155. package/src/hooks/use-strict-context.tsx +0 -16
  156. package/src/index.ts +0 -6
  157. package/src/languages/go.tsx +0 -281
  158. package/src/languages/http.tsx +0 -329
  159. package/src/languages/index.ts +0 -26
  160. package/src/languages/java.tsx +0 -358
  161. package/src/languages/python.tsx +0 -258
  162. package/src/languages/ruby.tsx +0 -327
  163. package/src/languages/typescript.tsx +0 -399
  164. package/src/markdown/index.ts +0 -112
  165. package/src/markdown/md.ts +0 -45
  166. package/src/markdown/utils.ts +0 -52
  167. package/src/routing.ts +0 -238
  168. package/src/search/form.tsx +0 -130
  169. package/src/search/index.tsx +0 -1
  170. package/src/search/indexer.ts +0 -248
  171. package/src/search/mcp.ts +0 -156
  172. package/src/search/printer.tsx +0 -86
  173. package/src/search/providers/algolia.ts +0 -88
  174. package/src/search/providers/fuse.ts +0 -19
  175. package/src/search/providers/pagefind.ts +0 -17
  176. package/src/search/providers/walker.ts +0 -32
  177. package/src/search/results.tsx +0 -183
  178. package/src/search/state.ts +0 -64
  179. package/src/search/types.ts +0 -116
  180. package/src/style.ts +0 -185
  181. package/src/styles/main.css +0 -989
  182. package/src/styles/primitives.css +0 -392
  183. package/src/styles/resets.css +0 -39
  184. package/src/styles/search.css +0 -359
  185. package/src/styles/sidebar.css +0 -85
  186. package/src/styles/snippets.css +0 -130
  187. package/src/styles/variables.css +0 -86
  188. package/src/utils.ts +0 -40
  189. /package/dist/{chunk-Bp6m_JJh.js → chunk-DsStOjWQ.js} +0 -0
  190. /package/dist/{md-Dg8aOyMA.js → md-DxiV1_vy.js} +0 -0
  191. /package/dist/{pagefind-ChrPfuVv.js → pagefind-BaK1krMe.js} +0 -0
  192. /package/dist/{types-DFN4M1Sp.js → types-__XoFvJ_.js} +0 -0
  193. /package/dist/{utils-ByZH9QWT.js → utils-BCfb0F9R.js} +0 -0
  194. /package/dist/{utils-DlayebL1.d.ts → utils-D43p_yTd.d.ts} +0 -0
@@ -1,281 +0,0 @@
1
- import * as React from 'react';
2
- import { GoAST as AST } from '@stainless/sdk-json';
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
- {type.$ref ? <SDKReference stainlessPath={type.$ref}>{type.typeName}</SDKReference> : type.typeName}
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
- }
@@ -1,329 +0,0 @@
1
- import { HttpAST as AST } from '@stainless/sdk-json';
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: Record<string, string> = {
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, false);
38
- const { Join } = useComponents();
39
-
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
- )
44
- return;
45
-
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
- });
54
-
55
- return (
56
- <span className={style.TypePreview} data-stldocs-type-preview="properties">
57
- <span className={style.TypeBrace}>{' { '}</span>
58
- <span className={style.TypePreviewContent}>
59
- <Join items={items} limit={3}>
60
- <span className={style.TextOperator}>, </span>
61
- </Join>
62
- </span>
63
- <span className={style.TypeBrace}>{' } '}</span>
64
- </span>
65
- );
66
- }
67
-
68
- export function TypeName({ type }: TypeProps) {
69
- const Lang = useLanguageComponents();
70
-
71
- if (type.kind === 'HttpTypeArray') return <>array of {<Lang.TypeName type={type.elementType} />}</>;
72
-
73
- if (type.kind === 'HttpTypeUnion' && type.types.every((t) => t.kind === 'HttpTypeLiteral')) return 'enum';
74
-
75
- if (type.kind === 'HttpTypeReference' && type.ident.split('.').at(-1) === 'Record') return 'map';
76
-
77
- return ComplexTypes[type.kind] ?? <Lang.Type type={type} />;
78
- }
79
-
80
- export function Type({ type }: TypeProps) {
81
- const Lang = useLanguageComponents();
82
- const { Join, SDKReference } = useComponents();
83
-
84
- switch (type.kind) {
85
- case 'HttpTypeUnknown':
86
- case 'HttpTypeUndefined':
87
- case 'HttpTypeNull':
88
- case 'HttpTypeBoolean':
89
- case 'HttpTypeNumber':
90
- return (
91
- <span className={style.Type}>
92
- <span className={style.TypePlain}>{type.kind.slice(8).toLowerCase()}</span>
93
- </span>
94
- );
95
-
96
- case 'HttpTypeString':
97
- return (
98
- <span className={style.Type}>
99
- <span className={style.TypePlain}>string</span>
100
- </span>
101
- );
102
-
103
- case 'HttpTypeLiteral':
104
- return (
105
- <span className={style.Type}>
106
- <span className={constStyle[typeof type.literal]}>{JSON.stringify(type.literal)}</span>
107
- </span>
108
- );
109
-
110
- case 'HttpTypeArray': {
111
- return (
112
- <span className={style.Type}>
113
- <span className={style.TypeArray}>{'array of '}</span>
114
- <Lang.Type type={type.elementType} />
115
- </span>
116
- );
117
- }
118
-
119
- case 'HttpTypeIntersection':
120
- case 'HttpTypeUnion': {
121
- const items = type.types.map((t, key) => <Lang.Type key={key} type={t} />);
122
-
123
- const delimiter = type.kind === 'HttpTypeUnion' ? 'or' : 'and';
124
-
125
- return (
126
- <span className={style.Type}>
127
- <span className={style.TypePreview} data-stldocs-type-preview="union">
128
- <span className={style.TypePreviewContent}>
129
- <Join items={items} limit={3}>
130
- <span className={style.TextOperator}> {delimiter} </span>
131
- </Join>
132
- </span>
133
- </span>
134
- </span>
135
- );
136
- }
137
-
138
- case 'HttpTypeReference': {
139
- const name = type.ident.split('.').at(-1);
140
- const params = type.typeParameters?.map((param, key) => <Lang.Type key={key} type={param} />);
141
-
142
- // TODO: come up with an unambiguous way to identify these on the sdkjson side
143
- // This is sketchy because it's possible for a user-defined type to be named "Record"
144
- if (
145
- name === 'Record' &&
146
- type.typeParameters?.length === 2 &&
147
- type.typeParameters?.at(0)!.kind === 'HttpTypeString'
148
- )
149
- return (
150
- <>
151
- <span className={style.TypeArray}>map</span>[{params?.[1]}]
152
- </>
153
- );
154
-
155
- return (
156
- <span className={style.Type}>
157
- <SDKReference stainlessPath={type.$ref!}>{name}</SDKReference>
158
- {params && params.length > 0 && (
159
- <>
160
- <span className={style.TypeBracket}>{'<'}</span>
161
- <Join items={params} limit={3}>
162
- <span className={style.TextOperator}>, </span>
163
- </Join>
164
- <span className={style.TypeBracket}>{'>'}</span>
165
- </>
166
- )}
167
- <TypePreview path={type.$ref!} />
168
- </span>
169
- );
170
- }
171
-
172
- case 'HttpTypeObject': {
173
- const items = type.members.map(({ ident }) => (
174
- <span className={style.TypePropertyName} key={ident}>
175
- <Identifier name={ident} />
176
- </span>
177
- ));
178
-
179
- return (
180
- <span className={style.Type}>
181
- <span className={style.TypePlain}>object</span>
182
- <span className={style.TypePreview} data-stldocs-type-preview="properties">
183
- <span className={style.TypeBrace}>{' {'}</span>
184
- <span className={style.TypePreviewContent}>
185
- {' '}
186
- <Join items={items} limit={3}>
187
- <span className={style.TextOperator}>, </span>
188
- </Join>{' '}
189
- </span>
190
- <span className={style.TypeBrace}>{'} '}</span>
191
- </span>
192
- </span>
193
- );
194
- }
195
- }
196
- }
197
-
198
- export type MethodSignatureProps = {
199
- decl: AST.HttpDeclFunction;
200
- };
201
-
202
- export function MethodSignature({ decl }: MethodSignatureProps) {
203
- void decl;
204
- return null;
205
- }
206
-
207
- export function MethodInfo({ decl, children }: MethodSignatureProps & { children: React.ReactNode }) {
208
- const Docs = useComponents();
209
-
210
- const params = Object.entries(decl.paramsChildren!)
211
- .filter(([, value]) => value.length)
212
- .map(([location, value]) => (
213
- <React.Fragment key={location}>
214
- <div className={style.MethodParameters} data-stldocs-property-group={location.at(0)}>
215
- <h5>
216
- {location.at(0)!.toUpperCase()}
217
- {location.slice(1)} Parameters
218
- <PropertyToggle target={location.at(0)!} />
219
- </h5>
220
- <Docs.SDKChildren paths={value} />
221
- </div>
222
- </React.Fragment>
223
- ));
224
-
225
- if ((decl.bodyParamsChildren?.['application/json']?.length ?? 0) > 0)
226
- params.push(
227
- <div className={style.MethodInfoSection}>
228
- <h5>
229
- Body Parameters
230
- <PropertyToggle target="body" />
231
- </h5>
232
- <div className={style.MethodParameters} data-stldocs-property-group="body">
233
- <Docs.SDKChildren paths={decl.bodyParamsChildren?.['application/json'] ?? []} />
234
- </div>
235
- </div>,
236
- );
237
-
238
- return (
239
- <div className={style.MethodInfo}>
240
- {children && <div className={style.MethodContent}>{children}</div>}
241
- {params.length > 0 && params}
242
- {(decl.responseChildren?.length ?? 0) > 0 && (
243
- <div className={style.MethodInfoSection}>
244
- <h5>
245
- Returns
246
- <PropertyToggle target="returns" />
247
- </h5>
248
- <div className={style.MethodReturns} data-stldocs-property-group="returns">
249
- <Docs.SDKChildren paths={decl.responseChildren ?? []} />
250
- </div>
251
- </div>
252
- )}
253
- </div>
254
- );
255
- }
256
-
257
- function renderVariantInfo(type: AST.HttpType) {
258
- if (
259
- type.kind === 'HttpTypeUnion' &&
260
- type.types.every((t) => t.kind === 'HttpTypeObject' || t.kind === 'HttpTypeReference')
261
- )
262
- return <>One of the following {type.types.length} object variants:</>;
263
- }
264
-
265
- export type PropertyProps = {
266
- decl: AST.HttpDeclaration;
267
- children: PropertyFn;
268
- };
269
-
270
- export function Property({ decl, children }: PropertyProps) {
271
- const Lang = useLanguageComponents();
272
-
273
- if (!decl) return;
274
-
275
- switch (decl.kind) {
276
- case 'HttpDeclProperty': {
277
- const variants = renderVariantInfo(decl.type);
278
-
279
- return children({
280
- name: decl.key,
281
- typeName: <Lang.TypeName type={decl.type} />,
282
- type: decl.type.kind in ComplexTypes && !variants && <Lang.Type type={decl.type} />,
283
- });
284
- }
285
-
286
- case 'HttpDeclTypeAlias':
287
- return children({
288
- name: decl.ident,
289
- typeName: <Lang.TypeName type={decl.type} />,
290
- });
291
-
292
- case 'HttpDeclReference':
293
- return children({ type: <Lang.Type type={decl.type} /> });
294
- }
295
- }
296
-
297
- export type DeclarationProps = { decl: AST.HttpDeclaration };
298
-
299
- export function Declaration({ decl }: DeclarationProps) {
300
- const Lang = useLanguageComponents();
301
-
302
- if (!decl) return;
303
-
304
- switch (decl.kind) {
305
- case 'HttpDeclProperty':
306
- return (
307
- <>
308
- <span className={style.TypePropertyName}>
309
- <Identifier name={decl.key} />
310
- </span>
311
- <span className={style.TextPunctuation}>: </span>
312
- {decl.optional && <span className={style.TextPunctuation}>optional </span>}
313
- <Lang.Type type={decl.type} />
314
- </>
315
- );
316
-
317
- case 'HttpDeclTypeAlias':
318
- return (
319
- <>
320
- <Identifier name={decl.ident} />
321
- <span className={style.TextOperator}> = </span>
322
- <Lang.Type type={decl.type} />
323
- </>
324
- );
325
-
326
- case 'HttpDeclReference':
327
- return <Lang.Type type={decl.type} />;
328
- }
329
- }
@@ -1,26 +0,0 @@
1
- import { type ReactNode } from 'react';
2
- import type { DeclarationNode, Type } from '@stainless/sdk-json';
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 }): 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
- }