@sanity/client 7.14.1 → 7.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1995,7 +1995,7 @@ export declare function _listen<R extends Record<string, Any> = Record<string, A
1995
1995
  */
1996
1996
  export declare function _listen<
1997
1997
  R extends Record<string, Any> = Record<string, Any>,
1998
- Opts extends ListenOptions = ListenOptions,
1998
+ Opts extends ListenOptions | ResumableListenOptions = ListenOptions | ResumableListenOptions,
1999
1999
  >(
2000
2000
  this: SanityClient | ObservableSanityClient,
2001
2001
  query: string,
@@ -2004,9 +2004,11 @@ export declare function _listen<
2004
2004
  ): Observable<ListenEventFromOptions<R, Opts>>
2005
2005
 
2006
2006
  /** @public */
2007
- export declare type ListenEvent<R extends Record<string, Any>> =
2007
+ export declare type ListenEvent<R extends Record<string, Any> = Record<string, Any>> =
2008
2008
  | MutationEvent<R>
2009
2009
  | ReconnectEvent
2010
+ | WelcomeBackEvent
2011
+ | ResetEvent
2010
2012
  | WelcomeEvent
2011
2013
  | OpenEvent
2012
2014
 
@@ -2021,9 +2023,9 @@ export declare type ListenEvent<R extends Record<string, Any>> =
2021
2023
  */
2022
2024
  declare type ListenEventFromOptions<
2023
2025
  R extends Record<string, Any> = Record<string, Any>,
2024
- Opts extends ListenOptions | undefined = undefined,
2025
- > = Opts extends ListenOptions
2026
- ? Opts['events'] extends ListenEventName[]
2026
+ Opts extends ListenOptions | ResumableListenOptions | undefined = undefined,
2027
+ > = Opts extends ListenOptions | ResumableListenOptions
2028
+ ? Opts['events'] extends (ResumableListenEventNames | ListenEventName)[]
2027
2029
  ? MapListenEventNamesToListenEvents<R, Opts['events']>
2028
2030
  : ListenEvent<R>
2029
2031
  : MutationEvent<R>
