@sanity/client 6.11.3 → 6.11.4-canary.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.
Files changed (49) hide show
  1. package/README.md +85 -4
  2. package/dist/_chunks/{browserMiddleware-1MULg59S.cjs → browserMiddleware-Pe3R-Bkh.cjs} +106 -20
  3. package/dist/_chunks/browserMiddleware-Pe3R-Bkh.cjs.map +1 -0
  4. package/dist/_chunks/{browserMiddleware-heyg-fDk.js → browserMiddleware-wklv-F5c.js} +108 -22
  5. package/dist/_chunks/browserMiddleware-wklv-F5c.js.map +1 -0
  6. package/dist/_chunks/{nodeMiddleware-CHxg1-zH.cjs → nodeMiddleware-7PkLkt-m.cjs} +107 -21
  7. package/dist/_chunks/nodeMiddleware-7PkLkt-m.cjs.map +1 -0
  8. package/dist/_chunks/{nodeMiddleware-u_fUUnxa.js → nodeMiddleware-LGORMZpx.js} +109 -23
  9. package/dist/_chunks/nodeMiddleware-LGORMZpx.js.map +1 -0
  10. package/dist/_chunks/stegaEncodeSourceMap-2y-qTNKB.cjs +230 -0
  11. package/dist/_chunks/stegaEncodeSourceMap-2y-qTNKB.cjs.map +1 -0
  12. package/dist/_chunks/stegaEncodeSourceMap-9L0STMBo.js +475 -0
  13. package/dist/_chunks/stegaEncodeSourceMap-9L0STMBo.js.map +1 -0
  14. package/dist/_chunks/stegaEncodeSourceMap-gXzb3LIV.js +226 -0
  15. package/dist/_chunks/stegaEncodeSourceMap-gXzb3LIV.js.map +1 -0
  16. package/dist/_chunks/stegaEncodeSourceMap-vNYIaMiu.cjs +479 -0
  17. package/dist/_chunks/stegaEncodeSourceMap-vNYIaMiu.cjs.map +1 -0
  18. package/dist/index.browser.cjs +1 -1
  19. package/dist/index.browser.js +2 -2
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.ts +133 -0
  22. package/dist/index.js +2 -2
  23. package/dist/stega.browser.cjs +10 -700
  24. package/dist/stega.browser.cjs.map +1 -1
  25. package/dist/stega.browser.js +5 -693
  26. package/dist/stega.browser.js.map +1 -1
  27. package/dist/stega.cjs +10 -451
  28. package/dist/stega.cjs.js +3 -5
  29. package/dist/stega.cjs.map +1 -1
  30. package/dist/stega.d.ts +1302 -1455
  31. package/dist/stega.js +5 -444
  32. package/dist/stega.js.map +1 -1
  33. package/package.json +12 -7
  34. package/src/SanityClient.ts +40 -4
  35. package/src/config.ts +34 -12
  36. package/src/data/dataMethods.ts +37 -9
  37. package/src/stega/index.browser.ts +3 -6
  38. package/src/stega/index.ts +3 -6
  39. package/src/stega/shared.ts +1 -13
  40. package/src/stega/types.ts +11 -18
  41. package/src/types.ts +24 -0
  42. package/umd/sanityClient.js +1073 -20
  43. package/umd/sanityClient.min.js +4 -3
  44. package/dist/_chunks/browserMiddleware-1MULg59S.cjs.map +0 -1
  45. package/dist/_chunks/browserMiddleware-heyg-fDk.js.map +0 -1
  46. package/dist/_chunks/nodeMiddleware-CHxg1-zH.cjs.map +0 -1
  47. package/dist/_chunks/nodeMiddleware-u_fUUnxa.js.map +0 -1
  48. package/src/stega/SanityStegaClient.ts +0 -298
  49. package/src/stega/config.ts +0 -76
