@xyd-js/uniform 0.1.0-xyd.14 → 0.1.0-xyd.17
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/CHANGELOG.md +24 -0
- package/dist/index.cjs +141 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -8
- package/dist/index.d.ts +26 -8
- package/dist/index.js +138 -78
- package/dist/index.js.map +1 -1
- package/dist/markdown.cjs +1 -1
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +3 -1
- package/dist/markdown.d.ts +3 -1
- package/dist/markdown.js +1 -1
- package/dist/markdown.js.map +1 -1
- package/dist/types-xkS6sfq2.d.cts +180 -0
- package/dist/types-xkS6sfq2.d.ts +180 -0
- package/index.ts +10 -4
- package/package.json +8 -4
- package/result.json +5 -0
- package/src/index.ts +35 -16
- package/src/markdown/index.ts +1 -1
- package/src/plugins/__tests__/pluginJsonView.test.ts +132 -0
- package/src/plugins/index.ts +2 -0
- package/src/plugins/pluginJsonView.ts +54 -0
- package/src/plugins/pluginNavigation.ts +135 -0
- package/src/types.ts +230 -73
- package/tsconfig.json +4 -1
- package/vitest.config.ts +15 -0
- package/dist/types-BK7L2PZz.d.cts +0 -81
- package/dist/types-BK7L2PZz.d.ts +0 -81
- package/src/utils.ts +0 -123
package/dist/types-BK7L2PZz.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
declare enum ReferenceCategory {
|
|
2
|
-
COMPONENTS = "components",
|
|
3
|
-
HOOKS = "hooks",
|
|
4
|
-
REST = "rest",
|
|
5
|
-
GRAPHQL = "graphql",
|
|
6
|
-
FUNCTIONS = "functions"
|
|
7
|
-
}
|
|
8
|
-
declare enum ReferenceType {
|
|
9
|
-
COMPONENT = "component",
|
|
10
|
-
HOOK = "hook",
|
|
11
|
-
REST_HTTP_GET = "rest_get",
|
|
12
|
-
REST_HTTP_POST = "rest_post",
|
|
13
|
-
REST_HTTP_PUT = "rest_put",
|
|
14
|
-
REST_HTTP_PATCH = "rest_patch",
|
|
15
|
-
REST_HTTP_DELETE = "rest_delete",
|
|
16
|
-
GRAPHQL_QUERY = "graphql_query",
|
|
17
|
-
GRAPHQL_MUTATION = "graphql_mutation",
|
|
18
|
-
FUNCTION_JS = "function_js"
|
|
19
|
-
}
|
|
20
|
-
interface GraphQLReferenceContext {
|
|
21
|
-
}
|
|
22
|
-
interface OpenAPIReferenceContext {
|
|
23
|
-
method: string;
|
|
24
|
-
path: string;
|
|
25
|
-
}
|
|
26
|
-
type ReferenceContext = GraphQLReferenceContext | OpenAPIReferenceContext;
|
|
27
|
-
interface ExampleRoot {
|
|
28
|
-
groups: ExampleGroup[];
|
|
29
|
-
}
|
|
30
|
-
interface ExampleGroup {
|
|
31
|
-
description?: string;
|
|
32
|
-
examples: Example[];
|
|
33
|
-
}
|
|
34
|
-
interface Example {
|
|
35
|
-
description?: string;
|
|
36
|
-
codeblock: CodeBlock;
|
|
37
|
-
}
|
|
38
|
-
interface CodeBlock {
|
|
39
|
-
title?: string;
|
|
40
|
-
tabs: CodeBlockTab[];
|
|
41
|
-
}
|
|
42
|
-
interface GraphQLExampleContext {
|
|
43
|
-
schema?: any;
|
|
44
|
-
}
|
|
45
|
-
interface OpenAPIExampleContext {
|
|
46
|
-
status?: number;
|
|
47
|
-
content?: string;
|
|
48
|
-
}
|
|
49
|
-
type ExampleContext = GraphQLExampleContext | OpenAPIExampleContext;
|
|
50
|
-
interface CodeBlockTab {
|
|
51
|
-
title: string;
|
|
52
|
-
code: string;
|
|
53
|
-
language: string;
|
|
54
|
-
context?: ExampleContext;
|
|
55
|
-
}
|
|
56
|
-
interface Reference<C = ReferenceContext> {
|
|
57
|
-
title: string;
|
|
58
|
-
description: string;
|
|
59
|
-
canonical: string;
|
|
60
|
-
definitions: Definition[];
|
|
61
|
-
examples: ExampleRoot;
|
|
62
|
-
category?: ReferenceCategory;
|
|
63
|
-
type?: ReferenceType;
|
|
64
|
-
context?: C;
|
|
65
|
-
}
|
|
66
|
-
interface Definition {
|
|
67
|
-
title: string;
|
|
68
|
-
properties: DefinitionProperty[];
|
|
69
|
-
type?: string;
|
|
70
|
-
id?: string;
|
|
71
|
-
description?: string;
|
|
72
|
-
}
|
|
73
|
-
interface DefinitionProperty {
|
|
74
|
-
name: string;
|
|
75
|
-
type: string;
|
|
76
|
-
description: string;
|
|
77
|
-
context?: any;
|
|
78
|
-
properties?: DefinitionProperty[];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export { type CodeBlock as C, type Definition as D, type ExampleRoot as E, type GraphQLReferenceContext as G, type OpenAPIReferenceContext as O, type Reference as R, ReferenceCategory as a, ReferenceType as b, type ReferenceContext as c, type ExampleGroup as d, type Example as e, type GraphQLExampleContext as f, type OpenAPIExampleContext as g, type ExampleContext as h, type CodeBlockTab as i, type DefinitionProperty as j };
|
package/src/utils.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import matter from 'gray-matter';
|
|
3
|
-
import {Sidebar, FrontMatter, PageFrontMatter} from "@xyd-js/core";
|
|
4
|
-
|
|
5
|
-
import {Reference} from "./types";
|
|
6
|
-
import uniform from "./index";
|
|
7
|
-
|
|
8
|
-
// interface UniformFrontMatter extends FrontMatter { // TODO: it's concept only
|
|
9
|
-
// scopes?: string
|
|
10
|
-
// }
|
|
11
|
-
|
|
12
|
-
type GroupMap = {
|
|
13
|
-
[key: string]: {
|
|
14
|
-
__groups: GroupMap
|
|
15
|
-
pages: Set<string>
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface pluginNavigationOptions {
|
|
20
|
-
urlPrefix: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function pluginNavigation(options: pluginNavigationOptions) {
|
|
24
|
-
if (!options.urlPrefix) {
|
|
25
|
-
throw new Error("urlPrefix is required")
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return function pluginNavigationInner(cb: (cb: () => {
|
|
29
|
-
pageFrontMatter: PageFrontMatter
|
|
30
|
-
sidebar: Sidebar[]
|
|
31
|
-
}) => void) {
|
|
32
|
-
const pageFrontMatter: PageFrontMatter = {}
|
|
33
|
-
const groupMaps: GroupMap = {}
|
|
34
|
-
|
|
35
|
-
cb(() => {
|
|
36
|
-
return {
|
|
37
|
-
pageFrontMatter: pageFrontMatter,
|
|
38
|
-
sidebar: convertGroupMapsToNavigations(groupMaps) as Sidebar[]
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return (ref: Reference) => {
|
|
43
|
-
const content = matter(ref.description || "") // TODO: pluginMatter before?
|
|
44
|
-
|
|
45
|
-
if (content.data) {
|
|
46
|
-
const data = content.data as FrontMatter
|
|
47
|
-
|
|
48
|
-
const pagePath = path.join(options.urlPrefix, ref.canonical)
|
|
49
|
-
|
|
50
|
-
if (data.title) {
|
|
51
|
-
pageFrontMatter[pagePath] = {
|
|
52
|
-
title: data.title,
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (data.group) {
|
|
57
|
-
if (typeof content?.data?.group === "string") {
|
|
58
|
-
// TODO: seek nested group (it's not always from 0)
|
|
59
|
-
throw new Error("group as string is not supported yet")
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
content.data.group.reduce((groups: GroupMap, group: string, i: number) => {
|
|
63
|
-
if (!groups[group]) {
|
|
64
|
-
groups[group] = {
|
|
65
|
-
__groups: {},
|
|
66
|
-
pages: new Set()
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (i === content.data.group.length - 1) {
|
|
71
|
-
groups[group].pages.add(pagePath)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return groups[group].__groups
|
|
75
|
-
}, groupMaps)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// back description to original without frontmatter
|
|
79
|
-
ref.description = content.content
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
function convertGroupMapsToNavigations(groupMaps: GroupMap): Sidebar[] {
|
|
87
|
-
const nav: Sidebar[] = []
|
|
88
|
-
|
|
89
|
-
Object.keys(groupMaps).map((groupName) => {
|
|
90
|
-
const current = groupMaps[groupName]
|
|
91
|
-
|
|
92
|
-
const pages: string[] | Sidebar[] = []
|
|
93
|
-
|
|
94
|
-
current.pages.forEach((page: string) => {
|
|
95
|
-
pages.push(page)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
if (Object.keys(current.__groups).length) {
|
|
99
|
-
const subNav: Sidebar = {
|
|
100
|
-
group: groupName,
|
|
101
|
-
pages: convertGroupMapsToNavigations(current.__groups)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
nav.push(subNav)
|
|
105
|
-
} else {
|
|
106
|
-
nav.push({
|
|
107
|
-
group: groupName,
|
|
108
|
-
pages,
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
return nav
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// example usage:
|
|
117
|
-
// const response = uniform([/* references */], {
|
|
118
|
-
// plugins: [pluginNavigation({
|
|
119
|
-
// urlPrefix: "/docs"
|
|
120
|
-
// })],
|
|
121
|
-
// });
|
|
122
|
-
|
|
123
|
-
|