@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.
- package/dist/chunk-BYypO7fO.js +18 -0
- package/dist/components/MaskedInput.d.ts +14 -0
- package/dist/components/MaskedInput.js +76 -0
- package/dist/components/breadcrumbs.d.ts +25 -0
- package/dist/components/breadcrumbs.js +64 -0
- package/dist/components/icons.d.ts +65 -0
- package/dist/components/icons.js +941 -0
- package/dist/components/index.d.ts +16 -0
- package/dist/components/index.js +75 -0
- package/dist/components/method.d.ts +59 -0
- package/dist/components/method.js +97 -0
- package/dist/components/overview.d.ts +39 -0
- package/dist/components/overview.js +139 -0
- package/dist/components/primitives.d.ts +107 -0
- package/dist/components/primitives.js +253 -0
- package/dist/components/properties.d.ts +54 -0
- package/dist/components/properties.js +140 -0
- package/dist/components/sdk-sidebar.d.ts +15 -0
- package/dist/components/sdk-sidebar.js +52 -0
- package/dist/components/sdk.d.ts +128 -0
- package/dist/components/sdk.js +490 -0
- package/dist/components/snippets.d.ts +71 -0
- package/dist/components/snippets.js +184 -0
- package/dist/components/stl-sidebar.d.ts +58 -0
- package/dist/components/stl-sidebar.js +114 -0
- package/dist/contexts/component-generics.d.ts +30 -0
- package/dist/contexts/component-generics.js +33 -0
- package/dist/contexts/component-types.d.ts +8 -0
- package/dist/contexts/component-types.js +0 -0
- package/dist/contexts/component.d.ts +21 -0
- package/dist/contexts/component.js +24 -0
- package/dist/contexts/docs.d.ts +62 -0
- package/dist/contexts/docs.js +91 -0
- package/dist/contexts/index.d.ts +13 -0
- package/dist/contexts/index.js +45 -0
- package/dist/contexts/markdown.d.ts +22 -0
- package/dist/contexts/markdown.js +49 -0
- package/dist/contexts/navigation.d.ts +29 -0
- package/dist/contexts/navigation.js +24 -0
- package/dist/contexts/use-components.d.ts +6 -0
- package/dist/contexts/use-components.js +8 -0
- package/dist/index-pvh-w1xa.d.ts +1776 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +9 -7542
- package/dist/languages/cli.d.ts +38 -0
- package/dist/languages/cli.js +167 -0
- package/dist/languages/csharp.d.ts +42 -0
- package/dist/languages/csharp.js +284 -0
- package/dist/languages/go.d.ts +40 -0
- package/dist/languages/go.js +304 -0
- package/dist/languages/http.d.ts +46 -0
- package/dist/languages/http.js +391 -0
- package/dist/languages/index.d.ts +51 -0
- package/dist/languages/index.js +33 -0
- package/dist/languages/java.d.ts +43 -0
- package/dist/languages/java.js +404 -0
- package/dist/languages/php.d.ts +40 -0
- package/dist/languages/php.js +313 -0
- package/dist/languages/python.d.ts +40 -0
- package/dist/languages/python.js +270 -0
- package/dist/languages/ruby.d.ts +40 -0
- package/dist/languages/ruby.js +388 -0
- package/dist/languages/terraform.d.ts +48 -0
- package/dist/languages/terraform.js +244 -0
- package/dist/languages/typescript.d.ts +40 -0
- package/dist/languages/typescript.js +450 -0
- package/dist/markdown/index.d.ts +11 -0
- package/dist/markdown/index.js +80 -0
- package/dist/markdown/md.d.ts +15 -0
- package/dist/markdown/md.js +41 -0
- package/dist/markdown/printer.d.ts +13 -0
- package/dist/markdown/printer.js +76 -0
- package/dist/markdown/utils.d.ts +21 -0
- package/dist/markdown/utils.js +31 -0
- package/dist/routing.d.ts +61 -0
- package/dist/routing.js +176 -150
- package/dist/spec.d.ts +65 -0
- package/dist/spec.js +167 -0
- package/dist/style.d.ts +177 -0
- package/dist/style.js +178 -0
- package/dist/styles/main.css +788 -752
- package/dist/styles/main.js +0 -0
- package/dist/styles/primitives.css +326 -458
- package/dist/styles/primitives.js +0 -0
- package/dist/styles/resets.css +32 -41
- package/dist/styles/resets.js +0 -0
- package/dist/styles/search.css +192 -270
- package/dist/styles/search.js +0 -0
- package/dist/styles/sidebar.css +182 -69
- package/dist/styles/sidebar.js +0 -0
- package/dist/styles/variables.css +28 -89
- package/dist/styles/variables.js +0 -0
- package/dist/styles.css +3333 -0
- package/dist/styles.mjs +1 -0
- package/dist/use-strict-context-L0c8JKg4.js +16 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +54 -0
- package/package.json +74 -22
- package/dist/mcp.js +0 -16003
- package/dist/styles/snippets.css +0 -132
- package/src/components/breadcrumbs.tsx +0 -94
- package/src/components/chat.tsx +0 -154
- package/src/components/dropdown.tsx +0 -91
- package/src/components/icons.tsx +0 -584
- package/src/components/index.ts +0 -9
- package/src/components/method.tsx +0 -146
- package/src/components/overview.tsx +0 -160
- package/src/components/primitives.tsx +0 -284
- package/src/components/properties.tsx +0 -130
- package/src/components/scripts/dropdown.ts +0 -78
- package/src/components/sdk.tsx +0 -403
- package/src/components/sidebar.tsx +0 -99
- package/src/components/snippets.tsx +0 -180
- package/src/contexts/component-generics.tsx +0 -48
- package/src/contexts/component-types.tsx +0 -5
- package/src/contexts/component.tsx +0 -32
- package/src/contexts/docs.tsx +0 -75
- package/src/contexts/index.tsx +0 -17
- package/src/contexts/markdown.tsx +0 -43
- package/src/contexts/navigation.tsx +0 -44
- package/src/contexts/search.tsx +0 -28
- package/src/contexts/use-components.tsx +0 -4
- package/src/index.ts +0 -6
- package/src/languages/go.tsx +0 -281
- package/src/languages/http.tsx +0 -321
- package/src/languages/index.ts +0 -26
- package/src/languages/java.tsx +0 -358
- package/src/languages/python.tsx +0 -255
- package/src/languages/ruby.tsx +0 -320
- package/src/languages/typescript.tsx +0 -393
- package/src/markdown/index.ts +0 -107
- package/src/markdown/md.ts +0 -45
- package/src/markdown/utils.ts +0 -49
- package/src/routing.ts +0 -238
- package/src/search/form.tsx +0 -127
- package/src/search/index.tsx +0 -1
- package/src/search/indexer.ts +0 -246
- package/src/search/mcp.ts +0 -61
- package/src/search/printer.tsx +0 -86
- package/src/search/providers/algolia.ts +0 -88
- package/src/search/providers/fuse.ts +0 -19
- package/src/search/providers/pagefind.ts +0 -17
- package/src/search/providers/walker.ts +0 -30
- package/src/search/results.tsx +0 -182
- package/src/search/state.ts +0 -64
- package/src/search/types.ts +0 -116
- package/src/style.ts +0 -196
- package/src/styles/main.css +0 -986
- package/src/styles/primitives.css +0 -580
- package/src/styles/resets.css +0 -39
- package/src/styles/search.css +0 -341
- package/src/styles/sidebar.css +0 -85
- package/src/styles/snippets.css +0 -130
- package/src/styles/variables.css +0 -86
- 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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
66
|
+
return language === "http" ? "http.curl" : `${language}.default`;
|
|
37
67
|
}
|
|
38
68
|
function isSupportedLanguage(language) {
|
|
39
|
-
|
|
69
|
+
return Languages.includes(language);
|
|
40
70
|
}
|
|
41
|
-
|
|
42
|
-
|
|
71
|
+
const DefaultLanguage = "http";
|
|
72
|
+
const StainlessPathPattern = /(\(resource\) (?<resource>[^\s]+))( > (\(method\) (?<method>[^\s]+)|\(model\) (?<model>[^\s]+))?)?/;
|
|
43
73
|
function parseStainlessPath(stainlessPath) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
84
|
+
return stainlessPath.replace(/ > \([^\s]+\)$/, "");
|
|
55
85
|
}
|
|
56
86
|
function getResource(stainlessPath) {
|
|
57
|
-
|
|
58
|
-
return parsed?.resource[0];
|
|
87
|
+
return parseStainlessPath(stainlessPath)?.resource?.[0];
|
|
59
88
|
}
|
|
60
89
|
function parseRoute(basePath, route) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
161
|
-
|
|
198
|
+
const path = generateRoute(basePath, language, stainlessPath);
|
|
199
|
+
window.history.pushState({
|
|
200
|
+
stainlessPath,
|
|
201
|
+
language
|
|
202
|
+
}, "", path);
|
|
162
203
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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 };
|