@xyd-js/uniform 0.1.0-xyd.4 → 0.1.0-xyd.6

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 ADDED
@@ -0,0 +1,9 @@
1
+ # @xyd-js/uniform
2
+
3
+ ## 0.1.0-xyd.6
4
+
5
+ ### Patch Changes
6
+
7
+ - initial changeset bump
8
+ - Updated dependencies
9
+ - @xyd-js/core@0.1.0-xyd.4
@@ -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\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\nexport interface Reference {\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?: ReferenceContext;\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 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;AAGA,QAAM,kBAAkB,oBAAI,IAAI;AAEhC,SAAO,QAAQ,QAAQ,CAAC,WAAW;AAC/B,UAAM,OAA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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/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\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\nexport interface Reference {\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?: ReferenceContext;\n}\n\nexport interface Definition {\n title: string;\n\n properties: DefinitionProperty[];\n\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;AAGA,QAAM,kBAAkB,oBAAI,IAAI;AAEhC,SAAO,QAAQ,QAA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AK,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"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as Reference } from './types-C8Pm_zQH.cjs';
2
- export { C as CodeBlock, i as CodeBlockTab, D as Definition, j as DefinitionProperty, e as Example, h as ExampleContext, d as ExampleGroup, E as ExampleRoot, f as GraphQLExampleContext, G as GraphQLReferenceContext, g as OpenAPIExampleContext, O as OpenAPIReferenceContext, a as ReferenceCategory, c as ReferenceContext, b as ReferenceType } from './types-C8Pm_zQH.cjs';
1
+ import { R as Reference } from './types-CbDJSEtC.cjs';
2
+ export { C as CodeBlock, i as CodeBlockTab, D as Definition, j as DefinitionProperty, e as Example, h as ExampleContext, d as ExampleGroup, E as ExampleRoot, f as GraphQLExampleContext, G as GraphQLReferenceContext, g as OpenAPIExampleContext, O as OpenAPIReferenceContext, a as ReferenceCategory, c as ReferenceContext, b as ReferenceType } from './types-CbDJSEtC.cjs';
3
3
  import { PageFrontMatter, Sidebar } from '@xyd-js/core';
4
4
 
5
5
  type UniformPlugin<T> = (cb: (cb: () => T) => void) => (ref: Reference) => void;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as Reference } from './types-C8Pm_zQH.js';
2
- export { C as CodeBlock, i as CodeBlockTab, D as Definition, j as DefinitionProperty, e as Example, h as ExampleContext, d as ExampleGroup, E as ExampleRoot, f as GraphQLExampleContext, G as GraphQLReferenceContext, g as OpenAPIExampleContext, O as OpenAPIReferenceContext, a as ReferenceCategory, c as ReferenceContext, b as ReferenceType } from './types-C8Pm_zQH.js';
1
+ import { R as Reference } from './types-CbDJSEtC.js';
2
+ export { C as CodeBlock, i as CodeBlockTab, D as Definition, j as DefinitionProperty, e as Example, h as ExampleContext, d as ExampleGroup, E as ExampleRoot, f as GraphQLExampleContext, G as GraphQLReferenceContext, g as OpenAPIExampleContext, O as OpenAPIReferenceContext, a as ReferenceCategory, c as ReferenceContext, b as ReferenceType } from './types-CbDJSEtC.js';
3
3
  import { PageFrontMatter, Sidebar } from '@xyd-js/core';
4
4
 
5
5
  type UniformPlugin<T> = (cb: (cb: () => T) => void) => (ref: Reference) => void;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/types.ts"],"sourcesContent":["// 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\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\nexport interface Reference {\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?: ReferenceContext;\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 properties?: DefinitionProperty[];\n}"],"mappings":";AAqBe,SAAR,QACH,YACA,QACF;AAKE,QAAM,WAGF;AAAA,IACA;AAAA,IACA,KAAK,CAAC;AAAA,EACV;AAGA,QAAM,kBAAkB,oBAAI,IAAI;AAEhC,SAAO,QAAQ,QAAQ,CAAC,WAAW;AAC/B,UAAM,OAAO,OAAO,QAAM;AACtB,sBAAgB,IAAI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O;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":["ReferenceCategory","ReferenceType"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/types.ts"],"sourcesContent":["// 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\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\nexport interface Reference {\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?: ReferenceContext;\n}\n\nexport interface Definition {\n title: string;\n\n properties: DefinitionProperty[];\n\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":";AAqBe,SAAR,QACH,YACA,QACF;AAKE,QAAM,WAGF;AAAA,IACA;AAAA,IACA,KAAK,CAAC;AAAA,EACV;AAGA,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,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AAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,sBAAmB;AAInB,EAAAA,eAAA,iBAAc;AAlBN,SAAAA;AAAA,GAAA;","names":["ReferenceCategory","ReferenceType"]}
package/dist/markdown.cjs CHANGED
@@ -40,6 +40,7 @@ var import_remark = require("remark");
40
40
  var import_remark_stringify = __toESM(require("remark-stringify"), 1);
41
41
 
42
42
  // src/markdown/utils.ts
43
+ var import_mdast_util_from_markdown = require("mdast-util-from-markdown");
43
44
  var import_unist_builder = require("unist-builder");
44
45
  var START_DEPTH_LEVEL = 2;
45
46
  function root(ast) {
@@ -59,7 +60,7 @@ function heading(title, canonical, description, refCategory, refType, refContext
59
60
  let uDesc = [
60
61
  (0, import_unist_builder.u)(
61
62
  "heading",
62
- { depth: START_DEPTH_LEVEL },
63
+ { depth: uTitle.depth + 1 },
63
64
  [(0, import_unist_builder.u)("text", `!description`)]
64
65
  ),
65
66
  (0, import_unist_builder.u)("paragraph", [(0, import_unist_builder.u)("text", description)])
@@ -186,6 +187,7 @@ function definitions(definitions2) {
186
187
  name: prop.name,
187
188
  type: prop.type,
188
189
  description: prop.description,
190
+ context: prop.context,
189
191
  properties: prop.properties
190
192
  // TODO: fix ts
191
193
  },
@@ -201,12 +203,33 @@ function properties(depth, props, output = []) {
201
203
  const uPropTitle = (0, import_unist_builder.u)("heading", { depth }, [(0, import_unist_builder.u)("text", propTitle)]);
202
204
  const uPropName = (0, import_unist_builder.u)("paragraph", { depth }, [(0, import_unist_builder.u)("text", `!name ${paramName}`)]);
203
205
  const uPropType = (0, import_unist_builder.u)("paragraph", { depth }, [(0, import_unist_builder.u)("text", `!type ${props.type}`)]);
204
- const uPropDesc = (0, import_unist_builder.u)("paragraph", { depth }, [(0, import_unist_builder.u)("text", props.description || "")]);
206
+ const markdownAst = (0, import_mdast_util_from_markdown.fromMarkdown)(props.description || "");
207
+ const uPropDesc = (0, import_unist_builder.u)("paragraph", { depth }, markdownAst.children);
208
+ const uContext = [];
209
+ if (props.context && Object.keys(props.context)) {
210
+ uContext.push((0, import_unist_builder.u)(
211
+ "heading",
212
+ { depth: depth + 1 },
213
+ [
214
+ (0, import_unist_builder.u)("text", `!context`)
215
+ ]
216
+ ));
217
+ for (const [key, value] of Object.entries(props.context)) {
218
+ uContext.push(
219
+ (0, import_unist_builder.u)(
220
+ "heading",
221
+ { depth: uContext[0].depth + 1 },
222
+ [(0, import_unist_builder.u)("text", `!${key} ${value}`)]
223
+ )
224
+ );
225
+ }
226
+ }
205
227
  output.push(
206
228
  uPropTitle,
207
229
  uPropName,
208
230
  uPropType,
209
- uPropDesc
231
+ uPropDesc,
232
+ ...uContext
210
233
  );
211
234
  if (props.properties) {
212
235
  const deepDepth = depth + 1;
@@ -241,11 +264,13 @@ function referenceAST(ref) {
241
264
  ref.type,
242
265
  ref.context
243
266
  );
267
+ md.push(
268
+ mdHeading.title
269
+ );
244
270
  if ((_a = mdHeading == null ? void 0 : mdHeading.description) == null ? void 0 : _a.length) {
245
271
  md.push(...mdHeading.description);
246
272
  }
247
273
  md.push(
248
- mdHeading.title,
249
274
  mdHeading.canonical
250
275
  );
251
276
  if (mdHeading.category) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../markdown.ts","../src/markdown/index.ts","../src/markdown/utils.ts"],"sourcesContent":["export * from \"./src/markdown/index\";\n","import {remark} from \"remark\";\nimport remarkStringify from \"remark-stringify\";\n\nimport {Reference} from \"../types\";\n\nimport {definitions, examples, heading, root} from \"./utils\";\n\n// TODO: any\nexport function compile(ast: any) {\n return remark()\n // .use(unlimitedHeadings)\n .use(remarkStringify, {\n bullet: '-',\n fences: true,\n listItemIndent: 'one',\n incrementListMarker: false,\n handlers: {\n heading(node) {\n return `${\"#\".repeat(node.depth)} ${node.children[0].value}`;\n },\n },\n })\n .stringify(root(ast));\n}\n\nexport function referenceAST(ref: Reference) {\n const md = []\n\n const mdHeading = heading(\n ref.title,\n ref.canonical,\n ref.description,\n ref.category,\n ref.type,\n ref.context\n )\n\n if (mdHeading?.description?.length) {\n md.push(...mdHeading.description)\n }\n\n md.push(\n mdHeading.title,\n mdHeading.canonical,\n )\n\n if (mdHeading.category) {\n md.push(mdHeading.category)\n }\n\n if (mdHeading.type) {\n md.push(mdHeading.type)\n }\n\n if (mdHeading?.context?.length) {\n md.push(...mdHeading.context)\n }\n\n const mdExamples = examples(ref.examples)\n const mdDefinitions = definitions(ref.definitions)\n md.push(...mdExamples, ...mdDefinitions)\n\n return md;\n}\n","import {u} from \"unist-builder\";\n\nimport {\n ExampleRoot,\n Definition,\n ReferenceCategory,\n ReferenceContext,\n ReferenceType,\n DefinitionProperty\n} from \"../types\";\n\n// START_DEPTH_LEVEL is the start depth level for the markdown AST\n// starts from 2 because 1 is reserved for the title\nconst START_DEPTH_LEVEL = 2\n\n// TODO: fix any\nexport function root(ast: any) {\n return u('root', ast);\n}\n\nexport function heading(\n title: string,\n canonical: string,\n description: string,\n refCategory?: ReferenceCategory,\n refType?: ReferenceType,\n refContext?: ReferenceContext\n) {\n const uTitle = u(\n 'heading',\n {depth: START_DEPTH_LEVEL},\n [u('text', `!!references ${title}`)]\n )\n\n const uCanonical = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!canonical ${canonical}`)]\n )\n\n let uDesc = [\n u(\n 'heading',\n {depth: START_DEPTH_LEVEL},\n [u('text', `!description`),]\n ),\n u('paragraph', [u('text', description)])\n ]\n\n\n let uRefCategory\n if (refCategory) {\n uRefCategory = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!category ${refCategory}`)]\n )\n }\n\n let uRefType\n if (refType) {\n uRefType = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!type ${refType}`)]\n )\n }\n\n let uContext = []\n\n if (refContext && Object.keys(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uTitle.depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n\n for (const [key, value] of Object.entries(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uContext[0].depth + 1},\n [u('text', `!${key} ${value}`)]\n )\n )\n }\n }\n\n return {\n title: uTitle,\n canonical: uCanonical,\n description: uDesc,\n category: uRefCategory || null,\n type: uRefType || null,\n context: uContext || null\n }\n}\n\nexport function examples(examples: ExampleRoot) {\n const md = []\n\n const uExampleRoot = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!examples`)]\n )\n md.push(uExampleRoot)\n\n examples.groups.forEach(group => {\n const uExampleGroups = u(\n 'heading',\n {depth: uExampleRoot.depth + 1},\n [u('text', `!!groups`)]\n )\n md.push(uExampleGroups)\n\n const uGroupDescription = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!description ${group.description}`)]\n )\n md.push(uGroupDescription)\n\n group.examples.forEach(example => {\n const uExamples = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!!examples`)]\n )\n md.push(uExamples)\n\n const codeBlock = u(\n 'heading',\n {depth: uExamples.depth + 1},\n [u('text', `!codeblock`)]\n )\n md.push(codeBlock)\n\n const codeBlockTitle = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!title ${example.codeblock.title}`)]\n )\n md.push(codeBlockTitle)\n\n const tabs = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!!tabs`)]\n )\n md.push(tabs)\n\n example.codeblock.tabs.forEach(tab => {\n const code = u('code', {\n lang: tab.language,\n meta: `!code ${tab.title}`\n }, tab.code);\n\n md.push(code)\n })\n\n })\n })\n\n return md\n}\n\nexport function definitions(definitions: Definition[]) {\n const md: any[] = []\n\n definitions.forEach(definition => {\n const uDefinition = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!!definitions`)]\n )\n md.push(uDefinition)\n\n md.push(u(\n 'heading',\n {depth: uDefinition.depth + 1},\n [u('text', `!title ${definition.title}`)]\n ))\n\n definition.properties.forEach(prop => {\n properties(\n uDefinition.depth + 1,\n {\n name: prop.name,\n type: prop.type,\n description: prop.description,\n properties: prop.properties // TODO: fix ts\n },\n md,\n )\n })\n })\n\n return md\n}\n\n// TODO: any[]\nexport function properties(\n depth: number,\n props: DefinitionProperty,\n output: any[] = []\n) {\n const paramName = props.name;\n\n const propTitle = `!!properties ${paramName}`; // TODO: check if `!!properties is enough`\n const uPropTitle = u('heading', {depth}, [u('text', propTitle)]);\n const uPropName = u('paragraph', {depth}, [u('text', `!name ${paramName}`)]);\n const uPropType = u('paragraph', {depth}, [u('text', `!type ${props.type}`)]);\n const uPropDesc = u('paragraph', {depth}, [u('text', props.description || '')]);\n\n output.push(\n uPropTitle,\n uPropName,\n uPropType,\n uPropDesc\n );\n\n if (props.properties) {\n const deepDepth = depth + 1\n\n for (const prop of props.properties) {\n properties(deepDepth, prop, output)\n }\n }\n}\n\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAqB;AACrB,8BAA4B;;;ACD5B,2BAAgB;AAahB,IAAM,oBAAoB;AAGnB,SAAS,KAAK,KAAU;AAC3B,aAAO,wBAAE,QAAQ,GAAG;AACxB;AAEO,SAAS,QACZ,OACA,WACA,aACA,aACA,SACA,YACF;AACE,QAAM,aAAS;AAAA,IACX;AAAA,IACA,EAAC,OAAO,kBAAiB;AAAA,IACzB,KAAC,wBAAE,QAAQ,gBAAgB,KAAK,EAAE,CAAC;AAAA,EACvC;AAEA,QAAM,iBAAa;AAAA,IACf;AAAA,IACA,EAAC,OAAO,OAAO,QAAQ,EAAC;AAAA,IACxB,KAAC,wBAAE,QAAQ,cAAc,SAAS,EAAE,CAAC;AAAA,EACzC;AAEA,MAAI,QAAQ;AAAA,QACR;AAAA,MACI;AAAA,MACA,EAAC,OAAO,kBAAiB;AAAA,MACzB,KAAC,wBAAE,QAAQ,cAAc,CAAE;AAAA,IAC/B;AAAA,QACA,wBAAE,aAAa,KAAC,wBAAE,QAAQ,WAAW,CAAC,CAAC;AAAA,EAC3C;AAGA,MAAI;AACJ,M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ify"]}
1
+ {"version":3,"sources":["../markdown.ts","../src/markdown/index.ts","../src/markdown/utils.ts"],"sourcesContent":["export * from \"./src/markdown/index\";\n","import {remark} from \"remark\";\nimport remarkStringify from \"remark-stringify\";\n\nimport {Reference} from \"../types\";\n\nimport {definitions, examples, heading, root} from \"./utils\";\n\n// TODO: any\nexport function compile(ast: any) {\n return remark()\n // .use(unlimitedHeadings)\n .use(remarkStringify, {\n bullet: '-',\n fences: true,\n listItemIndent: 'one',\n incrementListMarker: false,\n handlers: {\n heading(node) {\n return `${\"#\".repeat(node.depth)} ${node.children[0].value}`;\n },\n },\n })\n .stringify(root(ast));\n}\n\nexport function referenceAST(ref: Reference) {\n const md = []\n\n const mdHeading = heading(\n ref.title,\n ref.canonical,\n ref.description,\n ref.category,\n ref.type,\n ref.context\n )\n\n md.push(\n mdHeading.title,\n )\n\n if (mdHeading?.description?.length) {\n md.push(...mdHeading.description)\n }\n\n md.push(\n mdHeading.canonical,\n )\n\n if (mdHeading.category) {\n md.push(mdHeading.category)\n }\n\n if (mdHeading.type) {\n md.push(mdHeading.type)\n }\n\n if (mdHeading?.context?.length) {\n md.push(...mdHeading.context)\n }\n\n const mdExamples = examples(ref.examples)\n const mdDefinitions = definitions(ref.definitions)\n md.push(...mdExamples, ...mdDefinitions)\n\n return md;\n}\n","import { fromMarkdown } from \"mdast-util-from-markdown\";\nimport {u} from \"unist-builder\";\n\nimport {\n ExampleRoot,\n Definition,\n ReferenceCategory,\n ReferenceContext,\n ReferenceType,\n DefinitionProperty\n} from \"../types\";\n\n// START_DEPTH_LEVEL is the start depth level for the markdown AST\n// starts from 2 because 1 is reserved for the title\nconst START_DEPTH_LEVEL = 2\n\n// TODO: fix any\nexport function root(ast: any) {\n return u('root', ast);\n}\n\nexport function heading(\n title: string,\n canonical: string,\n description: string,\n refCategory?: ReferenceCategory,\n refType?: ReferenceType,\n refContext?: ReferenceContext\n) {\n const uTitle = u(\n 'heading',\n {depth: START_DEPTH_LEVEL},\n [u('text', `!!references ${title}`)]\n )\n\n const uCanonical = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!canonical ${canonical}`)]\n )\n\n let uDesc = [\n u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!description`),]\n ),\n u('paragraph', [u('text', description)])\n ]\n\n let uRefCategory\n if (refCategory) {\n uRefCategory = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!category ${refCategory}`)]\n )\n }\n\n let uRefType\n if (refType) {\n uRefType = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!type ${refType}`)]\n )\n }\n\n let uContext = []\n\n if (refContext && Object.keys(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uTitle.depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n\n for (const [key, value] of Object.entries(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uContext[0].depth + 1},\n [u('text', `!${key} ${value}`)]\n )\n )\n }\n }\n\n return {\n title: uTitle,\n canonical: uCanonical,\n description: uDesc,\n category: uRefCategory || null,\n type: uRefType || null,\n context: uContext || null\n }\n}\n\nexport function examples(examples: ExampleRoot) {\n const md = []\n\n const uExampleRoot = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!examples`)]\n )\n md.push(uExampleRoot)\n\n examples.groups.forEach(group => {\n const uExampleGroups = u(\n 'heading',\n {depth: uExampleRoot.depth + 1},\n [u('text', `!!groups`)]\n )\n md.push(uExampleGroups)\n\n const uGroupDescription = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!description ${group.description}`)]\n )\n md.push(uGroupDescription)\n\n group.examples.forEach(example => {\n const uExamples = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!!examples`)]\n )\n md.push(uExamples)\n\n const codeBlock = u(\n 'heading',\n {depth: uExamples.depth + 1},\n [u('text', `!codeblock`)]\n )\n md.push(codeBlock)\n\n const codeBlockTitle = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!title ${example.codeblock.title}`)]\n )\n md.push(codeBlockTitle)\n\n const tabs = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!!tabs`)]\n )\n md.push(tabs)\n\n example.codeblock.tabs.forEach(tab => {\n const code = u('code', {\n lang: tab.language,\n meta: `!code ${tab.title}`\n }, tab.code);\n\n md.push(code)\n })\n\n })\n })\n\n return md\n}\n\nexport function definitions(definitions: Definition[]) {\n const md: any[] = []\n\n definitions.forEach(definition => {\n const uDefinition = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!!definitions`)]\n )\n md.push(uDefinition)\n\n md.push(u(\n 'heading',\n {depth: uDefinition.depth + 1},\n [u('text', `!title ${definition.title}`)]\n ))\n\n definition.properties.forEach(prop => {\n properties(\n uDefinition.depth + 1,\n {\n name: prop.name,\n type: prop.type,\n description: prop.description,\n context: prop.context,\n properties: prop.properties // TODO: fix ts\n },\n md,\n )\n })\n })\n\n return md\n}\n\n// TODO: any[]\nexport function properties(\n depth: number,\n props: DefinitionProperty,\n output: any[] = []\n) {\n const paramName = props.name;\n\n const propTitle = `!!properties ${paramName}`; // TODO: check if `!!properties is enough`\n const uPropTitle = u('heading', {depth}, [u('text', propTitle)]);\n const uPropName = u('paragraph', {depth}, [u('text', `!name ${paramName}`)]);\n const uPropType = u('paragraph', {depth}, [u('text', `!type ${props.type}`)]);\n const markdownAst = fromMarkdown(props.description || '');\n const uPropDesc = u(\"paragraph\", { depth }, markdownAst.children);\n const uContext = []\n\n if (props.context && Object.keys(props.context)) {\n uContext.push(u(\n 'heading',\n {depth: depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n for (const [key, value] of Object.entries(props.context)) {\n uContext.push(u(\n 'heading',\n {depth: uContext[0].depth + 1},\n [u('text', `!${key} ${value}`)]\n )\n )\n }\n }\n\n output.push(\n uPropTitle,\n uPropName,\n uPropType,\n uPropDesc,\n ...uContext\n );\n\n if (props.properties) {\n const deepDepth = depth + 1\n\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AAA,EAChC;AAEA,QAAM,aAAa,SAAS,IAAI,QAAQ;AACxC,QAAM,gBAAgB,YAAY,IAAI,WAAW;AACjD,KAAG,KAAK,GAAG,YAAY,GAAG,aAAa;AAEvC,SAAO;AACX;","names":["examples","definitions","remarkStringify"]}
@@ -1,4 +1,4 @@
1
- import { R as Reference } from './types-C8Pm_zQH.cjs';
1
+ import { R as Reference } from './types-CbDJSEtC.cjs';
2
2
 
3
3
  declare function compile(ast: any): string;
4
4
  declare function referenceAST(ref: Reference): any[];
@@ -1,4 +1,4 @@
1
- import { R as Reference } from './types-C8Pm_zQH.js';
1
+ import { R as Reference } from './types-CbDJSEtC.js';
2
2
 
3
3
  declare function compile(ast: any): string;
4
4
  declare function referenceAST(ref: Reference): any[];
package/dist/markdown.js CHANGED
@@ -3,6 +3,7 @@ import { remark } from "remark";
3
3
  import remarkStringify from "remark-stringify";
4
4
 
5
5
  // src/markdown/utils.ts
6
+ import { fromMarkdown } from "mdast-util-from-markdown";
6
7
  import { u } from "unist-builder";
7
8
  var START_DEPTH_LEVEL = 2;
8
9
  function root(ast) {
@@ -22,7 +23,7 @@ function heading(title, canonical, description, refCategory, refType, refContext
22
23
  let uDesc = [
23
24
  u(
24
25
  "heading",
25
- { depth: START_DEPTH_LEVEL },
26
+ { depth: uTitle.depth + 1 },
26
27
  [u("text", `!description`)]
27
28
  ),
28
29
  u("paragraph", [u("text", description)])
@@ -149,6 +150,7 @@ function definitions(definitions2) {
149
150
  name: prop.name,
150
151
  type: prop.type,
151
152
  description: prop.description,
153
+ context: prop.context,
152
154
  properties: prop.properties
153
155
  // TODO: fix ts
154
156
  },
@@ -164,12 +166,33 @@ function properties(depth, props, output = []) {
164
166
  const uPropTitle = u("heading", { depth }, [u("text", propTitle)]);
165
167
  const uPropName = u("paragraph", { depth }, [u("text", `!name ${paramName}`)]);
166
168
  const uPropType = u("paragraph", { depth }, [u("text", `!type ${props.type}`)]);
167
- const uPropDesc = u("paragraph", { depth }, [u("text", props.description || "")]);
169
+ const markdownAst = fromMarkdown(props.description || "");
170
+ const uPropDesc = u("paragraph", { depth }, markdownAst.children);
171
+ const uContext = [];
172
+ if (props.context && Object.keys(props.context)) {
173
+ uContext.push(u(
174
+ "heading",
175
+ { depth: depth + 1 },
176
+ [
177
+ u("text", `!context`)
178
+ ]
179
+ ));
180
+ for (const [key, value] of Object.entries(props.context)) {
181
+ uContext.push(
182
+ u(
183
+ "heading",
184
+ { depth: uContext[0].depth + 1 },
185
+ [u("text", `!${key} ${value}`)]
186
+ )
187
+ );
188
+ }
189
+ }
168
190
  output.push(
169
191
  uPropTitle,
170
192
  uPropName,
171
193
  uPropType,
172
- uPropDesc
194
+ uPropDesc,
195
+ ...uContext
173
196
  );
174
197
  if (props.properties) {
175
198
  const deepDepth = depth + 1;
@@ -204,11 +227,13 @@ function referenceAST(ref) {
204
227
  ref.type,
205
228
  ref.context
206
229
  );
230
+ md.push(
231
+ mdHeading.title
232
+ );
207
233
  if ((_a = mdHeading == null ? void 0 : mdHeading.description) == null ? void 0 : _a.length) {
208
234
  md.push(...mdHeading.description);
209
235
  }
210
236
  md.push(
211
- mdHeading.title,
212
237
  mdHeading.canonical
213
238
  );
214
239
  if (mdHeading.category) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/markdown/index.ts","../src/markdown/utils.ts"],"sourcesContent":["import {remark} from \"remark\";\nimport remarkStringify from \"remark-stringify\";\n\nimport {Reference} from \"../types\";\n\nimport {definitions, examples, heading, root} from \"./utils\";\n\n// TODO: any\nexport function compile(ast: any) {\n return remark()\n // .use(unlimitedHeadings)\n .use(remarkStringify, {\n bullet: '-',\n fences: true,\n listItemIndent: 'one',\n incrementListMarker: false,\n handlers: {\n heading(node) {\n return `${\"#\".repeat(node.depth)} ${node.children[0].value}`;\n },\n },\n })\n .stringify(root(ast));\n}\n\nexport function referenceAST(ref: Reference) {\n const md = []\n\n const mdHeading = heading(\n ref.title,\n ref.canonical,\n ref.description,\n ref.category,\n ref.type,\n ref.context\n )\n\n if (mdHeading?.description?.length) {\n md.push(...mdHeading.description)\n }\n\n md.push(\n mdHeading.title,\n mdHeading.canonical,\n )\n\n if (mdHeading.category) {\n md.push(mdHeading.category)\n }\n\n if (mdHeading.type) {\n md.push(mdHeading.type)\n }\n\n if (mdHeading?.context?.length) {\n md.push(...mdHeading.context)\n }\n\n const mdExamples = examples(ref.examples)\n const mdDefinitions = definitions(ref.definitions)\n md.push(...mdExamples, ...mdDefinitions)\n\n return md;\n}\n","import {u} from \"unist-builder\";\n\nimport {\n ExampleRoot,\n Definition,\n ReferenceCategory,\n ReferenceContext,\n ReferenceType,\n DefinitionProperty\n} from \"../types\";\n\n// START_DEPTH_LEVEL is the start depth level for the markdown AST\n// starts from 2 because 1 is reserved for the title\nconst START_DEPTH_LEVEL = 2\n\n// TODO: fix any\nexport function root(ast: any) {\n return u('root', ast);\n}\n\nexport function heading(\n title: string,\n canonical: string,\n description: string,\n refCategory?: ReferenceCategory,\n refType?: ReferenceType,\n refContext?: ReferenceContext\n) {\n const uTitle = u(\n 'heading',\n {depth: START_DEPTH_LEVEL},\n [u('text', `!!references ${title}`)]\n )\n\n const uCanonical = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!canonical ${canonical}`)]\n )\n\n let uDesc = [\n u(\n 'heading',\n {depth: START_DEPTH_LEVEL},\n [u('text', `!description`),]\n ),\n u('paragraph', [u('text', description)])\n ]\n\n\n let uRefCategory\n if (refCategory) {\n uRefCategory = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!category ${refCategory}`)]\n )\n }\n\n let uRefType\n if (refType) {\n uRefType = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!type ${refType}`)]\n )\n }\n\n let uContext = []\n\n if (refContext && Object.keys(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uTitle.depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n\n for (const [key, value] of Object.entries(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uContext[0].depth + 1},\n [u('text', `!${key} ${value}`)]\n )\n )\n }\n }\n\n return {\n title: uTitle,\n canonical: uCanonical,\n description: uDesc,\n category: uRefCategory || null,\n type: uRefType || null,\n context: uContext || null\n }\n}\n\nexport function examples(examples: ExampleRoot) {\n const md = []\n\n const uExampleRoot = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!examples`)]\n )\n md.push(uExampleRoot)\n\n examples.groups.forEach(group => {\n const uExampleGroups = u(\n 'heading',\n {depth: uExampleRoot.depth + 1},\n [u('text', `!!groups`)]\n )\n md.push(uExampleGroups)\n\n const uGroupDescription = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!description ${group.description}`)]\n )\n md.push(uGroupDescription)\n\n group.examples.forEach(example => {\n const uExamples = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!!examples`)]\n )\n md.push(uExamples)\n\n const codeBlock = u(\n 'heading',\n {depth: uExamples.depth + 1},\n [u('text', `!codeblock`)]\n )\n md.push(codeBlock)\n\n const codeBlockTitle = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!title ${example.codeblock.title}`)]\n )\n md.push(codeBlockTitle)\n\n const tabs = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!!tabs`)]\n )\n md.push(tabs)\n\n example.codeblock.tabs.forEach(tab => {\n const code = u('code', {\n lang: tab.language,\n meta: `!code ${tab.title}`\n }, tab.code);\n\n md.push(code)\n })\n\n })\n })\n\n return md\n}\n\nexport function definitions(definitions: Definition[]) {\n const md: any[] = []\n\n definitions.forEach(definition => {\n const uDefinition = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!!definitions`)]\n )\n md.push(uDefinition)\n\n md.push(u(\n 'heading',\n {depth: uDefinition.depth + 1},\n [u('text', `!title ${definition.title}`)]\n ))\n\n definition.properties.forEach(prop => {\n properties(\n uDefinition.depth + 1,\n {\n name: prop.name,\n type: prop.type,\n description: prop.description,\n properties: prop.properties // TODO: fix ts\n },\n md,\n )\n })\n })\n\n return md\n}\n\n// TODO: any[]\nexport function properties(\n depth: number,\n props: DefinitionProperty,\n output: any[] = []\n) {\n const paramName = props.name;\n\n const propTitle = `!!properties ${paramName}`; // TODO: check if `!!properties is enough`\n const uPropTitle = u('heading', {depth}, [u('text', propTitle)]);\n const uPropName = u('paragraph', {depth}, [u('text', `!name ${paramName}`)]);\n const uPropType = u('paragraph', {depth}, [u('text', `!type ${props.type}`)]);\n const uPropDesc = u('paragraph', {depth}, [u('text', props.description || '')]);\n\n output.push(\n uPropTitle,\n uPropName,\n uPropType,\n uPropDesc\n );\n\n if (props.properties) {\n const deepDepth = depth + 1\n\n for (const prop of props.properties) {\n properties(deepDepth, prop, output)\n }\n }\n}\n\n\n\n"],"mappings":";AAAA,SAAQ,cAAa;AACrB,OAAO,qBAAqB;;;ACD5B,SAAQ,SAAQ;AAahB,IAAM,oBAAoB;AAGnB,SAAS,KAAK,KAAU;AAC3B,SAAO,EAAE,QAAQ,GAAG;AACxB;AAEO,SAAS,QACZ,OACA,WACA,aACA,aACA,SACA,YACF;AACE,QAAM,SAAS;AAAA,IACX;AAAA,IACA,EAAC,OAAO,kBAAiB;AAAA,IACzB,CAAC,EAAE,QAAQ,gBAAgB,KAAK,EAAE,CAAC;AAAA,EACvC;AAEA,QAAM,aAAa;AAAA,IACf;AAAA,IACA,EAAC,OAAO,OAAO,QAAQ,EAAC;AAAA,IACxB,CAAC,EAAE,QAAQ,cAAc,SAAS,EAAE,CAAC;AAAA,EACzC;AAEA,MAAI,QAAQ;AAAA,IACR;AAAA,MACI;AAAA,MACA,EAAC,OAAO,kBAAiB;AAAA,MACzB,CAAC,EAAE,QAAQ,cAAc,CAAE;AAAA,IAC/B;AAAA,IACA,EAAE,aAAa,CAAC,EAAE,QAAQ,WAAW,CAAC,CAAC;AAAA,EAC3C;AAGA,MAAI;AACJ,MAAI,aAAa;AACb,mBAAe;AAAA,MACX;AAAA,MACA,EAAC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Y;AACjC,iBAAW,WAAW,MAAM,MAAM;AAAA,IACtC;AAAA,EACJ;AACJ;;;AD/NO,SAAS,QAAQ,KAAU;AAC9B,SAAO,OAAO,EAET,IAAI,iBAAiB;AAAA,IAClB,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,gBAAgB;AAAA,IAChB,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACN,QAAQ,MAAM;AACV,eAAO,GAAG,IAAI,OAAO,KAAK,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,EAAE,KAAK;AAAA,MAC9D;AAAA,IACJ;AAAA,EACJ,CAAC,EACA,UAAU,KAAK,GAAG,CAAC;AAC5B;AAEO,SAAS,aAAa,KAAgB;AAzB7C;AA0BI,QAAM,KAAK,CAAC;AAEZ,QAAM,YAAY;AAAA,IACd,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,EACR;AAEA,OAAI,4CAAW,gBAAX,mBAAwB,QAAQ;AAChC,OAAG,KAAK,GAAG,UAAU,WAAW;AAAA,EACpC;AAEA,KAAG;AAAA,IACC,UAAU;AAAA,IACV,UAAU;AAAA,EACd;AAEA,MAAI,UAAU,UAAU;AACpB,OAAG,KAAK,UAAU,QAAQ;AAAA,EAC9B;AAEA,MAAI,UAAU,MAAM;AAChB,OAAG,KAAK,UAAU,IAAI;AAAA,EAC1B;AAEA,OAAI,4CAAW,YAAX,mBAAoB,QAAQ;AAC5B,OAAG,KAAK,GAAG,UAAU,OAAO;AAAA,EAChC;AAEA,QAAM,aAAa,SAAS,IAAI,QAAQ;AACxC,QAAM,gBAAgB,YAAY,IAAI,WAAW;AACjD,KAAG,KAAK,GAAG,YAAY,GAAG,aAAa;AAEvC,SAAO;AACX;","names":["examples","definitions"]}
1
+ {"version":3,"sources":["../src/markdown/index.ts","../src/markdown/utils.ts"],"sourcesContent":["import {remark} from \"remark\";\nimport remarkStringify from \"remark-stringify\";\n\nimport {Reference} from \"../types\";\n\nimport {definitions, examples, heading, root} from \"./utils\";\n\n// TODO: any\nexport function compile(ast: any) {\n return remark()\n // .use(unlimitedHeadings)\n .use(remarkStringify, {\n bullet: '-',\n fences: true,\n listItemIndent: 'one',\n incrementListMarker: false,\n handlers: {\n heading(node) {\n return `${\"#\".repeat(node.depth)} ${node.children[0].value}`;\n },\n },\n })\n .stringify(root(ast));\n}\n\nexport function referenceAST(ref: Reference) {\n const md = []\n\n const mdHeading = heading(\n ref.title,\n ref.canonical,\n ref.description,\n ref.category,\n ref.type,\n ref.context\n )\n\n md.push(\n mdHeading.title,\n )\n\n if (mdHeading?.description?.length) {\n md.push(...mdHeading.description)\n }\n\n md.push(\n mdHeading.canonical,\n )\n\n if (mdHeading.category) {\n md.push(mdHeading.category)\n }\n\n if (mdHeading.type) {\n md.push(mdHeading.type)\n }\n\n if (mdHeading?.context?.length) {\n md.push(...mdHeading.context)\n }\n\n const mdExamples = examples(ref.examples)\n const mdDefinitions = definitions(ref.definitions)\n md.push(...mdExamples, ...mdDefinitions)\n\n return md;\n}\n","import { fromMarkdown } from \"mdast-util-from-markdown\";\nimport {u} from \"unist-builder\";\n\nimport {\n ExampleRoot,\n Definition,\n ReferenceCategory,\n ReferenceContext,\n ReferenceType,\n DefinitionProperty\n} from \"../types\";\n\n// START_DEPTH_LEVEL is the start depth level for the markdown AST\n// starts from 2 because 1 is reserved for the title\nconst START_DEPTH_LEVEL = 2\n\n// TODO: fix any\nexport function root(ast: any) {\n return u('root', ast);\n}\n\nexport function heading(\n title: string,\n canonical: string,\n description: string,\n refCategory?: ReferenceCategory,\n refType?: ReferenceType,\n refContext?: ReferenceContext\n) {\n const uTitle = u(\n 'heading',\n {depth: START_DEPTH_LEVEL},\n [u('text', `!!references ${title}`)]\n )\n\n const uCanonical = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!canonical ${canonical}`)]\n )\n\n let uDesc = [\n u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!description`),]\n ),\n u('paragraph', [u('text', description)])\n ]\n\n let uRefCategory\n if (refCategory) {\n uRefCategory = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!category ${refCategory}`)]\n )\n }\n\n let uRefType\n if (refType) {\n uRefType = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!type ${refType}`)]\n )\n }\n\n let uContext = []\n\n if (refContext && Object.keys(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uTitle.depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n\n for (const [key, value] of Object.entries(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uContext[0].depth + 1},\n [u('text', `!${key} ${value}`)]\n )\n )\n }\n }\n\n return {\n title: uTitle,\n canonical: uCanonical,\n description: uDesc,\n category: uRefCategory || null,\n type: uRefType || null,\n context: uContext || null\n }\n}\n\nexport function examples(examples: ExampleRoot) {\n const md = []\n\n const uExampleRoot = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!examples`)]\n )\n md.push(uExampleRoot)\n\n examples.groups.forEach(group => {\n const uExampleGroups = u(\n 'heading',\n {depth: uExampleRoot.depth + 1},\n [u('text', `!!groups`)]\n )\n md.push(uExampleGroups)\n\n const uGroupDescription = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!description ${group.description}`)]\n )\n md.push(uGroupDescription)\n\n group.examples.forEach(example => {\n const uExamples = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!!examples`)]\n )\n md.push(uExamples)\n\n const codeBlock = u(\n 'heading',\n {depth: uExamples.depth + 1},\n [u('text', `!codeblock`)]\n )\n md.push(codeBlock)\n\n const codeBlockTitle = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!title ${example.codeblock.title}`)]\n )\n md.push(codeBlockTitle)\n\n const tabs = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!!tabs`)]\n )\n md.push(tabs)\n\n example.codeblock.tabs.forEach(tab => {\n const code = u('code', {\n lang: tab.language,\n meta: `!code ${tab.title}`\n }, tab.code);\n\n md.push(code)\n })\n\n })\n })\n\n return md\n}\n\nexport function definitions(definitions: Definition[]) {\n const md: any[] = []\n\n definitions.forEach(definition => {\n const uDefinition = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!!definitions`)]\n )\n md.push(uDefinition)\n\n md.push(u(\n 'heading',\n {depth: uDefinition.depth + 1},\n [u('text', `!title ${definition.title}`)]\n ))\n\n definition.properties.forEach(prop => {\n properties(\n uDefinition.depth + 1,\n {\n name: prop.name,\n type: prop.type,\n description: prop.description,\n context: prop.context,\n properties: prop.properties // TODO: fix ts\n },\n md,\n )\n })\n })\n\n return md\n}\n\n// TODO: any[]\nexport function properties(\n depth: number,\n props: DefinitionProperty,\n output: any[] = []\n) {\n const paramName = props.name;\n\n const propTitle = `!!properties ${paramName}`; // TODO: check if `!!properties is enough`\n const uPropTitle = u('heading', {depth}, [u('text', propTitle)]);\n const uPropName = u('paragraph', {depth}, [u('text', `!name ${paramName}`)]);\n const uPropType = u('paragraph', {depth}, [u('text', `!type ${props.type}`)]);\n const markdownAst = fromMarkdown(props.description || '');\n const uPropDesc = u(\"paragraph\", { depth }, markdownAst.children);\n const uContext = []\n\n if (props.context && Object.keys(props.context)) {\n uContext.push(u(\n 'heading',\n {depth: depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n for (const [key, value] of Object.entries(props.context)) {\n uContext.push(u(\n 'heading',\n {depth: uContext[0].depth + 1},\n [u('text', `!${key} ${value}`)]\n )\n )\n }\n }\n\n output.push(\n uPropTitle,\n uPropName,\n uPropType,\n uPropDesc,\n ...uContext\n );\n\n if (props.properties) {\n const deepDepth = depth + 1\n\n for (const prop of props.properties) {\n properties(deepDepth, prop, output)\n }\n }\n}\n\n\n\n"],"mappings":";AAAA,SAAQ,cAAa;AACrB,OAAO,qBAAqB;;;ACD5B,SAAS,oBAAoB;AAC7B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jC,iBAAW,WAAW,MAAM,MAAM;AAAA,IACtC;AAAA,EACJ;AACJ;;;ADtPO,SAAS,QAAQ,KAAU;AAC9B,SAAO,OAAO,EAET,IAAI,iBAAiB;AAAA,IAClB,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,gBAAgB;AAAA,IAChB,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACN,QAAQ,MAAM;AACV,eAAO,GAAG,IAAI,OAAO,KAAK,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,EAAE,KAAK;AAAA,MAC9D;AAAA,IACJ;AAAA,EACJ,CAAC,EACA,UAAU,KAAK,GAAG,CAAC;AAC5B;AAEO,SAAS,aAAa,KAAgB;AAzB7C;AA0BI,QAAM,KAAK,CAAC;AAEZ,QAAM,YAAY;AAAA,IACd,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,EACR;AAEA,KAAG;AAAA,IACC,UAAU;AAAA,EACd;AAEA,OAAI,4CAAW,gBAAX,mBAAwB,QAAQ;AAChC,OAAG,KAAK,GAAG,UAAU,WAAW;AAAA,EACpC;AAEA,KAAG;AAAA,IACC,UAAU;AAAA,EACd;AAEA,MAAI,UAAU,UAAU;AACpB,OAAG,KAAK,UAAU,QAAQ;AAAA,EAC9B;AAEA,MAAI,UAAU,MAAM;AAChB,OAAG,KAAK,UAAU,IAAI;AAAA,EAC1B;AAEA,OAAI,4CAAW,YAAX,mBAAoB,QAAQ;AAC5B,OAAG,KAAK,GAAG,UAAU,OAAO;AAAA,EAChC;AAEA,QAAM,aAAa,SAAS,IAAI,QAAQ;AACxC,QAAM,gBAAgB,YAAY,IAAI,WAAW;AACjD,KAAG,KAAK,GAAG,YAAY,GAAG,aAAa;AAEvC,SAAO;AACX;","names":["examples","definitions"]}
@@ -74,6 +74,7 @@ interface DefinitionProperty {
74
74
  name: string;
75
75
  type: string;
76
76
  description: string;
77
+ context?: any;
77
78
  properties?: DefinitionProperty[];
78
79
  }
79
80
 
@@ -74,6 +74,7 @@ interface DefinitionProperty {
74
74
  name: string;
75
75
  type: string;
76
76
  description: string;
77
+ context?: any;
77
78
  properties?: DefinitionProperty[];
78
79
  }
79
80
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyd-js/uniform",
3
- "version": "0.1.0-xyd.4",
3
+ "version": "0.1.0-xyd.6",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -13,11 +13,13 @@
13
13
  "dependencies": {
14
14
  "codehike": "^1.0.3",
15
15
  "gray-matter": "^4.0.3",
16
+ "mdast-util-from-markdown": "^2.0.2",
17
+ "mdast-util-to-markdown": "^2.1.2",
16
18
  "remark": "^15.0.1",
17
19
  "remark-stringify": "^11.0.0",
18
20
  "unist-builder": "^4.0.0",
19
21
  "unist-util-visit": "^5.0.0",
20
- "@xyd-js/core": "0.1.0-xyd.2"
22
+ "@xyd-js/core": "0.1.0-xyd.4"
21
23
  },
22
24
  "peerDependencies": {
23
25
  "@mdx-js/mdx": "^3.1.0"
@@ -35,12 +35,15 @@ export function referenceAST(ref: Reference) {
35
35
  ref.context
36
36
  )
37
37
 
38
+ md.push(
39
+ mdHeading.title,
40
+ )
41
+
38
42
  if (mdHeading?.description?.length) {
39
43
  md.push(...mdHeading.description)
40
44
  }
41
45
 
42
46
  md.push(
43
- mdHeading.title,
44
47
  mdHeading.canonical,
45
48
  )
46
49
 
@@ -1,3 +1,4 @@
1
+ import { fromMarkdown } from "mdast-util-from-markdown";
1
2
  import {u} from "unist-builder";
2
3
 
3
4
  import {
@@ -41,13 +42,12 @@ export function heading(
41
42
  let uDesc = [
42
43
  u(
43
44
  'heading',
44
- {depth: START_DEPTH_LEVEL},
45
+ {depth: uTitle.depth + 1},
45
46
  [u('text', `!description`),]
46
47
  ),
47
48
  u('paragraph', [u('text', description)])
48
49
  ]
49
50
 
50
-
51
51
  let uRefCategory
52
52
  if (refCategory) {
53
53
  uRefCategory = u(
@@ -191,6 +191,7 @@ export function definitions(definitions: Definition[]) {
191
191
  name: prop.name,
192
192
  type: prop.type,
193
193
  description: prop.description,
194
+ context: prop.context,
194
195
  properties: prop.properties // TODO: fix ts
195
196
  },
196
197
  md,
@@ -213,13 +214,35 @@ export function properties(
213
214
  const uPropTitle = u('heading', {depth}, [u('text', propTitle)]);
214
215
  const uPropName = u('paragraph', {depth}, [u('text', `!name ${paramName}`)]);
215
216
  const uPropType = u('paragraph', {depth}, [u('text', `!type ${props.type}`)]);
216
- const uPropDesc = u('paragraph', {depth}, [u('text', props.description || '')]);
217
+ const markdownAst = fromMarkdown(props.description || '');
218
+ const uPropDesc = u("paragraph", { depth }, markdownAst.children);
219
+ const uContext = []
220
+
221
+ if (props.context && Object.keys(props.context)) {
222
+ uContext.push(u(
223
+ 'heading',
224
+ {depth: depth + 1},
225
+ [
226
+ u('text', `!context`),
227
+ ]
228
+ ))
229
+
230
+ for (const [key, value] of Object.entries(props.context)) {
231
+ uContext.push(u(
232
+ 'heading',
233
+ {depth: uContext[0].depth + 1},
234
+ [u('text', `!${key} ${value}`)]
235
+ )
236
+ )
237
+ }
238
+ }
217
239
 
218
240
  output.push(
219
241
  uPropTitle,
220
242
  uPropName,
221
243
  uPropType,
222
- uPropDesc
244
+ uPropDesc,
245
+ ...uContext
223
246
  );
224
247
 
225
248
  if (props.properties) {
package/src/types.ts CHANGED
@@ -116,6 +116,7 @@ export interface Definition {
116
116
 
117
117
  properties: DefinitionProperty[];
118
118
 
119
+
119
120
  type?: string;
120
121
 
121
122
  id?: string;
@@ -130,5 +131,7 @@ export interface DefinitionProperty {
130
131
 
131
132
  description: string;
132
133
 
134
+ context?: any // TODO: better type
135
+
133
136
  properties?: DefinitionProperty[];
134
137
  }