Skip to content

Commit 1bc77f2

Browse files
amirhormaticlaude
andcommitted
Make push work for hierarchical entries and bare-markdown layouts
Fix entry ID truncation that broke nested entries like tables/events_, and let the Documents Layout accept markdown files without explicit catalogEntry frontmatter (name inferred from path, type defaulted to generic, required type aspect auto-injected). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 7768efd commit 1bc77f2

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

toolbox/mdcode/src/libts/layouts/documents.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as md from '../metadata';
99
import { CatalogLayout } from '../layout';
1010

1111
const OVERVIEW_ASPECT_KEY = 'dataplex-types.global.overview';
12+
const DEFAULT_ENTRY_TYPE = 'dataplex-types.global.generic';
1213

1314

1415
export 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(/\.md$/, '');
128+
}
129+
120130
export 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;

toolbox/mdcode/src/libts/sync.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,12 @@ export class CatalogSync {
8181

8282
const exist = await this._catalog.lookupEntry(project, location, entry.name);
8383
if (exist.status != 200 || !exist.result) {
84-
console.log(`entry ${name} does not exist, will try to create the entry.`);
85-
8684
const entryGroup = nameParts[5];
87-
const entryId = nameParts[7];
85+
const entryId = nameParts.slice(7).join('/');
8886
const createEntryRes = await this._catalog.createEntry(project, location, entryGroup, entryId, entry);
8987
if (createEntryRes.status != 200 || !createEntryRes.result) {
90-
console.log(`Failed to push entry ${entry.name}: Failed to create new entry.`);
88+
return { success: false, details: `Failed to create entry ${entry.name}: ${createEntryRes.message || createEntryRes.status}` };
9189
}
92-
console.log(`Successfully created and pushed entry ${entry.name}`);
9390
continue;
9491
}
9592

0 commit comments

Comments
 (0)