@stainless-api/docs-ui 0.1.0-beta.8 → 0.1.0-beta.80

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 (155) hide show
  1. package/dist/chunk-BYypO7fO.js +18 -0
  2. package/dist/components/MaskedInput.d.ts +14 -0
  3. package/dist/components/MaskedInput.js +76 -0
  4. package/dist/components/breadcrumbs.d.ts +25 -0
  5. package/dist/components/breadcrumbs.js +64 -0
  6. package/dist/components/icons.d.ts +65 -0
  7. package/dist/components/icons.js +941 -0
  8. package/dist/components/index.d.ts +16 -0
  9. package/dist/components/index.js +75 -0
  10. package/dist/components/method.d.ts +59 -0
  11. package/dist/components/method.js +97 -0
  12. package/dist/components/overview.d.ts +39 -0
  13. package/dist/components/overview.js +139 -0
  14. package/dist/components/primitives.d.ts +107 -0
  15. package/dist/components/primitives.js +253 -0
  16. package/dist/components/properties.d.ts +54 -0
  17. package/dist/components/properties.js +140 -0
  18. package/dist/components/sdk-sidebar.d.ts +15 -0
  19. package/dist/components/sdk-sidebar.js +52 -0
  20. package/dist/components/sdk.d.ts +128 -0
  21. package/dist/components/sdk.js +490 -0
  22. package/dist/components/snippets.d.ts +71 -0
  23. package/dist/components/snippets.js +184 -0
  24. package/dist/components/stl-sidebar.d.ts +58 -0
  25. package/dist/components/stl-sidebar.js +114 -0
  26. package/dist/contexts/component-generics.d.ts +30 -0
  27. package/dist/contexts/component-generics.js +33 -0
  28. package/dist/contexts/component-types.d.ts +8 -0
  29. package/dist/contexts/component-types.js +0 -0
  30. package/dist/contexts/component.d.ts +21 -0
  31. package/dist/contexts/component.js +24 -0
  32. package/dist/contexts/docs.d.ts +62 -0
  33. package/dist/contexts/docs.js +91 -0
  34. package/dist/contexts/index.d.ts +13 -0
  35. package/dist/contexts/index.js +45 -0
  36. package/dist/contexts/markdown.d.ts +22 -0
  37. package/dist/contexts/markdown.js +49 -0
  38. package/dist/contexts/navigation.d.ts +29 -0
  39. package/dist/contexts/navigation.js +24 -0
  40. package/dist/contexts/use-components.d.ts +6 -0
  41. package/dist/contexts/use-components.js +8 -0
  42. package/dist/index-pvh-w1xa.d.ts +1776 -0
  43. package/dist/index.d.ts +7 -0
  44. package/dist/index.js +9 -7542
  45. package/dist/languages/cli.d.ts +38 -0
  46. package/dist/languages/cli.js +167 -0
  47. package/dist/languages/csharp.d.ts +42 -0
  48. package/dist/languages/csharp.js +284 -0
  49. package/dist/languages/go.d.ts +40 -0
  50. package/dist/languages/go.js +304 -0
  51. package/dist/languages/http.d.ts +46 -0
  52. package/dist/languages/http.js +391 -0
  53. package/dist/languages/index.d.ts +51 -0
  54. package/dist/languages/index.js +33 -0
  55. package/dist/languages/java.d.ts +43 -0
  56. package/dist/languages/java.js +404 -0
  57. package/dist/languages/php.d.ts +40 -0
  58. package/dist/languages/php.js +313 -0
  59. package/dist/languages/python.d.ts +40 -0
  60. package/dist/languages/python.js +270 -0
  61. package/dist/languages/ruby.d.ts +40 -0
  62. package/dist/languages/ruby.js +388 -0
  63. package/dist/languages/terraform.d.ts +48 -0
  64. package/dist/languages/terraform.js +244 -0
  65. package/dist/languages/typescript.d.ts +40 -0
  66. package/dist/languages/typescript.js +450 -0
  67. package/dist/markdown/index.d.ts +11 -0
  68. package/dist/markdown/index.js +80 -0
  69. package/dist/markdown/md.d.ts +15 -0
  70. package/dist/markdown/md.js +41 -0
  71. package/dist/markdown/printer.d.ts +13 -0
  72. package/dist/markdown/printer.js +76 -0
  73. package/dist/markdown/utils.d.ts +21 -0
  74. package/dist/markdown/utils.js +31 -0
  75. package/dist/routing.d.ts +61 -0
  76. package/dist/routing.js +176 -150
  77. package/dist/spec.d.ts +65 -0
  78. package/dist/spec.js +167 -0
  79. package/dist/style.d.ts +177 -0
  80. package/dist/style.js +178 -0
  81. package/dist/styles/main.css +788 -752
  82. package/dist/styles/main.js +0 -0
  83. package/dist/styles/primitives.css +326 -458
  84. package/dist/styles/primitives.js +0 -0
  85. package/dist/styles/resets.css +32 -41
  86. package/dist/styles/resets.js +0 -0
  87. package/dist/styles/search.css +192 -270
  88. package/dist/styles/search.js +0 -0
  89. package/dist/styles/sidebar.css +182 -69
  90. package/dist/styles/sidebar.js +0 -0
  91. package/dist/styles/variables.css +28 -89
  92. package/dist/styles/variables.js +0 -0
  93. package/dist/styles.css +3333 -0
  94. package/dist/styles.mjs +1 -0
  95. package/dist/use-strict-context-L0c8JKg4.js +16 -0
  96. package/dist/utils.d.ts +20 -0
  97. package/dist/utils.js +54 -0
  98. package/package.json +74 -22
  99. package/dist/mcp.js +0 -16003
  100. package/dist/styles/snippets.css +0 -132
  101. package/src/components/breadcrumbs.tsx +0 -94
  102. package/src/components/chat.tsx +0 -154
  103. package/src/components/dropdown.tsx +0 -91
  104. package/src/components/icons.tsx +0 -584
  105. package/src/components/index.ts +0 -9
  106. package/src/components/method.tsx +0 -146
  107. package/src/components/overview.tsx +0 -160
  108. package/src/components/primitives.tsx +0 -284
  109. package/src/components/properties.tsx +0 -130
  110. package/src/components/scripts/dropdown.ts +0 -78
  111. package/src/components/sdk.tsx +0 -403
  112. package/src/components/sidebar.tsx +0 -99
  113. package/src/components/snippets.tsx +0 -180
  114. package/src/contexts/component-generics.tsx +0 -48
  115. package/src/contexts/component-types.tsx +0 -5
  116. package/src/contexts/component.tsx +0 -32
  117. package/src/contexts/docs.tsx +0 -75
  118. package/src/contexts/index.tsx +0 -17
  119. package/src/contexts/markdown.tsx +0 -43
  120. package/src/contexts/navigation.tsx +0 -44
  121. package/src/contexts/search.tsx +0 -28
  122. package/src/contexts/use-components.tsx +0 -4
  123. package/src/index.ts +0 -6
  124. package/src/languages/go.tsx +0 -281
  125. package/src/languages/http.tsx +0 -321
  126. package/src/languages/index.ts +0 -26
  127. package/src/languages/java.tsx +0 -358
  128. package/src/languages/python.tsx +0 -255
  129. package/src/languages/ruby.tsx +0 -320
  130. package/src/languages/typescript.tsx +0 -393
  131. package/src/markdown/index.ts +0 -107
  132. package/src/markdown/md.ts +0 -45
  133. package/src/markdown/utils.ts +0 -49
  134. package/src/routing.ts +0 -238
  135. package/src/search/form.tsx +0 -127
  136. package/src/search/index.tsx +0 -1
  137. package/src/search/indexer.ts +0 -246
  138. package/src/search/mcp.ts +0 -61
  139. package/src/search/printer.tsx +0 -86
  140. package/src/search/providers/algolia.ts +0 -88
  141. package/src/search/providers/fuse.ts +0 -19
  142. package/src/search/providers/pagefind.ts +0 -17
  143. package/src/search/providers/walker.ts +0 -30
  144. package/src/search/results.tsx +0 -182
  145. package/src/search/state.ts +0 -64
  146. package/src/search/types.ts +0 -116
  147. package/src/style.ts +0 -196
  148. package/src/styles/main.css +0 -986
  149. package/src/styles/primitives.css +0 -580
  150. package/src/styles/resets.css +0 -39
  151. package/src/styles/search.css +0 -341
  152. package/src/styles/sidebar.css +0 -85
  153. package/src/styles/snippets.css +0 -130
  154. package/src/styles/variables.css +0 -86
  155. package/src/utils.ts +0 -41
