Skip to content

Commit 930498f

Browse files
authored
Merge pull request #28 from atomic-ehr/remove-dead-code
Remove dead code
2 parents 28bff93 + c4d4f47 commit 930498f

68 files changed

Lines changed: 225 additions & 14107 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.knipignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Test helpers are intentionally exported for use across test files
2+
test/helpers/**
3+
4+
# Keep all exported types - they might be used by TypeScript consumers
5+
**/*.d.ts

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ AIDBOX_LICENSE_ID ?=
22

33
TYPECHECK = bunx tsc --noEmit
44
FORMAT = bunx biome format --write
5-
LINT = bunx biome lint --diagnostic-level=error --write --unsafe
5+
LINT = bunx biome check --write
66
TEST = bun test
77

88
.PHONY: all typecheck test-typeschema test-register test-codegen test-typescript-r4-example

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"noExcessiveCognitiveComplexity": {
4343
"level": "warn",
4444
"options": {
45-
"maxAllowedComplexity": 50
45+
"maxAllowedComplexity": 39
4646
}
4747
}
4848
},

bun.lock

Lines changed: 65 additions & 173 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/typescript-r4/demo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,15 @@ function runDemo() {
276276
const patient = createPatient();
277277
console.log("✓ Created patient:", patient.id);
278278

279-
const observation = createObservation(patient.id!);
279+
if (!patient.id) throw new Error("Failed to create patient");
280+
const observation = createObservation(patient.id);
280281
console.log("✓ Created glucose observation:", observation.id);
281282

282283
console.log(`\n${"=".repeat(60)}`);
283284
console.log("Bodyweight profile attach/extract demo:");
284285
console.log("=".repeat(60));
285286

286-
const bodyweightObs = createBodyWeightObservation(patient.id!);
287+
const bodyweightObs = createBodyWeightObservation(patient.id);
287288
console.log("✓ Created body weight observation with profile:", bodyweightObs.id);
288289

289290
const bundle = createBundle(patient, observation, bodyweightObs);

knip.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema.json",
3+
"entry": [
4+
"src/api/index.ts"
5+
],
6+
"project": [
7+
"src/**/*.ts",
8+
"test/**/*.ts"
9+
],
10+
"ignore": [
11+
"dist/**",
12+
"generated/**",
13+
".typeschema-cache/**",
14+
"**/*.d.ts"
15+
],
16+
"ignoreDependencies": [
17+
],
18+
"ignoreBinaries": [
19+
],
20+
"ignoreExportsUsedInFile": true,
21+
"rules": {
22+
"files": "warn",
23+
"dependencies": "warn",
24+
"devDependencies": "warn",
25+
"unlisted": "error",
26+
"binaries": "warn",
27+
"unresolved": "error",
28+
"exports": "warn",
29+
"types": "warn",
30+
"nsExports": "warn",
31+
"nsTypes": "warn",
32+
"enumMembers": "warn",
33+
"classMembers": "warn",
34+
"duplicates": "error"
35+
},
36+
"compilers": {
37+
"css": "css",
38+
"js": "tsx",
39+
"json": "json",
40+
"svg": "tsx",
41+
"ts": "tsx"
42+
}
43+
}

