Skip to content

Commit d84ecb2

Browse files
committed
Rename naming functions for consistency
- canonicalToName → tsNameFromCanonical - safeCamelCase → tsCamelCase - tsFhirPackageDir → tsPackageDir
1 parent 7af49c1 commit d84ecb2

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ const normalizeTsName = (n: string): string => {
2020
return n.replace(/\[x\]/g, "_x_").replace(/[- :.]/g, "_");
2121
};
2222

23-
export const safeCamelCase = (name: string): string => {
23+
export const tsCamelCase = (name: string): string => {
2424
if (!name) return "";
2525
// Remove [x] suffix and normalize special characters before camelCase
2626
const normalized = name.replace(/\[x\]/g, "").replace(/:/g, "_");
2727
return camelCase(normalized);
2828
};
2929

30-
export const tsFhirPackageDir = (name: string): string => {
30+
export const tsPackageDir = (name: string): string => {
3131
return kebabCase(name);
3232
};
3333

@@ -45,10 +45,10 @@ export const tsModuleFileName = (id: Identifier): string => {
4545
};
4646

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

51-
export const canonicalToName = (canonical: string | undefined, dropFragment = true) => {
51+
export const tsNameFromCanonical = (canonical: string | undefined, dropFragment = true) => {
5252
if (!canonical) return undefined;
5353
const localName = extractNameFromCanonical(canonical as CanonicalUrl, dropFragment);
5454
if (!localName) return undefined;
@@ -97,12 +97,12 @@ export const tsExtensionInputTypeName = (profileName: string, extensionName: str
9797
};
9898

9999
export const tsSliceMethodName = (sliceName: string): string => {
100-
const normalized = safeCamelCase(sliceName);
100+
const normalized = tsCamelCase(sliceName);
101101
return `set${uppercaseFirstLetter(normalized || "Slice")}`;
102102
};
103103

104104
export const tsExtensionMethodName = (name: string): string => {
105-
const normalized = safeCamelCase(name);
105+
const normalized = tsCamelCase(name);
106106
return `set${uppercaseFirstLetter(normalized || "Extension")}`;
107107
};
108108

@@ -112,13 +112,13 @@ export const tsQualifiedExtensionMethodName = (name: string, path?: string): str
112112
?.split(".")
113113
.filter((p) => p && p !== "extension")
114114
.join("_") ?? "";
115-
const pathPart = rawPath ? uppercaseFirstLetter(safeCamelCase(rawPath)) : "";
116-
const normalized = safeCamelCase(name);
115+
const pathPart = rawPath ? uppercaseFirstLetter(tsCamelCase(rawPath)) : "";
116+
const normalized = tsCamelCase(name);
117117
return `setExtension${pathPart}${uppercaseFirstLetter(normalized || "Extension")}`;
118118
};
119119

120120
export const tsQualifiedSliceMethodName = (fieldName: string, sliceName: string): string => {
121-
const fieldPart = uppercaseFirstLetter(safeCamelCase(fieldName) || "Field");
122-
const slicePart = uppercaseFirstLetter(safeCamelCase(sliceName) || "Slice");
121+
const fieldPart = uppercaseFirstLetter(tsCamelCase(fieldName) || "Field");
122+
const slicePart = uppercaseFirstLetter(tsCamelCase(sliceName) || "Slice");
123123
return `setSlice${fieldPart}${slicePart}`;
124124
};

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import {
1717
} from "@root/typeschema/types";
1818
import type { TypeSchemaIndex } from "@root/typeschema/utils";
1919
import {
20-
canonicalToName,
21-
safeCamelCase,
20+
tsCamelCase,
2221
tsExtensionInputTypeName,
2322
tsExtensionMethodName,
24-
tsFhirPackageDir,
2523
tsFieldName,
2624
tsModulePath,
25+
tsNameFromCanonical,
26+
tsPackageDir,
2727
tsProfileClassName,
2828
tsProfileModuleName,
2929
tsQualifiedExtensionMethodName,
@@ -447,8 +447,8 @@ export const generateProfileImports = (
447447

448448
const getModulePath = (typeId: Identifier): string => {
449449
if (isNestedIdentifier(typeId)) {
450-
const path = canonicalToName(typeId.url, true);
451-
if (path) return `../../${tsFhirPackageDir(typeId.package)}/${pascalCase(path)}`;
450+
const path = tsNameFromCanonical(typeId.url, true);
451+
if (path) return `../../${tsPackageDir(typeId.package)}/${pascalCase(path)}`;
452452
}
453453
return `../../${tsModulePath(typeId)}`;
454454
};
@@ -759,7 +759,7 @@ export const generateProfileClass = (
759759

760760
for (const ext of extensions) {
761761
if (!ext.url) continue;
762-
const baseName = uppercaseFirstLetter(safeCamelCase(ext.name));
762+
const baseName = uppercaseFirstLetter(tsCamelCase(ext.name));
763763
const getMethodName = `get${baseName}`;
764764
const getExtensionMethodName = `get${baseName}Extension`;
765765
if (generatedGetMethods.has(getMethodName)) continue;
@@ -843,7 +843,7 @@ export const generateProfileClass = (
843843
// 1. get{SliceName}() - returns simplified (without discriminator fields)
844844
// 2. get{SliceName}Raw() - returns full FHIR type with all fields
845845
for (const sliceDef of sliceDefs) {
846-
const baseName = uppercaseFirstLetter(safeCamelCase(sliceDef.sliceName));
846+
const baseName = uppercaseFirstLetter(tsCamelCase(sliceDef.sliceName));
847847
const getMethodName = `get${baseName}`;
848848
const getRawMethodName = `get${baseName}Raw`;
849849
if (generatedGetMethods.has(getMethodName)) continue;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import {
1818
} from "@root/typeschema/types";
1919
import { groupByPackages, type TypeSchemaIndex } from "@root/typeschema/utils";
2020
import {
21-
canonicalToName,
22-
tsFhirPackageDir,
2321
tsFieldName,
2422
tsModuleFileName,
2523
tsModuleName,
2624
tsModulePath,
25+
tsNameFromCanonical,
26+
tsPackageDir,
2727
tsProfileModuleFileName,
2828
tsResourceName,
2929
} from "./name";
@@ -114,7 +114,7 @@ export class TypeScript extends Writer<TypeScriptOptions> {
114114
});
115115
} else if (isNestedIdentifier(dep)) {
116116
const ndep = { ...dep };
117-
ndep.name = canonicalToName(dep.url) as Name;
117+
ndep.name = tsNameFromCanonical(dep.url) as Name;
118118
imports.push({
119119
tsPackage: `${importPrefix}${tsModulePath(ndep)}`,
120120
name: tsResourceName(dep),
@@ -179,7 +179,7 @@ export class TypeScript extends Writer<TypeScriptOptions> {
179179
}
180180

181181
let extendsClause: string | undefined;
182-
if (schema.base) extendsClause = `extends ${canonicalToName(schema.base.url)}`;
182+
if (schema.base) extendsClause = `extends ${tsNameFromCanonical(schema.base.url)}`;
183183

184184
this.debugComment(schema.identifier);
185185
if (!schema.fields && !extendsClause && !isResourceTypeSchema(schema)) {
@@ -303,8 +303,8 @@ export class TypeScript extends Writer<TypeScriptOptions> {
303303
}
304304

305305
for (const [packageName, packageSchemas] of Object.entries(grouped)) {
306-
const tsPackageDir = tsFhirPackageDir(packageName);
307-
this.cd(tsPackageDir, () => {
306+
const packageDir = tsPackageDir(packageName);
307+
this.cd(packageDir, () => {
308308
for (const schema of packageSchemas) {
309309
this.generateResourceModule(tsIndex, schema);
310310
}

0 commit comments

Comments
 (0)