Skip to content

Commit be03bb5

Browse files
committed
tiding: make typeschema generator API more strict
1 parent 6dae422 commit be03bb5

6 files changed

Lines changed: 21 additions & 21 deletions

File tree

src/api/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class APIBuilder {
238238
this.packages.push(packageRef);
239239
return this;
240240
}
241-
241+
242242
/**
243243
* Set a custom FHIR package registry URL
244244
* @param url The registry URL (default: https://fs.get-ig.org/pkgs/)

src/cli/commands/typeschema/generate.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { mkdir, writeFile } from "node:fs/promises";
88
import { dirname } from "node:path";
9+
import { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
910
import { complete, createLogger, list } from "@root/utils/codegen-logger";
1011
import { TypeSchemaGenerator } from "@typeschema/generator";
1112
import type { CommandModule } from "yargs";
@@ -116,6 +117,11 @@ export const generateTypeschemaCommand: CommandModule<Record<string, unknown>, G
116117
const generator = new TypeSchemaGenerator({
117118
treeshake: treeshakeOptions,
118119
registry: registryOption,
120+
manager: CanonicalManager({
121+
packages: [],
122+
workingDir: ".codegen-cache/canonical-manager-cache",
123+
registry: registryOption,
124+
}),
119125
});
120126

121127
// Generate schemas from all packages

src/typeschema/generator.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Provides high-level API for converting FHIR Structure Definitions to TypeSchema format.
66
*/
77

8-
import { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
8+
import type { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
99
import type { FHIRSchema, StructureDefinition } from "@atomic-ehr/fhirschema";
1010
import * as fhirschema from "@atomic-ehr/fhirschema";
1111
import type { CodegenLogger } from "@root/utils/codegen-logger";
@@ -34,15 +34,9 @@ export class TypeSchemaGenerator {
3434
private options: TypeschemaGeneratorOptions;
3535
private logger?: CodegenLogger;
3636

37-
constructor(options: TypeschemaGeneratorOptions = {}) {
37+
constructor(options: TypeschemaGeneratorOptions) {
3838
this.options = { ...options };
39-
this.manager =
40-
options.manager ||
41-
CanonicalManager({
42-
packages: [],
43-
workingDir: "tmp/fhir",
44-
registry: options.registry || undefined,
45-
});
39+
this.manager = options.manager;
4640
this.logger =
4741
options.logger ||
4842
createLogger({

src/typeschema/register.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export type Register = {
2929
} & ReturnType<typeof CanonicalManager>;
3030

3131
const readPackageDependencies = async (manager: ReturnType<typeof CanonicalManager>, packageMeta: PackageMeta) => {
32-
const packageJSON = (await manager.packageJson(packageMeta.name)) as any;
33-
const dependencies = packageJSON.dependencies;
34-
if (dependencies !== undefined) {
32+
const packageJSON = (await manager.packageJson(packageMeta.name)) as any;
33+
const dependencies = packageJSON.dependencies;
34+
if (dependencies !== undefined) {
3535
return Object.entries(dependencies).map(([name, version]): PackageMeta => {
36-
return { name: name as string, version: version as string };
37-
});
38-
}
39-
return [];
36+
return { name: name as string, version: version as string };
37+
});
38+
}
39+
return [];
4040
};
4141

4242
// FIXME: Tiding: PackageName, PkgId, PkgName

src/typeschema/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export const enrichValueSet = (vs: ValueSet, packageMeta: PackageMeta): RichValu
345345
export interface TypeschemaGeneratorOptions {
346346
logger?: import("../utils/codegen-logger").CodegenLogger;
347347
treeshake?: string[];
348-
manager?: ReturnType<typeof CanonicalManager> | null;
348+
manager: ReturnType<typeof CanonicalManager>;
349349
/** Custom FHIR package registry URL */
350350
registry?: string;
351351
}

test/unit/typeschema/field-builder.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe("Field Builder Core Logic", async () => {
198198
it("should handle fixed values", async () => {
199199
const element: FHIRSchemaElement = {
200200
type: "code",
201-
// @ts-ignore
201+
// @ts-expect-error
202202
fixed: "fixed-value",
203203
};
204204

@@ -218,7 +218,7 @@ describe("Field Builder Core Logic", async () => {
218218
it("should handle pattern constraints", async () => {
219219
const element: FHIRSchemaElement = {
220220
type: "string",
221-
// @ts-ignore
221+
// @ts-expect-error
222222
pattern: "\\d{3}-\\d{3}-\\d{4}",
223223
};
224224

@@ -259,7 +259,7 @@ describe("Field Builder Core Logic", async () => {
259259
const element: FHIRSchemaElement = {
260260
type: "string",
261261
short: "Short description",
262-
// @ts-ignore
262+
// @ts-expect-error
263263
definition: "Detailed definition",
264264
};
265265

0 commit comments

Comments
 (0)