@sanity/client 7.12.1 → 7.13.1
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/_chunks-cjs/resolveEditInfo.cjs +11 -5
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +2 -24
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +67 -7
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/resolveEditInfo.js +11 -5
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +2 -24
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +68 -8
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/index.browser.cjs +4 -6
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +53 -5
- package/dist/index.browser.d.ts +53 -5
- package/dist/index.browser.js +4 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +5 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -5
- package/dist/index.d.ts +53 -5
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +53 -5
- package/dist/stega.browser.d.ts +53 -5
- package/dist/stega.d.cts +53 -5
- package/dist/stega.d.ts +53 -5
- package/package.json +3 -2
- package/src/csm/jsonPath.ts +26 -0
- package/src/csm/resolveMapping.ts +10 -10
- package/src/data/listen.ts +65 -15
- package/src/stega/stega.ts +163 -0
- package/src/stega/stegaEncodeSourceMap.ts +3 -4
- package/src/types.ts +5 -2
- package/umd/sanityClient.js +76 -39
- package/umd/sanityClient.min.js +2 -2
package/dist/stega.browser.d.cts
CHANGED
|
@@ -2130,22 +2130,41 @@ export declare function _listen<R extends Record<string, Any> = Record<string, A
|
|
|
2130
2130
|
* @param options - Optional listener options
|
|
2131
2131
|
* @public
|
|
2132
2132
|
*/
|
|
2133
|
-
export declare function _listen<
|
|
2133
|
+
export declare function _listen<
|
|
2134
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2135
|
+
Opts extends ListenOptions = ListenOptions,
|
|
2136
|
+
>(
|
|
2134
2137
|
this: SanityClient | ObservableSanityClient,
|
|
2135
2138
|
query: string,
|
|
2136
2139
|
params?: ListenParams,
|
|
2137
|
-
options?:
|
|
2138
|
-
): Observable<
|
|
2140
|
+
options?: Opts,
|
|
2141
|
+
): Observable<ListenEventFromOptions<R, Opts>>
|
|
2139
2142
|
|
|
2140
2143
|
/** @public */
|
|
2141
2144
|
export declare type ListenEvent<R extends Record<string, Any>> =
|
|
2142
2145
|
| MutationEvent<R>
|
|
2143
|
-
| ChannelErrorEvent
|
|
2144
|
-
| DisconnectEvent
|
|
2145
2146
|
| ReconnectEvent
|
|
2146
2147
|
| WelcomeEvent
|
|
2147
2148
|
| OpenEvent
|
|
2148
2149
|
|
|
2150
|
+
/**
|
|
2151
|
+
* Maps a ListenOptions object and returns the Listen events opted for, e.g:
|
|
2152
|
+
* ```
|
|
2153
|
+
* type Test = ListenEventFromOptions<Doc, {events: ['welcome', 'mutation']}>
|
|
2154
|
+
* // ^? WelcomeEvent | MutationEvent<Doc>
|
|
2155
|
+
* ```
|
|
2156
|
+
*
|
|
2157
|
+
* @public
|
|
2158
|
+
*/
|
|
2159
|
+
declare type ListenEventFromOptions<
|
|
2160
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2161
|
+
Opts extends ListenOptions | undefined = undefined,
|
|
2162
|
+
> = Opts extends ListenOptions
|
|
2163
|
+
? Opts['events'] extends ListenEventName[]
|
|
2164
|
+
? MapListenEventNamesToListenEvents<R, Opts['events']>
|
|
2165
|
+
: ListenEvent<R>
|
|
2166
|
+
: MutationEvent<R>
|
|
2167
|
+
|
|
2149
2168
|
/** @public */
|
|
2150
2169
|
export declare type ListenEventName =
|
|
2151
2170
|
/** A mutation was performed */
|
|
@@ -2154,6 +2173,11 @@ export declare type ListenEventName =
|
|
|
2154
2173
|
| 'welcome'
|
|
2155
2174
|
/** The listener has been disconnected, and a reconnect attempt is scheduled */
|
|
2156
2175
|
| 'reconnect'
|
|
2176
|
+
/**
|
|
2177
|
+
* The listener connection has been established
|
|
2178
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
2179
|
+
*/
|
|
2180
|
+
| 'open'
|
|
2157
2181
|
|
|
2158
2182
|
/** @public */
|
|
2159
2183
|
export declare interface ListenOptions {
|
|
@@ -2295,6 +2319,30 @@ declare type Logger_2 =
|
|
|
2295
2319
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
2296
2320
|
>
|
|
2297
2321
|
|
|
2322
|
+
/**
|
|
2323
|
+
* Maps an array of listen events names to their corresponding listen event type, e.g:
|
|
2324
|
+
* ```
|
|
2325
|
+
* type Test = MapListenEventNamesToListenEvents<Doc, ['welcome']>
|
|
2326
|
+
* // ^? WelcomeEvent
|
|
2327
|
+
* ```
|
|
2328
|
+
*
|
|
2329
|
+
* @public
|
|
2330
|
+
*/
|
|
2331
|
+
declare type MapListenEventNamesToListenEvents<
|
|
2332
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2333
|
+
Events extends ListenEventName[] = ListenEventName[],
|
|
2334
|
+
> = Events extends (infer E)[]
|
|
2335
|
+
? E extends 'welcome'
|
|
2336
|
+
? WelcomeEvent
|
|
2337
|
+
: E extends 'mutation'
|
|
2338
|
+
? MutationEvent<R>
|
|
2339
|
+
: E extends 'reconnect'
|
|
2340
|
+
? ReconnectEvent
|
|
2341
|
+
: E extends 'open'
|
|
2342
|
+
? OpenEvent
|
|
2343
|
+
: never
|
|
2344
|
+
: never
|
|
2345
|
+
|
|
2298
2346
|
/** @public */
|
|
2299
2347
|
export declare type MediaLibraryAssetInstanceIdentifier = string | SanityReference
|
|
2300
2348
|
|
package/dist/stega.browser.d.ts
CHANGED
|
@@ -2130,22 +2130,41 @@ export declare function _listen<R extends Record<string, Any> = Record<string, A
|
|
|
2130
2130
|
* @param options - Optional listener options
|
|
2131
2131
|
* @public
|
|
2132
2132
|
*/
|
|
2133
|
-
export declare function _listen<
|
|
2133
|
+
export declare function _listen<
|
|
2134
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2135
|
+
Opts extends ListenOptions = ListenOptions,
|
|
2136
|
+
>(
|
|
2134
2137
|
this: SanityClient | ObservableSanityClient,
|
|
2135
2138
|
query: string,
|
|
2136
2139
|
params?: ListenParams,
|
|
2137
|
-
options?:
|
|
2138
|
-
): Observable<
|
|
2140
|
+
options?: Opts,
|
|
2141
|
+
): Observable<ListenEventFromOptions<R, Opts>>
|
|
2139
2142
|
|
|
2140
2143
|
/** @public */
|
|
2141
2144
|
export declare type ListenEvent<R extends Record<string, Any>> =
|
|
2142
2145
|
| MutationEvent<R>
|
|
2143
|
-
| ChannelErrorEvent
|
|
2144
|
-
| DisconnectEvent
|
|
2145
2146
|
| ReconnectEvent
|
|
2146
2147
|
| WelcomeEvent
|
|
2147
2148
|
| OpenEvent
|
|
2148
2149
|
|
|
2150
|
+
/**
|
|
2151
|
+
* Maps a ListenOptions object and returns the Listen events opted for, e.g:
|
|
2152
|
+
* ```
|
|
2153
|
+
* type Test = ListenEventFromOptions<Doc, {events: ['welcome', 'mutation']}>
|
|
2154
|
+
* // ^? WelcomeEvent | MutationEvent<Doc>
|
|
2155
|
+
* ```
|
|
2156
|
+
*
|
|
2157
|
+
* @public
|
|
2158
|
+
*/
|
|
2159
|
+
declare type ListenEventFromOptions<
|
|
2160
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2161
|
+
Opts extends ListenOptions | undefined = undefined,
|
|
2162
|
+
> = Opts extends ListenOptions
|
|
2163
|
+
? Opts['events'] extends ListenEventName[]
|
|
2164
|
+
? MapListenEventNamesToListenEvents<R, Opts['events']>
|
|
2165
|
+
: ListenEvent<R>
|
|
2166
|
+
: MutationEvent<R>
|
|
2167
|
+
|
|
2149
2168
|
/** @public */
|
|
2150
2169
|
export declare type ListenEventName =
|
|
2151
2170
|
/** A mutation was performed */
|
|
@@ -2154,6 +2173,11 @@ export declare type ListenEventName =
|
|
|
2154
2173
|
| 'welcome'
|
|
2155
2174
|
/** The listener has been disconnected, and a reconnect attempt is scheduled */
|
|
2156
2175
|
| 'reconnect'
|
|
2176
|
+
/**
|
|
2177
|
+
* The listener connection has been established
|
|
2178
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
2179
|
+
*/
|
|
2180
|
+
| 'open'
|
|
2157
2181
|
|
|
2158
2182
|
/** @public */
|
|
2159
2183
|
export declare interface ListenOptions {
|
|
@@ -2295,6 +2319,30 @@ declare type Logger_2 =
|
|
|
2295
2319
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
2296
2320
|
>
|
|
2297
2321
|
|
|
2322
|
+
/**
|
|
2323
|
+
* Maps an array of listen events names to their corresponding listen event type, e.g:
|
|
2324
|
+
* ```
|
|
2325
|
+
* type Test = MapListenEventNamesToListenEvents<Doc, ['welcome']>
|
|
2326
|
+
* // ^? WelcomeEvent
|
|
2327
|
+
* ```
|
|
2328
|
+
*
|
|
2329
|
+
* @public
|
|
2330
|
+
*/
|
|
2331
|
+
declare type MapListenEventNamesToListenEvents<
|
|
2332
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2333
|
+
Events extends ListenEventName[] = ListenEventName[],
|
|
2334
|
+
> = Events extends (infer E)[]
|
|
2335
|
+
? E extends 'welcome'
|
|
2336
|
+
? WelcomeEvent
|
|
2337
|
+
: E extends 'mutation'
|
|
2338
|
+
? MutationEvent<R>
|
|
2339
|
+
: E extends 'reconnect'
|
|
2340
|
+
? ReconnectEvent
|
|
2341
|
+
: E extends 'open'
|
|
2342
|
+
? OpenEvent
|
|
2343
|
+
: never
|
|
2344
|
+
: never
|
|
2345
|
+
|
|
2298
2346
|
/** @public */
|
|
2299
2347
|
export declare type MediaLibraryAssetInstanceIdentifier = string | SanityReference
|
|
2300
2348
|
|
package/dist/stega.d.cts
CHANGED
|
@@ -2130,22 +2130,41 @@ export declare function _listen<R extends Record<string, Any> = Record<string, A
|
|
|
2130
2130
|
* @param options - Optional listener options
|
|
2131
2131
|
* @public
|
|
2132
2132
|
*/
|
|
2133
|
-
export declare function _listen<
|
|
2133
|
+
export declare function _listen<
|
|
2134
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2135
|
+
Opts extends ListenOptions = ListenOptions,
|
|
2136
|
+
>(
|
|
2134
2137
|
this: SanityClient | ObservableSanityClient,
|
|
2135
2138
|
query: string,
|
|
2136
2139
|
params?: ListenParams,
|
|
2137
|
-
options?:
|
|
2138
|
-
): Observable<
|
|
2140
|
+
options?: Opts,
|
|
2141
|
+
): Observable<ListenEventFromOptions<R, Opts>>
|
|
2139
2142
|
|
|
2140
2143
|
/** @public */
|
|
2141
2144
|
export declare type ListenEvent<R extends Record<string, Any>> =
|
|
2142
2145
|
| MutationEvent<R>
|
|
2143
|
-
| ChannelErrorEvent
|
|
2144
|
-
| DisconnectEvent
|
|
2145
2146
|
| ReconnectEvent
|
|
2146
2147
|
| WelcomeEvent
|
|
2147
2148
|
| OpenEvent
|
|
2148
2149
|
|
|
2150
|
+
/**
|
|
2151
|
+
* Maps a ListenOptions object and returns the Listen events opted for, e.g:
|
|
2152
|
+
* ```
|
|
2153
|
+
* type Test = ListenEventFromOptions<Doc, {events: ['welcome', 'mutation']}>
|
|
2154
|
+
* // ^? WelcomeEvent | MutationEvent<Doc>
|
|
2155
|
+
* ```
|
|
2156
|
+
*
|
|
2157
|
+
* @public
|
|
2158
|
+
*/
|
|
2159
|
+
declare type ListenEventFromOptions<
|
|
2160
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2161
|
+
Opts extends ListenOptions | undefined = undefined,
|
|
2162
|
+
> = Opts extends ListenOptions
|
|
2163
|
+
? Opts['events'] extends ListenEventName[]
|
|
2164
|
+
? MapListenEventNamesToListenEvents<R, Opts['events']>
|
|
2165
|
+
: ListenEvent<R>
|
|
2166
|
+
: MutationEvent<R>
|
|
2167
|
+
|
|
2149
2168
|
/** @public */
|
|
2150
2169
|
export declare type ListenEventName =
|
|
2151
2170
|
/** A mutation was performed */
|
|
@@ -2154,6 +2173,11 @@ export declare type ListenEventName =
|
|
|
2154
2173
|
| 'welcome'
|
|
2155
2174
|
/** The listener has been disconnected, and a reconnect attempt is scheduled */
|
|
2156
2175
|
| 'reconnect'
|
|
2176
|
+
/**
|
|
2177
|
+
* The listener connection has been established
|
|
2178
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
2179
|
+
*/
|
|
2180
|
+
| 'open'
|
|
2157
2181
|
|
|
2158
2182
|
/** @public */
|
|
2159
2183
|
export declare interface ListenOptions {
|
|
@@ -2295,6 +2319,30 @@ declare type Logger_2 =
|
|
|
2295
2319
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
2296
2320
|
>
|
|
2297
2321
|
|
|
2322
|
+
/**
|
|
2323
|
+
* Maps an array of listen events names to their corresponding listen event type, e.g:
|
|
2324
|
+
* ```
|
|
2325
|
+
* type Test = MapListenEventNamesToListenEvents<Doc, ['welcome']>
|
|
2326
|
+
* // ^? WelcomeEvent
|
|
2327
|
+
* ```
|
|
2328
|
+
*
|
|
2329
|
+
* @public
|
|
2330
|
+
*/
|
|
2331
|
+
declare type MapListenEventNamesToListenEvents<
|
|
2332
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2333
|
+
Events extends ListenEventName[] = ListenEventName[],
|
|
2334
|
+
> = Events extends (infer E)[]
|
|
2335
|
+
? E extends 'welcome'
|
|
2336
|
+
? WelcomeEvent
|
|
2337
|
+
: E extends 'mutation'
|
|
2338
|
+
? MutationEvent<R>
|
|
2339
|
+
: E extends 'reconnect'
|
|
2340
|
+
? ReconnectEvent
|
|
2341
|
+
: E extends 'open'
|
|
2342
|
+
? OpenEvent
|
|
2343
|
+
: never
|
|
2344
|
+
: never
|
|
2345
|
+
|
|
2298
2346
|
/** @public */
|
|
2299
2347
|
export declare type MediaLibraryAssetInstanceIdentifier = string | SanityReference
|
|
2300
2348
|
|
package/dist/stega.d.ts
CHANGED
|
@@ -2130,22 +2130,41 @@ export declare function _listen<R extends Record<string, Any> = Record<string, A
|
|
|
2130
2130
|
* @param options - Optional listener options
|
|
2131
2131
|
* @public
|
|
2132
2132
|
*/
|
|
2133
|
-
export declare function _listen<
|
|
2133
|
+
export declare function _listen<
|
|
2134
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2135
|
+
Opts extends ListenOptions = ListenOptions,
|
|
2136
|
+
>(
|
|
2134
2137
|
this: SanityClient | ObservableSanityClient,
|
|
2135
2138
|
query: string,
|
|
2136
2139
|
params?: ListenParams,
|
|
2137
|
-
options?:
|
|
2138
|
-
): Observable<
|
|
2140
|
+
options?: Opts,
|
|
2141
|
+
): Observable<ListenEventFromOptions<R, Opts>>
|
|
2139
2142
|
|
|
2140
2143
|
/** @public */
|
|
2141
2144
|
export declare type ListenEvent<R extends Record<string, Any>> =
|
|
2142
2145
|
| MutationEvent<R>
|
|
2143
|
-
| ChannelErrorEvent
|
|
2144
|
-
| DisconnectEvent
|
|
2145
2146
|
| ReconnectEvent
|
|
2146
2147
|
| WelcomeEvent
|
|
2147
2148
|
| OpenEvent
|
|
2148
2149
|
|
|
2150
|
+
/**
|
|
2151
|
+
* Maps a ListenOptions object and returns the Listen events opted for, e.g:
|
|
2152
|
+
* ```
|
|
2153
|
+
* type Test = ListenEventFromOptions<Doc, {events: ['welcome', 'mutation']}>
|
|
2154
|
+
* // ^? WelcomeEvent | MutationEvent<Doc>
|
|
2155
|
+
* ```
|
|
2156
|
+
*
|
|
2157
|
+
* @public
|
|
2158
|
+
*/
|
|
2159
|
+
declare type ListenEventFromOptions<
|
|
2160
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2161
|
+
Opts extends ListenOptions | undefined = undefined,
|
|
2162
|
+
> = Opts extends ListenOptions
|
|
2163
|
+
? Opts['events'] extends ListenEventName[]
|
|
2164
|
+
? MapListenEventNamesToListenEvents<R, Opts['events']>
|
|
2165
|
+
: ListenEvent<R>
|
|
2166
|
+
: MutationEvent<R>
|
|
2167
|
+
|
|
2149
2168
|
/** @public */
|
|
2150
2169
|
export declare type ListenEventName =
|
|
2151
2170
|
/** A mutation was performed */
|
|
@@ -2154,6 +2173,11 @@ export declare type ListenEventName =
|
|
|
2154
2173
|
| 'welcome'
|
|
2155
2174
|
/** The listener has been disconnected, and a reconnect attempt is scheduled */
|
|
2156
2175
|
| 'reconnect'
|
|
2176
|
+
/**
|
|
2177
|
+
* The listener connection has been established
|
|
2178
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
2179
|
+
*/
|
|
2180
|
+
| 'open'
|
|
2157
2181
|
|
|
2158
2182
|
/** @public */
|
|
2159
2183
|
export declare interface ListenOptions {
|
|
@@ -2295,6 +2319,30 @@ declare type Logger_2 =
|
|
|
2295
2319
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
2296
2320
|
>
|
|
2297
2321
|
|
|
2322
|
+
/**
|
|
2323
|
+
* Maps an array of listen events names to their corresponding listen event type, e.g:
|
|
2324
|
+
* ```
|
|
2325
|
+
* type Test = MapListenEventNamesToListenEvents<Doc, ['welcome']>
|
|
2326
|
+
* // ^? WelcomeEvent
|
|
2327
|
+
* ```
|
|
2328
|
+
*
|
|
2329
|
+
* @public
|
|
2330
|
+
*/
|
|
2331
|
+
declare type MapListenEventNamesToListenEvents<
|
|
2332
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
2333
|
+
Events extends ListenEventName[] = ListenEventName[],
|
|
2334
|
+
> = Events extends (infer E)[]
|
|
2335
|
+
? E extends 'welcome'
|
|
2336
|
+
? WelcomeEvent
|
|
2337
|
+
: E extends 'mutation'
|
|
2338
|
+
? MutationEvent<R>
|
|
2339
|
+
: E extends 'reconnect'
|
|
2340
|
+
? ReconnectEvent
|
|
2341
|
+
: E extends 'open'
|
|
2342
|
+
? OpenEvent
|
|
2343
|
+
: never
|
|
2344
|
+
: never
|
|
2345
|
+
|
|
2298
2346
|
/** @public */
|
|
2299
2347
|
export declare type MediaLibraryAssetInstanceIdentifier = string | SanityReference
|
|
2300
2348
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.13.1",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+
|
|
21
|
+
"url": "git+https://github.com/sanity-io/client.git"
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"author": "Sanity.io <hello@sanity.io>",
|
|
@@ -163,6 +163,7 @@
|
|
|
163
163
|
"msw": "^2.7.3",
|
|
164
164
|
"next": "^15.3.0",
|
|
165
165
|
"nock": "^13.5.6",
|
|
166
|
+
"pkg-pr-new": "^0.0.60",
|
|
166
167
|
"prettier": "^3.5.3",
|
|
167
168
|
"prettier-plugin-packagejson": "^2.5.10",
|
|
168
169
|
"rimraf": "^5.0.7",
|
package/src/csm/jsonPath.ts
CHANGED
|
@@ -52,6 +52,32 @@ export function jsonPath(path: ContentSourceMapParsedPath): ContentSourceMapPath
|
|
|
52
52
|
})
|
|
53
53
|
.join('')}`
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export function jsonPathArray(path: ContentSourceMapParsedPath): string[] {
|
|
59
|
+
return path.map((segment) => {
|
|
60
|
+
if (typeof segment === 'string') {
|
|
61
|
+
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, (match) => {
|
|
62
|
+
return ESCAPE[match]
|
|
63
|
+
})
|
|
64
|
+
return `['${escapedKey}']`
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof segment === 'number') {
|
|
68
|
+
return `[${segment}]`
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (segment._key !== '') {
|
|
72
|
+
const escapedKey = segment._key.replace(/['\\]/g, (match) => {
|
|
73
|
+
return ESCAPE[match]
|
|
74
|
+
})
|
|
75
|
+
return `[?(@._key=='${escapedKey}')]`
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return `[${segment._index}]`
|
|
79
|
+
})
|
|
80
|
+
}
|
|
55
81
|
|
|
56
82
|
/**
|
|
57
83
|
* @internal
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {jsonPath, jsonPathToMappingPath} from './jsonPath'
|
|
1
|
+
import {jsonPath, jsonPathArray, jsonPathToMappingPath} from './jsonPath'
|
|
2
2
|
import type {ContentSourceMap, ContentSourceMapMapping, ContentSourceMapParsedPath} from './types'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -27,15 +27,15 @@ export function resolveMapping(
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const resultMappingPathArray = jsonPathArray(jsonPathToMappingPath(resultPath))
|
|
31
|
+
for (let i = resultMappingPathArray.length - 1; i > 0; i--) {
|
|
32
|
+
const key = `$${resultMappingPathArray.slice(0, i).join('')}`
|
|
33
|
+
const mappingFound = csm.mappings[key]
|
|
34
|
+
if (mappingFound) {
|
|
35
|
+
const pathSuffix = resultMappingPath.substring(key.length)
|
|
36
|
+
return {mapping: mappingFound, matchedPath: key, pathSuffix}
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
const pathSuffix = resultMappingPath.substring(matchedPath.length)
|
|
40
|
-
return {mapping, matchedPath, pathSuffix}
|
|
40
|
+
return undefined
|
|
41
41
|
}
|
package/src/data/listen.ts
CHANGED
|
@@ -5,9 +5,13 @@ import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
|
5
5
|
import {
|
|
6
6
|
type Any,
|
|
7
7
|
type ListenEvent,
|
|
8
|
+
type ListenEventName,
|
|
8
9
|
type ListenOptions,
|
|
9
10
|
type ListenParams,
|
|
10
11
|
type MutationEvent,
|
|
12
|
+
type OpenEvent,
|
|
13
|
+
type ReconnectEvent,
|
|
14
|
+
type WelcomeEvent,
|
|
11
15
|
} from '../types'
|
|
12
16
|
import defaults from '../util/defaults'
|
|
13
17
|
import {pick} from '../util/pick'
|
|
@@ -36,6 +40,49 @@ const defaultOptions = {
|
|
|
36
40
|
includeResult: true,
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Maps an array of listen events names to their corresponding listen event type, e.g:
|
|
45
|
+
* ```
|
|
46
|
+
* type Test = MapListenEventNamesToListenEvents<Doc, ['welcome']>
|
|
47
|
+
* // ^? WelcomeEvent
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export type MapListenEventNamesToListenEvents<
|
|
53
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
54
|
+
Events extends ListenEventName[] = ListenEventName[],
|
|
55
|
+
> = Events extends (infer E)[]
|
|
56
|
+
? E extends 'welcome'
|
|
57
|
+
? WelcomeEvent
|
|
58
|
+
: E extends 'mutation'
|
|
59
|
+
? MutationEvent<R>
|
|
60
|
+
: E extends 'reconnect'
|
|
61
|
+
? ReconnectEvent
|
|
62
|
+
: E extends 'open'
|
|
63
|
+
? OpenEvent
|
|
64
|
+
: never
|
|
65
|
+
: never
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Maps a ListenOptions object and returns the Listen events opted for, e.g:
|
|
69
|
+
* ```
|
|
70
|
+
* type Test = ListenEventFromOptions<Doc, {events: ['welcome', 'mutation']}>
|
|
71
|
+
* // ^? WelcomeEvent | MutationEvent<Doc>
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export type ListenEventFromOptions<
|
|
77
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
78
|
+
Opts extends ListenOptions | undefined = undefined,
|
|
79
|
+
> = Opts extends ListenOptions
|
|
80
|
+
? Opts['events'] extends ListenEventName[]
|
|
81
|
+
? MapListenEventNamesToListenEvents<R, Opts['events']>
|
|
82
|
+
: // fall back to ListenEvent if opts events is present, but we can't infer the literal event names
|
|
83
|
+
ListenEvent<R>
|
|
84
|
+
: MutationEvent<R>
|
|
85
|
+
|
|
39
86
|
/**
|
|
40
87
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
41
88
|
*
|
|
@@ -57,19 +104,25 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
|
57
104
|
* @param options - Optional listener options
|
|
58
105
|
* @public
|
|
59
106
|
*/
|
|
60
|
-
export function _listen<
|
|
107
|
+
export function _listen<
|
|
108
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
109
|
+
Opts extends ListenOptions = ListenOptions,
|
|
110
|
+
>(
|
|
61
111
|
this: SanityClient | ObservableSanityClient,
|
|
62
112
|
query: string,
|
|
63
113
|
params?: ListenParams,
|
|
64
|
-
options?:
|
|
65
|
-
): Observable<
|
|
114
|
+
options?: Opts,
|
|
115
|
+
): Observable<ListenEventFromOptions<R, Opts>>
|
|
66
116
|
/** @public */
|
|
67
|
-
export function _listen<
|
|
117
|
+
export function _listen<
|
|
118
|
+
R extends Record<string, Any> = Record<string, Any>,
|
|
119
|
+
Opts extends ListenOptions = ListenOptions,
|
|
120
|
+
>(
|
|
68
121
|
this: SanityClient | ObservableSanityClient,
|
|
69
122
|
query: string,
|
|
70
123
|
params?: ListenParams,
|
|
71
|
-
opts:
|
|
72
|
-
): Observable<
|
|
124
|
+
opts: Opts = {} as Opts,
|
|
125
|
+
): Observable<ListenEventFromOptions<R, Opts>> {
|
|
73
126
|
const {url, token, withCredentials, requestTagPrefix, headers: configHeaders} = this.config()
|
|
74
127
|
const tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join('.') : opts.tag
|
|
75
128
|
const options = {...defaults(opts, defaultOptions), tag}
|
|
@@ -81,7 +134,7 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
|
81
134
|
return throwError(() => new Error('Query too large for listener'))
|
|
82
135
|
}
|
|
83
136
|
|
|
84
|
-
const listenFor = options.events ? options.events : ['mutation']
|
|
137
|
+
const listenFor = (options.events ? options.events : ['mutation']) satisfies Opts['events']
|
|
85
138
|
|
|
86
139
|
const esOptions: EventSourceInit & {headers?: Record<string, string>} = {}
|
|
87
140
|
if (withCredentials) {
|
|
@@ -110,12 +163,9 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
|
110
163
|
return connectEventSource(initEventSource, listenFor).pipe(
|
|
111
164
|
reconnectOnConnectionFailure(),
|
|
112
165
|
filter((event) => listenFor.includes(event.type)),
|
|
113
|
-
map(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}) as MutationEvent<R> | ListenEvent<R>,
|
|
119
|
-
),
|
|
120
|
-
)
|
|
166
|
+
map((event) => ({
|
|
167
|
+
type: event.type,
|
|
168
|
+
...('data' in event ? (event.data as object) : {}),
|
|
169
|
+
})),
|
|
170
|
+
) as Observable<ListenEventFromOptions<R, Opts>>
|
|
121
171
|
}
|