Skip to content

TypeSchema: followReferences tree-shake option to generate referenced types - #202

Merged
ryukzak merged 3 commits into
mainfrom
tree-shake-follow-references
Jul 24, 2026
Merged

TypeSchema: followReferences tree-shake option to generate referenced types#202
ryukzak merged 3 commits into
mainfrom
tree-shake-follow-references

Conversation

@ryukzak

@ryukzak ryukzak commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator
  • Add followReferences?: boolean to TreeShakeRule (default: false): a root with the flag adds its reference targets — base resources (reference.resource) and target profiles (reference.profiles), including nested-type fields — to the kept set, with their regular dependencies pulled transitively.
  • Following is non-transitive over references: pulled-in types keep their own reference targets as plain string literals, so one flag cannot drag in the whole package.
  • Explicit tree-shake roots win over followed targets, so a followed reference cannot override another root's selectFields/ignoreFields rule.
  • Add treeShakeDefaults: { followReferences } to IrConf to enable the option for every root at once; a rule's own value overrides the default.
  • Tests: default drops targets, per-rule and default-based following, rule-over-default precedence, non-transitivity.
  • Document both options in README (Tree Shaking section) and CLAUDE.md; clarify that reference targets are not dependencies by default.

Follow-up to #201: reference targets no longer need to be tree-shake roots for correct Reference<...> types, but users may still want the referenced types generated — this makes that a one-flag opt-in instead of enumerating every target:

// before: every referenced type enumerated by hand
.typeSchema({
    treeShake: {
        "kbv.basis": {
            "https://fhir.kbv.de/StructureDefinition/KBV_PR_Base_Condition_Diagnosis": {},
            "https://fhir.kbv.de/StructureDefinition/KBV_PR_Base_Patient": {},
        },
    },
})

// after
.typeSchema({
    treeShake: {
        "kbv.basis": {
            "https://fhir.kbv.de/StructureDefinition/KBV_PR_Base_Condition_Diagnosis": { followReferences: true },
        },
    },
})

// or for all roots at once
.typeSchema({
    treeShake: { ... },
    treeShakeDefaults: { followReferences: true },
})

ryukzak added 3 commits July 24, 2026 13:45
…referenced types

A rule with followReferences: true adds the schema's reference targets
(reference.resource base resources and reference.profiles target profiles)
to the kept set, with their regular dependencies. Non-transitive: followed
types keep their own reference targets as plain string literals. Explicit
tree-shake roots win over followed targets. treeShakeDefaults applies the
option to every root at once; a rule's own value overrides the default.
@ryukzak
ryukzak merged commit c2bb358 into main Jul 24, 2026
35 checks passed
@ryukzak
ryukzak deleted the tree-shake-follow-references branch July 24, 2026 09:50
sussdorff added a commit to cognovis/codegen that referenced this pull request Jul 24, 2026
…hr#200/atomic-ehr#201/atomic-ehr#202 + fhirschema 0.0.14

fork-only: committed dist/ for git-URL installs (bun skips devDependencies)
sussdorff added a commit to cognovis/codegen that referenced this pull request Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant