@stainless-api/docs-ui 0.1.0-beta.3 → 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 (187) hide show
  1. package/dist/breadcrumbs-wJ7A9MGt.d.ts +20 -0
  2. package/dist/chunk-DsStOjWQ.js +13 -0
  3. package/dist/component-generics--y1IC_M-.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/chat.d.ts +14 -0
  8. package/dist/components/chat.js +142 -0
  9. package/dist/components/icons.d.ts +50 -0
  10. package/dist/components/icons.js +3 -0
  11. package/dist/components/index.d.ts +11 -0
  12. package/dist/components/index.js +15 -0
  13. package/dist/components/method.d.ts +2 -0
  14. package/dist/components/method.js +15 -0
  15. package/dist/components/overview.d.ts +2 -0
  16. package/dist/components/overview.js +15 -0
  17. package/dist/components/primitives.d.ts +2 -0
  18. package/dist/components/primitives.js +15 -0
  19. package/dist/components/properties.d.ts +2 -0
  20. package/dist/components/properties.js +15 -0
  21. package/dist/components/sdk.d.ts +3 -0
  22. package/dist/components/sdk.js +15 -0
  23. package/dist/components/sidebar.d.ts +2 -0
  24. package/dist/components/sidebar.js +15 -0
  25. package/dist/components/snippets.d.ts +4 -0
  26. package/dist/components/snippets.js +15 -0
  27. package/dist/contexts/component-generics.d.ts +2 -0
  28. package/dist/contexts/component-generics.js +3 -0
  29. package/dist/contexts/component-types.d.ts +17 -0
  30. package/dist/contexts/component-types.js +0 -0
  31. package/dist/contexts/component.d.ts +30 -0
  32. package/dist/contexts/component.js +15 -0
  33. package/dist/contexts/docs.d.ts +2 -0
  34. package/dist/contexts/docs.js +3 -0
  35. package/dist/contexts/index.d.ts +19 -0
  36. package/dist/contexts/index.js +15 -0
  37. package/dist/contexts/markdown.d.ts +2 -0
  38. package/dist/contexts/markdown.js +4 -0
  39. package/dist/contexts/navigation.d.ts +3 -0
  40. package/dist/contexts/navigation.js +3 -0
  41. package/dist/contexts/search.d.ts +4 -0
  42. package/dist/contexts/search.js +15 -0
  43. package/dist/contexts/use-components.d.ts +15 -0
  44. package/dist/contexts/use-components.js +4 -0
  45. package/dist/contexts-CMNI3ctP.js +3799 -0
  46. package/dist/docs-BvahWQ28.d.ts +46 -0
  47. package/dist/docs-CopwX9a7.js +54 -0
  48. package/dist/icons-yb-Jhkmg.js +753 -0
  49. package/dist/index-BmPNhnpe.d.ts +14 -0
  50. package/dist/index-D5NMSAld.d.ts +240 -0
  51. package/dist/index-rVFBdVz8.d.ts +15 -0
  52. package/dist/index.d.ts +21 -0
  53. package/dist/index.js +15 -7542
  54. package/dist/languages/go.d.ts +12 -0
  55. package/dist/languages/go.js +15 -0
  56. package/dist/languages/http.d.ts +12 -0
  57. package/dist/languages/http.js +15 -0
  58. package/dist/languages/index.d.ts +12 -0
  59. package/dist/languages/index.js +15 -0
  60. package/dist/languages/java.d.ts +12 -0
  61. package/dist/languages/java.js +15 -0
  62. package/dist/languages/python.d.ts +12 -0
  63. package/dist/languages/python.js +15 -0
  64. package/dist/languages/ruby.d.ts +12 -0
  65. package/dist/languages/ruby.js +15 -0
  66. package/dist/languages/typescript.d.ts +12 -0
  67. package/dist/languages/typescript.js +15 -0
  68. package/dist/markdown/index.d.ts +12 -0
  69. package/dist/markdown/index.js +15 -0
  70. package/dist/markdown/md.d.ts +15 -0
  71. package/dist/markdown/md.js +3 -0
  72. package/dist/markdown/utils.d.ts +4 -0
  73. package/dist/markdown/utils.js +3 -0
  74. package/dist/markdown-BmpyokB7.js +43 -0
  75. package/dist/markdown-w5UpIiGc.d.ts +22 -0
  76. package/dist/md-DxiV1_vy.js +41 -0
  77. package/dist/method-CLpRObBV.d.ts +71 -0
  78. package/dist/navigation-Blr3LaES.d.ts +29 -0
  79. package/dist/navigation-CGr5_w6z.js +24 -0
  80. package/dist/overview-DBnqhjAg.d.ts +39 -0
  81. package/dist/pagefind-BaK1krMe.js +15 -0
  82. package/dist/primitives-BFubD3w8.d.ts +99 -0
  83. package/dist/properties-DeQRa6VK.d.ts +46 -0
  84. package/dist/routing-8itEXLx6.js +189 -0
  85. package/dist/routing-DNN8R6bZ.d.ts +54 -0
  86. package/dist/routing.d.ts +2 -0
  87. package/dist/routing.js +3 -180
  88. package/dist/sdk-BVQyp5Dw.d.ts +119 -0
  89. package/dist/search/index.d.ts +26 -0
  90. package/dist/search/index.js +334 -0
  91. package/dist/search/providers/algolia.d.ts +24 -0
  92. package/dist/search/providers/algolia.js +15 -0
  93. package/dist/search/providers/fuse.d.ts +18 -0
  94. package/dist/search/providers/fuse.js +30 -0
  95. package/dist/search/providers/pagefind.d.ts +7 -0
  96. package/dist/search/providers/pagefind.js +3 -0
  97. package/dist/search/providers/walker.d.ts +9 -0
  98. package/dist/search/providers/walker.js +34 -0
  99. package/dist/search/types.d.ts +3 -0
  100. package/dist/search/types.js +3 -0
  101. package/dist/search-CPp6HpUy.d.ts +21 -0
  102. package/dist/sidebar-BoPLeaxp.d.ts +36 -0
  103. package/dist/snippets-DLHH_Voi.d.ts +46 -0
  104. package/dist/style-BEMLtSIK.d.ts +172 -0
  105. package/dist/style-CPgcT0Fw.js +173 -0
  106. package/dist/style.d.ts +2 -0
  107. package/dist/style.js +3 -0
  108. package/dist/styles/main.css +763 -736
  109. package/dist/styles/main.js +0 -0
  110. package/dist/styles/primitives.css +285 -464
  111. package/dist/styles/primitives.js +0 -0
  112. package/dist/styles/resets.css +34 -41
  113. package/dist/styles/resets.js +0 -0
  114. package/dist/styles/search.css +266 -248
  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/snippets.css +87 -88
  119. package/dist/styles/snippets.js +0 -0
  120. package/dist/styles/variables.css +87 -89
  121. package/dist/styles/variables.js +0 -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-2FmcHPHp.js +32 -0
  126. package/dist/utils-BCfb0F9R.js +30 -0
  127. package/dist/utils-D43p_yTd.d.ts +14 -0
  128. package/dist/utils-DVi3gJLL.d.ts +21 -0
  129. package/dist/utils.d.ts +2 -0
  130. package/dist/utils.js +4 -0
  131. package/package.json +78 -16
  132. package/dist/mcp.js +0 -16003
  133. package/src/components/breadcrumbs.tsx +0 -94
  134. package/src/components/chat.tsx +0 -154
  135. package/src/components/dropdown.tsx +0 -91
  136. package/src/components/icons.tsx +0 -584
  137. package/src/components/index.ts +0 -9
  138. package/src/components/method.tsx +0 -144
  139. package/src/components/overview.tsx +0 -159
  140. package/src/components/primitives.tsx +0 -284
  141. package/src/components/properties.tsx +0 -130
  142. package/src/components/scripts/dropdown.ts +0 -78
  143. package/src/components/sdk.tsx +0 -402
  144. package/src/components/sidebar.tsx +0 -99
  145. package/src/components/snippets.tsx +0 -179
  146. package/src/contexts/component-generics.tsx +0 -48
  147. package/src/contexts/component-types.tsx +0 -5
  148. package/src/contexts/component.tsx +0 -32
  149. package/src/contexts/docs.tsx +0 -75
  150. package/src/contexts/index.tsx +0 -17
  151. package/src/contexts/markdown.tsx +0 -43
  152. package/src/contexts/navigation.tsx +0 -44
  153. package/src/contexts/search.tsx +0 -28
  154. package/src/contexts/use-components.tsx +0 -4
  155. package/src/index.ts +0 -6
  156. package/src/languages/go.tsx +0 -281
  157. package/src/languages/http.tsx +0 -321
  158. package/src/languages/index.ts +0 -26
  159. package/src/languages/java.tsx +0 -358
  160. package/src/languages/python.tsx +0 -255
  161. package/src/languages/ruby.tsx +0 -320
  162. package/src/languages/typescript.tsx +0 -393
  163. package/src/markdown/index.ts +0 -107
  164. package/src/markdown/md.ts +0 -45
  165. package/src/markdown/utils.ts +0 -49
  166. package/src/routing.ts +0 -238
  167. package/src/search/form.tsx +0 -127
  168. package/src/search/index.tsx +0 -1
  169. package/src/search/indexer.ts +0 -246
  170. package/src/search/mcp.ts +0 -61
  171. package/src/search/printer.tsx +0 -86
  172. package/src/search/providers/algolia.ts +0 -88
  173. package/src/search/providers/fuse.ts +0 -19
  174. package/src/search/providers/pagefind.ts +0 -17
  175. package/src/search/providers/walker.ts +0 -30
  176. package/src/search/results.tsx +0 -181
  177. package/src/search/state.ts +0 -64
  178. package/src/search/types.ts +0 -116
  179. package/src/style.ts +0 -197
  180. package/src/styles/main.css +0 -993
  181. package/src/styles/primitives.css +0 -572
  182. package/src/styles/resets.css +0 -47
  183. package/src/styles/search.css +0 -342
  184. package/src/styles/sidebar.css +0 -87
  185. package/src/styles/snippets.css +0 -132
  186. package/src/styles/variables.css +0 -90
  187. package/src/utils.ts +0 -41
