@metaobjectsdev/codegen-ts 0.23.2 → 0.24.0
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/dist/generator.d.ts +9 -0
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js.map +1 -1
- package/dist/generators/api-field-shape.js +1 -1
- package/dist/generators/api-field-shape.js.map +1 -1
- package/dist/generators/api-model.d.ts.map +1 -1
- package/dist/generators/api-model.js +71 -42
- package/dist/generators/api-model.js.map +1 -1
- package/dist/generators/docs-data-builder.d.ts.map +1 -1
- package/dist/generators/docs-data-builder.js +36 -1
- package/dist/generators/docs-data-builder.js.map +1 -1
- package/dist/generators/docs-data.d.ts +14 -0
- package/dist/generators/docs-data.d.ts.map +1 -1
- package/dist/generators/docs-file.d.ts.map +1 -1
- package/dist/generators/docs-file.js +13 -4
- package/dist/generators/docs-file.js.map +1 -1
- package/dist/generators/extractor-file.d.ts.map +1 -1
- package/dist/generators/extractor-file.js +7 -11
- package/dist/generators/extractor-file.js.map +1 -1
- package/dist/generators/index.d.ts +4 -0
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +5 -0
- package/dist/generators/index.js.map +1 -1
- package/dist/generators/output-parser-file.d.ts.map +1 -1
- package/dist/generators/output-parser-file.js +12 -7
- package/dist/generators/output-parser-file.js.map +1 -1
- package/dist/generators/output-prompt-file.d.ts.map +1 -1
- package/dist/generators/output-prompt-file.js +14 -24
- package/dist/generators/output-prompt-file.js.map +1 -1
- package/dist/generators/requirement-tests.d.ts +44 -0
- package/dist/generators/requirement-tests.d.ts.map +1 -0
- package/dist/generators/requirement-tests.js +127 -0
- package/dist/generators/requirement-tests.js.map +1 -0
- package/dist/generators/requirements-file.d.ts +9 -0
- package/dist/generators/requirements-file.d.ts.map +1 -0
- package/dist/generators/requirements-file.js +53 -0
- package/dist/generators/requirements-file.js.map +1 -0
- package/dist/generators/requirements-markdown.d.ts +10 -0
- package/dist/generators/requirements-markdown.d.ts.map +1 -0
- package/dist/generators/requirements-markdown.js +71 -0
- package/dist/generators/requirements-markdown.js.map +1 -0
- package/dist/generators/requirements-toon.d.ts +3 -0
- package/dist/generators/requirements-toon.d.ts.map +1 -0
- package/dist/generators/requirements-toon.js +47 -0
- package/dist/generators/requirements-toon.js.map +1 -0
- package/dist/generators/requirements-view.d.ts +32 -0
- package/dist/generators/requirements-view.d.ts.map +1 -0
- package/dist/generators/requirements-view.js +64 -0
- package/dist/generators/requirements-view.js.map +1 -0
- package/dist/generators/trace-helper-file.d.ts.map +1 -1
- package/dist/generators/trace-helper-file.js +19 -11
- package/dist/generators/trace-helper-file.js.map +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/metaobjects-config.d.ts +12 -20
- package/dist/metaobjects-config.d.ts.map +1 -1
- package/dist/metaobjects-config.js +5 -1
- package/dist/metaobjects-config.js.map +1 -1
- package/dist/orphan-sweep.d.ts +38 -0
- package/dist/orphan-sweep.d.ts.map +1 -0
- package/dist/orphan-sweep.js +129 -0
- package/dist/orphan-sweep.js.map +1 -0
- package/dist/overwrite-policy.d.ts +97 -3
- package/dist/overwrite-policy.d.ts.map +1 -1
- package/dist/overwrite-policy.js +293 -81
- package/dist/overwrite-policy.js.map +1 -1
- package/dist/projection/build-projection-views.d.ts +8 -0
- package/dist/projection/build-projection-views.d.ts.map +1 -1
- package/dist/projection/build-projection-views.js +2 -0
- package/dist/projection/build-projection-views.js.map +1 -1
- package/dist/reconcile-orphans.d.ts +80 -0
- package/dist/reconcile-orphans.d.ts.map +1 -0
- package/dist/reconcile-orphans.js +61 -0
- package/dist/reconcile-orphans.js.map +1 -0
- package/dist/render-engine/embedded-templates.generated.js +1 -1
- package/dist/render-engine/embedded-templates.generated.js.map +1 -1
- package/dist/requirement-walk.d.ts +57 -0
- package/dist/requirement-walk.d.ts.map +1 -0
- package/dist/requirement-walk.js +94 -0
- package/dist/requirement-walk.js.map +1 -0
- package/dist/runner.d.ts +35 -0
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +217 -21
- package/dist/runner.js.map +1 -1
- package/dist/templates/extractor.d.ts +4 -4
- package/dist/templates/extractor.d.ts.map +1 -1
- package/dist/templates/extractor.js +18 -22
- package/dist/templates/extractor.js.map +1 -1
- package/dist/templates/find-inbound.d.ts +44 -0
- package/dist/templates/find-inbound.d.ts.map +1 -0
- package/dist/templates/find-inbound.js +69 -0
- package/dist/templates/find-inbound.js.map +1 -0
- package/dist/templates/output-format-spec-emitter.d.ts.map +1 -1
- package/dist/templates/output-format-spec-emitter.js +7 -4
- package/dist/templates/output-format-spec-emitter.js.map +1 -1
- package/dist/templates/output-parser.d.ts +8 -3
- package/dist/templates/output-parser.d.ts.map +1 -1
- package/dist/templates/output-parser.js +71 -31
- package/dist/templates/output-parser.js.map +1 -1
- package/dist/templates/output-prompt.d.ts +6 -5
- package/dist/templates/output-prompt.d.ts.map +1 -1
- package/dist/templates/output-prompt.js +26 -37
- package/dist/templates/output-prompt.js.map +1 -1
- package/dist/templates/queries.js +1 -1
- package/dist/templates/queries.js.map +1 -1
- package/dist/templates/requirement-test.d.ts +12 -0
- package/dist/templates/requirement-test.d.ts.map +1 -0
- package/dist/templates/requirement-test.js +120 -0
- package/dist/templates/requirement-test.js.map +1 -0
- package/dist/templates/zod-validators.d.ts.map +1 -1
- package/dist/templates/zod-validators.js +32 -15
- package/dist/templates/zod-validators.js.map +1 -1
- package/package.json +7 -6
- package/src/generator.ts +9 -0
- package/src/generators/api-field-shape.ts +1 -1
- package/src/generators/api-model.ts +69 -44
- package/src/generators/docs-data-builder.ts +37 -0
- package/src/generators/docs-data.ts +15 -0
- package/src/generators/docs-file.ts +13 -4
- package/src/generators/extractor-file.ts +7 -11
- package/src/generators/index.ts +11 -0
- package/src/generators/output-parser-file.ts +12 -7
- package/src/generators/output-prompt-file.ts +14 -27
- package/src/generators/requirement-tests.ts +203 -0
- package/src/generators/requirements-file.ts +71 -0
- package/src/generators/requirements-markdown.ts +72 -0
- package/src/generators/requirements-toon.ts +64 -0
- package/src/generators/requirements-view.ts +93 -0
- package/src/generators/trace-helper-file.ts +20 -10
- package/src/index.ts +47 -1
- package/src/metaobjects-config.ts +17 -22
- package/src/orphan-sweep.ts +178 -0
- package/src/overwrite-policy.ts +362 -89
- package/src/projection/build-projection-views.ts +10 -0
- package/src/reconcile-orphans.ts +136 -0
- package/src/reference/barrel.ts +4 -0
- package/src/reference/entity.ts +4 -0
- package/src/reference/queries.ts +4 -0
- package/src/reference/routes.ts +4 -0
- package/src/render-engine/embedded-templates.generated.ts +1 -1
- package/src/requirement-walk.ts +124 -0
- package/src/runner.ts +266 -27
- package/src/templates/extractor.ts +19 -24
- package/src/templates/find-inbound.ts +96 -0
- package/src/templates/output-format-spec-emitter.ts +7 -4
- package/src/templates/output-parser.ts +76 -34
- package/src/templates/output-prompt.ts +29 -42
- package/src/templates/queries.ts +1 -1
- package/src/templates/requirement-test.ts +140 -0
- package/src/templates/zod-validators.ts +32 -15
- package/templates/docs/entity-page.md.mustache +8 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// FR-038 §8 — deletion integrity: what happens to a generated file that is no
|
|
2
|
+
// longer generated.
|
|
3
|
+
//
|
|
4
|
+
// A requirement's stubs become orphans when the requirement is deleted. The
|
|
5
|
+
// obvious move — remove them, as the FR-038 draft said for `abandoned` entries —
|
|
6
|
+
// is safe only for an UNTOUCHED stub. On a filled one it eats assertions somebody
|
|
7
|
+
// wrote, and the whole point of the inversion is that the body is hand-written and
|
|
8
|
+
// survives regeneration.
|
|
9
|
+
//
|
|
10
|
+
// So: remove what the generator wrote, REFUSE what a human changed, and name it.
|
|
11
|
+
// That mirrors the migrate engine refusing a primary-key move rather than emitting
|
|
12
|
+
// something un-appliable (#258) — a refusal is recoverable, a deletion is not.
|
|
13
|
+
//
|
|
14
|
+
// Deliberately PURE: the caller supplies the readers. The decision is the part
|
|
15
|
+
// worth testing, and threading a filesystem through it would make the rule harder
|
|
16
|
+
// to exercise than the plumbing around it.
|
|
17
|
+
export function reconcileOrphans(args) {
|
|
18
|
+
const emitted = new Set(args.emitted);
|
|
19
|
+
const remove = [];
|
|
20
|
+
const refused = [];
|
|
21
|
+
const vanished = [];
|
|
22
|
+
for (const relPath of args.previouslyGenerated) {
|
|
23
|
+
if (emitted.has(relPath))
|
|
24
|
+
continue;
|
|
25
|
+
if (!args.owns(relPath))
|
|
26
|
+
continue;
|
|
27
|
+
if (!args.exists(relPath)) {
|
|
28
|
+
vanished.push(relPath);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// Fail closed: unless we can prove the file is untouched, guessing wrong
|
|
32
|
+
// deletes someone's work.
|
|
33
|
+
if (!args.isUntouched(relPath)) {
|
|
34
|
+
refused.push(relPath);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
remove.push(relPath);
|
|
38
|
+
}
|
|
39
|
+
return { remove, refused, vanished };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The message shown when a hand-edited orphan is refused.
|
|
43
|
+
*
|
|
44
|
+
* It has to say what happened, why nothing was deleted, and what the two ways out
|
|
45
|
+
* are — otherwise the reasonable reaction to an unexplained refusal is to delete
|
|
46
|
+
* the file, which is the outcome the refusal exists to prevent.
|
|
47
|
+
*/
|
|
48
|
+
export function refusedOrphanMessage(paths,
|
|
49
|
+
/** Which generator's namespace these came from. `orphanPolicy` is a generic
|
|
50
|
+
* `Generator` field and `sweepOrphans`/`OrphanPolicy` are exported precisely so an
|
|
51
|
+
* app can compose its own — so this message must not hardcode `requirement-tests`,
|
|
52
|
+
* naming a generator the project may not even use and a cause ("the requirement was
|
|
53
|
+
* removed") that may not apply. */
|
|
54
|
+
generatorName = "orphan cleanup") {
|
|
55
|
+
return (`${generatorName}: ${paths.length} generated file(s) are no longer produced by ` +
|
|
56
|
+
`this generator but have been edited by hand, so they were NOT deleted: ` +
|
|
57
|
+
`${paths.join(", ")}. Either what produced them was removed (delete these files ` +
|
|
58
|
+
`yourself if the edits are no longer wanted) or it was renamed (move the edits ` +
|
|
59
|
+
`into the newly generated file first — regeneration cannot follow a rename).`);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=reconcile-orphans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile-orphans.js","sourceRoot":"","sources":["../src/reconcile-orphans.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,oBAAoB;AACpB,EAAE;AACF,4EAA4E;AAC5E,iFAAiF;AACjF,kFAAkF;AAClF,mFAAmF;AACnF,yBAAyB;AACzB,EAAE;AACF,iFAAiF;AACjF,mFAAmF;AACnF,+EAA+E;AAC/E,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,2CAA2C;AAqE3C,MAAM,UAAU,gBAAgB,CAAC,IAA0B;IACzD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC/C,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,SAAS;QACnC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,SAAS;QAElC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,SAAS;QACX,CAAC;QAED,yEAAyE;QACzE,0BAA0B;QAC1B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtB,SAAS;QACX,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAwB;AACxB;;;;oCAIoC;AACpC,aAAa,GAAG,gBAAgB;IAEhC,OAAO,CACL,GAAG,aAAa,KAAK,KAAK,CAAC,MAAM,+CAA+C;QAChF,yEAAyE;QACzE,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,8DAA8D;QACjF,gFAAgF;QAChF,6EAA6E,CAC9E,CAAC;AACJ,CAAC"}
|
|
@@ -9,7 +9,7 @@ export const EMBEDDED_FRAMEWORK_TEMPLATES = {
|
|
|
9
9
|
"api/agent-api.md": "{{{generatedMarker}}}\n\n# {{title}}\n\nGenerated API reference for {{project}}; call these exactly as written. {{importNote}}\n{{#hasSetup}}\n\n## Setup\n{{#setup}}\n- `{{handle}}` — {{{note}}} `{{{snippetInline}}}`\n{{/setup}}\n{{/hasSetup}}\n{{#units}}\n\n## {{node}}\n{{#groups}}\n\n`{{importHeader}}`\n{{#symbols}}\n- `{{signature}}` — {{usage}}{{#throwsMarker}} {{throwsMarker}}{{/throwsMarker}}\n{{/symbols}}\n{{/groups}}\n{{#example}}\n\nExample:\n```ts\n{{{example}}}\n```\n{{/example}}\n{{/units}}\n",
|
|
10
10
|
"api/entity-api.md": "{{{generatedMarker}}}\n\n# {{node}} API\n{{#modelPageHref}}\n\n**Model / metadata:** [{{node}}]({{modelPageHref}})\n{{/modelPageHref}}\n\n> Import paths are relative to your generated-output directory.\n{{#hasSetup}}\n\n## Setup\n\nObtain the runtime handles the calls below need:\n{{#setup}}\n\n- `{{handle}}` — {{{note}}}\n\n```ts\n{{{snippet}}}\n```\n{{/setup}}\n{{/hasSetup}}\n{{#unitExample}}\n\n## Example\n\n```ts\n{{{unitExample}}}\n```\n{{/unitExample}}\n{{#sections}}\n\n## {{heading}}\n{{#symbols}}\n\n### `{{signature}}`\n\n{{usage}}\n\n```ts\n{{importLine}}\n```\n{{#hasFields}}\n\n{{fieldsCaption}}:\n\n| Field | Type | Required | Notes |\n|---|---|---|---|\n{{#fieldRows}}\n| `{{field}}` | `{{{type}}}` | {{required}} | {{notes}} |\n{{/fieldRows}}\n{{/hasFields}}\n{{#mountNote}}\n\nMount: {{{mountNote}}}\n{{/mountNote}}\n{{#throws}}\n\nThrows: {{throws}}\n{{/throws}}\n{{#example}}\n\n```ts\n{{{example}}}\n```\n{{/example}}\n{{/symbols}}\n{{/sections}}\n",
|
|
11
11
|
"api/index.md": "{{{generatedMarker}}}\n\n# {{title}}\n\n{{intro}}\n{{#hasEntities}}\n\n## Entities\n\n{{#entities}}\n- [{{node}}]({{href}}) — {{summary}} ({{symbolCount}} symbol{{^one}}s{{/one}})\n{{/entities}}\n{{/hasEntities}}\n{{#hasTemplates}}\n\n## Templates\n\n{{#templates}}\n- [{{node}}]({{href}}) — {{summary}} ({{symbolCount}} symbol{{^one}}s{{/one}})\n{{/templates}}\n{{/hasTemplates}}\n",
|
|
12
|
-
"docs/entity-page.md": "{{{generatedMarker}}}\n\n# {{entity.name}}\n{{#summaryLead}}\n\n{{{.}}}\n{{/summaryLead}}\n{{#descriptionQuote}}\n\n{{{.}}}\n{{/descriptionQuote}}\n{{#apiRefs.0}}\n\n**API reference:** {{/apiRefs.0}}{{#apiRefs}}[{{label}}]({{href}}){{^last}} · {{/last}}{{/apiRefs}}{{#apiRefs.0}}\n{{/apiRefs.0}}\n\n{{{preambleHeader}}}\n{{#hasIdentities}}\n\n## Identity\n\n{{#identities}}\n- {{{bullet}}}\n{{/identities}}\n{{/hasIdentities}}\n{{#hasNeighborhoodEr}}\n\n## In context\n\n{{{neighborhoodErBlock}}}\n{{/hasNeighborhoodEr}}\n{{#fields.hasFields}}\n\n## Fields\n\n| Field | Type | Required | Column | Rules |\n|---|---|---|---|---|\n{{#fields.rows}}\n| {{{fieldCell}}} | {{{typeCell}}} | {{requiredCell}} | {{{storageCell}}} | {{{rulesCell}}} |\n{{/fields.rows}}\n{{/fields.hasFields}}\n{{#fieldDetails.hasDetails}}\n\n## Field details\n\n{{#fieldDetails.rows}}\n{{{block}}}\n\n{{/fieldDetails.rows}}\n{{/fieldDetails.hasDetails}}\n{{#hasRelationships}}\n\n## Relationships\n\n{{#relationships}}\n- {{{bullet}}}\n{{/relationships}}\n{{/hasRelationships}}\n{{#hasUsedBy}}\n\n## Used by\n\n{{#usedBy}}\n- {{{bullet}}}\n{{/usedBy}}\n{{/hasUsedBy}}\n",
|
|
12
|
+
"docs/entity-page.md": "{{{generatedMarker}}}\n\n# {{entity.name}}\n{{#summaryLead}}\n\n{{{.}}}\n{{/summaryLead}}\n{{#descriptionQuote}}\n\n{{{.}}}\n{{/descriptionQuote}}\n{{#apiRefs.0}}\n\n**API reference:** {{/apiRefs.0}}{{#apiRefs}}[{{label}}]({{href}}){{^last}} · {{/last}}{{/apiRefs}}{{#apiRefs.0}}\n{{/apiRefs.0}}\n\n{{{preambleHeader}}}\n{{#hasIdentities}}\n\n## Identity\n\n{{#identities}}\n- {{{bullet}}}\n{{/identities}}\n{{/hasIdentities}}\n{{#hasNeighborhoodEr}}\n\n## In context\n\n{{{neighborhoodErBlock}}}\n{{/hasNeighborhoodEr}}\n{{#fields.hasFields}}\n\n## Fields\n\n| Field | Type | Required | Column | Rules |\n|---|---|---|---|---|\n{{#fields.rows}}\n| {{{fieldCell}}} | {{{typeCell}}} | {{requiredCell}} | {{{storageCell}}} | {{{rulesCell}}} |\n{{/fields.rows}}\n{{/fields.hasFields}}\n{{#fieldDetails.hasDetails}}\n\n## Field details\n\n{{#fieldDetails.rows}}\n{{{block}}}\n\n{{/fieldDetails.rows}}\n{{/fieldDetails.hasDetails}}\n{{#hasRelationships}}\n\n## Relationships\n\n{{#relationships}}\n- {{{bullet}}}\n{{/relationships}}\n{{/hasRelationships}}\n{{#hasUsedBy}}\n\n## Used by\n\n{{#usedBy}}\n- {{{bullet}}}\n{{/usedBy}}\n{{/hasUsedBy}}\n{{#hasClaimedBy}}\n\n## Required by\n\n{{#claimedBy}}\n- {{{bullet}}}\n{{/claimedBy}}\n{{/hasClaimedBy}}\n",
|
|
13
13
|
"docs/template-page.md": "{{{generatedMarker}}}\n\n# {{name}}\n{{#descriptionQuote}}\n\n{{{.}}}\n{{/descriptionQuote}}\n\n**Kind:** {{kind}}\n\n## Output\n{{^isEmail}}\n\n- Format: `{{format}}`\n{{/isEmail}}\n{{#isEmail}}\n\nMultipart email — rendered as the following parts:\n\n| Part | Source | Format | Escaping |\n|---|---|---|---|\n{{#parts}}\n| {{label}} | `{{ref}}` | `{{format}}` | {{#escaped}}escaped{{/escaped}}{{^escaped}}raw{{/escaped}} |\n{{/parts}}\n{{/isEmail}}\n\n## Input\n\n- Payload: [`{{payload.name}}`]({{payload.link}})\n{{#hasRequiredTags}}\n- Required fields:{{#requiredTags}} `{{.}}`{{/requiredTags}}\n{{/hasRequiredTags}}\n\n## Render contract\n\n- Every field referenced by the template is validated against the payload at generation time; an unknown field fails generation.\n{{#maxChars}}\n- Maximum length: {{.}} characters (rendering longer output fails).\n{{/maxChars}}\n{{#hasRequiredTags}}\n- Required tags must be present:{{#requiredTags}} `{{.}}`{{/requiredTags}}\n{{/hasRequiredTags}}\n\n## Source\n\n{{#sourceRefs}}\n- `{{.}}`\n{{/sourceRefs}}\n{{#templateSourceSection}}\n\n{{{.}}}\n{{/templateSourceSection}}\n\n## Capability\n\n{{capability}}\n",
|
|
14
14
|
};
|
|
15
15
|
//# sourceMappingURL=embedded-templates.generated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedded-templates.generated.js","sourceRoot":"","sources":["../../src/render-engine/embedded-templates.generated.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,iGAAiG;AACjG,EAAE;AACF,8DAA8D;AAC9D,oEAAoE;AACpE,wEAAwE;AACxE,sDAAsD;AACtD,MAAM,CAAC,MAAM,4BAA4B,GAA2B;IAClE,kBAAkB,EAAE,+fAA+f;IACnhB,mBAAmB,EAAE,88BAA88B;IACn+B,cAAc,EAAE,gYAAgY;IAChZ,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"embedded-templates.generated.js","sourceRoot":"","sources":["../../src/render-engine/embedded-templates.generated.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,iGAAiG;AACjG,EAAE;AACF,8DAA8D;AAC9D,oEAAoE;AACpE,wEAAwE;AACxE,sDAAsD;AACtD,MAAM,CAAC,MAAM,4BAA4B,GAA2B;IAClE,kBAAkB,EAAE,+fAA+f;IACnhB,mBAAmB,EAAE,88BAA88B;IACn+B,cAAc,EAAE,gYAAgY;IAChZ,qBAAqB,EAAE,kuCAAkuC;IACzvC,uBAAuB,EAAE,woCAAwoC;CAClqC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { MetaData, MetaRequirement } from "@metaobjectsdev/metadata";
|
|
2
|
+
/** The shape an app's `filter` receives. Never the node itself. */
|
|
3
|
+
export interface RequirementView {
|
|
4
|
+
/** "functional" | "architectural" — the check-polarity axis. */
|
|
5
|
+
readonly subType: string;
|
|
6
|
+
/** 1 solution · 2 segment · 3 service · 4 object · 5 member. Undefined on an
|
|
7
|
+
* unlevelled architectural requirement (the original flat policy form). */
|
|
8
|
+
readonly level: number | undefined;
|
|
9
|
+
readonly status: string | undefined;
|
|
10
|
+
/** Dotted path from the root through nesting ancestors — hierarchy is nesting. */
|
|
11
|
+
readonly path: string;
|
|
12
|
+
/** DISTINCT `type.subType` concerns among the resolved targets. */
|
|
13
|
+
readonly implementedByTypes: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
export interface ResolvedClaim {
|
|
16
|
+
/** The reference exactly as authored, for the doc comment. */
|
|
17
|
+
readonly ref: string;
|
|
18
|
+
readonly node: MetaData;
|
|
19
|
+
readonly concern: string;
|
|
20
|
+
}
|
|
21
|
+
export interface WalkedRequirement {
|
|
22
|
+
readonly node: MetaRequirement;
|
|
23
|
+
readonly view: RequirementView;
|
|
24
|
+
readonly targets: readonly ResolvedClaim[];
|
|
25
|
+
}
|
|
26
|
+
/** `<type>.<subType>` — the key a renderer map is looked up by. */
|
|
27
|
+
export declare function concernOf(node: MetaData): string;
|
|
28
|
+
/**
|
|
29
|
+
* The concern key for a requirement that resolves NO targets.
|
|
30
|
+
*
|
|
31
|
+
* Doubles as the catch-all renderer key, deliberately: a requirement with nothing
|
|
32
|
+
* to fan out over falls through to whatever the app registered as its default.
|
|
33
|
+
*/
|
|
34
|
+
export declare const NO_CONCERN = "*";
|
|
35
|
+
/**
|
|
36
|
+
* Depth-first walk of every `requirement.*` node, nested ones included.
|
|
37
|
+
*
|
|
38
|
+
* Unresolvable `@implementedBy` references are skipped rather than thrown on —
|
|
39
|
+
* resolution severity is `meta verify`'s job (it depends on `@status`, which is why
|
|
40
|
+
* it cannot live in the loader), and codegen must not fail a build over a
|
|
41
|
+
* diagnostic another command owns.
|
|
42
|
+
*/
|
|
43
|
+
export declare function walkRequirements(root: MetaData): WalkedRequirement[];
|
|
44
|
+
/**
|
|
45
|
+
* Group a requirement's targets by distinct concern — the fan-out unit.
|
|
46
|
+
*
|
|
47
|
+
* One entry per distinct `type.subType`, NOT one per target: a single architectural
|
|
48
|
+
* requirement claimed by 123 entities must emit one stub, not 123, which is the
|
|
49
|
+
* hostile-first-contact outcome FR-038 §10 exists to avoid.
|
|
50
|
+
*
|
|
51
|
+
* A requirement resolving NO targets still yields exactly ONE group. That is not a
|
|
52
|
+
* degenerate case: `REQUIREMENT_LINK_FLOOR_LEVEL` forbids `@implementedBy` below L4,
|
|
53
|
+
* so every L1–L3 requirement resolves nothing — and an application that chooses to
|
|
54
|
+
* cover L3 would otherwise get silence instead of a stub.
|
|
55
|
+
*/
|
|
56
|
+
export declare function groupByConcern(w: WalkedRequirement): Map<string, ResolvedClaim[]>;
|
|
57
|
+
//# sourceMappingURL=requirement-walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requirement-walk.d.ts","sourceRoot":"","sources":["../src/requirement-walk.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE1E,mEAAmE;AACnE,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;gFAC4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;CAChD;AAED,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,CAAC;CAC5C;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,MAAM,CAAC;AAE9B;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,iBAAiB,EAAE,CAmCpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC,CASjF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// FR-038 — walking `requirement.*` nodes and projecting them for downstream filters.
|
|
2
|
+
//
|
|
3
|
+
// WHY A WALK RATHER THAN ctx.matches: the `Generator` contract is entity-shaped —
|
|
4
|
+
// `GenContext.entities` is `MetaObject[]` and `filter` is
|
|
5
|
+
// `(entity: MetaObject) => boolean` — so a requirement-driven generator cannot use
|
|
6
|
+
// it and must walk `loadedRoot` itself. Generalising `Generator` over any node kind
|
|
7
|
+
// is the principled fix and is deliberately out of scope: it is a core contract
|
|
8
|
+
// change touching every existing generator in five ports.
|
|
9
|
+
//
|
|
10
|
+
// WHY A PROJECTION rather than the raw node: an application's filter is app-owned
|
|
11
|
+
// policy (FR-038 §5), and handing it a `MetaData` would bind adopter code to
|
|
12
|
+
// metamodel internals and export the ADR-0039 own-vs-resolving accessor trap. The
|
|
13
|
+
// projection is additive — it can grow, but it never hands out the node.
|
|
14
|
+
import { TYPE_REQUIREMENT, resolveClaim } from "@metaobjectsdev/metadata";
|
|
15
|
+
/** `<type>.<subType>` — the key a renderer map is looked up by. */
|
|
16
|
+
export function concernOf(node) {
|
|
17
|
+
return `${node.type}.${node.subType}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The concern key for a requirement that resolves NO targets.
|
|
21
|
+
*
|
|
22
|
+
* Doubles as the catch-all renderer key, deliberately: a requirement with nothing
|
|
23
|
+
* to fan out over falls through to whatever the app registered as its default.
|
|
24
|
+
*/
|
|
25
|
+
export const NO_CONCERN = "*";
|
|
26
|
+
/**
|
|
27
|
+
* Depth-first walk of every `requirement.*` node, nested ones included.
|
|
28
|
+
*
|
|
29
|
+
* Unresolvable `@implementedBy` references are skipped rather than thrown on —
|
|
30
|
+
* resolution severity is `meta verify`'s job (it depends on `@status`, which is why
|
|
31
|
+
* it cannot live in the loader), and codegen must not fail a build over a
|
|
32
|
+
* diagnostic another command owns.
|
|
33
|
+
*/
|
|
34
|
+
export function walkRequirements(root) {
|
|
35
|
+
const out = [];
|
|
36
|
+
const visit = (node, prefix) => {
|
|
37
|
+
if (node.type !== TYPE_REQUIREMENT)
|
|
38
|
+
return;
|
|
39
|
+
const path = prefix === "" ? node.name : `${prefix}.${node.name}`;
|
|
40
|
+
const req = node;
|
|
41
|
+
// Same referrer-package basis the CLI's checks use, so a bare reference binds
|
|
42
|
+
// package-locally under the ADR-0042 contract.
|
|
43
|
+
const referrerPkg = node.package ?? node.fileDefaultPackage ?? "";
|
|
44
|
+
const targets = [];
|
|
45
|
+
for (const ref of req.implementedBy()) {
|
|
46
|
+
const target = resolveClaim(root, ref, referrerPkg);
|
|
47
|
+
if (target === undefined)
|
|
48
|
+
continue;
|
|
49
|
+
targets.push({ ref, node: target, concern: concernOf(target) });
|
|
50
|
+
}
|
|
51
|
+
out.push({
|
|
52
|
+
node: req,
|
|
53
|
+
view: {
|
|
54
|
+
subType: node.subType,
|
|
55
|
+
level: req.level(),
|
|
56
|
+
status: req.status(),
|
|
57
|
+
path,
|
|
58
|
+
implementedByTypes: [...new Set(targets.map((t) => t.concern))],
|
|
59
|
+
},
|
|
60
|
+
targets,
|
|
61
|
+
});
|
|
62
|
+
for (const child of node.children())
|
|
63
|
+
visit(child, path);
|
|
64
|
+
};
|
|
65
|
+
for (const child of root.children())
|
|
66
|
+
visit(child, "");
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Group a requirement's targets by distinct concern — the fan-out unit.
|
|
71
|
+
*
|
|
72
|
+
* One entry per distinct `type.subType`, NOT one per target: a single architectural
|
|
73
|
+
* requirement claimed by 123 entities must emit one stub, not 123, which is the
|
|
74
|
+
* hostile-first-contact outcome FR-038 §10 exists to avoid.
|
|
75
|
+
*
|
|
76
|
+
* A requirement resolving NO targets still yields exactly ONE group. That is not a
|
|
77
|
+
* degenerate case: `REQUIREMENT_LINK_FLOOR_LEVEL` forbids `@implementedBy` below L4,
|
|
78
|
+
* so every L1–L3 requirement resolves nothing — and an application that chooses to
|
|
79
|
+
* cover L3 would otherwise get silence instead of a stub.
|
|
80
|
+
*/
|
|
81
|
+
export function groupByConcern(w) {
|
|
82
|
+
const groups = new Map();
|
|
83
|
+
for (const t of w.targets) {
|
|
84
|
+
const existing = groups.get(t.concern);
|
|
85
|
+
if (existing === undefined)
|
|
86
|
+
groups.set(t.concern, [t]);
|
|
87
|
+
else
|
|
88
|
+
existing.push(t);
|
|
89
|
+
}
|
|
90
|
+
if (groups.size === 0)
|
|
91
|
+
groups.set(NO_CONCERN, []);
|
|
92
|
+
return groups;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=requirement-walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requirement-walk.js","sourceRoot":"","sources":["../src/requirement-walk.ts"],"names":[],"mappings":"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"}
|
package/dist/runner.d.ts
CHANGED
|
@@ -30,6 +30,41 @@ export interface RunGenOpts {
|
|
|
30
30
|
* `--dry-run`, and watching it reappear.
|
|
31
31
|
*/
|
|
32
32
|
dryRun?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Output scope — an object is generated only when this predicate returns true
|
|
35
|
+
* for its fully-qualified name (`obj.resolutionKey()`, `<package>::<name>`).
|
|
36
|
+
* Intersects with `entityFilter`: both must pass. Absent ⇒ every object is
|
|
37
|
+
* in scope (byte-identical to a project with no `scope` declared).
|
|
38
|
+
*
|
|
39
|
+
* The collection metadata always loads in FULL regardless of this predicate —
|
|
40
|
+
* scope filters OUTPUT, never input (design §4.3). So an in-scope object may
|
|
41
|
+
* reference an out-of-scope one (an FK target, a relationship `@objectRef`, a
|
|
42
|
+
* projection's base) and resolve perfectly at load time, while the code
|
|
43
|
+
* emitted FOR the in-scope object still imports/names a symbol that was never
|
|
44
|
+
* generated. This is left silent by design, not auto-widened: the adopter
|
|
45
|
+
* declared the scope precisely because something else (another consumer,
|
|
46
|
+
* another codegen run) owns those objects, and the reference is real. Warning
|
|
47
|
+
* on it correctly would require walking every reference kind (identity.reference,
|
|
48
|
+
* every relationship.* @objectRef, projection extends bases, field.object
|
|
49
|
+
* @objectRef) FQN-resolved against the SAME scope — genuinely new machinery,
|
|
50
|
+
* not a fit for the existing `warnings: string[]` channel at this seam. If an
|
|
51
|
+
* adopter hits it, the failure is a plain compiler error in the generated
|
|
52
|
+
* code (an unresolved import) — loud, at build time, not silent at runtime.
|
|
53
|
+
*
|
|
54
|
+
* Deliberately a PLAIN PREDICATE, not the `include`/`exclude` pattern strings
|
|
55
|
+
* `@metaobjectsdev/sdk`'s `scope.ts` compiles. `codegen-ts` must not depend on
|
|
56
|
+
* `@metaobjectsdev/sdk` — the dependency runs the other way (`cli` depends on
|
|
57
|
+
* both) — so it cannot import `matchesScope`/`CompiledScope` itself. The
|
|
58
|
+
* design's "package patterns, never a predicate function" rule (§4.3 of the
|
|
59
|
+
* metadata-source-resolution design doc) governs CONFIG SURFACES that must
|
|
60
|
+
* port identically to a `pom.xml` / `metaobjects.config.yaml` in every
|
|
61
|
+
* language port; it says nothing about internal plumbing between two
|
|
62
|
+
* TypeScript packages in this one repo. Do not "fix" this into a config
|
|
63
|
+
* shape — `cli`'s `gen`/`verify` commands are the only callers, and a
|
|
64
|
+
* `Collection` already exposes exactly this predicate as `inScope`, which
|
|
65
|
+
* they pass straight through.
|
|
66
|
+
*/
|
|
67
|
+
scope?: (fqn: string) => boolean;
|
|
33
68
|
}
|
|
34
69
|
export interface RunGenResult {
|
|
35
70
|
files: WriteResult[];
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,0BAA0B,CAAC;AAMrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,0BAA0B,CAAC;AAMrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAQpE,OAAO,EAOL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,YAAY,EAElB,MAAM,uBAAuB,CAAC;AAU/B,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;4BAEwB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;oDACgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;qBAEiB;IACjB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;gDAC4C;IAC5C,SAAS,EAAE,WAAW,EAAE,CAAC;CAC1B;AAkBD,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAghBpE"}
|
package/dist/runner.js
CHANGED
|
@@ -10,7 +10,9 @@ import { normalizeConfig, DEFAULT_TARGET_NAME } from "./metaobjects-config.js";
|
|
|
10
10
|
import { buildPkMap } from "./pk-resolver.js";
|
|
11
11
|
import { buildRelationMap } from "./relation-resolver.js";
|
|
12
12
|
import { makeRenderContext } from "./render-context.js";
|
|
13
|
-
import {
|
|
13
|
+
import { sweepOrphans } from "./orphan-sweep.js";
|
|
14
|
+
import { refusedOrphanMessage } from "./reconcile-orphans.js";
|
|
15
|
+
import { decideAndWrite, previewWriteStatus, hasHashManifest, listGeneratedPaths, loadEngineVersion, saveEngineVersion, } from "./overwrite-policy.js";
|
|
14
16
|
/** JS-identifier-shape only. Prevents filesystem traversal when metadata comes
|
|
15
17
|
* from untrusted sources (e.g. MCP). Mirrors the guard in legacy generate.ts. */
|
|
16
18
|
const VALID_ENTITY_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
@@ -58,6 +60,10 @@ export async function runGen(opts) {
|
|
|
58
60
|
// since the last gen, note it (generated output may legitimately differ). Purely
|
|
59
61
|
// informational — the version file is separate from `.hashes.json` and never
|
|
60
62
|
// affects the merge. Only fires when a prior stamp exists AND differs.
|
|
63
|
+
// Captured BEFORE any write, because the first write creates the manifest — read
|
|
64
|
+
// it afterwards and every project looks migrated.
|
|
65
|
+
const hadHashManifest = hasHashManifest(genStateDir);
|
|
66
|
+
const relativeForDisplay = (p) => projectRoot !== undefined ? relative(projectRoot, p) : p;
|
|
61
67
|
const hasPersistentGenState = opts.projectRoot !== undefined || opts.genStateDir !== undefined;
|
|
62
68
|
const installedEngine = hasPersistentGenState ? engineVersion() : undefined;
|
|
63
69
|
const recordedEngine = hasPersistentGenState ? loadEngineVersion(genStateDir) : undefined;
|
|
@@ -76,16 +82,49 @@ export async function runGen(opts) {
|
|
|
76
82
|
throw new Error("runGen: opts.metadata must be a loaded MetaRoot.");
|
|
77
83
|
}
|
|
78
84
|
const root = opts.metadata;
|
|
79
|
-
// 1. Resolve entities (
|
|
85
|
+
// 1. Resolve entities (entityFilter + scope + safety check). This is the
|
|
86
|
+
// single choke point for entity selection — scope INTERSECTS entityFilter
|
|
87
|
+
// (an object must pass both), matched against the object's
|
|
88
|
+
// fully-qualified name (resolutionKey(), never the bare name — two
|
|
89
|
+
// packages may declare the same short name).
|
|
80
90
|
const allObjects = root.objects();
|
|
81
91
|
const entityFilter = opts.entityFilter;
|
|
82
|
-
const
|
|
92
|
+
const afterEntityFilter = entityFilter
|
|
83
93
|
? allObjects.filter((o) => entityFilter.includes(o.name))
|
|
84
94
|
: allObjects;
|
|
95
|
+
const scope = opts.scope;
|
|
96
|
+
const filtered = scope
|
|
97
|
+
? afterEntityFilter.filter((o) => scope(o.resolutionKey()))
|
|
98
|
+
: afterEntityFilter;
|
|
85
99
|
if (filtered.length === 0) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
100
|
+
// Name the REAL cause. When `scope` is absent, this is byte-identical to
|
|
101
|
+
// the pre-scope two-way branch (kept as its own arm, rather than folded
|
|
102
|
+
// into the scope-aware logic below, so an unscoped project's warning text
|
|
103
|
+
// — including its quirky edge case: an empty root with entityFilter set
|
|
104
|
+
// still blames entityFilter — is untouched). Only when `scope` is
|
|
105
|
+
// present does a THIRD reason become reachable: "root has no object
|
|
106
|
+
// children" for a scoped-out model, or "...entityFilter" for a scope
|
|
107
|
+
// that admitted everything entityFilter then excluded, are both false
|
|
108
|
+
// statements that send the reader to the wrong file.
|
|
109
|
+
let reason;
|
|
110
|
+
if (scope === undefined) {
|
|
111
|
+
// Byte-identical to the pre-scope branch, quirk included: an EMPTY root
|
|
112
|
+
// with an entityFilter set still blames the filter. Wrong, and untouched
|
|
113
|
+
// — changing what an unscoped project reads is a behaviour change, and
|
|
114
|
+
// this is a shape change.
|
|
115
|
+
reason = entityFilter
|
|
116
|
+
? "no object children match the provided entityFilter"
|
|
117
|
+
: "root has no object children";
|
|
118
|
+
}
|
|
119
|
+
else if (allObjects.length === 0) {
|
|
120
|
+
reason = "root has no object children";
|
|
121
|
+
}
|
|
122
|
+
else if (afterEntityFilter.length === 0) {
|
|
123
|
+
reason = "no object children match the provided entityFilter";
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
reason = "no object children match the configured scope";
|
|
127
|
+
}
|
|
89
128
|
warnings.push(`No entities to generate — ${reason}.`);
|
|
90
129
|
return { files: [], warnings, conflicts: [] };
|
|
91
130
|
}
|
|
@@ -146,12 +185,25 @@ export async function runGen(opts) {
|
|
|
146
185
|
targetOf(g);
|
|
147
186
|
const entityGen = config.generators.find((g) => g.emitsEntityModule);
|
|
148
187
|
const entityModuleTarget = entityGen ? targetOf(entityGen) : targets[DEFAULT_TARGET_NAME];
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
188
|
+
// NO eager importBase check here, deliberately.
|
|
189
|
+
//
|
|
190
|
+
// There used to be one: "any generator on a non-entity target ⇒ the entity
|
|
191
|
+
// target must have importBase". It asked the wrong question — target placement,
|
|
192
|
+
// not whether anything actually imports across targets — so it convicted every
|
|
193
|
+
// multi-target project whose second target imports nothing, and the only way
|
|
194
|
+
// out was to set a value that is provably inert. An adopter hit this with a
|
|
195
|
+
// requirement-test target that imports no entity modules at all.
|
|
196
|
+
//
|
|
197
|
+
// `crossTargetEntityPath` (import-path.ts) is the SOLE consumer of importBase
|
|
198
|
+
// and already throws when it is missing, naming the resolution that needed it —
|
|
199
|
+
// and every cross-target entry point (`entityModuleSpecifier`,
|
|
200
|
+
// `barrelModuleSpecifier`) routes through it. That throw happens inside phase 4,
|
|
201
|
+
// before the write phase, and the runner tags it with the generator name, so
|
|
202
|
+
// the diagnostic is strictly better than the one removed here.
|
|
203
|
+
//
|
|
204
|
+
// The trade, stated: a generator whose cross-target import is CONDITIONAL now
|
|
205
|
+
// fails when a model change first makes it real, rather than at config time.
|
|
206
|
+
// That is the correct moment — it is also the only moment the answer is known.
|
|
155
207
|
// 3. Build shared render state once.
|
|
156
208
|
const pkMap = buildPkMap(root);
|
|
157
209
|
const relationMap = buildRelationMap(root);
|
|
@@ -193,6 +245,10 @@ export async function runGen(opts) {
|
|
|
193
245
|
const includeHonoRoutes = config.generators.some((g) => g.emitsHonoRoutes === true);
|
|
194
246
|
// 4. Run each generator with a per-target render context; collect with full path.
|
|
195
247
|
const emitted = [];
|
|
248
|
+
// FR-038 §8 — generators that opted into orphan reconciliation, paired with the
|
|
249
|
+
// directory their policy's relative paths are measured from. Collected here
|
|
250
|
+
// because `writeOutDir` is resolved per generator inside this loop.
|
|
251
|
+
const orphanJobs = [];
|
|
196
252
|
for (const generator of config.generators) {
|
|
197
253
|
// ADR-0025: `meta docs` is the single docs door. A `meta gen` config that
|
|
198
254
|
// still lists a deprecated doc generator is warned + skipped, not run — the
|
|
@@ -213,6 +269,13 @@ export async function runGen(opts) {
|
|
|
213
269
|
const writeOutDir = projectRoot !== undefined && !isAbsolute(selfTarget.outDir)
|
|
214
270
|
? resolve(projectRoot, selfTarget.outDir)
|
|
215
271
|
: selfTarget.outDir;
|
|
272
|
+
if (generator.orphanPolicy !== undefined) {
|
|
273
|
+
orphanJobs.push({
|
|
274
|
+
generatorName: generator.name,
|
|
275
|
+
writeOutDir,
|
|
276
|
+
policy: generator.orphanPolicy,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
216
279
|
const renderContext = makeRenderContext({
|
|
217
280
|
dialect: config.dialect,
|
|
218
281
|
loadedRoot: root,
|
|
@@ -282,17 +345,147 @@ export async function runGen(opts) {
|
|
|
282
345
|
// 5. Write phase.
|
|
283
346
|
const writes = [];
|
|
284
347
|
const conflicts = [];
|
|
348
|
+
// FR-038 §8 — reconcile files a previous run generated that this run does not.
|
|
349
|
+
//
|
|
350
|
+
// Gated on a real `projectRoot` for a load-bearing reason, not caution: without
|
|
351
|
+
// one, `decideAndWrite` keys each snapshot by a hash of its absolute path
|
|
352
|
+
// instead of a project-relative path, so gen-state holds no path to resolve and
|
|
353
|
+
// reconciliation has nothing to reason about. That gate is also what keeps
|
|
354
|
+
// `verify --codegen` inert — it runs against a throwaway root whose gen-state is
|
|
355
|
+
// empty — and what keeps programmatic/test callers from ever deleting a file.
|
|
356
|
+
// Refusals are reported ONE of two ways, and which one matters more than the
|
|
357
|
+
// wording. A project with no manifest at all predates the manifest being
|
|
358
|
+
// committed: every refusal in it has the SAME single cause and the same one-line
|
|
359
|
+
// fix, so N per-file warnings would be a wall that buries the instruction — the
|
|
360
|
+
// hostile-first-contact outcome that gets a tool switched off. A project that DOES
|
|
361
|
+
// have a manifest is refusing because specific files were edited, and there the
|
|
362
|
+
// per-file naming is the actionable part.
|
|
363
|
+
//
|
|
364
|
+
// Self-extinguishing: once the manifest is committed, the aggregate never fires
|
|
365
|
+
// again.
|
|
366
|
+
const MAX_NAMED = 5;
|
|
367
|
+
const reportRefusals = () => {
|
|
368
|
+
const refused = writes.filter((w) => w.status === "refused");
|
|
369
|
+
if (refused.length === 0)
|
|
370
|
+
return;
|
|
371
|
+
if (!hadHashManifest) {
|
|
372
|
+
const names = refused.slice(0, MAX_NAMED).map((w) => relativeForDisplay(w.path));
|
|
373
|
+
const more = refused.length > MAX_NAMED ? `, and ${refused.length - MAX_NAMED} more` : "";
|
|
374
|
+
warnings.push(`Refused to overwrite ${refused.length} existing file(s), and this project has ` +
|
|
375
|
+
`no codegen hash manifest — so 'meta gen' cannot tell your edits from its own ` +
|
|
376
|
+
`stale output, and it will not guess. This is the expected first run for a ` +
|
|
377
|
+
`project created before the manifest was committed. ` +
|
|
378
|
+
`ONE-TIME FIX: commit '.metaobjects/.gen-state/.hashes.json' (un-ignore it in ` +
|
|
379
|
+
`.metaobjects/.gitignore with '.gen-state/*' + '!.gen-state/.hashes.json'), ` +
|
|
380
|
+
`then re-run. To adopt fresh output and DISCARD any hand edits in these files ` +
|
|
381
|
+
`instead, re-run with --baseline=fresh. Files: ${names.join(", ")}${more}.`);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
for (const w of refused) {
|
|
385
|
+
warnings.push(`Refused to overwrite ${w.path}: ${w.conflictHint ?? "content differs and could not be verified as generated."}`);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
const sweep = (dryRun) => {
|
|
389
|
+
if (projectRoot === undefined || orphanJobs.length === 0)
|
|
390
|
+
return;
|
|
391
|
+
// NEVER reconcile a PARTIAL run. `meta gen <entity>` narrows the object set, so
|
|
392
|
+
// `emitted` is a subset of the full output BY CONSTRUCTION — every path belonging
|
|
393
|
+
// to an unselected entity looks exactly like an orphan, and the untouched ones get
|
|
394
|
+
// deleted. The shipped `requirementTests()` escapes only by accident (it walks
|
|
395
|
+
// `ctx.loadedRoot` and ignores `ctx.matches`); any app generator that honours
|
|
396
|
+
// `ctx.matches` — the documented, encouraged composition — would wipe every
|
|
397
|
+
// non-selected entity's output on a routine filtered run.
|
|
398
|
+
//
|
|
399
|
+
// The runner is the ONLY layer that knows the run was partial: a generator sees a
|
|
400
|
+
// narrowed entity list and cannot tell it from a model that genuinely has one
|
|
401
|
+
// entity. So the guard has to live here.
|
|
402
|
+
if (opts.entityFilter !== undefined && opts.entityFilter.length > 0) {
|
|
403
|
+
// Say it only when something was ACTUALLY withheld. With no previously-generated
|
|
404
|
+
// path outside this run's own output there are no orphan candidates at all, so
|
|
405
|
+
// the sweep provably no-ops and there is nothing to report. `meta gen <entity>`
|
|
406
|
+
// is a routine command; warning on every one of them teaches the reader to skim
|
|
407
|
+
// the message, which is how the real one gets skimmed too.
|
|
408
|
+
//
|
|
409
|
+
// Note the manifest is NOT empty here even on a first run — the writes above have
|
|
410
|
+
// already recorded this run's own paths in it — so the emitted set has to come
|
|
411
|
+
// out before counting. Computing the candidate set is safe on a filtered run;
|
|
412
|
+
// what must never happen is ACTING on it.
|
|
413
|
+
//
|
|
414
|
+
// A non-empty candidate set is the FLOOR, not proof that a specific file would
|
|
415
|
+
// have been removed: whether one falls inside an opting-in generator's namespace
|
|
416
|
+
// is the reconcile's answer, and running that is the thing being skipped.
|
|
417
|
+
const emittedRel = new Set(emitted.map((f) => relative(projectRoot, f.fullPath)));
|
|
418
|
+
const withheld = listGeneratedPaths(genStateDir).filter((p) => !emittedRel.has(p));
|
|
419
|
+
if (withheld.length > 0) {
|
|
420
|
+
warnings.push(`Skipped orphan cleanup: this run generated only ${opts.entityFilter.join(", ")}, ` +
|
|
421
|
+
`so it cannot tell a file belonging to an unselected entity from one that is no ` +
|
|
422
|
+
`longer generated. Run 'meta gen' with no entity filter to reconcile deletions.`);
|
|
423
|
+
}
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const result = sweepOrphans({
|
|
427
|
+
genStateDir,
|
|
428
|
+
projectRoot,
|
|
429
|
+
emittedRelPaths: emitted.map((f) => relative(projectRoot, f.fullPath)),
|
|
430
|
+
jobs: orphanJobs,
|
|
431
|
+
dryRun,
|
|
432
|
+
});
|
|
433
|
+
// Both kinds are the same file outcome — gone. What differs is what it cost,
|
|
434
|
+
// which is what the warning below is for.
|
|
435
|
+
for (const relPath of [...result.removed, ...result.forced]) {
|
|
436
|
+
writes.push({ path: join(projectRoot, relPath), status: "removed" });
|
|
437
|
+
}
|
|
438
|
+
if (result.refused.length > 0) {
|
|
439
|
+
// Grouped by the generator that refused, so each message names a generator the
|
|
440
|
+
// project actually registered. `orphanPolicy` is generic and apps are encouraged
|
|
441
|
+
// to compose their own, so one blanket message naming `requirement-tests` would
|
|
442
|
+
// be wrong for precisely the users the seam exists for.
|
|
443
|
+
const byGenerator = new Map();
|
|
444
|
+
for (const relPath of result.refused) {
|
|
445
|
+
const owner = result.refusedBy.get(relPath) ?? "orphan cleanup";
|
|
446
|
+
const list = byGenerator.get(owner);
|
|
447
|
+
if (list === undefined)
|
|
448
|
+
byGenerator.set(owner, [relPath]);
|
|
449
|
+
else
|
|
450
|
+
list.push(relPath);
|
|
451
|
+
}
|
|
452
|
+
for (const [owner, paths] of byGenerator) {
|
|
453
|
+
warnings.push(refusedOrphanMessage(paths, owner));
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (result.forced.length > 0) {
|
|
457
|
+
warnings.push(`Deleted ${result.forced.length} hand-edited generated file(s) because a ` +
|
|
458
|
+
`generator's orphanPolicy sets force: ${result.forced.join(", ")}. ` +
|
|
459
|
+
`Hand-written content in them is gone — recover from version control.`);
|
|
460
|
+
}
|
|
461
|
+
};
|
|
285
462
|
// --dry-run: report what WOULD be written and touch nothing — no output files
|
|
286
463
|
// and no .gen-state/ snapshot (writing the snapshot would silently re-baseline
|
|
287
464
|
// the merge base, so a later real run could skip a genuinely-needed write).
|
|
288
465
|
if (opts.dryRun === true) {
|
|
289
466
|
for (const file of emitted) {
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
//
|
|
294
|
-
|
|
467
|
+
// Ask the same policy the real run asks, in a read-only mode. This used to be
|
|
468
|
+
// `existsSync(...) ? "overwrite" : "new"`, which previewed a hand-edited file
|
|
469
|
+
// as "overwrite" while the real run refused it — the one case the preview most
|
|
470
|
+
// needs to be right about. A merge outcome is still coarse (see
|
|
471
|
+
// previewWriteStatus), because clean-vs-conflicted is unknowable without merging.
|
|
472
|
+
const policyOpts = {
|
|
473
|
+
strategy,
|
|
474
|
+
genStateDir,
|
|
475
|
+
baseline,
|
|
476
|
+
};
|
|
477
|
+
if (projectRoot !== undefined) {
|
|
478
|
+
policyOpts.outputRelPath = relative(projectRoot, file.fullPath);
|
|
479
|
+
}
|
|
480
|
+
writes.push({
|
|
481
|
+
path: file.fullPath,
|
|
482
|
+
status: previewWriteStatus(file.fullPath, file.content, policyOpts),
|
|
483
|
+
});
|
|
295
484
|
}
|
|
485
|
+
reportRefusals();
|
|
486
|
+
// A preview that hides a pending deletion is worse than no preview at all, so
|
|
487
|
+
// the sweep still runs — in decide-and-report mode, touching nothing.
|
|
488
|
+
sweep(true);
|
|
296
489
|
return { files: writes, warnings, conflicts };
|
|
297
490
|
}
|
|
298
491
|
for (const file of emitted) {
|
|
@@ -315,11 +508,14 @@ export async function runGen(opts) {
|
|
|
315
508
|
warnings.push(`Merge conflict in ${file.fullPath}: resolve diff3 markers and re-run ` +
|
|
316
509
|
`'meta gen' to advance the canonical state.`);
|
|
317
510
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
`Move to a different outDir, delete the file, or add the header to opt in.`);
|
|
321
|
-
}
|
|
511
|
+
// Refusals are reported together after the loop (see reportRefusals) so a
|
|
512
|
+
// whole-project cause can be stated once instead of once per file.
|
|
322
513
|
}
|
|
514
|
+
reportRefusals();
|
|
515
|
+
// Sweep AFTER the writes: writing is the primary job, and a deletion that runs
|
|
516
|
+
// first would be unrecoverable if a later write threw. Ordering cannot change
|
|
517
|
+
// the decision — a path this run emitted is never an orphan either way.
|
|
518
|
+
sweep(false);
|
|
323
519
|
// #232 — stamp the engine version that produced this snapshot, so the NEXT gen can
|
|
324
520
|
// detect an engine change. Written after a successful run only.
|
|
325
521
|
if (installedEngine !== undefined)
|