@xyd-js/uniform 0.0.0-build-8b31648-20250923204702 → 0.0.0-build-9f87f13-20250930210637

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 CHANGED
@@ -1,9 +1,9 @@
1
1
  # @xyd-js/uniform
2
2
 
3
- ## 0.0.0-build-8b31648-20250923204702
3
+ ## 0.0.0-build-9f87f13-20250930210637
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - update all packages
8
8
  - Updated dependencies
9
- - @xyd-js/core@0.0.0-build-8b31648-20250923204702
9
+ - @xyd-js/core@0.0.0-build-9f87f13-20250930210637
package/dist/index.cjs CHANGED
@@ -35,7 +35,8 @@ __export(index_exports, {
35
35
  ReferenceType: () => ReferenceType,
36
36
  default: () => uniform,
37
37
  pluginJsonView: () => pluginJsonView,
38
- pluginNavigation: () => pluginNavigation
38
+ pluginNavigation: () => pluginNavigation,
39
+ uniformToInputJsonSchema: () => uniformToInputJsonSchema
39
40
  });
40
41
  module.exports = __toCommonJS(index_exports);
41
42
 
@@ -80,6 +81,158 @@ var ReferenceType = /* @__PURE__ */ ((ReferenceType2) => {
80
81
  return ReferenceType2;
81
82
  })(ReferenceType || {});
82
83
 
