Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/@aws-cdk/service-spec-importers/src/db-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import {
UpdatedEvent,
UpdatedEventTypeDefinition,
UpdatedEventProperty,
ResourceField,
} from '@aws-cdk/service-spec-types';
import { Reference } from '@cdklabs/tskb';
import {
diffByKey,
collapseUndefined,
Expand Down Expand Up @@ -204,8 +206,8 @@ export class DbDiff {
description: diffScalar(a, b, 'description'),
source: diffScalar(a, b, 'source'),
detailType: diffScalar(a, b, 'detailType'),
resourcesField: diffField(a, b, 'resourcesField', jsonEq),
rootProperty: diffField(a, b, 'rootProperty', jsonEq),
resourcesField: diffField(a, b, 'resourcesField', this.eqEventResourcesField.bind(this)),
rootProperty: diffField(a, b, 'rootProperty', this.eqEventRootProperty.bind(this)),
typeDefinitionDiff: this.diffEventTypeDefinitions(a, b),
} satisfies AllFieldsGiven<UpdatedEvent>);
}
Expand Down Expand Up @@ -254,6 +256,23 @@ export class DbDiff {
return this.stringifyGenericType(a, this.db1) === this.stringifyGenericType(b, this.db2);
}

private eqEventRootProperty(a: Reference<EventTypeDefinition>, b: Reference<EventTypeDefinition>): boolean {
return this.eqEventPropertyType({ type: 'ref', reference: a }, { type: 'ref', reference: b });
}

private eqEventResourcesField(a: ResourceField[], b: ResourceField[]): boolean {
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) {
if (
!this.eqEventPropertyType({ type: 'ref', reference: a[i].type }, { type: 'ref', reference: b[i].type }) ||
a[i].fieldName !== b[i].fieldName
) {
return false;
}
}
return true;
}

/**
* Stringify a generic property type for comparison.
*/
Expand Down
26 changes: 26 additions & 0 deletions packages/@aws-cdk/service-spec-importers/test/db-diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,29 @@ test('metrics diff only on statistic and ignore dedup key for diff', () => {
statistic: { new: 'Maximum', old: 'Average' },
});
});

test('event diff ignores different $ref IDs when event type definitions have same name', () => {
const eventType1 = db1.allocate('eventTypeDefinition', { name: 'WorkSpacesAccess', properties: {} });
const eventType2 = db2.allocate('eventTypeDefinition', { name: 'WorkSpacesAccess', properties: {} });

const event1 = db1.allocate('event', {
name: 'aws.workspaces@WorkSpacesAccess',
description: 'Test event',
source: 'aws.workspaces',
detailType: 'WorkSpaces Access',
rootProperty: ref(eventType1),
resourcesField: [{ type: ref(eventType1), fieldName: 'workspaceId' }],
});

const event2 = db2.allocate('event', {
name: 'aws.workspaces@WorkSpacesAccess',
description: 'Test event',
source: 'aws.workspaces',
detailType: 'WorkSpaces Access',
rootProperty: ref(eventType2),
resourcesField: [{ type: ref(eventType2), fieldName: 'workspaceId' }],
});

const ed = diff.diffEvent(event1, event2);
expect(ed).toBeUndefined();
});