package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
"cli": "bun run src/cli/index.ts",
4848
"codegen": "bun run src/cli/index.ts",
4949
"codegen:all": "bun run src/cli/index.ts generate",
50-
"prune": "ts-prune --project tsconfig.json"
50+
"prune": "knip",
51+
"prune:strict": "knip --strict",
52+
"prune:fix": "knip --fix"
5153
},
5254
"repository": {
5355
"type": "git",
@@ -62,22 +64,16 @@
6264
"dependencies": {
6365
"@atomic-ehr/fhir-canonical-manager": "^0.0.15",
6466
"@atomic-ehr/fhirschema": "^0.0.5",
65-
"@inquirer/prompts": "^7.8.1",
66-
"ajv": "^8.17.1",
67-
"glob": "^12.0.0",
68-
"handlebars": "^4.7.8",
69-
"ora": "^8.2.0",
7067
"picocolors": "^1.1.1",
7168
"yaml": "^2.8.1",
7269
"yargs": "^18.0.0"
7370
},
7471
"devDependencies": {
7572
"@biomejs/biome": "^2.1.4",
7673
"@types/bun": "^1.2.23",
77-
"@types/handlebars": "^4.1.0",
7874
"@types/node": "^22.17.1",
7975
"@types/yargs": "^17.0.33",
80-
"ts-prune": "^0.10.3",
76+
"knip": "^5.27.2",
8177
"tsup": "^8.5.1",
8278
"typescript": "^5.9.2"
8379
}

src/api/builder.ts

Lines changed: 17 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ import * as fs from "node:fs";
99
import * as afs from "node:fs/promises";
1010
import * as Path from "node:path";
1111
import { CanonicalManager } from "@atomic-ehr/fhir-canonical-manager";
12-
import type { GeneratedFile } from "@root/api/generators/base/types";
1312
import { CSharp } from "@root/api/writer-generator/csharp/csharp";
1413
import { registerFromManager } from "@root/typeschema/register";
15-
import { mkTypeSchemaIndex, type TreeShake, treeShake } from "@root/typeschema/utils";
16-
import { generateTypeSchemas, TypeSchemaCache, TypeSchemaGenerator, TypeSchemaParser } from "@typeschema/index";
14+
import { mkTypeSchemaIndex, type TreeShake, type TypeSchemaIndex, treeShake } from "@root/typeschema/utils";
15+
import { generateTypeSchemas, TypeSchemaGenerator, TypeSchemaParser } from "@typeschema/index";
1716
import { extractNameFromCanonical, packageMetaToFhir, packageMetaToNpm, type TypeSchema } from "@typeschema/types";
18-
import type { Config, TypeSchemaConfig } from "../config";
17+
import type { TypeSchemaConfig } from "../config";
1918
import { CodegenLogger, createLogger } from "../utils/codegen-logger";
20-
import type { GeneratorInput } from "./generators/base/BaseGenerator";
21-
import { TypeScriptGenerator as TypeScriptGeneratorDepricated } from "./generators/typescript";
2219
import { TypeScript, type TypeScriptOptions } from "./writer-generator/typescript";
2320
import type { Writer, WriterOptions } from "./writer-generator/writer";
2421

@@ -57,6 +54,14 @@ export interface GenerationResult {
5754
duration: number;
5855
}
5956

57+
export interface GeneratedFile {
58+
path: string;
59+
filename: string;
60+
timestamp: Date;
61+
}
62+
63+
export type GeneratorInput = { schemas: TypeSchema[]; index: TypeSchemaIndex };
64+
6065
interface Generator {
6166
generate: (input: GeneratorInput) => Promise<GeneratedFile[]>;
6267
setOutputDir: (outputDir: string) => void;
@@ -65,13 +70,10 @@ interface Generator {
6570

6671
const writerToGenerator = (writerGen: Writer): Generator => {
6772
const getGeneratedFiles = () => {
68-
return writerGen.writtenFiles().map((fn: string) => {
73+
return writerGen.writtenFiles().map((fn: string): GeneratedFile => {
6974
return {
7075
path: Path.normalize(Path.join(writerGen.opts.outputDir, fn)),
7176
filename: fn.replace(/^.*[\\/]/, ""),
72-
content: "",
73-
exports: [],
74-
size: 0,
7577
timestamp: new Date(),
7678
};
7779
});
@@ -206,7 +208,6 @@ export class APIBuilder {
206208
private schemas: TypeSchema[] = [];
207209
private options: APIBuilderConfig;
208210
private generators: Map<string, Generator> = new Map();
209-
private cache?: TypeSchemaCache;
210211
private pendingOperations: Promise<void>[] = [];
211212
private typeSchemaGenerator?: TypeSchemaGenerator;
212213
private logger: CodegenLogger;
@@ -238,10 +239,6 @@ export class APIBuilder {
238239
verbose: this.options.verbose,
239240
prefix: "API",
240241
});
241-
242-
if (this.options.cache) {
243-
this.cache = new TypeSchemaCache(this.typeSchemaConfig);
244-
}
245242
}
246243

247244
fromPackage(packageName: string, version?: string): APIBuilder {
@@ -268,47 +265,6 @@ export class APIBuilder {
268265
return this;
269266
}
270267

271-
typescriptDepricated(
272-
options: {
273-
moduleFormat?: "esm" | "cjs";
274-
generateIndex?: boolean;
275-
includeDocuments?: boolean;
276-
namingConvention?: "PascalCase" | "camelCase";
277-
includeExtensions?: boolean;
278-
includeProfiles?: boolean;
279-
generateValueSets?: boolean;
280-
includeValueSetHelpers?: boolean;
281-
valueSetStrengths?: ("required" | "preferred" | "extensible" | "example")[];
282-
valueSetMode?: "all" | "required-only" | "custom";
283-
valueSetDirectory?: string;
284-
} = {},
285-
): APIBuilder {
286-
const typesOutputDir = `${this.options.outputDir}/types`;
287-
288-
const generator = new TypeScriptGeneratorDepricated({
289-
outputDir: typesOutputDir,
290-
moduleFormat: options.moduleFormat || "esm",
291-
generateIndex: options.generateIndex ?? true,
292-
includeDocuments: options.includeDocuments ?? true,
293-
namingConvention: options.namingConvention || "PascalCase",
294-
includeExtensions: options.includeExtensions ?? false,
295-
includeProfiles: options.includeProfiles ?? false,
296-
generateValueSets: options.generateValueSets ?? false,
297-
includeValueSetHelpers: options.includeValueSetHelpers ?? false,
298-
valueSetStrengths: options.valueSetStrengths ?? ["required"],
299-
logger: this.logger.child("TS"),
300-
valueSetMode: options.valueSetMode ?? "required-only",
301-
valueSetDirectory: options.valueSetDirectory ?? "valuesets",
302-
verbose: this.options.verbose,
303-
validate: true, // Enable validation for debugging
304-
overwrite: this.options.overwrite,
305-
});
306-
307-
this.generators.set("typescript", generator);
308-
this.logger.debug(`Configured TypeScript generator (${options.moduleFormat || "esm"})`);
309-
return this;
310-
}
311-
312268
typescript(userOpts: Partial<TypeScriptOptions>) {
313269
const defaultWriterOpts: WriterOptions = {
314270
logger: this.logger,
@@ -510,14 +466,11 @@ export class APIBuilder {
510466

511467
private async loadFromFiles(filePaths: string[]): Promise<void> {
512468
if (!this.typeSchemaGenerator) {
513-
this.typeSchemaGenerator = new TypeSchemaGenerator(
514-
{
515-
verbose: this.options.verbose,
516-
logger: this.logger.child("Schema"),
517-
treeshake: this.typeSchemaConfig?.treeshake,
518-
},
519-
this.typeSchemaConfig,
520-
);
469+
this.typeSchemaGenerator = new TypeSchemaGenerator({
470+
verbose: this.options.verbose,
471+
logger: this.logger.child("Schema"),
472+
treeshake: this.typeSchemaConfig?.treeshake,
473+
});
521474
}
522475

523476
const parser = new TypeSchemaParser({
@@ -526,10 +479,6 @@ export class APIBuilder {
526479

527480
const schemas = await parser.parseFromFiles(filePaths);
528481
this.schemas = [...this.schemas, ...schemas];
529-
530-
if (this.cache) {
531-
this.cache.setMany(schemas);
532-
}
533482
}
534483

535484
private async executeGenerators(result: GenerationResult, input: GeneratorInput): Promise<void> {
@@ -549,36 +498,3 @@ export class APIBuilder {
549498
}
550499
}
551500
}
552-
553-
/**
554-
* Create an API builder instance from a configuration object
555-
*/
556-
export function createAPIFromConfig(config: Config): APIBuilder {
557-
const builder = new APIBuilder({
558-
outputDir: config.outputDir,
559-
verbose: config.verbose,
560-
overwrite: config.overwrite,
561-
cache: config.cache,
562-
cleanOutput: config.cleanOutput,
563-
typeSchemaConfig: config.typeSchema,
564-
});
565-
566-
// Add packages if specified
567-
if (config.packages && config.packages.length > 0) {
568-
for (const pkg of config.packages) {
569-
builder.fromPackage(pkg);
570-
}
571-
}
572-
573-
// Add files if specified
574-
if (config.files && config.files.length > 0) {
575-
builder.fromFiles(...config.files);
576-
}
577-
578-
// Configure TypeScript generator if specified
579-
if (config.typescript) {
580-
builder.typescriptDepricated(config.typescript);
581-
}
582-
583-
return builder;
584-
}

0 commit comments

Comments
 (0)