84
+ // src/converters.ts
85
+ function uniformToInputJsonSchema(reference) {
86
+ var _a, _b, _c, _d;
87
+ if (!((_a = reference == null ? void 0 : reference.definitions) == null ? void 0 : _a.length)) {
88
+ return null;
89
+ }
90
+ const inputDefinitions = [];
91
+ for (const def of reference.definitions) {
92
+ if ((def == null ? void 0 : def.type) === "return") {
93
+ continue;
94
+ }
95
+ const definitionSchemas = [];
96
+ if ((_b = def == null ? void 0 : def.properties) == null ? void 0 : _b.length) {
97
+ const result = uniformPropertiesToJsonSchema(def.properties, def.type);
98
+ if (result) {
99
+ definitionSchemas.push(result);
100
+ }
101
+ }
102
+ if ((_c = def == null ? void 0 : def.variants) == null ? void 0 : _c.length) {
103
+ const variantSchemas = [];
104
+ for (const variant of def.variants) {
105
+ if ((_d = variant == null ? void 0 : variant.properties) == null ? void 0 : _d.length) {
106
+ const result = uniformPropertiesToJsonSchema(variant.properties, def.type);
107
+ if (result) {
108
+ variantSchemas.push(result);
109
+ }
110
+ }
111
+ }
112
+ if (variantSchemas.length > 0) {
113
+ if (variantSchemas.length === 1) {
114
+ definitionSchemas.push(variantSchemas[0]);
115
+ } else {
116
+ definitionSchemas.push({
117
+ oneOf: variantSchemas
118
+ });
119
+ }
120
+ }
121
+ }
122
+ if (definitionSchemas.length === 1) {
123
+ inputDefinitions.push(definitionSchemas[0]);
124
+ } else if (definitionSchemas.length > 1) {
125
+ inputDefinitions.push({
126
+ allOf: definitionSchemas
127
+ });
128
+ }
129
+ }
130
+ if (inputDefinitions.length === 0) {
131
+ return null;
132
+ } else if (inputDefinitions.length === 1) {
133
+ return inputDefinitions[0];
134
+ } else {
135
+ return {
136
+ allOf: inputDefinitions
137
+ };
138
+ }
139
+ }
140
+ function uniformPropertiesToJsonSchema(properties, id) {
141
+ var _a, _b, _c;
142
+ if (Array.isArray(properties)) {
143
+ let jsonSchemaProps = {};
144
+ let requiredFields = [];
145
+ if (properties.length) {
146
+ for (const property of properties) {
147
+ const v = uniformPropertiesToJsonSchema(property);
148
+ if (v) {
149
+ jsonSchemaProps[property.name] = v;
150
+ }
151
+ const isRequired = (_a = property.meta) == null ? void 0 : _a.some(
152
+ (meta) => meta.name === "required" && meta.value === "true"
153
+ );
154
+ if (isRequired) {
155
+ requiredFields.push(property.name);
156
+ }
157
+ }
158
+ }
159
+ const schema2 = {
160
+ $id: id || void 0,
161
+ type: "object",
162
+ properties: jsonSchemaProps
163
+ };
164
+ if (requiredFields.length > 0) {
165
+ schema2.required = requiredFields;
166
+ }
167
+ return schema2;
168
+ }
169
+ if (properties.type === "$$enum" /* ENUM */) {
170
+ const schema2 = {
171
+ description: properties.description
172
+ };
173
+ const enumType = properties.ofProperty && properties.ofProperty.type || ((_c = (_b = properties.meta) == null ? void 0 : _b.find((meta) => meta.name === "enum-type")) == null ? void 0 : _c.value) || "string";
174
+ schema2.type = enumType;
175
+ if (properties.properties && properties.properties.length > 0) {
176
+ schema2.enum = properties.properties.map((prop) => prop.name);
177
+ }
178
+ return schema2;
179
+ }
180
+ if (properties.type === "$$array" /* ARRAY */) {
181
+ const schema2 = {
182
+ type: "array",
183
+ description: properties.description
184
+ };
185
+ if (properties.ofProperty) {
186
+ const itemsSchema = uniformPropertiesToJsonSchema(properties.ofProperty);
187
+ if (itemsSchema) {
188
+ schema2.items = itemsSchema;
189
+ }
190
+ }
191
+ return schema2;
192
+ }
193
+ if (properties.type === "$$xor" /* XOR */) {
194
+ const schema2 = {
195
+ description: properties.description
196
+ };
197
+ if (properties.properties && properties.properties.length > 0) {
198
+ schema2.oneOf = properties.properties.map((prop) => {
199
+ const propSchema = uniformPropertiesToJsonSchema(prop);
200
+ return propSchema || {};
201
+ }).filter((schema3) => Object.keys(schema3).length > 0);
202
+ }
203
+ return schema2;
204
+ }
205
+ if (properties.type === "$$union" /* UNION */) {
206
+ const schema2 = {
207
+ description: properties.description
208
+ };
209
+ if (properties.properties && properties.properties.length > 0) {
210
+ schema2.anyOf = properties.properties.map((prop) => {
211
+ const propSchema = uniformPropertiesToJsonSchema(prop);
212
+ return propSchema || {};
213
+ }).filter((schema3) => Object.keys(schema3).length > 0);
214
+ }
215
+ return schema2;
216
+ }
217
+ if (properties.ofProperty) {
218
+ return uniformPropertiesToJsonSchema(properties.ofProperty);
219
+ }
220
+ const schema = {
221
+ type: properties.type,
222
+ description: properties.description
223
+ };
224
+ if (properties.type === "object" && properties.properties && properties.properties.length > 0) {
225
+ const nestedSchema = uniformPropertiesToJsonSchema(properties.properties);
226
+ if (nestedSchema && nestedSchema.properties) {
227
+ schema.properties = nestedSchema.properties;
228
+ if (nestedSchema.required) {
229
+ schema.required = nestedSchema.required;
230
+ }
231
+ }
232
+ }
233
+ return schema;
234
+ }
235
+
83
236
  // src/index.ts
