@@ -12,8 +12,6 @@ import {
1212 type OpenEvent ,
1313 type ReconnectEvent ,
1414 type ResetEvent ,
15- type ResumableListenEventNames ,
16- type ResumableListenOptions ,
1715 type WelcomeBackEvent ,
1816 type WelcomeEvent ,
1917} from '../types'
@@ -37,7 +35,6 @@ const possibleOptions = [
3735 'includeAllVersions' ,
3836 'visibility' ,
3937 'effectFormat' ,
40- 'enableResume' ,
4138 'tag' ,
4239]
4340
@@ -56,10 +53,7 @@ const defaultOptions = {
5653 */
5754export type MapListenEventNamesToListenEvents <
5855 R extends Record < string , Any > = Record < string , Any > ,
59- Events extends ( ResumableListenEventNames | ListenEventName ) [ ] = (
60- | ResumableListenEventNames
61- | ListenEventName
62- ) [ ] ,
56+ Events extends ListenEventName [ ] = ListenEventName [ ] ,
6357> = Events extends ( infer E ) [ ]
6458 ? E extends 'welcome'
6559 ? WelcomeEvent
@@ -87,13 +81,13 @@ export type MapListenEventNamesToListenEvents<
8781 */
8882export type ListenEventFromOptions <
8983 R extends Record < string , Any > = Record < string , Any > ,
90- Opts extends ListenOptions | ResumableListenOptions | undefined = undefined ,
91- > = Opts extends ListenOptions | ResumableListenOptions
92- ? Opts [ 'events' ] extends ( ResumableListenEventNames | ListenEventName ) [ ]
84+ Opts extends ListenOptions | undefined = undefined ,
85+ > = Opts extends ListenOptions
86+ ? Opts [ 'events' ] extends ListenEventName [ ]
9387 ? MapListenEventNamesToListenEvents < R , Opts [ 'events' ] >
9488 : // fall back to ListenEvent if opts events is present, but we can't infer the literal event names
9589 ListenEvent < R >
96- : MutationEvent < R >
90+ : MutationEvent < R > | ResetEvent
9791
9892/**
9993 * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
@@ -107,7 +101,7 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
107101 this : SanityClient | ObservableSanityClient ,
108102 query : string ,
109103 params ?: ListenParams ,
110- ) : Observable < MutationEvent < R > >
104+ ) : Observable < MutationEvent < R > | ResetEvent >
111105/**
112106 * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
113107 *
@@ -118,7 +112,7 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
118112 */
119113export function _listen <
120114 R extends Record < string , Any > = Record < string , Any > ,
121- Opts extends ListenOptions | ResumableListenOptions = ListenOptions ,
115+ Opts extends ListenOptions = ListenOptions ,
122116> (
123117 this : SanityClient | ObservableSanityClient ,
124118 query : string ,
@@ -139,14 +133,16 @@ export function _listen<
139133 const tag = opts . tag && requestTagPrefix ? [ requestTagPrefix , opts . tag ] . join ( '.' ) : opts . tag
140134 const options = { ...defaults ( opts , defaultOptions ) , tag}
141135 const listenOpts = pick ( options , possibleOptions )
142- const qs = encodeQueryString ( { query, params, options : { tag, ...listenOpts } } )
136+ const qs = encodeQueryString ( { query, params, options : { tag, ...listenOpts , enableResume : true } } )
143137
144138 const uri = `${ url } ${ _getDataUrl ( this , 'listen' , qs ) } `
145139 if ( uri . length > MAX_URL_LENGTH ) {
146140 return throwError ( ( ) => new Error ( 'Query too large for listener' ) )
147141 }
148142
149- const listenFor = ( options . events ? options . events : [ 'mutation' ] ) satisfies Opts [ 'events' ]
143+ const listenFor = (
144+ options . events ? options . events : [ 'mutation' , 'reset' ]
145+ ) satisfies Opts [ 'events' ]
150146
151147 const esOptions : EventSourceInit & { headers ?: Record < string , string > } = { }
152148 if ( withCredentials ) {
0 commit comments