Skip to content

Commit

Permalink
Create timeline version of other fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed May 22, 2024
1 parent 7c1374d commit e4fbc95
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions packages/versioning/src/versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,28 @@ function getParentAddedVersion(
return undefined;
}

function getParentAddedVersionInTimeline(
program: Program,
type: Type,
timeline: VersioningTimeline
): Version | undefined {
let parentMap: Map<TimelineMoment, Availability> | undefined = undefined;
if (type.kind === "ModelProperty" && type.model !== undefined) {
parentMap = getAvailabilityMapInTimeline(program, type.model, timeline);
} else if (type.kind === "Operation" && type.interface !== undefined) {
parentMap = getAvailabilityMapInTimeline(program, type.interface, timeline);
}
if (parentMap === undefined) return undefined;
for (const [moment, availability] of parentMap.entries()) {
if (availability === Availability.Added) {
// FIXME: is this actually correct?
// We essentially want to return the first (earliest) time this is added.
return moment.versions().next().value;
}
}
return undefined;
}

export function getAvailabilityMap(
program: Program,
type: Type
Expand All @@ -827,6 +849,8 @@ export function getAvailabilityMap(
)
return undefined;

// implicitly, all versioned things are assumed to have been added at
// v1 if not specified, or inherited from their parent.
if (!added.length && !parentAdded) {
// no version information on the item or its parent implicitly means it has always been available
added.push(allVersions[0]);
Expand Down Expand Up @@ -865,7 +889,8 @@ export function getAvailabilityMapInTimeline(
): Map<TimelineMoment, Availability> | undefined {
const avail = new Map<TimelineMoment, Availability>();

const added = getAddedOnVersions(program, type) ?? [];
const parentAdded = getParentAddedVersionInTimeline(program, type, timeline);
let added = getAddedOnVersions(program, type) ?? [];
const removed = getRemovedOnVersions(program, type) ?? [];
const typeChanged = getTypeChangedFrom(program, type);
const returnTypeChanged = getReturnTypeChangedFrom(program, type);
Expand All @@ -881,9 +906,16 @@ export function getAvailabilityMapInTimeline(
return undefined;

// implicitly, all versioned things are assumed to have been added at
// v1 if not specified
if (!added.length) {
// v1 if not specified, or inherited from their parent.
if (!added.length && !parentAdded) {
// no version information on the item or its parent implicitly means it has always been available
added.push(timeline.first().versions().next().value);
} else if (!added.length && parentAdded) {
// if no version info on type but is on parent, inherit that parent's "added" version
added.push(parentAdded);
} else if (added.length && parentAdded) {
// if "added" info on both the type and parent, combine them
added = [parentAdded, ...added];
}

// something isn't available by default
Expand Down

0 comments on commit e4fbc95

Please sign in to comment.