@sanity/client 7.12.0 → 7.13.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.
package/dist/index.d.cts CHANGED
@@ -1965,22 +1965,41 @@ export declare function _listen<R extends Record<string, Any> = Record<string, A
1965
1965
  * @param options - Optional listener options
1966
1966
  * @public
1967
1967
  */
1968
- export declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
1968
+ export declare function _listen<
1969
+ R extends Record<string, Any> = Record<string, Any>,
1970
+ Opts extends ListenOptions = ListenOptions,
1971
+ >(
1969
1972
  this: SanityClient | ObservableSanityClient,
1970
1973
  query: string,
1971
1974
  params?: ListenParams,
1972
- options?: ListenOptions,
1973
- ): Observable<ListenEvent<R>>
1975
+ options?: Opts,
1976
+ ): Observable<ListenEventFromOptions<R, Opts>>
1974
1977
 
1975
1978
  /** @public */
1976
1979
  export declare type ListenEvent<R extends Record<string, Any>> =
1977
1980
  | MutationEvent<R>
1978
- | ChannelErrorEvent
1979
- | DisconnectEvent
1980
1981
  | ReconnectEvent
1981
1982
  | WelcomeEvent
1982
1983
  | OpenEvent
1983
1984
 
1985
+ /**
1986
+ * Maps a ListenOptions object and returns the Listen events opted for, e.g:
1987
+ * ```
1988
+ * type Test = ListenEventFromOptions<Doc, {events: ['welcome', 'mutation']}>
1989
+ * // ^? WelcomeEvent | MutationEvent<Doc>
1990
+ * ```
1991
+ *
1992
+ * @public
1993
+ */
1994
+ declare type ListenEventFromOptions<
1995
+ R extends Record<string, Any> = Record<string, Any>,
1996
+ Opts extends ListenOptions | undefined = undefined,
1997
+ > = Opts extends ListenOptions
1998
+ ? Opts['events'] extends ListenEventName[]
1999
+ ? MapListenEventNamesToListenEvents<R, Opts['events']>
2000
+ : ListenEvent<R>
2001
+ : MutationEvent<R>
2002
+
1984
2003
  /** @public */
1985
2004
  export declare type ListenEventName =
1986
2005
  /** A mutation was performed */
@@ -1989,6 +2008,11 @@ export declare type ListenEventName =
1989
2008
  | 'welcome'
1990
2009
  /** The listener has been disconnected, and a reconnect attempt is scheduled */
1991
2010
  | 'reconnect'
2011
+ /**
2012
+ * The listener connection has been established
2013
+ * note: it's usually a better option to use the 'welcome' event
2014
+ */
2015
+ | 'open'
1992
2016
 
1993
2017
  /** @public */
