@xyd-js/uniform 0.1.0-xyd.15 → 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 +16 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @xyd-js/uniform
|
|
2
2
|
|
|
3
|
+
## 0.1.0-xyd.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- test
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @xyd-js/core@0.1.0-xyd.15
|
|
10
|
+
|
|
11
|
+
## 0.1.0-xyd.16
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- update packages
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @xyd-js/core@0.1.0-xyd.14
|
|
18
|
+
|
|
3
19
|
## 0.1.0-xyd.15
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -30,31 +30,81 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
DEFINED_DEFINITION_PROPERTY_TYPE: () => DEFINED_DEFINITION_PROPERTY_TYPE,
|
|
33
34
|
ReferenceCategory: () => ReferenceCategory,
|
|
34
35
|
ReferenceType: () => ReferenceType,
|
|
35
36
|
default: () => uniform,
|
|
37
|
+
pluginJsonView: () => pluginJsonView,
|
|
36
38
|
pluginNavigation: () => pluginNavigation
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(index_exports);
|
|
39
41
|
|
|
42
|
+
// src/types.ts
|
|
43
|
+
var DEFINED_DEFINITION_PROPERTY_TYPE = /* @__PURE__ */ ((DEFINED_DEFINITION_PROPERTY_TYPE2) => {
|
|
44
|
+
DEFINED_DEFINITION_PROPERTY_TYPE2["UNION"] = "$$union";
|
|
45
|
+
DEFINED_DEFINITION_PROPERTY_TYPE2["XOR"] = "$$xor";
|
|
46
|
+
DEFINED_DEFINITION_PROPERTY_TYPE2["ARRAY"] = "$$array";
|
|
47
|
+
DEFINED_DEFINITION_PROPERTY_TYPE2["ENUM"] = "$$enum";
|
|
48
|
+
return DEFINED_DEFINITION_PROPERTY_TYPE2;
|
|
49
|
+
})(DEFINED_DEFINITION_PROPERTY_TYPE || {});
|
|
50
|
+
var ReferenceCategory = /* @__PURE__ */ ((ReferenceCategory2) => {
|
|
51
|
+
ReferenceCategory2["COMPONENTS"] = "components";
|
|
52
|
+
ReferenceCategory2["HOOKS"] = "hooks";
|
|
53
|
+
ReferenceCategory2["REST"] = "rest";
|
|
54
|
+
ReferenceCategory2["GRAPHQL"] = "graphql";
|
|
55
|
+
ReferenceCategory2["FUNCTIONS"] = "functions";
|
|
56
|
+
return ReferenceCategory2;
|
|
57
|
+
})(ReferenceCategory || {});
|
|
58
|
+
var ReferenceType = /* @__PURE__ */ ((ReferenceType2) => {
|
|
59
|
+
ReferenceType2["COMPONENT"] = "component";
|
|
60
|
+
ReferenceType2["HOOK"] = "hook";
|
|
61
|
+
ReferenceType2["REST_HTTP_GET"] = "rest_get";
|
|
62
|
+
ReferenceType2["REST_HTTP_POST"] = "rest_post";
|
|
63
|
+
ReferenceType2["REST_HTTP_PUT"] = "rest_put";
|
|
64
|
+
ReferenceType2["REST_HTTP_PATCH"] = "rest_patch";
|
|
65
|
+
ReferenceType2["REST_HTTP_DELETE"] = "rest_delete";
|
|
66
|
+
ReferenceType2["REST_HTTP_OPTIONS"] = "rest_options";
|
|
67
|
+
ReferenceType2["REST_HTTP_HEAD"] = "rest_head";
|
|
68
|
+
ReferenceType2["REST_HTTP_TRACE"] = "rest_trace";
|
|
69
|
+
ReferenceType2["REST_COMPONENT_SCHEMA"] = "rest_component_schema";
|
|
70
|
+
ReferenceType2["GRAPHQL_QUERY"] = "graphql_query";
|
|
71
|
+
ReferenceType2["GRAPHQL_MUTATION"] = "graphql_mutation";
|
|
72
|
+
ReferenceType2["GRAPHQL_SUBSCRIPTION"] = "graphql_subscription";
|
|
73
|
+
ReferenceType2["GRAPHQL_SCALAR"] = "graphql_scalar";
|
|
74
|
+
ReferenceType2["GRAPHQL_OBJECT"] = "graphql_object";
|
|
75
|
+
ReferenceType2["GRAPHQL_INTERFACE"] = "graphql_interface";
|
|
76
|
+
ReferenceType2["GRAPHQL_UNION"] = "graphql_union";
|
|
77
|
+
ReferenceType2["GRAPHQL_ENUM"] = "graphql_enum";
|
|
78
|
+
ReferenceType2["GRAPHQL_INPUT"] = "graphql_input";
|
|
79
|
+
ReferenceType2["FUNCTION_JS"] = "function_js";
|
|
80
|
+
return ReferenceType2;
|
|
81
|
+
})(ReferenceType || {});
|
|
82
|
+
|
|
40
83
|
// src/index.ts
|
|
41
84
|
function uniform(references, config) {
|
|
42
85
|
const response = {
|
|
43
86
|
references,
|
|
44
87
|
out: {}
|
|
45
88
|
};
|
|
46
|
-
const finishCallbacks = /* @__PURE__ */ new Set();
|
|
47
89
|
config.plugins.forEach((plugin) => {
|
|
48
|
-
|
|
49
|
-
|
|
90
|
+
let defer = void 0;
|
|
91
|
+
const call = plugin({
|
|
92
|
+
references,
|
|
93
|
+
defer: (cb) => {
|
|
94
|
+
if (typeof cb === "function") {
|
|
95
|
+
defer = cb;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// visit: (pattern, callback) => {
|
|
99
|
+
// }
|
|
50
100
|
});
|
|
51
|
-
references.
|
|
52
|
-
call(ref
|
|
101
|
+
references.map((ref, i) => {
|
|
102
|
+
call(ref, {
|
|
103
|
+
index: i
|
|
104
|
+
});
|
|
53
105
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (typeof cb === "function") {
|
|
57
|
-
const resp = cb();
|
|
106
|
+
if (typeof defer === "function") {
|
|
107
|
+
const resp = defer();
|
|
58
108
|
if (typeof resp !== "object") {
|
|
59
109
|
throw new Error(`Invalid callback return type: ${typeof resp}`);
|
|
60
110
|
}
|
|
@@ -62,112 +112,124 @@ function uniform(references, config) {
|
|
|
62
112
|
...response.out,
|
|
63
113
|
...resp
|
|
64
114
|
};
|
|
65
|
-
} else {
|
|
66
|
-
throw new Error(`Invalid callback type: ${typeof cb}`);
|
|
67
115
|
}
|
|
68
116
|
});
|
|
69
117
|
return response;
|
|
70
118
|
}
|
|
71
119
|
|
|
72
|
-
// src/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
120
|
+
// src/plugins/pluginJsonView.ts
|
|
121
|
+
function pluginJsonView(options) {
|
|
122
|
+
return function pluginJsonViewInner({
|
|
123
|
+
defer
|
|
124
|
+
}) {
|
|
125
|
+
const jsonViews = [];
|
|
126
|
+
defer(() => ({
|
|
127
|
+
jsonViews
|
|
128
|
+
}));
|
|
129
|
+
return (ref) => {
|
|
130
|
+
const lines = [];
|
|
131
|
+
lines.push("{");
|
|
132
|
+
ref.definitions.forEach((def) => {
|
|
133
|
+
def.properties.forEach((prop, index) => {
|
|
134
|
+
var _a;
|
|
135
|
+
const value = (((_a = prop.examples) == null ? void 0 : _a[0]) || "").replace(/^"|"$|[^a-zA-Z0-9\s\-_.,:/@#=;+()]/g, "");
|
|
136
|
+
const comment = prop.examples && prop.examples.length > 1 ? ` // or "${prop.examples[1].replace(/^"|"$|[^a-zA-Z0-9\s\-_.,:/@#=;+()]/g, "")}"` : "";
|
|
137
|
+
const isLast = index === def.properties.length - 1;
|
|
138
|
+
lines.push(` "${prop.name}": "${value}"${isLast ? "" : ","}${comment}`);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
lines.push("}");
|
|
142
|
+
jsonViews.push(lines.join("\n"));
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/plugins/pluginNavigation.ts
|
|
148
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
149
|
+
var DEFAULT_VIRTUAL_FOLDER = ".xyd/.cache/.content";
|
|
150
|
+
var DEFAULT_GROUP_NAME = "API Reference";
|
|
151
|
+
function pluginNavigation(settings, options) {
|
|
76
152
|
if (!options.urlPrefix) {
|
|
77
153
|
throw new Error("urlPrefix is required");
|
|
78
154
|
}
|
|
79
|
-
return function pluginNavigationInner(
|
|
155
|
+
return function pluginNavigationInner({
|
|
156
|
+
defer
|
|
157
|
+
}) {
|
|
80
158
|
const pageFrontMatter = {};
|
|
81
159
|
const groupMaps = {};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
87
|
-
});
|
|
160
|
+
defer(() => ({
|
|
161
|
+
pageFrontMatter,
|
|
162
|
+
sidebar: convertGroupMapsToSidebar(settings, groupMaps)
|
|
163
|
+
}));
|
|
88
164
|
return (ref) => {
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
165
|
+
const dataCtx = ref.context;
|
|
166
|
+
const pagePath = import_node_path.default.join(options.urlPrefix, ref.canonical);
|
|
167
|
+
let group = (dataCtx == null ? void 0 : dataCtx.group) || [];
|
|
168
|
+
let title = ref.title;
|
|
169
|
+
if (pageFrontMatter[pagePath]) {
|
|
170
|
+
console.error("(pluginNavigation): pageFrontMatter[pagePath] already exists", pagePath);
|
|
171
|
+
}
|
|
172
|
+
if (!group) {
|
|
173
|
+
group = [options.defaultGroup || DEFAULT_GROUP_NAME];
|
|
174
|
+
}
|
|
175
|
+
pageFrontMatter[pagePath] = {
|
|
176
|
+
title
|
|
177
|
+
};
|
|
178
|
+
if (typeof group === "string") {
|
|
179
|
+
throw new Error("group as string is not supported yet");
|
|
180
|
+
}
|
|
181
|
+
group.reduce((groups, groupName, i) => {
|
|
182
|
+
if (!groups[groupName]) {
|
|
183
|
+
groups[groupName] = {
|
|
184
|
+
__groups: {},
|
|
185
|
+
pages: /* @__PURE__ */ new Set()
|
|
97
186
|
};
|
|
98
187
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
throw new Error("group as string is not supported yet");
|
|
102
|
-
}
|
|
103
|
-
content.data.group.reduce((groups, group, i) => {
|
|
104
|
-
if (!groups[group]) {
|
|
105
|
-
groups[group] = {
|
|
106
|
-
__groups: {},
|
|
107
|
-
pages: /* @__PURE__ */ new Set()
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
if (i === content.data.group.length - 1) {
|
|
111
|
-
groups[group].pages.add(pagePath);
|
|
112
|
-
}
|
|
113
|
-
return groups[group].__groups;
|
|
114
|
-
}, groupMaps);
|
|
188
|
+
if (i === group.length - 1) {
|
|
189
|
+
groups[groupName].pages.add(pagePath);
|
|
115
190
|
}
|
|
116
|
-
|
|
117
|
-
}
|
|
191
|
+
return groups[groupName].__groups;
|
|
192
|
+
}, groupMaps);
|
|
118
193
|
};
|
|
119
194
|
};
|
|
120
195
|
}
|
|
121
|
-
function
|
|
196
|
+
function convertGroupMapsToSidebar(settings, groupMaps) {
|
|
122
197
|
const nav = [];
|
|
123
198
|
Object.keys(groupMaps).map((groupName) => {
|
|
124
199
|
const current = groupMaps[groupName];
|
|
125
200
|
const pages = [];
|
|
126
201
|
current.pages.forEach((page) => {
|
|
127
|
-
|
|
202
|
+
var _a, _b;
|
|
203
|
+
if ((_b = (_a = settings == null ? void 0 : settings.engine) == null ? void 0 : _a.uniform) == null ? void 0 : _b.store) {
|
|
204
|
+
pages.push(page);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
pages.push({
|
|
208
|
+
virtual: import_node_path.default.join(DEFAULT_VIRTUAL_FOLDER, page),
|
|
209
|
+
page
|
|
210
|
+
});
|
|
128
211
|
});
|
|
129
212
|
if (Object.keys(current.__groups).length) {
|
|
130
213
|
const subNav = {
|
|
131
214
|
group: groupName,
|
|
132
|
-
pages:
|
|
215
|
+
pages: convertGroupMapsToSidebar(settings, current.__groups)
|
|
133
216
|
};
|
|
134
217
|
nav.push(subNav);
|
|
135
|
-
|
|
136
|
-
nav.push({
|
|
137
|
-
group: groupName,
|
|
138
|
-
pages
|
|
139
|
-
});
|
|
218
|
+
return;
|
|
140
219
|
}
|
|
220
|
+
nav.push({
|
|
221
|
+
group: groupName,
|
|
222
|
+
pages
|
|
223
|
+
});
|
|
141
224
|
});
|
|
142
225
|
return nav;
|
|
143
226
|
}
|
|
144
|
-
|
|
145
|
-
// src/types.ts
|
|
146
|
-
var ReferenceCategory = /* @__PURE__ */ ((ReferenceCategory2) => {
|
|
147
|
-
ReferenceCategory2["COMPONENTS"] = "components";
|
|
148
|
-
ReferenceCategory2["HOOKS"] = "hooks";
|
|
149
|
-
ReferenceCategory2["REST"] = "rest";
|
|
150
|
-
ReferenceCategory2["GRAPHQL"] = "graphql";
|
|
151
|
-
ReferenceCategory2["FUNCTIONS"] = "functions";
|
|
152
|
-
return ReferenceCategory2;
|
|
153
|
-
})(ReferenceCategory || {});
|
|
154
|
-
var ReferenceType = /* @__PURE__ */ ((ReferenceType2) => {
|
|
155
|
-
ReferenceType2["COMPONENT"] = "component";
|
|
156
|
-
ReferenceType2["HOOK"] = "hook";
|
|
157
|
-
ReferenceType2["REST_HTTP_GET"] = "rest_get";
|
|
158
|
-
ReferenceType2["REST_HTTP_POST"] = "rest_post";
|
|
159
|
-
ReferenceType2["REST_HTTP_PUT"] = "rest_put";
|
|
160
|
-
ReferenceType2["REST_HTTP_PATCH"] = "rest_patch";
|
|
161
|
-
ReferenceType2["REST_HTTP_DELETE"] = "rest_delete";
|
|
162
|
-
ReferenceType2["GRAPHQL_QUERY"] = "graphql_query";
|
|
163
|
-
ReferenceType2["GRAPHQL_MUTATION"] = "graphql_mutation";
|
|
164
|
-
ReferenceType2["FUNCTION_JS"] = "function_js";
|
|
165
|
-
return ReferenceType2;
|
|
166
|
-
})(ReferenceType || {});
|
|
167
227
|
// Annotate the CommonJS export names for ESM import in node:
|
|
168
228
|
0 && (module.exports = {
|
|
229
|
+
DEFINED_DEFINITION_PROPERTY_TYPE,
|
|
169
230
|
ReferenceCategory,
|
|
170
231
|
ReferenceType,
|
|
232
|
+
pluginJsonView,
|
|
171
233
|
pluginNavigation
|
|
172
234
|
});
|
|
173
235
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts","../src/index.ts","../src/utils.ts","../src/types.ts"],"sourcesContent":["export {default} from \"./src/index\"\n\nexport {\n pluginNavigation\n} from \"./src/utils\"\n\nexport * from \"./src/types\"\n\n","// Define the new PluginV type with a callback function that returns another function\nimport {Reference} from \"./types\";\n\n// Define the new PluginV type with a callback function that returns another function\nexport type UniformPlugin<T> = (cb: (cb: () => T) => void) => (ref: Reference) => void;\n\n// Utility type to infer if a type is an array and avoid wrapping it into an array twice\ntype NormalizeArray<T> = T extends Array<infer U> ? U[] : T;\n\n// Infer the return type of the plugin callback properly and normalize array types\ntype PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;\n\n// Merge all plugin return types into a single object and normalize arrays\ntype MergePluginResults<T extends UniformPlugin<any>[]> = {\n [K in keyof UnionToIntersection<PluginResult<T[number]>>]: NormalizeArray<UnionToIntersection<PluginResult<T[number]>>[K]>\n};\n\n// Utility type to handle intersection to an object type\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;\n\n// Implement the uniform function\nexport default function uniform<T extends UniformPlugin<any>[]>(\n references: Reference[],\n config: { plugins: T }\n) {\n // Infer the merged result type from all plugins\n type ResultType = MergePluginResults<T>;\n\n // Initialize the response with a type-safe out object\n const response: {\n references: Reference[]\n out: { [K in keyof ResultType]: ResultType[K] }\n } = {\n references,\n out: {} as { [K in keyof ResultType]: ResultType[K] }\n };\n\n const finishCallbacks = new Set();\n\n config.plugins.forEach((plugin) => {\n const call = plugin(cb => {\n finishCallbacks.add(cb);\n })\n\n references.forEach((ref) => {\n call(ref)\n });\n })\n\n finishCallbacks.forEach(cb => {\n if (typeof cb === \"function\") {\n const resp = cb()\n if (typeof resp !== \"object\") {\n throw new Error(`Invalid callback return type: ${typeof resp}`)\n }\n\n response.out = {\n ...response.out,\n ...resp\n }\n } else {\n throw new Error(`Invalid callback type: ${typeof cb}`)\n }\n });\n\n return response;\n}\n\n// Example usage\n// const examplePlugin: UniformPlugin<{ value: boolean }> = (cb) => {\n// return (ref: Reference) => {\n// };\n// };\n// function examplePlugin(cb: (cb: () => { value: boolean }) => void) {\n// cb(() => ({\n// value: true,\n// }));\n//\n// return (ref: Reference) => {\n//\n// };\n// }\n// const response = uniform([/* references */], {\n// plugins: [examplePlugin],\n// });\n// response.out\n","import path from 'path';\nimport matter from 'gray-matter';\nimport {Sidebar, FrontMatter, PageFrontMatter} from \"@xyd-js/core\";\n\nimport {Reference} from \"./types\";\nimport uniform from \"./index\";\n\n// interface UniformFrontMatter extends FrontMatter { // TODO: it's concept only\n// scopes?: string\n// }\n\ntype GroupMap = {\n [key: string]: {\n __groups: GroupMap\n pages: Set<string>\n }\n}\n\nexport interface pluginNavigationOptions {\n urlPrefix: string\n}\n\nexport function pluginNavigation(options: pluginNavigationOptions) {\n if (!options.urlPrefix) {\n throw new Error(\"urlPrefix is required\")\n }\n\n return function pluginNavigationInner(cb: (cb: () => {\n pageFrontMatter: PageFrontMatter\n sidebar: Sidebar[]\n }) => void) {\n const pageFrontMatter: PageFrontMatter = {}\n const groupMaps: GroupMap = {}\n\n cb(() => {\n return {\n pageFrontMatter: pageFrontMatter,\n sidebar: convertGroupMapsToNavigations(groupMaps) as Sidebar[]\n }\n })\n\n return (ref: Reference) => {\n const content = matter(ref.description || \"\") // TODO: pluginMatter before?\n\n if (content.data) {\n const data = content.data as FrontMatter\n\n const pagePath = path.join(options.urlPrefix, ref.canonical)\n\n if (data.title) {\n pageFrontMatter[pagePath] = {\n title: data.title,\n }\n }\n\n if (data.group) {\n if (typeof content?.data?.group === \"string\") {\n // TODO: seek nested group (it's not always from 0)\n throw new Error(\"group as string is not supported yet\")\n }\n\n content.data.group.reduce((groups: GroupMap, group: string, i: number) => {\n if (!groups[group]) {\n groups[group] = {\n __groups: {},\n pages: new Set()\n }\n }\n\n if (i === content.data.group.length - 1) {\n groups[group].pages.add(pagePath)\n }\n\n return groups[group].__groups\n }, groupMaps)\n }\n\n // back description to original without frontmatter\n ref.description = content.content\n }\n }\n }\n}\n\n\nfunction convertGroupMapsToNavigations(groupMaps: GroupMap): Sidebar[] {\n const nav: Sidebar[] = []\n\n Object.keys(groupMaps).map((groupName) => {\n const current = groupMaps[groupName]\n\n const pages: string[] | Sidebar[] = []\n\n current.pages.forEach((page: string) => {\n pages.push(page)\n })\n\n if (Object.keys(current.__groups).length) {\n const subNav: Sidebar = {\n group: groupName,\n pages: convertGroupMapsToNavigations(current.__groups)\n }\n\n nav.push(subNav)\n } else {\n nav.push({\n group: groupName,\n pages,\n })\n }\n })\n\n return nav\n}\n\n// example usage:\n// const response = uniform([/* references */], {\n// plugins: [pluginNavigation({\n// urlPrefix: \"/docs\"\n// })],\n// });\n\n\n","// TODO: concept only\nexport enum ReferenceCategory {\n // for React\n COMPONENTS = \"components\",\n HOOKS = \"hooks\",\n // end for React\n\n // for API\n REST = \"rest\",\n GRAPHQL = \"graphql\",\n // end for API\n\n // for code\n FUNCTIONS = \"functions\",\n //\n}\n\n// TODO: concept only\nexport enum ReferenceType {\n // for React\n COMPONENT = \"component\",\n HOOK = \"hook\",\n // end for React\n\n // for API\n REST_HTTP_GET = \"rest_get\",\n REST_HTTP_POST = \"rest_post\",\n REST_HTTP_PUT = \"rest_put\",\n REST_HTTP_PATCH = \"rest_patch\",\n REST_HTTP_DELETE = \"rest_delete\",\n // ---\n GRAPHQL_QUERY = \"graphql_query\",\n GRAPHQL_MUTATION = \"graphql_mutation\",\n // end for API\n\n // for code\n FUNCTION_JS = \"function_js\",\n // end for code\n}\n\nexport interface GraphQLReferenceContext {\n}\n\n// TODO: custom value?\nexport interface OpenAPIReferenceContext {\n method: string;\n\n path: string;\n}\n\nexport type ReferenceContext = GraphQLReferenceContext | OpenAPIReferenceContext;\n\nexport interface ExampleRoot {\n groups: ExampleGroup[];\n}\n\nexport interface ExampleGroup {\n description?: string;\n\n examples: Example[];\n}\n\nexport interface Example {\n description?: string; // TODO: replace with title ?\n\n codeblock: CodeBlock;\n}\n\nexport interface CodeBlock {\n title?: string;\n\n tabs: CodeBlockTab[];\n}\n\nexport interface GraphQLExampleContext {\n schema?: any; // TODO:\n}\n\nexport interface OpenAPIExampleContext {\n status?: number;\n\n content?: string;\n}\n\nexport type ExampleContext = GraphQLExampleContext | OpenAPIExampleContext;\n\nexport interface CodeBlockTab {\n // title of the tab e.g \"JavaScript\"\n title: string;\n\n // code in the tab e.g \"console.log('Hello World')\"\n code: string\n\n // language of the code e.g \"js\"\n language: string;\n\n // context of the generation method e.g openapi or graphql\n context?: ExampleContext;\n}\n\n// TODO: type, and category also as generic?\nexport interface Reference<C = ReferenceContext> {\n title: string;\n description: string;\n canonical: string;\n\n definitions: Definition[]\n examples: ExampleRoot\n\n category?: ReferenceCategory; // TODO: do we need that?\n type?: ReferenceType; // TODO: do we need that?\n context?: C;\n}\n\nexport interface Definition {\n title: string;\n\n properties: DefinitionProperty[];\n\n type?: string;\n\n id?: string;\n\n description?: string;\n}\n\nexport interface DefinitionProperty {\n name: string;\n\n type: string;\n\n description: string;\n\n context?: any // TODO: better type\n\n properties?: DefinitionProperty[];\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqBe,SAAR,QACH,YACA,QACF;AAKE,QAAM,WAGF;AAAA,IACA;AAAA,IACA,KAAK,CAAC;AAAA,EACV;AAEA,QAAM,kBAAkB,oBAAI,IAAI;AAEhC,SAAO,QAAQ,QAAQ,CAAC,WAAW;AAC/B,UAAM,OAAO,OAAO,QAAM;AACtB,sBAAgB,IAAI,EAAE;AAAA,IAC1B,CAAC;AAED,eAAW,QAAQ,CAAC,QAAQ;AACxB,WAAK,GAAG;AAAA,IACZ,CAAC;AAAA,EACL,CAAC;AAED,kBAAgB,QAAQ,QAAM;AAC1B,QAAI,OAAO,OAAO,YAAY;AAC1B,YAAM,OAAO,GAAG;AAChB,UAAI,OAAO,SAAS,UAAU;AAC1B,cAAM,IAAI,MAAM,iCAAiC,OAAO,IAAI,EAAE;AAAA,MAClE;AAEA,eAAS,MAAM;AAAA,QACX,GAAG,SAAS;AAAA,QACZ,GAAG;AAAA,MACP;AAAA,IACJ,OAAO;AACH,YAAM,IAAI,MAAM,0BAA0B,OAAO,EAAE,EAAE;AAAA,IACzD;AAAA,EACJ,CAAC;AAED,SAAO;AACX;;;AClEA,kBAAiB;AACjB,yBAAmB;AAqBZ,SAAS,iBAAiB,SAAkC;AAC/D,MAAI,CAAC,QAAQ,WAAW;AACpB,UAA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,QAA8B,CAAC;AAErC,YAAQ,MAAM,QAAQ,CAAC,SAAiB;AACpC,YAAM,KAAK,IAAI;AAAA,IACnB,CAAC;AAED,QAAI,OAAO,KAAK,QAAQ,QAAQ,EAAE,QAAQ;AACtC,YAAM,SAAkB;AAAA,QACpB,OAAO;AAAA,QACP,OAAO,8BAA8B,QAAQ,QAAQ;AAAA,MACzD;AAEA,UAAI,KAAK,MAAM;AAAA,IACnB,OAAO;AACH,UAAI,KAAK;AAAA,QACL,OAAO;AAAA,QACP;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAED,SAAO;AACX;;;AChHO,IAAK,oBAAL,kBAAKC,uBAAL;AAEH,EAAAA,mBAAA,gBAAa;AACb,EAAAA,mBAAA,WAAQ;AAIR,EAAAA,mBAAA,UAAO;AACP,EAAAA,mBAAA,aAAU;AAIV,EAAAA,mBAAA,eAAY;AAZJ,SAAAA;AAAA,GAAA;AAiBL,IAAK,gBAAL,kBAAKC,mBAAL;AAEH,EAAAA,eAAA,eAAY;AACZ,EAAAA,eAAA,UAAO;AAIP,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,oBAAiB;AACjB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,qBAAkB;AAClB,EAAAA,eAAA,sBAAmB;AAEnB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,sBAAmB;AAInB,EAAAA,eAAA,iBAAc;AAlBN,SAAAA;AAAA,GAAA;","names":["matter","path","ReferenceCategory","ReferenceType"]}
|
|
1
|
+
{"version":3,"sources":["../index.ts","../src/types.ts","../src/index.ts","../src/plugins/pluginJsonView.ts","../src/plugins/pluginNavigation.ts"],"sourcesContent":["export * from \"./src/types\"\nexport type {\n UniformPlugin,\n UniformPluginArgs\n} from \"./src/index\"\n\nexport { default } from \"./src/index\"\n\nexport {\n pluginJsonView,\n pluginNavigation,\n} from \"./src/plugins\"\n\n\n","import React from \"react\";\nimport {HighlightedCode} from \"codehike/code\";\n\n// TODO: type, and category also as generic?\nexport interface Reference<\n C = ReferenceContext,\n M extends DefinitionMeta = DefinitionMeta,\n VM extends DefinitionVariantMeta = DefinitionVariantMeta\n> {\n title: string;\n description: string | React.ReactNode;\n canonical: string;\n\n definitions: Definition<M, VM>[] // TODO: in the future from generic?\n examples: ExampleRoot\n\n\n category?: ReferenceCategory; // TODO: do we need that?\n\n type?: ReferenceType; // TODO: do we need that?\n\n context?: C;\n\n /**\n * TODO: !!!! BETTER !!!!\n * @internal\n */\n __UNSAFE_selector?: (selector: string) => any;\n}\n\nexport type DefinitionOpenAPIMeta = Meta<\"contentType\" | \"required\" | \"definitionDescription\">;\nexport type DefinitionTypeDocMeta = Meta<\"type\">;\nexport type DefinitionGraphqlMeta = Meta<\"type\" | \"graphqlName\">;\n\nexport type DefinitionMeta = DefinitionOpenAPIMeta | DefinitionTypeDocMeta | DefinitionGraphqlMeta\n\nexport type SymbolDef = {\n id?: string | string[];\n\n canonical?: string | string[];\n}\n\nexport interface Definition<\n M extends DefinitionMeta = DefinitionMeta,\n VM extends DefinitionVariantMeta = DefinitionVariantMeta\n> {\n title: string;\n\n properties: DefinitionProperty[];\n\n rootProperty?: DefinitionProperty\n\n variants?: DefinitionVariant<VM>[];\n\n description?: string | React.ReactNode;\n\n meta?: M[];\n\n /**\n * @unsafe\n */\n symbolDef?: SymbolDef;\n\n /**\n * @unsafe\n */\n id?: string;\n\n /**\n * @unsafe\n */\n type?: string;\n}\n\nexport type DefinitionVariantOpenAPIMeta = Meta<\"status\" | \"contentType\" | \"definitionDescription\" | \"required\">;\nexport type CommonDefinitionVariantMeta = Meta<\"symbolName\">;\n\nexport type DefinitionVariantMeta = CommonDefinitionVariantMeta | DefinitionVariantOpenAPIMeta\n\nexport interface DefinitionVariant<\n M extends DefinitionVariantMeta = DefinitionVariantMeta\n> {\n title: string;\n\n properties: DefinitionProperty[];\n\n rootProperty?: DefinitionProperty\n\n description?: string | React.ReactNode;\n\n symbolDef?: SymbolDef;\n\n meta?: M[];\n}\n\nexport interface Meta<T = string> {\n name: T;\n\n value?: unknown; // TODO: better type?\n}\n\nexport type DefinitionPropertyMeta = Meta<\"required\" | \"deprecated\" | \"internal\" | \"defaults\" | \"nullable\" | \"example\" | \"examples\" | \"minimum\" | \"maximum\" | \"enum-type\"> // TODO: better solution than enum-type?\n\nexport enum DEFINED_DEFINITION_PROPERTY_TYPE {\n UNION = \"$$union\",\n\n XOR = \"$$xor\",\n\n ARRAY = \"$$array\",\n\n ENUM = \"$$enum\",\n\n // TYPE = \"$$type\", TODO: good idea?\n}\n\nexport interface DefinitionProperty {\n name: string;\n\n type: string | DEFINED_DEFINITION_PROPERTY_TYPE\n\n description: string | React.ReactNode;\n\n // TODO: in the future more advanced examples?\n examples?: string | string[];\n\n symbolDef?: SymbolDef;\n\n meta?: DefinitionPropertyMeta[];\n\n context?: any // TODO: better type\n\n properties?: DefinitionProperty[];\n\n ofProperty?: DefinitionProperty;\n}\n\nexport interface ExampleRoot {\n groups: ExampleGroup[];\n}\n\nexport interface ExampleGroup {\n description?: string;\n\n examples: Example[];\n}\n\nexport interface Example {\n description?: string; // TODO: replace with title ?\n\n codeblock: CodeBlock;\n}\n\nexport interface CodeBlock {\n title?: string;\n\n tabs: CodeBlockTab[];\n}\n\nexport interface CodeBlockTab {\n // title of the tab e.g \"JavaScript\"\n title: string;\n\n // code in the tab e.g \"console.log('Hello World')\"\n code: string\n\n // language of the code e.g \"js\"\n language: string;\n\n // context of the generation method e.g openapi or graphql\n context?: ExampleContext;\n\n // TODO: highlighted code\n highlighted?: HighlightedCode;\n}\n\nexport type ExampleContext = GraphQLExampleContext | OpenAPIExampleContext;\n\n// TODO: concept only\nexport enum ReferenceCategory {\n // for React\n COMPONENTS = \"components\",\n HOOKS = \"hooks\",\n // end for React\n\n // for API\n REST = \"rest\",\n GRAPHQL = \"graphql\",\n // end for API\n\n // for code\n FUNCTIONS = \"functions\",\n //\n}\n\n// TODO: concept only\nexport enum ReferenceType {\n // for React\n COMPONENT = \"component\",\n HOOK = \"hook\",\n // end for React\n\n // for API\n // TODO: better type system for specific api typesl like gql or rest\n REST_HTTP_GET = \"rest_get\",\n REST_HTTP_POST = \"rest_post\",\n REST_HTTP_PUT = \"rest_put\",\n REST_HTTP_PATCH = \"rest_patch\",\n REST_HTTP_DELETE = \"rest_delete\",\n REST_HTTP_OPTIONS = \"rest_options\",\n REST_HTTP_HEAD = \"rest_head\",\n REST_HTTP_TRACE = \"rest_trace\",\n\n REST_COMPONENT_SCHEMA = \"rest_component_schema\",\n // ---\n GRAPHQL_QUERY = \"graphql_query\",\n GRAPHQL_MUTATION = \"graphql_mutation\",\n GRAPHQL_SUBSCRIPTION = \"graphql_subscription\",\n\n GRAPHQL_SCALAR = \"graphql_scalar\",\n GRAPHQL_OBJECT = \"graphql_object\",\n GRAPHQL_INTERFACE = \"graphql_interface\",\n GRAPHQL_UNION = \"graphql_union\",\n GRAPHQL_ENUM = \"graphql_enum\",\n GRAPHQL_INPUT = \"graphql_input\",\n // end for API\n\n // for code\n FUNCTION_JS = \"function_js\",\n // end for code\n}\n\nexport interface BaseReferenceContext {\n group?: string[];\n\n scopes?: string[];\n}\n\nexport interface GraphQLReferenceContext extends BaseReferenceContext {\n /**\n * @unsafe\n */\n graphqlTypeShort: string;\n\n graphqlName: string;\n}\n\n// TODO: custom value?\nexport interface OpenAPIReferenceContext extends BaseReferenceContext {\n method?: string;\n\n path?: string;\n\n fullPath?: string;\n\n componentSchema?: string\n}\n\nexport type TypeDocReferenceContextMeta = Meta<\"internal\">\n\n// Add TypeDocReferenceContext to the union type\nexport interface TypeDocReferenceContext extends BaseReferenceContext {\n symbolId: string;\n symbolName: string;\n symbolKind: number;\n packageName: string;\n fileName: string;\n fileFullPath: string;\n line: number;\n col: number;\n signatureText: {\n code: string;\n lang: string;\n };\n sourcecode: {\n code: string;\n lang: string;\n };\n category?: string;\n meta?: TypeDocReferenceContextMeta[]\n}\n\nexport type ReferenceContext = GraphQLReferenceContext | OpenAPIReferenceContext | TypeDocReferenceContext\n\nexport interface GraphQLExampleContext {\n schema?: any; // TODO:\n}\n\nexport interface OpenAPIExampleContext {\n status?: number;\n\n content?: string;\n}\n\n\n","// Define the new PluginV type with a callback function that returns another function\nimport {Reference} from \"./types\";\n\nexport * from \"./types\";\n\n// Define the new PluginV type with a callback function that returns another function\nexport type UniformPluginArgs = {\n references: Reference[] | Reference,\n defer: (defer: () => any) => void;\n\n // TODO: maybe in the future\n // visit: (selector: string | \"[method] [path]\", callback: (...args: any[]) => void) => void;\n}\n\n\nexport type UniformPluginRestArgs = {\n index: number;\n}\nexport type UniformPlugin<T> = (args: UniformPluginArgs) => (ref: Reference, restArgs: UniformPluginRestArgs) => void;\n\n// Utility type to infer if a type is an array and avoid wrapping it into an array twice\ntype NormalizeArray<T> = T extends Array<infer U> ? U[] : T;\n\n// Infer the return type of the plugin callback properly and normalize array types\ntype PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;\n\n// Merge all plugin return types into a single object and normalize arrays\ntype MergePluginResults<T extends UniformPlugin<any>[]> = {\n [K in keyof UnionToIntersection<PluginResult<T[number]>>]: NormalizeArray<UnionToIntersection<PluginResult<T[number]>>[K]>\n};\n\n// Utility type to handle intersection to an object type\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;\n\n// Implement the uniform function\nexport default function uniform<T extends UniformPlugin<any>[]>(\n references: Reference[],\n config: { plugins: T }\n) {\n // Infer the merged result type from all plugins\n type ResultType = MergePluginResults<T>;\n\n // Initialize the response with a type-safe out object\n const response: {\n references: Reference[]\n out: { [K in keyof ResultType]: ResultType[K] }\n } = {\n references,\n out: {} as { [K in keyof ResultType]: ResultType[K] }\n };\n\n config.plugins.forEach((plugin) => {\n let defer: any = undefined; // fix any\n\n const call = plugin({\n references: references,\n defer: (cb) => {\n if (typeof cb === \"function\") {\n defer = cb\n }\n },\n // visit: (pattern, callback) => {\n // }\n })\n\n references.map((ref, i) => {\n call(ref, {\n index: i,\n })\n });\n\n if (typeof defer === \"function\") {\n const resp = defer()\n if (typeof resp !== \"object\") {\n throw new Error(`Invalid callback return type: ${typeof resp}`)\n }\n\n response.out = {\n ...response.out,\n ...resp\n }\n }\n })\n\n return response;\n}\n\n// Example usage\n// const examplePlugin: UniformPlugin<{ value: boolean }> = (cb) => {\n// return (ref: Reference) => {\n// };\n// };\n// function examplePlugin(defer: (defer: () => { value: boolean }) => void) {\n// defer(() => ({\n// value: true,\n// }));\n//\n// return (ref: Reference) => {\n//\n// };\n// }\n// const response = uniform([/* references */], {\n// plugins: [examplePlugin],\n// });\n// response.out\n","import type { UniformPluginArgs, UniformPlugin } from \"../index\";\nimport { Reference } from \"../types\";\n\nexport interface pluginJsonViewOptions {\n}\n\ntype pluginJsonViewOutput = {\n jsonViews: string;\n}\n\nexport function pluginJsonView(\n options?: pluginJsonViewOptions\n): UniformPlugin<pluginJsonViewOutput> {\n\n return function pluginJsonViewInner({\n defer,\n }: UniformPluginArgs) {\n const jsonViews: string[] = [];\n\n defer(() => ({\n jsonViews\n }))\n\n return (ref: Reference) => {\n // Build the output string manually to ensure exact format\n const lines: string[] = [];\n lines.push('{');\n \n ref.definitions.forEach(def => {\n def.properties.forEach((prop, index) => {\n // Remove any quotes and trailing characters from the value\n const value = (prop.examples?.[0] || '').replace(/^\"|\"$|[^a-zA-Z0-9\\s\\-_.,:/@#=;+()]/g, '');\n const comment = prop.examples && prop.examples.length > 1 \n ? ` // or \"${(prop.examples as string[])[1].replace(/^\"|\"$|[^a-zA-Z0-9\\s\\-_.,:/@#=;+()]/g, '')}\"`\n : '';\n const isLast = index === def.properties.length - 1;\n // Add comma after the value but before the comment\n lines.push(` \"${prop.name}\": \"${value}\"${isLast ? '' : ','}${comment}`);\n });\n });\n \n lines.push('}');\n \n jsonViews.push(lines.join('\\n'));\n }\n }\n}\n\n// example usage:\n// const response = uniform([/* references */], {\n// plugins: [pluginJsonView({\n// \n// })],\n// });\n","import path from 'node:path';\n\nimport type { Sidebar, Metadata, MetadataMap, Settings, PageURL } from \"@xyd-js/core\";\n\nimport type { UniformPluginArgs, UniformPlugin } from \"../index\";\nimport { CodeBlockTab, Example, ExampleGroup, Reference } from \"../types\";\n\nconst DEFAULT_VIRTUAL_FOLDER = \".xyd/.cache/.content\" // TODO: share this + .xyd/.build/.content for build\n\nconst DEFAULT_GROUP_NAME = \"API Reference\" // TODO: configurable\n\ntype GroupMap = {\n [key: string]: {\n __groups: GroupMap\n pages: Set<string>\n }\n}\n\nexport interface pluginNavigationOptions {\n urlPrefix: string\n defaultGroup?: string\n}\n\ntype pluginNavigationOutput = {\n pageFrontMatter: MetadataMap;\n sidebar: Sidebar[];\n}\n\nexport function pluginNavigation(\n settings: Settings,\n options: pluginNavigationOptions\n): UniformPlugin<pluginNavigationOutput> {\n if (!options.urlPrefix) {\n throw new Error(\"urlPrefix is required\")\n }\n\n return function pluginNavigationInner({\n defer,\n }: UniformPluginArgs) {\n const pageFrontMatter: MetadataMap = {}\n const groupMaps: GroupMap = {}\n\n defer(() => ({\n pageFrontMatter,\n sidebar: convertGroupMapsToSidebar(settings, groupMaps) as Sidebar[]\n }))\n\n return (ref: Reference) => {\n const dataCtx = ref.context\n const pagePath = path.join(options.urlPrefix, ref.canonical)\n\n let group = dataCtx?.group || []\n let title = ref.title\n\n if (pageFrontMatter[pagePath]) {\n console.error(\"(pluginNavigation): pageFrontMatter[pagePath] already exists\", pagePath)\n }\n\n if (!group) {\n group = [options.defaultGroup || DEFAULT_GROUP_NAME]\n }\n\n pageFrontMatter[pagePath] = {\n title,\n }\n\n if (typeof group === \"string\") {\n // TODO: seek nested group (it's not always from 0)\n throw new Error(\"group as string is not supported yet\")\n }\n\n group.reduce((groups: GroupMap, groupName: string, i: number) => {\n if (!groups[groupName]) {\n groups[groupName] = {\n __groups: {},\n pages: new Set()\n }\n }\n\n if (i === group.length - 1) {\n groups[groupName].pages.add(pagePath)\n }\n\n return groups[groupName].__groups\n }, groupMaps)\n }\n }\n}\n\nfunction convertGroupMapsToSidebar(settings: Settings, groupMaps: GroupMap): Sidebar[] {\n const nav: Sidebar[] = []\n\n Object.keys(groupMaps).map((groupName) => {\n const current = groupMaps[groupName]\n\n const pages: PageURL[] = []\n\n current.pages.forEach((page: string) => {\n if (settings?.engine?.uniform?.store) {\n pages.push(page)\n return\n }\n pages.push({\n virtual: path.join(DEFAULT_VIRTUAL_FOLDER, page),\n page: page,\n })\n })\n\n if (Object.keys(current.__groups).length) {\n const subNav: Sidebar = {\n group: groupName,\n pages: convertGroupMapsToSidebar(settings, current.__groups)\n }\n\n nav.push(subNav)\n\n return\n }\n\n nav.push({\n group: groupName,\n pages,\n })\n })\n\n return nav\n}\n\n// TODO: in the future xyd settings must be removed cuz uniform will be part of opendocs\n// example usage:\n// const response = uniform([/* references */], {\n// plugins: [pluginNavigation({}, {\n// urlPrefix: \"/docs\"\n// })],\n// });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuGO,IAAK,mCAAL,kBAAKA,sCAAL;AACH,EAAAA,kCAAA,WAAQ;AAER,EAAAA,kCAAA,SAAM;AAEN,EAAAA,kCAAA,WAAQ;AAER,EAAAA,kCAAA,UAAO;AAPC,SAAAA;AAAA,GAAA;AA2EL,IAAK,oBAAL,kBAAKC,uBAAL;AAEH,EAAAA,mBAAA,gBAAa;AACb,EAAAA,mBAAA,WAAQ;AAIR,EAAAA,mBAAA,UAAO;AACP,EAAAA,mBAAA,aAAU;AAIV,EAAAA,mBAAA,eAAY;AAZJ,SAAAA;AAAA,GAAA;AAiBL,IAAK,gBAAL,kBAAKC,mBAAL;AAEH,EAAAA,eAAA,eAAY;AACZ,EAAAA,eAAA,UAAO;AAKP,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,oBAAiB;AACjB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,qBAAkB;AAClB,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AK,MAAM;AAEf;AAAA,IACJ;AAEA,QAAI,KAAK;AAAA,MACL,OAAO;AAAA,MACP;AAAA,IACJ,CAAC;AAAA,EACL,CAAC;AAED,SAAO;AACX;","names":["DEFINED_DEFINITION_PROPERTY_TYPE","ReferenceCategory","ReferenceType","path"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { R as Reference } from './types-
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
1
|
+
import { R as Reference } from './types-xkS6sfq2.cjs';
|
|
2
|
+
export { B as BaseReferenceContext, m as CodeBlock, n as CodeBlockTab, C as CommonDefinitionVariantMeta, i as DEFINED_DEFINITION_PROPERTY_TYPE, d as Definition, b as DefinitionGraphqlMeta, c as DefinitionMeta, D as DefinitionOpenAPIMeta, j as DefinitionProperty, h as DefinitionPropertyMeta, a as DefinitionTypeDocMeta, g as DefinitionVariant, f as DefinitionVariantMeta, e as DefinitionVariantOpenAPIMeta, l as Example, o as ExampleContext, k as ExampleGroup, E as ExampleRoot, t as GraphQLExampleContext, G as GraphQLReferenceContext, M as Meta, u as OpenAPIExampleContext, O as OpenAPIReferenceContext, p as ReferenceCategory, s as ReferenceContext, q as ReferenceType, S as SymbolDef, r as TypeDocReferenceContext, T as TypeDocReferenceContextMeta } from './types-xkS6sfq2.cjs';
|
|
3
|
+
import { Settings, MetadataMap, Sidebar } from '@xyd-js/core';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'codehike/code';
|
|
4
6
|
|
|
5
|
-
type
|
|
7
|
+
type UniformPluginArgs = {
|
|
8
|
+
references: Reference[] | Reference;
|
|
9
|
+
defer: (defer: () => any) => void;
|
|
10
|
+
};
|
|
11
|
+
type UniformPluginRestArgs = {
|
|
12
|
+
index: number;
|
|
13
|
+
};
|
|
14
|
+
type UniformPlugin<T> = (args: UniformPluginArgs) => (ref: Reference, restArgs: UniformPluginRestArgs) => void;
|
|
6
15
|
type NormalizeArray<T> = T extends Array<infer U> ? U[] : T;
|
|
7
16
|
type PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;
|
|
8
17
|
type MergePluginResults<T extends UniformPlugin<any>[]> = {
|
|
@@ -16,12 +25,21 @@ declare function uniform<T extends UniformPlugin<any>[]>(references: Reference[]
|
|
|
16
25
|
out: MergePluginResults<T> extends infer T_1 ? { [K in keyof T_1]: MergePluginResults<T>[K]; } : never;
|
|
17
26
|
};
|
|
18
27
|
|
|
28
|
+
interface pluginJsonViewOptions {
|
|
29
|
+
}
|
|
30
|
+
type pluginJsonViewOutput = {
|
|
31
|
+
jsonViews: string;
|
|
32
|
+
};
|
|
33
|
+
declare function pluginJsonView(options?: pluginJsonViewOptions): UniformPlugin<pluginJsonViewOutput>;
|
|
34
|
+
|
|
19
35
|
interface pluginNavigationOptions {
|
|
20
36
|
urlPrefix: string;
|
|
37
|
+
defaultGroup?: string;
|
|
21
38
|
}
|
|
22
|
-
|
|
23
|
-
pageFrontMatter:
|
|
39
|
+
type pluginNavigationOutput = {
|
|
40
|
+
pageFrontMatter: MetadataMap;
|
|
24
41
|
sidebar: Sidebar[];
|
|
25
|
-
}
|
|
42
|
+
};
|
|
43
|
+
declare function pluginNavigation(settings: Settings, options: pluginNavigationOptions): UniformPlugin<pluginNavigationOutput>;
|
|
26
44
|
|
|
27
|
-
export { Reference, uniform as default, pluginNavigation };
|
|
45
|
+
export { Reference, type UniformPlugin, type UniformPluginArgs, uniform as default, pluginJsonView, pluginNavigation };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { R as Reference } from './types-
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
1
|
+
import { R as Reference } from './types-xkS6sfq2.js';
|
|
2
|
+
export { B as BaseReferenceContext, m as CodeBlock, n as CodeBlockTab, C as CommonDefinitionVariantMeta, i as DEFINED_DEFINITION_PROPERTY_TYPE, d as Definition, b as DefinitionGraphqlMeta, c as DefinitionMeta, D as DefinitionOpenAPIMeta, j as DefinitionProperty, h as DefinitionPropertyMeta, a as DefinitionTypeDocMeta, g as DefinitionVariant, f as DefinitionVariantMeta, e as DefinitionVariantOpenAPIMeta, l as Example, o as ExampleContext, k as ExampleGroup, E as ExampleRoot, t as GraphQLExampleContext, G as GraphQLReferenceContext, M as Meta, u as OpenAPIExampleContext, O as OpenAPIReferenceContext, p as ReferenceCategory, s as ReferenceContext, q as ReferenceType, S as SymbolDef, r as TypeDocReferenceContext, T as TypeDocReferenceContextMeta } from './types-xkS6sfq2.js';
|
|
3
|
+
import { Settings, MetadataMap, Sidebar } from '@xyd-js/core';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'codehike/code';
|
|
4
6
|
|
|
5
|
-
type
|
|
7
|
+
type UniformPluginArgs = {
|
|
8
|
+
references: Reference[] | Reference;
|
|
9
|
+
defer: (defer: () => any) => void;
|
|
10
|
+
};
|
|
11
|
+
type UniformPluginRestArgs = {
|
|
12
|
+
index: number;
|
|
13
|
+
};
|
|
14
|
+
type UniformPlugin<T> = (args: UniformPluginArgs) => (ref: Reference, restArgs: UniformPluginRestArgs) => void;
|
|
6
15
|
type NormalizeArray<T> = T extends Array<infer U> ? U[] : T;
|
|
7
16
|
type PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;
|
|
8
17
|
type MergePluginResults<T extends UniformPlugin<any>[]> = {
|
|
@@ -16,12 +25,21 @@ declare function uniform<T extends UniformPlugin<any>[]>(references: Reference[]
|
|
|
16
25
|
out: MergePluginResults<T> extends infer T_1 ? { [K in keyof T_1]: MergePluginResults<T>[K]; } : never;
|
|
17
26
|
};
|
|
18
27
|
|
|
28
|
+
interface pluginJsonViewOptions {
|
|
29
|
+
}
|
|
30
|
+
type pluginJsonViewOutput = {
|
|
31
|
+
jsonViews: string;
|
|
32
|
+
};
|
|
33
|
+
declare function pluginJsonView(options?: pluginJsonViewOptions): UniformPlugin<pluginJsonViewOutput>;
|
|
34
|
+
|
|
19
35
|
interface pluginNavigationOptions {
|
|
20
36
|
urlPrefix: string;
|
|
37
|
+
defaultGroup?: string;
|
|
21
38
|
}
|
|
22
|
-
|
|
23
|
-
pageFrontMatter:
|
|
39
|
+
type pluginNavigationOutput = {
|
|
40
|
+
pageFrontMatter: MetadataMap;
|
|
24
41
|
sidebar: Sidebar[];
|
|
25
|
-
}
|
|
42
|
+
};
|
|
43
|
+
declare function pluginNavigation(settings: Settings, options: pluginNavigationOptions): UniformPlugin<pluginNavigationOutput>;
|
|
26
44
|
|
|
27
|
-
export { Reference, uniform as default, pluginNavigation };
|
|
45
|
+
export { Reference, type UniformPlugin, type UniformPluginArgs, uniform as default, pluginJsonView, pluginNavigation };
|