@@ -1,393 +0,0 @@
1
- import * as React from 'react';
2
- import type * as TSAST from '~/lib/json-spec-v2/TSAST';
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 = {
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);
70
- const { Join } = useComponents();
71
-
72
- if (!(decl && 'children' in decl && decl.children.length > 0) || decl['type']?.['kind'] === 'TSTypeUnion')
73
- return;
74
-
75
- const items = decl.children.map((prop, key) => (
76
- <span key={key} className={style.TypePropertyName}>
77
- <span className={style.TextIdentifier}>{spec?.decls?.[language]?.[prop]?.['key']}</span>
78
- </span>
79
- ));
80
-
81
- return (
82
- <span className={style.TypePreview} data-stldocs-type-preview="properties">
83
- <span className={style.TypeBrace}>{' {'}</span>
84
- <span className={style.TypePreviewContent}>
85
- {' '}
86
- <Join items={items} limit={3}>
87
- <span className={style.TextOperator}>, </span>
88
- </Join>{' '}
89
- </span>
90
- <span className={style.TypeBrace}>{'} '}</span>
91
- </span>
92
- );
93
- }
94
-
95
- export function TypeName({ type }: TypeProps) {
96
- const Lang = useLanguageComponents();
97
- return ComplexTypes[type.kind] ?? <Lang.Type type={type} />;
98
- }
99
-
100
- export function Type({ type }: TypeProps) {
101
- const Lang = useLanguageComponents();
102
- const { Join, SDKReference } = useComponents();
103
-
104
- switch (type.kind) {
105
- case 'TSTypeUnknown':
106
- case 'TSTypeUndefined':
107
- case 'TSTypeNever':
108
- case 'TSTypeVoid':
109
- case 'TSTypeNull':
110
- case 'TSTypeAny':
111
- case 'TSTypeBoolean':
112
- case 'TSTypeNumber':
113
- return (
114
- <span className={style.Type}>
115
- <span className={style.TypeKeyword}>{type.kind.slice(6).toLowerCase()}</span>
116
- </span>
117
- );
118
-
119
- case 'TSTypeString':
120
- return (
121
- <span className={style.Type}>
122
- <span className={style.TypeString}>string</span>
123
- </span>
124
- );
125
-
126
- case 'TSTypeLiteral':
127
- return (
128
- <span className={style.Type}>
129
- <span className={constStyle[typeof type.literal]}>{JSON.stringify(type.literal)}</span>
130
- </span>
131
- );
132
-
133
- case 'TSTypeArray': {
134
- return (
135
- <span className={style.Type}>
136
- <span className={style.TypeArray}>{'Array<'}</span>
137
- <Lang.Type type={type.elementType} />
138
- <span className={style.TypeArray}>{'>'}</span>
139
- </span>
140
- );
141
- }
142
-
143
- case 'TSTypeReference': {
144
- const name = type.ident.split('.').at(-1);
145
- const params = type.typeParameters?.map((param, key) => <Lang.Type key={key} type={param} />);
146
-
147
- return (
148
- <span className={style.Type}>
149
- <SDKReference stainlessPath={type.$ref}>{name}</SDKReference>
150
- {params && params.length > 0 && (
151
- <>
152
- <span className={style.TypeBracket}>{'<'}</span>
153
- <Join items={params} limit={3}>
154
- <span className={style.TextOperator}>, </span>
155
- </Join>
156
- <span className={style.TypeBracket}>{'>'}</span>
157
- </>
158
- )}
159
- <TypePreview path={type.$ref} />
160
- </span>
161
- );
162
- }
163
-
164
- case 'TSTypeIntersection':
165
- case 'TSTypeUnion': {
166
- const items = type.types.map((t, key) => <Lang.Type key={key} type={t} />);
167
-
168
- const delimiter = type.kind === 'TSTypeUnion' ? '|' : '&';
169
-
170
- return (
171
- <span className={style.Type}>
172
- <span className={style.TypePreview} data-stldocs-type-preview="union">
173
- <span className={style.TypePreviewContent}>
174
- <Join items={items} limit={3}>
175
- <span className={style.TextOperator}> {delimiter} </span>
176
- </Join>
177
- </span>
178
- </span>
179
- </span>
180
- );
181
- }
182
-
183
- case 'TSTypeObject':
184
- case 'TSTypeInterface': {
185
- const extend =
186
- type.kind === 'TSTypeObject'
187
- ? null
188
- : type.extends?.map((ref, key) => <Lang.Type key={key} type={ref} />);
189
-
190
- const items = type.members.map((prop, key) => (
191
- <React.Fragment key={key}>
192
- <span className={style.TypePropertyName}>
193
- <Identifier name={prop.ident} optional={prop.optional} />
194
- </span>
195
- <span className={style.TextPunctuation}>: </span>
196
- <Lang.Type type={prop.type} />
197
- </React.Fragment>
198
- ));
199
-
200
- return (
201
- <span className={style.Type}>
202
- {extend?.length && (
203
- <>
204
- <span className={style.TypeKeyword}> extends </span>
205
- <Join items={extend} limit={3}>
206
- <span className={style.TextOperator}>, </span>
207
- </Join>
208
- </>
209
- )}
210
- <span className={style.TypePreview} data-stldocs-type-preview="properties">
211
- <span className={style.TypeBrace}>{'{ '}</span>
212
- <span className={style.TypePreviewContent}>
213
- <Join items={items} limit={3}>
214
- <span className={style.TextOperator}>, </span>
215
- </Join>
216
- </span>
217
- <span className={style.TypeBrace}>{'} '}</span>
218
- </span>
219
- </span>
220
- );
221
- }
222
- }
223
- }
224
-
225
- export type MethodSignatureProps = {
226
- decl: TSAST.TSDeclFunction;
227
- };
228
-
229
- export function MethodSignature({ decl }: MethodSignatureProps) {
230
- const Lang = useLanguageComponents();
231
- const { Join, Tooltip } = useComponents();
232
-
233
- const params = decl.signature.parameters.map((param, i) => (
234
- <React.Fragment key={i}>
235
- <Tooltip content={<Lang.Type type={param.type} />}>
236
- <span className={style.TextIdentifier}>{param.ident}</span>
237
- </Tooltip>
238
- {param.optional && <span className={style.TextPunctuation}>?</span>}
239
- </React.Fragment>
240
- ));
241
-
242
- return (
243
- <div className={style.MethodSignature}>
244
- <span className={style.SignatureTitle}>
245
- {decl.signature.async && <span className={style.TextKeyword}>async </span>}
246
- <span className={style.SignatureQualified}>
247
- <span className={style.TextIdentifier}>{decl.qualified?.slice(0, -decl.ident.length)}</span>
248
- </span>
249
- <span className={style.SignatureName}>
250
- <span className={style.TextIdentifier}>{decl.ident}</span>
251
- </span>
252
- <span className={style.MethodSignature}>
253
- {decl.signature.typeParameters && <TypeParams params={decl.signature.typeParameters} />}
254
- <span className={style.SignatureParen}>{'('}</span>
255
-
256
- <span className={style.SignatureParams}>
257
- <Join items={params}>
258
- <span className={style.TextOperator}>{', '}</span>
259
- </Join>
260
- </span>
261
-
262
- <span className={style.SignatureParen}>{')'}</span>
263
- {decl.signature.returns && (
264
- <>
265
- <span className={style.TextPunctuation}>: </span>
266
- <Lang.Type type={decl.signature.returns} />
267
- </>
268
- )}
269
- </span>
270
- </span>
271
- </div>
272
- );
273
- }
274
-
275
- export type PropertyProps = {
276
- decl: TSAST.TSDeclaration;
277
- children?: PropertyFn;
278
- };
279
-
280
- export function Property({ decl, children }: PropertyProps) {
281
- const Lang = useLanguageComponents();
282
-
283
- if (!decl) return;
284
-
285
- switch (decl.kind) {
286
- case 'TSDeclProperty':
287
- return children({
288
- name: decl.key,
289
- typeName: <Lang.TypeName type={decl.type} />,
290
- type: decl.type.kind in ComplexTypes && <Lang.Type type={decl.type} />,
291
- });
292
-
293
- case 'TSDeclTypeAlias':
294
- return children({
295
- name: decl.ident,
296
- typeName: 'alias',
297
- type: <Lang.Type type={decl.type} />,
298
- });
299
-
300
- case 'TSDeclReference':
301
- return children({ type: <Lang.Type type={decl.type} /> });
302
-
303
- case 'TSDeclInterface':
304
- return children({
305
- type: (
306
- <>
307
- <span className={style.TextIdentifier}>{decl.ident}</span>
308
- {decl.typeParameters && <TypeParams params={decl.typeParameters} />}
309
- {decl.extends?.flatMap((t, key) => (
310
- <React.Fragment key={`extends:${key}`}>
311
- <span className={style.TextKeyword}> extends </span>
312
- <Lang.Type type={t} />
313
- </React.Fragment>
314
- ))}
315
- </>
316
- ),
317
- });
318
- }
319
- }
320
-
321
- export type DeclarationProps = { decl: TSAST.TSDeclaration };
322
-
323
- export function Declaration({ decl }: DeclarationProps) {
324
- const Lang = useLanguageComponents();
325
-
326
- if (!decl) return;
327
-
328
- switch (decl.kind) {
329
- case 'TSDeclProperty':
330
- return (
331
- <>
332
- {decl.declare && <span className={style.TextKeyword}>declare </span>}
333
- <span className={style.TypePropertyName}>
334
- <Identifier name={decl.key} optional={decl.optional} />
335
- </span>
336
- <span className={style.TextPunctuation}>: </span>
337
- <Lang.Type type={decl.type} />
338
- </>
339
- );
340
-
341
- case 'TSDeclFunction':
342
- return <Lang.MethodSignature decl={decl} />;
343
-
344
- case 'TSDeclTypeAlias':
345
- return (
346
- <>
347
- <Identifier name={decl.ident} />
348
- <TypeParams params={decl.typeParameters} />
349
- <span className={style.TextOperator}> = </span>
350
- <Lang.Type type={decl.type} />
351
- </>
352
- );
353
-
354
- case 'TSDeclReference':
355
- return <Lang.Type type={decl.type} />;
356
-
357
- case 'TSDeclInterface':
358
- return (
359
- <>
360
- <span className={style.TextIdentifier}>{decl.ident}</span>
361
- <TypeParams params={decl.typeParameters} />
362
- {decl.extends?.map((t, index) => (
363
- <React.Fragment key={index}>
364
- <span className={style.TextKeyword}> extends </span>
365
- <Lang.Type type={t} />
366
- </React.Fragment>
367
- ))}
368
- <TypePreview path={decl.stainlessPath} />
369
- </>
370
- );
371
-
372
- case 'TSDeclClass':
373
- return (
374
- <>
375
- <span className={style.TextKeyword}>class </span>
376
- <span className={style.TextIdentifier}>{decl.ident}</span>
377
- <TypeParams params={decl.typeParameters} />
378
- {decl.superClass ? (
379
- <>
380
- <span className={style.TextKeyword}> extends </span>
381
- <Lang.Type type={decl.superClass} />
382
- </>
383
- ) : null}
384
- {decl.implements?.map((t, index) => (
385
- <React.Fragment key={index}>
386
- <span className={style.TextKeyword}> implements </span>
387
- <Lang.Type type={t} />
388
- </React.Fragment>
389
- ))}
390
- </>
391
- );
392
- }
393
- }
@@ -1,107 +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 '~/lib/json-spec-v2/types';
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.length > 0;
22
- const showModelProps = !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) {
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(' ');
45
-
46
- const output = [
47
- md.heading(2, method.title),
48
- env.language === 'http' ? null : 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.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) {
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).map((resource) => renderResource(env, resource));
86
- return [...doc, ...children];
87
- }
88
-
89
- export function render(env: EnvironmentType, node: SDKJSON.Resource | SDKJSON.Method | SDKJSON.Model) {
90
- switch (node.kind) {
91
- case 'resource':
92
- return renderResource(env, node);
93
- case 'http_method':
94
- return renderMethod(env, node);
95
- case 'model':
96
- return renderModel(env, node);
97
- }
98
- }
99
-
100
- export function renderMarkdown(
101
- env: EnvironmentType,
102
- node: SDKJSON.Resource | SDKJSON.Method | SDKJSON.Model,
103
- ) {
104
- const content = render(env, node);
105
- const doc = new Markdoc.Ast.Node('document', {}, content);
106
- return Markdoc.format(doc);
107
- }
@@ -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,49 +0,0 @@
1
- import { Parser } from 'htmlparser2';
2
- import type { DocsLanguage } from '../routing';
3
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
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 = decl['type']['$ref'];
23
- if (refId === path) return decl;
24
- if (refId) return getDecl(env, refId);
25
- }
26
-
27
- return decl;
28
- }
29
-
30
- export function getSnippet(env: EnvironmentType, path: string) {
31
- let snippet = env.spec?.snippets?.[`${env.language}.default`]?.[path];
32
- if (typeof snippet === 'string' && env.transforms?.transformRequestSnippet) {
33
- snippet = env.transforms.transformRequestSnippet({ snippet, language: env.language });
34
- }
35
- return snippet;
36
- }
37
-
38
- export function stripMarkup(content: string) {
39
- let output = '';
40
-
41
- const parser = new Parser({
42
- ontext(content) {
43
- output += content;
44
- },
45
- });
46
-
47
- parser.parseComplete(content);
48
- return output;
49
- }