@sanity/client 6.24.3 → 6.24.4
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.browser.cjs +188 -128
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +109 -0
- package/dist/index.browser.d.ts +109 -0
- package/dist/index.browser.js +189 -129
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +189 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +109 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +190 -130
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +109 -0
- package/dist/stega.browser.d.ts +109 -0
- package/dist/stega.d.cts +109 -0
- package/dist/stega.d.ts +109 -0
- package/package.json +3 -3
- package/src/data/eventsource.ts +255 -0
- package/src/data/eventsourcePolyfill.ts +7 -0
- package/src/data/listen.ts +31 -142
- package/src/data/live.ts +60 -120
- package/src/data/reconnectOnConnectionFailure.ts +30 -0
- package/src/data/transaction.ts +26 -1
- package/src/defineCreateClient.ts +11 -0
- package/src/types.ts +10 -0
- package/umd/sanityClient.js +988 -144
- package/umd/sanityClient.min.js +2 -2
package/dist/stega.browser.d.cts
CHANGED
|
@@ -305,6 +305,16 @@ export declare class BaseTransaction {
|
|
|
305
305
|
protected _add(mut: Mutation): this
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
/**
|
|
309
|
+
* @public
|
|
310
|
+
* The server sent a `channelError` message. Usually indicative of a bad or malformed request
|
|
311
|
+
*/
|
|
312
|
+
export declare class ChannelError extends Error {
|
|
313
|
+
readonly name = 'ChannelError'
|
|
314
|
+
readonly data?: unknown
|
|
315
|
+
constructor(message: string, data: unknown)
|
|
316
|
+
}
|
|
317
|
+
|
|
308
318
|
/**
|
|
309
319
|
* An error occurred. This is different from a network-level error (which will be emitted as 'error').
|
|
310
320
|
* Possible causes are things such as malformed filters, non-existant datasets or similar.
|
|
@@ -403,6 +413,39 @@ export declare type ClientReturn<
|
|
|
403
413
|
*/
|
|
404
414
|
export declare interface ClientStegaConfig extends ClientConfig {}
|
|
405
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
418
|
+
*
|
|
419
|
+
* Since the `EventSource` API is not provided by all environments, this function enables custom initialization of the EventSource instance
|
|
420
|
+
* for runtimes that requires polyfilling or custom setup logic (e.g. custom HTTP headers)
|
|
421
|
+
* via the passed `initEventSource` function which must return an EventSource instance.
|
|
422
|
+
*
|
|
423
|
+
* Possible errors to be thrown on the returned observable are:
|
|
424
|
+
* - {@link MessageError}
|
|
425
|
+
* - {@link MessageParseError}
|
|
426
|
+
* - {@link ChannelError}
|
|
427
|
+
* - {@link DisconnectError}
|
|
428
|
+
* - {@link ConnectionFailedError}
|
|
429
|
+
*
|
|
430
|
+
* @param initEventSource - A function that returns an EventSource instance or an Observable that resolves to an EventSource instance
|
|
431
|
+
* @param events - an array of named events from the API to listen for.
|
|
432
|
+
*
|
|
433
|
+
* @internal
|
|
434
|
+
*/
|
|
435
|
+
export declare function connectEventSource<EventName extends string>(
|
|
436
|
+
initEventSource: () => EventSourceInstance | Observable<EventSourceInstance>,
|
|
437
|
+
events: EventName[],
|
|
438
|
+
): Observable<ServerSentEvent<EventName>>
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* @public
|
|
442
|
+
* Thrown if the EventSource connection could not be established.
|
|
443
|
+
* Note that ConnectionFailedErrors are rare, and disconnects will normally be handled by the EventSource instance itself and emitted as `reconnect` events.
|
|
444
|
+
*/
|
|
445
|
+
export declare class ConnectionFailedError extends Error {
|
|
446
|
+
readonly name = 'ConnectionFailedError'
|
|
447
|
+
}
|
|
448
|
+
|
|
406
449
|
/** @public */
|
|
407
450
|
export declare interface ContentSourceMap {
|
|
408
451
|
mappings: ContentSourceMapMappings
|
|
@@ -734,6 +777,18 @@ export declare type DiscardAction = {
|
|
|
734
777
|
purge?: boolean
|
|
735
778
|
}
|
|
736
779
|
|
|
780
|
+
/**
|
|
781
|
+
* The listener has been told to explicitly disconnect.
|
|
782
|
+
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
783
|
+
* eg in the case of a deleted dataset, a blocked project or similar events.
|
|
784
|
+
* @public
|
|
785
|
+
*/
|
|
786
|
+
export declare class DisconnectError extends Error {
|
|
787
|
+
readonly name = 'DisconnectError'
|
|
788
|
+
readonly reason?: string
|
|
789
|
+
constructor(message: string, reason?: string, options?: ErrorOptions)
|
|
790
|
+
}
|
|
791
|
+
|
|
737
792
|
/**
|
|
738
793
|
* The listener has been told to explicitly disconnect and not reconnect.
|
|
739
794
|
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
@@ -799,6 +854,16 @@ export declare interface ErrorProps {
|
|
|
799
854
|
details: Any
|
|
800
855
|
}
|
|
801
856
|
|
|
857
|
+
/**
|
|
858
|
+
* @internal
|
|
859
|
+
*/
|
|
860
|
+
export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name>
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* @internal
|
|
864
|
+
*/
|
|
865
|
+
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
866
|
+
|
|
802
867
|
/** @public */
|
|
803
868
|
export declare type FilterDefault = (props: {
|
|
804
869
|
/**
|
|
@@ -1020,6 +1085,7 @@ export declare type ListenEvent<R extends Record<string, Any>> =
|
|
|
1020
1085
|
| DisconnectEvent
|
|
1021
1086
|
| ReconnectEvent
|
|
1022
1087
|
| WelcomeEvent
|
|
1088
|
+
| OpenEvent
|
|
1023
1089
|
|
|
1024
1090
|
/** @public */
|
|
1025
1091
|
export declare type ListenEventName =
|
|
@@ -1151,6 +1217,24 @@ declare type Logger_2 =
|
|
|
1151
1217
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
1152
1218
|
>
|
|
1153
1219
|
|
|
1220
|
+
/**
|
|
1221
|
+
* @public
|
|
1222
|
+
* The server sent an `error`-event to tell the client that an unexpected error has happened.
|
|
1223
|
+
*/
|
|
1224
|
+
export declare class MessageError extends Error {
|
|
1225
|
+
readonly name = 'MessageError'
|
|
1226
|
+
readonly data?: unknown
|
|
1227
|
+
constructor(message: string, data: unknown, options?: ErrorOptions)
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* @public
|
|
1232
|
+
* An error occurred while parsing the message sent by the server as JSON. Should normally not happen.
|
|
1233
|
+
*/
|
|
1234
|
+
export declare class MessageParseError extends Error {
|
|
1235
|
+
readonly name = 'MessageParseError'
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1154
1238
|
/** @internal */
|
|
1155
1239
|
export declare interface MultipleActionResult {
|
|
1156
1240
|
transactionId: string
|
|
@@ -2068,6 +2152,15 @@ export declare class ObservableUsersClient {
|
|
|
2068
2152
|
): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
2069
2153
|
}
|
|
2070
2154
|
|
|
2155
|
+
/**
|
|
2156
|
+
* The listener connection has been established
|
|
2157
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
2158
|
+
* @public
|
|
2159
|
+
*/
|
|
2160
|
+
export declare type OpenEvent = {
|
|
2161
|
+
type: 'open'
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2071
2164
|
/** @public */
|
|
2072
2165
|
export declare class Patch extends BasePatch {
|
|
2073
2166
|
#private
|
|
@@ -3066,6 +3159,15 @@ export declare class ServerError extends Error {
|
|
|
3066
3159
|
constructor(res: Any)
|
|
3067
3160
|
}
|
|
3068
3161
|
|
|
3162
|
+
/**
|
|
3163
|
+
* @public
|
|
3164
|
+
*/
|
|
3165
|
+
export declare interface ServerSentEvent<Name extends string> {
|
|
3166
|
+
type: Name
|
|
3167
|
+
id?: string
|
|
3168
|
+
data?: unknown
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3069
3171
|
/** @internal */
|
|
3070
3172
|
export declare interface SingleActionResult {
|
|
3071
3173
|
transactionId: string
|
|
@@ -3236,6 +3338,13 @@ export declare class Transaction extends BaseTransaction {
|
|
|
3236
3338
|
* @param patchOps - Operations to perform, or a builder function
|
|
3237
3339
|
*/
|
|
3238
3340
|
patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
|
|
3341
|
+
/**
|
|
3342
|
+
* Performs a patch on the given selection. Can either be a builder function or an object of patch operations.
|
|
3343
|
+
*
|
|
3344
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
3345
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
3346
|
+
*/
|
|
3347
|
+
patch(patch: MutationSelection, patchOps?: PatchBuilder | PatchOperations): this
|
|
3239
3348
|
/**
|
|
3240
3349
|
* Adds the given patch instance to the transaction.
|
|
3241
3350
|
* The operation is added to the current transaction, ready to be commited by `commit()`
|
package/dist/stega.browser.d.ts
CHANGED
|
@@ -305,6 +305,16 @@ export declare class BaseTransaction {
|
|
|
305
305
|
protected _add(mut: Mutation): this
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
/**
|
|
309
|
+
* @public
|
|
310
|
+
* The server sent a `channelError` message. Usually indicative of a bad or malformed request
|
|
311
|
+
*/
|
|
312
|
+
export declare class ChannelError extends Error {
|
|
313
|
+
readonly name = 'ChannelError'
|
|
314
|
+
readonly data?: unknown
|
|
315
|
+
constructor(message: string, data: unknown)
|
|
316
|
+
}
|
|
317
|
+
|
|
308
318
|
/**
|
|
309
319
|
* An error occurred. This is different from a network-level error (which will be emitted as 'error').
|
|
310
320
|
* Possible causes are things such as malformed filters, non-existant datasets or similar.
|
|
@@ -403,6 +413,39 @@ export declare type ClientReturn<
|
|
|
403
413
|
*/
|
|
404
414
|
export declare interface ClientStegaConfig extends ClientConfig {}
|
|
405
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
418
|
+
*
|
|
419
|
+
* Since the `EventSource` API is not provided by all environments, this function enables custom initialization of the EventSource instance
|
|
420
|
+
* for runtimes that requires polyfilling or custom setup logic (e.g. custom HTTP headers)
|
|
421
|
+
* via the passed `initEventSource` function which must return an EventSource instance.
|
|
422
|
+
*
|
|
423
|
+
* Possible errors to be thrown on the returned observable are:
|
|
424
|
+
* - {@link MessageError}
|
|
425
|
+
* - {@link MessageParseError}
|
|
426
|
+
* - {@link ChannelError}
|
|
427
|
+
* - {@link DisconnectError}
|
|
428
|
+
* - {@link ConnectionFailedError}
|
|
429
|
+
*
|
|
430
|
+
* @param initEventSource - A function that returns an EventSource instance or an Observable that resolves to an EventSource instance
|
|
431
|
+
* @param events - an array of named events from the API to listen for.
|
|
432
|
+
*
|
|
433
|
+
* @internal
|
|
434
|
+
*/
|
|
435
|
+
export declare function connectEventSource<EventName extends string>(
|
|
436
|
+
initEventSource: () => EventSourceInstance | Observable<EventSourceInstance>,
|
|
437
|
+
events: EventName[],
|
|
438
|
+
): Observable<ServerSentEvent<EventName>>
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* @public
|
|
442
|
+
* Thrown if the EventSource connection could not be established.
|
|
443
|
+
* Note that ConnectionFailedErrors are rare, and disconnects will normally be handled by the EventSource instance itself and emitted as `reconnect` events.
|
|
444
|
+
*/
|
|
445
|
+
export declare class ConnectionFailedError extends Error {
|
|
446
|
+
readonly name = 'ConnectionFailedError'
|
|
447
|
+
}
|
|
448
|
+
|
|
406
449
|
/** @public */
|
|
407
450
|
export declare interface ContentSourceMap {
|
|
408
451
|
mappings: ContentSourceMapMappings
|
|
@@ -734,6 +777,18 @@ export declare type DiscardAction = {
|
|
|
734
777
|
purge?: boolean
|
|
735
778
|
}
|
|
736
779
|
|
|
780
|
+
/**
|
|
781
|
+
* The listener has been told to explicitly disconnect.
|
|
782
|
+
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
783
|
+
* eg in the case of a deleted dataset, a blocked project or similar events.
|
|
784
|
+
* @public
|
|
785
|
+
*/
|
|
786
|
+
export declare class DisconnectError extends Error {
|
|
787
|
+
readonly name = 'DisconnectError'
|
|
788
|
+
readonly reason?: string
|
|
789
|
+
constructor(message: string, reason?: string, options?: ErrorOptions)
|
|
790
|
+
}
|
|
791
|
+
|
|
737
792
|
/**
|
|
738
793
|
* The listener has been told to explicitly disconnect and not reconnect.
|
|
739
794
|
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
@@ -799,6 +854,16 @@ export declare interface ErrorProps {
|
|
|
799
854
|
details: Any
|
|
800
855
|
}
|
|
801
856
|
|
|
857
|
+
/**
|
|
858
|
+
* @internal
|
|
859
|
+
*/
|
|
860
|
+
export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name>
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* @internal
|
|
864
|
+
*/
|
|
865
|
+
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
866
|
+
|
|
802
867
|
/** @public */
|
|
803
868
|
export declare type FilterDefault = (props: {
|
|
804
869
|
/**
|
|
@@ -1020,6 +1085,7 @@ export declare type ListenEvent<R extends Record<string, Any>> =
|
|
|
1020
1085
|
| DisconnectEvent
|
|
1021
1086
|
| ReconnectEvent
|
|
1022
1087
|
| WelcomeEvent
|
|
1088
|
+
| OpenEvent
|
|
1023
1089
|
|
|
1024
1090
|
/** @public */
|
|
1025
1091
|
export declare type ListenEventName =
|
|
@@ -1151,6 +1217,24 @@ declare type Logger_2 =
|
|
|
1151
1217
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
1152
1218
|
>
|
|
1153
1219
|
|
|
1220
|
+
/**
|
|
1221
|
+
* @public
|
|
1222
|
+
* The server sent an `error`-event to tell the client that an unexpected error has happened.
|
|
1223
|
+
*/
|
|
1224
|
+
export declare class MessageError extends Error {
|
|
1225
|
+
readonly name = 'MessageError'
|
|
1226
|
+
readonly data?: unknown
|
|
1227
|
+
constructor(message: string, data: unknown, options?: ErrorOptions)
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* @public
|
|
1232
|
+
* An error occurred while parsing the message sent by the server as JSON. Should normally not happen.
|
|
1233
|
+
*/
|
|
1234
|
+
export declare class MessageParseError extends Error {
|
|
1235
|
+
readonly name = 'MessageParseError'
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1154
1238
|
/** @internal */
|
|
1155
1239
|
export declare interface MultipleActionResult {
|
|
1156
1240
|
transactionId: string
|
|
@@ -2068,6 +2152,15 @@ export declare class ObservableUsersClient {
|
|
|
2068
2152
|
): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
2069
2153
|
}
|
|
2070
2154
|
|
|
2155
|
+
/**
|
|
2156
|
+
* The listener connection has been established
|
|
2157
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
2158
|
+
* @public
|
|
2159
|
+
*/
|
|
2160
|
+
export declare type OpenEvent = {
|
|
2161
|
+
type: 'open'
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2071
2164
|
/** @public */
|
|
2072
2165
|
export declare class Patch extends BasePatch {
|
|
2073
2166
|
#private
|
|
@@ -3066,6 +3159,15 @@ export declare class ServerError extends Error {
|
|
|
3066
3159
|
constructor(res: Any)
|
|
3067
3160
|
}
|
|
3068
3161
|
|
|
3162
|
+
/**
|
|
3163
|
+
* @public
|
|
3164
|
+
*/
|
|
3165
|
+
export declare interface ServerSentEvent<Name extends string> {
|
|
3166
|
+
type: Name
|
|
3167
|
+
id?: string
|
|
3168
|
+
data?: unknown
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3069
3171
|
/** @internal */
|
|
3070
3172
|
export declare interface SingleActionResult {
|
|
3071
3173
|
transactionId: string
|
|
@@ -3236,6 +3338,13 @@ export declare class Transaction extends BaseTransaction {
|
|
|
3236
3338
|
* @param patchOps - Operations to perform, or a builder function
|
|
3237
3339
|
*/
|
|
3238
3340
|
patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
|
|
3341
|
+
/**
|
|
3342
|
+
* Performs a patch on the given selection. Can either be a builder function or an object of patch operations.
|
|
3343
|
+
*
|
|
3344
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
3345
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
3346
|
+
*/
|
|
3347
|
+
patch(patch: MutationSelection, patchOps?: PatchBuilder | PatchOperations): this
|
|
3239
3348
|
/**
|
|
3240
3349
|
* Adds the given patch instance to the transaction.
|
|
3241
3350
|
* The operation is added to the current transaction, ready to be commited by `commit()`
|
package/dist/stega.d.cts
CHANGED
|
@@ -305,6 +305,16 @@ export declare class BaseTransaction {
|
|
|
305
305
|
protected _add(mut: Mutation): this
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
/**
|
|
309
|
+
* @public
|
|
310
|
+
* The server sent a `channelError` message. Usually indicative of a bad or malformed request
|
|
311
|
+
*/
|
|
312
|
+
export declare class ChannelError extends Error {
|
|
313
|
+
readonly name = 'ChannelError'
|
|
314
|
+
readonly data?: unknown
|
|
315
|
+
constructor(message: string, data: unknown)
|
|
316
|
+
}
|
|
317
|
+
|
|
308
318
|
/**
|
|
309
319
|
* An error occurred. This is different from a network-level error (which will be emitted as 'error').
|
|
310
320
|
* Possible causes are things such as malformed filters, non-existant datasets or similar.
|
|
@@ -403,6 +413,39 @@ export declare type ClientReturn<
|
|
|
403
413
|
*/
|
|
404
414
|
export declare interface ClientStegaConfig extends ClientConfig {}
|
|
405
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
418
|
+
*
|
|
419
|
+
* Since the `EventSource` API is not provided by all environments, this function enables custom initialization of the EventSource instance
|
|
420
|
+
* for runtimes that requires polyfilling or custom setup logic (e.g. custom HTTP headers)
|
|
421
|
+
* via the passed `initEventSource` function which must return an EventSource instance.
|
|
422
|
+
*
|
|
423
|
+
* Possible errors to be thrown on the returned observable are:
|
|
424
|
+
* - {@link MessageError}
|
|
425
|
+
* - {@link MessageParseError}
|
|
426
|
+
* - {@link ChannelError}
|
|
427
|
+
* - {@link DisconnectError}
|
|
428
|
+
* - {@link ConnectionFailedError}
|
|
429
|
+
*
|
|
430
|
+
* @param initEventSource - A function that returns an EventSource instance or an Observable that resolves to an EventSource instance
|
|
431
|
+
* @param events - an array of named events from the API to listen for.
|
|
432
|
+
*
|
|
433
|
+
* @internal
|
|
434
|
+
*/
|
|
435
|
+
export declare function connectEventSource<EventName extends string>(
|
|
436
|
+
initEventSource: () => EventSourceInstance | Observable<EventSourceInstance>,
|
|
437
|
+
events: EventName[],
|
|
438
|
+
): Observable<ServerSentEvent<EventName>>
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* @public
|
|
442
|
+
* Thrown if the EventSource connection could not be established.
|
|
443
|
+
* Note that ConnectionFailedErrors are rare, and disconnects will normally be handled by the EventSource instance itself and emitted as `reconnect` events.
|
|
444
|
+
*/
|
|
445
|
+
export declare class ConnectionFailedError extends Error {
|
|
446
|
+
readonly name = 'ConnectionFailedError'
|
|
447
|
+
}
|
|
448
|
+
|
|
406
449
|
/** @public */
|
|
407
450
|
export declare interface ContentSourceMap {
|
|
408
451
|
mappings: ContentSourceMapMappings
|
|
@@ -734,6 +777,18 @@ export declare type DiscardAction = {
|
|
|
734
777
|
purge?: boolean
|
|
735
778
|
}
|
|
736
779
|
|
|
780
|
+
/**
|
|
781
|
+
* The listener has been told to explicitly disconnect.
|
|
782
|
+
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
783
|
+
* eg in the case of a deleted dataset, a blocked project or similar events.
|
|
784
|
+
* @public
|
|
785
|
+
*/
|
|
786
|
+
export declare class DisconnectError extends Error {
|
|
787
|
+
readonly name = 'DisconnectError'
|
|
788
|
+
readonly reason?: string
|
|
789
|
+
constructor(message: string, reason?: string, options?: ErrorOptions)
|
|
790
|
+
}
|
|
791
|
+
|
|
737
792
|
/**
|
|
738
793
|
* The listener has been told to explicitly disconnect and not reconnect.
|
|
739
794
|
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
@@ -799,6 +854,16 @@ export declare interface ErrorProps {
|
|
|
799
854
|
details: Any
|
|
800
855
|
}
|
|
801
856
|
|
|
857
|
+
/**
|
|
858
|
+
* @internal
|
|
859
|
+
*/
|
|
860
|
+
export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name>
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* @internal
|
|
864
|
+
*/
|
|
865
|
+
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
866
|
+
|
|
802
867
|
/** @public */
|
|
803
868
|
export declare type FilterDefault = (props: {
|
|
804
869
|
/**
|
|
@@ -1020,6 +1085,7 @@ export declare type ListenEvent<R extends Record<string, Any>> =
|
|
|
1020
1085
|
| DisconnectEvent
|
|
1021
1086
|
| ReconnectEvent
|
|
1022
1087
|
| WelcomeEvent
|
|
1088
|
+
| OpenEvent
|
|
1023
1089
|
|
|
1024
1090
|
/** @public */
|
|
1025
1091
|
export declare type ListenEventName =
|
|
@@ -1151,6 +1217,24 @@ declare type Logger_2 =
|
|
|
1151
1217
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
1152
1218
|
>
|
|
1153
1219
|
|
|
1220
|
+
/**
|
|
1221
|
+
* @public
|
|
1222
|
+
* The server sent an `error`-event to tell the client that an unexpected error has happened.
|
|
1223
|
+
*/
|
|
1224
|
+
export declare class MessageError extends Error {
|
|
1225
|
+
readonly name = 'MessageError'
|
|
1226
|
+
readonly data?: unknown
|
|
1227
|
+
constructor(message: string, data: unknown, options?: ErrorOptions)
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* @public
|
|
1232
|
+
* An error occurred while parsing the message sent by the server as JSON. Should normally not happen.
|
|
1233
|
+
*/
|
|
1234
|
+
export declare class MessageParseError extends Error {
|
|
1235
|
+
readonly name = 'MessageParseError'
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1154
1238
|
/** @internal */
|
|
1155
1239
|
export declare interface MultipleActionResult {
|
|
1156
1240
|
transactionId: string
|
|
@@ -2068,6 +2152,15 @@ export declare class ObservableUsersClient {
|
|
|
2068
2152
|
): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
2069
2153
|
}
|
|
2070
2154
|
|
|
2155
|
+
/**
|
|
2156
|
+
* The listener connection has been established
|
|
2157
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
2158
|
+
* @public
|
|
2159
|
+
*/
|
|
2160
|
+
export declare type OpenEvent = {
|
|
2161
|
+
type: 'open'
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2071
2164
|
/** @public */
|
|
2072
2165
|
export declare class Patch extends BasePatch {
|
|
2073
2166
|
#private
|
|
@@ -3066,6 +3159,15 @@ export declare class ServerError extends Error {
|
|
|
3066
3159
|
constructor(res: Any)
|
|
3067
3160
|
}
|
|
3068
3161
|
|
|
3162
|
+
/**
|
|
3163
|
+
* @public
|
|
3164
|
+
*/
|
|
3165
|
+
export declare interface ServerSentEvent<Name extends string> {
|
|
3166
|
+
type: Name
|
|
3167
|
+
id?: string
|
|
3168
|
+
data?: unknown
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3069
3171
|
/** @internal */
|
|
3070
3172
|
export declare interface SingleActionResult {
|
|
3071
3173
|
transactionId: string
|
|
@@ -3236,6 +3338,13 @@ export declare class Transaction extends BaseTransaction {
|
|
|
3236
3338
|
* @param patchOps - Operations to perform, or a builder function
|
|
3237
3339
|
*/
|
|
3238
3340
|
patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
|
|
3341
|
+
/**
|
|
3342
|
+
* Performs a patch on the given selection. Can either be a builder function or an object of patch operations.
|
|
3343
|
+
*
|
|
3344
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
3345
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
3346
|
+
*/
|
|
3347
|
+
patch(patch: MutationSelection, patchOps?: PatchBuilder | PatchOperations): this
|
|
3239
3348
|
/**
|
|
3240
3349
|
* Adds the given patch instance to the transaction.
|
|
3241
3350
|
* The operation is added to the current transaction, ready to be commited by `commit()`
|
package/dist/stega.d.ts
CHANGED
|
@@ -305,6 +305,16 @@ export declare class BaseTransaction {
|
|
|
305
305
|
protected _add(mut: Mutation): this
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
/**
|
|
309
|
+
* @public
|
|
310
|
+
* The server sent a `channelError` message. Usually indicative of a bad or malformed request
|
|
311
|
+
*/
|
|
312
|
+
export declare class ChannelError extends Error {
|
|
313
|
+
readonly name = 'ChannelError'
|
|
314
|
+
readonly data?: unknown
|
|
315
|
+
constructor(message: string, data: unknown)
|
|
316
|
+
}
|
|
317
|
+
|
|
308
318
|
/**
|
|
309
319
|
* An error occurred. This is different from a network-level error (which will be emitted as 'error').
|
|
310
320
|
* Possible causes are things such as malformed filters, non-existant datasets or similar.
|
|
@@ -403,6 +413,39 @@ export declare type ClientReturn<
|
|
|
403
413
|
*/
|
|
404
414
|
export declare interface ClientStegaConfig extends ClientConfig {}
|
|
405
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Sanity API specific EventSource handler shared between the listen and live APIs
|
|
418
|
+
*
|
|
419
|
+
* Since the `EventSource` API is not provided by all environments, this function enables custom initialization of the EventSource instance
|
|
420
|
+
* for runtimes that requires polyfilling or custom setup logic (e.g. custom HTTP headers)
|
|
421
|
+
* via the passed `initEventSource` function which must return an EventSource instance.
|
|
422
|
+
*
|
|
423
|
+
* Possible errors to be thrown on the returned observable are:
|
|
424
|
+
* - {@link MessageError}
|
|
425
|
+
* - {@link MessageParseError}
|
|
426
|
+
* - {@link ChannelError}
|
|
427
|
+
* - {@link DisconnectError}
|
|
428
|
+
* - {@link ConnectionFailedError}
|
|
429
|
+
*
|
|
430
|
+
* @param initEventSource - A function that returns an EventSource instance or an Observable that resolves to an EventSource instance
|
|
431
|
+
* @param events - an array of named events from the API to listen for.
|
|
432
|
+
*
|
|
433
|
+
* @internal
|
|
434
|
+
*/
|
|
435
|
+
export declare function connectEventSource<EventName extends string>(
|
|
436
|
+
initEventSource: () => EventSourceInstance | Observable<EventSourceInstance>,
|
|
437
|
+
events: EventName[],
|
|
438
|
+
): Observable<ServerSentEvent<EventName>>
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* @public
|
|
442
|
+
* Thrown if the EventSource connection could not be established.
|
|
443
|
+
* Note that ConnectionFailedErrors are rare, and disconnects will normally be handled by the EventSource instance itself and emitted as `reconnect` events.
|
|
444
|
+
*/
|
|
445
|
+
export declare class ConnectionFailedError extends Error {
|
|
446
|
+
readonly name = 'ConnectionFailedError'
|
|
447
|
+
}
|
|
448
|
+
|
|
406
449
|
/** @public */
|
|
407
450
|
export declare interface ContentSourceMap {
|
|
408
451
|
mappings: ContentSourceMapMappings
|
|
@@ -734,6 +777,18 @@ export declare type DiscardAction = {
|
|
|
734
777
|
purge?: boolean
|
|
735
778
|
}
|
|
736
779
|
|
|
780
|
+
/**
|
|
781
|
+
* The listener has been told to explicitly disconnect.
|
|
782
|
+
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
783
|
+
* eg in the case of a deleted dataset, a blocked project or similar events.
|
|
784
|
+
* @public
|
|
785
|
+
*/
|
|
786
|
+
export declare class DisconnectError extends Error {
|
|
787
|
+
readonly name = 'DisconnectError'
|
|
788
|
+
readonly reason?: string
|
|
789
|
+
constructor(message: string, reason?: string, options?: ErrorOptions)
|
|
790
|
+
}
|
|
791
|
+
|
|
737
792
|
/**
|
|
738
793
|
* The listener has been told to explicitly disconnect and not reconnect.
|
|
739
794
|
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
@@ -799,6 +854,16 @@ export declare interface ErrorProps {
|
|
|
799
854
|
details: Any
|
|
800
855
|
}
|
|
801
856
|
|
|
857
|
+
/**
|
|
858
|
+
* @internal
|
|
859
|
+
*/
|
|
860
|
+
export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name>
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* @internal
|
|
864
|
+
*/
|
|
865
|
+
export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
|
|
866
|
+
|
|
802
867
|
/** @public */
|
|
803
868
|
export declare type FilterDefault = (props: {
|
|
804
869
|
/**
|
|
@@ -1020,6 +1085,7 @@ export declare type ListenEvent<R extends Record<string, Any>> =
|
|
|
1020
1085
|
| DisconnectEvent
|
|
1021
1086
|
| ReconnectEvent
|
|
1022
1087
|
| WelcomeEvent
|
|
1088
|
+
| OpenEvent
|
|
1023
1089
|
|
|
1024
1090
|
/** @public */
|
|
1025
1091
|
export declare type ListenEventName =
|
|
@@ -1151,6 +1217,24 @@ declare type Logger_2 =
|
|
|
1151
1217
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
1152
1218
|
>
|
|
1153
1219
|
|
|
1220
|
+
/**
|
|
1221
|
+
* @public
|
|
1222
|
+
* The server sent an `error`-event to tell the client that an unexpected error has happened.
|
|
1223
|
+
*/
|
|
1224
|
+
export declare class MessageError extends Error {
|
|
1225
|
+
readonly name = 'MessageError'
|
|
1226
|
+
readonly data?: unknown
|
|
1227
|
+
constructor(message: string, data: unknown, options?: ErrorOptions)
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* @public
|
|
1232
|
+
* An error occurred while parsing the message sent by the server as JSON. Should normally not happen.
|
|
1233
|
+
*/
|
|
1234
|
+
export declare class MessageParseError extends Error {
|
|
1235
|
+
readonly name = 'MessageParseError'
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1154
1238
|
/** @internal */
|
|
1155
1239
|
export declare interface MultipleActionResult {
|
|
1156
1240
|
transactionId: string
|
|
@@ -2068,6 +2152,15 @@ export declare class ObservableUsersClient {
|
|
|
2068
2152
|
): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
2069
2153
|
}
|
|
2070
2154
|
|
|
2155
|
+
/**
|
|
2156
|
+
* The listener connection has been established
|
|
2157
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
2158
|
+
* @public
|
|
2159
|
+
*/
|
|
2160
|
+
export declare type OpenEvent = {
|
|
2161
|
+
type: 'open'
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2071
2164
|
/** @public */
|
|
2072
2165
|
export declare class Patch extends BasePatch {
|
|
2073
2166
|
#private
|
|
@@ -3066,6 +3159,15 @@ export declare class ServerError extends Error {
|
|
|
3066
3159
|
constructor(res: Any)
|
|
3067
3160
|
}
|
|
3068
3161
|
|
|
3162
|
+
/**
|
|
3163
|
+
* @public
|
|
3164
|
+
*/
|
|
3165
|
+
export declare interface ServerSentEvent<Name extends string> {
|
|
3166
|
+
type: Name
|
|
3167
|
+
id?: string
|
|
3168
|
+
data?: unknown
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3069
3171
|
/** @internal */
|
|
3070
3172
|
export declare interface SingleActionResult {
|
|
3071
3173
|
transactionId: string
|
|
@@ -3236,6 +3338,13 @@ export declare class Transaction extends BaseTransaction {
|
|
|
3236
3338
|
* @param patchOps - Operations to perform, or a builder function
|
|
3237
3339
|
*/
|
|
3238
3340
|
patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
|
|
3341
|
+
/**
|
|
3342
|
+
* Performs a patch on the given selection. Can either be a builder function or an object of patch operations.
|
|
3343
|
+
*
|
|
3344
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
3345
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
3346
|
+
*/
|
|
3347
|
+
patch(patch: MutationSelection, patchOps?: PatchBuilder | PatchOperations): this
|
|
3239
3348
|
/**
|
|
3240
3349
|
* Adds the given patch instance to the transaction.
|
|
3241
3350
|
* The operation is added to the current transaction, ready to be commited by `commit()`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "6.24.
|
|
3
|
+
"version": "6.24.4",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
},
|
|
120
120
|
"dependencies": {
|
|
121
121
|
"@sanity/eventsource": "^5.0.2",
|
|
122
|
-
"get-it": "^8.6.
|
|
122
|
+
"get-it": "^8.6.6",
|
|
123
123
|
"rxjs": "^7.0.0"
|
|
124
124
|
},
|
|
125
125
|
"devDependencies": {
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
129
129
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
130
130
|
"@sanity/client-latest": "npm:@sanity/client@latest",
|
|
131
|
-
"@sanity/pkg-utils": "^
|
|
131
|
+
"@sanity/pkg-utils": "^7.0.1",
|
|
132
132
|
"@types/json-diff": "^1.0.3",
|
|
133
133
|
"@types/node": "^22.9.0",
|
|
134
134
|
"@typescript-eslint/eslint-plugin": "^8.19.1",
|