@@ -0,0 +1,76 @@
1
+ import { t as __exportAll } from "../chunk-BYypO7fO.js";
2
+ import { DocsProvider } from "../contexts/docs.js";
3
+ import "../use-strict-context-L0c8JKg4.js";
4
+ import { useLanguageComponents } from "../contexts/index.js";
5
+ import style_default from "../style.js";
6
+ import { ComponentProvider } from "../contexts/component.js";
7
+ import "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ import { renderToStaticMarkup } from "react-dom/server";
10
+
11
+ //#region src/markdown/printer.tsx
12
+ var printer_exports = /* @__PURE__ */ __exportAll({
13
+ declaration: () => declaration,
14
+ methodSignature: () => methodSignature,
15
+ type: () => type,
16
+ typeName: () => typeName
17
+ });
18
+ function SDKReference({ stainlessPath, children }) {
19
+ if (!stainlessPath) return children;
20
+ return /* @__PURE__ */ jsx("span", {
21
+ className: style_default.TypeReference,
22
+ children
23
+ });
24
+ }
25
+ function Providers({ language, children }) {
26
+ return /* @__PURE__ */ jsx(DocsProvider, {
27
+ spec: null,
28
+ language,
29
+ children: /* @__PURE__ */ jsx(ComponentProvider, {
30
+ components: { SDKReference },
31
+ children
32
+ })
33
+ });
34
+ }
35
+ function RenderType({ type, full }) {
36
+ const { Type, TypeName } = useLanguageComponents();
37
+ return full ? /* @__PURE__ */ jsx(Type, { type }) : /* @__PURE__ */ jsx(TypeName, { type });
38
+ }
39
+ function typeName(language, type) {
40
+ return renderToStaticMarkup(/* @__PURE__ */ jsx(Providers, {
41
+ language,
42
+ children: /* @__PURE__ */ jsx(RenderType, { type })
43
+ }));
44
+ }
45
+ function type(language, type) {
46
+ return renderToStaticMarkup(/* @__PURE__ */ jsx(Providers, {
47
+ language,
48
+ children: /* @__PURE__ */ jsx(RenderType, {
49
+ type,
50
+ full: true
51
+ })
52
+ }));
53
+ }
54
+ function RenderDeclaration({ decl }) {
55
+ const { Declaration } = useLanguageComponents();
56
+ return /* @__PURE__ */ jsx(Declaration, { decl });
57
+ }
58
+ function declaration(language, decl) {
59
+ return renderToStaticMarkup(/* @__PURE__ */ jsx(Providers, {
60
+ language,
61
+ children: /* @__PURE__ */ jsx(RenderDeclaration, { decl })
62
+ }));
63
+ }
64
+ function RenderMethod({ method }) {
65
+ const { MethodSignature } = useLanguageComponents();
66
+ return /* @__PURE__ */ jsx(MethodSignature, { decl: method });
67
+ }
68
+ function methodSignature(language, decl) {
69
+ return renderToStaticMarkup(/* @__PURE__ */ jsx(Providers, {
70
+ language,
71
+ children: /* @__PURE__ */ jsx(RenderMethod, { method: decl })
72
+ }));
73
+ }
74
+
75
+ //#endregion
76
+ export { declaration, methodSignature, printer_exports as t, type, typeName };
@@ -0,0 +1,21 @@
1
+ import { u as LanguageDeclNodes, v as Spec, y as SpecLanguage } from "../index-pvh-w1xa.js";
2
+ import { DocsLanguage } from "../routing.js";
3
+ import { TransformRequestSnippetFn } from "../components/sdk.js";
4
+
5
+ //#region src/markdown/utils.d.ts
6
+ type EnvironmentType = {
7
+ spec: Spec;
8
+ language: DocsLanguage;
9
+ transforms?: {
10
+ transformRequestSnippet?: TransformRequestSnippetFn;
11
+ };
12
+ options: {
13
+ renderNestedResources?: boolean;
14
+ includeModelProperties?: boolean | 'method-page';
15
+ };
16
+ };
17
+ declare function getDecl(env: EnvironmentType, path: string): LanguageDeclNodes[SpecLanguage] | undefined;
18
+ declare function getSnippet(env: EnvironmentType, path: string, snippetId?: 'default' | `custom:${string}`): string | undefined;
19
+ declare function stripMarkup(content: string): string;
20
+ //#endregion
21
+ export { EnvironmentType, getDecl, getSnippet, stripMarkup };
@@ -0,0 +1,31 @@
1
+ import { Parser } from "htmlparser2";
2
+
3
+ //#region src/markdown/utils.ts
4
+ function getDecl(env, path) {
5
+ const decl = env.spec?.decls?.[env.language]?.[path];
6
+ if (decl?.kind?.endsWith("Reference")) {
7
+ const refId = "type" in decl && typeof decl["type"] === "object" && "$ref" in decl["type"] ? decl["type"]["$ref"] : null;
8
+ if (refId === path) return decl;
9
+ if (refId) return getDecl(env, refId);
10
+ }
11
+ return decl;
12
+ }
13
+ function getSnippet(env, path, snippetId = "default") {
14
+ const lang = env.language === "http" ? "http.curl" : `${env.language}.default`;
15
+ let snippet = env.spec?.snippets?.[lang]?.[path]?.[snippetId]?.content;
16
+ if (snippet && env.transforms?.transformRequestSnippet) snippet = env.transforms.transformRequestSnippet({
17
+ snippet,
18
+ language: env.language
19
+ });
20
+ return snippet;
21
+ }
22
+ function stripMarkup(content) {
23
+ let output = "";
24
+ new Parser({ ontext(content) {
25
+ output += content;
26
+ } }).parseComplete(content);
27
+ return output;
28
+ }
29
+
30
+ //#endregion
31
+ export { getDecl, getSnippet, stripMarkup };
@@ -0,0 +1,61 @@
1
+ import { d as Method, f as Model, h as Resource, v as Spec } from "./index-pvh-w1xa.js";
2
+
3
+ //#region src/routing.d.ts
4
+ declare namespace routing_d_exports {
5
+ export { DocsLanguage, LanguageNames, Languages, ParsedStainlessPath, RouteEntry, SpecTreeEntry, SupportedLanguageSyntaxes, expandToElement, findNavigationPath, generateMissingRouteList, generateRoute, generateRouteList, getLanguageSnippet, getResource, isSupportedLanguage, parseRoute, parseStainlessPath, scrollToPath, trimStainlessPath, updateHistory, walkTree };
6
+ }
7
+ declare const Languages: readonly ["http", "node", "python", "go", "typescript", "terraform", "ruby", "java", "kotlin", "csharp", "php", "cli"];
8
+ declare const SupportedLanguageSyntaxes: string[];
9
+ type DocsLanguage = (typeof Languages)[number];
10
+ declare const LanguageNames: Record<DocsLanguage, string>;
11
+ declare function getLanguageSnippet(language: DocsLanguage): "http.curl" | "node.default" | "python.default" | "go.default" | "typescript.default" | "terraform.default" | "ruby.default" | "java.default" | "kotlin.default" | "csharp.default" | "php.default" | "cli.default";
12
+ declare function isSupportedLanguage(language: string): language is DocsLanguage;
13
+ type ParsedStainlessPath = ReturnType<typeof parseStainlessPath>;
14
+ declare function parseStainlessPath(stainlessPath: string): {
15
+ resource: string[] | null;
16
+ method: string | null;
17
+ model: string | null;
18
+ routable: string | undefined;
19
+ } | null;
20
+ declare function trimStainlessPath(stainlessPath: string): string;
21
+ declare function getResource(stainlessPath: string): string | undefined;
22
+ declare function parseRoute(basePath: string, route: string): {
23
+ stainlessPath: string;
24
+ language: DocsLanguage;
25
+ };
26
+ declare function generateRoute(basePath: string, language: string, stainlessPath: string): string | null;
27
+ type SpecTreeEntry = {
28
+ data: Method | Resource | Model;
29
+ path: string[];
30
+ };
31
+ declare function walkTree(spec: Spec, includeModels?: boolean): Generator<SpecTreeEntry, void, any>;
32
+ type RouteEntry = {
33
+ title: string;
34
+ kind: SpecTreeEntry['data']['kind'];
35
+ language: DocsLanguage;
36
+ stainlessPath: string;
37
+ slug: string;
38
+ };
39
+ declare function generateRouteList({
40
+ spec,
41
+ languages,
42
+ excludeLanguages
43
+ }: {
44
+ spec: Spec;
45
+ languages?: DocsLanguage[];
46
+ excludeLanguages?: DocsLanguage[];
47
+ }): RouteEntry[];
48
+ declare function generateMissingRouteList({
49
+ spec,
50
+ basePath
51
+ }: {
52
+ spec: Spec;
53
+ basePath: string;
54
+ }): string[];
55
+ type ResourceOrMethod = Resource | Method;
56
+ declare function findNavigationPath(items: ResourceOrMethod[], target: string): string[] | undefined;
57
+ declare function expandToElement(el: HTMLElement | null): void;
58
+ declare function scrollToPath(stainlessPath: string): void;
59
+ declare function updateHistory(basePath: string, language: DocsLanguage, stainlessPath: string): void;
60
+ //#endregion
61
+ export { DocsLanguage, LanguageNames, Languages, ParsedStainlessPath, RouteEntry, SpecTreeEntry, SupportedLanguageSyntaxes, expandToElement, findNavigationPath, generateMissingRouteList, generateRoute, generateRouteList, getLanguageSnippet, getResource, isSupportedLanguage, parseRoute, parseStainlessPath, scrollToPath, routing_d_exports as t, trimStainlessPath, updateHistory, walkTree };
package/dist/routing.js CHANGED
@@ -1,180 +1,206 @@
1
- // src/routing.ts
2
- var Languages = [
3
- "http",
4
- "node",
5
- "python",
6
- "go",
7
- "typescript",
8
- "terraform",
9
- "ruby",
10
- "java",
11
- "kotlin"
1
+ import { t as __exportAll } from "./chunk-BYypO7fO.js";
2
+
3
+ //#region src/routing.ts
4
+ var routing_exports = /* @__PURE__ */ __exportAll({
5
+ LanguageNames: () => LanguageNames,
6
+ Languages: () => Languages,
7
+ SupportedLanguageSyntaxes: () => SupportedLanguageSyntaxes,
8
+ expandToElement: () => expandToElement,
9
+ findNavigationPath: () => findNavigationPath,
10
+ generateMissingRouteList: () => generateMissingRouteList,
11
+ generateRoute: () => generateRoute,
12
+ generateRouteList: () => generateRouteList,
13
+ getLanguageSnippet: () => getLanguageSnippet,
14
+ getResource: () => getResource,
15
+ isSupportedLanguage: () => isSupportedLanguage,
16
+ parseRoute: () => parseRoute,
17
+ parseStainlessPath: () => parseStainlessPath,
18
+ scrollToPath: () => scrollToPath,
19
+ trimStainlessPath: () => trimStainlessPath,
20
+ updateHistory: () => updateHistory,
21
+ walkTree: () => walkTree
22
+ });
23
+ const Languages = [
24
+ "http",
25
+ "node",
26
+ "python",
27
+ "go",
28
+ "typescript",
29
+ "terraform",
30
+ "ruby",
31
+ "java",
32
+ "kotlin",
33
+ "csharp",
34
+ "php",
35
+ "cli"
12
36
  ];
13
- var SupportedLanguageSyntaxes = [
14
- "http",
15
- "javascript",
16
- "python",
17
- "go",
18
- "typescript",
19
- "terraform",
20
- "ruby",
21
- "java",
22
- "kotlin"
37
+ const SupportedLanguageSyntaxes = [
38
+ "http",
39
+ "javascript",
40
+ "python",
41
+ "go",
42
+ "typescript",
43
+ "terraform",
44
+ "ruby",
45
+ "java",
46
+ "kotlin",
47
+ "csharp",
48
+ "php",
49
+ "bash"
23
50
  ];
24
- var LanguageNames = {
25
- http: "HTTP",
26
- node: "TypeScript",
27
- typescript: "TypeScript",
28
- python: "Python",
29
- go: "Go",
30
- ruby: "Ruby",
31
- java: "Java",
32
- kotlin: "Kotlin",
33
- terraform: "Terraform"
51
+ const LanguageNames = {
52
+ http: "HTTP",
53
+ node: "TypeScript",
54
+ typescript: "TypeScript",
55
+ python: "Python",
56
+ go: "Go",
57
+ ruby: "Ruby",
58
+ java: "Java",
59
+ kotlin: "Kotlin",
60
+ terraform: "Terraform",
61
+ csharp: "C#",
62
+ php: "PHP",
63
+ cli: "CLI Tool"
34
64
  };
35
65
  function getLanguageSnippet(language) {
36
- return language === "http" ? "http.curl" : `${language}.default`;
66
+ return language === "http" ? "http.curl" : `${language}.default`;
37
67
  }
38
68
  function isSupportedLanguage(language) {
39
- return Languages.includes(language);
69
+ return Languages.includes(language);
40
70
  }
41
- var DefaultLanguage = "http";
42
- var StainlessPathPattern = /(\(resource\) (?<resource>[^\s]+))( > (\(method\) (?<method>[^\s]+)|\(model\) (?<model>[^\s]+))?)?/;
71
+ const DefaultLanguage = "http";
72
+ const StainlessPathPattern = /(\(resource\) (?<resource>[^\s]+))( > (\(method\) (?<method>[^\s]+)|\(model\) (?<model>[^\s]+))?)?/;
43
73
  function parseStainlessPath(stainlessPath) {
44
- const match = stainlessPath.match(StainlessPathPattern);
45
- if (!match) return null;
46
- return {
47
- resource: match.groups.resource.split("."),
48
- method: match.groups.method ?? null,
49
- model: match.groups.model ?? null,
50
- routable: match.groups.model ? match[1] : match[0]
51
- };
74
+ const match = stainlessPath.match(StainlessPathPattern);
75
+ if (!match?.groups) return null;
76
+ return {
77
+ resource: match.groups.resource?.split(".") ?? null,
78
+ method: match.groups.method ?? null,
79
+ model: match.groups.model ?? null,
80
+ routable: match.groups.model ? match[1] : match[0]
81
+ };
52
82
  }
53
83
  function trimStainlessPath(stainlessPath) {
54
- return stainlessPath.replace(/ > \([^\s]+\)$/, "");
84
+ return stainlessPath.replace(/ > \([^\s]+\)$/, "");
55
85
  }
56
86
  function getResource(stainlessPath) {
57
- const parsed = parseStainlessPath(stainlessPath);
58
- return parsed?.resource[0];
87
+ return parseStainlessPath(stainlessPath)?.resource?.[0];
59
88
  }
60
89
  function parseRoute(basePath, route) {
61
- if (!route.startsWith(basePath)) return { stainlessPath: "", language: DefaultLanguage };
62
- if (basePath && route.startsWith(basePath)) route = route.slice(basePath.length);
63
- let stainlessPath = "";
64
- let elements = route.slice(1).split("/");
65
- let language = DefaultLanguage;
66
- if (elements[0] && Languages.includes(elements[0])) {
67
- language = elements[0];
68
- elements = elements.slice(1);
69
- }
70
- while (elements.length > 0) {
71
- const element = elements.shift();
72
- switch (element) {
73
- case "resources":
74
- stainlessPath += `(resource) ${elements.shift()}`;
75
- break;
76
- case "subresources":
77
- stainlessPath += `.${elements.shift()}`;
78
- break;
79
- case "methods":
80
- stainlessPath += ` > (method) ${elements.shift()}`;
81
- break;
82
- }
83
- }
84
- return { stainlessPath, language };
90
+ if (!route.startsWith(basePath)) return {
91
+ stainlessPath: "",
92
+ language: DefaultLanguage
93
+ };
94
+ if (basePath && route.startsWith(basePath)) route = route.slice(basePath.length);
95
+ let stainlessPath = "";
96
+ let elements = route.slice(1).split("/");
97
+ let language = DefaultLanguage;
98
+ if (elements[0] && Languages.includes(elements[0])) {
99
+ language = elements[0];
100
+ elements = elements.slice(1);
101
+ }
102
+ while (elements.length > 0) switch (elements.shift()) {
103
+ case "resources":
104
+ stainlessPath += `(resource) ${elements.shift()}`;
105
+ break;
106
+ case "subresources":
107
+ stainlessPath += `.${elements.shift()}`;
108
+ break;
109
+ case "methods":
110
+ stainlessPath += ` > (method) ${elements.shift()}`;
111
+ break;
112
+ }
113
+ return {
114
+ stainlessPath,
115
+ language
116
+ };
85
117
  }
86
118
  function generateRoute(basePath, language, stainlessPath) {
87
- const parsedPath = parseStainlessPath(stainlessPath);
88
- if (!parsedPath) return null;
89
- const path = [basePath.endsWith("/") ? basePath.slice(0, -1) : basePath];
90
- if (language && language !== DefaultLanguage) path.push(language);
91
- const resources = parsedPath.resource.flatMap((name, index) => [
92
- index > 0 ? "subresources" : "resources",
93
- name
94
- ]);
95
- const resourcePath = parsedPath.model ? resources.slice(0, 2) : resources;
96
- path.push(...resourcePath);
97
- if (parsedPath.method) path.push("methods", parsedPath.method);
98
- return stainlessPath.length > parsedPath.routable.length ? `${path.join("/")}#${encodeURIComponent(stainlessPath)}` : path.join("/");
119
+ const parsedPath = parseStainlessPath(stainlessPath);
120
+ if (!parsedPath) return null;
121
+ const path = [basePath.endsWith("/") ? basePath.slice(0, -1) : basePath];
122
+ if (language && language !== DefaultLanguage) path.push(language);
123
+ const resources = parsedPath.resource.flatMap((name, index) => [index > 0 ? "subresources" : "resources", name]);
124
+ const resourcePath = parsedPath.model ? resources.slice(0, 2) : resources;
125
+ path.push(...resourcePath);
126
+ if (parsedPath.method) path.push("methods", parsedPath.method);
127
+ return stainlessPath.length > parsedPath.routable.length ? `${path.join("/")}#${encodeURIComponent(stainlessPath)}` : path.join("/");
99
128
  }
100
129
  function* walkResource(resource, path, includeModels) {
101
- yield { data: resource, path };
102
- for (const data of Object.values(resource.methods)) {
103
- yield { data, path: [...path, "methods", data.name] };
104
- }
105
- if (includeModels)
106
- for (const data of Object.values(resource.models)) {
107
- yield { data, path: [...path, "models", data.name] };
108
- }
109
- for (const data of Object.values(resource.subresources ?? {})) {
110
- yield* walkResource(data, [...path, "subresources", data.name]);
111
- }
130
+ yield {
131
+ data: resource,
132
+ path
133
+ };
134
+ for (const data of Object.values(resource.methods)) yield {
135
+ data,
136
+ path: [
137
+ ...path,
138
+ "methods",
139
+ data.name
140
+ ]
141
+ };
142
+ if (includeModels) for (const data of Object.values(resource.models)) yield {
143
+ data,
144
+ path: [
145
+ ...path,
146
+ "models",
147
+ data.name
148
+ ]
149
+ };
150
+ for (const data of Object.values(resource.subresources ?? {})) yield* walkResource(data, [
151
+ ...path,
152
+ "subresources",
153
+ data.name
154
+ ]);
112
155
  }
113
156
  function* walkTree(spec, includeModels) {
114
- for (const data of Object.values(spec.resources)) {
115
- yield* walkResource(data, ["resources", data.name], includeModels);
116
- }
157
+ for (const data of Object.values(spec.resources)) yield* walkResource(data, ["resources", data.name], includeModels);
117
158
  }
118
- function generateRouteList({
119
- spec,
120
- languages,
121
- excludeLanguages = []
122
- }) {
123
- const entries = Array.from(walkTree(spec));
124
- const langs = languages ?? spec.docs?.languages ?? ["http"];
125
- return langs.filter((lang) => Languages.includes(lang) && lang !== "terraform").filter((lang) => !excludeLanguages?.includes(lang)).flatMap(
126
- (language) => entries.map(({ path, data: { title, kind, stainlessPath } }) => ({
127
- title,
128
- kind,
129
- language,
130
- stainlessPath,
131
- slug: (language === "http" ? path : [language, ...path]).join("/")
132
- }))
133
- );
159
+ function generateRouteList({ spec, languages, excludeLanguages = [] }) {
160
+ const entries = Array.from(walkTree(spec));
161
+ return (languages ?? spec.docs?.languages ?? ["http"]).filter((lang) => Languages.includes(lang)).filter((lang) => !excludeLanguages?.includes(lang)).flatMap((language) => entries.map(({ path, data: { title, kind, stainlessPath } }) => ({
162
+ title,
163
+ kind,
164
+ language,
165
+ stainlessPath,
166
+ slug: (language === "http" ? path : [language, ...path]).join("/")
167
+ })));
168
+ }
169
+ function generateMissingRouteList({ spec, basePath }) {
170
+ const entries = Array.from(walkTree(spec));
171
+ return (spec.docs?.languages ?? ["http"]).filter((lang) => Languages.includes(lang)).flatMap((language) => entries.filter(({ data: { stainlessPath, ...rest } }) => {
172
+ if (spec.decls?.[language]?.[stainlessPath] === void 0) return rest.kind === "http_method";
173
+ return false;
174
+ }).map(({ path }) => `${basePath.endsWith("/") ? basePath.slice(0, -1) : basePath}/${language === "http" ? path.join("/") : [language, ...path].join("/")}`));
134
175
  }
135
176
  function findNavigationPath(items, target) {
136
- for (const item of Object.values(items)) {
137
- if (item.stainlessPath === target) return [item.stainlessPath];
138
- if (item.kind === "http_method") continue;
139
- const path = findNavigationPath(
140
- [...Object.values(item.methods ?? {}), ...Object.values(item.subresources ?? {})],
141
- target
142
- );
143
- if (path) return [item.stainlessPath, ...path];
144
- }
177
+ for (const item of Object.values(items)) {
178
+ if (item.stainlessPath === target) return [item.stainlessPath];
179
+ if (item.kind === "http_method") continue;
180
+ const path = findNavigationPath([...Object.values(item.methods ?? {}), ...Object.values(item.subresources ?? {})], target);
181
+ if (path) return [item.stainlessPath, ...path];
182
+ }
145
183
  }
146
184
  function expandToElement(el) {
147
- while (el) {
148
- if (el.tagName === "DETAILS") el["open"] = true;
149
- el = el.parentElement;
150
- }
185
+ while (el) {
186
+ if (el instanceof HTMLDetailsElement) el.open = true;
187
+ el = el.parentElement;
188
+ }
151
189
  }
152
190
  function scrollToPath(stainlessPath) {
153
- const el = document.getElementById(stainlessPath);
154
- if (el) {
155
- expandToElement(el);
156
- el.scrollIntoView({ behavior: "smooth" });
157
- }
191
+ const el = document.getElementById(stainlessPath);
192
+ if (el) {
193
+ expandToElement(el);
194
+ el.scrollIntoView({ behavior: "smooth" });
195
+ }
158
196
  }
159
197
  function updateHistory(basePath, language, stainlessPath) {
160
- const path = generateRoute(basePath, language, stainlessPath);
161
- window.history.pushState({ stainlessPath, language }, "", path);
198
+ const path = generateRoute(basePath, language, stainlessPath);
199
+ window.history.pushState({
200
+ stainlessPath,
201
+ language
202
+ }, "", path);
162
203
  }
163
- export {
164
- LanguageNames,
165
- Languages,
166
- SupportedLanguageSyntaxes,
167
- expandToElement,
168
- findNavigationPath,
169
- generateRoute,
170
- generateRouteList,
171
- getLanguageSnippet,
172
- getResource,
173
- isSupportedLanguage,
174
- parseRoute,
175
- parseStainlessPath,
176
- scrollToPath,
177
- trimStainlessPath,
178
- updateHistory,
179
- walkTree
180
- };
204
+
205
+ //#endregion
206
+ export { LanguageNames, Languages, SupportedLanguageSyntaxes, expandToElement, findNavigationPath, generateMissingRouteList, generateRoute, generateRouteList, getLanguageSnippet, getResource, isSupportedLanguage, parseRoute, parseStainlessPath, scrollToPath, routing_exports as t, trimStainlessPath, updateHistory, walkTree };
package/dist/spec.d.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { d as Method, f as Model, h as Resource, i as DeclarationNode, v as Spec, y as SpecLanguage } from "./index-pvh-w1xa.js";
2
+ import { DocsLanguage } from "./routing.js";
3
+
4
+ //#region src/spec.d.ts
5
+ type SecurityScheme = Spec['security_schemes'][number];
6
+ interface SpecTransforms {
7
+ resource(resource: Resource): Resource;
8
+ method(method: Method): Method;
9
+ model(model: Model): Model;
10
+ declaration(decl: DeclarationNode, language: SpecLanguage): DeclarationNode;
11
+ securityScheme(scheme: SecurityScheme): SecurityScheme;
12
+ snippet(snippet: string, language: string): string;
13
+ markdown(content?: string): string | undefined;
14
+ }
15
+ declare function defineTransforms(transforms?: Partial<SpecTransforms>): {
16
+ resource: (resource: Resource) => Resource;
17
+ method: (method: Method) => Method;
18
+ model: (model: Model) => Model;
19
+ declaration: (decl: DeclarationNode, language: SpecLanguage) => DeclarationNode;
20
+ securityScheme: (scheme: SecurityScheme) => SecurityScheme;
21
+ snippet: (snippet: string, language: string) => string;
22
+ markdown: (content?: string) => string | undefined;
23
+ };
24
+ declare function generateNavigation(resource: Partial<Resource>): {
25
+ title: string | undefined;
26
+ name: string | undefined;
27
+ subresources: Record<string, Partial<Resource>> | undefined;
28
+ methods: Record<string, Partial<Method>> | undefined;
29
+ models: Record<string, Partial<Model>> | undefined;
30
+ stainlessPath: string | undefined;
31
+ terraform: {
32
+ Name: string;
33
+ QualifiedName: string;
34
+ } | undefined;
35
+ };
36
+ declare function generateSpecForResource(spec: Spec, name: string, lang: DocsLanguage, transforms: SpecTransforms): Partial<Spec>;
37
+ declare function transform(spec: Spec, transforms: SpecTransforms): {
38
+ name: string;
39
+ lang: "http" | "node" | "python" | "go" | "typescript" | "terraform" | "ruby" | "java" | "kotlin" | "csharp" | "php" | "cli";
40
+ spec: Partial<Spec>;
41
+ }[];
42
+ declare function split(spec: Spec, transforms?: SpecTransforms): {
43
+ resources: ReturnType<typeof transform>;
44
+ navigation: {
45
+ languages: ("http" | "node" | "python" | "go" | "typescript" | "terraform" | "ruby" | "java" | "kotlin" | "csharp" | "php" | "cli" | "sql" | "openapi")[] | undefined;
46
+ resources: {
47
+ [k: string]: {
48
+ title: string | undefined;
49
+ name: string | undefined;
50
+ subresources: Record<string, Partial<Resource>> | undefined;
51
+ methods: Record<string, Partial<Method>> | undefined;
52
+ models: Record<string, Partial<Model>> | undefined;
53
+ stainlessPath: string | undefined;
54
+ terraform: {
55
+ Name: string;
56
+ QualifiedName: string;
57
+ } | undefined;
58
+ };
59
+ };
60
+ };
61
+ };
62
+ declare function parseSpec(content: string): Spec | undefined;
63
+ declare function retrieve(apiKey: string, project: string, revision: string): Promise<Spec | undefined>;
64
+ //#endregion
65
+ export { SecurityScheme, SpecTransforms, defineTransforms, generateNavigation, generateSpecForResource, parseSpec, retrieve, split, transform };