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