@atomic-ehr/codegen 0.0.18 → 0.0.19-canary.20260917110212.f40edba

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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as FS from '@atomic-ehr/fhirschema';
2
2
  import { FHIRSchema, StructureDefinition as StructureDefinition$1, FHIRSchemaElement } from '@atomic-ehr/fhirschema';
3
- import { CanonicalManager, PreprocessContext } from '@atomic-ehr/fhir-canonical-manager';
3
+ import { CanonicalManager, Patches, PreprocessContext, PackageIndexMode, ReportEntry } from '@atomic-ehr/fhir-canonical-manager';
4
4
 
5
5
  interface Extension extends Element {
6
6
  url: string;
@@ -937,6 +937,8 @@ type Register = {
937
937
  allFs(): RichFHIRSchema[];
938
938
  /** Returns all ValueSets from all packages in the resolver */
939
939
  allVs(): RichValueSet[];
940
+ /** Returns raw terminology resources grouped by their originating package. */
941
+ allTerminology(): PackageTerminology[];
940
942
  resolveVs(_pkg: PackageMeta, canonicalUrl: CanonicalUrl): RichValueSet | undefined;
941
943
  resolveAny(canonicalUrl: CanonicalUrl): any | undefined;
942
944
  resolveElementSnapshot(fhirSchema: RichFHIRSchema, path: string[]): FHIRSchemaElement;
@@ -947,6 +949,25 @@ type Register = {
947
949
  type PkgId = string;
948
950
  type PkgName = string;
949
951
  type FocusedResource = StructureDefinition$1 | ValueSet | CodeSystem;
952
+ type TerminologyResource = {
953
+ resourceType: "CodeSystem" | "ValueSet" | "NamingSystem";
954
+ id?: string;
955
+ name?: string;
956
+ url: string;
957
+ /** Declared CodeSystem content mode; malformed packages may carry other strings. */
958
+ content?: CodeSystem["content"] | (string & {});
959
+ concept?: CodeSystemConcept[];
960
+ };
961
+ type PackageTerminology = {
962
+ packageMeta: PackageMeta;
963
+ resources: TerminologyResource[];
964
+ };
965
+ /**
966
+ * User-supplied attestation of how a package's content was verified, stamped
967
+ * verbatim on its entries. `"unverifiable"` also suppresses codes and
968
+ * displays; packages without an attestation are stamped `"not-recorded"`.
969
+ */
970
+ type TerminologyVerification = "registry-integrity" | "unverifiable" | (string & {});
950
971
  type CanonicalResolution<T> = {
951
972
  deep: number;
952
973
  pkg: PackageMeta;
@@ -958,6 +979,7 @@ type PackageIndex = {
958
979
  canonicalResolution: Record<CanonicalUrl, CanonicalResolution<FocusedResource>[]>;
959
980
  fhirSchemas: Record<CanonicalUrl, RichFHIRSchema>;
960
981
  valueSets: Record<CanonicalUrl, RichValueSet>;
982
+ terminology: TerminologyResource[];
961
983
  };
962
984
  type PackageAwareResolver = Record<PkgId, PackageIndex>;
963
985
  type ResolutionTree = Record<PkgName, Record<CanonicalUrl, {
@@ -1087,8 +1109,29 @@ type TypeScriptOptions = {
1087
1109
  */
1088
1110
  openResourceTypeSet: boolean;
1089
1111
  primitiveTypeExtension: boolean;
1112
+ /** How relative import/export specifiers are written in generated modules.
1113
+ *
1114
+ * - "extensionless" (default): `"./profiles"`, `"../Patient"` — resolved by
1115
+ * bundlers, TypeScript and Bun.
1116
+ * - "node-esm": explicit file targets (`"./profiles/index.js"`,
1117
+ * `"../Patient.js"`), so output transpiled to plain `.js` modules under
1118
+ * `"type": "module"` loads under Node's ESM resolver.
1119
+ */
1120
+ moduleSpecifierStyle?: "extensionless" | "node-esm";
1090
1121
  extensionGetterDefault?: "flat" | "profile" | "raw";
1091
1122
  sliceGetterDefault?: "flat" | "raw";
1123
+ terminology?: {
1124
+ /** Emit one terminology module for every resolved package. Defaults to false. */
1125
+ enabled?: boolean;
1126
+ /**
1127
+ * Limit terminology modules to these `name@version` package refs.
1128
+ * When omitted, every resolved package in the closure emits one —
1129
+ * which for real closures (VSAC, hl7.terminology, ...) can be huge.
1130
+ */
1131
+ packages?: string[];
1132
+ /** Attestation per `name@version` package ref; see {@link TerminologyVerification}. */
1133
+ packageVerification?: Record<string, TerminologyVerification>;
1134
+ };
1092
1135
  } & WriterOptions;
1093
1136
 
1094
1137
  /**
@@ -1099,18 +1142,63 @@ type TypeScriptOptions = {
1099
1142
  */
1100
1143
 
1101
1144
  /**
1102
- * Configuration options for the API builder
1145
+ * Configuration of the CanonicalManager package loader. Everything in this block is forwarded
1146
+ * verbatim to the CanonicalManager the builder constructs; it is ignored when a prebuilt
1147
+ * `manager`/`register` is injected (they own their own configuration).
1103
1148
  */
1149
+ type CanonicalManagerOptions = {
1150
+ /** Custom FHIR package registry URL (default: https://fs.get-ig.org/pkgs/). */
1151
+ registry?: string;
1152
+ /** How a package's shipped `.index.json` is treated: trust it (`"use"`, default), heal a
1153
+ * broken one with a directory scan (`"recover"`), or rebuild it unconditionally (`"regenerate"`). */
1154
+ packageIndex?: PackageIndexMode;
1155
+ /** Drop the CanonicalManager cache before loading packages. Note that this wipes the whole
1156
+ * working directory, every cached package set included — pair it with a dedicated
1157
+ * `workingDir` so unrelated callers keep their downloads. */
1158
+ dropCache?: boolean;
1159
+ /** Directory holding the downloaded packages and their processed cache
1160
+ * (default: `.codegen-cache/canonical-manager-cache`). */
1161
+ workingDir?: string;
1162
+ /** Per-phase patch handlers (package-defect fixes; helpers on the `@atomic-ehr/fhir-canonical-manager/patch` subpath). */
1163
+ patches?: Partial<Patches>;
1164
+ };
1165
+ /** Stored generator configuration — read throughout a generation run. */
1104
1166
  interface APIBuilderOptions {
1105
1167
  outputDir: string;
1106
1168
  cleanOutput: boolean;
1107
1169
  throwException: boolean;
1108
1170
  typeSchema?: IrConf;
1109
- /** Custom FHIR package registry URL (default: https://fs.get-ig.org/pkgs/) */
1110
- registry: string | undefined;
1111
- /** Drop the canonical manager cache */
1112
- dropCanonicalManagerCache: boolean;
1113
1171
  }
1172
+ /** Old spellings of the loader configuration, each mapped onto `canonicalManager` with a
1173
+ * deprecation warning; the whole block is deleted together in a future release. */
1174
+ type DeprecatedLoaderOptions = {
1175
+ /** @deprecated Use `canonicalManager: { registry }`. */
1176
+ registry?: string;
1177
+ /** @deprecated Use `canonicalManager: { dropCache }`. */
1178
+ dropCanonicalManagerCache?: boolean;
1179
+ /** @deprecated Use `canonicalManager: { patches }`. */
1180
+ patches?: Partial<Patches>;
1181
+ /** @deprecated Use `canonicalManager: { patches }` with the CM `/patch` subpath helpers. */
1182
+ preprocessPackage?: (context: PreprocessContext) => PreprocessContext;
1183
+ /** @deprecated Use `canonicalManager: { packageIndex }`. */
1184
+ packageIndex?: PackageIndexMode;
1185
+ /** @deprecated Use `canonicalManager: { packageIndex: "regenerate" }`. */
1186
+ ignorePackageIndex?: boolean;
1187
+ /** @deprecated Pass the instance via `canonicalManager` instead. */
1188
+ manager?: ReturnType<typeof CanonicalManager>;
1189
+ };
1190
+ /** What the constructor accepts: stored options, input wiring, and the deprecated spellings. */
1191
+ type APIBuilderInput = Partial<APIBuilderOptions> & DeprecatedLoaderOptions & {
1192
+ /** The package loader: either its configuration (registry, packageIndex, dropCache,
1193
+ * patches) for the manager the builder constructs, or a prebuilt CanonicalManager
1194
+ * instance — interchangeable from the caller's side. */
1195
+ canonicalManager?: CanonicalManagerOptions | ReturnType<typeof CanonicalManager>;
1196
+ /** Apply the shipped input fixes (`src/api/builtin-patches.ts`) to the constructed
1197
+ * loader. Defaults to true; `false` is the explicit opt-out. */
1198
+ builtinPatches?: boolean;
1199
+ register?: Register;
1200
+ logger?: CodegenLogManager;
1201
+ };
1114
1202
  type GenerationReport = {
1115
1203
  success: boolean;
1116
1204
  outputDir: string;
@@ -1119,6 +1207,9 @@ type GenerationReport = {
1119
1207
  errors: string[];
1120
1208
  warnings: string[];
1121
1209
  duration: number;
1210
+ /** CanonicalManager input-fix diagnostics (exclusions, index recoveries, deprecations).
1211
+ * Absent when a prebuilt `register` is used; empty for packages served from cache. */
1212
+ inputReport?: ReportEntry[];
1122
1213
  };
1123
1214
  interface PrettyReportOptions {
1124
1215
  /** When a generator produces more than this many files, aggregate them by directory instead of listing each file. */
@@ -1143,13 +1234,7 @@ declare class APIBuilder {
1143
1234
  private managerInput;
1144
1235
  private logger;
1145
1236
  private generators;
1146
- constructor(userOpts?: Partial<APIBuilderOptions> & {
1147
- manager?: ReturnType<typeof CanonicalManager>;
1148
- register?: Register;
1149
- preprocessPackage?: (context: PreprocessContext) => PreprocessContext;
1150
- ignorePackageIndex?: boolean;
1151
- logger?: CodegenLogManager;
1152
- });
1237
+ constructor(userOpts?: APIBuilderInput);
1153
1238
  fromPackage(packageName: string, version?: string): APIBuilder;
1154
1239
  fromPackageRef(packageRef: string): APIBuilder;
1155
1240
  localStructureDefinitions(config: LocalStructureDefinitionConfig): APIBuilder;
@@ -1159,12 +1244,21 @@ declare class APIBuilder {
1159
1244
  python(userOptions: Partial<PythonGeneratorOptions>): APIBuilder;
1160
1245
  mustache(templatePath: string, userOpts: Partial<FileSystemWriterOptions & FileBasedMustacheGeneratorOptions>): this;
1161
1246
  csharp(userOptions: Partial<CSharpGeneratorOptions>): APIBuilder;
1247
+ /** Set by `outputTo`, to tell an explicit output directory from the default one. */
1248
+ private explicitOutputDir?;
1249
+ /** Output directory for a generator being configured now. `subdir` applies only when
1250
+ * `outputTo` never named one. */
1251
+ private generatorOutputDir;
1162
1252
  /**
1163
- * Set the output directory for all generators
1253
+ * Set the output directory for all generators, whenever they are configured
1164
1254
  */
1165
1255
  outputTo(directory: string): APIBuilder;
1166
1256
  throwException(enabled?: boolean): APIBuilder;
1167
1257
  cleanOutput(enabled?: boolean): APIBuilder;
1258
+ /** Set when a TypeScript generator wants terminology modules: the emitted
1259
+ * terminology types are derived from the generated CodeSystem type, so it
1260
+ * must survive tree shaking even when the user's rules don't ask for it. */
1261
+ private wantsTerminologyTypes;
1168
1262
  typeSchema(cfg: IrConf): this;
1169
1263
  irReport(userOpts: Partial<IrReportWriterWriterOptions>): this;
1170
1264
  generate(): Promise<GenerationReport>;