@xyd-js/uniform 0.1.0-xyd.4 → 0.1.0-xyd.56
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 +418 -0
- package/LICENSE +21 -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 +42 -10
- 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 +42 -10
- package/dist/markdown.js.map +1 -1
- package/dist/types-BiglsETJ.d.cts +180 -0
- package/dist/types-BiglsETJ.d.ts +180 -0
- package/index.ts +10 -4
- package/package.json +9 -5
- package/src/index.ts +35 -17
- package/src/markdown/index.ts +5 -2
- package/src/markdown/utils.ts +45 -10
- 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 -70
- package/tsconfig.json +4 -1
- package/vitest.config.ts +15 -0
- package/dist/types-C8Pm_zQH.d.cts +0 -80
- package/dist/types-C8Pm_zQH.d.ts +0 -80
- package/src/utils.ts +0 -123
package/src/types.ts
CHANGED
|
@@ -1,3 +1,180 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {HighlightedCode} from "codehike/code";
|
|
3
|
+
|
|
4
|
+
// TODO: type, and category also as generic?
|
|
5
|
+
export interface Reference<
|
|
6
|
+
C = ReferenceContext,
|
|
7
|
+
M extends DefinitionMeta = DefinitionMeta,
|
|
8
|
+
VM extends DefinitionVariantMeta = DefinitionVariantMeta
|
|
9
|
+
> {
|
|
10
|
+
title: string;
|
|
11
|
+
description: string | React.ReactNode;
|
|
12
|
+
canonical: string;
|
|
13
|
+
|
|
14
|
+
definitions: Definition<M, VM>[] // TODO: in the future from generic?
|
|
15
|
+
examples: ExampleRoot
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
category?: ReferenceCategory; // TODO: do we need that?
|
|
19
|
+
|
|
20
|
+
type?: ReferenceType; // TODO: do we need that?
|
|
21
|
+
|
|
22
|
+
context?: C;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* TODO: !!!! BETTER !!!!
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
__UNSAFE_selector?: (selector: string) => any;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type DefinitionOpenAPIMeta = Meta<"contentType" | "required" | "definitionDescription">;
|
|
32
|
+
export type DefinitionTypeDocMeta = Meta<"type">;
|
|
33
|
+
export type DefinitionGraphqlMeta = Meta<"type" | "graphqlName">;
|
|
34
|
+
|
|
35
|
+
export type DefinitionMeta = DefinitionOpenAPIMeta | DefinitionTypeDocMeta | DefinitionGraphqlMeta
|
|
36
|
+
|
|
37
|
+
export type SymbolDef = {
|
|
38
|
+
id?: string | string[];
|
|
39
|
+
|
|
40
|
+
canonical?: string | string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface Definition<
|
|
44
|
+
M extends DefinitionMeta = DefinitionMeta,
|
|
45
|
+
VM extends DefinitionVariantMeta = DefinitionVariantMeta
|
|
46
|
+
> {
|
|
47
|
+
title: string;
|
|
48
|
+
|
|
49
|
+
properties: DefinitionProperty[];
|
|
50
|
+
|
|
51
|
+
rootProperty?: DefinitionProperty
|
|
52
|
+
|
|
53
|
+
variants?: DefinitionVariant<VM>[];
|
|
54
|
+
|
|
55
|
+
description?: string | React.ReactNode;
|
|
56
|
+
|
|
57
|
+
meta?: M[];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
symbolDef?: SymbolDef;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
id?: string;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
type?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type DefinitionVariantOpenAPIMeta = Meta<"status" | "contentType" | "definitionDescription" | "required">;
|
|
76
|
+
export type CommonDefinitionVariantMeta = Meta<"symbolName">;
|
|
77
|
+
|
|
78
|
+
export type DefinitionVariantMeta = CommonDefinitionVariantMeta | DefinitionVariantOpenAPIMeta
|
|
79
|
+
|
|
80
|
+
export interface DefinitionVariant<
|
|
81
|
+
M extends DefinitionVariantMeta = DefinitionVariantMeta
|
|
82
|
+
> {
|
|
83
|
+
title: string;
|
|
84
|
+
|
|
85
|
+
properties: DefinitionProperty[];
|
|
86
|
+
|
|
87
|
+
rootProperty?: DefinitionProperty
|
|
88
|
+
|
|
89
|
+
description?: string | React.ReactNode;
|
|
90
|
+
|
|
91
|
+
symbolDef?: SymbolDef;
|
|
92
|
+
|
|
93
|
+
meta?: M[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface Meta<T = string> {
|
|
97
|
+
name: T;
|
|
98
|
+
|
|
99
|
+
value?: unknown; // TODO: better type?
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type DefinitionPropertyMeta = Meta<"required" | "deprecated" | "internal" | "defaults" | "nullable" | "example" | "examples" | "minimum" | "maximum" | "enum-type"> // TODO: better solution than enum-type?
|
|
103
|
+
|
|
104
|
+
export enum DEFINED_DEFINITION_PROPERTY_TYPE {
|
|
105
|
+
UNION = "$$union",
|
|
106
|
+
|
|
107
|
+
XOR = "$$xor",
|
|
108
|
+
|
|
109
|
+
ARRAY = "$$array",
|
|
110
|
+
|
|
111
|
+
ENUM = "$$enum",
|
|
112
|
+
|
|
113
|
+
// TYPE = "$$type", TODO: good idea?
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface DefinitionProperty {
|
|
117
|
+
name: string;
|
|
118
|
+
|
|
119
|
+
type: string | DEFINED_DEFINITION_PROPERTY_TYPE
|
|
120
|
+
|
|
121
|
+
description: string | React.ReactNode;
|
|
122
|
+
|
|
123
|
+
// TODO: in the future more advanced examples?
|
|
124
|
+
examples?: string | string[];
|
|
125
|
+
|
|
126
|
+
symbolDef?: SymbolDef;
|
|
127
|
+
|
|
128
|
+
meta?: DefinitionPropertyMeta[];
|
|
129
|
+
|
|
130
|
+
context?: any // TODO: better type
|
|
131
|
+
|
|
132
|
+
properties?: DefinitionProperty[];
|
|
133
|
+
|
|
134
|
+
ofProperty?: DefinitionProperty;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface ExampleRoot {
|
|
138
|
+
groups: ExampleGroup[];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface ExampleGroup {
|
|
142
|
+
description?: string;
|
|
143
|
+
|
|
144
|
+
examples: Example[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface Example {
|
|
148
|
+
description?: string; // TODO: replace with title ?
|
|
149
|
+
|
|
150
|
+
codeblock: CodeBlock;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface CodeBlock {
|
|
154
|
+
title?: string;
|
|
155
|
+
|
|
156
|
+
tabs: CodeBlockTab[];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface CodeBlockTab {
|
|
160
|
+
// title of the tab e.g "JavaScript"
|
|
161
|
+
title: string;
|
|
162
|
+
|
|
163
|
+
// code in the tab e.g "console.log('Hello World')"
|
|
164
|
+
code: string
|
|
165
|
+
|
|
166
|
+
// language of the code e.g "js"
|
|
167
|
+
language: string;
|
|
168
|
+
|
|
169
|
+
// context of the generation method e.g openapi or graphql
|
|
170
|
+
context?: ExampleContext;
|
|
171
|
+
|
|
172
|
+
// TODO: highlighted code
|
|
173
|
+
highlighted?: HighlightedCode;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export type ExampleContext = GraphQLExampleContext | OpenAPIExampleContext;
|
|
177
|
+
|
|
1
178
|
// TODO: concept only
|
|
2
179
|
export enum ReferenceCategory {
|
|
3
180
|
// for React
|
|
@@ -23,14 +200,28 @@ export enum ReferenceType {
|
|
|
23
200
|
// end for React
|
|
24
201
|
|
|
25
202
|
// for API
|
|
203
|
+
// TODO: better type system for specific api typesl like gql or rest
|
|
26
204
|
REST_HTTP_GET = "rest_get",
|
|
27
205
|
REST_HTTP_POST = "rest_post",
|
|
28
206
|
REST_HTTP_PUT = "rest_put",
|
|
29
207
|
REST_HTTP_PATCH = "rest_patch",
|
|
30
208
|
REST_HTTP_DELETE = "rest_delete",
|
|
209
|
+
REST_HTTP_OPTIONS = "rest_options",
|
|
210
|
+
REST_HTTP_HEAD = "rest_head",
|
|
211
|
+
REST_HTTP_TRACE = "rest_trace",
|
|
212
|
+
|
|
213
|
+
REST_COMPONENT_SCHEMA = "rest_component_schema",
|
|
31
214
|
// ---
|
|
32
215
|
GRAPHQL_QUERY = "graphql_query",
|
|
33
216
|
GRAPHQL_MUTATION = "graphql_mutation",
|
|
217
|
+
GRAPHQL_SUBSCRIPTION = "graphql_subscription",
|
|
218
|
+
|
|
219
|
+
GRAPHQL_SCALAR = "graphql_scalar",
|
|
220
|
+
GRAPHQL_OBJECT = "graphql_object",
|
|
221
|
+
GRAPHQL_INTERFACE = "graphql_interface",
|
|
222
|
+
GRAPHQL_UNION = "graphql_union",
|
|
223
|
+
GRAPHQL_ENUM = "graphql_enum",
|
|
224
|
+
GRAPHQL_INPUT = "graphql_input",
|
|
34
225
|
// end for API
|
|
35
226
|
|
|
36
227
|
// for code
|
|
@@ -38,40 +229,58 @@ export enum ReferenceType {
|
|
|
38
229
|
// end for code
|
|
39
230
|
}
|
|
40
231
|
|
|
41
|
-
export interface
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// TODO: custom value?
|
|
45
|
-
export interface OpenAPIReferenceContext {
|
|
46
|
-
method: string;
|
|
232
|
+
export interface BaseReferenceContext {
|
|
233
|
+
group?: string[];
|
|
47
234
|
|
|
48
|
-
|
|
235
|
+
scopes?: string[];
|
|
49
236
|
}
|
|
50
237
|
|
|
51
|
-
export
|
|
238
|
+
export interface GraphQLReferenceContext extends BaseReferenceContext {
|
|
239
|
+
/**
|
|
240
|
+
* @internal
|
|
241
|
+
*/
|
|
242
|
+
graphqlTypeShort: string;
|
|
52
243
|
|
|
53
|
-
|
|
54
|
-
groups: ExampleGroup[];
|
|
244
|
+
graphqlName: string;
|
|
55
245
|
}
|
|
56
246
|
|
|
57
|
-
|
|
58
|
-
|
|
247
|
+
// TODO: custom value?
|
|
248
|
+
export interface OpenAPIReferenceContext extends BaseReferenceContext {
|
|
249
|
+
method?: string;
|
|
59
250
|
|
|
60
|
-
|
|
61
|
-
}
|
|
251
|
+
path?: string;
|
|
62
252
|
|
|
63
|
-
|
|
64
|
-
description?: string; // TODO: replace with title ?
|
|
253
|
+
fullPath?: string;
|
|
65
254
|
|
|
66
|
-
|
|
255
|
+
componentSchema?: string
|
|
67
256
|
}
|
|
68
257
|
|
|
69
|
-
export
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
258
|
+
export type TypeDocReferenceContextMeta = Meta<"internal">
|
|
259
|
+
|
|
260
|
+
// Add TypeDocReferenceContext to the union type
|
|
261
|
+
export interface TypeDocReferenceContext extends BaseReferenceContext {
|
|
262
|
+
symbolId: string;
|
|
263
|
+
symbolName: string;
|
|
264
|
+
symbolKind: number;
|
|
265
|
+
packageName: string;
|
|
266
|
+
fileName: string;
|
|
267
|
+
fileFullPath: string;
|
|
268
|
+
line: number;
|
|
269
|
+
col: number;
|
|
270
|
+
signatureText: {
|
|
271
|
+
code: string;
|
|
272
|
+
lang: string;
|
|
273
|
+
};
|
|
274
|
+
sourcecode: {
|
|
275
|
+
code: string;
|
|
276
|
+
lang: string;
|
|
277
|
+
};
|
|
278
|
+
category?: string;
|
|
279
|
+
meta?: TypeDocReferenceContextMeta[]
|
|
73
280
|
}
|
|
74
281
|
|
|
282
|
+
export type ReferenceContext = GraphQLReferenceContext | OpenAPIReferenceContext | TypeDocReferenceContext
|
|
283
|
+
|
|
75
284
|
export interface GraphQLExampleContext {
|
|
76
285
|
schema?: any; // TODO:
|
|
77
286
|
}
|
|
@@ -82,53 +291,4 @@ export interface OpenAPIExampleContext {
|
|
|
82
291
|
content?: string;
|
|
83
292
|
}
|
|
84
293
|
|
|
85
|
-
export type ExampleContext = GraphQLExampleContext | OpenAPIExampleContext;
|
|
86
|
-
|
|
87
|
-
export interface CodeBlockTab {
|
|
88
|
-
// title of the tab e.g "JavaScript"
|
|
89
|
-
title: string;
|
|
90
|
-
|
|
91
|
-
// code in the tab e.g "console.log('Hello World')"
|
|
92
|
-
code: string
|
|
93
|
-
|
|
94
|
-
// language of the code e.g "js"
|
|
95
|
-
language: string;
|
|
96
294
|
|
|
97
|
-
// context of the generation method e.g openapi or graphql
|
|
98
|
-
context?: ExampleContext;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface Reference {
|
|
102
|
-
title: string;
|
|
103
|
-
description: string;
|
|
104
|
-
canonical: string;
|
|
105
|
-
|
|
106
|
-
definitions: Definition[]
|
|
107
|
-
examples: ExampleRoot
|
|
108
|
-
|
|
109
|
-
category?: ReferenceCategory; // TODO: do we need that?
|
|
110
|
-
type?: ReferenceType; // TODO: do we need that?
|
|
111
|
-
context?: ReferenceContext;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface Definition {
|
|
115
|
-
title: string;
|
|
116
|
-
|
|
117
|
-
properties: DefinitionProperty[];
|
|
118
|
-
|
|
119
|
-
type?: string;
|
|
120
|
-
|
|
121
|
-
id?: string;
|
|
122
|
-
|
|
123
|
-
description?: string;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export interface DefinitionProperty {
|
|
127
|
-
name: string;
|
|
128
|
-
|
|
129
|
-
type: string;
|
|
130
|
-
|
|
131
|
-
description: string;
|
|
132
|
-
|
|
133
|
-
properties?: DefinitionProperty[];
|
|
134
|
-
}
|
package/tsconfig.json
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
+
"paths": {
|
|
4
|
+
"@xyd-js/core": ["../xyd-core/index.ts"],
|
|
5
|
+
},
|
|
3
6
|
"target": "ES2020",
|
|
4
7
|
"module": "ESNext",
|
|
5
8
|
"moduleResolution": "node",
|
|
@@ -11,7 +14,7 @@
|
|
|
11
14
|
"declaration": true,
|
|
12
15
|
"declarationMap": true,
|
|
13
16
|
"incremental": true,
|
|
14
|
-
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo"
|
|
17
|
+
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo",
|
|
15
18
|
},
|
|
16
19
|
"include": ["examples/basic-example/**/*.ts", "src/**/*.ts"],
|
|
17
20
|
"exclude": ["node_modules", "dist"]
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
globals: true,
|
|
6
|
+
environment: 'node',
|
|
7
|
+
include: ['src/**/*.test.ts' ,'packages/ts/**/*.test.ts'],
|
|
8
|
+
coverage: {
|
|
9
|
+
provider: 'v8',
|
|
10
|
+
reporter: ['text', 'json', 'html'],
|
|
11
|
+
include: ['src/**/*.ts', 'packages/ts/**/*.ts'],
|
|
12
|
+
exclude: ['src/**/*.test.ts', 'src/**/*.d.ts', 'packages/ts/**/*.test.ts', 'packages/ts/**/*.d.ts']
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
@@ -1,80 +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 {
|
|
57
|
-
title: string;
|
|
58
|
-
description: string;
|
|
59
|
-
canonical: string;
|
|
60
|
-
definitions: Definition[];
|
|
61
|
-
examples: ExampleRoot;
|
|
62
|
-
category?: ReferenceCategory;
|
|
63
|
-
type?: ReferenceType;
|
|
64
|
-
context?: ReferenceContext;
|
|
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
|
-
properties?: DefinitionProperty[];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
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/dist/types-C8Pm_zQH.d.ts
DELETED
|
@@ -1,80 +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 {
|
|
57
|
-
title: string;
|
|
58
|
-
description: string;
|
|
59
|
-
canonical: string;
|
|
60
|
-
definitions: Definition[];
|
|
61
|
-
examples: ExampleRoot;
|
|
62
|
-
category?: ReferenceCategory;
|
|
63
|
-
type?: ReferenceType;
|
|
64
|
-
context?: ReferenceContext;
|
|
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
|
-
properties?: DefinitionProperty[];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
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
|
-
|