@@ -61,7 +61,7 @@ const addEntities =
6161 } ;
6262 } ;
6363 } ,
64- { expiresAt , date } : { expiresAt : number ; date : number } ,
64+ meta : { expiresAt : number ; date : number } ,
6565 ) =>
6666 ( schema : any , processedEntity : any , id : any ) => {
6767 const schemaKey = schema . key ;
@@ -82,7 +82,7 @@ const addEntities =
8282
8383 // if either of these is undefined, it resolves to 'false' which
8484 // means we fallback to 'newer' (processedEntity) takes priority
85- const preferExisting = entityMeta [ schemaKey ] [ id ] ?. date > date ;
85+ const preferExisting = entityMeta [ schemaKey ] [ id ] ?. date > meta . date ;
8686 if ( typeof processedEntity !== typeof inStoreEntity ) {
8787 entities [ schemaKey ] [ id ] = preferExisting
8888 ? inStoreEntity
@@ -135,10 +135,14 @@ Entity: ${JSON.stringify(entity, undefined, 2)}`);
135135 }
136136 // set this after index updates so we know what indexes to remove from
137137 existingEntities [ schemaKey ] [ id ] = entities [ schemaKey ] [ id ] ;
138+ // TODO: eventually assume this exists and don't check for conditional. probably early 2022
139+ const entityExpiresAt = schema . expiresAt
140+ ? schema . expiresAt ( meta , processedEntity )
141+ : meta . expiresAt ;
138142 entityMeta [ schemaKey ] [ id ] =
139- entityMeta [ schemaKey ] [ id ] ?. expiresAt >= expiresAt
143+ entityMeta [ schemaKey ] [ id ] ?. expiresAt >= entityExpiresAt
140144 ? entityMeta [ schemaKey ] [ id ]
141- : { expiresAt, date } ;
145+ : { expiresAt : entityExpiresAt , date : meta . date } ;
142146 } ;
143147
144148function expectedSchemaType ( schema : Schema ) {
0 commit comments