@xyd-js/uniform 0.1.0-xyd.4 → 0.1.0-xyd.5
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/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/markdown.cjs +26 -3
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +1 -1
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.js +26 -3
- package/dist/markdown.js.map +1 -1
- package/dist/{types-C8Pm_zQH.d.cts → types-CbDJSEtC.d.cts} +1 -0
- package/dist/{types-C8Pm_zQH.d.ts → types-CbDJSEtC.d.ts} +1 -0
- package/package.json +1 -1
- package/src/markdown/index.ts +4 -1
- package/src/markdown/utils.ts +24 -3
- package/src/types.ts +3 -0
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts","../src/index.ts","../src/utils.ts","../src/types.ts"],"sourcesContent":["export {default} from \"./src/index\"\n\nexport {\n pluginNavigation\n} from \"./src/utils\"\n\nexport * from \"./src/types\"\n\n","// Define the new PluginV type with a callback function that returns another function\nimport {Reference} from \"./types\";\n\n// Define the new PluginV type with a callback function that returns another function\nexport type UniformPlugin<T> = (cb: (cb: () => T) => void) => (ref: Reference) => void;\n\n// Utility type to infer if a type is an array and avoid wrapping it into an array twice\ntype NormalizeArray<T> = T extends Array<infer U> ? U[] : T;\n\n// Infer the return type of the plugin callback properly and normalize array types\ntype PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;\n\n// Merge all plugin return types into a single object and normalize arrays\ntype MergePluginResults<T extends UniformPlugin<any>[]> = {\n [K in keyof UnionToIntersection<PluginResult<T[number]>>]: NormalizeArray<UnionToIntersection<PluginResult<T[number]>>[K]>\n};\n\n// Utility type to handle intersection to an object type\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;\n\n// Implement the uniform function\nexport default function uniform<T extends UniformPlugin<any>[]>(\n references: Reference[],\n config: { plugins: T }\n) {\n // Infer the merged result type from all plugins\n type ResultType = MergePluginResults<T>;\n\n // Initialize the response with a type-safe out object\n const response: {\n references: Reference[]\n out: { [K in keyof ResultType]: ResultType[K] }\n } = {\n references,\n out: {} as { [K in keyof ResultType]: ResultType[K] }\n };\n\n\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[];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A,IACL;AAAA,EACJ,CAAC;AAED,SAAO;AACX;;;AChHO,IAAK,oBAAL,kBAAKC,uBAAL;AAEH,EAAAA,mBAAA,gBAAa;AACb,EAAAA,mBAAA,WAAQ;AAIR,EAAAA,mBAAA,UAAO;AACP,EAAAA,mBAAA,aAAU;AAIV,EAAAA,mBAAA,eAAY;AAZJ,SAAAA;AAAA,GAAA;AAiBL,IAAK,gBAAL,kBAAKC,mBAAL;AAEH,EAAAA,eAAA,eAAY;AACZ,EAAAA,eAAA,UAAO;AAIP,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,oBAAiB;AACjB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,qBAAkB;AAClB,EAAAA,eAAA,sBAAmB;AAEnB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,sBAAmB;AAInB,EAAAA,eAAA,iBAAc;AAlBN,SAAAA;AAAA,GAAA;","names":["matter","path","ReferenceCategory","ReferenceType"]}
|
|
1
|
+
{"version":3,"sources":["../index.ts","../src/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;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,OAAO;AAAA,QACP;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAED,SAAO;AACX;;;AChHO,IAAK,oBAAL,kBAAKC,uBAAL;AAEH,EAAAA,mBAAA,gBAAa;AACb,EAAAA,mBAAA,WAAQ;AAIR,EAAAA,mBAAA,UAAO;AACP,EAAAA,mBAAA,aAAU;AAIV,EAAAA,mBAAA,eAAY;AAZJ,SAAAA;AAAA,GAAA;AAiBL,IAAK,gBAAL,kBAAKC,mBAAL;AAEH,EAAAA,eAAA,eAAY;AACZ,EAAAA,eAAA,UAAO;AAIP,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,oBAAiB;AACjB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,qBAAkB;AAClB,EAAAA,eAAA,sBAAmB;AAEnB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,sBAAmB;AAInB,EAAAA,eAAA,iBAAc;AAlBN,SAAAA;AAAA,GAAA;","names":["matter","path","ReferenceCategory","ReferenceType"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as Reference } from './types-
|
|
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-
|
|
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-
|
|
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-
|
|
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,EAAE;AAAA,IAC1B,CAAC;AAED,eAAW,QAAQ,CAAC,QAAQ;AACxB,WAAK,GAAG;AAAA,IACZ,CAAC;AAAA,EACL,CAAC;AAED,kBAAgB,QAAQ,QAAM;AAC1B,QAAI,OAAO,OAAO,YAAY;AAC1B,YAAM,OAAO,GAAG;AAChB,UAAI,OAAO,SAAS,UAAU;AAC1B,cAAM,IAAI,MAAM,iCAAiC,OAAO,IAAI,EAAE;AAAA,MAClE;AAEA,eAAS,MAAM;AAAA,QACX,GAAG,SAAS;AAAA,QACZ,GAAG;AAAA,MACP;AAAA,IACJ,OAAO;AACH,YAAM,IAAI,MAAM,0BAA0B,OAAO,EAAE,EAAE;AAAA,IACzD;AAAA,EACJ,CAAC;AAED,SAAO;AACX;;;ACnEA,OAAO,UAAU;AACjB,OAAO,YAAY;AAqBZ,SAAS,iBAAiB,SAAkC;AAC/D,MAAI,CAAC,QAAQ,WAAW;AACpB,UAAM,IAAI,MAAM,uBAAuB;AAAA,EAC3C;AAEA,SAAO,SAAS,sBAAsB,IAG1B;AACR,UAAM,kBAAmC,CAAC;AAC1C,UAAM,YAAsB,CAAC;AAE7B,OAAG,MAAM;AACL,aAAO;AAAA,QACH;AAAA,QACA,SAAS,8BAA8B,SAAS;AAAA,MACpD;AAAA,IACJ,CAAC;AAED,WAAO,CAAC,QAAmB;AAzCnC;AA0CY,YAAM,UAAU,OAAO,IAAI,eAAe,EA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AAAA,QACP;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ,CAAC;AAED,SAAO;AACX;;;AChHO,IAAK,oBAAL,kBAAKA,uBAAL;AAEH,EAAAA,mBAAA,gBAAa;AACb,EAAAA,mBAAA,WAAQ;AAIR,EAAAA,mBAAA,UAAO;AACP,EAAAA,mBAAA,aAAU;AAIV,EAAAA,mBAAA,eAAY;AAZJ,SAAAA;AAAA,GAAA;AAiBL,IAAK,gBAAL,kBAAKC,mBAAL;AAEH,EAAAA,eAAA,eAAY;AACZ,EAAAA,eAAA,UAAO;AAIP,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,oBAAiB;AACjB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,qBAAkB;AAClB,EAAAA,eAAA,sBAAmB;AAEnB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,sBAAmB;AAInB,EAAAA,eAAA,iBAAc;AAlBN,SAAAA;AAAA,GAAA;","names":["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":";AAq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EAAAA,mBAAA,WAAQ;AAIR,EAAAA,mBAAA,UAAO;AACP,EAAAA,mBAAA,aAAU;AAIV,EAAAA,mBAAA,eAAY;AAZJ,SAAAA;AAAA,GAAA;AAiBL,IAAK,gBAAL,kBAAKC,mBAAL;AAEH,EAAAA,eAAA,eAAY;AACZ,EAAAA,eAAA,UAAO;AAIP,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,oBAAiB;AACjB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,qBAAkB;AAClB,EAAAA,eAAA,sBAAmB;AAEnB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,sBAAmB;AAInB,EAAAA,eAAA,iBAAc;AAlBN,SAAAA;AAAA,GAAA;","names":["ReferenceCategory","ReferenceType"]}
|
package/dist/markdown.cjs
CHANGED
|
@@ -59,7 +59,7 @@ function heading(title, canonical, description, refCategory, refType, refContext
|
|
|
59
59
|
let uDesc = [
|
|
60
60
|
(0, import_unist_builder.u)(
|
|
61
61
|
"heading",
|
|
62
|
-
{ depth:
|
|
62
|
+
{ depth: uTitle.depth + 1 },
|
|
63
63
|
[(0, import_unist_builder.u)("text", `!description`)]
|
|
64
64
|
),
|
|
65
65
|
(0, import_unist_builder.u)("paragraph", [(0, import_unist_builder.u)("text", description)])
|
|
@@ -186,6 +186,7 @@ function definitions(definitions2) {
|
|
|
186
186
|
name: prop.name,
|
|
187
187
|
type: prop.type,
|
|
188
188
|
description: prop.description,
|
|
189
|
+
context: prop.context,
|
|
189
190
|
properties: prop.properties
|
|
190
191
|
// TODO: fix ts
|
|
191
192
|
},
|
|
@@ -202,11 +203,31 @@ function properties(depth, props, output = []) {
|
|
|
202
203
|
const uPropName = (0, import_unist_builder.u)("paragraph", { depth }, [(0, import_unist_builder.u)("text", `!name ${paramName}`)]);
|
|
203
204
|
const uPropType = (0, import_unist_builder.u)("paragraph", { depth }, [(0, import_unist_builder.u)("text", `!type ${props.type}`)]);
|
|
204
205
|
const uPropDesc = (0, import_unist_builder.u)("paragraph", { depth }, [(0, import_unist_builder.u)("text", props.description || "")]);
|
|
206
|
+
const uContext = [];
|
|
207
|
+
if (props.context && Object.keys(props.context)) {
|
|
208
|
+
uContext.push((0, import_unist_builder.u)(
|
|
209
|
+
"heading",
|
|
210
|
+
{ depth: depth + 1 },
|
|
211
|
+
[
|
|
212
|
+
(0, import_unist_builder.u)("text", `!context`)
|
|
213
|
+
]
|
|
214
|
+
));
|
|
215
|
+
for (const [key, value] of Object.entries(props.context)) {
|
|
216
|
+
uContext.push(
|
|
217
|
+
(0, import_unist_builder.u)(
|
|
218
|
+
"heading",
|
|
219
|
+
{ depth: uContext[0].depth + 1 },
|
|
220
|
+
[(0, import_unist_builder.u)("text", `!${key} ${value}`)]
|
|
221
|
+
)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
205
225
|
output.push(
|
|
206
226
|
uPropTitle,
|
|
207
227
|
uPropName,
|
|
208
228
|
uPropType,
|
|
209
|
-
uPropDesc
|
|
229
|
+
uPropDesc,
|
|
230
|
+
...uContext
|
|
210
231
|
);
|
|
211
232
|
if (props.properties) {
|
|
212
233
|
const deepDepth = depth + 1;
|
|
@@ -241,11 +262,13 @@ function referenceAST(ref) {
|
|
|
241
262
|
ref.type,
|
|
242
263
|
ref.context
|
|
243
264
|
);
|
|
265
|
+
md.push(
|
|
266
|
+
mdHeading.title
|
|
267
|
+
);
|
|
244
268
|
if ((_a = mdHeading == null ? void 0 : mdHeading.description) == null ? void 0 : _a.length) {
|
|
245
269
|
md.push(...mdHeading.description);
|
|
246
270
|
}
|
|
247
271
|
md.push(
|
|
248
|
-
mdHeading.title,
|
|
249
272
|
mdHeading.canonical
|
|
250
273
|
);
|
|
251
274
|
if (mdHeading.category) {
|
package/dist/markdown.cjs.map
CHANGED
|
@@ -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,IACz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;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","remarkStringify"]}
|
|
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 {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 uPropDesc = u('paragraph', {depth}, [u('text', props.description || '')]);\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;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,OAAO,QAAQ,EAAC;AAAA,MACxB,KAAC,wBAAE,QAAQ,cAAc,CAAE;AAAA,IAC/B;AAAA,QACA,wBAAE,aAAa,KAAC,wBAAE,QAAQ,WAAW,CAAC,CAAC;AAAA,EAC3C;AAEA,MAAI;AACJ,MAAI,aAAa;AACb,uBAAe;AAAA,MACX;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A,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","remarkStringify"]}
|
package/dist/markdown.d.cts
CHANGED
package/dist/markdown.d.ts
CHANGED
package/dist/markdown.js
CHANGED
|
@@ -22,7 +22,7 @@ function heading(title, canonical, description, refCategory, refType, refContext
|
|
|
22
22
|
let uDesc = [
|
|
23
23
|
u(
|
|
24
24
|
"heading",
|
|
25
|
-
{ depth:
|
|
25
|
+
{ depth: uTitle.depth + 1 },
|
|
26
26
|
[u("text", `!description`)]
|
|
27
27
|
),
|
|
28
28
|
u("paragraph", [u("text", description)])
|
|
@@ -149,6 +149,7 @@ function definitions(definitions2) {
|
|
|
149
149
|
name: prop.name,
|
|
150
150
|
type: prop.type,
|
|
151
151
|
description: prop.description,
|
|
152
|
+
context: prop.context,
|
|
152
153
|
properties: prop.properties
|
|
153
154
|
// TODO: fix ts
|
|
154
155
|
},
|
|
@@ -165,11 +166,31 @@ function properties(depth, props, output = []) {
|
|
|
165
166
|
const uPropName = u("paragraph", { depth }, [u("text", `!name ${paramName}`)]);
|
|
166
167
|
const uPropType = u("paragraph", { depth }, [u("text", `!type ${props.type}`)]);
|
|
167
168
|
const uPropDesc = u("paragraph", { depth }, [u("text", props.description || "")]);
|
|
169
|
+
const uContext = [];
|
|
170
|
+
if (props.context && Object.keys(props.context)) {
|
|
171
|
+
uContext.push(u(
|
|
172
|
+
"heading",
|
|
173
|
+
{ depth: depth + 1 },
|
|
174
|
+
[
|
|
175
|
+
u("text", `!context`)
|
|
176
|
+
]
|
|
177
|
+
));
|
|
178
|
+
for (const [key, value] of Object.entries(props.context)) {
|
|
179
|
+
uContext.push(
|
|
180
|
+
u(
|
|
181
|
+
"heading",
|
|
182
|
+
{ depth: uContext[0].depth + 1 },
|
|
183
|
+
[u("text", `!${key} ${value}`)]
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
168
188
|
output.push(
|
|
169
189
|
uPropTitle,
|
|
170
190
|
uPropName,
|
|
171
191
|
uPropType,
|
|
172
|
-
uPropDesc
|
|
192
|
+
uPropDesc,
|
|
193
|
+
...uContext
|
|
173
194
|
);
|
|
174
195
|
if (props.properties) {
|
|
175
196
|
const deepDepth = depth + 1;
|
|
@@ -204,11 +225,13 @@ function referenceAST(ref) {
|
|
|
204
225
|
ref.type,
|
|
205
226
|
ref.context
|
|
206
227
|
);
|
|
228
|
+
md.push(
|
|
229
|
+
mdHeading.title
|
|
230
|
+
);
|
|
207
231
|
if ((_a = mdHeading == null ? void 0 : mdHeading.description) == null ? void 0 : _a.length) {
|
|
208
232
|
md.push(...mdHeading.description);
|
|
209
233
|
}
|
|
210
234
|
md.push(
|
|
211
|
-
mdHeading.title,
|
|
212
235
|
mdHeading.canonical
|
|
213
236
|
);
|
|
214
237
|
if (mdHeading.category) {
|
package/dist/markdown.js.map
CHANGED
|
@@ -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,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A,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 {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 uPropDesc = u('paragraph', {depth}, [u('text', props.description || '')]);\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,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,OAAO,QAAQ,EAAC;AAAA,MACxB,CAAC,EAAE,QAAQ,cAAc,CAAE;AAAA,IAC/B;AAAA,IACA,EAAE,aAAa,CAAC,EAAE,QAAQ,WAAW,CAAC,CAAC;AAAA,EAC3C;AAEA,MAAI;AACJ,MAAI,aAAa;AACb,mBAAe;AAAA,MACX;AAAA,MACA,EAAC,OAAO,OAAO,QAAQ,EAAC;AAAA,MACxB,CAAC,EAAE,QAAQ,aAAa,WAAW,EAAE,CAAC;AAAA,IAC1C;AAAA,EACJ;AAEA,MAAI;AACJ,MAAI,SAAS;AACT,eAAW;AAAA,MACP;AAAA,MACA,EAAC,OAAO,OAAO,QAAQ,EAAC;AAAA,MACxB,CAAC,EAAE,QAAQ,SAAS,OAAO,EAAE,CAAC;AAAA,IAClC;AAAA,EACJ;AAEA,MAAI,WAAW,CAAC;AAEhB,MAAI,cAAc,OAAO,KAAK,UAAU,GAAG;AACvC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AgB,YAAY,IAAI,WAAW;AACjD,KAAG,KAAK,GAAG,YAAY,GAAG,aAAa;AAEvC,SAAO;AACX;","names":["examples","definitions"]}
|
package/package.json
CHANGED
package/src/markdown/index.ts
CHANGED
|
@@ -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
|
|
package/src/markdown/utils.ts
CHANGED
|
@@ -41,13 +41,12 @@ export function heading(
|
|
|
41
41
|
let uDesc = [
|
|
42
42
|
u(
|
|
43
43
|
'heading',
|
|
44
|
-
{depth:
|
|
44
|
+
{depth: uTitle.depth + 1},
|
|
45
45
|
[u('text', `!description`),]
|
|
46
46
|
),
|
|
47
47
|
u('paragraph', [u('text', description)])
|
|
48
48
|
]
|
|
49
49
|
|
|
50
|
-
|
|
51
50
|
let uRefCategory
|
|
52
51
|
if (refCategory) {
|
|
53
52
|
uRefCategory = u(
|
|
@@ -191,6 +190,7 @@ export function definitions(definitions: Definition[]) {
|
|
|
191
190
|
name: prop.name,
|
|
192
191
|
type: prop.type,
|
|
193
192
|
description: prop.description,
|
|
193
|
+
context: prop.context,
|
|
194
194
|
properties: prop.properties // TODO: fix ts
|
|
195
195
|
},
|
|
196
196
|
md,
|
|
@@ -214,12 +214,33 @@ export function properties(
|
|
|
214
214
|
const uPropName = u('paragraph', {depth}, [u('text', `!name ${paramName}`)]);
|
|
215
215
|
const uPropType = u('paragraph', {depth}, [u('text', `!type ${props.type}`)]);
|
|
216
216
|
const uPropDesc = u('paragraph', {depth}, [u('text', props.description || '')]);
|
|
217
|
+
const uContext = []
|
|
218
|
+
|
|
219
|
+
if (props.context && Object.keys(props.context)) {
|
|
220
|
+
uContext.push(u(
|
|
221
|
+
'heading',
|
|
222
|
+
{depth: depth + 1},
|
|
223
|
+
[
|
|
224
|
+
u('text', `!context`),
|
|
225
|
+
]
|
|
226
|
+
))
|
|
227
|
+
|
|
228
|
+
for (const [key, value] of Object.entries(props.context)) {
|
|
229
|
+
uContext.push(u(
|
|
230
|
+
'heading',
|
|
231
|
+
{depth: uContext[0].depth + 1},
|
|
232
|
+
[u('text', `!${key} ${value}`)]
|
|
233
|
+
)
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
217
237
|
|
|
218
238
|
output.push(
|
|
219
239
|
uPropTitle,
|
|
220
240
|
uPropName,
|
|
221
241
|
uPropType,
|
|
222
|
-
uPropDesc
|
|
242
|
+
uPropDesc,
|
|
243
|
+
...uContext
|
|
223
244
|
);
|
|
224
245
|
|
|
225
246
|
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
|
}
|