Skip to content

Commit c19171b

Browse files
committed
Rename: Identifier -> TypeIdentifier; NestedTypeSchema -> NestedType.
1 parent 2d9b25f commit c19171b

24 files changed

Lines changed: 169 additions & 152 deletions

src/api/mustache/generator/NameGenerator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Field, Identifier, NestedType, TypeSchema } from "@typeschema/types";
1+
import type { Field, NestedTypeSchema, TypeIdentifier, TypeSchema } from "@typeschema/types";
22

33
export type NameTransformation = {
44
pattern: RegExp | string;
@@ -65,7 +65,7 @@ export class NameGenerator {
6565
return this._generateTypeName(name);
6666
}
6767

68-
private _generateTypeFromTypeRef(typeRef: Identifier): string {
68+
private _generateTypeFromTypeRef(typeRef: TypeIdentifier): string {
6969
if (typeRef.kind === "primitive-type") {
7070
return this._generateTypeName(typeRef.name);
7171
}
@@ -86,7 +86,7 @@ export class NameGenerator {
8686
return this._generateTypeFromTypeRef((schema as any).type);
8787
}
8888

89-
public generateType(schemaOrRefOrString: TypeSchema | NestedType | Identifier | string): string {
89+
public generateType(schemaOrRefOrString: TypeSchema | NestedTypeSchema | TypeIdentifier | string): string {
9090
if (typeof schemaOrRefOrString === "string") {
9191
return this._generateTypeName(schemaOrRefOrString);
9292
}

src/api/mustache/generator/ViewModelFactory.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import type { IsPrefixed } from "@root/utils/types";
1515
import {
1616
type ChoiceFieldInstance,
1717
type Field,
18-
type Identifier,
1918
isComplexTypeIdentifier,
2019
isNotChoiceDeclarationField,
2120
isResourceIdentifier,
22-
type NestedType,
21+
type NestedTypeSchema,
2322
type RegularField,
23+
type TypeIdentifier,
2424
type TypeSchema,
2525
} from "@typeschema/types";
2626

@@ -35,15 +35,15 @@ export class ViewModelFactory {
3535
constructor(
3636
private readonly tsIndex: TypeSchemaIndex,
3737
private readonly nameGenerator: NameGenerator,
38-
private readonly filterPred: (id: Identifier) => boolean,
38+
private readonly filterPred: (id: TypeIdentifier) => boolean,
3939
) {}
4040

4141
public createUtility(): RootViewModel<ViewModel> {
4242
return this._createForRoot();
4343
}
4444

4545
public createComplexType(
46-
typeRef: Identifier,
46+
typeRef: TypeIdentifier,
4747
cache: ViewModelCache = { resourcesByUri: {}, complexTypesByUri: {} },
4848
): RootViewModel<ResolvedTypeViewModel> {
4949
const base = this._createForComplexType(typeRef, cache);
@@ -64,7 +64,7 @@ export class ViewModelFactory {
6464
});
6565
}
6666
public createResource(
67-
typeRef: Identifier,
67+
typeRef: TypeIdentifier,
6868
cache: ViewModelCache = { resourcesByUri: {}, complexTypesByUri: {} },
6969
): RootViewModel<ResolvedTypeViewModel> {
7070
const base = this._createForResource(typeRef, cache);
@@ -85,7 +85,7 @@ export class ViewModelFactory {
8585
});
8686
}
8787

88-
private _createFor(typeRef: Identifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel {
88+
private _createFor(typeRef: TypeIdentifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel {
8989
if (typeRef.kind === "complex-type") {
9090
return this._createForComplexType(typeRef, cache, nestedIn);
9191
}
@@ -95,7 +95,11 @@ export class ViewModelFactory {
9595
throw new Error(`Unknown type ${typeRef.kind}`);
9696
}
9797

98-
private _createForComplexType(typeRef: Identifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel {
98+
private _createForComplexType(
99+
typeRef: TypeIdentifier,
100+
cache: ViewModelCache,
101+
nestedIn?: TypeSchema,
102+
): TypeViewModel {
99103
const type = this.tsIndex.resolve(typeRef);
100104
if (!type) {
101105
throw new Error(`ComplexType ${typeRef.name} not found`);
@@ -108,7 +112,7 @@ export class ViewModelFactory {
108112
return res;
109113
}
110114

111-
private _createForResource(typeRef: Identifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel {
115+
private _createForResource(typeRef: TypeIdentifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel {
112116
const type = this.tsIndex.resolve(typeRef);
113117
if (!type) {
114118
throw new Error(`Resource ${typeRef.name} not found`);
@@ -121,25 +125,25 @@ export class ViewModelFactory {
121125
return res;
122126
}
123127

124-
private _createChildrenFor(typeRef: Identifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel[] {
128+
private _createChildrenFor(typeRef: TypeIdentifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel[] {
125129
const schema = this.tsIndex.resolve(typeRef);
126130
if (!schema || !("typeFamily" in schema)) return [];
127131
if (isComplexTypeIdentifier(typeRef)) {
128132
return (schema.typeFamily?.complexTypes ?? [])
129133
.filter(this.filterPred)
130-
.map((childRef: Identifier) => this._createFor(childRef, cache, nestedIn));
134+
.map((childRef: TypeIdentifier) => this._createFor(childRef, cache, nestedIn));
131135
}
132136
if (isResourceIdentifier(typeRef)) {
133137
return (schema.typeFamily?.resources ?? [])
134138
.filter(this.filterPred)
135-
.map((childRef: Identifier) => this._createFor(childRef, cache, nestedIn));
139+
.map((childRef: TypeIdentifier) => this._createFor(childRef, cache, nestedIn));
136140
}
137141
return [];
138142
}
139143

140-
private _createParentsFor(base: TypeSchema | NestedType, cache: ViewModelCache) {
144+
private _createParentsFor(base: TypeSchema | NestedTypeSchema, cache: ViewModelCache) {
141145
const parents: TypeViewModel[] = [];
142-
let parentRef: Identifier | undefined = "base" in base ? base.base : undefined;
146+
let parentRef: TypeIdentifier | undefined = "base" in base ? base.base : undefined;
143147
while (parentRef) {
144148
parents.push(this._createFor(parentRef, cache, undefined));
145149
const parent = this.tsIndex.resolve(parentRef);
@@ -149,7 +153,7 @@ export class ViewModelFactory {
149153
}
150154

151155
private _createForNestedType(
152-
nested: NestedType,
156+
nested: NestedTypeSchema,
153157
cache: ViewModelCache,
154158
nestedIn?: TypeSchema,
155159
): ResolvedTypeViewModel {
@@ -171,7 +175,7 @@ export class ViewModelFactory {
171175
}
172176

173177
private _createTypeViewModel(
174-
schema: TypeSchema | NestedType,
178+
schema: TypeSchema | NestedTypeSchema,
175179
cache: ViewModelCache,
176180
nestedIn?: TypeSchema,
177181
): TypeViewModel {
@@ -229,7 +233,7 @@ export class ViewModelFactory {
229233
};
230234
}
231235

232-
private _collectDependencies(schema: TypeSchema | NestedType): TypeViewModel["dependencies"] {
236+
private _collectDependencies(schema: TypeSchema | NestedTypeSchema): TypeViewModel["dependencies"] {
233237
const dependencies: TypeViewModel["dependencies"] = {
234238
resources: [],
235239
complexTypes: [],
@@ -273,35 +277,35 @@ export class ViewModelFactory {
273277
return dependencies;
274278
}
275279

276-
private _createIsResource(typeRef: Identifier): Record<IsPrefixed<string>, boolean> | false {
280+
private _createIsResource(typeRef: TypeIdentifier): Record<IsPrefixed<string>, boolean> | false {
277281
if (typeRef.kind !== "resource") {
278282
return false;
279283
}
280284
return Object.fromEntries(
281285
this.tsIndex
282286
.collectResources()
283287
.map((e) => e.identifier)
284-
.map((resourceRef: Identifier) => [
288+
.map((resourceRef: TypeIdentifier) => [
285289
`is${resourceRef.name.charAt(0).toUpperCase() + resourceRef.name.slice(1)}`,
286290
resourceRef.url === typeRef.url,
287291
]),
288292
) as Record<IsPrefixed<string>, boolean>;
289293
}
290-
private _createIsComplexType(typeRef: Identifier): Record<IsPrefixed<string>, boolean> | false {
294+
private _createIsComplexType(typeRef: TypeIdentifier): Record<IsPrefixed<string>, boolean> | false {
291295
if (typeRef.kind !== "complex-type" && typeRef.kind !== "nested") {
292296
return false;
293297
}
294298
return Object.fromEntries(
295299
this.tsIndex
296300
.collectComplexTypes()
297301
.map((e) => e.identifier)
298-
.map((complexTypeRef: Identifier) => [
302+
.map((complexTypeRef: TypeIdentifier) => [
299303
`is${complexTypeRef.name.charAt(0).toUpperCase() + complexTypeRef.name.slice(1)}`,
300304
complexTypeRef.url === typeRef.url,
301305
]),
302306
) as Record<IsPrefixed<string>, boolean>;
303307
}
304-
private _createIsPrimitiveType(typeRef: Identifier): Record<IsPrefixed<string>, boolean> | false {
308+
private _createIsPrimitiveType(typeRef: TypeIdentifier): Record<IsPrefixed<string>, boolean> | false {
305309
if (typeRef.kind !== "primitive-type") {
306310
return false;
307311
}
@@ -310,7 +314,10 @@ export class ViewModelFactory {
310314
) as FieldViewModel["isPrimitive"];
311315
}
312316

313-
private _collectNestedComplex(schema: TypeSchema | NestedType, cache: ViewModelCache): ResolvedTypeViewModel[] {
317+
private _collectNestedComplex(
318+
schema: TypeSchema | NestedTypeSchema,
319+
cache: ViewModelCache,
320+
): ResolvedTypeViewModel[] {
314321
const nested: ResolvedTypeViewModel[] = [];
315322
if ("nested" in schema && schema.nested) {
316323
schema.nested
@@ -347,14 +354,14 @@ export class ViewModelFactory {
347354
complexTypes: this.tsIndex
348355
.collectComplexTypes()
349356
.map((e) => e.identifier)
350-
.map((typeRef: Identifier) => ({
357+
.map((typeRef: TypeIdentifier) => ({
351358
name: typeRef.name,
352359
saveName: this.nameGenerator.generateType(typeRef),
353360
})),
354361
resources: this.tsIndex
355362
.collectResources()
356363
.map((e) => e.identifier)
357-
.map((typeRef: Identifier) => ({
364+
.map((typeRef: TypeIdentifier) => ({
358365
name: typeRef.name,
359366
saveName: this.nameGenerator.generateType(typeRef),
360367
})),

src/api/mustache/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IsPrefixed } from "@root/utils/types";
2-
import type { Field, NestedType, TypeSchema } from "@typeschema/types";
2+
import type { Field, NestedTypeSchema, TypeSchema } from "@typeschema/types";
33

44
export type DebugMixin = {
55
debug: string;
@@ -131,7 +131,7 @@ export type RootViewModel<T> = T & {
131131
};
132132

133133
export type TypeViewModel = NamedViewModel & {
134-
schema: TypeSchema | NestedType;
134+
schema: TypeSchema | NestedTypeSchema;
135135
fields: FieldViewModel[];
136136

137137
dependencies: {

src/api/writer-generator/csharp/csharp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
44
import { pascalCase, uppercaseFirstLetter, uppercaseFirstLetterOfEach } from "@root/api/writer-generator/utils.ts";
55
import { Writer, type WriterOptions } from "@root/api/writer-generator/writer.ts";
66
import type { PartialBy } from "@root/utils/types.ts";
7-
import type { Field, Identifier, RegularField } from "@typeschema/types";
7+
import type { Field, RegularField, TypeIdentifier } from "@typeschema/types";
88
import {
99
type ChoiceFieldInstance,
1010
isChoiceDeclarationField,
@@ -74,7 +74,7 @@ const canonicalToName = (canonical: string | undefined, dropFragment = true): st
7474
return formatName(localName);
7575
};
7676

77-
const getResourceName = (id: Identifier): string => {
77+
const getResourceName = (id: TypeIdentifier): string => {
7878
if (id.kind === "nested") {
7979
const url = id.url;
8080
const path = canonicalToName(url, false);

src/api/writer-generator/python.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
55
import { camelCase, pascalCase, snakeCase, uppercaseFirstLetterOfEach } from "@root/api/writer-generator/utils";
66
import { Writer, type WriterOptions } from "@root/api/writer-generator/writer.ts";
77
import { groupByPackages, sortAsDeclarationSequence, type TypeSchemaIndex } from "@root/typeschema/utils";
8-
import type { EnumDefinition, Field, Identifier, SpecializationTypeSchema } from "@typeschema/types.ts";
8+
import type { EnumDefinition, Field, SpecializationTypeSchema, TypeIdentifier } from "@typeschema/types.ts";
99

1010
const PRIMITIVE_TYPE_MAP: Record<string, string> = {
1111
boolean: "bool",
@@ -125,7 +125,7 @@ const canonicalToName = (canonical: string | undefined, dropFragment = true) =>
125125
return snakeCase(localName);
126126
};
127127

128-
const deriveResourceName = (id: Identifier): string => {
128+
const deriveResourceName = (id: TypeIdentifier): string => {
129129
if (id.kind === "nested") {
130130
const url = id.url;
131131
const path = canonicalToName(url, false);
@@ -585,7 +585,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
585585
this.importResourceDependencies(schema.dependencies);
586586
}
587587

588-
private importComplexTypeDependencies(dependencies: Identifier[]): void {
588+
private importComplexTypeDependencies(dependencies: TypeIdentifier[]): void {
589589
const complexTypeDeps = dependencies.filter((dep) => dep.kind === "complex-type");
590590
const depsByPackage = this.groupDependenciesByPackage(complexTypeDeps);
591591

@@ -594,7 +594,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
594594
}
595595
}
596596

597-
private importResourceDependencies(dependencies: Identifier[]): void {
597+
private importResourceDependencies(dependencies: TypeIdentifier[]): void {
598598
const resourceDeps = dependencies.filter((dep) => dep.kind === "resource");
599599

600600
for (const dep of resourceDeps) {
@@ -606,7 +606,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
606606
}
607607
}
608608

609-
private groupDependenciesByPackage(dependencies: Identifier[]): ImportGroup {
609+
private groupDependenciesByPackage(dependencies: TypeIdentifier[]): ImportGroup {
610610
const grouped: ImportGroup = {};
611611

612612
for (const dep of dependencies) {
@@ -646,7 +646,7 @@ export class Python extends Writer<PythonGeneratorOptions> {
646646
this.line(")");
647647
}
648648

649-
private pyImportType(identifier: Identifier): void {
649+
private pyImportType(identifier: TypeIdentifier): void {
650650
this.pyImportFrom(this.pyPackage(identifier), pascalCase(identifier.name));
651651
}
652652

@@ -727,15 +727,15 @@ export class Python extends Writer<PythonGeneratorOptions> {
727727
return parts.join(".");
728728
}
729729

730-
private pyFhirPackage(identifier: Identifier): string {
730+
private pyFhirPackage(identifier: TypeIdentifier): string {
731731
return this.pyFhirPackageByName(identifier.package);
732732
}
733733

734734
private pyFhirPackageByName(name: string): string {
735735
return [this.opts.rootPackageName, this.buildPyPackageName(name)].join(".");
736736
}
737737

738-
private pyPackage(identifier: Identifier): string {
738+
private pyPackage(identifier: TypeIdentifier): string {
739739
if (identifier.kind === "complex-type") {
740740
return `${this.pyFhirPackage(identifier)}.base`;
741741
}

src/api/writer-generator/typescript/name.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
import {
88
type CanonicalUrl,
99
extractNameFromCanonical,
10-
type Identifier,
1110
type ProfileTypeSchema,
11+
type TypeIdentifier,
1212
} from "@root/typeschema/types";
1313
import type { TypeSchemaIndex } from "@root/typeschema/utils";
1414

@@ -31,7 +31,7 @@ export const tsPackageDir = (name: string): string => {
3131
return kebabCase(name);
3232
};
3333

34-
export const tsModuleName = (id: Identifier): string => {
34+
export const tsModuleName = (id: TypeIdentifier): string => {
3535
// NOTE: Why not pascal case?
3636
// In hl7-fhir-uv-xver-r5-r4 we have:
3737
// - http://hl7.org/fhir/5.0/StructureDefinition/extension-Subscription.topic (subscription_topic)
@@ -40,11 +40,11 @@ export const tsModuleName = (id: Identifier): string => {
4040
return uppercaseFirstLetter(tsResourceName(id));
4141
};
4242

43-
export const tsModuleFileName = (id: Identifier): string => {
43+
export const tsModuleFileName = (id: TypeIdentifier): string => {
4444
return `${tsModuleName(id)}.ts`;
4545
};
4646

47-
export const tsModulePath = (id: Identifier): string => {
47+
export const tsModulePath = (id: TypeIdentifier): string => {
4848
return `${tsPackageDir(id.package)}/${tsModuleName(id)}`;
4949
};
5050

@@ -55,7 +55,7 @@ export const tsNameFromCanonical = (canonical: string | undefined, dropFragment
5555
return normalizeTsName(localName);
5656
};
5757

58-
export const tsResourceName = (id: Identifier): string => {
58+
export const tsResourceName = (id: TypeIdentifier): string => {
5959
if (id.kind === "nested") {
6060
const url = id.url;
6161
// Extract name from URL without normalizing dots (needed for fragment splitting)
@@ -137,4 +137,4 @@ export const tsResolvedSliceBaseName = (
137137
sliceName: string,
138138
): string => sliceBaseNames[`${fieldName}:${sliceName}`] ?? sliceName;
139139

140-
export const tsValueFieldName = (id: Identifier): string => `value${uppercaseFirstLetter(id.name)}`;
140+
export const tsValueFieldName = (id: TypeIdentifier): string => `value${uppercaseFirstLetter(id.name)}`;

0 commit comments

Comments
 (0)