1- import { ClassMirror , EnumMirror , MethodMirror , Type } from '@cparra/apex-reflection' ;
1+ import { ClassMirror , EnumMirror , InterfaceMirror , MethodMirror , Type } from '@cparra/apex-reflection' ;
22import { pipe } from 'fp-ts/function' ;
33import { areMethodsEqual } from './method-changes-checker' ;
44import { CustomObjectMetadata } from '../reflection/sobject/reflect-custom-object-sources' ;
@@ -54,7 +54,7 @@ export function processChangelog(oldVersion: VersionManifest, newVersion: Versio
5454 newOrModifiedApexMembers : getNewOrModifiedApexMembers ( oldVersion , newVersion ) ,
5555 newCustomObjects : getNewCustomObjects ( oldVersion , newVersion ) ,
5656 removedCustomObjects : getRemovedCustomObjects ( oldVersion , newVersion ) ,
57- customObjectModifications : getModifiedCustomObjectLabels ( oldVersion , newVersion ) ,
57+ customObjectModifications : getCustomObjectModifications ( oldVersion , newVersion ) ,
5858 } ;
5959}
6060
@@ -98,27 +98,48 @@ function getNewOrModifiedApexMembers(oldVersion: VersionManifest, newVersion: Ve
9898 ) ;
9999}
100100
101- function getModifiedCustomObjectLabels (
102- oldVersion : VersionManifest ,
103- newVersion : VersionManifest ,
104- ) : NewOrModifiedMember [ ] {
105- return pipe ( getCustomObjectsInBothVersions ( oldVersion , newVersion ) , ( customObjectsInBoth ) =>
106- customObjectsInBoth
107- . filter ( ( { oldType, newType } ) => oldType . label . toLowerCase ( ) !== newType . label . toLowerCase ( ) )
108- . map ( ( { newType } ) => ( {
109- typeName : newType . name ,
110- modifications : [ { __typename : 'LabelChanged' , name : newType . label } ] ,
111- } ) ) ,
101+ function getCustomObjectModifications ( oldVersion : VersionManifest , newVersion : VersionManifest ) : NewOrModifiedMember [ ] {
102+ return pipe (
103+ getCustomObjectsInBothVersions ( oldVersion , newVersion ) ,
104+ ( customObjectsInBoth ) => [
105+ ...getModifiedCustomObjectLabels ( customObjectsInBoth ) ,
106+ ...getNewOrRemovedCustomFields ( customObjectsInBoth ) ,
107+ ] ,
108+ ( customObjectModifications ) => customObjectModifications . filter ( ( member ) => member . modifications . length > 0 ) ,
112109 ) ;
113110}
114111
112+ function getModifiedCustomObjectLabels ( typesInBoth : TypeInBoth < CustomObjectMetadata > [ ] ) : NewOrModifiedMember [ ] {
113+ return typesInBoth
114+ . filter ( ( { oldType, newType } ) => oldType . label . toLowerCase ( ) !== newType . label . toLowerCase ( ) )
115+ . map ( ( { newType } ) => ( {
116+ typeName : newType . name ,
117+ modifications : [ { __typename : 'LabelChanged' , name : newType . label } ] ,
118+ } ) ) ;
119+ }
120+
121+ function getNewOrRemovedCustomFields ( typesInBoth : TypeInBoth < CustomObjectMetadata > [ ] ) : NewOrModifiedMember [ ] {
122+ return typesInBoth . map ( ( { oldType, newType } ) => {
123+ const oldCustomObject = oldType ;
124+ const newCustomObject = newType ;
125+
126+ return {
127+ typeName : newType . name ,
128+ modifications : [
129+ ...getNewValues ( oldCustomObject , newCustomObject , 'fields' , 'NewField' ) ,
130+ ...getRemovedValues ( oldCustomObject , newCustomObject , 'fields' , 'RemovedField' ) ,
131+ ] ,
132+ } ;
133+ } ) ;
134+ }
135+
115136function getNewOrModifiedEnumValues ( typesInBoth : TypeInBoth < Type > [ ] ) : NewOrModifiedMember [ ] {
116137 return pipe (
117- typesInBoth . filter ( ( typeInBoth ) => typeInBoth . oldType . type_name === 'enum' ) ,
138+ typesInBoth . filter ( ( typeInBoth ) : typeInBoth is TypeInBoth < EnumMirror > => typeInBoth . oldType . type_name === 'enum' ) ,
118139 ( enumsInBoth ) =>
119140 enumsInBoth . map ( ( { oldType, newType } ) => {
120- const oldEnum = oldType as EnumMirror ;
121- const newEnum = newType as EnumMirror ;
141+ const oldEnum = oldType ;
142+ const newEnum = newType ;
122143 return {
123144 typeName : newType . name ,
124145 modifications : [
@@ -133,24 +154,25 @@ function getNewOrModifiedEnumValues(typesInBoth: TypeInBoth<Type>[]): NewOrModif
133154function getNewOrModifiedMethods ( typesInBoth : TypeInBoth < Type > [ ] ) : NewOrModifiedMember [ ] {
134155 return pipe (
135156 typesInBoth . filter (
136- ( typeInBoth ) => typeInBoth . oldType . type_name === 'class' || typeInBoth . oldType . type_name === 'interface' ,
157+ ( typeInBoth ) : typeInBoth is TypeInBoth < ClassMirror | InterfaceMirror > =>
158+ typeInBoth . oldType . type_name === 'class' || typeInBoth . oldType . type_name === 'interface' ,
137159 ) ,
138160 ( typesInBoth ) =>
139161 typesInBoth . map ( ( { oldType, newType } ) => {
140- const oldMethodAware = oldType as MethodAware ;
141- const newMethodAware = newType as MethodAware ;
162+ const oldMethodAware = oldType ;
163+ const newMethodAware = newType ;
142164
143165 return {
144166 typeName : newType . name ,
145167 modifications : [
146- ...getNewValues < MethodMirror , MethodAware , 'methods' > (
168+ ...getNewValues < MethodMirror , InterfaceMirror | ClassMirror , 'methods' > (
147169 oldMethodAware ,
148170 newMethodAware ,
149171 'methods' ,
150172 'NewMethod' ,
151173 areMethodsEqual ,
152174 ) ,
153- ...getRemovedValues < MethodMirror , MethodAware , 'methods' > (
175+ ...getRemovedValues < MethodMirror , InterfaceMirror | ClassMirror , 'methods' > (
154176 oldMethodAware ,
155177 newMethodAware ,
156178 'methods' ,
@@ -228,12 +250,12 @@ function areEqualByName<T extends NameAware>(oldValue: T, newValue: T): boolean
228250 return oldValue . name . toLowerCase ( ) === newValue . name . toLowerCase ( ) ;
229251}
230252
231- function getNewValues < Named extends NameAware , T extends Record < K , Named [ ] > , K extends keyof T > (
253+ function getNewValues < Searchable extends NameAware , T extends Record < K , Searchable [ ] > , K extends keyof T > (
232254 oldPlaceToSearch : T ,
233255 newPlaceToSearch : T ,
234256 keyToSearch : K ,
235257 typeName : ModificationTypes ,
236- areEqualFn : AreEqualFn < Named > = areEqualByName ,
258+ areEqualFn : AreEqualFn < Searchable > = areEqualByName ,
237259) : MemberModificationType [ ] {
238260 return newPlaceToSearch [ keyToSearch ]
239261 . filter ( ( newValue ) => ! oldPlaceToSearch [ keyToSearch ] . some ( ( oldValue ) => areEqualFn ( oldValue , newValue ) ) )
@@ -253,7 +275,3 @@ function getRemovedValues<Named extends NameAware, T extends Record<K, Named[]>,
253275 . map ( ( value ) => value . name )
254276 . map ( ( name ) => ( { __typename : typeName , name } ) ) ;
255277}
256-
257- type MethodAware = {
258- methods : MethodMirror [ ] ;
259- } ;
0 commit comments