@@ -1,298 +0,0 @@
1
- import {Observable} from 'rxjs'
2
- import {map} from 'rxjs/operators'
3
-
4
- import {defaultConfig} from '../config'
5
- import {
6
- ObservableSanityClient as INTERNAL_DO_NOT_USE_DIRECTLY_ObservableSanityClient,
7
- SanityClient as INTERNAL_DO_NOT_USE_DIRECTLY_SanityClient,
8
- } from '../SanityClient'
9
- import type {
10
- Any,
11
- ClientConfig,
12
- FilteredResponseQueryOptions,
13
- HttpRequest,
14
- QueryParams,
15
- RawQueryResponse,
16
- UnfilteredResponseQueryOptions,
17
- } from '../types'
18
- import {
19
- defaultStegaConfig,
20
- initStegaConfig,
21
- splitConfig,
22
- splitStegaConfigFromFetchOptions,
23
- } from './config'
24
- import {stegaEncodeSourceMap} from './stegaEncodeSourceMap'
25
- import {ClientStegaConfig, InitializedClientStegaConfig, InitializedStegaConfig} from './types'
26
- import {vercelStegaCleanAll} from './vercelStegaCleanAll'
27
-
28
- /** @public */
29
- export class ObservableSanityStegaClient extends INTERNAL_DO_NOT_USE_DIRECTLY_ObservableSanityClient {
30
- /**
31
- * Private properties
32
- */
33
- #httpRequest: HttpRequest
34
- private stegaConfig: InitializedStegaConfig
35
-
36
- constructor(httpRequest: HttpRequest, config: ClientStegaConfig = defaultConfig) {
37
- const {clientConfig, stegaConfig} = splitConfig(config)
38
- super(httpRequest, clientConfig)
39
-
40
- this.#httpRequest = httpRequest
41
- this.stegaConfig = initStegaConfig(stegaConfig, defaultStegaConfig)
42
- }
43
-
44
- /**
45
- * Clone the client - returns a new instance
46
- */
47
- clone(): ObservableSanityStegaClient {
48
- return new ObservableSanityStegaClient(this.#httpRequest, this.config())
49
- }
50
-
51
- /**
52
- * Returns the current client configuration
53
- */
54
- config(): InitializedClientStegaConfig
55
- /**
56
- * Reconfigure the client. Note that this _mutates_ the current client.
57
- */
58
- config(newConfig?: Partial<ClientStegaConfig>): this
59
- config(newConfig?: Partial<ClientStegaConfig>): ClientStegaConfig | this {
60
- if (newConfig === undefined) {
61
- return {...super.config(), stega: {...this.stegaConfig}}
62
- }
63
-
64
- const {clientConfig, stegaConfig} = splitConfig(newConfig)
65
- super.config(clientConfig)
66
-
67
- this.stegaConfig = initStegaConfig(stegaConfig, this.stegaConfig || {})
68
- return this
69
- }
70
-
71
- /**
72
- * Clone the client with a new (partial) configuration.
73
- *
74
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
75
- */
76
- withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityStegaClient {
77
- const thisConfig = this.config()
78
- const {stegaConfig} = splitConfig(newConfig || {})
79
- return new ObservableSanityStegaClient(this.#httpRequest, {
80
- ...thisConfig,
81
- ...newConfig,
82
- stega: {
83
- ...(thisConfig.stega || {}),
84
- ...(stegaConfig || {}),
85
- },
86
- })
87
- }
88
-
89
- /**
90
- * Perform a GROQ-query against the configured dataset.
91
- *
92
- * @param query - GROQ-query to perform
93
- */
94
- fetch<R = Any>(query: string): Observable<R>
95
- /**
96
- * Perform a GROQ-query against the configured dataset.
97
- *
98
- * @param query - GROQ-query to perform
99
- * @param params - Query parameters
100
- */
101
- fetch<R = Any, Q = QueryParams>(query: string, params: Q): Observable<R>
102
- /**
103
- * Perform a GROQ-query against the configured dataset.
104
- *
105
- * @param query - GROQ-query to perform
106
- * @param params - Query parameters
107
- * @param options - Request options
108
- */
109
- fetch<R = Any, Q = QueryParams>(
110
- query: string,
111
- params: Q | undefined,
112
- options: FilteredResponseQueryOptions,
113
- ): Observable<R>
114
- /**
115
- * Perform a GROQ-query against the configured dataset.
116
- *
117
- * @param query - GROQ-query to perform
118
- * @param params - Query parameters
119
- * @param options - Request options
120
- */
121
- fetch<R = Any, Q = QueryParams>(
122
- query: string,
123
- params: Q | undefined,
124
- options: UnfilteredResponseQueryOptions,
125
- ): Observable<RawQueryResponse<R>>
126
- fetch<R, Q extends QueryParams>(
127
- query: string,
128
- _params?: Q,
129
- _options: FilteredResponseQueryOptions | UnfilteredResponseQueryOptions = {},
130
- ): Observable<RawQueryResponse<R> | R> {
131
- const {stegaConfig, fetchOptions: options} = splitStegaConfigFromFetchOptions(
132
- _options,
133
- this.stegaConfig,
134
- )
135
- const params = _params ? vercelStegaCleanAll(_params) : _params
136
- if (!stegaConfig.enabled) {
137
- return super.fetch<R, Q>(query, params, options as Any)
138
- }
139
- const {filterResponse: originalFilterResponse = true} = options
140
- return super
141
- .fetch<R, Q>(
142
- query,
143
- params,
144
- Object.assign({}, options as Any, {
145
- filterResponse: false,
146
- resultSourceMap: 'withKeyArraySelector',
147
- }),
148
- )
149
- .pipe(
150
- map((res: Any) => {
151
- const {result: _result, resultSourceMap} = res as RawQueryResponse<R>
152
- const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig)
153
- return originalFilterResponse ? result : {...res, result}
154
- }),
155
- )
156
- }
157
- }
158
-
159
- /** @public */
160
- export class SanityStegaClient extends INTERNAL_DO_NOT_USE_DIRECTLY_SanityClient {
161
- /**
162
- * Observable version of the Sanity client, with the same configuration as the promise-based one
163
- */
164
- observable: ObservableSanityStegaClient
165
-
166
- /**
167
- * Private properties
168
- */
169
- #httpRequest: HttpRequest
170
- private stegaConfig: InitializedStegaConfig
171
-
172
- constructor(httpRequest: HttpRequest, config: ClientStegaConfig = defaultConfig) {
173
- const {clientConfig, stegaConfig} = splitConfig(config)
174
- super(httpRequest, clientConfig)
175
-
176
- this.#httpRequest = httpRequest
177
- this.stegaConfig = initStegaConfig(stegaConfig, defaultStegaConfig)
178
-
179
- this.observable = new ObservableSanityStegaClient(httpRequest, config)
180
- }
181
-
182
- /**
183
- * Clone the client - returns a new instance
184
- */
185
- clone(): SanityStegaClient {
186
- return new SanityStegaClient(this.#httpRequest, this.config())
187
- }
188
-
189
- /**
190
- * Returns the current client configuration
191
- */
192
- config(): InitializedClientStegaConfig
193
- /**
194
- * Reconfigure the client. Note that this _mutates_ the current client.
195
- */
196
- config(newConfig?: Partial<ClientStegaConfig>): this
197
- config(newConfig?: Partial<ClientStegaConfig>): ClientStegaConfig | this {
198
- if (newConfig === undefined) {
199
- return {...super.config(), stega: {...this.stegaConfig}}
200
- }
201
-
202
- const {clientConfig, stegaConfig} = splitConfig(newConfig)
203
- super.config(clientConfig)
204
-
205
- this.stegaConfig = initStegaConfig(stegaConfig, {...(this.stegaConfig || {})})
206
- return this
207
- }
208
-
209
- /**
210
- * Clone the client with a new (partial) configuration.
211
- *
212
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
213
- */
214
- withConfig(newConfig?: Partial<ClientStegaConfig>): SanityStegaClient {
215
- const thisConfig = this.config()
216
- const {stegaConfig} = splitConfig(newConfig || {})
217
- return new SanityStegaClient(this.#httpRequest, {
218
- ...thisConfig,
219
- ...newConfig,
220
- stega: {
221
- ...(thisConfig.stega || {}),
222
- ...(stegaConfig || {}),
223
- },
224
- })
225
- }
226
-
227
- /**
228
- * Perform a GROQ-query against the configured dataset.
229
- *
230
- * @param query - GROQ-query to perform
231
- */
232
- fetch<R = Any>(query: string): Promise<R>
233
- /**
234
- * Perform a GROQ-query against the configured dataset.
235
- *
236
- * @param query - GROQ-query to perform
237
- * @param params - Optional query parameters
238
- */
239
- fetch<R = Any, Q = QueryParams>(query: string, params: Q): Promise<R>
240
- /**
241
- * Perform a GROQ-query against the configured dataset.
242
- *
243
- * @param query - GROQ-query to perform
244
- * @param params - Optional query parameters
245
- * @param options - Request options
246
- */
247
- fetch<R = Any, Q = QueryParams>(
248
- query: string,
249
- params: Q | undefined,
250
- options: FilteredResponseQueryOptions,
251
- ): Promise<R>
252
- /**
253
- * Perform a GROQ-query against the configured dataset.
254
- *
255
- * @param query - GROQ-query to perform
256
- * @param params - Optional query parameters
257
- * @param options - Request options
258
- */
259
- fetch<R = Any, Q = QueryParams>(
260
- query: string,
261
- params: Q | undefined,
262
- options: UnfilteredResponseQueryOptions,
263
- ): Promise<RawQueryResponse<R>>
264
- fetch<R, Q extends QueryParams>(
265
- query: string,
266
- _params?: Q,
267
- _options: FilteredResponseQueryOptions | UnfilteredResponseQueryOptions = {},
268
- ): Promise<RawQueryResponse<R> | R> {
269
- const {stegaConfig, fetchOptions: options} = splitStegaConfigFromFetchOptions(
270
- _options,
271
- this.stegaConfig,
272
- )
273
- const params = _params ? vercelStegaCleanAll(_params) : _params
274
- if (!stegaConfig.enabled) {
275
- return super.fetch<R, Q>(query, params, options as Any)
276
- }
277
- const {filterResponse: originalFilterResponse = true} = options
278
- return super
279
- .fetch<R, Q>(
280
- query,
281
- params,
282
- Object.assign({}, options as Any, {
283
- filterResponse: false,
284
- resultSourceMap: 'withKeyArraySelector',
285
- }),
286
- )
287
- .then((res: Any) => {
288
- const {result: _result, resultSourceMap} = res as RawQueryResponse<R>
289
- const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig)
290
- return originalFilterResponse ? result : {...res, result}
291
- })
292
- }
293
- }
294
-
295
- export type {
296
- INTERNAL_DO_NOT_USE_DIRECTLY_ObservableSanityClient,
297
- INTERNAL_DO_NOT_USE_DIRECTLY_SanityClient,
298
- }
@@ -1,76 +0,0 @@
1
- import type {
2
- ClientConfig,
3
- FilteredResponseQueryOptions,
4
- UnfilteredResponseQueryOptions,
5
- } from '../types'
6
- import type {ClientStegaConfig, InitializedStegaConfig, StegaConfig} from './types'
7
-
8
- export const defaultStegaConfig: StegaConfig = {
9
- enabled: false,
10
- filter: (props) => props.filterDefault(props),
11
- }
12
-
13
- export function splitConfig(config: ClientStegaConfig): {
14
- clientConfig: ClientConfig
15
- stegaConfig: StegaConfig
16
- } {
17
- const {stega = {}, ...clientConfig} = config
18
- return {clientConfig, stegaConfig: typeof stega === 'boolean' ? {enabled: stega} : stega}
19
- }
20
-
21
- export const initStegaConfig = (
22
- config: Partial<StegaConfig>,
23
- prevConfig: Partial<StegaConfig>,
24
- ): InitializedStegaConfig => {
25
- const specifiedConfig = Object.assign({} as StegaConfig, prevConfig, config)
26
- const newConfig = Object.assign({} as InitializedStegaConfig, defaultStegaConfig, specifiedConfig)
27
-
28
- if ('encodeSourceMap' in newConfig) {
29
- throw new Error(
30
- `It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client/stega'. Did you mean 'enabled'?`,
31
- )
32
- }
33
-
34
- if ('encodeSourceMapAtPath' in newConfig) {
35
- throw new Error(
36
- `It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client/stega'. Did you mean 'filter'?`,
37
- )
38
- }
39
-
40
- if (typeof newConfig.enabled !== 'boolean') {
41
- throw new Error(`config.enabled must be a boolean, received ${newConfig.enabled}`)
42
- }
43
-
44
- if (newConfig.enabled && newConfig.studioUrl === undefined) {
45
- throw new Error(`config.studioUrl must be defined when config.enabled is true`)
46
- }
47
-
48
- if (
49
- newConfig.enabled &&
50
- typeof newConfig.studioUrl !== 'string' &&
51
- typeof newConfig.studioUrl !== 'function'
52
- ) {
53
- throw new Error(
54
- `config.studioUrl must be a string or a function, received ${newConfig.studioUrl}`,
55
- )
56
- }
57
-
58
- return newConfig
59
- }
60
-
61
- export function splitStegaConfigFromFetchOptions(
62
- options: (FilteredResponseQueryOptions | UnfilteredResponseQueryOptions) & {
63
- stega?: boolean | StegaConfig
64
- },
65
- initializedStegaConfig: InitializedStegaConfig,
66
- ): {
67
- fetchOptions: FilteredResponseQueryOptions | UnfilteredResponseQueryOptions
68
- stegaConfig: InitializedStegaConfig
69
- } {
70
- const {stega = {}, ...fetchOptions} = options
71
- const stegaConfig = initStegaConfig(
72
- typeof stega === 'boolean' ? {enabled: stega} : stega,
73
- initializedStegaConfig,
74
- )
75
- return {fetchOptions, stegaConfig}
76
- }