@@ -76,6 +76,11 @@ const addEntities =
7676 // TODO: maybe have distinct merge function for this case
7777 entities [ schemaKey ] [ id ] = schema . merge ( existingEntity , processedEntity ) ;
7878 } else {
79+ // TODO: eventually assume this exists and don't check for conditional. probably early 2022
80+ const entityExpiresAt = schema . expiresAt
81+ ? schema . expiresAt ( meta , processedEntity )
82+ : meta . expiresAt ;
83+
7984 const inStoreEntity = existingEntities [ schemaKey ] [ id ] ;
8085 if ( inStoreEntity ) {
8186 // this case we already have this entity in store
@@ -93,8 +98,17 @@ const addEntities =
9398 ? schema . merge ( processedEntity , inStoreEntity )
9499 : schema . merge ( inStoreEntity , processedEntity ) ;
95100 }
101+
102+ entityMeta [ schemaKey ] [ id ] =
103+ entityMeta [ schemaKey ] [ id ] ?. expiresAt >= entityExpiresAt
104+ ? entityMeta [ schemaKey ] [ id ]
105+ : { expiresAt : entityExpiresAt , date : meta . date } ;
96106 } else {
97107 entities [ schemaKey ] [ id ] = processedEntity ;
108+ entityMeta [ schemaKey ] [ id ] = {
109+ expiresAt : entityExpiresAt ,
110+ date : meta . date ,
111+ } ;
98112 }
99113 }
100114
@@ -135,14 +149,6 @@ Entity: ${JSON.stringify(entity, undefined, 2)}`);
135149 }
136150 // set this after index updates so we know what indexes to remove from
137151 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 ;
142- entityMeta [ schemaKey ] [ id ] =
143- entityMeta [ schemaKey ] [ id ] ?. expiresAt >= entityExpiresAt
144- ? entityMeta [ schemaKey ] [ id ]
145- : { expiresAt : entityExpiresAt , date : meta . date } ;
146152 } ;
147153
148154function expectedSchemaType ( schema : Schema ) {
0 commit comments