@stainless-api/docs-ui 0.1.0-beta.4 → 0.1.0-beta.40

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 (188) hide show
  1. package/dist/breadcrumbs-CZg0Fk4V.d.ts +20 -0
  2. package/dist/chunk-Bf_Gc_jT.js +18 -0
  3. package/dist/component-generics-BLXXX1dz.d.ts +30 -0
  4. package/dist/component-generics-D3ybuN5r.js +45 -0
  5. package/dist/components/breadcrumbs.d.ts +2 -0
  6. package/dist/components/breadcrumbs.js +15 -0
  7. package/dist/components/icons.d.ts +50 -0
  8. package/dist/components/icons.js +3 -0
  9. package/dist/components/index.d.ts +11 -0
  10. package/dist/components/index.js +15 -0
  11. package/dist/components/method.d.ts +2 -0
  12. package/dist/components/method.js +15 -0
  13. package/dist/components/overview.d.ts +2 -0
  14. package/dist/components/overview.js +15 -0
  15. package/dist/components/primitives.d.ts +2 -0
  16. package/dist/components/primitives.js +15 -0
  17. package/dist/components/properties.d.ts +2 -0
  18. package/dist/components/properties.js +15 -0
  19. package/dist/components/sdk.d.ts +3 -0
  20. package/dist/components/sdk.js +15 -0
  21. package/dist/components/sidebar.d.ts +2 -0
  22. package/dist/components/sidebar.js +15 -0
  23. package/dist/components/snippets.d.ts +4 -0
  24. package/dist/components/snippets.js +15 -0
  25. package/dist/contexts/component-generics.d.ts +2 -0
  26. package/dist/contexts/component-generics.js +3 -0
  27. package/dist/contexts/component-types.d.ts +17 -0
  28. package/dist/contexts/component-types.js +0 -0
  29. package/dist/contexts/component.d.ts +30 -0
  30. package/dist/contexts/component.js +15 -0
  31. package/dist/contexts/docs.d.ts +2 -0
  32. package/dist/contexts/docs.js +3 -0
  33. package/dist/contexts/index.d.ts +19 -0
  34. package/dist/contexts/index.js +15 -0
  35. package/dist/contexts/markdown.d.ts +2 -0
  36. package/dist/contexts/markdown.js +4 -0
  37. package/dist/contexts/navigation.d.ts +3 -0
  38. package/dist/contexts/navigation.js +3 -0
  39. package/dist/contexts/search.d.ts +4 -0
  40. package/dist/contexts/search.js +15 -0
  41. package/dist/contexts/use-components.d.ts +15 -0
  42. package/dist/contexts/use-components.js +4 -0
  43. package/dist/contexts-B-OYzYpz.js +3837 -0
  44. package/dist/docs-BeJaKOCE.d.ts +46 -0
  45. package/dist/docs-CopwX9a7.js +54 -0
  46. package/dist/icons-yb-Jhkmg.js +753 -0
  47. package/dist/index-CBi59jcw.d.ts +240 -0
  48. package/dist/index-DT1wzg21.d.ts +15 -0
  49. package/dist/index-DteYqCJO.d.ts +14 -0
  50. package/dist/index.d.ts +21 -0
  51. package/dist/index.js +15 -7542
  52. package/dist/languages/go.d.ts +12 -0
  53. package/dist/languages/go.js +15 -0
  54. package/dist/languages/http.d.ts +12 -0
  55. package/dist/languages/http.js +15 -0
  56. package/dist/languages/index.d.ts +12 -0
  57. package/dist/languages/index.js +15 -0
  58. package/dist/languages/java.d.ts +12 -0
  59. package/dist/languages/java.js +15 -0
  60. package/dist/languages/python.d.ts +12 -0
  61. package/dist/languages/python.js +15 -0
  62. package/dist/languages/ruby.d.ts +12 -0
  63. package/dist/languages/ruby.js +15 -0
  64. package/dist/languages/typescript.d.ts +12 -0
  65. package/dist/languages/typescript.js +15 -0
  66. package/dist/markdown/index.d.ts +12 -0
  67. package/dist/markdown/index.js +15 -0
  68. package/dist/markdown/md.d.ts +15 -0
  69. package/dist/markdown/md.js +3 -0
  70. package/dist/markdown/utils.d.ts +4 -0
  71. package/dist/markdown/utils.js +3 -0
  72. package/dist/markdown-DTVxnxGP.d.ts +22 -0
  73. package/dist/markdown-Diyg-eof.js +48 -0
  74. package/dist/md-DxiV1_vy.js +41 -0
  75. package/dist/method-DHjDGGA_.d.ts +71 -0
  76. package/dist/navigation-CGr5_w6z.js +24 -0
  77. package/dist/navigation-rt_B_1lt.d.ts +29 -0
  78. package/dist/overview-CKJV2xUO.d.ts +39 -0
  79. package/dist/pagefind-BaK1krMe.js +15 -0
  80. package/dist/primitives-CiVFjnRA.d.ts +99 -0
  81. package/dist/properties-Z45x-uLZ.d.ts +46 -0
  82. package/dist/routing-DNN8R6bZ.d.ts +54 -0
  83. package/dist/routing-qs2YNG9o.js +189 -0
  84. package/dist/routing.d.ts +2 -0
  85. package/dist/routing.js +3 -180
  86. package/dist/sdk-DDWWoPPD.d.ts +119 -0
  87. package/dist/search/index.d.ts +26 -0
  88. package/dist/search/index.js +334 -0
  89. package/dist/search/providers/algolia.d.ts +24 -0
  90. package/dist/search/providers/algolia.js +15 -0
  91. package/dist/search/providers/fuse.d.ts +18 -0
  92. package/dist/search/providers/fuse.js +30 -0
  93. package/dist/search/providers/pagefind.d.ts +7 -0
  94. package/dist/search/providers/pagefind.js +3 -0
  95. package/dist/search/providers/walker.d.ts +9 -0
  96. package/dist/search/providers/walker.js +34 -0
  97. package/dist/search/types.d.ts +3 -0
  98. package/dist/search/types.js +3 -0
  99. package/dist/search-CCDWCiAd.d.ts +21 -0
  100. package/dist/sidebar-DrtsF85U.d.ts +36 -0
  101. package/dist/snippets-B2EEG7AK.d.ts +46 -0
  102. package/dist/spec.d.ts +65 -0
  103. package/dist/spec.js +167 -0
  104. package/dist/style-BhhgPVF6.js +165 -0
  105. package/dist/style-p4qTfnmO.d.ts +164 -0
  106. package/dist/style.d.ts +2 -0
  107. package/dist/style.js +3 -0
  108. package/dist/styles/main.css +724 -754
  109. package/dist/styles/main.js +0 -0
  110. package/dist/styles/primitives.css +287 -466
  111. package/dist/styles/primitives.js +0 -0
  112. package/dist/styles/resets.css +31 -41
  113. package/dist/styles/resets.js +0 -0
  114. package/dist/styles/search.css +175 -274
  115. package/dist/styles/search.js +0 -0
  116. package/dist/styles/sidebar.css +59 -60
  117. package/dist/styles/sidebar.js +0 -0
  118. package/dist/styles/variables.css +26 -89
  119. package/dist/styles/variables.js +0 -0
  120. package/dist/styles.css +1753 -0
  121. package/dist/styles.mjs +1 -0
  122. package/dist/types-DNSz4kuM.d.ts +83 -0
  123. package/dist/types-__XoFvJ_.js +34 -0
  124. package/dist/use-components-BHEwm0mE.js +7 -0
  125. package/dist/utils-CA3mYNaX.d.ts +21 -0
  126. package/dist/utils-D43p_yTd.d.ts +14 -0
  127. package/dist/utils-FnJ4tyuN.js +32 -0
  128. package/dist/utils-Jo_o4DX9.js +31 -0
  129. package/dist/utils.d.ts +2 -0
  130. package/dist/utils.js +4 -0
  131. package/package.json +84 -19
  132. package/dist/mcp.js +0 -16003
  133. package/dist/styles/snippets.css +0 -132
  134. package/src/components/breadcrumbs.tsx +0 -94
  135. package/src/components/chat.tsx +0 -154
  136. package/src/components/dropdown.tsx +0 -91
  137. package/src/components/icons.tsx +0 -584
  138. package/src/components/index.ts +0 -9
  139. package/src/components/method.tsx +0 -144
  140. package/src/components/overview.tsx +0 -159
  141. package/src/components/primitives.tsx +0 -284
  142. package/src/components/properties.tsx +0 -130
  143. package/src/components/scripts/dropdown.ts +0 -78
  144. package/src/components/sdk.tsx +0 -402
  145. package/src/components/sidebar.tsx +0 -99
  146. package/src/components/snippets.tsx +0 -179
  147. package/src/contexts/component-generics.tsx +0 -48
  148. package/src/contexts/component-types.tsx +0 -5
  149. package/src/contexts/component.tsx +0 -32
  150. package/src/contexts/docs.tsx +0 -75
  151. package/src/contexts/index.tsx +0 -17
  152. package/src/contexts/markdown.tsx +0 -43
  153. package/src/contexts/navigation.tsx +0 -44
  154. package/src/contexts/search.tsx +0 -28
  155. package/src/contexts/use-components.tsx +0 -4
  156. package/src/index.ts +0 -6
  157. package/src/languages/go.tsx +0 -281
  158. package/src/languages/http.tsx +0 -321
  159. package/src/languages/index.ts +0 -26
  160. package/src/languages/java.tsx +0 -358
  161. package/src/languages/python.tsx +0 -255
  162. package/src/languages/ruby.tsx +0 -320
  163. package/src/languages/typescript.tsx +0 -393
  164. package/src/markdown/index.ts +0 -107
  165. package/src/markdown/md.ts +0 -45
  166. package/src/markdown/utils.ts +0 -49
  167. package/src/routing.ts +0 -238
  168. package/src/search/form.tsx +0 -127
  169. package/src/search/index.tsx +0 -1
  170. package/src/search/indexer.ts +0 -246
  171. package/src/search/mcp.ts +0 -61
  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 -30
  177. package/src/search/results.tsx +0 -181
  178. package/src/search/state.ts +0 -64
  179. package/src/search/types.ts +0 -116
  180. package/src/style.ts +0 -197
  181. package/src/styles/main.css +0 -993
  182. package/src/styles/primitives.css +0 -572
  183. package/src/styles/resets.css +0 -47
  184. package/src/styles/search.css +0 -342
  185. package/src/styles/sidebar.css +0 -87
  186. package/src/styles/snippets.css +0 -132
  187. package/src/styles/variables.css +0 -90
  188. 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
- }