@stainless-api/docs-ui 0.1.0-beta.7 → 0.1.0-beta.70

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 (215) hide show
  1. package/dist/breadcrumbs-BhYwbXkc.d.ts +25 -0
  2. package/dist/breadcrumbs-Cvm5Ifm7.d.ts +25 -0
  3. package/dist/breadcrumbs-DA4WgDhR.js +63 -0
  4. package/dist/chunk-BN_g-Awi.js +18 -0
  5. package/dist/cli-F3kMmeoJ.js +166 -0
  6. package/dist/component-P9sn5yyG.js +23 -0
  7. package/dist/component-generics-ByGsYTc8.d.ts +30 -0
  8. package/dist/component-generics-POFirVVb.js +45 -0
  9. package/dist/component-generics-zU0Pqx8m.d.ts +30 -0
  10. package/dist/components/MaskedInput.d.ts +14 -0
  11. package/dist/components/MaskedInput.js +76 -0
  12. package/dist/components/breadcrumbs.d.ts +2 -0
  13. package/dist/components/breadcrumbs.js +9 -0
  14. package/dist/components/icons.d.ts +60 -0
  15. package/dist/components/icons.js +3 -0
  16. package/dist/components/index.d.ts +11 -0
  17. package/dist/components/index.js +19 -0
  18. package/dist/components/method.d.ts +2 -0
  19. package/dist/components/method.js +10 -0
  20. package/dist/components/overview.d.ts +2 -0
  21. package/dist/components/overview.js +11 -0
  22. package/dist/components/primitives.d.ts +2 -0
  23. package/dist/components/primitives.js +8 -0
  24. package/dist/components/properties.d.ts +2 -0
  25. package/dist/components/properties.js +9 -0
  26. package/dist/components/sdk-sidebar.d.ts +2 -0
  27. package/dist/components/sdk-sidebar.js +10 -0
  28. package/dist/components/sdk.d.ts +2 -0
  29. package/dist/components/sdk.js +10 -0
  30. package/dist/components/snippets.d.ts +3 -0
  31. package/dist/components/snippets.js +9 -0
  32. package/dist/components/stl-sidebar.d.ts +2 -0
  33. package/dist/components/stl-sidebar.js +5 -0
  34. package/dist/components-w1JmIrB0.js +71 -0
  35. package/dist/contexts/component-generics.d.ts +2 -0
  36. package/dist/contexts/component-generics.js +3 -0
  37. package/dist/contexts/component-types.d.ts +17 -0
  38. package/dist/contexts/component-types.js +0 -0
  39. package/dist/contexts/component.d.ts +30 -0
  40. package/dist/contexts/component.js +30 -0
  41. package/dist/contexts/docs.d.ts +2 -0
  42. package/dist/contexts/docs.js +3 -0
  43. package/dist/contexts/index.d.ts +23 -0
  44. package/dist/contexts/index.js +7 -0
  45. package/dist/contexts/markdown.d.ts +2 -0
  46. package/dist/contexts/markdown.js +4 -0
  47. package/dist/contexts/navigation.d.ts +2 -0
  48. package/dist/contexts/navigation.js +3 -0
  49. package/dist/contexts/use-components.d.ts +15 -0
  50. package/dist/contexts/use-components.js +4 -0
  51. package/dist/contexts-CVj20VV4.js +41 -0
  52. package/dist/csharp-D6_jlynY.js +283 -0
  53. package/dist/docs-BmOB2f-I.js +61 -0
  54. package/dist/docs-g4IPmtZr.d.ts +48 -0
  55. package/dist/docs-z3fl2eW-.d.ts +48 -0
  56. package/dist/go-COaHV3Hc.js +303 -0
  57. package/dist/http-fOPCX17A.js +389 -0
  58. package/dist/icons-BYKn5X8E.js +885 -0
  59. package/dist/index-B8Zys1C2.d.ts +347 -0
  60. package/dist/index-C5Zmb2CI.d.ts +16 -0
  61. package/dist/index-CwjGm9zX.d.ts +1722 -0
  62. package/dist/index-D7PkxNgB.d.ts +16 -0
  63. package/dist/index-DIaM6Ync.d.ts +347 -0
  64. package/dist/index.d.ts +20 -0
  65. package/dist/index.js +32 -7542
  66. package/dist/java-CxGSJVvv.js +403 -0
  67. package/dist/languages/cli.d.ts +12 -0
  68. package/dist/languages/cli.js +21 -0
  69. package/dist/languages/csharp.d.ts +12 -0
  70. package/dist/languages/csharp.js +9 -0
  71. package/dist/languages/go.d.ts +12 -0
  72. package/dist/languages/go.js +9 -0
  73. package/dist/languages/http.d.ts +12 -0
  74. package/dist/languages/http.js +20 -0
  75. package/dist/languages/index.d.ts +12 -0
  76. package/dist/languages/index.js +29 -0
  77. package/dist/languages/java.d.ts +12 -0
  78. package/dist/languages/java.js +9 -0
  79. package/dist/languages/python.d.ts +12 -0
  80. package/dist/languages/python.js +9 -0
  81. package/dist/languages/ruby.d.ts +12 -0
  82. package/dist/languages/ruby.js +9 -0
  83. package/dist/languages/terraform.d.ts +12 -0
  84. package/dist/languages/terraform.js +9 -0
  85. package/dist/languages/typescript.d.ts +12 -0
  86. package/dist/languages/typescript.js +9 -0
  87. package/dist/languages-B6eap2M6.js +30 -0
  88. package/dist/markdown/index.d.ts +12 -0
  89. package/dist/markdown/index.js +107 -0
  90. package/dist/markdown/md.d.ts +15 -0
  91. package/dist/markdown/md.js +41 -0
  92. package/dist/markdown/printer.d.ts +13 -0
  93. package/dist/markdown/printer.js +100 -0
  94. package/dist/markdown/utils.d.ts +21 -0
  95. package/dist/markdown/utils.js +31 -0
  96. package/dist/markdown-CTKHMLVr.js +49 -0
  97. package/dist/markdown-Cdh0TSHp.d.ts +22 -0
  98. package/dist/markdown-Cibv9fDR.d.ts +22 -0
  99. package/dist/method-630cPKDl.d.ts +59 -0
  100. package/dist/method-BPDUyBlD.js +96 -0
  101. package/dist/method-BzkPRXGL.d.ts +59 -0
  102. package/dist/navigation-BW-SBvb4.d.ts +29 -0
  103. package/dist/navigation-DWYqC_HX.d.ts +29 -0
  104. package/dist/navigation-aoYZ_tl4.js +24 -0
  105. package/dist/overview-Cui1XtuC.d.ts +39 -0
  106. package/dist/overview-DFwfIK6k.js +138 -0
  107. package/dist/overview-RXc9iPzz.d.ts +39 -0
  108. package/dist/primitives-DJEqe_r1.js +250 -0
  109. package/dist/primitives-DhGxFYx6.d.ts +105 -0
  110. package/dist/primitives-MsH-h0bU.d.ts +105 -0
  111. package/dist/properties-BnbBKd5a.js +132 -0
  112. package/dist/properties-Bynmj9_H.d.ts +54 -0
  113. package/dist/properties-C9W4QJ_F.d.ts +54 -0
  114. package/dist/python-DsTuWCKE.js +269 -0
  115. package/dist/routing-C64k4fmX.js +205 -0
  116. package/dist/routing-Cm_9XJiQ.d.ts +61 -0
  117. package/dist/routing-utiR5mY3.d.ts +61 -0
  118. package/dist/routing.d.ts +2 -0
  119. package/dist/routing.js +3 -180
  120. package/dist/ruby-BncKp6hd.js +387 -0
  121. package/dist/sdk-BvZeXpsj.d.ts +122 -0
  122. package/dist/sdk-Bw99eXxA.js +399 -0
  123. package/dist/sdk-GMOw94wL.d.ts +122 -0
  124. package/dist/sdk-sidebar-NCBSWuUW.d.ts +15 -0
  125. package/dist/sdk-sidebar-VNY2-O1Y.d.ts +15 -0
  126. package/dist/sdk-sidebar-V_MTkVw8.js +50 -0
  127. package/dist/snippets-BehbU3rt.js +164 -0
  128. package/dist/snippets-Bj7Ey56K.d.ts +53 -0
  129. package/dist/snippets-CQQSDvg2.d.ts +53 -0
  130. package/dist/spec.d.ts +65 -0
  131. package/dist/spec.js +167 -0
  132. package/dist/stl-sidebar-CXzs_shz.d.ts +58 -0
  133. package/dist/stl-sidebar-DSkUHwcU.d.ts +58 -0
  134. package/dist/stl-sidebar-WtimNrk1.js +106 -0
  135. package/dist/style-HpXpcJ9v.js +172 -0
  136. package/dist/style.d.ts +171 -0
  137. package/dist/style.js +3 -0
  138. package/dist/styles/main.css +744 -754
  139. package/dist/styles/main.js +0 -0
  140. package/dist/styles/primitives.css +327 -458
  141. package/dist/styles/primitives.js +0 -0
  142. package/dist/styles/resets.css +32 -41
  143. package/dist/styles/resets.js +0 -0
  144. package/dist/styles/search.css +192 -270
  145. package/dist/styles/search.js +0 -0
  146. package/dist/styles/sidebar.css +170 -69
  147. package/dist/styles/sidebar.js +0 -0
  148. package/dist/styles/variables.css +26 -89
  149. package/dist/styles/variables.js +0 -0
  150. package/dist/styles.css +3273 -0
  151. package/dist/styles.mjs +1 -0
  152. package/dist/terraform-B95X4rNK.js +243 -0
  153. package/dist/typescript-n46M9OtL.js +449 -0
  154. package/dist/use-components-BUz3GbO4.js +7 -0
  155. package/dist/utils-DPbkW1Tz.js +54 -0
  156. package/dist/utils.d.ts +20 -0
  157. package/dist/utils.js +3 -0
  158. package/package.json +74 -22
  159. package/dist/mcp.js +0 -16003
  160. package/dist/styles/snippets.css +0 -132
  161. package/src/components/breadcrumbs.tsx +0 -94
  162. package/src/components/chat.tsx +0 -154
  163. package/src/components/dropdown.tsx +0 -91
  164. package/src/components/icons.tsx +0 -584
  165. package/src/components/index.ts +0 -9
  166. package/src/components/method.tsx +0 -144
  167. package/src/components/overview.tsx +0 -159
  168. package/src/components/primitives.tsx +0 -284
  169. package/src/components/properties.tsx +0 -130
  170. package/src/components/scripts/dropdown.ts +0 -78
  171. package/src/components/sdk.tsx +0 -402
  172. package/src/components/sidebar.tsx +0 -99
  173. package/src/components/snippets.tsx +0 -179
  174. package/src/contexts/component-generics.tsx +0 -48
  175. package/src/contexts/component-types.tsx +0 -5
  176. package/src/contexts/component.tsx +0 -32
  177. package/src/contexts/docs.tsx +0 -75
  178. package/src/contexts/index.tsx +0 -17
  179. package/src/contexts/markdown.tsx +0 -43
  180. package/src/contexts/navigation.tsx +0 -44
  181. package/src/contexts/search.tsx +0 -28
  182. package/src/contexts/use-components.tsx +0 -4
  183. package/src/index.ts +0 -6
  184. package/src/languages/go.tsx +0 -281
  185. package/src/languages/http.tsx +0 -321
  186. package/src/languages/index.ts +0 -26
  187. package/src/languages/java.tsx +0 -358
  188. package/src/languages/python.tsx +0 -255
  189. package/src/languages/ruby.tsx +0 -320
  190. package/src/languages/typescript.tsx +0 -393
  191. package/src/markdown/index.ts +0 -107
  192. package/src/markdown/md.ts +0 -45
  193. package/src/markdown/utils.ts +0 -49
  194. package/src/routing.ts +0 -238
  195. package/src/search/form.tsx +0 -127
  196. package/src/search/index.tsx +0 -1
  197. package/src/search/indexer.ts +0 -246
  198. package/src/search/mcp.ts +0 -61
  199. package/src/search/printer.tsx +0 -86
  200. package/src/search/providers/algolia.ts +0 -88
  201. package/src/search/providers/fuse.ts +0 -19
  202. package/src/search/providers/pagefind.ts +0 -17
  203. package/src/search/providers/walker.ts +0 -30
  204. package/src/search/results.tsx +0 -181
  205. package/src/search/state.ts +0 -64
  206. package/src/search/types.ts +0 -116
  207. package/src/style.ts +0 -197
  208. package/src/styles/main.css +0 -993
  209. package/src/styles/primitives.css +0 -572
  210. package/src/styles/resets.css +0 -47
  211. package/src/styles/search.css +0 -342
  212. package/src/styles/sidebar.css +0 -87
  213. package/src/styles/snippets.css +0 -132
  214. package/src/styles/variables.css +0 -90
  215. package/src/utils.ts +0 -41
@@ -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
- }
@@ -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
- }
@@ -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
- }