mikro-orm-markdown 0.1.0-alpha.1 → 0.1.0-alpha.2
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/README.ko.md +27 -23
- package/README.md +26 -22
- package/dist/cli.cjs +117 -69
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +117 -69
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +115 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +115 -62
- package/dist/index.js.map +1 -1
- package/package.json +16 -12
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/docs/jsdoc.ts","../src/metadata/load.ts","../src/render/mermaid.ts","../src/model/build.ts","../src/render/markdown.ts","../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport type { Options } from '@mikro-orm/core';\nimport { Command } from 'commander';\nimport { MetadataLoadError, generateMarkdown } from './index.js';\n\ninterface CliOptions {\n config: string;\n out: string;\n title: string;\n description?: string;\n src: string[];\n}\n\nasync function run(opts: CliOptions): Promise<void> {\n const configPath = path.resolve(opts.config);\n const outPath = path.resolve(opts.out);\n\n let ormOptions: Options;\n try {\n const mod = (await import(configPath)) as { default?: unknown };\n ormOptions = (mod.default ?? mod);\n } catch (err) {\n const hint = configPath.endsWith('.ts')\n ? '\\nHint: TypeScript configs require tsx or ts-node:\\n npx tsx ./node_modules/.bin/mikro-orm-markdown ...'\n : '';\n process.stderr.write(\n `Error: Cannot load config: ${configPath}\\n${err instanceof Error ? err.message : String(err)}${hint}\\n`,\n );\n process.exit(1);\n }\n\n let markdown: string;\n try {\n markdown = await generateMarkdown({\n orm: ormOptions,\n title: opts.title,\n src: opts.src,\n ...(opts.description !== undefined && { description: opts.description }),\n });\n } catch (err) {\n const msg = err instanceof MetadataLoadError ? err.message : (err instanceof Error ? err.message : String(err));\n process.stderr.write(`Error: ${msg}\\n`);\n process.exit(1);\n }\n\n await fs.writeFile(outPath, markdown, 'utf-8');\n process.stdout.write(`✓ Written to ${path.relative(process.cwd(), outPath)}\\n`);\n}\n\nconst program = new Command()\n .name('mikro-orm-markdown')\n .description('Generate Mermaid ERD + markdown docs from MikroORM entities')\n .requiredOption('-c, --config <path>', 'MikroORM config file path')\n .option('-o, --out <path>', 'Output markdown file path', './ERD.md')\n .option('-t, --title <string>', 'Document title', 'Database Schema')\n .option('-d, --description <string>', 'Optional description paragraph shown below the title')\n .option(\n '-s, --src <glob>',\n 'Glob pattern for entity source files, repeatable (for JSDoc extraction)',\n (val: string, prev: string[]) => [...prev, val],\n [] as string[],\n )\n .action(run);\n\nprogram.parseAsync(process.argv).catch((err: unknown) => {\n process.stderr.write(`${err instanceof Error ? err.message : String(err)}\\n`);\n process.exit(1);\n});\n","import type { JSDoc } from 'ts-morph';\nimport { Project } from 'ts-morph';\n\n/** JSDoc information extracted from an entity class. */\nexport interface EntityJsDocInfo {\n /** Class-level description (text before any @tags). */\n description?: string;\n /** Namespaces from @namespace tags — appears in both ERD and text table. */\n namespaces: string[];\n /** Namespaces from @erd tags — appears in ERD only. */\n erdNamespaces: string[];\n /** Namespaces from @describe tags — appears in text table only. */\n describeNamespaces: string[];\n /** True when @hidden tag is present — entity is excluded from all output. */\n hidden: boolean;\n}\n\n/** JSDoc information extracted from a single entity property. */\nexport interface PropJsDocInfo {\n /** Property description text. */\n description?: string;\n}\n\n/** Keyed by entity class name. */\nexport type EntityJsDocMap = Map<string, EntityJsDocInfo>;\n\n/** Outer key: entity class name. Inner key: property name. */\nexport type PropJsDocMap = Map<string, Map<string, PropJsDocInfo>>;\n\nexport interface JsDocResult {\n entities: EntityJsDocMap;\n props: PropJsDocMap;\n}\n\n/**\n * Parses TypeScript source files matched by the provided globs and extracts\n * JSDoc descriptions and custom tags (@namespace, @erd, @describe, @hidden)\n * from entity classes and their properties.\n *\n * Returns empty maps if no source files are matched or no JSDoc is found.\n * Never throws — errors are silently ignored so missing docs don't block generation.\n */\nexport function loadJsDoc(srcGlobs: string[]): JsDocResult {\n const entities: EntityJsDocMap = new Map();\n const props: PropJsDocMap = new Map();\n\n if (srcGlobs.length === 0) return { entities, props };\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n skipLoadingLibFiles: true,\n compilerOptions: {\n experimentalDecorators: true,\n skipLibCheck: true,\n },\n });\n\n project.addSourceFilesAtPaths(srcGlobs);\n\n for (const sourceFile of project.getSourceFiles()) {\n for (const cls of sourceFile.getClasses()) {\n const className = cls.getName();\n if (!className) continue;\n\n const classDocs = cls.getJsDocs();\n if (classDocs.length > 0) {\n entities.set(className, parseEntityJsDoc(classDocs));\n }\n\n const propMap = new Map<string, PropJsDocInfo>();\n for (const prop of cls.getProperties()) {\n const propDocs = prop.getJsDocs();\n if (propDocs.length === 0) continue;\n const desc = extractDescription(propDocs);\n if (desc !== undefined) {\n propMap.set(prop.getName(), { description: desc });\n }\n }\n if (propMap.size > 0) {\n props.set(className, propMap);\n }\n }\n }\n\n return { entities, props };\n}\n\nfunction parseEntityJsDoc(jsDocs: JSDoc[]): EntityJsDocInfo {\n const namespaces: string[] = [];\n const erdNamespaces: string[] = [];\n const describeNamespaces: string[] = [];\n let hidden = false;\n let description: string | undefined;\n\n for (const doc of jsDocs) {\n const desc = doc.getDescription().trim();\n if (desc && description === undefined) description = desc;\n\n for (const tag of doc.getTags()) {\n const tagName = tag.getTagName();\n const comment = tag.getCommentText()?.trim();\n\n if (tagName === 'namespace' && comment) namespaces.push(comment);\n else if (tagName === 'erd' && comment) erdNamespaces.push(comment);\n else if (tagName === 'describe' && comment) describeNamespaces.push(comment);\n else if (tagName === 'hidden') hidden = true;\n }\n }\n\n return {\n ...(description !== undefined && { description }),\n namespaces,\n erdNamespaces,\n describeNamespaces,\n hidden,\n };\n}\n\nfunction extractDescription(jsDocs: JSDoc[]): string | undefined {\n for (const doc of jsDocs) {\n const desc = doc.getDescription().trim();\n if (desc) return desc;\n }\n return undefined;\n}\n","import { MikroORM } from '@mikro-orm/core';\nimport type { EntityMetadata, Options } from '@mikro-orm/core';\n\n/** Errors thrown during metadata loading */\nexport class MetadataLoadError extends Error {\n constructor(\n message: string,\n public override readonly cause?: unknown,\n ) {\n super(message);\n this.name = 'MetadataLoadError';\n }\n}\n\n/**\n * Runs MikroORM entity discovery without connecting to the database,\n * and returns all discovered EntityMetadata objects.\n *\n * The caller is responsible for filtering (e.g. excluding abstract,\n * embeddable, or pivot entities) based on rendering needs.\n */\nexport async function loadEntityMetadata(options: Options): Promise<EntityMetadata[]> {\n let orm: MikroORM | undefined;\n\n try {\n orm = await MikroORM.init({\n ...options,\n debug: false,\n });\n } catch (cause) {\n throw new MetadataLoadError(\n 'Failed to initialize MikroORM and run entity discovery. ' +\n 'Make sure your config is valid and all entity files are accessible.',\n cause,\n );\n }\n\n try {\n const all = Object.values(orm.getMetadata().getAll());\n\n if (all.length === 0) {\n throw new MetadataLoadError(\n 'No entities were discovered. ' +\n 'Check that your config specifies at least one entity path or class.',\n );\n }\n\n return all;\n } finally {\n await orm.close(true);\n }\n}\n","import { ReferenceKind } from '@mikro-orm/core';\nimport type { EntityMetadata, EntityProperty, FormulaTable } from '@mikro-orm/core';\nimport type {\n ColumnModel,\n ConstraintModel,\n DiagramModel,\n EntityModel,\n RelationEdge,\n} from '../model/types.js';\n\n// Dummy table descriptor used when resolving formula expressions for documentation.\n// String-based formulas ignore both arguments; function-based formulas use the alias.\nconst FORMULA_DUMMY_TABLE: FormulaTable = {\n alias: 'e0',\n name: '',\n qualifiedName: '',\n toString: () => 'e0',\n};\n\n/**\n * Converts raw MikroORM EntityMetadata array into a DiagramModel.\n *\n * Excluded from entity boxes:\n * - Pivot tables (auto-generated M:N join tables) — represented as edges\n * - @Embeddable classes — their columns appear inline inside the owning entity\n */\nexport function buildDiagramModel(metas: EntityMetadata[]): DiagramModel {\n const metaByClass = new Map(metas.map((m) => [m.className, m]));\n\n const entities: EntityModel[] = metas\n .filter((meta) => !meta.pivotTable && !meta.embeddable)\n .map((meta) => buildEntityModel(meta, metaByClass));\n\n const relations: RelationEdge[] = buildRelationEdges(metas);\n\n return { entities, relations };\n}\n\nfunction buildEntityModel(\n meta: EntityMetadata,\n metaByClass: Map<string, EntityMetadata>,\n): EntityModel {\n // STI root: has discriminatorColumn, no discriminatorValue of its own.\n // Its properties list includes all child-only columns (marked inherited=true) — filter them out.\n const isStiRoot = meta.discriminatorColumn !== undefined && !meta.discriminatorValue;\n const isStiChild = Boolean(meta.extends) && meta.discriminatorValue !== undefined;\n\n const columns: ColumnModel[] = [];\n for (const prop of Object.values(meta.properties)) {\n if (isStiRoot && prop.inherited === true) continue;\n const col = buildColumn(prop, metaByClass, meta);\n if (col !== null) columns.push(col);\n }\n\n return {\n className: meta.className,\n tableName: meta.tableName,\n columns,\n isPivot: false,\n isEmbeddable: meta.embeddable === true,\n ...(isStiRoot && { discriminatorColumn: meta.discriminatorColumn as string }),\n ...(isStiChild && { extendsEntity: meta.extends }),\n constraints: buildConstraints(meta),\n };\n}\n\n/** Returns a ColumnModel for renderable properties, or null to skip. */\nfunction buildColumn(\n prop: EntityProperty,\n metaByClass: Map<string, EntityMetadata>,\n owningMeta: EntityMetadata,\n): ColumnModel | null {\n // Skip the EMBEDDED group reference — individual flat columns appear as SCALAR entries\n if (prop.kind === ReferenceKind.EMBEDDED) return null;\n\n if (prop.kind === ReferenceKind.SCALAR) {\n // For @Formula columns, formula is set on a SCALAR-kinded property\n const formulaExpr: string | undefined = prop.formula !== undefined\n ? resolveFormulaExpr(prop.formula as (table: FormulaTable, cols: Record<string, string>) => string)\n : undefined;\n\n // Flat embedded columns carry `embedded: [ownerPropName, embeddedPropName]`\n let embeddedIn: string | undefined;\n if (prop.embedded !== undefined) {\n const parentPropName = prop.embedded[0];\n embeddedIn = owningMeta.properties[parentPropName]?.type;\n }\n\n const isDiscriminator =\n owningMeta.discriminatorColumn !== undefined &&\n prop.name === owningMeta.discriminatorColumn;\n\n return {\n propName: prop.name,\n fieldName: prop.fieldNames?.[0] ?? prop.name,\n type: normalizeType(prop.type),\n isPrimary: prop.primary === true,\n isForeignKey: false,\n isUnique: prop.unique === true,\n isNullable: prop.nullable === true,\n ...(formulaExpr !== undefined && { formula: formulaExpr }),\n ...(embeddedIn !== undefined && { embeddedIn }),\n ...(isDiscriminator && { isDiscriminator: true }),\n };\n }\n\n // FK columns: m:1 always owns the FK; 1:1 only when owner === true\n if (\n prop.kind === ReferenceKind.MANY_TO_ONE ||\n (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner === true)\n ) {\n const fkType = resolveFkType(prop.type, metaByClass);\n return {\n propName: prop.name,\n fieldName: prop.fieldNames?.[0] ?? `${prop.name}_id`,\n type: fkType,\n isPrimary: false,\n isForeignKey: true,\n isUnique: prop.unique === true,\n isNullable: prop.nullable === true,\n };\n }\n\n // ONE_TO_MANY, MANY_TO_MANY (both owner and inverse) → no physical column\n return null;\n}\n\n/**\n * Calls the FormulaCallback with a dummy table and column proxy to extract the SQL expression.\n * String-based formulas (most common) ignore their arguments and return the literal string.\n * Function-based formulas use the alias/column names from the dummy objects.\n * Returns empty string on unexpected errors.\n */\nfunction resolveFormulaExpr(\n cb: (table: FormulaTable, cols: Record<string, string>) => string,\n): string {\n try {\n const cols = new Proxy({}, {\n get: (_target, key: string | symbol) => (typeof key === 'string' ? key : ''),\n });\n return cb(FORMULA_DUMMY_TABLE, cols);\n } catch {\n return '';\n }\n}\n\n/** Looks up the PK type of the referenced entity to use as FK column type. */\nfunction resolveFkType(\n referencedClassName: string,\n metaByClass: Map<string, EntityMetadata>,\n): string {\n const refMeta = metaByClass.get(referencedClassName);\n if (!refMeta) return 'integer';\n const pkProp = Object.values(refMeta.properties).find((p) => p.primary === true);\n return pkProp ? normalizeType(pkProp.type) : 'integer';\n}\n\n/** Collects indexes, unique constraints, and check constraints from entity-level metadata. */\nfunction buildConstraints(meta: EntityMetadata): ConstraintModel[] {\n const result: ConstraintModel[] = [];\n\n for (const idx of meta.indexes ?? []) {\n const props = idx.properties;\n result.push({\n type: 'index',\n properties: Array.isArray(props) ? props.map(String) : props ? [String(props)] : [],\n ...(idx.name !== undefined && { name: idx.name }),\n });\n }\n\n for (const uniq of meta.uniques ?? []) {\n const props = uniq.properties;\n result.push({\n type: 'unique',\n properties: Array.isArray(props) ? props.map(String) : props ? [String(props)] : [],\n ...(uniq.name !== undefined && { name: uniq.name }),\n });\n }\n\n for (const check of meta.checks ?? []) {\n // Skip function-based check expressions (they require column reference objects at runtime)\n if (typeof check.expression !== 'string') continue;\n result.push({\n type: 'check',\n properties: [],\n expression: check.expression,\n ...(check.name !== undefined && { name: check.name }),\n });\n }\n\n return result;\n}\n\n/** Builds edges only from owning sides to avoid duplicate arrows. Includes STI inheritance. */\nfunction buildRelationEdges(metas: EntityMetadata[]): RelationEdge[] {\n const edges: RelationEdge[] = [];\n\n for (const meta of metas) {\n if (meta.pivotTable || meta.embeddable) continue;\n\n for (const prop of Object.values(meta.properties)) {\n const edge = buildEdge(meta.className, prop);\n if (edge !== null) edges.push(edge);\n }\n\n }\n\n return edges;\n}\n\nfunction buildEdge(fromEntity: string, prop: EntityProperty): RelationEdge | null {\n const isNullable = prop.nullable === true;\n\n if (prop.kind === ReferenceKind.MANY_TO_ONE) {\n return {\n fromEntity,\n toEntity: prop.type,\n fromCardinality: '}o',\n toCardinality: isNullable ? 'o|' : '||',\n label: prop.name,\n };\n }\n\n if (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner === true) {\n return {\n fromEntity,\n toEntity: prop.type,\n fromCardinality: '||',\n toCardinality: isNullable ? 'o|' : '||',\n label: prop.name,\n };\n }\n\n if (prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner === true) {\n return {\n fromEntity,\n toEntity: prop.type,\n fromCardinality: '}o',\n toCardinality: 'o{',\n label: prop.name,\n };\n }\n\n return null;\n}\n\n/**\n * Renders a DiagramModel as a Mermaid erDiagram block string.\n * The returned string starts with \"erDiagram\" and is ready to embed in a\n * markdown code fence.\n */\nexport function renderErDiagram(model: DiagramModel): string {\n const lines: string[] = ['erDiagram'];\n\n for (const entity of model.entities) {\n lines.push(` ${entity.className} {`);\n for (const col of entity.columns) {\n lines.push(` ${renderColumnLine(col)}`);\n }\n lines.push(' }');\n }\n\n for (const rel of model.relations) {\n lines.push(\n ` ${rel.fromEntity} ${rel.fromCardinality}--${rel.toCardinality} ${rel.toEntity} : \"${rel.label}\"`,\n );\n }\n\n return lines.join('\\n');\n}\n\nfunction renderColumnLine(col: ColumnModel): string {\n // Priority: PK > FK > UK\n let qualifier = '';\n if (col.isPrimary) qualifier = ' PK';\n else if (col.isForeignKey) qualifier = ' FK';\n else if (col.isUnique) qualifier = ' UK';\n\n // Comment priority (v1 differentiators over prisma-markdown):\n // 1. @Formula SQL expression — \"formula: LENGTH(name)\"\n // 2. STI discriminator column — \"discriminator\"\n // 3. Embedded source type — \"[Address]\"\n // 4. DB/TS name mismatch — \"<tsPropName>\"\n let comment: string | undefined;\n if (col.formula !== undefined) {\n comment = col.formula ? `formula: ${col.formula}` : 'formula';\n } else if (col.isDiscriminator) {\n comment = 'discriminator';\n } else if (col.embeddedIn !== undefined) {\n comment = `[${col.embeddedIn}]`;\n } else if (col.fieldName !== col.propName) {\n comment = col.propName;\n }\n\n const commentStr = comment !== undefined ? ` \"${comment}\"` : '';\n return `${col.type} ${col.fieldName}${qualifier}${commentStr}`;\n}\n\n/** Strips characters that are invalid in Mermaid type identifiers. */\nfunction normalizeType(type: string): string {\n return type.replace(/[^a-zA-Z0-9_]/g, '_');\n}\n","import type { EntityMetadata } from '@mikro-orm/core';\nimport type { EntityJsDocInfo, JsDocResult, PropJsDocInfo } from '../docs/jsdoc.js';\nimport type { EntityModel, RelationEdge } from './types.js';\nimport { buildDiagramModel } from '../render/mermaid.js';\n\n/** An entity with its structural model and JSDoc info merged together. */\nexport interface EnrichedEntity {\n model: EntityModel;\n /** Undefined if the entity has no class-level JSDoc. */\n jsDoc: EntityJsDocInfo | undefined;\n /** Per-property description map (empty map if no property JSDoc). */\n propDocs: Map<string, PropJsDocInfo>;\n}\n\n/**\n * A single namespace group, ready to render as one section of the document.\n *\n * - `erdEntities`: shown in the Mermaid ERD block (@namespace + @erd)\n * - `textEntities`: shown in the column-table sections (@namespace + @describe)\n * - `erdRelations`: relation edges where both endpoints are in `erdEntities`\n */\nexport interface NamespaceGroup {\n name: string;\n erdEntities: EnrichedEntity[];\n textEntities: EnrichedEntity[];\n erdRelations: RelationEdge[];\n}\n\n/** Complete document model — input to the markdown renderer. */\nexport interface DocumentModel {\n title: string;\n /** Optional paragraph rendered below the H1 heading. */\n description?: string;\n groups: NamespaceGroup[];\n}\n\n/**\n * Merges MikroORM structural metadata with JSDoc information and organises the\n * result into namespace groups for rendering.\n *\n * Entities with @hidden are excluded.\n * Entities with no namespace tags fall into the \"default\" group.\n * Groups are ordered alphabetically, with \"default\" always last.\n */\nexport function buildDocumentModel(\n metas: EntityMetadata[],\n jsDocResult: JsDocResult,\n title: string,\n description?: string,\n): DocumentModel {\n const { entities: diagramEntities, relations: allRelations } = buildDiagramModel(metas);\n\n // Build enriched entity map, filtering out @hidden entities.\n const enrichedByClass = new Map<string, EnrichedEntity>();\n for (const model of diagramEntities) {\n const jsDoc = jsDocResult.entities.get(model.className);\n if (jsDoc?.hidden) continue;\n const propDocs = jsDocResult.props.get(model.className) ?? new Map<string, PropJsDocInfo>();\n enrichedByClass.set(model.className, { model, jsDoc, propDocs });\n }\n\n // Collect all unique namespace names referenced by any entity.\n const groupNames = new Set<string>();\n let anyUntagged = false;\n for (const { jsDoc } of enrichedByClass.values()) {\n const allNs = [\n ...(jsDoc?.namespaces ?? []),\n ...(jsDoc?.erdNamespaces ?? []),\n ...(jsDoc?.describeNamespaces ?? []),\n ];\n if (allNs.length === 0) {\n anyUntagged = true;\n } else {\n for (const ns of allNs) groupNames.add(ns);\n }\n }\n if (anyUntagged) groupNames.add('default');\n\n const groups: NamespaceGroup[] = [];\n for (const groupName of groupNames) {\n const isDefault = groupName === 'default';\n\n const erdEntities = [...enrichedByClass.values()].filter(({ jsDoc }) =>\n belongsToGroupForErd(jsDoc, groupName, isDefault),\n );\n\n const textEntities = [...enrichedByClass.values()].filter(({ jsDoc }) =>\n belongsToGroupForText(jsDoc, groupName, isDefault),\n );\n\n const erdClassNames = new Set(erdEntities.map((e) => e.model.className));\n const erdRelations = allRelations.filter(\n (r) => erdClassNames.has(r.fromEntity) && erdClassNames.has(r.toEntity),\n );\n\n groups.push({ name: groupName, erdEntities, textEntities, erdRelations });\n }\n\n // Sort alphabetically; \"default\" is always last.\n groups.sort((a, b) => {\n if (a.name === 'default') return 1;\n if (b.name === 'default') return -1;\n return a.name.localeCompare(b.name);\n });\n\n return { title, groups, ...(description !== undefined && { description }) };\n}\n\nfunction hasNoNamespaceTags(jsDoc: EntityJsDocInfo | undefined): boolean {\n if (!jsDoc) return true;\n return (\n jsDoc.namespaces.length === 0 &&\n jsDoc.erdNamespaces.length === 0 &&\n jsDoc.describeNamespaces.length === 0\n );\n}\n\nfunction belongsToGroupForErd(\n jsDoc: EntityJsDocInfo | undefined,\n groupName: string,\n isDefault: boolean,\n): boolean {\n if (isDefault) return hasNoNamespaceTags(jsDoc);\n if (!jsDoc) return false;\n return jsDoc.namespaces.includes(groupName) || jsDoc.erdNamespaces.includes(groupName);\n}\n\nfunction belongsToGroupForText(\n jsDoc: EntityJsDocInfo | undefined,\n groupName: string,\n isDefault: boolean,\n): boolean {\n if (isDefault) return hasNoNamespaceTags(jsDoc);\n if (!jsDoc) return false;\n return jsDoc.namespaces.includes(groupName) || jsDoc.describeNamespaces.includes(groupName);\n}\n","import type { EnrichedEntity, DocumentModel, NamespaceGroup } from '../model/build.js';\nimport type { ColumnModel, ConstraintModel, DiagramModel } from '../model/types.js';\nimport { renderErDiagram } from './mermaid.js';\n\n/**\n * Renders a DocumentModel as a markdown string.\n * Each namespace group becomes a level-2 section with a Mermaid ERD block\n * followed by per-entity column tables.\n */\nexport function renderMarkdown(docModel: DocumentModel): string {\n const sections: string[] = [`# ${docModel.title}`];\n\n if (docModel.description) {\n sections.push(docModel.description);\n }\n\n for (const group of docModel.groups) {\n sections.push(renderGroupSection(group));\n }\n\n return sections.join('\\n\\n');\n}\n\nfunction renderGroupSection(group: NamespaceGroup): string {\n const parts: string[] = [`## ${group.name}`];\n\n if (group.erdEntities.length > 0) {\n const diagramModel: DiagramModel = {\n entities: group.erdEntities.map((e) => e.model),\n relations: group.erdRelations,\n };\n parts.push('```mermaid\\n' + renderErDiagram(diagramModel) + '\\n```');\n }\n\n for (const entity of group.textEntities) {\n parts.push(renderEntitySection(entity));\n }\n\n return parts.join('\\n\\n');\n}\n\nfunction renderEntitySection(entity: EnrichedEntity): string {\n const parts: string[] = [`### ${entity.model.className}`];\n\n if (entity.jsDoc?.description) {\n parts.push(`> ${entity.jsDoc.description}`);\n }\n\n // STI metadata note\n if (entity.model.discriminatorColumn) {\n parts.push(\n `*STI root — discriminator column: \\`${entity.model.discriminatorColumn}\\`*`,\n );\n } else if (entity.model.extendsEntity) {\n parts.push(`*Extends \\`${entity.model.extendsEntity}\\` (Single Table Inheritance)*`);\n }\n\n if (entity.model.columns.length > 0) {\n parts.push(renderColumnTable(entity));\n }\n\n if (entity.model.constraints.length > 0) {\n parts.push(renderConstraints(entity.model.constraints));\n }\n\n return parts.join('\\n\\n');\n}\n\nfunction renderColumnTable(entity: EnrichedEntity): string {\n const header = '| Column | Type | Key | Nullable | Description |';\n const sep = '|--------|------|-----|----------|-------------|';\n const rows = entity.model.columns.map((col) => {\n const key = resolveColumnKey(col);\n const nullable = col.isNullable && !col.isPrimary ? 'Y' : '';\n const desc = entity.propDocs.get(col.propName)?.description ?? '';\n return `| ${col.fieldName} | ${col.type} | ${key} | ${nullable} | ${desc} |`;\n });\n return [header, sep, ...rows].join('\\n');\n}\n\n/** Returns the \"Key\" cell value for the column table. */\nfunction resolveColumnKey(col: ColumnModel): string {\n if (col.isPrimary) return 'PK';\n if (col.isForeignKey) {\n // Show TS property name in parentheses if it differs from the DB column name\n return col.fieldName !== col.propName ? `FK (${col.propName})` : 'FK';\n }\n if (col.isUnique) return 'UK';\n if (col.formula !== undefined) return `formula: ${col.formula}`;\n if (col.isDiscriminator) return 'discriminator';\n if (col.embeddedIn !== undefined) return `[${col.embeddedIn}]`;\n return '';\n}\n\n\nfunction renderConstraints(constraints: ConstraintModel[]): string {\n const lines = ['**Constraints:**', ''];\n for (const c of constraints) {\n const name = c.name ? ` \\`${c.name}\\`` : '';\n if (c.type === 'index') {\n lines.push(`- Index${name}: (${c.properties.join(', ')})`);\n } else if (c.type === 'unique') {\n lines.push(`- Unique${name}: (${c.properties.join(', ')})`);\n } else if (c.type === 'check') {\n lines.push(`- Check${name}: \\`${c.expression ?? ''}\\``);\n }\n }\n return lines.join('\\n');\n}\n","import type { Options } from '@mikro-orm/core';\nimport { loadJsDoc } from './docs/jsdoc.js';\nimport { loadEntityMetadata } from './metadata/load.js';\nimport { buildDocumentModel } from './model/build.js';\nimport { renderMarkdown } from './render/markdown.js';\n\nexport type { GenerateOptions } from './model/types.js';\nexport { MetadataLoadError } from './metadata/load.js';\n\n/** Options for the programmatic API. */\nexport interface GenerateMarkdownOptions {\n /** MikroORM configuration (driver, entities, dbName, …). */\n orm: Options;\n /** Title shown as the H1 heading in the generated document. */\n title?: string;\n /** Optional description paragraph rendered below the H1 heading. */\n description?: string;\n /**\n * Glob patterns for TypeScript entity source files.\n * Used for JSDoc extraction (@namespace, @hidden, descriptions).\n * Omit to skip JSDoc parsing — all entities go into the \"default\" section.\n */\n src?: string[];\n}\n\n/**\n * Generates a Mermaid ERD + markdown documentation document from MikroORM\n * entity metadata.\n *\n * @example\n * ```ts\n * import { generateMarkdown } from 'mikro-orm-markdown';\n * import ormConfig from './mikro-orm.config.js';\n *\n * const markdown = await generateMarkdown({\n * orm: ormConfig,\n * title: 'My Database',\n * src: ['src/entities/*.ts'],\n * });\n * ```\n */\nexport async function generateMarkdown(options: GenerateMarkdownOptions): Promise<string> {\n const { orm, title = 'Database Schema', description, src = [] } = options;\n\n const metas = await loadEntityMetadata(orm);\n const jsDocResult = loadJsDoc(src);\n const docModel = buildDocumentModel(metas, jsDocResult, title, description);\n return renderMarkdown(docModel);\n}\n"],"mappings":";;;AAEA,YAAY,QAAQ;AACpB,YAAY,UAAU;AAEtB,SAAS,eAAe;;;ACJxB,SAAS,eAAe;AAyCjB,SAAS,UAAU,UAAiC;AACzD,QAAM,WAA2B,oBAAI,IAAI;AACzC,QAAM,QAAsB,oBAAI,IAAI;AAEpC,MAAI,SAAS,WAAW,EAAG,QAAO,EAAE,UAAU,MAAM;AAEpD,QAAM,UAAU,IAAI,QAAQ;AAAA,IAC1B,6BAA6B;AAAA,IAC7B,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,MACf,wBAAwB;AAAA,MACxB,cAAc;AAAA,IAChB;AAAA,EACF,CAAC;AAED,UAAQ,sBAAsB,QAAQ;AAEtC,aAAW,cAAc,QAAQ,eAAe,GAAG;AACjD,eAAW,OAAO,WAAW,WAAW,GAAG;AACzC,YAAM,YAAY,IAAI,QAAQ;AAC9B,UAAI,CAAC,UAAW;AAEhB,YAAM,YAAY,IAAI,UAAU;AAChC,UAAI,UAAU,SAAS,GAAG;AACxB,iBAAS,IAAI,WAAW,iBAAiB,SAAS,CAAC;AAAA,MACrD;AAEA,YAAM,UAAU,oBAAI,IAA2B;AAC/C,iBAAW,QAAQ,IAAI,cAAc,GAAG;AACtC,cAAM,WAAW,KAAK,UAAU;AAChC,YAAI,SAAS,WAAW,EAAG;AAC3B,cAAM,OAAO,mBAAmB,QAAQ;AACxC,YAAI,SAAS,QAAW;AACtB,kBAAQ,IAAI,KAAK,QAAQ,GAAG,EAAE,aAAa,KAAK,CAAC;AAAA,QACnD;AAAA,MACF;AACA,UAAI,QAAQ,OAAO,GAAG;AACpB,cAAM,IAAI,WAAW,OAAO;AAAA,MAC9B;AAAA,IACF;AA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c.ts","../src/metadata/load.ts","../src/render/mermaid.ts","../src/model/build.ts","../src/render/markdown.ts","../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport type { Options } from '@mikro-orm/core';\nimport { Command } from 'commander';\nimport { generateMarkdown, MetadataLoadError } from './index.js';\n\ninterface CliOptions {\n config: string;\n out: string;\n title: string;\n description?: string;\n src?: string[];\n}\n\nasync function run(opts: CliOptions): Promise<void> {\n const configPath = path.resolve(opts.config);\n const outPath = path.resolve(opts.out);\n\n let ormOptions: Options;\n try {\n const mod = (await import(configPath)) as { default?: unknown };\n ormOptions = mod.default ?? mod;\n } catch (err) {\n const hint = configPath.endsWith('.ts')\n ? '\\nHint: TypeScript configs require tsx or ts-node:\\n npx tsx ./node_modules/.bin/mikro-orm-markdown ...'\n : '';\n process.stderr.write(\n `Error: Cannot load config: ${configPath}\\n${err instanceof Error ? err.message : String(err)}${hint}\\n`\n );\n process.exit(1);\n }\n\n let markdown: string;\n try {\n markdown = await generateMarkdown({\n orm: ormOptions,\n title: opts.title,\n src: opts.src ?? [],\n ...(opts.description !== undefined && { description: opts.description }),\n });\n } catch (err) {\n const msg = err instanceof MetadataLoadError ? err.message : err instanceof Error ? err.message : String(err);\n process.stderr.write(`Error: ${msg}\\n`);\n process.exit(1);\n }\n\n await fs.writeFile(outPath, markdown, 'utf-8');\n process.stdout.write(`✓ Written to ${path.relative(process.cwd(), outPath)}\\n`);\n}\n\nconst program = new Command()\n .name('mikro-orm-markdown')\n .description('Generate Mermaid ERD + markdown docs from MikroORM entities')\n .requiredOption('-c, --config <path>', 'MikroORM config file path')\n .option('-o, --out <path>', 'Output markdown file path', './ERD.md')\n .option('-t, --title <string>', 'Document title', 'Database Schema')\n .option('-d, --description <string>', 'Optional description paragraph shown below the title')\n .option('-s, --src <glob>', 'JSDoc source glob (repeatable)', (val: string, prev: string[] = []) => [...prev, val])\n .action(run);\n\nprogram.parseAsync(process.argv).catch((err: unknown) => {\n process.stderr.write(`${err instanceof Error ? err.message : String(err)}\\n`);\n process.exit(1);\n});\n","import type { JSDoc } from 'ts-morph';\nimport { Project } from 'ts-morph';\n\n/** JSDoc information extracted from an entity class. */\nexport interface EntityJsDocInfo {\n /** Class-level description (text before any @tags). */\n description?: string;\n /** Namespaces from @namespace tags — appears in both ERD and text table. */\n namespaces: string[];\n /** Namespaces from @erd tags — appears in ERD only. */\n erdNamespaces: string[];\n /** Namespaces from @describe tags — appears in text table only. */\n describeNamespaces: string[];\n /** True when @hidden tag is present — entity is excluded from all output. */\n hidden: boolean;\n}\n\n/** JSDoc information extracted from a single entity property. */\nexport interface PropJsDocInfo {\n /** Property description text. */\n description?: string;\n}\n\n/** Keyed by entity class name. */\nexport type EntityJsDocMap = Map<string, EntityJsDocInfo>;\n\n/** Outer key: entity class name. Inner key: property name. */\nexport type PropJsDocMap = Map<string, Map<string, PropJsDocInfo>>;\n\nexport interface JsDocResult {\n entities: EntityJsDocMap;\n props: PropJsDocMap;\n}\n\n/**\n * Parses TypeScript source files matched by the provided globs and extracts\n * JSDoc descriptions and custom tags (@namespace, @erd, @describe, @hidden)\n * from entity classes and their properties.\n *\n * Returns empty maps if no source files are matched or no JSDoc is found.\n * Never throws — errors are silently ignored so missing docs don't block generation.\n */\nexport function loadJsDoc(srcGlobs: string[]): JsDocResult {\n const entities: EntityJsDocMap = new Map();\n const props: PropJsDocMap = new Map();\n\n if (srcGlobs.length === 0) {\n return { entities, props };\n }\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n skipLoadingLibFiles: true,\n compilerOptions: {\n experimentalDecorators: true,\n skipLibCheck: true,\n },\n });\n\n project.addSourceFilesAtPaths(srcGlobs);\n\n for (const sourceFile of project.getSourceFiles()) {\n for (const cls of sourceFile.getClasses()) {\n const className = cls.getName();\n if (!className) {\n continue;\n }\n\n const classDocs = cls.getJsDocs();\n if (classDocs.length > 0) {\n entities.set(className, parseEntityJsDoc(classDocs));\n }\n\n const propMap = new Map<string, PropJsDocInfo>();\n for (const prop of cls.getProperties()) {\n const propDocs = prop.getJsDocs();\n if (propDocs.length === 0) {\n continue;\n }\n const desc = extractDescription(propDocs);\n if (desc !== undefined) {\n propMap.set(prop.getName(), { description: desc });\n }\n }\n if (propMap.size > 0) {\n props.set(className, propMap);\n }\n }\n }\n\n return { entities, props };\n}\n\nfunction parseEntityJsDoc(jsDocs: JSDoc[]): EntityJsDocInfo {\n const namespaces: string[] = [];\n const erdNamespaces: string[] = [];\n const describeNamespaces: string[] = [];\n let hidden = false;\n let description: string | undefined;\n\n for (const doc of jsDocs) {\n const desc = doc.getDescription().trim();\n if (desc && description === undefined) {\n description = desc;\n }\n\n for (const tag of doc.getTags()) {\n const tagName = tag.getTagName();\n const comment = tag.getCommentText()?.trim();\n\n if (tagName === 'namespace' && comment) {\n namespaces.push(comment);\n } else if (tagName === 'erd' && comment) {\n erdNamespaces.push(comment);\n } else if (tagName === 'describe' && comment) {\n describeNamespaces.push(comment);\n } else if (tagName === 'hidden') {\n hidden = true;\n }\n }\n }\n\n return {\n ...(description !== undefined && { description }),\n namespaces,\n erdNamespaces,\n describeNamespaces,\n hidden,\n };\n}\n\nfunction extractDescription(jsDocs: JSDoc[]): string | undefined {\n for (const doc of jsDocs) {\n const desc = doc.getDescription().trim();\n if (desc) {\n return desc;\n }\n }\n return undefined;\n}\n","import type { EntityMetadata, Options } from '@mikro-orm/core';\nimport { MikroORM } from '@mikro-orm/core';\n\n/** Errors thrown during metadata loading */\nexport class MetadataLoadError extends Error {\n constructor(\n message: string,\n public override readonly cause?: unknown\n ) {\n super(message);\n this.name = 'MetadataLoadError';\n }\n}\n\n/**\n * Runs MikroORM entity discovery without connecting to the database,\n * and returns all discovered EntityMetadata objects.\n *\n * The caller is responsible for filtering (e.g. excluding abstract,\n * embeddable, or pivot entities) based on rendering needs.\n */\nexport async function loadEntityMetadata(options: Options): Promise<EntityMetadata[]> {\n let orm: MikroORM;\n try {\n orm = await MikroORM.init({\n ...options,\n debug: false,\n connect: false,\n });\n } catch (cause) {\n throw new MetadataLoadError(\n 'Failed to initialize MikroORM and run entity discovery. ' +\n 'Make sure your config is valid and all entity files are accessible.',\n cause\n );\n }\n\n const all = Object.values(orm.getMetadata().getAll());\n\n if (all.length === 0) {\n throw new MetadataLoadError(\n 'No entities were discovered. ' + 'Check that your config specifies at least one entity path or class.'\n );\n }\n\n return all;\n}\n","import type { EntityMetadata, EntityProperty, FormulaTable } from '@mikro-orm/core';\nimport { ReferenceKind } from '@mikro-orm/core';\nimport type { ColumnModel, ConstraintModel, DiagramModel, EntityModel, RelationEdge } from '../model/types.js';\n\n// Dummy table descriptor used when resolving formula expressions for documentation.\n// String-based formulas ignore both arguments; function-based formulas use the alias.\nconst FORMULA_DUMMY_TABLE: FormulaTable = {\n alias: 'e0',\n name: '',\n qualifiedName: '',\n toString: () => 'e0',\n};\n\n/**\n * Converts raw MikroORM EntityMetadata array into a DiagramModel.\n *\n * Excluded from entity boxes:\n * - Pivot tables (auto-generated M:N join tables) — represented as edges\n * - @Embeddable classes — their columns appear inline inside the owning entity\n */\nexport function buildDiagramModel(metas: EntityMetadata[]): DiagramModel {\n const metaByClass = new Map(metas.map((m) => [m.className, m]));\n\n const entities: EntityModel[] = metas\n .filter((meta) => !meta.pivotTable && !meta.embeddable)\n .map((meta) => buildEntityModel(meta, metaByClass));\n\n const relations: RelationEdge[] = buildRelationEdges(metas);\n\n return { entities, relations };\n}\n\nfunction buildEntityModel(meta: EntityMetadata, metaByClass: Map<string, EntityMetadata>): EntityModel {\n // STI root: has discriminatorColumn, no discriminatorValue of its own.\n // Its properties list includes all child-only columns (marked inherited=true) — filter them out.\n const isStiRoot = meta.discriminatorColumn !== undefined && !meta.discriminatorValue;\n const isStiChild = Boolean(meta.extends) && meta.discriminatorValue !== undefined;\n\n const columns: ColumnModel[] = [];\n for (const prop of Object.values(meta.properties)) {\n if (isStiRoot && prop.inherited === true) {\n continue;\n }\n const col = buildColumn(prop, metaByClass, meta);\n if (col !== null) {\n columns.push(col);\n }\n }\n\n return {\n className: meta.className,\n tableName: meta.tableName,\n columns,\n isPivot: false,\n isEmbeddable: meta.embeddable === true,\n ...(isStiRoot && { discriminatorColumn: meta.discriminatorColumn as string }),\n ...(isStiChild && { extendsEntity: meta.extends }),\n constraints: buildConstraints(meta),\n };\n}\n\n/** Returns a ColumnModel for renderable properties, or null to skip. */\nfunction buildColumn(\n prop: EntityProperty,\n metaByClass: Map<string, EntityMetadata>,\n owningMeta: EntityMetadata\n): ColumnModel | null {\n // Skip the EMBEDDED group reference — individual flat columns appear as SCALAR entries\n if (prop.kind === ReferenceKind.EMBEDDED) {\n return null;\n }\n\n if (prop.kind === ReferenceKind.SCALAR) {\n // For @Formula columns, formula is set on a SCALAR-kinded property\n const formulaExpr: string | undefined =\n prop.formula !== undefined\n ? resolveFormulaExpr(prop.formula as (table: FormulaTable, cols: Record<string, string>) => string)\n : undefined;\n\n // Flat embedded columns carry `embedded: [ownerPropName, embeddedPropName]`\n let embeddedIn: string | undefined;\n if (prop.embedded !== undefined) {\n const parentPropName = prop.embedded[0];\n embeddedIn = owningMeta.properties[parentPropName]?.type;\n }\n\n const isDiscriminator =\n owningMeta.discriminatorColumn !== undefined && prop.name === owningMeta.discriminatorColumn;\n\n return {\n propName: prop.name,\n fieldName: prop.fieldNames?.[0] ?? prop.name,\n type: normalizeType(prop.type),\n isPrimary: prop.primary === true,\n isForeignKey: false,\n isUnique: prop.unique === true,\n isNullable: prop.nullable === true,\n ...(formulaExpr !== undefined && { formula: formulaExpr }),\n ...(embeddedIn !== undefined && { embeddedIn }),\n ...(isDiscriminator && { isDiscriminator: true }),\n };\n }\n\n // FK columns: m:1 always owns the FK; 1:1 only when owner === true\n if (prop.kind === ReferenceKind.MANY_TO_ONE || (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner === true)) {\n const fkType = resolveFkType(prop.type, metaByClass);\n return {\n propName: prop.name,\n fieldName: prop.fieldNames?.[0] ?? `${prop.name}_id`,\n type: fkType,\n isPrimary: false,\n isForeignKey: true,\n isUnique: prop.unique === true,\n isNullable: prop.nullable === true,\n };\n }\n\n // ONE_TO_MANY, MANY_TO_MANY (both owner and inverse) → no physical column\n return null;\n}\n\n/**\n * Calls the FormulaCallback with a dummy table and column proxy to extract the SQL expression.\n * String-based formulas (most common) ignore their arguments and return the literal string.\n * Function-based formulas use the alias/column names from the dummy objects.\n * Returns empty string on unexpected errors.\n */\nfunction resolveFormulaExpr(cb: (table: FormulaTable, cols: Record<string, string>) => string): string {\n try {\n const cols = new Proxy<Record<string, string>>(\n {},\n {\n get: (_target: Record<string, string>, key: string | symbol): string => (typeof key === 'string' ? key : ''),\n }\n );\n return cb(FORMULA_DUMMY_TABLE, cols);\n } catch {\n return '';\n }\n}\n\n/** Looks up the PK type of the referenced entity to use as FK column type. */\nfunction resolveFkType(referencedClassName: string, metaByClass: Map<string, EntityMetadata>): string {\n const refMeta = metaByClass.get(referencedClassName);\n if (!refMeta) {\n return 'integer';\n }\n const pkProp = Object.values(refMeta.properties).find((p) => p.primary === true);\n return pkProp ? normalizeType(pkProp.type) : 'integer';\n}\n\n/** Collects indexes, unique constraints, and check constraints from entity-level metadata. */\nfunction buildConstraints(meta: EntityMetadata): ConstraintModel[] {\n const result: ConstraintModel[] = [];\n\n for (const idx of meta.indexes ?? []) {\n const props = idx.properties;\n result.push({\n type: 'index',\n properties: Array.isArray(props) ? props.map(String) : props ? [String(props)] : [],\n ...(idx.name !== undefined && { name: idx.name }),\n });\n }\n\n for (const uniq of meta.uniques ?? []) {\n const props = uniq.properties;\n result.push({\n type: 'unique',\n properties: Array.isArray(props) ? props.map(String) : props ? [String(props)] : [],\n ...(uniq.name !== undefined && { name: uniq.name }),\n });\n }\n\n for (const check of meta.checks ?? []) {\n // Skip function-based check expressions (they require column reference objects at runtime)\n if (typeof check.expression !== 'string') {\n continue;\n }\n result.push({\n type: 'check',\n properties: [],\n expression: check.expression,\n ...(check.name !== undefined && { name: check.name }),\n });\n }\n\n return result;\n}\n\n/** Builds edges only from owning sides to avoid duplicate arrows. Includes STI inheritance. */\nfunction buildRelationEdges(metas: EntityMetadata[]): RelationEdge[] {\n const edges: RelationEdge[] = [];\n\n for (const meta of metas) {\n if (meta.pivotTable || meta.embeddable) {\n continue;\n }\n\n for (const prop of Object.values(meta.properties)) {\n const edge = buildEdge(meta.className, prop);\n if (edge !== null) {\n edges.push(edge);\n }\n }\n }\n\n return edges;\n}\n\nfunction buildEdge(fromEntity: string, prop: EntityProperty): RelationEdge | null {\n const isNullable = prop.nullable === true;\n\n if (prop.kind === ReferenceKind.MANY_TO_ONE) {\n return {\n fromEntity,\n toEntity: prop.type,\n fromCardinality: '}o',\n toCardinality: isNullable ? 'o|' : '||',\n label: prop.name,\n };\n }\n\n if (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner === true) {\n return {\n fromEntity,\n toEntity: prop.type,\n fromCardinality: '||',\n toCardinality: isNullable ? 'o|' : '||',\n label: prop.name,\n };\n }\n\n if (prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner === true) {\n return {\n fromEntity,\n toEntity: prop.type,\n fromCardinality: '}o',\n toCardinality: 'o{',\n label: prop.name,\n };\n }\n\n return null;\n}\n\n/**\n * Renders a DiagramModel as a Mermaid erDiagram block string.\n * The returned string starts with \"erDiagram\" and is ready to embed in a\n * markdown code fence.\n */\nexport function renderErDiagram(model: DiagramModel): string {\n const lines: string[] = ['erDiagram'];\n\n for (const entity of model.entities) {\n lines.push(` ${entity.className} {`);\n for (const col of entity.columns) {\n lines.push(` ${renderColumnLine(col)}`);\n }\n lines.push(' }');\n }\n\n for (const rel of model.relations) {\n lines.push(` ${rel.fromEntity} ${rel.fromCardinality}--${rel.toCardinality} ${rel.toEntity} : \"${rel.label}\"`);\n }\n\n return lines.join('\\n');\n}\n\nfunction renderColumnLine(col: ColumnModel): string {\n // Priority: PK > FK > UK\n let qualifier = '';\n if (col.isPrimary) {\n qualifier = ' PK';\n } else if (col.isForeignKey) {\n qualifier = ' FK';\n } else if (col.isUnique) {\n qualifier = ' UK';\n }\n\n // Comment priority (v1 differentiators over prisma-markdown):\n // 1. @Formula SQL expression — \"formula: LENGTH(name)\"\n // 2. STI discriminator column — \"discriminator\"\n // 3. Embedded source type — \"[Address]\"\n // 4. DB/TS name mismatch — \"<tsPropName>\"\n let comment: string | undefined;\n if (col.formula !== undefined) {\n comment = col.formula ? `formula: ${col.formula}` : 'formula';\n } else if (col.isDiscriminator) {\n comment = 'discriminator';\n } else if (col.embeddedIn !== undefined) {\n comment = `[${col.embeddedIn}]`;\n } else if (col.fieldName !== col.propName) {\n comment = col.propName;\n }\n\n const commentStr = comment !== undefined ? ` \"${comment}\"` : '';\n return `${col.type} ${col.fieldName}${qualifier}${commentStr}`;\n}\n\n/** Strips characters that are invalid in Mermaid type identifiers. */\nfunction normalizeType(type: string): string {\n return type.replace(/[^a-zA-Z0-9_]/g, '_');\n}\n","import type { EntityMetadata } from '@mikro-orm/core';\nimport type { EntityJsDocInfo, JsDocResult, PropJsDocInfo } from '../docs/jsdoc.js';\nimport { buildDiagramModel } from '../render/mermaid.js';\nimport type { EntityModel, RelationEdge } from './types.js';\n\n/** An entity with its structural model and JSDoc info merged together. */\nexport interface EnrichedEntity {\n model: EntityModel;\n /** Undefined if the entity has no class-level JSDoc. */\n jsDoc: EntityJsDocInfo | undefined;\n /** Per-property description map (empty map if no property JSDoc). */\n propDocs: Map<string, PropJsDocInfo>;\n}\n\n/**\n * A single namespace group, ready to render as one section of the document.\n *\n * - `erdEntities`: shown in the Mermaid ERD block (@namespace + @erd)\n * - `textEntities`: shown in the column-table sections (@namespace + @describe)\n * - `erdRelations`: relation edges where both endpoints are in `erdEntities`\n */\nexport interface NamespaceGroup {\n name: string;\n erdEntities: EnrichedEntity[];\n textEntities: EnrichedEntity[];\n erdRelations: RelationEdge[];\n}\n\n/** Complete document model — input to the markdown renderer. */\nexport interface DocumentModel {\n title: string;\n /** Optional paragraph rendered below the H1 heading. */\n description?: string;\n groups: NamespaceGroup[];\n}\n\n/**\n * Merges MikroORM structural metadata with JSDoc information and organises the\n * result into namespace groups for rendering.\n *\n * Entities with @hidden are excluded.\n * Entities with no namespace tags fall into the \"default\" group.\n * Groups are ordered alphabetically, with \"default\" always last.\n */\nexport function buildDocumentModel(\n metas: EntityMetadata[],\n jsDocResult: JsDocResult,\n title: string,\n description?: string\n): DocumentModel {\n const { entities: diagramEntities, relations: allRelations } = buildDiagramModel(metas);\n\n // Build enriched entity map, filtering out @hidden entities.\n const enrichedByClass = new Map<string, EnrichedEntity>();\n for (const model of diagramEntities) {\n const jsDoc = jsDocResult.entities.get(model.className);\n if (jsDoc?.hidden) {\n continue;\n }\n const propDocs = jsDocResult.props.get(model.className) ?? new Map<string, PropJsDocInfo>();\n enrichedByClass.set(model.className, { model, jsDoc, propDocs });\n }\n\n // Collect all unique namespace names referenced by any entity.\n const groupNames = new Set<string>();\n let anyUntagged = false;\n for (const { jsDoc } of enrichedByClass.values()) {\n const allNs = [...(jsDoc?.namespaces ?? []), ...(jsDoc?.erdNamespaces ?? []), ...(jsDoc?.describeNamespaces ?? [])];\n if (allNs.length === 0) {\n anyUntagged = true;\n } else {\n for (const ns of allNs) {\n groupNames.add(ns);\n }\n }\n }\n if (anyUntagged) {\n groupNames.add('default');\n }\n\n const groups: NamespaceGroup[] = [];\n for (const groupName of groupNames) {\n const isDefault = groupName === 'default';\n\n const erdEntities = [...enrichedByClass.values()].filter(({ jsDoc }) =>\n belongsToGroupForErd(jsDoc, groupName, isDefault)\n );\n\n const textEntities = [...enrichedByClass.values()].filter(({ jsDoc }) =>\n belongsToGroupForText(jsDoc, groupName, isDefault)\n );\n\n const erdClassNames = new Set(erdEntities.map((e) => e.model.className));\n const erdRelations = allRelations.filter((r) => erdClassNames.has(r.fromEntity) && erdClassNames.has(r.toEntity));\n\n groups.push({ name: groupName, erdEntities, textEntities, erdRelations });\n }\n\n // Sort alphabetically; \"default\" is always last.\n groups.sort((a, b) => {\n if (a.name === 'default') {\n return 1;\n }\n if (b.name === 'default') {\n return -1;\n }\n return a.name.localeCompare(b.name);\n });\n\n return { title, groups, ...(description !== undefined && { description }) };\n}\n\nfunction hasNoNamespaceTags(jsDoc: EntityJsDocInfo | undefined): boolean {\n if (!jsDoc) {\n return true;\n }\n return jsDoc.namespaces.length === 0 && jsDoc.erdNamespaces.length === 0 && jsDoc.describeNamespaces.length === 0;\n}\n\nfunction belongsToGroupForErd(jsDoc: EntityJsDocInfo | undefined, groupName: string, isDefault: boolean): boolean {\n if (isDefault) {\n return hasNoNamespaceTags(jsDoc);\n }\n if (!jsDoc) {\n return false;\n }\n return jsDoc.namespaces.includes(groupName) || jsDoc.erdNamespaces.includes(groupName);\n}\n\nfunction belongsToGroupForText(jsDoc: EntityJsDocInfo | undefined, groupName: string, isDefault: boolean): boolean {\n if (isDefault) {\n return hasNoNamespaceTags(jsDoc);\n }\n if (!jsDoc) {\n return false;\n }\n return jsDoc.namespaces.includes(groupName) || jsDoc.describeNamespaces.includes(groupName);\n}\n","import type { DocumentModel, EnrichedEntity, NamespaceGroup } from '../model/build.js';\nimport type { ColumnModel, ConstraintModel, DiagramModel } from '../model/types.js';\nimport { renderErDiagram } from './mermaid.js';\n\n/**\n * Renders a DocumentModel as a markdown string.\n * Each namespace group becomes a level-2 section with a Mermaid ERD block\n * followed by per-entity column tables.\n */\nexport function renderMarkdown(docModel: DocumentModel): string {\n const sections: string[] = [`# ${docModel.title}`];\n\n if (docModel.description) {\n sections.push(docModel.description);\n }\n\n for (const group of docModel.groups) {\n sections.push(renderGroupSection(group));\n }\n\n return sections.join('\\n\\n');\n}\n\nfunction renderGroupSection(group: NamespaceGroup): string {\n const parts: string[] = [`## ${group.name}`];\n\n if (group.erdEntities.length > 0) {\n const diagramModel: DiagramModel = {\n entities: group.erdEntities.map((e) => e.model),\n relations: group.erdRelations,\n };\n parts.push('```mermaid\\n' + renderErDiagram(diagramModel) + '\\n```');\n }\n\n for (const entity of group.textEntities) {\n parts.push(renderEntitySection(entity));\n }\n\n return parts.join('\\n\\n');\n}\n\nfunction renderEntitySection(entity: EnrichedEntity): string {\n const parts: string[] = [`### ${entity.model.className}`];\n\n if (entity.jsDoc?.description) {\n parts.push(`> ${entity.jsDoc.description}`);\n }\n\n // STI metadata note\n if (entity.model.discriminatorColumn) {\n parts.push(`*STI root — discriminator column: \\`${entity.model.discriminatorColumn}\\`*`);\n } else if (entity.model.extendsEntity) {\n parts.push(`*Extends \\`${entity.model.extendsEntity}\\` (Single Table Inheritance)*`);\n }\n\n if (entity.model.columns.length > 0) {\n parts.push(renderColumnTable(entity));\n }\n\n if (entity.model.constraints.length > 0) {\n parts.push(renderConstraints(entity.model.constraints));\n }\n\n return parts.join('\\n\\n');\n}\n\nfunction renderColumnTable(entity: EnrichedEntity): string {\n const header = '| Column | Type | Key | Nullable | Description |';\n const sep = '|--------|------|-----|----------|-------------|';\n const rows = entity.model.columns.map((col) => {\n const key = resolveColumnKey(col);\n const nullable = col.isNullable && !col.isPrimary ? 'Y' : '';\n const desc = entity.propDocs.get(col.propName)?.description ?? '';\n return `| ${col.fieldName} | ${col.type} | ${key} | ${nullable} | ${desc} |`;\n });\n return [header, sep, ...rows].join('\\n');\n}\n\n/** Returns the \"Key\" cell value for the column table. */\nfunction resolveColumnKey(col: ColumnModel): string {\n if (col.isPrimary) {\n return 'PK';\n }\n if (col.isForeignKey) {\n // Show TS property name in parentheses if it differs from the DB column name\n return col.fieldName !== col.propName ? `FK (${col.propName})` : 'FK';\n }\n if (col.isUnique) {\n return 'UK';\n }\n if (col.formula !== undefined) {\n return `formula: ${col.formula}`;\n }\n if (col.isDiscriminator) {\n return 'discriminator';\n }\n if (col.embeddedIn !== undefined) {\n return `[${col.embeddedIn}]`;\n }\n return '';\n}\n\nfunction renderConstraints(constraints: ConstraintModel[]): string {\n const lines = ['**Constraints:**', ''];\n for (const c of constraints) {\n const name = c.name ? ` \\`${c.name}\\`` : '';\n if (c.type === 'index') {\n lines.push(`- Index${name}: (${c.properties.join(', ')})`);\n } else if (c.type === 'unique') {\n lines.push(`- Unique${name}: (${c.properties.join(', ')})`);\n } else if (c.type === 'check') {\n lines.push(`- Check${name}: \\`${c.expression ?? ''}\\``);\n }\n }\n return lines.join('\\n');\n}\n","import type { Options } from '@mikro-orm/core';\nimport { loadJsDoc } from './docs/jsdoc.js';\nimport { loadEntityMetadata } from './metadata/load.js';\nimport { buildDocumentModel } from './model/build.js';\nimport { renderMarkdown } from './render/markdown.js';\n\nexport { MetadataLoadError } from './metadata/load.js';\nexport type { GenerateOptions } from './model/types.js';\n\n/** Options for the programmatic API. */\nexport interface GenerateMarkdownOptions {\n /** MikroORM configuration (driver, entities, dbName, …). */\n orm: Options;\n /** Title shown as the H1 heading in the generated document. */\n title?: string;\n /** Optional description paragraph rendered below the H1 heading. */\n description?: string;\n /**\n * Glob patterns for TypeScript entity source files.\n * Used for JSDoc extraction (@namespace, @hidden, descriptions).\n * Omit to skip JSDoc parsing — all entities go into the \"default\" section.\n */\n src?: string[];\n}\n\n/**\n * Generates a Mermaid ERD + markdown documentation document from MikroORM\n * entity metadata.\n *\n * @example\n * ```ts\n * import { generateMarkdown } from 'mikro-orm-markdown';\n * import ormConfig from './mikro-orm.config.js';\n *\n * const markdown = await generateMarkdown({\n * orm: ormConfig,\n * title: 'My Database',\n * src: ['src/entities/*.ts'],\n * });\n * ```\n */\nexport async function generateMarkdown(options: GenerateMarkdownOptions): Promise<string> {\n const { orm, title = 'Database Schema', description, src = [] } = options;\n\n const metas = await loadEntityMetadata(orm);\n const jsDocResult = loadJsDoc(src);\n const docModel = buildDocumentModel(metas, jsDocResult, title, description);\n return renderMarkdown(docModel);\n}\n"],"mappings":";;;AAEA,YAAY,QAAQ;AACpB,YAAY,UAAU;AAEtB,SAAS,eAAe;;;ACJxB,SAAS,eAAe;AAyCjB,SAAS,UAAU,UAAiC;AACzD,QAAM,WAA2B,oBAAI,IAAI;AACzC,QAAM,QAAsB,oBAAI,IAAI;AAEpC,MAAI,SAAS,WAAW,GA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C;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,9 @@ var import_ts_morph = require("ts-morph");
|
|
|
30
30
|
function loadJsDoc(srcGlobs) {
|
|
31
31
|
const entities = /* @__PURE__ */ new Map();
|
|
32
32
|
const props = /* @__PURE__ */ new Map();
|
|
33
|
-
if (srcGlobs.length === 0)
|
|
33
|
+
if (srcGlobs.length === 0) {
|
|
34
|
+
return { entities, props };
|
|
35
|
+
}
|
|
34
36
|
const project = new import_ts_morph.Project({
|
|
35
37
|
skipAddingFilesFromTsConfig: true,
|
|
36
38
|
skipLoadingLibFiles: true,
|
|
@@ -43,7 +45,9 @@ function loadJsDoc(srcGlobs) {
|
|
|
43
45
|
for (const sourceFile of project.getSourceFiles()) {
|
|
44
46
|
for (const cls of sourceFile.getClasses()) {
|
|
45
47
|
const className = cls.getName();
|
|
46
|
-
if (!className)
|
|
48
|
+
if (!className) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
47
51
|
const classDocs = cls.getJsDocs();
|
|
48
52
|
if (classDocs.length > 0) {
|
|
49
53
|
entities.set(className, parseEntityJsDoc(classDocs));
|
|
@@ -51,7 +55,9 @@ function loadJsDoc(srcGlobs) {
|
|
|
51
55
|
const propMap = /* @__PURE__ */ new Map();
|
|
52
56
|
for (const prop of cls.getProperties()) {
|
|
53
57
|
const propDocs = prop.getJsDocs();
|
|
54
|
-
if (propDocs.length === 0)
|
|
58
|
+
if (propDocs.length === 0) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
55
61
|
const desc = extractDescription(propDocs);
|
|
56
62
|
if (desc !== void 0) {
|
|
57
63
|
propMap.set(prop.getName(), { description: desc });
|
|
@@ -72,14 +78,21 @@ function parseEntityJsDoc(jsDocs) {
|
|
|
72
78
|
let description;
|
|
73
79
|
for (const doc of jsDocs) {
|
|
74
80
|
const desc = doc.getDescription().trim();
|
|
75
|
-
if (desc && description === void 0)
|
|
81
|
+
if (desc && description === void 0) {
|
|
82
|
+
description = desc;
|
|
83
|
+
}
|
|
76
84
|
for (const tag of doc.getTags()) {
|
|
77
85
|
const tagName = tag.getTagName();
|
|
78
86
|
const comment = tag.getCommentText()?.trim();
|
|
79
|
-
if (tagName === "namespace" && comment)
|
|
80
|
-
|
|
81
|
-
else if (tagName === "
|
|
82
|
-
|
|
87
|
+
if (tagName === "namespace" && comment) {
|
|
88
|
+
namespaces.push(comment);
|
|
89
|
+
} else if (tagName === "erd" && comment) {
|
|
90
|
+
erdNamespaces.push(comment);
|
|
91
|
+
} else if (tagName === "describe" && comment) {
|
|
92
|
+
describeNamespaces.push(comment);
|
|
93
|
+
} else if (tagName === "hidden") {
|
|
94
|
+
hidden = true;
|
|
95
|
+
}
|
|
83
96
|
}
|
|
84
97
|
}
|
|
85
98
|
return {
|
|
@@ -93,7 +106,9 @@ function parseEntityJsDoc(jsDocs) {
|
|
|
93
106
|
function extractDescription(jsDocs) {
|
|
94
107
|
for (const doc of jsDocs) {
|
|
95
108
|
const desc = doc.getDescription().trim();
|
|
96
|
-
if (desc)
|
|
109
|
+
if (desc) {
|
|
110
|
+
return desc;
|
|
111
|
+
}
|
|
97
112
|
}
|
|
98
113
|
return void 0;
|
|
99
114
|
}
|
|
@@ -112,7 +127,8 @@ async function loadEntityMetadata(options) {
|
|
|
112
127
|
try {
|
|
113
128
|
orm = await import_core.MikroORM.init({
|
|
114
129
|
...options,
|
|
115
|
-
debug: false
|
|
130
|
+
debug: false,
|
|
131
|
+
connect: false
|
|
116
132
|
});
|
|
117
133
|
} catch (cause) {
|
|
118
134
|
throw new MetadataLoadError(
|
|
@@ -120,17 +136,13 @@ async function loadEntityMetadata(options) {
|
|
|
120
136
|
cause
|
|
121
137
|
);
|
|
122
138
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
return all;
|
|
131
|
-
} finally {
|
|
132
|
-
await orm.close(true);
|
|
139
|
+
const all = Object.values(orm.getMetadata().getAll());
|
|
140
|
+
if (all.length === 0) {
|
|
141
|
+
throw new MetadataLoadError(
|
|
142
|
+
"No entities were discovered. Check that your config specifies at least one entity path or class."
|
|
143
|
+
);
|
|
133
144
|
}
|
|
145
|
+
return all;
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
// src/render/mermaid.ts
|
|
@@ -152,9 +164,13 @@ function buildEntityModel(meta, metaByClass) {
|
|
|
152
164
|
const isStiChild = Boolean(meta.extends) && meta.discriminatorValue !== void 0;
|
|
153
165
|
const columns = [];
|
|
154
166
|
for (const prop of Object.values(meta.properties)) {
|
|
155
|
-
if (isStiRoot && prop.inherited === true)
|
|
167
|
+
if (isStiRoot && prop.inherited === true) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
156
170
|
const col = buildColumn(prop, metaByClass, meta);
|
|
157
|
-
if (col !== null)
|
|
171
|
+
if (col !== null) {
|
|
172
|
+
columns.push(col);
|
|
173
|
+
}
|
|
158
174
|
}
|
|
159
175
|
return {
|
|
160
176
|
className: meta.className,
|
|
@@ -168,7 +184,9 @@ function buildEntityModel(meta, metaByClass) {
|
|
|
168
184
|
};
|
|
169
185
|
}
|
|
170
186
|
function buildColumn(prop, metaByClass, owningMeta) {
|
|
171
|
-
if (prop.kind === import_core2.ReferenceKind.EMBEDDED)
|
|
187
|
+
if (prop.kind === import_core2.ReferenceKind.EMBEDDED) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
172
190
|
if (prop.kind === import_core2.ReferenceKind.SCALAR) {
|
|
173
191
|
const formulaExpr = prop.formula !== void 0 ? resolveFormulaExpr(prop.formula) : void 0;
|
|
174
192
|
let embeddedIn;
|
|
@@ -206,9 +224,12 @@ function buildColumn(prop, metaByClass, owningMeta) {
|
|
|
206
224
|
}
|
|
207
225
|
function resolveFormulaExpr(cb) {
|
|
208
226
|
try {
|
|
209
|
-
const cols = new Proxy(
|
|
210
|
-
|
|
211
|
-
|
|
227
|
+
const cols = new Proxy(
|
|
228
|
+
{},
|
|
229
|
+
{
|
|
230
|
+
get: (_target, key) => typeof key === "string" ? key : ""
|
|
231
|
+
}
|
|
232
|
+
);
|
|
212
233
|
return cb(FORMULA_DUMMY_TABLE, cols);
|
|
213
234
|
} catch {
|
|
214
235
|
return "";
|
|
@@ -216,7 +237,9 @@ function resolveFormulaExpr(cb) {
|
|
|
216
237
|
}
|
|
217
238
|
function resolveFkType(referencedClassName, metaByClass) {
|
|
218
239
|
const refMeta = metaByClass.get(referencedClassName);
|
|
219
|
-
if (!refMeta)
|
|
240
|
+
if (!refMeta) {
|
|
241
|
+
return "integer";
|
|
242
|
+
}
|
|
220
243
|
const pkProp = Object.values(refMeta.properties).find((p) => p.primary === true);
|
|
221
244
|
return pkProp ? normalizeType(pkProp.type) : "integer";
|
|
222
245
|
}
|
|
@@ -239,7 +262,9 @@ function buildConstraints(meta) {
|
|
|
239
262
|
});
|
|
240
263
|
}
|
|
241
264
|
for (const check of meta.checks ?? []) {
|
|
242
|
-
if (typeof check.expression !== "string")
|
|
265
|
+
if (typeof check.expression !== "string") {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
243
268
|
result.push({
|
|
244
269
|
type: "check",
|
|
245
270
|
properties: [],
|
|
@@ -252,10 +277,14 @@ function buildConstraints(meta) {
|
|
|
252
277
|
function buildRelationEdges(metas) {
|
|
253
278
|
const edges = [];
|
|
254
279
|
for (const meta of metas) {
|
|
255
|
-
if (meta.pivotTable || meta.embeddable)
|
|
280
|
+
if (meta.pivotTable || meta.embeddable) {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
256
283
|
for (const prop of Object.values(meta.properties)) {
|
|
257
284
|
const edge = buildEdge(meta.className, prop);
|
|
258
|
-
if (edge !== null)
|
|
285
|
+
if (edge !== null) {
|
|
286
|
+
edges.push(edge);
|
|
287
|
+
}
|
|
259
288
|
}
|
|
260
289
|
}
|
|
261
290
|
return edges;
|
|
@@ -301,17 +330,19 @@ function renderErDiagram(model) {
|
|
|
301
330
|
lines.push(" }");
|
|
302
331
|
}
|
|
303
332
|
for (const rel of model.relations) {
|
|
304
|
-
lines.push(
|
|
305
|
-
` ${rel.fromEntity} ${rel.fromCardinality}--${rel.toCardinality} ${rel.toEntity} : "${rel.label}"`
|
|
306
|
-
);
|
|
333
|
+
lines.push(` ${rel.fromEntity} ${rel.fromCardinality}--${rel.toCardinality} ${rel.toEntity} : "${rel.label}"`);
|
|
307
334
|
}
|
|
308
335
|
return lines.join("\n");
|
|
309
336
|
}
|
|
310
337
|
function renderColumnLine(col) {
|
|
311
338
|
let qualifier = "";
|
|
312
|
-
if (col.isPrimary)
|
|
313
|
-
|
|
314
|
-
else if (col.
|
|
339
|
+
if (col.isPrimary) {
|
|
340
|
+
qualifier = " PK";
|
|
341
|
+
} else if (col.isForeignKey) {
|
|
342
|
+
qualifier = " FK";
|
|
343
|
+
} else if (col.isUnique) {
|
|
344
|
+
qualifier = " UK";
|
|
345
|
+
}
|
|
315
346
|
let comment;
|
|
316
347
|
if (col.formula !== void 0) {
|
|
317
348
|
comment = col.formula ? `formula: ${col.formula}` : "formula";
|
|
@@ -335,25 +366,27 @@ function buildDocumentModel(metas, jsDocResult, title, description) {
|
|
|
335
366
|
const enrichedByClass = /* @__PURE__ */ new Map();
|
|
336
367
|
for (const model of diagramEntities) {
|
|
337
368
|
const jsDoc = jsDocResult.entities.get(model.className);
|
|
338
|
-
if (jsDoc?.hidden)
|
|
369
|
+
if (jsDoc?.hidden) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
339
372
|
const propDocs = jsDocResult.props.get(model.className) ?? /* @__PURE__ */ new Map();
|
|
340
373
|
enrichedByClass.set(model.className, { model, jsDoc, propDocs });
|
|
341
374
|
}
|
|
342
375
|
const groupNames = /* @__PURE__ */ new Set();
|
|
343
376
|
let anyUntagged = false;
|
|
344
377
|
for (const { jsDoc } of enrichedByClass.values()) {
|
|
345
|
-
const allNs = [
|
|
346
|
-
...jsDoc?.namespaces ?? [],
|
|
347
|
-
...jsDoc?.erdNamespaces ?? [],
|
|
348
|
-
...jsDoc?.describeNamespaces ?? []
|
|
349
|
-
];
|
|
378
|
+
const allNs = [...jsDoc?.namespaces ?? [], ...jsDoc?.erdNamespaces ?? [], ...jsDoc?.describeNamespaces ?? []];
|
|
350
379
|
if (allNs.length === 0) {
|
|
351
380
|
anyUntagged = true;
|
|
352
381
|
} else {
|
|
353
|
-
for (const ns of allNs)
|
|
382
|
+
for (const ns of allNs) {
|
|
383
|
+
groupNames.add(ns);
|
|
384
|
+
}
|
|
354
385
|
}
|
|
355
386
|
}
|
|
356
|
-
if (anyUntagged)
|
|
387
|
+
if (anyUntagged) {
|
|
388
|
+
groupNames.add("default");
|
|
389
|
+
}
|
|
357
390
|
const groups = [];
|
|
358
391
|
for (const groupName of groupNames) {
|
|
359
392
|
const isDefault = groupName === "default";
|
|
@@ -364,30 +397,42 @@ function buildDocumentModel(metas, jsDocResult, title, description) {
|
|
|
364
397
|
({ jsDoc }) => belongsToGroupForText(jsDoc, groupName, isDefault)
|
|
365
398
|
);
|
|
366
399
|
const erdClassNames = new Set(erdEntities.map((e) => e.model.className));
|
|
367
|
-
const erdRelations = allRelations.filter(
|
|
368
|
-
(r) => erdClassNames.has(r.fromEntity) && erdClassNames.has(r.toEntity)
|
|
369
|
-
);
|
|
400
|
+
const erdRelations = allRelations.filter((r) => erdClassNames.has(r.fromEntity) && erdClassNames.has(r.toEntity));
|
|
370
401
|
groups.push({ name: groupName, erdEntities, textEntities, erdRelations });
|
|
371
402
|
}
|
|
372
403
|
groups.sort((a, b) => {
|
|
373
|
-
if (a.name === "default")
|
|
374
|
-
|
|
404
|
+
if (a.name === "default") {
|
|
405
|
+
return 1;
|
|
406
|
+
}
|
|
407
|
+
if (b.name === "default") {
|
|
408
|
+
return -1;
|
|
409
|
+
}
|
|
375
410
|
return a.name.localeCompare(b.name);
|
|
376
411
|
});
|
|
377
412
|
return { title, groups, ...description !== void 0 && { description } };
|
|
378
413
|
}
|
|
379
414
|
function hasNoNamespaceTags(jsDoc) {
|
|
380
|
-
if (!jsDoc)
|
|
415
|
+
if (!jsDoc) {
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
381
418
|
return jsDoc.namespaces.length === 0 && jsDoc.erdNamespaces.length === 0 && jsDoc.describeNamespaces.length === 0;
|
|
382
419
|
}
|
|
383
420
|
function belongsToGroupForErd(jsDoc, groupName, isDefault) {
|
|
384
|
-
if (isDefault)
|
|
385
|
-
|
|
421
|
+
if (isDefault) {
|
|
422
|
+
return hasNoNamespaceTags(jsDoc);
|
|
423
|
+
}
|
|
424
|
+
if (!jsDoc) {
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
386
427
|
return jsDoc.namespaces.includes(groupName) || jsDoc.erdNamespaces.includes(groupName);
|
|
387
428
|
}
|
|
388
429
|
function belongsToGroupForText(jsDoc, groupName, isDefault) {
|
|
389
|
-
if (isDefault)
|
|
390
|
-
|
|
430
|
+
if (isDefault) {
|
|
431
|
+
return hasNoNamespaceTags(jsDoc);
|
|
432
|
+
}
|
|
433
|
+
if (!jsDoc) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
391
436
|
return jsDoc.namespaces.includes(groupName) || jsDoc.describeNamespaces.includes(groupName);
|
|
392
437
|
}
|
|
393
438
|
|
|
@@ -422,9 +467,7 @@ function renderEntitySection(entity) {
|
|
|
422
467
|
parts.push(`> ${entity.jsDoc.description}`);
|
|
423
468
|
}
|
|
424
469
|
if (entity.model.discriminatorColumn) {
|
|
425
|
-
parts.push(
|
|
426
|
-
`*STI root \u2014 discriminator column: \`${entity.model.discriminatorColumn}\`*`
|
|
427
|
-
);
|
|
470
|
+
parts.push(`*STI root \u2014 discriminator column: \`${entity.model.discriminatorColumn}\`*`);
|
|
428
471
|
} else if (entity.model.extendsEntity) {
|
|
429
472
|
parts.push(`*Extends \`${entity.model.extendsEntity}\` (Single Table Inheritance)*`);
|
|
430
473
|
}
|
|
@@ -448,14 +491,24 @@ function renderColumnTable(entity) {
|
|
|
448
491
|
return [header, sep, ...rows].join("\n");
|
|
449
492
|
}
|
|
450
493
|
function resolveColumnKey(col) {
|
|
451
|
-
if (col.isPrimary)
|
|
494
|
+
if (col.isPrimary) {
|
|
495
|
+
return "PK";
|
|
496
|
+
}
|
|
452
497
|
if (col.isForeignKey) {
|
|
453
498
|
return col.fieldName !== col.propName ? `FK (${col.propName})` : "FK";
|
|
454
499
|
}
|
|
455
|
-
if (col.isUnique)
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
if (col.
|
|
500
|
+
if (col.isUnique) {
|
|
501
|
+
return "UK";
|
|
502
|
+
}
|
|
503
|
+
if (col.formula !== void 0) {
|
|
504
|
+
return `formula: ${col.formula}`;
|
|
505
|
+
}
|
|
506
|
+
if (col.isDiscriminator) {
|
|
507
|
+
return "discriminator";
|
|
508
|
+
}
|
|
509
|
+
if (col.embeddedIn !== void 0) {
|
|
510
|
+
return `[${col.embeddedIn}]`;
|
|
511
|
+
}
|
|
459
512
|
return "";
|
|
460
513
|
}
|
|
461
514
|
function renderConstraints(constraints) {
|