@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.
- package/dist/index.browser.cjs +1 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +92 -12
- package/dist/index.browser.d.ts +92 -12
- package/dist/index.browser.js +1 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +92 -12
- package/dist/index.d.ts +92 -12
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +92 -12
- package/dist/stega.browser.d.ts +92 -12
- package/dist/stega.d.cts +92 -12
- package/dist/stega.d.ts +92 -12
- package/package.json +1 -1
- package/src/data/listen.ts +21 -9
- package/src/types.ts +78 -4
- package/umd/sanityClient.js +1 -0
- package/umd/sanityClient.min.js +1 -1
package/package.json
CHANGED
package/src/data/listen.ts
CHANGED
|
@@ -11,6 +11,10 @@ import {
|
|
|
11
11
|
type MutationEvent,
|
|
12
12
|
type OpenEvent,
|
|
13
13
|
type ReconnectEvent,
|
|
14
|
+
type ResetEvent,
|
|
15
|
+
type ResumableListenEventNames,
|
|
16
|
+
type ResumableListenOptions,
|
|
17
|
+
type WelcomeBackEvent,
|
|
14
18
|
type WelcomeEvent,
|
|
15
19
|
} from '../types'
|
|
16
20
|
import defaults from '../util/defaults'
|
|
@@ -33,6 +37,7 @@ const possibleOptions = [
|
|
|
33
37
|
'includeAllVersions',
|
|
34
38
|
'visibility',
|
|
35
39
|
'effectFormat',
|
|
40
|
+
'enableResume',
|
|
36
41
|
'tag',
|
|
37
42
|
]
|
|
38
43
|
|
|
@@ -51,7 +56,10 @@ const defaultOptions = {
|
|
|
51
56
|
*/
|
|
52
57
|
export type MapListenEventNamesToListenEvents<
|
|
53
58
|
R extends Record<string, Any> = Record<string, Any>,
|
|
54
|
-
Events extends ListenEventName[] =
|
|
59
|
+
Events extends (ResumableListenEventNames | ListenEventName)[] = (
|
|
60
|
+
| ResumableListenEventNames
|
|
61
|
+
| ListenEventName
|
|
62
|
+
)[],
|
|
55
63
|
> = Events extends (infer E)[]
|
|
56
64
|
? E extends 'welcome'
|
|
57
65
|
? WelcomeEvent
|
|
@@ -59,9 +67,13 @@ export type MapListenEventNamesToListenEvents<
|
|
|
59
67
|
? MutationEvent<R>
|
|
60
68
|
: E extends 'reconnect'
|
|
61
69
|
? ReconnectEvent
|
|
62
|
-
: E extends '
|
|
63
|
-
?
|
|
64
|
-
:
|
|
70
|
+
: E extends 'welcomeback'
|
|
71
|
+
? WelcomeBackEvent
|
|
72
|
+
: E extends 'reset'
|
|
73
|
+
? ResetEvent
|
|
74
|
+
: E extends 'open'
|
|
75
|
+
? OpenEvent
|
|
76
|
+
: never
|
|
65
77
|
: never
|
|
66
78
|
|
|
67
79
|
/**
|
|
@@ -75,9 +87,9 @@ export type MapListenEventNamesToListenEvents<
|
|
|
75
87
|
*/
|
|
76
88
|
export type ListenEventFromOptions<
|
|
77
89
|
R extends Record<string, Any> = Record<string, Any>,
|
|
78
|
-
Opts extends ListenOptions | undefined = undefined,
|
|
79
|
-
> = Opts extends ListenOptions
|
|
80
|
-
? Opts['events'] extends ListenEventName[]
|
|
90
|
+
Opts extends ListenOptions | ResumableListenOptions | undefined = undefined,
|
|
91
|
+
> = Opts extends ListenOptions | ResumableListenOptions
|
|
92
|
+
? Opts['events'] extends (ResumableListenEventNames | ListenEventName)[]
|
|
81
93
|
? MapListenEventNamesToListenEvents<R, Opts['events']>
|
|
82
94
|
: // fall back to ListenEvent if opts events is present, but we can't infer the literal event names
|
|
83
95
|
ListenEvent<R>
|
|
@@ -106,7 +118,7 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
|
106
118
|
*/
|
|
107
119
|
export function _listen<
|
|
108
120
|
R extends Record<string, Any> = Record<string, Any>,
|
|
109
|
-
Opts extends ListenOptions = ListenOptions,
|
|
121
|
+
Opts extends ListenOptions | ResumableListenOptions = ListenOptions | ResumableListenOptions,
|
|
110
122
|
>(
|
|
111
123
|
this: SanityClient | ObservableSanityClient,
|
|
112
124
|
query: string,
|
|
@@ -116,7 +128,7 @@ export function _listen<
|
|
|
116
128
|
/** @public */
|
|
117
129
|
export function _listen<
|
|
118
130
|
R extends Record<string, Any> = Record<string, Any>,
|
|
119
|
-
Opts extends ListenOptions = ListenOptions,
|
|
131
|
+
Opts extends ListenOptions | ResumableListenOptions = ListenOptions | ResumableListenOptions,
|
|
120
132
|
>(
|
|
121
133
|
this: SanityClient | ObservableSanityClient,
|
|
122
134
|
query: string,
|
package/src/types.ts
CHANGED
|
@@ -1151,8 +1151,14 @@ export type OpenEvent = {
|
|
|
1151
1151
|
}
|
|
1152
1152
|
|
|
1153
1153
|
/**
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1154
|
+
* Emitted when the listener connection has been successfully established
|
|
1155
|
+
* and is ready to receive events.
|
|
1156
|
+
*
|
|
1157
|
+
* If the listener was created with `enableResume: true` and resume support
|
|
1158
|
+
* is available, the `welcome` event will only be emitted on the initial
|
|
1159
|
+
* connection. On subsequent reconnects, a `welcomeback` event will be
|
|
1160
|
+
* emitted instead, followed by any events that were missed while the
|
|
1161
|
+
* connection was disconnected.
|
|
1156
1162
|
*
|
|
1157
1163
|
* @public
|
|
1158
1164
|
*/
|
|
@@ -1161,10 +1167,44 @@ export type WelcomeEvent = {
|
|
|
1161
1167
|
listenerName: string
|
|
1162
1168
|
}
|
|
1163
1169
|
|
|
1170
|
+
/**
|
|
1171
|
+
* Emitted when the listener reconnects and successfully resumes from
|
|
1172
|
+
* its previous position.
|
|
1173
|
+
*
|
|
1174
|
+
* Even if the listener is created with `enableResume: true`, resume support
|
|
1175
|
+
* may not be available. In that case, a reconnect will emit `welcome`
|
|
1176
|
+
* instead of `welcomeback`.
|
|
1177
|
+
*
|
|
1178
|
+
* If resumability is unavailable, even listeners created with `enableResume: true` may still
|
|
1179
|
+
* emit `welcome` when reconnected. Subscribers should therefore treat `welcome` after a reconnect
|
|
1180
|
+
* the same way they would otherwise treat a `reset` event.
|
|
1181
|
+
*
|
|
1182
|
+
* @public
|
|
1183
|
+
*/
|
|
1184
|
+
export type WelcomeBackEvent = {
|
|
1185
|
+
type: 'welcomeback'
|
|
1186
|
+
listenerName: string
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
/**
|
|
1190
|
+
* The listener can't be resumed or otherwise need to reset its local state
|
|
1191
|
+
*
|
|
1192
|
+
* If resumability is unavailable, even listeners created with `enableResume: true` may still
|
|
1193
|
+
* emit `welcome` when reconnected. Subscribers should therefore treat `welcome` after a reconnect
|
|
1194
|
+
* the same way they would otherwise treat a `reset` event.
|
|
1195
|
+
*
|
|
1196
|
+
* @public
|
|
1197
|
+
*/
|
|
1198
|
+
export type ResetEvent = {
|
|
1199
|
+
type: 'reset'
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1164
1202
|
/** @public */
|
|
1165
|
-
export type ListenEvent<R extends Record<string, Any>> =
|
|
1203
|
+
export type ListenEvent<R extends Record<string, Any> = Record<string, Any>> =
|
|
1166
1204
|
| MutationEvent<R>
|
|
1167
1205
|
| ReconnectEvent
|
|
1206
|
+
| WelcomeBackEvent
|
|
1207
|
+
| ResetEvent
|
|
1168
1208
|
| WelcomeEvent
|
|
1169
1209
|
| OpenEvent
|
|
1170
1210
|
|
|
@@ -1182,6 +1222,14 @@ export type ListenEventName =
|
|
|
1182
1222
|
*/
|
|
1183
1223
|
| 'open'
|
|
1184
1224
|
|
|
1225
|
+
/** @public */
|
|
1226
|
+
export type ResumableListenEventNames =
|
|
1227
|
+
| ListenEventName
|
|
1228
|
+
/** The listener has reconnected and successfully resumed from where it left off */
|
|
1229
|
+
| 'welcomeback'
|
|
1230
|
+
/** The listener can't be resumed or otherwise need to reset its local state */
|
|
1231
|
+
| 'reset'
|
|
1232
|
+
|
|
1185
1233
|
/** @public */
|
|
1186
1234
|
export type ListenParams = {[key: string]: Any}
|
|
1187
1235
|
|
|
@@ -1233,7 +1281,7 @@ export interface ListenOptions {
|
|
|
1233
1281
|
|
|
1234
1282
|
/**
|
|
1235
1283
|
* Array of event names to include in the observable. By default, only mutation events are included.
|
|
1236
|
-
*
|
|
1284
|
+
* Note: `welcomeback` and `reset` events requires `enableResume: true`
|
|
1237
1285
|
* @defaultValue `['mutation']`
|
|
1238
1286
|
*/
|
|
1239
1287
|
events?: ListenEventName[]
|
|
@@ -1255,6 +1303,32 @@ export interface ListenOptions {
|
|
|
1255
1303
|
* @defaultValue `undefined`
|
|
1256
1304
|
*/
|
|
1257
1305
|
tag?: string
|
|
1306
|
+
|
|
1307
|
+
/**
|
|
1308
|
+
* If this is enabled, the client will normally resume events upon reconnect
|
|
1309
|
+
* 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.
|
|
1310
|
+
* @beta
|
|
1311
|
+
* @defaultValue `false`
|
|
1312
|
+
*/
|
|
1313
|
+
enableResume?: boolean
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
/** @public */
|
|
1317
|
+
export interface ResumableListenOptions extends Omit<ListenOptions, 'events' | 'enableResume'> {
|
|
1318
|
+
/**
|
|
1319
|
+
* If this is enabled, the client will normally resume events upon reconnect
|
|
1320
|
+
* Note that you should also subscribe to `reset`-events and handle the case where the backend is unable to resume
|
|
1321
|
+
* @beta
|
|
1322
|
+
* @defaultValue `false`
|
|
1323
|
+
*/
|
|
1324
|
+
enableResume: true
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* Array of event names to include in the observable. By default, only mutation events are included.
|
|
1328
|
+
*
|
|
1329
|
+
* @defaultValue `['mutation']`
|
|
1330
|
+
*/
|
|
1331
|
+
events?: ResumableListenEventNames[]
|
|
1258
1332
|
}
|
|
1259
1333
|
|
|
1260
1334
|
/** @public */
|