diff --git a/src/api/mustache/generator/NameGenerator.ts b/src/api/mustache/generator/NameGenerator.ts index 5719c51cb..e4e12ca71 100644 --- a/src/api/mustache/generator/NameGenerator.ts +++ b/src/api/mustache/generator/NameGenerator.ts @@ -1,4 +1,4 @@ -import type { Field, Identifier, NestedType, TypeSchema } from "@typeschema/types"; +import type { Field, NestedTypeSchema, TypeIdentifier, TypeSchema } from "@typeschema/types"; export type NameTransformation = { pattern: RegExp | string; @@ -65,7 +65,7 @@ export class NameGenerator { return this._generateTypeName(name); } - private _generateTypeFromTypeRef(typeRef: Identifier): string { + private _generateTypeFromTypeRef(typeRef: TypeIdentifier): string { if (typeRef.kind === "primitive-type") { return this._generateTypeName(typeRef.name); } @@ -86,7 +86,7 @@ export class NameGenerator { return this._generateTypeFromTypeRef((schema as any).type); } - public generateType(schemaOrRefOrString: TypeSchema | NestedType | Identifier | string): string { + public generateType(schemaOrRefOrString: TypeSchema | NestedTypeSchema | TypeIdentifier | string): string { if (typeof schemaOrRefOrString === "string") { return this._generateTypeName(schemaOrRefOrString); } diff --git a/src/api/mustache/generator/ViewModelFactory.ts b/src/api/mustache/generator/ViewModelFactory.ts index e190c6e58..78a7b6e09 100644 --- a/src/api/mustache/generator/ViewModelFactory.ts +++ b/src/api/mustache/generator/ViewModelFactory.ts @@ -15,12 +15,12 @@ import type { IsPrefixed } from "@root/utils/types"; import { type ChoiceFieldInstance, type Field, - type Identifier, isComplexTypeIdentifier, isNotChoiceDeclarationField, isResourceIdentifier, - type NestedType, + type NestedTypeSchema, type RegularField, + type TypeIdentifier, type TypeSchema, } from "@typeschema/types"; @@ -35,7 +35,7 @@ export class ViewModelFactory { constructor( private readonly tsIndex: TypeSchemaIndex, private readonly nameGenerator: NameGenerator, - private readonly filterPred: (id: Identifier) => boolean, + private readonly filterPred: (id: TypeIdentifier) => boolean, ) {} public createUtility(): RootViewModel { @@ -43,7 +43,7 @@ export class ViewModelFactory { } public createComplexType( - typeRef: Identifier, + typeRef: TypeIdentifier, cache: ViewModelCache = { resourcesByUri: {}, complexTypesByUri: {} }, ): RootViewModel { const base = this._createForComplexType(typeRef, cache); @@ -64,7 +64,7 @@ export class ViewModelFactory { }); } public createResource( - typeRef: Identifier, + typeRef: TypeIdentifier, cache: ViewModelCache = { resourcesByUri: {}, complexTypesByUri: {} }, ): RootViewModel { const base = this._createForResource(typeRef, cache); @@ -85,7 +85,7 @@ export class ViewModelFactory { }); } - private _createFor(typeRef: Identifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel { + private _createFor(typeRef: TypeIdentifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel { if (typeRef.kind === "complex-type") { return this._createForComplexType(typeRef, cache, nestedIn); } @@ -95,7 +95,11 @@ export class ViewModelFactory { throw new Error(`Unknown type ${typeRef.kind}`); } - private _createForComplexType(typeRef: Identifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel { + private _createForComplexType( + typeRef: TypeIdentifier, + cache: ViewModelCache, + nestedIn?: TypeSchema, + ): TypeViewModel { const type = this.tsIndex.resolve(typeRef); if (!type) { throw new Error(`ComplexType ${typeRef.name} not found`); @@ -108,7 +112,7 @@ export class ViewModelFactory { return res; } - private _createForResource(typeRef: Identifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel { + private _createForResource(typeRef: TypeIdentifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel { const type = this.tsIndex.resolve(typeRef); if (!type) { throw new Error(`Resource ${typeRef.name} not found`); @@ -121,25 +125,25 @@ export class ViewModelFactory { return res; } - private _createChildrenFor(typeRef: Identifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel[] { + private _createChildrenFor(typeRef: TypeIdentifier, cache: ViewModelCache, nestedIn?: TypeSchema): TypeViewModel[] { const schema = this.tsIndex.resolve(typeRef); if (!schema || !("typeFamily" in schema)) return []; if (isComplexTypeIdentifier(typeRef)) { return (schema.typeFamily?.complexTypes ?? []) .filter(this.filterPred) - .map((childRef: Identifier) => this._createFor(childRef, cache, nestedIn)); + .map((childRef: TypeIdentifier) => this._createFor(childRef, cache, nestedIn)); } if (isResourceIdentifier(typeRef)) { return (schema.typeFamily?.resources ?? []) .filter(this.filterPred) - .map((childRef: Identifier) => this._createFor(childRef, cache, nestedIn)); + .map((childRef: TypeIdentifier) => this._createFor(childRef, cache, nestedIn)); } return []; } - private _createParentsFor(base: TypeSchema | NestedType, cache: ViewModelCache) { + private _createParentsFor(base: TypeSchema | NestedTypeSchema, cache: ViewModelCache) { const parents: TypeViewModel[] = []; - let parentRef: Identifier | undefined = "base" in base ? base.base : undefined; + let parentRef: TypeIdentifier | undefined = "base" in base ? base.base : undefined; while (parentRef) { parents.push(this._createFor(parentRef, cache, undefined)); const parent = this.tsIndex.resolve(parentRef); @@ -149,7 +153,7 @@ export class ViewModelFactory { } private _createForNestedType( - nested: NestedType, + nested: NestedTypeSchema, cache: ViewModelCache, nestedIn?: TypeSchema, ): ResolvedTypeViewModel { @@ -171,7 +175,7 @@ export class ViewModelFactory { } private _createTypeViewModel( - schema: TypeSchema | NestedType, + schema: TypeSchema | NestedTypeSchema, cache: ViewModelCache, nestedIn?: TypeSchema, ): TypeViewModel { @@ -229,7 +233,7 @@ export class ViewModelFactory { }; } - private _collectDependencies(schema: TypeSchema | NestedType): TypeViewModel["dependencies"] { + private _collectDependencies(schema: TypeSchema | NestedTypeSchema): TypeViewModel["dependencies"] { const dependencies: TypeViewModel["dependencies"] = { resources: [], complexTypes: [], @@ -273,7 +277,7 @@ export class ViewModelFactory { return dependencies; } - private _createIsResource(typeRef: Identifier): Record, boolean> | false { + private _createIsResource(typeRef: TypeIdentifier): Record, boolean> | false { if (typeRef.kind !== "resource") { return false; } @@ -281,13 +285,13 @@ export class ViewModelFactory { this.tsIndex .collectResources() .map((e) => e.identifier) - .map((resourceRef: Identifier) => [ + .map((resourceRef: TypeIdentifier) => [ `is${resourceRef.name.charAt(0).toUpperCase() + resourceRef.name.slice(1)}`, resourceRef.url === typeRef.url, ]), ) as Record, boolean>; } - private _createIsComplexType(typeRef: Identifier): Record, boolean> | false { + private _createIsComplexType(typeRef: TypeIdentifier): Record, boolean> | false { if (typeRef.kind !== "complex-type" && typeRef.kind !== "nested") { return false; } @@ -295,13 +299,13 @@ export class ViewModelFactory { this.tsIndex .collectComplexTypes() .map((e) => e.identifier) - .map((complexTypeRef: Identifier) => [ + .map((complexTypeRef: TypeIdentifier) => [ `is${complexTypeRef.name.charAt(0).toUpperCase() + complexTypeRef.name.slice(1)}`, complexTypeRef.url === typeRef.url, ]), ) as Record, boolean>; } - private _createIsPrimitiveType(typeRef: Identifier): Record, boolean> | false { + private _createIsPrimitiveType(typeRef: TypeIdentifier): Record, boolean> | false { if (typeRef.kind !== "primitive-type") { return false; } @@ -310,7 +314,10 @@ export class ViewModelFactory { ) as FieldViewModel["isPrimitive"]; } - private _collectNestedComplex(schema: TypeSchema | NestedType, cache: ViewModelCache): ResolvedTypeViewModel[] { + private _collectNestedComplex( + schema: TypeSchema | NestedTypeSchema, + cache: ViewModelCache, + ): ResolvedTypeViewModel[] { const nested: ResolvedTypeViewModel[] = []; if ("nested" in schema && schema.nested) { schema.nested @@ -347,14 +354,14 @@ export class ViewModelFactory { complexTypes: this.tsIndex .collectComplexTypes() .map((e) => e.identifier) - .map((typeRef: Identifier) => ({ + .map((typeRef: TypeIdentifier) => ({ name: typeRef.name, saveName: this.nameGenerator.generateType(typeRef), })), resources: this.tsIndex .collectResources() .map((e) => e.identifier) - .map((typeRef: Identifier) => ({ + .map((typeRef: TypeIdentifier) => ({ name: typeRef.name, saveName: this.nameGenerator.generateType(typeRef), })), diff --git a/src/api/mustache/types.ts b/src/api/mustache/types.ts index 8342eac6c..75f764840 100644 --- a/src/api/mustache/types.ts +++ b/src/api/mustache/types.ts @@ -1,5 +1,5 @@ import type { IsPrefixed } from "@root/utils/types"; -import type { Field, NestedType, TypeSchema } from "@typeschema/types"; +import type { Field, NestedTypeSchema, TypeSchema } from "@typeschema/types"; export type DebugMixin = { debug: string; @@ -131,7 +131,7 @@ export type RootViewModel = T & { }; export type TypeViewModel = NamedViewModel & { - schema: TypeSchema | NestedType; + schema: TypeSchema | NestedTypeSchema; fields: FieldViewModel[]; dependencies: { diff --git a/src/api/writer-generator/csharp/csharp.ts b/src/api/writer-generator/csharp/csharp.ts index cd42aba83..29bdf546f 100644 --- a/src/api/writer-generator/csharp/csharp.ts +++ b/src/api/writer-generator/csharp/csharp.ts @@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url"; import { pascalCase, uppercaseFirstLetter, uppercaseFirstLetterOfEach } from "@root/api/writer-generator/utils.ts"; import { Writer, type WriterOptions } from "@root/api/writer-generator/writer.ts"; import type { PartialBy } from "@root/utils/types.ts"; -import type { Field, Identifier, RegularField } from "@typeschema/types"; +import type { Field, RegularField, TypeIdentifier } from "@typeschema/types"; import { type ChoiceFieldInstance, isChoiceDeclarationField, @@ -74,7 +74,7 @@ const canonicalToName = (canonical: string | undefined, dropFragment = true): st return formatName(localName); }; -const getResourceName = (id: Identifier): string => { +const getResourceName = (id: TypeIdentifier): string => { if (id.kind === "nested") { const url = id.url; const path = canonicalToName(url, false); diff --git a/src/api/writer-generator/python.ts b/src/api/writer-generator/python.ts index da9ce4d1f..7c87b9795 100644 --- a/src/api/writer-generator/python.ts +++ b/src/api/writer-generator/python.ts @@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url"; import { camelCase, pascalCase, snakeCase, uppercaseFirstLetterOfEach } from "@root/api/writer-generator/utils"; import { Writer, type WriterOptions } from "@root/api/writer-generator/writer.ts"; import { groupByPackages, sortAsDeclarationSequence, type TypeSchemaIndex } from "@root/typeschema/utils"; -import type { EnumDefinition, Field, Identifier, SpecializationTypeSchema } from "@typeschema/types.ts"; +import type { EnumDefinition, Field, SpecializationTypeSchema, TypeIdentifier } from "@typeschema/types.ts"; const PRIMITIVE_TYPE_MAP: Record = { boolean: "bool", @@ -125,7 +125,7 @@ const canonicalToName = (canonical: string | undefined, dropFragment = true) => return snakeCase(localName); }; -const deriveResourceName = (id: Identifier): string => { +const deriveResourceName = (id: TypeIdentifier): string => { if (id.kind === "nested") { const url = id.url; const path = canonicalToName(url, false); @@ -585,7 +585,7 @@ export class Python extends Writer { this.importResourceDependencies(schema.dependencies); } - private importComplexTypeDependencies(dependencies: Identifier[]): void { + private importComplexTypeDependencies(dependencies: TypeIdentifier[]): void { const complexTypeDeps = dependencies.filter((dep) => dep.kind === "complex-type"); const depsByPackage = this.groupDependenciesByPackage(complexTypeDeps); @@ -594,7 +594,7 @@ export class Python extends Writer { } } - private importResourceDependencies(dependencies: Identifier[]): void { + private importResourceDependencies(dependencies: TypeIdentifier[]): void { const resourceDeps = dependencies.filter((dep) => dep.kind === "resource"); for (const dep of resourceDeps) { @@ -606,7 +606,7 @@ export class Python extends Writer { } } - private groupDependenciesByPackage(dependencies: Identifier[]): ImportGroup { + private groupDependenciesByPackage(dependencies: TypeIdentifier[]): ImportGroup { const grouped: ImportGroup = {}; for (const dep of dependencies) { @@ -646,7 +646,7 @@ export class Python extends Writer { this.line(")"); } - private pyImportType(identifier: Identifier): void { + private pyImportType(identifier: TypeIdentifier): void { this.pyImportFrom(this.pyPackage(identifier), pascalCase(identifier.name)); } @@ -727,7 +727,7 @@ export class Python extends Writer { return parts.join("."); } - private pyFhirPackage(identifier: Identifier): string { + private pyFhirPackage(identifier: TypeIdentifier): string { return this.pyFhirPackageByName(identifier.package); } @@ -735,7 +735,7 @@ export class Python extends Writer { return [this.opts.rootPackageName, this.buildPyPackageName(name)].join("."); } - private pyPackage(identifier: Identifier): string { + private pyPackage(identifier: TypeIdentifier): string { if (identifier.kind === "complex-type") { return `${this.pyFhirPackage(identifier)}.base`; } diff --git a/src/api/writer-generator/typescript/name.ts b/src/api/writer-generator/typescript/name.ts index 49e821e4c..6eacb5281 100644 --- a/src/api/writer-generator/typescript/name.ts +++ b/src/api/writer-generator/typescript/name.ts @@ -7,8 +7,8 @@ import { import { type CanonicalUrl, extractNameFromCanonical, - type Identifier, type ProfileTypeSchema, + type TypeIdentifier, } from "@root/typeschema/types"; import type { TypeSchemaIndex } from "@root/typeschema/utils"; @@ -31,7 +31,7 @@ export const tsPackageDir = (name: string): string => { return kebabCase(name); }; -export const tsModuleName = (id: Identifier): string => { +export const tsModuleName = (id: TypeIdentifier): string => { // NOTE: Why not pascal case? // In hl7-fhir-uv-xver-r5-r4 we have: // - http://hl7.org/fhir/5.0/StructureDefinition/extension-Subscription.topic (subscription_topic) @@ -40,11 +40,11 @@ export const tsModuleName = (id: Identifier): string => { return uppercaseFirstLetter(tsResourceName(id)); }; -export const tsModuleFileName = (id: Identifier): string => { +export const tsModuleFileName = (id: TypeIdentifier): string => { return `${tsModuleName(id)}.ts`; }; -export const tsModulePath = (id: Identifier): string => { +export const tsModulePath = (id: TypeIdentifier): string => { return `${tsPackageDir(id.package)}/${tsModuleName(id)}`; }; @@ -55,7 +55,7 @@ export const tsNameFromCanonical = (canonical: string | undefined, dropFragment return normalizeTsName(localName); }; -export const tsResourceName = (id: Identifier): string => { +export const tsResourceName = (id: TypeIdentifier): string => { if (id.kind === "nested") { const url = id.url; // Extract name from URL without normalizing dots (needed for fragment splitting) @@ -137,4 +137,4 @@ export const tsResolvedSliceBaseName = ( sliceName: string, ): string => sliceBaseNames[`${fieldName}:${sliceName}`] ?? sliceName; -export const tsValueFieldName = (id: Identifier): string => `value${uppercaseFirstLetter(id.name)}`; +export const tsValueFieldName = (id: TypeIdentifier): string => `value${uppercaseFirstLetter(id.name)}`; diff --git a/src/api/writer-generator/typescript/profile-extensions.ts b/src/api/writer-generator/typescript/profile-extensions.ts index a6f59ded3..cf86a3ad4 100644 --- a/src/api/writer-generator/typescript/profile-extensions.ts +++ b/src/api/writer-generator/typescript/profile-extensions.ts @@ -1,10 +1,10 @@ import { type CanonicalUrl, - type Identifier, isChoiceDeclarationField, isProfileTypeSchema, type ProfileExtension, type ProfileTypeSchema, + type TypeIdentifier, } from "@root/typeschema/types"; import type { TypeSchemaIndex } from "@root/typeschema/utils"; import { @@ -419,7 +419,7 @@ export const generateExtensionMethods = ( export const collectTypesFromExtensions = ( tsIndex: TypeSchemaIndex, flatProfile: ProfileTypeSchema, - addType: (typeId: Identifier) => void, + addType: (typeId: TypeIdentifier) => void, ): boolean => { let needsExtensionType = false; @@ -455,7 +455,7 @@ export const collectTypesFromExtensions = ( export const collectTypesFromFlatInput = ( tsIndex: TypeSchemaIndex, flatProfile: ProfileTypeSchema, - addType: (typeId: Identifier) => void, + addType: (typeId: TypeIdentifier) => void, ) => { if (flatProfile.base.name !== "Extension") return; const subSlices = collectSubExtensionSlices(flatProfile); diff --git a/src/api/writer-generator/typescript/profile-slices.ts b/src/api/writer-generator/typescript/profile-slices.ts index a6bd52cd8..1166a08b7 100644 --- a/src/api/writer-generator/typescript/profile-slices.ts +++ b/src/api/writer-generator/typescript/profile-slices.ts @@ -1,11 +1,11 @@ import { type ConstrainedChoiceInfo, - type Identifier, isChoiceDeclarationField, isNotChoiceDeclarationField, isPrimitiveIdentifier, type ProfileTypeSchema, type RegularField, + type TypeIdentifier, } from "@root/typeschema/types"; import type { TypeSchemaIndex } from "@root/typeschema/utils"; import { @@ -20,7 +20,7 @@ import { tsGet, tsTypeFromIdentifier } from "./utils"; import type { TypeScript } from "./writer"; /** Collect choice declaration field names from a base type schema */ -const collectChoiceBaseNames = (tsIndex: TypeSchemaIndex, typeId: Identifier): Set => { +const collectChoiceBaseNames = (tsIndex: TypeSchemaIndex, typeId: TypeIdentifier): Set => { const names = new Set(); const schema = tsIndex.resolve(typeId); if (schema && "fields" in schema && schema.fields) { @@ -46,7 +46,7 @@ export const extractResourceTypeFromMatch = (match: Record): st export const collectTypesFromSlices = ( tsIndex: TypeSchemaIndex, flatProfile: ProfileTypeSchema, - addType: (typeId: Identifier) => void, + addType: (typeId: TypeIdentifier) => void, ) => { const pkgName = flatProfile.identifier.package; for (const field of Object.values(flatProfile.fields ?? {})) { diff --git a/src/api/writer-generator/typescript/profile-validation.ts b/src/api/writer-generator/typescript/profile-validation.ts index e5270f765..22f6ebe68 100644 --- a/src/api/writer-generator/typescript/profile-validation.ts +++ b/src/api/writer-generator/typescript/profile-validation.ts @@ -1,10 +1,10 @@ import { type ChoiceFieldInstance, - type Identifier, isChoiceDeclarationField, isChoiceInstanceField, type ProfileTypeSchema, type RegularField, + type TypeIdentifier, } from "@root/typeschema/types"; import type { TypeSchemaIndex } from "@root/typeschema/utils"; import { tsProfileClassName } from "./name"; @@ -15,7 +15,7 @@ export const collectRegularFieldValidation = ( warnings: string[], name: string, field: RegularField | ChoiceFieldInstance, - resolveRef: (ref: Identifier) => Identifier, + resolveRef: (ref: TypeIdentifier) => TypeIdentifier, canonicalUrlExpr?: { url: string; expr: string }, ) => { if (field.excluded) { diff --git a/src/api/writer-generator/typescript/profile.ts b/src/api/writer-generator/typescript/profile.ts index 9cbb5e3da..e9f420c09 100644 --- a/src/api/writer-generator/typescript/profile.ts +++ b/src/api/writer-generator/typescript/profile.ts @@ -1,7 +1,6 @@ import { pascalCase, uppercaseFirstLetter } from "@root/api/writer-generator/utils"; import { type CanonicalUrl, - type Identifier, isChoiceDeclarationField, isChoiceInstanceField, isNestedIdentifier, @@ -12,6 +11,7 @@ import { type ProfileTypeSchema, packageMeta, packageMetaToFhir, + type TypeIdentifier, } from "@root/typeschema/types"; import type { TypeSchemaIndex } from "@root/typeschema/utils"; import { @@ -53,9 +53,9 @@ import type { TypeScript } from "./writer"; type ProfileFactoryInfo = { autoFields: { name: string; value: string }[]; /** Array fields with required slices — optional param with auto-merge of required stubs */ - sliceAutoFields: { name: string; tsType: string; typeId: Identifier; sliceNames: string[] }[]; - params: { name: string; tsType: string; typeId: Identifier }[]; - accessors: { name: string; tsType: string; typeId: Identifier }[]; + sliceAutoFields: { name: string; tsType: string; typeId: TypeIdentifier; sliceNames: string[] }[]; + params: { name: string; tsType: string; typeId: TypeIdentifier }[]; + accessors: { name: string; tsType: string; typeId: TypeIdentifier }[]; }; const collectChoiceAccessors = ( @@ -248,7 +248,7 @@ const generateProfileHelpersImport = ( export const generateProfileImports = (w: TypeScript, tsIndex: TypeSchemaIndex, flatProfile: ProfileTypeSchema) => { const usedTypes = new Map(); - const getModulePath = (typeId: Identifier): string => { + const getModulePath = (typeId: TypeIdentifier): string => { if (isNestedIdentifier(typeId)) { const path = tsNameFromCanonical(typeId.url, true); if (path) return `../../${tsPackageDir(typeId.package)}/${pascalCase(path)}`; @@ -256,7 +256,7 @@ export const generateProfileImports = (w: TypeScript, tsIndex: TypeSchemaIndex, return `../../${tsModulePath(typeId)}`; }; - const addType = (typeId: Identifier) => { + const addType = (typeId: TypeIdentifier) => { if (typeId.kind === "primitive-type") return; const tsName = tsResourceName(typeId); if (!usedTypes.has(tsName)) { diff --git a/src/api/writer-generator/typescript/utils.ts b/src/api/writer-generator/typescript/utils.ts index e949c399e..256de3ece 100644 --- a/src/api/writer-generator/typescript/utils.ts +++ b/src/api/writer-generator/typescript/utils.ts @@ -1,10 +1,10 @@ import { type ChoiceFieldInstance, type EnumDefinition, - type Identifier, isNestedIdentifier, isPrimitiveIdentifier, type RegularField, + type TypeIdentifier, } from "@root/typeschema/types"; import { tsResourceName } from "./name"; @@ -62,7 +62,7 @@ export const resolveFieldTsType = ( schemaName: string, tsName: string, field: RegularField | ChoiceFieldInstance, - resolveRef?: (ref: Identifier) => Identifier, + resolveRef?: (ref: TypeIdentifier) => TypeIdentifier, genericFieldMap?: Record, ): string => { if (genericFieldMap?.[tsName]) return genericFieldMap[tsName]; @@ -89,10 +89,10 @@ export const resolveFieldTsType = ( export const fieldTsType = ( field: RegularField | ChoiceFieldInstance, - resolveRef?: (ref: Identifier) => Identifier, + resolveRef?: (ref: TypeIdentifier) => TypeIdentifier, ): string => resolveFieldTsType("", "", field, resolveRef) + (field.array ? "[]" : ""); -export const tsTypeFromIdentifier = (id: Identifier): string => { +export const tsTypeFromIdentifier = (id: TypeIdentifier): string => { if (isNestedIdentifier(id)) return tsResourceName(id); if (isPrimitiveIdentifier(id)) return resolvePrimitiveType(id.name); // Fallback: check if id.name is a known primitive type even if kind isn't set diff --git a/src/typeschema/core/field-builder.ts b/src/typeschema/core/field-builder.ts index b554de62c..08e94f2aa 100644 --- a/src/typeschema/core/field-builder.ts +++ b/src/typeschema/core/field-builder.ts @@ -15,10 +15,10 @@ import type { Field, FieldSlice, FieldSlicing, - Identifier, Name, RegularField, RichFHIRSchema, + TypeIdentifier, ValueConstraint, } from "../types"; import { BINDABLE_TYPES, buildEnum } from "./binding"; @@ -64,7 +64,7 @@ const buildReferences = ( register: Register, fhirSchema: RichFHIRSchema, element: FHIRSchemaElement, -): Identifier[] | undefined => { +): TypeIdentifier[] | undefined => { if (!element.refers) return undefined; return element.refers.map((ref) => { const curl = register.ensureSpecializationCanonicalUrl(ref as Name); @@ -261,7 +261,7 @@ export function buildFieldType( path: string[], element: FHIRSchemaElement, logger?: CodegenLog, -): Identifier | undefined { +): TypeIdentifier | undefined { if (element.elementReference) { const refPath = element.elementReference .slice(1) // drop canonicalUrl @@ -352,7 +352,7 @@ export const mkField = ( } return { - type: fieldType as Identifier, + type: fieldType as TypeIdentifier, required: isRequired(register, fhirSchema, path), excluded: isExcluded(register, fhirSchema, path), diff --git a/src/typeschema/core/identifier.ts b/src/typeschema/core/identifier.ts index 0ad00ccc5..615c5b4aa 100644 --- a/src/typeschema/core/identifier.ts +++ b/src/typeschema/core/identifier.ts @@ -8,11 +8,11 @@ import type { FHIRSchemaElement } from "@atomic-ehr/fhirschema"; import type { BindingIdentifier, CanonicalUrl, - Identifier, Name, PackageMeta, RichFHIRSchema, RichValueSet, + TypeIdentifier, ValueSetIdentifier, } from "@typeschema/types"; import type { Register } from "../register"; @@ -27,7 +27,7 @@ function getVersionFromUrl(url: CanonicalUrl): string | undefined { return version; } -function determineKind(fhirSchema: RichFHIRSchema): Identifier["kind"] { +function determineKind(fhirSchema: RichFHIRSchema): TypeIdentifier["kind"] { if (fhirSchema.derivation === "constraint") return "profile"; if (fhirSchema.kind === "primitive-type") return "primitive-type"; if (fhirSchema.kind === "complex-type") return "complex-type"; @@ -36,7 +36,7 @@ function determineKind(fhirSchema: RichFHIRSchema): Identifier["kind"] { return "resource"; } -export function mkIdentifier(fhirSchema: RichFHIRSchema): Identifier { +export function mkIdentifier(fhirSchema: RichFHIRSchema): TypeIdentifier { return { kind: determineKind(fhirSchema), package: fhirSchema.package_meta.name, diff --git a/src/typeschema/core/nested-types.ts b/src/typeschema/core/nested-types.ts index 957c4dee8..e6bac1b64 100644 --- a/src/typeschema/core/nested-types.ts +++ b/src/typeschema/core/nested-types.ts @@ -7,7 +7,15 @@ import type { FHIRSchema, FHIRSchemaElement } from "@atomic-ehr/fhirschema"; import { mergeFsElementProps, type Register, resolveFsElementGenealogy } from "@root/typeschema/register"; import type { CodegenLog } from "@root/utils/log"; -import type { CanonicalUrl, Field, Identifier, Name, NestedIdentifier, NestedType, RichFHIRSchema } from "../types"; +import type { + CanonicalUrl, + Field, + Name, + NestedIdentifier, + NestedTypeSchema, + RichFHIRSchema, + TypeIdentifier, +} from "../types"; import { mkField, mkNestedField } from "./field-builder"; /** @@ -149,7 +157,7 @@ export function mkNestedTypes( register: Register, fhirSchema: RichFHIRSchema, logger?: CodegenLog, -): NestedType[] | undefined { +): NestedTypeSchema[] | undefined { if (!fhirSchema.elements) return undefined; const nested = collectNestedElements(fhirSchema, [], fhirSchema.elements).filter(([path, element]) => { @@ -164,7 +172,7 @@ export function mkNestedTypes( return true; }); - const nestedTypes = [] as NestedType[]; + const nestedTypes = [] as NestedTypeSchema[]; for (const [path, element] of nested) { const identifier = mkNestedIdentifier(register, fhirSchema, path); @@ -177,7 +185,7 @@ export function mkNestedTypes( const baseUrl = register.ensureSpecializationCanonicalUrl(baseName); const baseFs = register.resolveFs(fhirSchema.package_meta, baseUrl); if (!baseFs) throw new Error(`Could not resolve base type ${baseName}`); - const base: Identifier = { + const base: TypeIdentifier = { kind: "complex-type", package: baseFs.package_meta.name, version: baseFs.package_meta.version, @@ -187,7 +195,7 @@ export function mkNestedTypes( const fields = transformNestedElements(register, fhirSchema, path, element.elements ?? {}, logger); - const nestedType: NestedType = { + const nestedType: NestedTypeSchema = { identifier, base, fields, @@ -200,8 +208,8 @@ export function mkNestedTypes( return nestedTypes.length === 0 ? undefined : nestedTypes; } -export function extractNestedDependencies(nestedTypes: NestedType[]): Identifier[] { - const deps: Identifier[] = []; +export function extractNestedDependencies(nestedTypes: NestedTypeSchema[]): TypeIdentifier[] { + const deps: TypeIdentifier[] = []; for (const nested of nestedTypes) { if (nested.base) { diff --git a/src/typeschema/core/profile-extensions.ts b/src/typeschema/core/profile-extensions.ts index abdd83cb0..42c51837d 100644 --- a/src/typeschema/core/profile-extensions.ts +++ b/src/typeschema/core/profile-extensions.ts @@ -12,10 +12,10 @@ import { type CanonicalUrl, concatIdentifiers, type ExtensionSubField, - type Identifier, type ProfileExtension, type ProfileIdentifier, type RichFHIRSchema, + type TypeIdentifier, } from "@typeschema/types"; import { buildFieldType } from "./field-builder"; @@ -26,11 +26,11 @@ const extractExtensionValueFieldTypes = ( fhirSchema: RichFHIRSchema, extensionUrl: CanonicalUrl, logger?: CodegenLog, -): Identifier[] | undefined => { +): TypeIdentifier[] | undefined => { const extensionSchema = register.resolveFs(fhirSchema.package_meta, extensionUrl); if (!extensionSchema?.elements) return undefined; - const valueFieldTypes: Identifier[] = []; + const valueFieldTypes: TypeIdentifier[] = []; for (const [key, element] of Object.entries(extensionSchema.elements)) { if (element.choiceOf !== "value" && !key.startsWith("value")) continue; const fieldType = buildFieldType(register, extensionSchema, [key], element, logger); @@ -54,7 +54,7 @@ const extractLegacySubExtensions = ( const sliceName = key.split(":")[1]; if (!sliceName) continue; - let valueType: Identifier | undefined; + let valueType: TypeIdentifier | undefined; for (const [elemKey, elemValue] of Object.entries(element.elements ?? {})) { if (elemValue.choiceOf !== "value" && !elemKey.startsWith("value")) continue; valueType = buildFieldType(register, extensionSchema, [key, elemKey], elemValue, logger); @@ -87,7 +87,7 @@ const extractSlicingSubExtensions = ( const schema = slice.schema; if (!schema) continue; - let valueType: Identifier | undefined; + let valueType: TypeIdentifier | undefined; for (const [elemKey, elemValue] of Object.entries(schema.elements ?? {})) { const elem = elemValue as any; if (elem.choiceOf !== "value" && !elemKey.startsWith("value")) continue; diff --git a/src/typeschema/core/transformer.ts b/src/typeschema/core/transformer.ts index d0c30d8ac..e52c121d8 100644 --- a/src/typeschema/core/transformer.ts +++ b/src/typeschema/core/transformer.ts @@ -12,13 +12,13 @@ import { concatIdentifiers, extractExtensionDeps, type Field, - type Identifier, isNestedIdentifier, isProfileIdentifier, - type NestedType, + type NestedTypeSchema, packageMetaToFhir, type RichFHIRSchema, type RichValueSet, + type TypeIdentifier, type TypeSchema, type ValueSetTypeSchema, } from "@typeschema/types"; @@ -60,8 +60,8 @@ export function mkFields( return fields; } -function extractFieldDependencies(fields: Record): Identifier[] { - const deps: Identifier[] = []; +function extractFieldDependencies(fields: Record): TypeIdentifier[] { + const deps: TypeIdentifier[] = []; for (const field of Object.values(fields)) { if ("type" in field && field.type) { @@ -93,11 +93,11 @@ export async function transformValueSet( } export function extractDependencies( - identifier: Identifier, - base: Identifier | undefined, + identifier: TypeIdentifier, + base: TypeIdentifier | undefined, fields: Record | undefined, - nestedTypes: NestedType[] | undefined, -): Identifier[] | undefined { + nestedTypes: NestedTypeSchema[] | undefined, +): TypeIdentifier[] | undefined { const deps = []; if (base) deps.push(base); if (fields) deps.push(...extractFieldDependencies(fields)); @@ -118,7 +118,7 @@ export function extractDependencies( export function transformFhirSchema(register: Register, fhirSchema: RichFHIRSchema, logger?: CodegenLog): TypeSchema[] { const identifier = mkIdentifier(fhirSchema); - let base: Identifier | undefined; + let base: TypeIdentifier | undefined; if (fhirSchema.base) { const baseFs = register.resolveFs( fhirSchema.package_meta, diff --git a/src/typeschema/index.ts b/src/typeschema/index.ts index 5a26bbea8..fa02d170f 100644 --- a/src/typeschema/index.ts +++ b/src/typeschema/index.ts @@ -20,7 +20,7 @@ import { hashSchema, packageMetaToFhir, type TypeSchema } from "./types"; // Re-export core dependencies export { shouldSkipCanonical, skipList } from "./skip-hack"; -export type { Identifier, TypeSchema } from "./types"; +export type { TypeIdentifier as Identifier, TypeSchema } from "./types"; export interface GenerateTypeSchemasResult { schemas: TypeSchema[]; diff --git a/src/typeschema/ir/logic-promotion.ts b/src/typeschema/ir/logic-promotion.ts index 91da02e08..f0a7184e3 100644 --- a/src/typeschema/ir/logic-promotion.ts +++ b/src/typeschema/ir/logic-promotion.ts @@ -7,8 +7,9 @@ import { isProfileTypeSchema, isSpecializationTypeSchema, isValueSetTypeSchema, - type NestedType, + type NestedTypeSchema, type PkgName, + type TypeIdentifier, } from "@root/typeschema/types"; import type { TypeSchemaIndex } from "@root/typeschema/utils"; import type { LogicalPromotionConf } from "./types"; @@ -18,8 +19,8 @@ export const promoteLogical = (tsIndex: TypeSchemaIndex, promotes: LogicalPromot Object.entries(promotes).map(([pkg, urls]) => [pkg, new Set(urls)]), ); - const identifierToString = (i: Identifier): string => `${i.package}-${i.version}-${i.kind}-${i.url}`; - const renames: Record = Object.fromEntries( + const identifierToString = (i: TypeIdentifier): string => `${i.package}-${i.version}-${i.kind}-${i.url}`; + const renames: Record = Object.fromEntries( tsIndex.schemas .map((schema) => { const promo = promoteSets[schema.identifier.package]?.has(schema.identifier.url); @@ -30,13 +31,13 @@ export const promoteLogical = (tsIndex: TypeSchemaIndex, promotes: LogicalPromot }) .filter((e) => e !== undefined), ); - const replace = (i: Identifier): Identifier => renames[identifierToString(i)] || i; + const replace = (i: TypeIdentifier): TypeIdentifier => renames[identifierToString(i)] || i; const replaceInFields = (fields: Record | undefined) => { if (!fields) return undefined; return Object.fromEntries( Object.entries(fields).map(([k, f]) => { if (isChoiceDeclarationField(f)) return [k, f]; - return [k, { ...f, type: f.type ? replace(f.type) : undefined }]; + return [k, { ...f, type: f.type ? replace(f.type as Identifier) : undefined }]; }), ); }; @@ -49,7 +50,7 @@ export const promoteLogical = (tsIndex: TypeSchemaIndex, promotes: LogicalPromot cloned.dependencies = cloned.dependencies?.map(replace); if (isSpecializationTypeSchema(cloned) || isProfileTypeSchema(cloned)) { cloned.fields = replaceInFields(cloned.fields); - cloned.nested = cloned.nested?.map((n: NestedType) => { + cloned.nested = cloned.nested?.map((n: NestedTypeSchema) => { return { ...n, base: replace(n.base), diff --git a/src/typeschema/ir/tree-shake.ts b/src/typeschema/ir/tree-shake.ts index d329a2a08..540a4e8ac 100644 --- a/src/typeschema/ir/tree-shake.ts +++ b/src/typeschema/ir/tree-shake.ts @@ -15,7 +15,7 @@ import { isProfileTypeSchema, isSpecializationTypeSchema, isValueSetTypeSchema, - type NestedType, + type NestedTypeSchema, type PkgName, type ProfileTypeSchema, type SpecializationTypeSchema, @@ -207,7 +207,7 @@ export const treeShakeTypeSchema = (schema: TypeSchema, rule: TreeShakeRule, _lo if (schema.nested) { const usedTypes = new Set(); - const collectUsedNestedTypes = (s: SpecializationTypeSchema | NestedType) => { + const collectUsedNestedTypes = (s: SpecializationTypeSchema | NestedTypeSchema) => { Object.values(s.fields ?? {}) .filter(isNotChoiceDeclarationField) .filter((f) => isNestedIdentifier(f.type)) diff --git a/src/typeschema/types.ts b/src/typeschema/types.ts index ad26b0167..964509d3e 100644 --- a/src/typeschema/types.ts +++ b/src/typeschema/types.ts @@ -106,42 +106,43 @@ export type Identifier = | PrimitiveIdentifier | ComplexTypeIdentifier | ResourceIdentifier - | NestedIdentifier | BindingIdentifier | ValueSetIdentifier | ProfileIdentifier | LogicalIdentifier; -export const isResourceIdentifier = (id: Identifier | undefined): id is ResourceIdentifier => { +export type TypeIdentifier = Identifier | NestedIdentifier; + +export const isResourceIdentifier = (id: TypeIdentifier | undefined): id is ResourceIdentifier => { return id?.kind === "resource"; }; -export const isLogicalIdentifier = (id: Identifier | undefined): id is LogicalIdentifier => { +export const isLogicalIdentifier = (id: TypeIdentifier | undefined): id is LogicalIdentifier => { return id?.kind === "logical"; }; -export const isComplexTypeIdentifier = (id: Identifier | undefined): id is ComplexTypeIdentifier => { +export const isComplexTypeIdentifier = (id: TypeIdentifier | undefined): id is ComplexTypeIdentifier => { return id?.kind === "complex-type"; }; -export const isPrimitiveIdentifier = (id: Identifier | undefined): id is PrimitiveIdentifier => { +export const isPrimitiveIdentifier = (id: TypeIdentifier | undefined): id is PrimitiveIdentifier => { return id?.kind === "primitive-type"; }; -export const isNestedIdentifier = (id: Identifier | undefined): id is NestedIdentifier => { +export const isNestedIdentifier = (id: TypeIdentifier | undefined): id is NestedIdentifier => { return id?.kind === "nested"; }; -export const isProfileIdentifier = (id: Identifier | undefined): id is ProfileIdentifier => { +export const isProfileIdentifier = (id: TypeIdentifier | undefined): id is ProfileIdentifier => { return id?.kind === "profile"; }; -export const concatIdentifiers = (...sources: (Identifier[] | undefined)[]): Identifier[] | undefined => { +export const concatIdentifiers = (...sources: (TypeIdentifier[] | undefined)[]): TypeIdentifier[] | undefined => { const entries = sources - .filter((s): s is Identifier[] => s !== undefined) - .flatMap((s) => s.map((id): [string, Identifier] => [id.url, id])); + .filter((s): s is TypeIdentifier[] => s !== undefined) + .flatMap((s) => s.map((id): [string, TypeIdentifier] => [id.url, id])); if (entries.length === 0) return undefined; - const deduped = Object.values(Object.fromEntries(entries) as Record); + const deduped = Object.values(Object.fromEntries(entries) as Record); return deduped.sort((a, b) => a.url.localeCompare(b.url)); }; @@ -191,24 +192,24 @@ export function isValueSetTypeSchema(schema: TypeSchema | undefined): schema is interface PrimitiveTypeSchema { identifier: PrimitiveIdentifier; description?: string; - base: Identifier; - dependencies?: Identifier[]; + base: TypeIdentifier; + dependencies?: TypeIdentifier[]; } -export interface NestedType { +export interface NestedTypeSchema { identifier: NestedIdentifier; - base: Identifier; + base: TypeIdentifier; fields: Record; } export interface ProfileTypeSchema { identifier: ProfileIdentifier; - base: Identifier; + base: TypeIdentifier; description?: string; fields?: Record; extensions?: ProfileExtension[]; - dependencies?: Identifier[]; - nested?: NestedType[]; + dependencies?: TypeIdentifier[]; + nested?: NestedTypeSchema[]; } export type DiscriminatorType = "value" | "exists" | "pattern" | "type" | "profile"; @@ -223,7 +224,7 @@ export interface FieldSlicing { export type ConstrainedChoiceInfo = { choiceBase: string; variant: string; - variantType: Identifier; + variantType: TypeIdentifier; allChoiceNames: string[]; }; @@ -239,7 +240,7 @@ export interface FieldSlice { export interface ExtensionSubField { name: string; url: string; - valueFieldType?: Identifier; + valueFieldType?: TypeIdentifier; min?: number; max?: string; } @@ -252,12 +253,12 @@ export interface ProfileExtension { min?: number; max?: string; mustSupport?: boolean; - valueFieldTypes?: Identifier[]; + valueFieldTypes?: TypeIdentifier[]; subExtensions?: ExtensionSubField[]; isComplex?: boolean; } -export const extractExtensionDeps = (ext: ProfileExtension): Identifier[] => [ +export const extractExtensionDeps = (ext: ProfileExtension): TypeIdentifier[] => [ ...(ext.valueFieldTypes ?? []), ...(ext.profile ? [ext.profile] : []), ...(ext.subExtensions?.flatMap((sub) => (sub.valueFieldType ? [sub.valueFieldType] : [])) ?? []), @@ -265,12 +266,12 @@ export const extractExtensionDeps = (ext: ProfileExtension): Identifier[] => [ export interface SpecializationTypeSchema { // TODO: restrict to ResourceIdentifier | ComplexTypeIdentifier | LogicalIdentifier - identifier: Identifier; - base?: Identifier; + identifier: TypeIdentifier; + base?: TypeIdentifier; description?: string; fields?: { [k: string]: Field }; - nested?: NestedType[]; - dependencies?: Identifier[]; + nested?: NestedTypeSchema[]; + dependencies?: TypeIdentifier[]; /** Transitive children grouped by kind (e.g. Resource → { resources: [DomainResource, Patient, …] }) */ typeFamily?: { resources?: ResourceIdentifier[]; @@ -279,8 +280,8 @@ export interface SpecializationTypeSchema { } export interface RegularField { - type: Identifier; - reference?: Identifier[]; + type: TypeIdentifier; + reference?: TypeIdentifier[]; required?: boolean; excluded?: boolean; array?: boolean; @@ -305,11 +306,11 @@ export interface ChoiceFieldDeclaration { export interface ChoiceFieldInstance { choiceOf: string; - type: Identifier; + type: TypeIdentifier; required?: boolean; excluded?: boolean; array?: boolean; - reference?: Identifier[]; + reference?: TypeIdentifier[]; binding?: BindingIdentifier; enum?: EnumDefinition; min?: number; @@ -343,7 +344,7 @@ export interface BindingTypeSchema { strength?: string; enum?: EnumDefinition; valueset?: ValueSetIdentifier; - dependencies?: Identifier[]; + dependencies?: TypeIdentifier[]; } export type Field = RegularField | ChoiceFieldDeclaration | ChoiceFieldInstance; diff --git a/src/typeschema/utils.ts b/src/typeschema/utils.ts index 124f26a65..6d7803d3c 100644 --- a/src/typeschema/utils.ts +++ b/src/typeschema/utils.ts @@ -9,7 +9,6 @@ import { type ChoiceFieldInstance, type ConstrainedChoiceInfo, type Field, - type Identifier, isChoiceDeclarationField, isChoiceInstanceField, isComplexTypeIdentifier, @@ -23,6 +22,7 @@ import { type ProfileExtension, type ProfileTypeSchema, type SpecializationTypeSchema, + type TypeIdentifier, type TypeSchema, } from "./types"; @@ -109,7 +109,7 @@ export const sortAsDeclarationSequence = (schemas: SpecializationTypeSchema[]): /** Populate `typeFamily` on specialization schemas with transitive children grouped by kind. */ const populateTypeFamily = (schemas: TypeSchema[]): void => { - const directChildrenByParent: Record = {}; + const directChildrenByParent: Record = {}; for (const schema of schemas) { if (!isSpecializationTypeSchema(schema) || !schema.base) continue; const parentUrl = schema.base.url; @@ -117,11 +117,11 @@ const populateTypeFamily = (schemas: TypeSchema[]): void => { directChildrenByParent[parentUrl].push(schema.identifier); } - const transitiveCache: Record = {}; - const getTransitiveChildren = (parentUrl: string): Identifier[] => { + const transitiveCache: Record = {}; + const getTransitiveChildren = (parentUrl: string): TypeIdentifier[] => { if (transitiveCache[parentUrl]) return transitiveCache[parentUrl]; const direct = directChildrenByParent[parentUrl] ?? []; - const result: Identifier[] = [...direct]; + const result: TypeIdentifier[] = [...direct]; for (const child of direct) { result.push(...getTransitiveChildren(child.url)); } @@ -154,16 +154,16 @@ export type TypeSchemaIndex = { collectResources: () => SpecializationTypeSchema[]; collectLogicalModels: () => SpecializationTypeSchema[]; collectProfiles: () => ProfileTypeSchema[]; - resolve: (id: Identifier) => TypeSchema | undefined; + resolve: (id: TypeIdentifier) => TypeSchema | undefined; resolveByUrl: (pkgName: PkgName, url: CanonicalUrl) => TypeSchema | undefined; tryHierarchy: (schema: TypeSchema) => TypeSchema[] | undefined; hierarchy: (schema: TypeSchema) => TypeSchema[]; findLastSpecialization: (schema: TypeSchema) => TypeSchema; - findLastSpecializationByIdentifier: (id: Identifier) => Identifier; + findLastSpecializationByIdentifier: (id: TypeIdentifier) => TypeIdentifier; flatProfile: (schema: ProfileTypeSchema) => ProfileTypeSchema; constrainedChoice: ( pkgName: PkgName, - baseTypeId: Identifier, + baseTypeId: TypeIdentifier, sliceElements: string[], ) => ConstrainedChoiceInfo | undefined; isWithMetaField: (profile: ProfileTypeSchema) => boolean; @@ -173,7 +173,7 @@ export type TypeSchemaIndex = { replaceSchemas: (schemas: TypeSchema[]) => TypeSchemaIndex; }; -type EntityTree = Record>>; +type EntityTree = Record>>; export const mkTypeSchemaIndex = ( schemas: TypeSchema[], @@ -218,7 +218,7 @@ export const mkTypeSchemaIndex = ( } populateTypeFamily(schemas); - const resolve = (id: Identifier) => { + const resolve = (id: TypeIdentifier) => { if (id.kind === "nested") return nestedIndex[id.url]?.[id.package]; return index[id.url]?.[id.package]; }; @@ -280,7 +280,7 @@ export const mkTypeSchemaIndex = ( return nonConstraintSchema; }; - const findLastSpecializationByIdentifier = (id: Identifier): Identifier => { + const findLastSpecializationByIdentifier = (id: TypeIdentifier): TypeIdentifier => { const schema = resolve(id); if (!schema) return id; return findLastSpecialization(schema).identifier; @@ -388,7 +388,7 @@ export const mkTypeSchemaIndex = ( const constrainedChoice = ( pkgName: PkgName, - baseTypeId: Identifier, + baseTypeId: TypeIdentifier, sliceElements: string[], ): ConstrainedChoiceInfo | undefined => { const baseSchema = resolveByUrl(pkgName, baseTypeId.url as CanonicalUrl); diff --git a/test/unit/api/writer-generator/typescript/name.test.ts b/test/unit/api/writer-generator/typescript/name.test.ts index 42b4e81dd..97462ddcd 100644 --- a/test/unit/api/writer-generator/typescript/name.test.ts +++ b/test/unit/api/writer-generator/typescript/name.test.ts @@ -1,14 +1,14 @@ import { describe, expect, test } from "bun:test"; import { tsResourceName } from "@root/api/writer-generator/typescript/name"; -import type { CanonicalUrl, Identifier, Name } from "@root/typeschema/types"; +import type { CanonicalUrl, Name, TypeIdentifier } from "@root/typeschema/types"; const makeIdentifier = (props: { - kind: Identifier["kind"]; + kind: TypeIdentifier["kind"]; name: string; url?: string; package?: string; version?: string; -}): Identifier => { +}): TypeIdentifier => { return { kind: props.kind, package: props.package ?? "test-package", diff --git a/test/unit/typeschema/ir/tree-shake.test.ts b/test/unit/typeschema/ir/tree-shake.test.ts index dffafabb2..77bd2881c 100644 --- a/test/unit/typeschema/ir/tree-shake.test.ts +++ b/test/unit/typeschema/ir/tree-shake.test.ts @@ -9,11 +9,11 @@ import { import { registerFromPackageMetas } from "@root/typeschema/register"; import type { CanonicalUrl, - Identifier, Name, ProfileIdentifier, ProfileTypeSchema, SpecializationTypeSchema, + TypeIdentifier, } from "@root/typeschema/types"; import { mkIndex, mkR4Register, mkTestLogger, r4Package, r5Package, resolveTs } from "@typeschema-test/utils"; @@ -275,7 +275,7 @@ describe("treeShake specific TypeSchema", async () => { }); describe("ignoreExtensions", () => { - const mkDep = (url: string): Identifier => ({ + const mkDep = (url: string): TypeIdentifier => ({ kind: "complex-type", name: url.split("/").pop()! as Name, url: url as CanonicalUrl, diff --git a/test/unit/typeschema/utils.test.ts b/test/unit/typeschema/utils.test.ts index bfbb726fb..ba1521399 100644 --- a/test/unit/typeschema/utils.test.ts +++ b/test/unit/typeschema/utils.test.ts @@ -1,15 +1,15 @@ import { describe, expect, it } from "bun:test"; import type { CanonicalUrl, - Identifier, Name, ProfileTypeSchema, RegularField, SpecializationTypeSchema, + TypeIdentifier, } from "@typeschema/types"; import { mkTypeSchemaIndex } from "@typeschema/utils"; -const stringType: Identifier = { +const stringType: TypeIdentifier = { name: "string" as Name, package: "test", kind: "primitive-type", @@ -17,7 +17,7 @@ const stringType: Identifier = { url: "http://example.org/StructureDefinition/string" as CanonicalUrl, }; -const numberType: Identifier = { +const numberType: TypeIdentifier = { name: "number" as Name, package: "test", kind: "primitive-type", @@ -25,7 +25,7 @@ const numberType: Identifier = { url: "http://example.org/StructureDefinition/number" as CanonicalUrl, }; -const booleanType: Identifier = { +const booleanType: TypeIdentifier = { name: "boolean" as Name, package: "test", kind: "primitive-type",