1994
2018
  export declare interface ListenOptions {
@@ -2123,6 +2147,30 @@ export declare type Logger =
2123
2147
  Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
2124
2148
  >
2125
2149
 
2150
+ /**
2151
+ * Maps an array of listen events names to their corresponding listen event type, e.g:
2152
+ * ```
2153
+ * type Test = MapListenEventNamesToListenEvents<Doc, ['welcome']>
2154
+ * // ^? WelcomeEvent
2155
+ * ```
2156
+ *
2157
+ * @public
2158
+ */
2159
+ declare type MapListenEventNamesToListenEvents<
2160
+ R extends Record<string, Any> = Record<string, Any>,
2161
+ Events extends ListenEventName[] = ListenEventName[],
2162
+ > = Events extends (infer E)[]
2163
+ ? E extends 'welcome'
2164
+ ? WelcomeEvent
2165
+ : E extends 'mutation'
2166
+ ? MutationEvent<R>
2167
+ : E extends 'reconnect'
2168
+ ? ReconnectEvent
2169
+ : E extends 'open'
2170
+ ? OpenEvent
2171
+ : never
2172
+ : never
2173
+
2126
2174
  /** @public */
2127
2175
  export declare type MediaLibraryAssetInstanceIdentifier = string | SanityReference
2128
2176
 
@@ -3281,7 +3329,7 @@ export declare class ObservableSanityClient {
3281
3329
  createVersion(
3282
3330
  args: {
3283
3331
  baseId: string
3284
- releaseId: string
3332
+ releaseId?: string
3285
3333
  publishedId: string
3286
3334
  ifBaseRevisionId?: string
3287
3335
  },
@@ -5094,7 +5142,7 @@ export declare class SanityClient {
5094
5142
  args: {
5095
5143
  publishedId: string
5096
5144
  baseId: string
5097
- releaseId: string
5145
+ releaseId?: string
5098
5146
  ifBaseRevisionId?: string
5099
5147
  },
5100
5148
  options?: BaseActionOptions,
package/dist/index.d.ts CHANGED
@@ -1965,22 +1965,41 @@ export declare function _listen<R extends Record<string, Any> = Record<string, A
1965
1965
  * @param options - Optional listener options
1966
1966
  * @public
1967
1967
  */
1968
- export declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
1968
+ export declare function _listen<
1969
+ R extends Record<string, Any> = Record<string, Any>,
1970
+ Opts extends ListenOptions = ListenOptions,
1971
+ >(
1969
1972
  this: SanityClient | ObservableSanityClient,
1970
1973
  query: string,
1971
1974
  params?: ListenParams,
1972
- options?: ListenOptions,
1973
- ): Observable<ListenEvent<R>>
1975
+ options?: Opts,
1976
+ ): Observable<ListenEventFromOptions<R, Opts>>
1974
1977
 
1975
1978
  /** @public */
1976
1979
  export declare type ListenEvent<R extends Record<string, Any>> =
1977
1980
  | MutationEvent<R>
1978
- | ChannelErrorEvent
1979
- | DisconnectEvent
1980
1981
  | ReconnectEvent
1981
1982
  | WelcomeEvent
1982
1983
  | OpenEvent
1983
1984
 
1985
+ /**
1986
+ * Maps a ListenOptions object and returns the Listen events opted for, e.g:
1987
+ * ```
1988
+ * type Test = ListenEventFromOptions<Doc, {events: ['welcome', 'mutation']}>
1989
+ * // ^? WelcomeEvent | MutationEvent<Doc>
1990
+ * ```
1991
+ *
1992
+ * @public
1993
+ */
1994
+ declare type ListenEventFromOptions<
1995
+ R extends Record<string, Any> = Record<string, Any>,
1996
+ Opts extends ListenOptions | undefined = undefined,
1997
+ > = Opts extends ListenOptions
1998
+ ? Opts['events'] extends ListenEventName[]
1999
+ ? MapListenEventNamesToListenEvents<R, Opts['events']>
2000
+ : ListenEvent<R>
2001
+ : MutationEvent<R>
2002
+
1984
2003
  /** @public */
1985
2004
  export declare type ListenEventName =
1986
2005
  /** A mutation was performed */
@@ -1989,6 +2008,11 @@ export declare type ListenEventName =
1989
2008
  | 'welcome'
1990
2009
  /** The listener has been disconnected, and a reconnect attempt is scheduled */
1991
2010
  | 'reconnect'
2011
+ /**
2012
+ * The listener connection has been established
2013
+ * note: it's usually a better option to use the 'welcome' event
2014
+ */
2015
+ | 'open'
1992
2016
 
1993
2017
  /** @public */
1994
2018
  export declare interface ListenOptions {
@@ -2123,6 +2147,30 @@ export declare type Logger =
2123
2147
  Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
2124
2148
  >
2125
2149
 
2150
+ /**
2151
+ * Maps an array of listen events names to their corresponding listen event type, e.g:
2152
+ * ```
2153
+ * type Test = MapListenEventNamesToListenEvents<Doc, ['welcome']>
2154
+ * // ^? WelcomeEvent
2155
+ * ```
2156
+ *
2157
+ * @public
2158
+ */
2159
+ declare type MapListenEventNamesToListenEvents<
2160
+ R extends Record<string, Any> = Record<string, Any>,
2161
+ Events extends ListenEventName[] = ListenEventName[],
2162
+ > = Events extends (infer E)[]
2163
+ ? E extends 'welcome'
2164
+ ? WelcomeEvent
2165
+ : E extends 'mutation'
2166
+ ? MutationEvent<R>
2167
+ : E extends 'reconnect'
2168
+ ? ReconnectEvent
2169
+ : E extends 'open'
2170
+ ? OpenEvent
2171
+ : never
2172
+ : never
2173
+
2126
2174
  /** @public */
2127
2175
  export declare type MediaLibraryAssetInstanceIdentifier = string | SanityReference
2128
2176
 
@@ -3281,7 +3329,7 @@ export declare class ObservableSanityClient {
3281
3329
  createVersion(
3282
3330
  args: {
3283
3331
  baseId: string
3284
- releaseId: string
3332
+ releaseId?: string
3285
3333
  publishedId: string
3286
3334
  ifBaseRevisionId?: string
3287
3335
  },
@@ -5094,7 +5142,7 @@ export declare class SanityClient {
5094
5142
  args: {
5095
5143
  publishedId: string
5096
5144
  baseId: string
5097
- releaseId: string
5145
+ releaseId?: string
5098
5146
  ifBaseRevisionId?: string
5099
5147
  },
5100
5148
  options?: BaseActionOptions,
package/dist/index.js CHANGED
@@ -1217,12 +1217,10 @@ function _listen(query, params, opts = {}) {
1217
1217
  ), listenFor).pipe(
1218
1218
  reconnectOnConnectionFailure(),
1219
1219
  filter((event) => listenFor.includes(event.type)),
1220
- map(
1221
- (event) => ({
1222
- type: event.type,
1223
- ..."data" in event ? event.data : {}
1224
- })
1225
- )
1220
+ map((event) => ({
1221
+ type: event.type,
1222
+ ..."data" in event ? event.data : {}
1223
+ }))
1226
1224
  );
1227
1225
  }
1228
1226
  function shareReplayLatest(configOrPredicate, config) {
@@ -2670,7 +2668,7 @@ function defineDeprecatedCreateClient(createClient2) {
2670
2668
  return printNoDefaultExport(), createClient2(config);
2671
2669
  };
2672
2670
  }
2673
- var name = "@sanity/client", version = "7.12.0";
2671
+ var name = "@sanity/client", version = "7.13.0";
2674
2672
  const middleware = [
2675
2673
  debug({ verbose: !0, namespace: "sanity:client" }),
2676
2674
  headers({ "User-Agent": `${name} ${version}` }),