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 92bb935
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 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
3 changes: 2 additions & 1 deletion packages/versioning/test/versioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ describe("versioning: logic", () => {
[
[v2, "v2"],
[v3, "v3"],
[v3, "v4"],
[v4, "v4"],
],
source
);
Expand Down Expand Up @@ -1960,6 +1960,7 @@ describe("versioning: logic", () => {
function assertModelProjectsTo(types: [Model, string][], target: Model) {
types.forEach(([m, version]) => {
const projection = project(m, version, "from");
const projection2 = project(m, version, "to");

Check warning on line 1963 in packages/versioning/test/versioning.test.ts

View workflow job for this annotation

GitHub Actions / Lint

'projection2' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 1963 in packages/versioning/test/versioning.test.ts

View workflow job for this annotation

GitHub Actions / Lint

'projection2' is assigned a value but never used. Allowed unused vars must match /^_/u
strictEqual(projection.properties.size, target.properties.size);
for (const prop of projection.properties.values()) {
ok(target.properties.has(prop.name));
Expand Down

0 comments on commit 92bb935

Please sign in to comment.