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/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/docs/jsdoc.ts","../src/metadata/load.ts","../src/render/mermaid.ts","../src/model/build.ts","../src/render/markdown.ts"],"sourcesContent":["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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAwB;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,wBAAQ;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;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,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AACzB,MAAI,IAAI,YAAY,OAAW,QAAO,YAAY,IAAI,OAAO;AAC7D,MAAI,IAAI,gBAAiB,QAAO;AAChC,MAAI,IAAI,eAAe,OAAW,QAAO,IAAI,IAAI,UAAU;AAC3D,SAAO;AACT;AAGA,SAAS,kBAAkB,aAAwC;AACjE,QAAM,QAAQ,CAAC,oBAAoB,EAAE;AACrC,aAAW,KAAK,aAAa;AAC3B,UAAM,OAAO,EAAE,OAAO,MAAM,EAAE,IAAI,OAAO;AACzC,QAAI,EAAE,SAAS,SAAS;AACtB,YAAM,KAAK,UAAU,IAAI,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG;AAAA,IAC3D,WAAW,EAAE,SAAS,UAAU;AAC9B,YAAM,KAAK,WAAW,IAAI,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG;AAAA,IAC5D,WAAW,EAAE,SAAS,SAAS;AAC7B,YAAM,KAAK,UAAU,IAAI,OAAO,EAAE,cAAc,EAAE,IAAI;AAAA,IACxD;AAAA,EACF;AACA,SAAO,MAAM,KAAK,IAAI;AACxB;;;ALnEA,eAAsB,iBAAiB,SAAmD;AACxF,QAAM,EAAE,KAAK,QAAQ,mBAAmB,aAAa,MAAM,CAAC,EAAE,IAAI;AAElE,QAAM,QAAQ,MAAM,mBAAmB,GAAG;AAC1C,QAAM,cAAc,UAAU,GAAG;AACjC,QAAM,WAAW,mBAAmB,OAAO,aAAa,OAAO,WAAW;AAC1E,SAAO,eAAe,QAAQ;AAChC;","names":["import_core"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/docs/jsdoc.ts","../src/metadata/load.ts","../src/render/mermaid.ts","../src/model/build.ts","../src/render/markdown.ts"],"sourcesContent":["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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAwB;AAyCjB,SAAS,UAAU,UAAiC;AACzD,QAAM,WAA2B,oBAAI,IAAI;AACzC,QAAM,QAAsB,oBAAI,IAAI;AAEpC,MAAI,SAAS,WAAW,GAAG;AACzB,WAAO,EAAE,UAAU,MAAM;AAAA,EAC3B;AAEA,QAAM,UAAU,IAAI,wBAAQ;AAAA,IAC1B,6BAA6B;AAAA,IAC7B,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,MACf,wBAAwB;AAAA,MACxB,cAAc;AAAA,IAChB;AAAA,EACF,CAAC;AAED,UAAQ,sBAAsB,QAAQ;AAE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A,SAAO;AACT;AAEA,SAAS,kBAAkB,aAAwC;AACjE,QAAM,QAAQ,CAAC,oBAAoB,EAAE;AACrC,aAAW,KAAK,aAAa;AAC3B,UAAM,OAAO,EAAE,OAAO,MAAM,EAAE,IAAI,OAAO;AACzC,QAAI,EAAE,SAAS,SAAS;AACtB,YAAM,KAAK,UAAU,IAAI,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG;AAAA,IAC3D,WAAW,EAAE,SAAS,UAAU;AAC9B,YAAM,KAAK,WAAW,IAAI,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG;AAAA,IAC5D,WAAW,EAAE,SAAS,SAAS;AAC7B,YAAM,KAAK,UAAU,IAAI,OAAO,EAAE,cAAc,EAAE,IAAI;AAAA,IACxD;AAAA,EACF;AACA,SAAO,MAAM,KAAK,IAAI;AACxB;;;AL1EA,eAAsB,iBAAiB,SAAmD;AACxF,QAAM,EAAE,KAAK,QAAQ,mBAAmB,aAAa,MAAM,CAAC,EAAE,IAAI;AAElE,QAAM,QAAQ,MAAM,mBAAmB,GAAG;AAC1C,QAAM,cAAc,UAAU,GAAG;AACjC,QAAM,WAAW,mBAAmB,OAAO,aAAa,OAAO,WAAW;AAC1E,SAAO,eAAe,QAAQ;AAChC;","names":["import_core"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Options } from '@mikro-orm/core';
|
|
2
2
|
|
|
3
|
+
/** Errors thrown during metadata loading */
|
|
4
|
+
declare class MetadataLoadError extends Error {
|
|
5
|
+
readonly cause?: unknown | undefined;
|
|
6
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
/** Options accepted by the main generateMarkdown function and CLI. */
|
|
4
10
|
interface GenerateOptions {
|
|
5
11
|
/** Path to the MikroORM config file (default: mikro-orm.config.ts). */
|
|
@@ -12,12 +18,6 @@ interface GenerateOptions {
|
|
|
12
18
|
src?: string[];
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
/** Errors thrown during metadata loading */
|
|
16
|
-
declare class MetadataLoadError extends Error {
|
|
17
|
-
readonly cause?: unknown | undefined;
|
|
18
|
-
constructor(message: string, cause?: unknown | undefined);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
21
|
/** Options for the programmatic API. */
|
|
22
22
|
interface GenerateMarkdownOptions {
|
|
23
23
|
/** MikroORM configuration (driver, entities, dbName, …). */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Options } from '@mikro-orm/core';
|
|
2
2
|
|
|
3
|
+
/** Errors thrown during metadata loading */
|
|
4
|
+
declare class MetadataLoadError extends Error {
|
|
5
|
+
readonly cause?: unknown | undefined;
|
|
6
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
/** Options accepted by the main generateMarkdown function and CLI. */
|
|
4
10
|
interface GenerateOptions {
|
|
5
11
|
/** Path to the MikroORM config file (default: mikro-orm.config.ts). */
|
|
@@ -12,12 +18,6 @@ interface GenerateOptions {
|
|
|
12
18
|
src?: string[];
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
/** Errors thrown during metadata loading */
|
|
16
|
-
declare class MetadataLoadError extends Error {
|
|
17
|
-
readonly cause?: unknown | undefined;
|
|
18
|
-
constructor(message: string, cause?: unknown | undefined);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
21
|
/** Options for the programmatic API. */
|
|
22
22
|
interface GenerateMarkdownOptions {
|
|
23
23
|
/** MikroORM configuration (driver, entities, dbName, …). */
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,9 @@ import { Project } from "ts-morph";
|
|
|
3
3
|
function loadJsDoc(srcGlobs) {
|
|
4
4
|
const entities = /* @__PURE__ */ new Map();
|
|
5
5
|
const props = /* @__PURE__ */ new Map();
|
|
6
|
-
if (srcGlobs.length === 0)
|
|
6
|
+
if (srcGlobs.length === 0) {
|
|
7
|
+
return { entities, props };
|
|
8
|
+
}
|
|
7
9
|
const project = new Project({
|
|
8
10
|
skipAddingFilesFromTsConfig: true,
|
|
9
11
|
skipLoadingLibFiles: true,
|
|
@@ -16,7 +18,9 @@ function loadJsDoc(srcGlobs) {
|
|
|
16
18
|
for (const sourceFile of project.getSourceFiles()) {
|
|
17
19
|
for (const cls of sourceFile.getClasses()) {
|
|
18
20
|
const className = cls.getName();
|
|
19
|
-
if (!className)
|
|
21
|
+
if (!className) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
20
24
|
const classDocs = cls.getJsDocs();
|
|
21
25
|
if (classDocs.length > 0) {
|
|
22
26
|
entities.set(className, parseEntityJsDoc(classDocs));
|
|
@@ -24,7 +28,9 @@ function loadJsDoc(srcGlobs) {
|
|
|
24
28
|
const propMap = /* @__PURE__ */ new Map();
|
|
25
29
|
for (const prop of cls.getProperties()) {
|
|
26
30
|
const propDocs = prop.getJsDocs();
|
|
27
|
-
if (propDocs.length === 0)
|
|
31
|
+
if (propDocs.length === 0) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
28
34
|
const desc = extractDescription(propDocs);
|
|
29
35
|
if (desc !== void 0) {
|
|
30
36
|
propMap.set(prop.getName(), { description: desc });
|
|
@@ -45,14 +51,21 @@ function parseEntityJsDoc(jsDocs) {
|
|
|
45
51
|
let description;
|
|
46
52
|
for (const doc of jsDocs) {
|
|
47
53
|
const desc = doc.getDescription().trim();
|
|
48
|
-
if (desc && description === void 0)
|
|
54
|
+
if (desc && description === void 0) {
|
|
55
|
+
description = desc;
|
|
56
|
+
}
|
|
49
57
|
for (const tag of doc.getTags()) {
|
|
50
58
|
const tagName = tag.getTagName();
|
|
51
59
|
const comment = tag.getCommentText()?.trim();
|
|
52
|
-
if (tagName === "namespace" && comment)
|
|
53
|
-
|
|
54
|
-
else if (tagName === "
|
|
55
|
-
|
|
60
|
+
if (tagName === "namespace" && comment) {
|
|
61
|
+
namespaces.push(comment);
|
|
62
|
+
} else if (tagName === "erd" && comment) {
|
|
63
|
+
erdNamespaces.push(comment);
|
|
64
|
+
} else if (tagName === "describe" && comment) {
|
|
65
|
+
describeNamespaces.push(comment);
|
|
66
|
+
} else if (tagName === "hidden") {
|
|
67
|
+
hidden = true;
|
|
68
|
+
}
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
return {
|
|
@@ -66,7 +79,9 @@ function parseEntityJsDoc(jsDocs) {
|
|
|
66
79
|
function extractDescription(jsDocs) {
|
|
67
80
|
for (const doc of jsDocs) {
|
|
68
81
|
const desc = doc.getDescription().trim();
|
|
69
|
-
if (desc)
|
|
82
|
+
if (desc) {
|
|
83
|
+
return desc;
|
|
84
|
+
}
|
|
70
85
|
}
|
|
71
86
|
return void 0;
|
|
72
87
|
}
|
|
@@ -85,7 +100,8 @@ async function loadEntityMetadata(options) {
|
|
|
85
100
|
try {
|
|
86
101
|
orm = await MikroORM.init({
|
|
87
102
|
...options,
|
|
88
|
-
debug: false
|
|
103
|
+
debug: false,
|
|
104
|
+
connect: false
|
|
89
105
|
});
|
|
90
106
|
} catch (cause) {
|
|
91
107
|
throw new MetadataLoadError(
|
|
@@ -93,17 +109,13 @@ async function loadEntityMetadata(options) {
|
|
|
93
109
|
cause
|
|
94
110
|
);
|
|
95
111
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
return all;
|
|
104
|
-
} finally {
|
|
105
|
-
await orm.close(true);
|
|
112
|
+
const all = Object.values(orm.getMetadata().getAll());
|
|
113
|
+
if (all.length === 0) {
|
|
114
|
+
throw new MetadataLoadError(
|
|
115
|
+
"No entities were discovered. Check that your config specifies at least one entity path or class."
|
|
116
|
+
);
|
|
106
117
|
}
|
|
118
|
+
return all;
|
|
107
119
|
}
|
|
108
120
|
|
|
109
121
|
// src/render/mermaid.ts
|
|
@@ -125,9 +137,13 @@ function buildEntityModel(meta, metaByClass) {
|
|
|
125
137
|
const isStiChild = Boolean(meta.extends) && meta.discriminatorValue !== void 0;
|
|
126
138
|
const columns = [];
|
|
127
139
|
for (const prop of Object.values(meta.properties)) {
|
|
128
|
-
if (isStiRoot && prop.inherited === true)
|
|
140
|
+
if (isStiRoot && prop.inherited === true) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
129
143
|
const col = buildColumn(prop, metaByClass, meta);
|
|
130
|
-
if (col !== null)
|
|
144
|
+
if (col !== null) {
|
|
145
|
+
columns.push(col);
|
|
146
|
+
}
|
|
131
147
|
}
|
|
132
148
|
return {
|
|
133
149
|
className: meta.className,
|
|
@@ -141,7 +157,9 @@ function buildEntityModel(meta, metaByClass) {
|
|
|
141
157
|
};
|
|
142
158
|
}
|
|
143
159
|
function buildColumn(prop, metaByClass, owningMeta) {
|
|
144
|
-
if (prop.kind === ReferenceKind.EMBEDDED)
|
|
160
|
+
if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
145
163
|
if (prop.kind === ReferenceKind.SCALAR) {
|
|
146
164
|
const formulaExpr = prop.formula !== void 0 ? resolveFormulaExpr(prop.formula) : void 0;
|
|
147
165
|
let embeddedIn;
|
|
@@ -179,9 +197,12 @@ function buildColumn(prop, metaByClass, owningMeta) {
|
|
|
179
197
|
}
|
|
180
198
|
function resolveFormulaExpr(cb) {
|
|
181
199
|
try {
|
|
182
|
-
const cols = new Proxy(
|
|
183
|
-
|
|
184
|
-
|
|
200
|
+
const cols = new Proxy(
|
|
201
|
+
{},
|
|
202
|
+
{
|
|
203
|
+
get: (_target, key) => typeof key === "string" ? key : ""
|
|
204
|
+
}
|
|
205
|
+
);
|
|
185
206
|
return cb(FORMULA_DUMMY_TABLE, cols);
|
|
186
207
|
} catch {
|
|
187
208
|
return "";
|
|
@@ -189,7 +210,9 @@ function resolveFormulaExpr(cb) {
|
|
|
189
210
|
}
|
|
190
211
|
function resolveFkType(referencedClassName, metaByClass) {
|
|
191
212
|
const refMeta = metaByClass.get(referencedClassName);
|
|
192
|
-
if (!refMeta)
|
|
213
|
+
if (!refMeta) {
|
|
214
|
+
return "integer";
|
|
215
|
+
}
|
|
193
216
|
const pkProp = Object.values(refMeta.properties).find((p) => p.primary === true);
|
|
194
217
|
return pkProp ? normalizeType(pkProp.type) : "integer";
|
|
195
218
|
}
|
|
@@ -212,7 +235,9 @@ function buildConstraints(meta) {
|
|
|
212
235
|
});
|
|
213
236
|
}
|
|
214
237
|
for (const check of meta.checks ?? []) {
|
|
215
|
-
if (typeof check.expression !== "string")
|
|
238
|
+
if (typeof check.expression !== "string") {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
216
241
|
result.push({
|
|
217
242
|
type: "check",
|
|
218
243
|
properties: [],
|
|
@@ -225,10 +250,14 @@ function buildConstraints(meta) {
|
|
|
225
250
|
function buildRelationEdges(metas) {
|
|
226
251
|
const edges = [];
|
|
227
252
|
for (const meta of metas) {
|
|
228
|
-
if (meta.pivotTable || meta.embeddable)
|
|
253
|
+
if (meta.pivotTable || meta.embeddable) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
229
256
|
for (const prop of Object.values(meta.properties)) {
|
|
230
257
|
const edge = buildEdge(meta.className, prop);
|
|
231
|
-
if (edge !== null)
|
|
258
|
+
if (edge !== null) {
|
|
259
|
+
edges.push(edge);
|
|
260
|
+
}
|
|
232
261
|
}
|
|
233
262
|
}
|
|
234
263
|
return edges;
|
|
@@ -274,17 +303,19 @@ function renderErDiagram(model) {
|
|
|
274
303
|
lines.push(" }");
|
|
275
304
|
}
|
|
276
305
|
for (const rel of model.relations) {
|
|
277
|
-
lines.push(
|
|
278
|
-
` ${rel.fromEntity} ${rel.fromCardinality}--${rel.toCardinality} ${rel.toEntity} : "${rel.label}"`
|
|
279
|
-
);
|
|
306
|
+
lines.push(` ${rel.fromEntity} ${rel.fromCardinality}--${rel.toCardinality} ${rel.toEntity} : "${rel.label}"`);
|
|
280
307
|
}
|
|
281
308
|
return lines.join("\n");
|
|
282
309
|
}
|
|
283
310
|
function renderColumnLine(col) {
|
|
284
311
|
let qualifier = "";
|
|
285
|
-
if (col.isPrimary)
|
|
286
|
-
|
|
287
|
-
else if (col.
|
|
312
|
+
if (col.isPrimary) {
|
|
313
|
+
qualifier = " PK";
|
|
314
|
+
} else if (col.isForeignKey) {
|
|
315
|
+
qualifier = " FK";
|
|
316
|
+
} else if (col.isUnique) {
|
|
317
|
+
qualifier = " UK";
|
|
318
|
+
}
|
|
288
319
|
let comment;
|
|
289
320
|
if (col.formula !== void 0) {
|
|
290
321
|
comment = col.formula ? `formula: ${col.formula}` : "formula";
|
|
@@ -308,25 +339,27 @@ function buildDocumentModel(metas, jsDocResult, title, description) {
|
|
|
308
339
|
const enrichedByClass = /* @__PURE__ */ new Map();
|
|
309
340
|
for (const model of diagramEntities) {
|
|
310
341
|
const jsDoc = jsDocResult.entities.get(model.className);
|
|
311
|
-
if (jsDoc?.hidden)
|
|
342
|
+
if (jsDoc?.hidden) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
312
345
|
const propDocs = jsDocResult.props.get(model.className) ?? /* @__PURE__ */ new Map();
|
|
313
346
|
enrichedByClass.set(model.className, { model, jsDoc, propDocs });
|
|
314
347
|
}
|
|
315
348
|
const groupNames = /* @__PURE__ */ new Set();
|
|
316
349
|
let anyUntagged = false;
|
|
317
350
|
for (const { jsDoc } of enrichedByClass.values()) {
|
|
318
|
-
const allNs = [
|
|
319
|
-
...jsDoc?.namespaces ?? [],
|
|
320
|
-
...jsDoc?.erdNamespaces ?? [],
|
|
321
|
-
...jsDoc?.describeNamespaces ?? []
|
|
322
|
-
];
|
|
351
|
+
const allNs = [...jsDoc?.namespaces ?? [], ...jsDoc?.erdNamespaces ?? [], ...jsDoc?.describeNamespaces ?? []];
|
|
323
352
|
if (allNs.length === 0) {
|
|
324
353
|
anyUntagged = true;
|
|
325
354
|
} else {
|
|
326
|
-
for (const ns of allNs)
|
|
355
|
+
for (const ns of allNs) {
|
|
356
|
+
groupNames.add(ns);
|
|
357
|
+
}
|
|
327
358
|
}
|
|
328
359
|
}
|
|
329
|
-
if (anyUntagged)
|
|
360
|
+
if (anyUntagged) {
|
|
361
|
+
groupNames.add("default");
|
|
362
|
+
}
|
|
330
363
|
const groups = [];
|
|
331
364
|
for (const groupName of groupNames) {
|
|
332
365
|
const isDefault = groupName === "default";
|
|
@@ -337,30 +370,42 @@ function buildDocumentModel(metas, jsDocResult, title, description) {
|
|
|
337
370
|
({ jsDoc }) => belongsToGroupForText(jsDoc, groupName, isDefault)
|
|
338
371
|
);
|
|
339
372
|
const erdClassNames = new Set(erdEntities.map((e) => e.model.className));
|
|
340
|
-
const erdRelations = allRelations.filter(
|
|
341
|
-
(r) => erdClassNames.has(r.fromEntity) && erdClassNames.has(r.toEntity)
|
|
342
|
-
);
|
|
373
|
+
const erdRelations = allRelations.filter((r) => erdClassNames.has(r.fromEntity) && erdClassNames.has(r.toEntity));
|
|
343
374
|
groups.push({ name: groupName, erdEntities, textEntities, erdRelations });
|
|
344
375
|
}
|
|
345
376
|
groups.sort((a, b) => {
|
|
346
|
-
if (a.name === "default")
|
|
347
|
-
|
|
377
|
+
if (a.name === "default") {
|
|
378
|
+
return 1;
|
|
379
|
+
}
|
|
380
|
+
if (b.name === "default") {
|
|
381
|
+
return -1;
|
|
382
|
+
}
|
|
348
383
|
return a.name.localeCompare(b.name);
|
|
349
384
|
});
|
|
350
385
|
return { title, groups, ...description !== void 0 && { description } };
|
|
351
386
|
}
|
|
352
387
|
function hasNoNamespaceTags(jsDoc) {
|
|
353
|
-
if (!jsDoc)
|
|
388
|
+
if (!jsDoc) {
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
354
391
|
return jsDoc.namespaces.length === 0 && jsDoc.erdNamespaces.length === 0 && jsDoc.describeNamespaces.length === 0;
|
|
355
392
|
}
|
|
356
393
|
function belongsToGroupForErd(jsDoc, groupName, isDefault) {
|
|
357
|
-
if (isDefault)
|
|
358
|
-
|
|
394
|
+
if (isDefault) {
|
|
395
|
+
return hasNoNamespaceTags(jsDoc);
|
|
396
|
+
}
|
|
397
|
+
if (!jsDoc) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
359
400
|
return jsDoc.namespaces.includes(groupName) || jsDoc.erdNamespaces.includes(groupName);
|
|
360
401
|
}
|
|
361
402
|
function belongsToGroupForText(jsDoc, groupName, isDefault) {
|
|
362
|
-
if (isDefault)
|
|
363
|
-
|
|
403
|
+
if (isDefault) {
|
|
404
|
+
return hasNoNamespaceTags(jsDoc);
|
|
405
|
+
}
|
|
406
|
+
if (!jsDoc) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
364
409
|
return jsDoc.namespaces.includes(groupName) || jsDoc.describeNamespaces.includes(groupName);
|
|
365
410
|
}
|
|
366
411
|
|
|
@@ -395,9 +440,7 @@ function renderEntitySection(entity) {
|
|
|
395
440
|
parts.push(`> ${entity.jsDoc.description}`);
|
|
396
441
|
}
|
|
397
442
|
if (entity.model.discriminatorColumn) {
|
|
398
|
-
parts.push(
|
|
399
|
-
`*STI root \u2014 discriminator column: \`${entity.model.discriminatorColumn}\`*`
|
|
400
|
-
);
|
|
443
|
+
parts.push(`*STI root \u2014 discriminator column: \`${entity.model.discriminatorColumn}\`*`);
|
|
401
444
|
} else if (entity.model.extendsEntity) {
|
|
402
445
|
parts.push(`*Extends \`${entity.model.extendsEntity}\` (Single Table Inheritance)*`);
|
|
403
446
|
}
|
|
@@ -421,14 +464,24 @@ function renderColumnTable(entity) {
|
|
|
421
464
|
return [header, sep, ...rows].join("\n");
|
|
422
465
|
}
|
|
423
466
|
function resolveColumnKey(col) {
|
|
424
|
-
if (col.isPrimary)
|
|
467
|
+
if (col.isPrimary) {
|
|
468
|
+
return "PK";
|
|
469
|
+
}
|
|
425
470
|
if (col.isForeignKey) {
|
|
426
471
|
return col.fieldName !== col.propName ? `FK (${col.propName})` : "FK";
|
|
427
472
|
}
|
|
428
|
-
if (col.isUnique)
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
if (col.
|
|
473
|
+
if (col.isUnique) {
|
|
474
|
+
return "UK";
|
|
475
|
+
}
|
|
476
|
+
if (col.formula !== void 0) {
|
|
477
|
+
return `formula: ${col.formula}`;
|
|
478
|
+
}
|
|
479
|
+
if (col.isDiscriminator) {
|
|
480
|
+
return "discriminator";
|
|
481
|
+
}
|
|
482
|
+
if (col.embeddedIn !== void 0) {
|
|
483
|
+
return `[${col.embeddedIn}]`;
|
|
484
|
+
}
|
|
432
485
|
return "";
|
|
433
486
|
}
|
|
434
487
|
function renderConstraints(constraints) {
|