84
237
  function uniform(references, config) {
85
238
  const response = {
@@ -227,6 +380,7 @@ function convertGroupMapsToSidebar(settings, groupMaps) {
227
380
  ReferenceCategory,
228
381
  ReferenceType,
229
382
  pluginJsonView,
230
- pluginNavigation
383
+ pluginNavigation,
384
+ uniformToInputJsonSchema
231
385
  });
232
386
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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 * @internal\n */\n symbolDef?: SymbolDef;\n\n /**\n * @internal\n */\n id?: string;\n\n /**\n * @internal\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 * @internal\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 servers?: 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;AA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AE1B,YAAQ,MAAM,QAAQ,CAAC,SAAiB;AAjGhD;AAkGY,WAAI,gDAAU,WAAV,mBAAkB,YAAlB,mBAA2B,OAAO;AAClC,cAAM,KAAK,IAAI;AACf;AAAA,MACJ;AACA,YAAM,KAAK;AAAA,QACP,SAAS,iBAAAA,QAAK,KAAK,wBAAwB,IAAI;AAAA,QAC/C;AAAA,MACJ,CAAC;AAAA,IACL,CAAC;AAED,QAAI,OAAO,KAAK,QAAQ,QAAQ,EAAE,QAAQ;AACtC,YAAM,SAAkB;AAAA,QACpB,OAAO;AAAA,QACP,OAAO,0BAA0B,UAAU,QAAQ,QAAQ;AAAA,MAC/D;AAEA,UAAI,KAAK,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"]}
1
+ {"version":3,"sources":["../index.ts","../src/types.ts","../src/converters.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, uniformToInputJsonSchema } 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 type DefinitionTypeREST = \"$rest.param.path\" | \"$rest.param.query\" | \"$rest.param.header\" | \"$rest.param.cookie\" | \"$rest.request.body\"\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 * @internal\n */\n symbolDef?: SymbolDef;\n\n /**\n * @internal\n */\n id?: string;\n\n /**\n * @internal\n */\n type?: \"return\" | DefinitionTypeREST\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 * @internal\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 servers?: 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","import {DEFINED_DEFINITION_PROPERTY_TYPE, DefinitionProperty, Reference} from \"./types\";\nimport {JSONSchema7, JSONSchema7TypeName} from \"json-schema\";\n\nexport function uniformToInputJsonSchema(reference: Reference): JSONSchema7 | null {\n if (!reference?.definitions?.length) {\n return null;\n }\n\n const inputDefinitions: JSONSchema7[] = [];\n\n for (const def of reference.definitions) {\n if (def?.type === \"return\") {\n continue;\n }\n\n // Process each definition\n const definitionSchemas: JSONSchema7[] = [];\n\n // Add main properties if they exist\n if (def?.properties?.length) {\n const result = uniformPropertiesToJsonSchema(def.properties, def.type);\n if (result) {\n definitionSchemas.push(result as JSONSchema7);\n }\n }\n\n // Add variant properties if they exist\n if (def?.variants?.length) {\n const variantSchemas: JSONSchema7[] = [];\n \n for (const variant of def.variants) {\n if (variant?.properties?.length) {\n const result = uniformPropertiesToJsonSchema(variant.properties, def.type);\n if (result) {\n variantSchemas.push(result as JSONSchema7);\n }\n }\n }\n\n // If there are variants, use oneOf\n if (variantSchemas.length > 0) {\n if (variantSchemas.length === 1) {\n definitionSchemas.push(variantSchemas[0]);\n } else {\n definitionSchemas.push({\n oneOf: variantSchemas\n });\n }\n }\n }\n\n // Add this definition's schema(s) to the input definitions\n if (definitionSchemas.length === 1) {\n inputDefinitions.push(definitionSchemas[0]);\n } else if (definitionSchemas.length > 1) {\n inputDefinitions.push({\n allOf: definitionSchemas\n });\n }\n }\n\n // Return the final schema\n if (inputDefinitions.length === 0) {\n return null;\n } else if (inputDefinitions.length === 1) {\n return inputDefinitions[0];\n } else {\n // Multiple definitions use allOf\n return {\n allOf: inputDefinitions\n };\n }\n}\n\nexport function uniformPropertiesToJsonSchema(\n properties: DefinitionProperty[] | DefinitionProperty,\n id?: string\n): JSONSchema7 | null {\n if (Array.isArray(properties)) {\n let jsonSchemaProps: { [key: string]: JSONSchema7 } = {};\n let requiredFields: string[] = [];\n\n if (properties.length) {\n for (const property of properties) {\n const v = uniformPropertiesToJsonSchema(property);\n if (v) {\n jsonSchemaProps[property.name] = v;\n }\n\n // Check if property is required\n const isRequired = property.meta?.some(\n (meta) => meta.name === \"required\" && meta.value === \"true\"\n );\n if (isRequired) {\n requiredFields.push(property.name);\n }\n }\n }\n\n const schema: JSONSchema7 = {\n $id: id || undefined,\n type: \"object\",\n properties: jsonSchemaProps,\n };\n\n // Only add required array if there are required fields\n if (requiredFields.length > 0) {\n schema.required = requiredFields;\n }\n\n return schema;\n }\n\n // Handle enum types\n if (properties.type === DEFINED_DEFINITION_PROPERTY_TYPE.ENUM) {\n const schema: JSONSchema7 = {\n description: properties.description as string,\n };\n\n // Get the base type from ofProperty or meta\n const enumType: string =\n (properties.ofProperty && (properties.ofProperty as any).type) ||\n (properties.meta?.find((meta) => meta.name === \"enum-type\")\n ?.value as string) ||\n \"string\";\n\n schema.type = enumType as JSONSchema7TypeName;\n\n // Extract enum values from properties array\n if (properties.properties && properties.properties.length > 0) {\n schema.enum = properties.properties.map((prop) => prop.name);\n }\n\n return schema;\n }\n\n // Handle array types\n if (properties.type === DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY) {\n const schema: JSONSchema7 = {\n type: \"array\",\n description: properties.description as string,\n };\n\n // Set items schema from ofProperty\n if (properties.ofProperty) {\n const itemsSchema = uniformPropertiesToJsonSchema(properties.ofProperty);\n if (itemsSchema) {\n schema.items = itemsSchema;\n }\n }\n\n return schema;\n }\n\n // Handle XOR (oneOf) types\n if (properties.type === DEFINED_DEFINITION_PROPERTY_TYPE.XOR) {\n const schema: JSONSchema7 = {\n description: properties.description as string,\n };\n\n // Convert properties array to oneOf schemas\n if (properties.properties && properties.properties.length > 0) {\n schema.oneOf = properties.properties\n .map((prop) => {\n const propSchema = uniformPropertiesToJsonSchema(prop);\n return propSchema || {};\n })\n .filter((schema) => Object.keys(schema).length > 0);\n }\n\n return schema;\n }\n\n // Handle UNION (anyOf) types\n if (properties.type === DEFINED_DEFINITION_PROPERTY_TYPE.UNION) {\n const schema: JSONSchema7 = {\n description: properties.description as string,\n };\n\n // Convert properties array to anyOf schemas\n if (properties.properties && properties.properties.length > 0) {\n schema.anyOf = properties.properties\n .map((prop) => {\n const propSchema = uniformPropertiesToJsonSchema(prop);\n return propSchema || {};\n })\n .filter((schema) => Object.keys(schema).length > 0);\n }\n\n return schema;\n }\n\n if (properties.ofProperty) {\n return uniformPropertiesToJsonSchema(properties.ofProperty);\n }\n\n // Build the schema for single property\n const schema: JSONSchema7 = {\n type: properties.type as JSONSchema7TypeName,\n description: properties.description as string,\n };\n\n // Handle object types with nested properties\n if (properties.type === \"object\" && properties.properties && properties.properties.length > 0) {\n const nestedSchema = uniformPropertiesToJsonSchema(properties.properties);\n if (nestedSchema && nestedSchema.properties) {\n schema.properties = nestedSchema.properties;\n if (nestedSchema.required) {\n schema.required = nestedSchema.required;\n }\n }\n }\n\n return schema;\n}\n","// Define the new PluginV type with a callback function that returns another function\nimport {Reference} from \"./types\";\n\nexport {\n uniformToInputJsonSchema,\n uniformPropertiesToJsonSchema\n} from \"./converters\";\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;AAAA;;;ACyGO,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,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f;AAAA,MACJ;AACA,YAAM,KAAK;AAAA,QACP,SAAS,iBAAAA,QAAK,KAAK,wBAAwB,IAAI;AAAA,QAC/C;AAAA,MACJ,CAAC;AAAA,IACL,CAAC;AAED,QAAI,OAAO,KAAK,QAAQ,QAAQ,EAAE,QAAQ;AACtC,YAAM,SAAkB;AAAA,QACpB,OAAO;AAAA,QACP,OAAO,0BAA0B,UAAU,QAAQ,QAAQ;AAAA,MAC/D;AAEA,UAAI,KAAK,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","schema","path"]}
package/dist/index.d.cts CHANGED
@@ -1,9 +1,12 @@
1
- import { R as Reference } from './types-DiQsFerK.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-DiQsFerK.cjs';
1
+ import { R as Reference } from './types-DcJGRAj1.cjs';
2
+ export { B as BaseReferenceContext, n as CodeBlock, o as CodeBlockTab, C as CommonDefinitionVariantMeta, j as DEFINED_DEFINITION_PROPERTY_TYPE, e as Definition, b as DefinitionGraphqlMeta, c as DefinitionMeta, D as DefinitionOpenAPIMeta, k as DefinitionProperty, i as DefinitionPropertyMeta, a as DefinitionTypeDocMeta, d as DefinitionTypeREST, h as DefinitionVariant, g as DefinitionVariantMeta, f as DefinitionVariantOpenAPIMeta, m as Example, p as ExampleContext, l as ExampleGroup, E as ExampleRoot, u as GraphQLExampleContext, G as GraphQLReferenceContext, M as Meta, v as OpenAPIExampleContext, O as OpenAPIReferenceContext, q as ReferenceCategory, t as ReferenceContext, r as ReferenceType, S as SymbolDef, s as TypeDocReferenceContext, T as TypeDocReferenceContextMeta } from './types-DcJGRAj1.cjs';
3
3
  import { Settings, MetadataMap, Sidebar } from '@xyd-js/core';
