@@ -9,6 +9,7 @@ import * as md from '../metadata';
99import { CatalogLayout } from '../layout' ;
1010
1111const OVERVIEW_ASPECT_KEY = 'dataplex-types.global.overview' ;
12+ const DEFAULT_ENTRY_TYPE = 'dataplex-types.global.generic' ;
1213
1314
1415export class DocumentsLayout implements CatalogLayout {
@@ -38,9 +39,8 @@ export class DocumentsLayout implements CatalogLayout {
3839 try {
3940 const content = await fs . promises . readFile ( localPath , 'utf8' ) ;
4041 const { entry } = parseMarkdown ( content ) ;
41- if ( entry && entry . name ) {
42- this . _index . set ( entry . name , localPath ) ;
43- }
42+ const name = entry ?. name ?? deriveEntryNameFromPath ( localPath , this . _catalogPath ) ;
43+ this . _index . set ( name , localPath ) ;
4444 }
4545 catch ( err ) {
4646 // Skip unreadable/invalid files during indexing
@@ -63,12 +63,17 @@ export class DocumentsLayout implements CatalogLayout {
6363 throw new Error ( `Entry not found: ${ name } ` ) ;
6464 }
6565 const content = await fs . promises . readFile ( entryPath , 'utf8' ) ;
66- const { entry, body } = parseMarkdown ( content ) ;
66+ const { entry : parsed , body } = parseMarkdown ( content ) ;
6767
68- if ( ! entry ) {
69- throw new Error ( `Missing YAML frontmatter in Markdown file: ${ entryPath } ` ) ;
68+ const entry : md . Entry = parsed ?? ( { type : DEFAULT_ENTRY_TYPE , resource : { } } as md . Entry ) ;
69+ if ( ! entry . name ) {
70+ entry . name = name ;
7071 }
71-
72+
73+ // Ensure the entry's type aspect is present — Dataplex create requires it.
74+ entry . aspects = entry . aspects ?? { } ;
75+ entry . aspects [ entry . type ] = entry . aspects [ entry . type ] ?? { } ;
76+
7277 const bodyTrimmed = body . trim ( ) ;
7378 if ( bodyTrimmed ) {
7479 if ( ! entry . aspects ) {
@@ -117,6 +122,11 @@ export class DocumentsLayout implements CatalogLayout {
117122 }
118123}
119124
125+ function deriveEntryNameFromPath ( absolutePath : string , catalogPath : string ) : string {
126+ const rel = path . relative ( catalogPath , absolutePath ) ;
127+ return rel . replace ( / \. m d $ / , '' ) ;
128+ }
129+
120130export function parseMarkdown ( content : string ) : { entry : md . Entry | null ; body : string } {
121131 const lines = content . split ( / \r ? \n / ) ;
122132 if ( lines [ 0 ] !== '---' ) {
@@ -132,7 +142,10 @@ export function parseMarkdown(content: string): { entry: md.Entry|null; body: st
132142 const body = lines . slice ( endIndex + 1 ) . join ( '\n' ) ;
133143
134144 const entry = ( metadata . catalogEntry ?? { } ) as md . Entry ;
135- entry . type = metadata . type ;
145+ const declaredType = metadata . type ;
146+ entry . type = ( typeof declaredType === 'string' && declaredType . startsWith ( 'dataplex-types.' ) )
147+ ? declaredType
148+ : DEFAULT_ENTRY_TYPE ;
136149 entry . resource = entry . resource ?? { }
137150 entry . resource . displayName = metadata . title ;
138151 entry . resource . description = metadata . description ;
0 commit comments