Skip to content

Commit 81c10df

Browse files
dmealingclaude
andcommitted
feat(#208): TS MetaSource @sql/@Unmanaged resolving accessors
Task 2 — add `sqlBody` (the @SQL hand-written body, narrowed to a non-empty string) and `isUnmanaged` (the @Unmanaged flag) resolving accessors to the TS MetaSource, next to effectiveKind/role. RESOLVING (ADR-0039) — sources are inheritable, so these read the effective attr via attr(...), not own-only. Consumed by the loader validation, suppression, and migrate tasks that follow. Gated by a new TDD test; full metadata suite 2188/2188 + typecheck clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NGQ7oSuNcjhsMHWwZzhBwr
1 parent 5ecacb0 commit 81c10df

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

server/typescript/packages/metadata/src/persistence/source/meta-source.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
SOURCE_ATTR_FUNCTION,
1616
SOURCE_ATTR_KIND,
1717
SOURCE_ATTR_ROLE,
18+
SOURCE_ATTR_SQL,
19+
SOURCE_ATTR_UNMANAGED,
1820
SOURCE_READ_ONLY_KINDS,
1921
DEFAULT_SOURCE_KIND,
2022
DEFAULT_SOURCE_ROLE,
@@ -59,6 +61,27 @@ export class MetaSource extends MetaData {
5961
return typeof v === "string" && v !== "" ? v : DEFAULT_SOURCE_ROLE;
6062
}
6163

64+
/**
65+
* FR-024/#208 — the hand-written SQL body for this source's DB object, when
66+
* declared via `@sql`. The tool registers + fingerprints + drift-checks this
67+
* body but never authors or parses it.
68+
*/
69+
get sqlBody(): string | undefined {
70+
// ADR-0039: resolving — an inherited source's @sql lives on the super node.
71+
const v = this.attr(SOURCE_ATTR_SQL);
72+
return typeof v === "string" && v !== "" ? v : undefined;
73+
}
74+
75+
/**
76+
* FR-024/#208 — true when this source's DB object is managed elsewhere
77+
* (Flyway / a hand-migration owns its DDL); `meta migrate` does not
78+
* create/drop/drift-check it.
79+
*/
80+
get isUnmanaged(): boolean {
81+
// ADR-0039: resolving — an inherited source's @unmanaged lives on the super node.
82+
return this.attr(SOURCE_ATTR_UNMANAGED) === true;
83+
}
84+
6285
/**
6386
* True when this source's effective kind is read-only (view, materializedView,
6487
* storedProc, tableFunction). Derived from the @kind attr on source.rdb.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// #208 Task 2 — MetaSource resolving accessors for @sql / @unmanaged
2+
// (registered in Task 1, commit 5ecacb01). Mirrors the effectiveKind/role
3+
// accessor test pattern in test/source-rdb.test.ts.
4+
5+
import { expect, test } from "bun:test";
6+
import { loadString } from "../src/index.js";
7+
import { MetaSource } from "../src/persistence/source/meta-source.js";
8+
9+
test("MetaSource exposes @sql body and @unmanaged flag (resolving)", async () => {
10+
const { root } = await loadString(
11+
`{"metadata.root":{"package":"t","children":[
12+
{"object.projection":{"name":"R","children":[
13+
{"source.rdb":{"@kind":"view","@view":"v_r","@sql":"SELECT 1"}},
14+
{"field.int":{"name":"x"}}]}}]}}`,
15+
"json",
16+
);
17+
const src = root
18+
.findObject("R")!
19+
.ownChildren()
20+
.find((c) => c instanceof MetaSource)! as MetaSource;
21+
expect(src.sqlBody).toBe("SELECT 1");
22+
expect(src.isUnmanaged).toBe(false);
23+
});

0 commit comments

Comments
 (0)