@@ -19,6 +19,8 @@ import type LoaderService from '../services/loader-service';
19
19
import type MessageService from '../services/message-service' ;
20
20
import type NetworkService from '../services/network' ;
21
21
22
+ import type { RealmEventEventContent } from '@cardstack/base/matrix-event' ;
23
+
22
24
const log = logger ( 'resource:file' ) ;
23
25
const utf8 = new TextDecoder ( ) ;
24
26
const encoder = new TextEncoder ( ) ;
@@ -91,7 +93,7 @@ class _FileResource extends Resource<Args> {
91
93
92
94
private setSubscription (
93
95
realmURL : string ,
94
- callback : ( ev : { type : string ; data : string } ) => void ,
96
+ callback : ( ev : RealmEventEventContent ) => void ,
95
97
) {
96
98
if ( this . subscription && this . subscription . url !== realmURL ) {
97
99
this . subscription . unsubscribe ( ) ;
@@ -197,19 +199,18 @@ class _FileResource extends Resource<Args> {
197
199
} ,
198
200
} ) ;
199
201
200
- this . setSubscription ( realmURL , ( event : { type : string ; data : string } ) => {
201
- let eventData = JSON . parse ( event . data ) ;
202
+ this . setSubscription ( realmURL , ( event : RealmEventEventContent ) => {
202
203
if (
203
- event . type !== 'index' ||
204
+ event . eventName !== 'index' ||
204
205
// we wait specifically for the index complete event ("incremental") so
205
206
// that the subsequent index read retrieves the latest contents of the file
206
- eventData . type !== 'incremental' ||
207
- ! Array . isArray ( eventData . invalidations )
207
+ event . indexType !== 'incremental' ||
208
+ ! Array . isArray ( event . invalidations )
208
209
) {
209
210
return ;
210
211
}
211
212
212
- let { invalidations } = eventData as { invalidations : string [ ] } ;
213
+ let { invalidations } = event as { invalidations : string [ ] } ;
213
214
let normalizedURL = this . url . endsWith ( '.json' )
214
215
? this . url . replace ( / \. j s o n $ / , '' )
215
216
: this . url ;
0 commit comments