Skip to content

Commit f13d36c

Browse files
committed
ref: add isSnapshotProfileIdentifier guard; replace inline kind checks
Two inline `id.kind === "profile-snapshot"` checks in resolve/resolveType become `isSnapshotProfileIdentifier(id)`, matching the style of every other identifier guard in types.ts. Biome --write also dropped a pre-existing redundant `!!canonicalUrl` double-negation in profile.ts (already inside an `&&` chain).
1 parent 6b75765 commit f13d36c

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ const generateProfileHelpersImport = (
236236
const canonicalUrl = snapshot.identifier.url;
237237

238238
const imports: string[] = [];
239-
if (snapshot.base.name === "Extension" && !!canonicalUrl && collectSubExtensionSlices(snapshot).length > 0)
239+
if (snapshot.base.name === "Extension" && canonicalUrl && collectSubExtensionSlices(snapshot).length > 0)
240240
imports.push("isRawExtensionInput");
241241
if (canonicalUrl && hasMeta) imports.push("ensureProfile");
242242
if (sliceDefs.length > 0 || factoryInfo.sliceAutoFields.length > 0)

src/typeschema/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ export const isProfileIdentifier = (id: TypeIdentifier | undefined): id is Profi
147147
return id?.kind === "profile";
148148
};
149149

150+
export const isSnapshotProfileIdentifier = (id: TypeIdentifier | undefined): id is SnapshotProfileIdentifier => {
151+
return id?.kind === "profile-snapshot";
152+
};
153+
150154
export const isSpecializationIdentifier = (
151155
id: TypeIdentifier | undefined,
152156
): id is ResourceIdentifier | ComplexTypeIdentifier | LogicalIdentifier => {

src/typeschema/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
isProfileTypeSchema,
2424
isResourceIdentifier,
2525
isResourceTypeSchema,
26+
isSnapshotProfileIdentifier,
2627
isSnapshotProfileTypeSchema,
2728
isSpecializationTypeSchema,
2829
type LogicalTypeSchema,
@@ -371,12 +372,12 @@ export const mkTypeSchemaIndex = (
371372
populateTypeFamily(schemas);
372373

373374
const resolve = (id: Identifier): TypeSchema | undefined => {
374-
if (id.kind === "profile-snapshot") return snapshotIndex[id.url]?.[id.package];
375+
if (isSnapshotProfileIdentifier(id)) return snapshotIndex[id.url]?.[id.package];
375376
return index[id.url]?.[id.package];
376377
};
377378
const resolveType = (id: TypeIdentifier): TypeSchema | NestedTypeSchema | undefined => {
378379
if (isNestedIdentifier(id)) return nestedIndex[id.url]?.[id.package];
379-
if (id.kind === "profile-snapshot") return snapshotIndex[id.url]?.[id.package];
380+
if (isSnapshotProfileIdentifier(id)) return snapshotIndex[id.url]?.[id.package];
380381
return index[id.url]?.[id.package];
381382
};
382383

0 commit comments

Comments
 (0)