@@ -2076,7 +2078,7 @@ export declare interface ListenOptions {
2076
2078
  visibility?: 'transaction' | 'query'
2077
2079
  /**
2078
2080
  * Array of event names to include in the observable. By default, only mutation events are included.
2079
- *
2081
+ * Note: `welcomeback` and `reset` events requires `enableResume: true`
2080
2082
  * @defaultValue `['mutation']`
2081
2083
  */
2082
2084
  events?: ListenEventName[]
@@ -2096,6 +2098,13 @@ export declare interface ListenOptions {
2096
2098
  * @defaultValue `undefined`
2097
2099
  */
2098
2100
  tag?: string
2101
+ /**
2102
+ * If this is enabled, the client will normally resume events upon reconnect
2103
+ * When if enabling this, you should also add the `reset` to the events array and handle the case where the backend is unable to resume.
2104
+ * @beta
2105
+ * @defaultValue `false`
2106
+ */
2107
+ enableResume?: boolean
2099
2108
  }
2100
2109
 
2101
2110
  /** @public */
@@ -2186,7 +2195,10 @@ export declare type Logger =
2186
2195
  */
2187
2196
  declare type MapListenEventNamesToListenEvents<
2188
2197
  R extends Record<string, Any> = Record<string, Any>,
2189
- Events extends ListenEventName[] = ListenEventName[],
2198
+ Events extends (ResumableListenEventNames | ListenEventName)[] = (
2199
+ | ResumableListenEventNames
2200
+ | ListenEventName
2201
+ )[],
2190
2202
  > = Events extends (infer E)[]
2191
2203
  ? E extends 'welcome'
2192
2204
  ? WelcomeEvent
@@ -2194,9 +2206,13 @@ declare type MapListenEventNamesToListenEvents<
2194
2206
  ? MutationEvent<R>
2195
2207
  : E extends 'reconnect'
2196
2208
  ? ReconnectEvent
2197
- : E extends 'open'
2198
- ? OpenEvent
2199
- : never
2209
+ : E extends 'welcomeback'
2210
+ ? WelcomeBackEvent
2211
+ : E extends 'reset'
2212
+ ? ResetEvent
2213
+ : E extends 'open'
2214
+ ? OpenEvent
2215
+ : never
2200
2216
  : never
2201
2217
 
2202
2218
  /** @public */
@@ -4738,6 +4754,19 @@ export declare interface RequestOptions {
4738
4754
  signal?: AbortSignal
4739
4755
  }
4740
4756
 
4757
+ /**
4758
+ * The listener can't be resumed or otherwise need to reset its local state
4759
+ *
4760
+ * If resumability is unavailable, even listeners created with `enableResume: true` may still
4761
+ * emit `welcome` when reconnected. Subscribers should therefore treat `welcome` after a reconnect
4762
+ * the same way they would otherwise treat a `reset` event.
4763
+ *
4764
+ * @public
4765
+ */
4766
+ export declare type ResetEvent = {
4767
+ type: 'reset'
4768
+ }
4769
+
4741
4770
  export {ResolveStudioUrl}
4742
4771
 
4743
4772
  /** @public */
@@ -4770,6 +4799,32 @@ export declare interface ResponseQueryOptions extends RequestOptions {
4770
4799
  cacheMode?: 'noStale'
4771
4800
  }
4772
4801
 
4802
+ /** @public */
4803
+ export declare type ResumableListenEventNames =
4804
+ | ListenEventName
4805
+ /** The listener has reconnected and successfully resumed from where it left off */
4806
+ | 'welcomeback'
4807
+ /** The listener can't be resumed or otherwise need to reset its local state */
4808
+ | 'reset'
4809
+
4810
+ /** @public */
4811
+ export declare interface ResumableListenOptions
4812
+ extends Omit<ListenOptions, 'events' | 'enableResume'> {
4813
+ /**
4814
+ * If this is enabled, the client will normally resume events upon reconnect
4815
+ * Note that you should also subscribe to `reset`-events and handle the case where the backend is unable to resume
4816
+ * @beta
4817
+ * @defaultValue `false`
4818
+ */
4819
+ enableResume: true
4820
+ /**
4821
+ * Array of event names to include in the observable. By default, only mutation events are included.
4822
+ *
4823
+ * @defaultValue `['mutation']`
4824
+ */
4825
+ events?: ResumableListenEventNames[]
4826
+ }
4827
+
4773
4828
  /** @internal */
4774
4829
  export declare interface SanityAssetDocument extends SanityDocument {
4775
4830
  url: string
@@ -6501,8 +6556,33 @@ export declare interface VideoPlaybackTokens {
6501
6556
  }
6502
6557
 
6503
6558
  /**
6504
- * The listener has been established, and will start receiving events.
6505
- * Note that this is also emitted upon _reconnection_.
6559
+ * Emitted when the listener reconnects and successfully resumes from
6560
+ * its previous position.
6561
+ *
6562
+ * Even if the listener is created with `enableResume: true`, resume support
6563
+ * may not be available. In that case, a reconnect will emit `welcome`
6564
+ * instead of `welcomeback`.
6565
+ *
6566
+ * If resumability is unavailable, even listeners created with `enableResume: true` may still
6567
+ * emit `welcome` when reconnected. Subscribers should therefore treat `welcome` after a reconnect
6568
+ * the same way they would otherwise treat a `reset` event.
6569
+ *
6570
+ * @public
6571
+ */
6572
+ export declare type WelcomeBackEvent = {
6573
+ type: 'welcomeback'
6574
+ listenerName: string
6575
+ }
6576
+
6577
+ /**
6578
+ * Emitted when the listener connection has been successfully established
6579
+ * and is ready to receive events.
6580
+ *
6581
+ * If the listener was created with `enableResume: true` and resume support
6582
+ * is available, the `welcome` event will only be emitted on the initial
6583
+ * connection. On subsequent reconnects, a `welcomeback` event will be
6584
+ * emitted instead, followed by any events that were missed while the
6585
+ * connection was disconnected.
6506
6586
  *
6507
6587
  * @public
6508
6588
  */
@@ -1995,7 +1995,7 @@ export declare function _listen<R extends Record<string, Any> = Record<string, A
1995
1995
  */
1996
1996
  export declare function _listen<
1997
1997
  R extends Record<string, Any> = Record<string, Any>,
1998
- Opts extends ListenOptions = ListenOptions,
1998
+ Opts extends ListenOptions | ResumableListenOptions = ListenOptions | ResumableListenOptions,
1999
1999
  >(
2000
2000
  this: SanityClient | ObservableSanityClient,
2001
2001
  query: string,
@@ -2004,9 +2004,11 @@ export declare function _listen<
2004
2004
  ): Observable<ListenEventFromOptions<R, Opts>>
2005
2005
 
2006
2006
  /** @public */
2007
- export declare type ListenEvent<R extends Record<string, Any>> =
2007
+ export declare type ListenEvent<R extends Record<string, Any> = Record<string, Any>> =
2008
2008
  | MutationEvent<R>
2009
2009
  | ReconnectEvent
2010
+ | WelcomeBackEvent
2011
+ | ResetEvent
2010
2012
  | WelcomeEvent
2011
2013
  | OpenEvent
2012
2014
 
@@ -2021,9 +2023,9 @@ export declare type ListenEvent<R extends Record<string, Any>> =
2021
2023
  */
2022
2024
  declare type ListenEventFromOptions<
2023
2025
  R extends Record<string, Any> = Record<string, Any>,
2024
- Opts extends ListenOptions | undefined = undefined,
2025
- > = Opts extends ListenOptions
2026
- ? Opts['events'] extends ListenEventName[]
2026
+ Opts extends ListenOptions | ResumableListenOptions | undefined = undefined,
2027
+ > = Opts extends ListenOptions | ResumableListenOptions
2028
+ ? Opts['events'] extends (ResumableListenEventNames | ListenEventName)[]
2027
2029
  ? MapListenEventNamesToListenEvents<R, Opts['events']>
2028
2030
  : ListenEvent<R>
2029
2031
  : MutationEvent<R>
@@ -2076,7 +2078,7 @@ export declare interface ListenOptions {
2076
2078
  visibility?: 'transaction' | 'query'
2077
2079
  /**
2078
2080
  * Array of event names to include in the observable. By default, only mutation events are included.
2079
- *
2081
+ * Note: `welcomeback` and `reset` events requires `enableResume: true`
2080
2082
  * @defaultValue `['mutation']`
2081
2083
  */
2082
2084
  events?: ListenEventName[]
@@ -2096,6 +2098,13 @@ export declare interface ListenOptions {
2096
2098
  * @defaultValue `undefined`
2097
2099
  */
2098
2100
  tag?: string
2101
+ /**
2102
+ * If this is enabled, the client will normally resume events upon reconnect
2103
+ * When if enabling this, you should also add the `reset` to the events array and handle the case where the backend is unable to resume.
2104
+ * @beta
2105
+ * @defaultValue `false`
2106
+ */
2107
+ enableResume?: boolean
2099
2108
  }
2100
2109
 
2101
2110
  /** @public */
@@ -2186,7 +2195,10 @@ export declare type Logger =
2186
2195
  */
2187
2196
  declare type MapListenEventNamesToListenEvents<
2188
2197
  R extends Record<string, Any> = Record<string, Any>,
2189
- Events extends ListenEventName[] = ListenEventName[],
2198
+ Events extends (ResumableListenEventNames | ListenEventName)[] = (
2199
+ | ResumableListenEventNames
2200
+ | ListenEventName
2201
+ )[],
2190
2202
  > = Events extends (infer E)[]
2191
2203
  ? E extends 'welcome'
2192
2204
  ? WelcomeEvent
@@ -2194,9 +2206,13 @@ declare type MapListenEventNamesToListenEvents<
2194
2206
  ? MutationEvent<R>
2195
2207
  : E extends 'reconnect'
2196
2208
  ? ReconnectEvent
2197
- : E extends 'open'
2198
- ? OpenEvent
2199
- : never
2209
+ : E extends 'welcomeback'
2210
+ ? WelcomeBackEvent
2211
+ : E extends 'reset'
2212
+ ? ResetEvent
2213
+ : E extends 'open'
2214
+ ? OpenEvent
2215
+ : never
2200
2216
  : never
2201
2217
 
2202
2218
  /** @public */
@@ -4738,6 +4754,19 @@ export declare interface RequestOptions {
4738
4754
  signal?: AbortSignal
4739
4755
  }
4740
4756
 
4757
+ /**
4758
+ * The listener can't be resumed or otherwise need to reset its local state
4759
+ *
4760
+ * If resumability is unavailable, even listeners created with `enableResume: true` may still
4761
+ * emit `welcome` when reconnected. Subscribers should therefore treat `welcome` after a reconnect
4762
+ * the same way they would otherwise treat a `reset` event.
4763
+ *
4764
+ * @public
4765
+ */
4766
+ export declare type ResetEvent = {
4767
+ type: 'reset'
4768
+ }
4769
+
4741
4770
  export {ResolveStudioUrl}
4742
4771
 
4743
4772
  /** @public */
@@ -4770,6 +4799,32 @@ export declare interface ResponseQueryOptions extends RequestOptions {
4770
4799
  cacheMode?: 'noStale'
4771
4800
  }
4772
4801
 
4802
+ /** @public */
4803
+ export declare type ResumableListenEventNames =
4804
+ | ListenEventName
4805
+ /** The listener has reconnected and successfully resumed from where it left off */
4806
+ | 'welcomeback'
4807
+ /** The listener can't be resumed or otherwise need to reset its local state */
4808
+ | 'reset'
4809
+
4810
+ /** @public */
4811
+ export declare interface ResumableListenOptions
4812
+ extends Omit<ListenOptions, 'events' | 'enableResume'> {
4813
+ /**
4814
+ * If this is enabled, the client will normally resume events upon reconnect
4815
+ * Note that you should also subscribe to `reset`-events and handle the case where the backend is unable to resume
4816
+ * @beta
4817
+ * @defaultValue `false`
4818
+ */
4819
+ enableResume: true
4820
+ /**
4821
+ * Array of event names to include in the observable. By default, only mutation events are included.
4822
+ *
4823
+ * @defaultValue `['mutation']`
4824
+ */
4825
+ events?: ResumableListenEventNames[]
4826
+ }
4827
+
4773
4828
  /** @internal */
4774
4829
  export declare interface SanityAssetDocument extends SanityDocument {
4775
4830
  url: string
@@ -6501,8 +6556,33 @@ export declare interface VideoPlaybackTokens {
6501
6556
  }
6502
6557
 
6503
6558
  /**
6504
- * The listener has been established, and will start receiving events.
6505
- * Note that this is also emitted upon _reconnection_.
6559
+ * Emitted when the listener reconnects and successfully resumes from
6560
+ * its previous position.
6561
+ *
6562
+ * Even if the listener is created with `enableResume: true`, resume support
6563
+ * may not be available. In that case, a reconnect will emit `welcome`
6564
+ * instead of `welcomeback`.
6565
+ *
6566
+ * If resumability is unavailable, even listeners created with `enableResume: true` may still
6567
+ * emit `welcome` when reconnected. Subscribers should therefore treat `welcome` after a reconnect
6568
+ * the same way they would otherwise treat a `reset` event.
6569
+ *
6570
+ * @public
6571
+ */
6572
+ export declare type WelcomeBackEvent = {
6573
+ type: 'welcomeback'
6574
+ listenerName: string
6575
+ }
6576
+
6577
+ /**
6578
+ * Emitted when the listener connection has been successfully established
6579
+ * and is ready to receive events.
6580
+ *
6581
+ * If the listener was created with `enableResume: true` and resume support
6582
+ * is available, the `welcome` event will only be emitted on the initial
6583
+ * connection. On subsequent reconnects, a `welcomeback` event will be
6584
+ * emitted instead, followed by any events that were missed while the
6585
+ * connection was disconnected.
6506
6586
  *
6507
6587
  * @public
6508
6588
  */
@@ -1393,6 +1393,7 @@ const MAX_URL_LENGTH = 14800, possibleOptions = [
1393
1393
  "includeAllVersions",
1394
1394
  "visibility",
1395
1395
  "effectFormat",
1396
+ "enableResume",
1396
1397
  "tag"
1397
1398
  ], defaultOptions = {
1398
1399
  includeResult: !0