4
+ import { JSONSchema7 } from 'json-schema';
4
5
  import 'react';
5
6
  import 'codehike/code';
6
7
 
8
+ declare function uniformToInputJsonSchema(reference: Reference): JSONSchema7 | null;
9
+
7
10
  type UniformPluginArgs = {
8
11
  references: Reference[] | Reference;
9
12
  defer: (defer: () => any) => void;
@@ -42,4 +45,4 @@ type pluginNavigationOutput = {
42
45
  };
43
46
  declare function pluginNavigation(settings: Settings, options: pluginNavigationOptions): UniformPlugin<pluginNavigationOutput>;
44
47
 
45
- export { Reference, type UniformPlugin, type UniformPluginArgs, uniform as default, pluginJsonView, pluginNavigation };
48
+ export { Reference, type UniformPlugin, type UniformPluginArgs, uniform as default, pluginJsonView, pluginNavigation, uniformToInputJsonSchema };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,12 @@
1
- import { R as Reference } from './types-DiQsFerK.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-DiQsFerK.js';
1
+ import { R as Reference } from './types-DcJGRAj1.js';
2
+ export { B as BaseReferenceContext, n as CodeBlock, o as CodeBlockTab, C as CommonDefinitionVariantMeta, j as DEFINED_DEFINITION_PROPERTY_TYPE, e as Definition, b as DefinitionGraphqlMeta, c as DefinitionMeta, D as DefinitionOpenAPIMeta, k as DefinitionProperty, i as DefinitionPropertyMeta, a as DefinitionTypeDocMeta, d as DefinitionTypeREST, h as DefinitionVariant, g as DefinitionVariantMeta, f as DefinitionVariantOpenAPIMeta, m as Example, p as ExampleContext, l as ExampleGroup, E as ExampleRoot, u as GraphQLExampleContext, G as GraphQLReferenceContext, M as Meta, v as OpenAPIExampleContext, O as OpenAPIReferenceContext, q as ReferenceCategory, t as ReferenceContext, r as ReferenceType, S as SymbolDef, s as TypeDocReferenceContext, T as TypeDocReferenceContextMeta } from './types-DcJGRAj1.js';
3
3
  import { Settings, MetadataMap, Sidebar } from '@xyd-js/core';
4
+ import { JSONSchema7 } from 'json-schema';
4
5
  import 'react';
5
6
  import 'codehike/code';
6
7
 
8
+ declare function uniformToInputJsonSchema(reference: Reference): JSONSchema7 | null;
9
+
7
10
  type UniformPluginArgs = {
8
11
  references: Reference[] | Reference;
9
12
  defer: (defer: () => any) => void;
@@ -42,4 +45,4 @@ type pluginNavigationOutput = {
42
45
  };
43
46
  declare function pluginNavigation(settings: Settings, options: pluginNavigationOptions): UniformPlugin<pluginNavigationOutput>;
44
47
 
45
- export { Reference, type UniformPlugin, type UniformPluginArgs, uniform as default, pluginJsonView, pluginNavigation };
48
+ export { Reference, type UniformPlugin, type UniformPluginArgs, uniform as default, pluginJsonView, pluginNavigation, uniformToInputJsonSchema };
package/dist/index.js CHANGED
@@ -39,6 +39,158 @@ var ReferenceType = /* @__PURE__ */ ((ReferenceType2) => {
39
39
  return ReferenceType2;
40
40
  })(ReferenceType || {});
41
41
 
42
+ // src/converters.ts
43
+ function uniformToInputJsonSchema(reference) {
44
+ var _a, _b, _c, _d;
45
+ if (!((_a = reference == null ? void 0 : reference.definitions) == null ? void 0 : _a.length)) {
46
+ return null;
47
+ }
48
+ const inputDefinitions = [];
49
+ for (const def of reference.definitions) {
50
+ if ((def == null ? void 0 : def.type) === "return") {
51
+ continue;
52
+ }
53
+ const definitionSchemas = [];
54
+ if ((_b = def == null ? void 0 : def.properties) == null ? void 0 : _b.length) {
55
+ const result = uniformPropertiesToJsonSchema(def.properties, def.type);
56
+ if (result) {
57
+ definitionSchemas.push(result);
58
+ }
59
+ }
60
+ if ((_c = def == null ? void 0 : def.variants) == null ? void 0 : _c.length) {
61
+ const variantSchemas = [];
62
+ for (const variant of def.variants) {
63
+ if ((_d = variant == null ? void 0 : variant.properties) == null ? void 0 : _d.length) {
64
+ const result = uniformPropertiesToJsonSchema(variant.properties, def.type);
65
+ if (result) {
66
+ variantSchemas.push(result);
67
+ }
68
+ }
69
+ }
70
+ if (variantSchemas.length > 0) {
71
+ if (variantSchemas.length === 1) {
72
+ definitionSchemas.push(variantSchemas[0]);
73
+ } else {
74
+ definitionSchemas.push({
75
+ oneOf: variantSchemas
76
+ });
77
+ }
78
+ }
79
+ }
80
+ if (definitionSchemas.length === 1) {
81
+ inputDefinitions.push(definitionSchemas[0]);
82
+ } else if (definitionSchemas.length > 1) {
83
+ inputDefinitions.push({
84
+ allOf: definitionSchemas
85
+ });
86
+ }
87
+ }
88
+ if (inputDefinitions.length === 0) {
89
+ return null;
90
+ } else if (inputDefinitions.length === 1) {
91
+ return inputDefinitions[0];
92
+ } else {
93
+ return {
94
+ allOf: inputDefinitions
95
+ };
96
+ }
97
+ }
98
+ function uniformPropertiesToJsonSchema(properties, id) {
99
+ var _a, _b, _c;
100
+ if (Array.isArray(properties)) {
101
+ let jsonSchemaProps = {};
102
+ let requiredFields = [];
103
+ if (properties.length) {
104
+ for (const property of properties) {
105
+ const v = uniformPropertiesToJsonSchema(property);
106
+ if (v) {
107
+ jsonSchemaProps[property.name] = v;
108
+ }
109
+ const isRequired = (_a = property.meta) == null ? void 0 : _a.some(
110
+ (meta) => meta.name === "required" && meta.value === "true"
111
+ );
112
+ if (isRequired) {
113
+ requiredFields.push(property.name);
114
+ }
115
+ }
116
+ }
117
+ const schema2 = {
118
+ $id: id || void 0,
119
+ type: "object",
120
+ properties: jsonSchemaProps
121
+ };
122
+ if (requiredFields.length > 0) {
123
+ schema2.required = requiredFields;
124
+ }
125
+ return schema2;
126
+ }
127
+ if (properties.type === "$$enum" /* ENUM */) {
128
+ const schema2 = {
129
+ description: properties.description
130
+ };
131
+ const enumType = properties.ofProperty && properties.ofProperty.type || ((_c = (_b = properties.meta) == null ? void 0 : _b.find((meta) => meta.name === "enum-type")) == null ? void 0 : _c.value) || "string";
132
+ schema2.type = enumType;
133
+ if (properties.properties && properties.properties.length > 0) {
134
+ schema2.enum = properties.properties.map((prop) => prop.name);
135
+ }
136
+ return schema2;
137
+ }
138
+ if (properties.type === "$$array" /* ARRAY */) {
139
+ const schema2 = {
140
+ type: "array",
141
+ description: properties.description
142
+ };
143
+ if (properties.ofProperty) {
144
+ const itemsSchema = uniformPropertiesToJsonSchema(properties.ofProperty);
145
+ if (itemsSchema) {
146
+ schema2.items = itemsSchema;
147
+ }
148
+ }
149
+ return schema2;
150
+ }
151
+ if (properties.type === "$$xor" /* XOR */) {
152
+ const schema2 = {
153
+ description: properties.description
154
+ };
155
+ if (properties.properties && properties.properties.length > 0) {
156
+ schema2.oneOf = properties.properties.map((prop) => {
157
+ const propSchema = uniformPropertiesToJsonSchema(prop);
158
+ return propSchema || {};
159
+ }).filter((schema3) => Object.keys(schema3).length > 0);
160
+ }
161
+ return schema2;
162
+ }
163
+ if (properties.type === "$$union" /* UNION */) {
164
+ const schema2 = {
165
+ description: properties.description
166
+ };
167
+ if (properties.properties && properties.properties.length > 0) {
168
+ schema2.anyOf = properties.properties.map((prop) => {
169
+ const propSchema = uniformPropertiesToJsonSchema(prop);
170
+ return propSchema || {};
171
+ }).filter((schema3) => Object.keys(schema3).length > 0);
172
+ }
173
+ return schema2;
174
+ }
175
+ if (properties.ofProperty) {
176
+ return uniformPropertiesToJsonSchema(properties.ofProperty);
177
+ }
178
+ const schema = {
179
+ type: properties.type,
180
+ description: properties.description
181
+ };
182
+ if (properties.type === "object" && properties.properties && properties.properties.length > 0) {
183
+ const nestedSchema = uniformPropertiesToJsonSchema(properties.properties);
184
+ if (nestedSchema && nestedSchema.properties) {
185
+ schema.properties = nestedSchema.properties;
186
+ if (nestedSchema.required) {
187
+ schema.required = nestedSchema.required;
188
+ }
189
+ }
190
+ }
191
+ return schema;
192
+ }
193
+
42
194
  // src/index.ts
43
195
  function uniform(references, config) {
44
196
  const response = {
@@ -186,6 +338,7 @@ export {
186
338
  ReferenceType,
187
339
  uniform as default,
188
340
  pluginJsonView,
189
- pluginNavigation
341
+ pluginNavigation,
342
+ uniformToInputJsonSchema
190
343
  };
191
344
  //# sourceMappingURL=index.js.map