@sanity/client 6.2.0-fetch.6 → 6.2.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 +7 -9
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +7 -9
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +8 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +93 -93
- package/dist/index.js +8 -10
- package/dist/index.js.map +1 -1
- package/package.json +23 -19
- package/src/SanityClient.ts +83 -83
- package/src/assets/AssetsClient.ts +13 -13
- package/src/config.ts +3 -4
- package/src/data/dataMethods.ts +20 -21
- package/src/data/listen.ts +3 -3
- package/src/data/patch.ts +11 -11
- package/src/data/transaction.ts +13 -13
- package/src/datasets/DatasetsClient.ts +4 -4
- package/src/http/request.ts +1 -1
- package/src/http/requestOptions.ts +1 -1
- package/src/index.browser.ts +1 -1
- package/src/index.ts +1 -1
- package/src/projects/ProjectsClient.ts +2 -2
- package/src/users/UsersClient.ts +4 -4
- package/src/validators.ts +2 -2
- package/src/warnings.ts +1 -1
- package/umd/sanityClient.js +51 -20
- package/umd/sanityClient.min.js +3 -3
|
@@ -34,7 +34,7 @@ export class ObservableAssetsClient {
|
|
|
34
34
|
upload(
|
|
35
35
|
assetType: 'file',
|
|
36
36
|
body: UploadBody,
|
|
37
|
-
options?: UploadClientConfig
|
|
37
|
+
options?: UploadClientConfig,
|
|
38
38
|
): Observable<HttpRequestEvent<{document: SanityAssetDocument}>>
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -47,7 +47,7 @@ export class ObservableAssetsClient {
|
|
|
47
47
|
upload(
|
|
48
48
|
assetType: 'image',
|
|
49
49
|
body: UploadBody,
|
|
50
|
-
options?: UploadClientConfig
|
|
50
|
+
options?: UploadClientConfig,
|
|
51
51
|
): Observable<HttpRequestEvent<{document: SanityImageAssetDocument}>>
|
|
52
52
|
/**
|
|
53
53
|
* Uploads a file or an image asset to the configured dataset
|
|
@@ -59,12 +59,12 @@ export class ObservableAssetsClient {
|
|
|
59
59
|
upload(
|
|
60
60
|
assetType: 'file' | 'image',
|
|
61
61
|
body: UploadBody,
|
|
62
|
-
options?: UploadClientConfig
|
|
62
|
+
options?: UploadClientConfig,
|
|
63
63
|
): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>>
|
|
64
64
|
upload(
|
|
65
65
|
assetType: 'file' | 'image',
|
|
66
66
|
body: UploadBody,
|
|
67
|
-
options?: UploadClientConfig
|
|
67
|
+
options?: UploadClientConfig,
|
|
68
68
|
): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>> {
|
|
69
69
|
return _upload(this.#client, this.#httpRequest, assetType, body, options)
|
|
70
70
|
}
|
|
@@ -89,7 +89,7 @@ export class AssetsClient {
|
|
|
89
89
|
upload(
|
|
90
90
|
assetType: 'file',
|
|
91
91
|
body: UploadBody,
|
|
92
|
-
options?: UploadClientConfig
|
|
92
|
+
options?: UploadClientConfig,
|
|
93
93
|
): Promise<SanityAssetDocument>
|
|
94
94
|
/**
|
|
95
95
|
* Uploads an image asset to the configured dataset
|
|
@@ -101,7 +101,7 @@ export class AssetsClient {
|
|
|
101
101
|
upload(
|
|
102
102
|
assetType: 'image',
|
|
103
103
|
body: UploadBody,
|
|
104
|
-
options?: UploadClientConfig
|
|
104
|
+
options?: UploadClientConfig,
|
|
105
105
|
): Promise<SanityImageAssetDocument>
|
|
106
106
|
/**
|
|
107
107
|
* Uploads a file or an image asset to the configured dataset
|
|
@@ -113,12 +113,12 @@ export class AssetsClient {
|
|
|
113
113
|
upload(
|
|
114
114
|
assetType: 'file' | 'image',
|
|
115
115
|
body: UploadBody,
|
|
116
|
-
options?: UploadClientConfig
|
|
116
|
+
options?: UploadClientConfig,
|
|
117
117
|
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
118
118
|
upload(
|
|
119
119
|
assetType: 'file' | 'image',
|
|
120
120
|
body: UploadBody,
|
|
121
|
-
options?: UploadClientConfig
|
|
121
|
+
options?: UploadClientConfig,
|
|
122
122
|
): Promise<SanityAssetDocument | SanityImageAssetDocument> {
|
|
123
123
|
const observable = _upload(this.#client, this.#httpRequest, assetType, body, options)
|
|
124
124
|
return lastValueFrom(
|
|
@@ -127,9 +127,9 @@ export class AssetsClient {
|
|
|
127
127
|
map(
|
|
128
128
|
(event) =>
|
|
129
129
|
(event as ResponseEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>)
|
|
130
|
-
.body.document
|
|
131
|
-
)
|
|
132
|
-
)
|
|
130
|
+
.body.document,
|
|
131
|
+
),
|
|
132
|
+
),
|
|
133
133
|
)
|
|
134
134
|
}
|
|
135
135
|
}
|
|
@@ -139,7 +139,7 @@ function _upload(
|
|
|
139
139
|
httpRequest: HttpRequest,
|
|
140
140
|
assetType: 'image' | 'file',
|
|
141
141
|
body: UploadBody,
|
|
142
|
-
opts: UploadClientConfig = {}
|
|
142
|
+
opts: UploadClientConfig = {},
|
|
143
143
|
): Observable<HttpRequestEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>> {
|
|
144
144
|
validators.validateAssetType(assetType)
|
|
145
145
|
|
|
@@ -187,6 +187,6 @@ function optionsFromFile(opts: Record<string, Any>, file: Any) {
|
|
|
187
187
|
filename: opts.preserveFilename === false ? undefined : file.name,
|
|
188
188
|
contentType: file.type,
|
|
189
189
|
},
|
|
190
|
-
opts
|
|
190
|
+
opts,
|
|
191
191
|
)
|
|
192
192
|
}
|
package/src/config.ts
CHANGED
|
@@ -35,14 +35,14 @@ export const validateApiPerspective = function validateApiPerspective(perspectiv
|
|
|
35
35
|
return
|
|
36
36
|
default:
|
|
37
37
|
throw new TypeError(
|
|
38
|
-
'Invalid API perspective string, expected `published`, `previewDrafts` or `raw`'
|
|
38
|
+
'Invalid API perspective string, expected `published`, `previewDrafts` or `raw`',
|
|
39
39
|
)
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export const initConfig = (
|
|
44
44
|
config: Partial<ClientConfig>,
|
|
45
|
-
prevConfig: Partial<ClientConfig
|
|
45
|
+
prevConfig: Partial<ClientConfig>,
|
|
46
46
|
): InitializedClientConfig => {
|
|
47
47
|
const specifiedConfig = Object.assign({}, prevConfig, config)
|
|
48
48
|
if (!specifiedConfig.apiVersion) {
|
|
@@ -72,7 +72,7 @@ export const initConfig = (
|
|
|
72
72
|
'logger' in newConfig
|
|
73
73
|
) {
|
|
74
74
|
throw new Error(
|
|
75
|
-
`It looks like you're using options meant for '@sanity/preview-kit/client', such as 'encodeSourceMapAtPath', 'encodeSourceMap', 'studioUrl' and 'logger'. Make sure you're using the right import
|
|
75
|
+
`It looks like you're using options meant for '@sanity/preview-kit/client', such as 'encodeSourceMapAtPath', 'encodeSourceMap', 'studioUrl' and 'logger'. Make sure you're using the right import.`,
|
|
76
76
|
)
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -86,7 +86,6 @@ export const initConfig = (
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
if (projectBased) {
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- the nullability here is wrong, as line 48 throws an error if it's undefined
|
|
90
89
|
validate.projectId(newConfig.projectId!)
|
|
91
90
|
}
|
|
92
91
|
|
package/src/data/dataMethods.ts
CHANGED
|
@@ -65,7 +65,7 @@ export function _fetch<R, Q extends QueryParams>(
|
|
|
65
65
|
httpRequest: HttpRequest,
|
|
66
66
|
query: string,
|
|
67
67
|
params?: Q,
|
|
68
|
-
options: FilteredResponseQueryOptions | UnfilteredResponseQueryOptions = {}
|
|
68
|
+
options: FilteredResponseQueryOptions | UnfilteredResponseQueryOptions = {},
|
|
69
69
|
): Observable<RawQueryResponse<R> | R> {
|
|
70
70
|
const mapResponse =
|
|
71
71
|
options.filterResponse === false ? (res: Any) => res : (res: Any) => res.result
|
|
@@ -83,12 +83,12 @@ export function _getDocument<R extends Record<string, Any>>(
|
|
|
83
83
|
client: ObservableSanityClient | SanityClient,
|
|
84
84
|
httpRequest: HttpRequest,
|
|
85
85
|
id: string,
|
|
86
|
-
opts: {tag?: string} = {}
|
|
86
|
+
opts: {tag?: string} = {},
|
|
87
87
|
): Observable<SanityDocument<R> | undefined> {
|
|
88
88
|
const options = {uri: _getDataUrl(client, 'doc', id), json: true, tag: opts.tag}
|
|
89
89
|
return _requestObservable<SanityDocument<R> | undefined>(client, httpRequest, options).pipe(
|
|
90
90
|
filter(isResponse),
|
|
91
|
-
map((event) => event.body.documents && event.body.documents[0])
|
|
91
|
+
map((event) => event.body.documents && event.body.documents[0]),
|
|
92
92
|
)
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -97,7 +97,7 @@ export function _getDocuments<R extends Record<string, Any>>(
|
|
|
97
97
|
client: ObservableSanityClient | SanityClient,
|
|
98
98
|
httpRequest: HttpRequest,
|
|
99
99
|
ids: string[],
|
|
100
|
-
opts: {tag?: string} = {}
|
|
100
|
+
opts: {tag?: string} = {},
|
|
101
101
|
): Observable<(SanityDocument<R> | null)[]> {
|
|
102
102
|
const options = {uri: _getDataUrl(client, 'doc', ids.join(',')), json: true, tag: opts.tag}
|
|
103
103
|
return _requestObservable<(SanityDocument<R> | null)[]>(client, httpRequest, options).pipe(
|
|
@@ -105,7 +105,7 @@ export function _getDocuments<R extends Record<string, Any>>(
|
|
|
105
105
|
map((event: Any) => {
|
|
106
106
|
const indexed = indexBy(event.body.documents || [], (doc: Any) => doc._id)
|
|
107
107
|
return ids.map((id) => indexed[id] || null)
|
|
108
|
-
})
|
|
108
|
+
}),
|
|
109
109
|
)
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -119,7 +119,7 @@ export function _createIfNotExists<R extends Record<string, Any>>(
|
|
|
119
119
|
| AllDocumentsMutationOptions
|
|
120
120
|
| BaseMutationOptions
|
|
121
121
|
| FirstDocumentIdMutationOptions
|
|
122
|
-
| FirstDocumentMutationOptions
|
|
122
|
+
| FirstDocumentMutationOptions,
|
|
123
123
|
): Observable<
|
|
124
124
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
125
125
|
> {
|
|
@@ -137,7 +137,7 @@ export function _createOrReplace<R extends Record<string, Any>>(
|
|
|
137
137
|
| AllDocumentsMutationOptions
|
|
138
138
|
| BaseMutationOptions
|
|
139
139
|
| FirstDocumentIdMutationOptions
|
|
140
|
-
| FirstDocumentMutationOptions
|
|
140
|
+
| FirstDocumentMutationOptions,
|
|
141
141
|
): Observable<
|
|
142
142
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
143
143
|
> {
|
|
@@ -155,7 +155,7 @@ export function _delete<R extends Record<string, Any>>(
|
|
|
155
155
|
| AllDocumentsMutationOptions
|
|
156
156
|
| BaseMutationOptions
|
|
157
157
|
| FirstDocumentIdMutationOptions
|
|
158
|
-
| FirstDocumentMutationOptions
|
|
158
|
+
| FirstDocumentMutationOptions,
|
|
159
159
|
): Observable<
|
|
160
160
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
161
161
|
> {
|
|
@@ -164,7 +164,7 @@ export function _delete<R extends Record<string, Any>>(
|
|
|
164
164
|
httpRequest,
|
|
165
165
|
'mutate',
|
|
166
166
|
{mutations: [{delete: getSelection(selection)}]},
|
|
167
|
-
options
|
|
167
|
+
options,
|
|
168
168
|
)
|
|
169
169
|
}
|
|
170
170
|
|
|
@@ -178,7 +178,7 @@ export function _mutate<R extends Record<string, Any>>(
|
|
|
178
178
|
| AllDocumentsMutationOptions
|
|
179
179
|
| BaseMutationOptions
|
|
180
180
|
| FirstDocumentIdMutationOptions
|
|
181
|
-
| FirstDocumentMutationOptions
|
|
181
|
+
| FirstDocumentMutationOptions,
|
|
182
182
|
): Observable<
|
|
183
183
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
184
184
|
> {
|
|
@@ -204,7 +204,7 @@ export function _dataRequest(
|
|
|
204
204
|
httpRequest: HttpRequest,
|
|
205
205
|
endpoint: string,
|
|
206
206
|
body: Any,
|
|
207
|
-
options: Any = {}
|
|
207
|
+
options: Any = {},
|
|
208
208
|
): Any {
|
|
209
209
|
const isMutation = endpoint === 'mutate'
|
|
210
210
|
const isQuery = endpoint === 'query'
|
|
@@ -258,7 +258,7 @@ export function _dataRequest(
|
|
|
258
258
|
results: results,
|
|
259
259
|
[key]: ids,
|
|
260
260
|
}
|
|
261
|
-
})
|
|
261
|
+
}),
|
|
262
262
|
)
|
|
263
263
|
}
|
|
264
264
|
|
|
@@ -270,7 +270,7 @@ export function _create<R extends Record<string, Any>>(
|
|
|
270
270
|
httpRequest: HttpRequest,
|
|
271
271
|
doc: Any,
|
|
272
272
|
op: Any,
|
|
273
|
-
options: Any = {}
|
|
273
|
+
options: Any = {},
|
|
274
274
|
): Observable<
|
|
275
275
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
276
276
|
> {
|
|
@@ -285,7 +285,7 @@ export function _create<R extends Record<string, Any>>(
|
|
|
285
285
|
export function _requestObservable<R>(
|
|
286
286
|
client: SanityClient | ObservableSanityClient,
|
|
287
287
|
httpRequest: HttpRequest,
|
|
288
|
-
options: RequestObservableOptions
|
|
288
|
+
options: RequestObservableOptions,
|
|
289
289
|
): Observable<HttpRequestEvent<R>> {
|
|
290
290
|
const uri = options.url || (options.uri as string)
|
|
291
291
|
const config = client.config()
|
|
@@ -325,12 +325,11 @@ export function _requestObservable<R>(
|
|
|
325
325
|
config,
|
|
326
326
|
Object.assign({}, options, {
|
|
327
327
|
url: _getUrl(client, uri, useCdn),
|
|
328
|
-
})
|
|
328
|
+
}),
|
|
329
329
|
) as RequestOptions
|
|
330
330
|
|
|
331
331
|
const request = new Observable<HttpRequestEvent<R>>((subscriber) =>
|
|
332
|
-
|
|
333
|
-
httpRequest(reqOptions, config.requester!).subscribe(subscriber)
|
|
332
|
+
httpRequest(reqOptions, config.requester!).subscribe(subscriber),
|
|
334
333
|
)
|
|
335
334
|
|
|
336
335
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request
|
|
@@ -342,11 +341,11 @@ export function _requestObservable<R>(
|
|
|
342
341
|
export function _request<R>(
|
|
343
342
|
client: SanityClient | ObservableSanityClient,
|
|
344
343
|
httpRequest: HttpRequest,
|
|
345
|
-
options: Any
|
|
344
|
+
options: Any,
|
|
346
345
|
): Observable<R> {
|
|
347
346
|
const observable = _requestObservable<R>(client, httpRequest, options).pipe(
|
|
348
347
|
filter((event: Any) => event.type === 'response'),
|
|
349
|
-
map((event: Any) => event.body)
|
|
348
|
+
map((event: Any) => event.body),
|
|
350
349
|
)
|
|
351
350
|
|
|
352
351
|
return observable
|
|
@@ -358,7 +357,7 @@ export function _request<R>(
|
|
|
358
357
|
export function _getDataUrl(
|
|
359
358
|
client: SanityClient | ObservableSanityClient,
|
|
360
359
|
operation: string,
|
|
361
|
-
path?: string
|
|
360
|
+
path?: string,
|
|
362
361
|
): string {
|
|
363
362
|
const config = client.config()
|
|
364
363
|
const catalog = validators.hasDataset(config)
|
|
@@ -373,7 +372,7 @@ export function _getDataUrl(
|
|
|
373
372
|
export function _getUrl(
|
|
374
373
|
client: SanityClient | ObservableSanityClient,
|
|
375
374
|
uri: string,
|
|
376
|
-
canUseCdn = false
|
|
375
|
+
canUseCdn = false,
|
|
377
376
|
): string {
|
|
378
377
|
const {url, cdnUrl} = client.config()
|
|
379
378
|
const base = canUseCdn ? cdnUrl : url
|
package/src/data/listen.ts
CHANGED
|
@@ -35,7 +35,7 @@ const defaultOptions = {
|
|
|
35
35
|
export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
36
36
|
this: SanityClient | ObservableSanityClient,
|
|
37
37
|
query: string,
|
|
38
|
-
params?: QueryParams
|
|
38
|
+
params?: QueryParams,
|
|
39
39
|
): Observable<MutationEvent<R>>
|
|
40
40
|
/**
|
|
41
41
|
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
@@ -49,14 +49,14 @@ export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
|
49
49
|
this: SanityClient | ObservableSanityClient,
|
|
50
50
|
query: string,
|
|
51
51
|
params?: QueryParams,
|
|
52
|
-
options?: ListenOptions
|
|
52
|
+
options?: ListenOptions,
|
|
53
53
|
): Observable<ListenEvent<R>>
|
|
54
54
|
/** @internal */
|
|
55
55
|
export function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
56
56
|
this: SanityClient | ObservableSanityClient,
|
|
57
57
|
query: string,
|
|
58
58
|
params?: QueryParams,
|
|
59
|
-
opts: ListenOptions = {}
|
|
59
|
+
opts: ListenOptions = {},
|
|
60
60
|
): Observable<MutationEvent<R> | ListenEvent<R>> {
|
|
61
61
|
const {url, token, withCredentials, requestTagPrefix} = this.config()
|
|
62
62
|
const tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join('.') : opts.tag
|
package/src/data/patch.ts
CHANGED
|
@@ -198,7 +198,7 @@ export class ObservablePatch extends BasePatch {
|
|
|
198
198
|
constructor(
|
|
199
199
|
selection: PatchSelection,
|
|
200
200
|
operations?: PatchOperations,
|
|
201
|
-
client?: ObservableSanityClient
|
|
201
|
+
client?: ObservableSanityClient,
|
|
202
202
|
) {
|
|
203
203
|
super(selection, operations)
|
|
204
204
|
this.#client = client
|
|
@@ -217,7 +217,7 @@ export class ObservablePatch extends BasePatch {
|
|
|
217
217
|
* @param options - Options for the mutation operation
|
|
218
218
|
*/
|
|
219
219
|
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
220
|
-
options: FirstDocumentMutationOptions
|
|
220
|
+
options: FirstDocumentMutationOptions,
|
|
221
221
|
): Observable<SanityDocument<R>>
|
|
222
222
|
/**
|
|
223
223
|
* Commit the patch, returning an observable that produces an array of the mutated documents
|
|
@@ -225,7 +225,7 @@ export class ObservablePatch extends BasePatch {
|
|
|
225
225
|
* @param options - Options for the mutation operation
|
|
226
226
|
*/
|
|
227
227
|
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
228
|
-
options: AllDocumentsMutationOptions
|
|
228
|
+
options: AllDocumentsMutationOptions,
|
|
229
229
|
): Observable<SanityDocument<R>[]>
|
|
230
230
|
/**
|
|
231
231
|
* Commit the patch, returning an observable that produces a mutation result object
|
|
@@ -245,7 +245,7 @@ export class ObservablePatch extends BasePatch {
|
|
|
245
245
|
* @param options - Options for the mutation operation
|
|
246
246
|
*/
|
|
247
247
|
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
248
|
-
options?: BaseMutationOptions
|
|
248
|
+
options?: BaseMutationOptions,
|
|
249
249
|
): Observable<SanityDocument<R>>
|
|
250
250
|
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
251
251
|
options?:
|
|
@@ -253,14 +253,14 @@ export class ObservablePatch extends BasePatch {
|
|
|
253
253
|
| AllDocumentsMutationOptions
|
|
254
254
|
| FirstDocumentIdMutationOptions
|
|
255
255
|
| AllDocumentIdsMutationOptions
|
|
256
|
-
| BaseMutationOptions
|
|
256
|
+
| BaseMutationOptions,
|
|
257
257
|
): Observable<
|
|
258
258
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
259
259
|
> {
|
|
260
260
|
if (!this.#client) {
|
|
261
261
|
throw new Error(
|
|
262
262
|
'No `client` passed to patch, either provide one or pass the ' +
|
|
263
|
-
'patch to a clients `mutate()` method'
|
|
263
|
+
'patch to a clients `mutate()` method',
|
|
264
264
|
)
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -291,7 +291,7 @@ export class Patch extends BasePatch {
|
|
|
291
291
|
* @param options - Options for the mutation operation
|
|
292
292
|
*/
|
|
293
293
|
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
294
|
-
options: FirstDocumentMutationOptions
|
|
294
|
+
options: FirstDocumentMutationOptions,
|
|
295
295
|
): Promise<SanityDocument<R>>
|
|
296
296
|
/**
|
|
297
297
|
* Commit the patch, returning a promise that resolves to an array of the mutated documents
|
|
@@ -299,7 +299,7 @@ export class Patch extends BasePatch {
|
|
|
299
299
|
* @param options - Options for the mutation operation
|
|
300
300
|
*/
|
|
301
301
|
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
302
|
-
options: AllDocumentsMutationOptions
|
|
302
|
+
options: AllDocumentsMutationOptions,
|
|
303
303
|
): Promise<SanityDocument<R>[]>
|
|
304
304
|
/**
|
|
305
305
|
* Commit the patch, returning a promise that resolves to a mutation result object
|
|
@@ -319,7 +319,7 @@ export class Patch extends BasePatch {
|
|
|
319
319
|
* @param options - Options for the mutation operation
|
|
320
320
|
*/
|
|
321
321
|
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
322
|
-
options?: BaseMutationOptions
|
|
322
|
+
options?: BaseMutationOptions,
|
|
323
323
|
): Promise<SanityDocument<R>>
|
|
324
324
|
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
325
325
|
options?:
|
|
@@ -327,14 +327,14 @@ export class Patch extends BasePatch {
|
|
|
327
327
|
| AllDocumentsMutationOptions
|
|
328
328
|
| FirstDocumentIdMutationOptions
|
|
329
329
|
| AllDocumentIdsMutationOptions
|
|
330
|
-
| BaseMutationOptions
|
|
330
|
+
| BaseMutationOptions,
|
|
331
331
|
): Promise<
|
|
332
332
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
333
333
|
> {
|
|
334
334
|
if (!this.#client) {
|
|
335
335
|
throw new Error(
|
|
336
336
|
'No `client` passed to patch, either provide one or pass the ' +
|
|
337
|
-
'patch to a clients `mutate()` method'
|
|
337
|
+
'patch to a clients `mutate()` method',
|
|
338
338
|
)
|
|
339
339
|
}
|
|
340
340
|
|
package/src/data/transaction.ts
CHANGED
|
@@ -52,7 +52,7 @@ export class BaseTransaction {
|
|
|
52
52
|
* @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
|
|
53
53
|
*/
|
|
54
54
|
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
55
|
-
doc: IdentifiedSanityDocumentStub<R
|
|
55
|
+
doc: IdentifiedSanityDocumentStub<R>,
|
|
56
56
|
): this {
|
|
57
57
|
const op = 'createIfNotExists'
|
|
58
58
|
validators.validateObject(op, doc)
|
|
@@ -67,7 +67,7 @@ export class BaseTransaction {
|
|
|
67
67
|
* @param doc - Document to create or replace. Requires `_id` and `_type` properties.
|
|
68
68
|
*/
|
|
69
69
|
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
70
|
-
doc: IdentifiedSanityDocumentStub<R
|
|
70
|
+
doc: IdentifiedSanityDocumentStub<R>,
|
|
71
71
|
): this {
|
|
72
72
|
const op = 'createOrReplace'
|
|
73
73
|
validators.validateObject(op, doc)
|
|
@@ -154,7 +154,7 @@ export class Transaction extends BaseTransaction {
|
|
|
154
154
|
* @param options - Options for the mutation operation
|
|
155
155
|
*/
|
|
156
156
|
commit<R extends Record<string, Any>>(
|
|
157
|
-
options: TransactionFirstDocumentMutationOptions
|
|
157
|
+
options: TransactionFirstDocumentMutationOptions,
|
|
158
158
|
): Promise<SanityDocument<R>>
|
|
159
159
|
/**
|
|
160
160
|
* Commit the transaction, returning a promise that resolves to an array of the mutated documents
|
|
@@ -162,7 +162,7 @@ export class Transaction extends BaseTransaction {
|
|
|
162
162
|
* @param options - Options for the mutation operation
|
|
163
163
|
*/
|
|
164
164
|
commit<R extends Record<string, Any>>(
|
|
165
|
-
options: TransactionAllDocumentsMutationOptions
|
|
165
|
+
options: TransactionAllDocumentsMutationOptions,
|
|
166
166
|
): Promise<SanityDocument<R>[]>
|
|
167
167
|
/**
|
|
168
168
|
* Commit the transaction, returning a promise that resolves to a mutation result object
|
|
@@ -188,20 +188,20 @@ export class Transaction extends BaseTransaction {
|
|
|
188
188
|
| TransactionAllDocumentsMutationOptions
|
|
189
189
|
| TransactionFirstDocumentIdMutationOptions
|
|
190
190
|
| TransactionAllDocumentIdsMutationOptions
|
|
191
|
-
| BaseMutationOptions
|
|
191
|
+
| BaseMutationOptions,
|
|
192
192
|
): Promise<
|
|
193
193
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
194
194
|
> {
|
|
195
195
|
if (!this.#client) {
|
|
196
196
|
throw new Error(
|
|
197
197
|
'No `client` passed to transaction, either provide one or pass the ' +
|
|
198
|
-
'transaction to a clients `mutate()` method'
|
|
198
|
+
'transaction to a clients `mutate()` method',
|
|
199
199
|
)
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
return this.#client.mutate<R>(
|
|
203
203
|
this.serialize() as Any,
|
|
204
|
-
Object.assign({transactionId: this.trxId}, defaultMutateOptions, options || {})
|
|
204
|
+
Object.assign({transactionId: this.trxId}, defaultMutateOptions, options || {}),
|
|
205
205
|
)
|
|
206
206
|
}
|
|
207
207
|
|
|
@@ -264,7 +264,7 @@ export class ObservableTransaction extends BaseTransaction {
|
|
|
264
264
|
* @param options - Options for the mutation operation
|
|
265
265
|
*/
|
|
266
266
|
commit<R extends Record<string, Any>>(
|
|
267
|
-
options: TransactionFirstDocumentMutationOptions
|
|
267
|
+
options: TransactionFirstDocumentMutationOptions,
|
|
268
268
|
): Observable<SanityDocument<R>>
|
|
269
269
|
/**
|
|
270
270
|
* Commit the transaction, returning an observable that produces an array of the mutated documents
|
|
@@ -272,7 +272,7 @@ export class ObservableTransaction extends BaseTransaction {
|
|
|
272
272
|
* @param options - Options for the mutation operation
|
|
273
273
|
*/
|
|
274
274
|
commit<R extends Record<string, Any>>(
|
|
275
|
-
options: TransactionAllDocumentsMutationOptions
|
|
275
|
+
options: TransactionAllDocumentsMutationOptions,
|
|
276
276
|
): Observable<SanityDocument<R>[]>
|
|
277
277
|
/**
|
|
278
278
|
* Commit the transaction, returning an observable that produces a mutation result object
|
|
@@ -298,20 +298,20 @@ export class ObservableTransaction extends BaseTransaction {
|
|
|
298
298
|
| TransactionAllDocumentsMutationOptions
|
|
299
299
|
| TransactionFirstDocumentIdMutationOptions
|
|
300
300
|
| TransactionAllDocumentIdsMutationOptions
|
|
301
|
-
| BaseMutationOptions
|
|
301
|
+
| BaseMutationOptions,
|
|
302
302
|
): Observable<
|
|
303
303
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
304
304
|
> {
|
|
305
305
|
if (!this.#client) {
|
|
306
306
|
throw new Error(
|
|
307
307
|
'No `client` passed to transaction, either provide one or pass the ' +
|
|
308
|
-
'transaction to a clients `mutate()` method'
|
|
308
|
+
'transaction to a clients `mutate()` method',
|
|
309
309
|
)
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
return this.#client.mutate<R>(
|
|
313
313
|
this.serialize() as Any,
|
|
314
|
-
Object.assign({transactionId: this.trxId}, defaultMutateOptions, options || {})
|
|
314
|
+
Object.assign({transactionId: this.trxId}, defaultMutateOptions, options || {}),
|
|
315
315
|
)
|
|
316
316
|
}
|
|
317
317
|
|
|
@@ -332,7 +332,7 @@ export class ObservableTransaction extends BaseTransaction {
|
|
|
332
332
|
patch(patch: ObservablePatch): this
|
|
333
333
|
patch(
|
|
334
334
|
patchOrDocumentId: ObservablePatch | string,
|
|
335
|
-
patchOps?: ObservablePatchBuilder | PatchOperations
|
|
335
|
+
patchOps?: ObservablePatchBuilder | PatchOperations,
|
|
336
336
|
): this {
|
|
337
337
|
const isBuilder = typeof patchOps === 'function'
|
|
338
338
|
const isPatch =
|
|
@@ -68,7 +68,7 @@ export class DatasetsClient {
|
|
|
68
68
|
*/
|
|
69
69
|
create(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse> {
|
|
70
70
|
return lastValueFrom(
|
|
71
|
-
_modify<DatasetResponse>(this.#client, this.#httpRequest, 'PUT', name, options)
|
|
71
|
+
_modify<DatasetResponse>(this.#client, this.#httpRequest, 'PUT', name, options),
|
|
72
72
|
)
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -80,7 +80,7 @@ export class DatasetsClient {
|
|
|
80
80
|
*/
|
|
81
81
|
edit(name: string, options?: {aclMode?: DatasetAclMode}): Promise<DatasetResponse> {
|
|
82
82
|
return lastValueFrom(
|
|
83
|
-
_modify<DatasetResponse>(this.#client, this.#httpRequest, 'PATCH', name, options)
|
|
83
|
+
_modify<DatasetResponse>(this.#client, this.#httpRequest, 'PATCH', name, options),
|
|
84
84
|
)
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -98,7 +98,7 @@ export class DatasetsClient {
|
|
|
98
98
|
*/
|
|
99
99
|
list(): Promise<DatasetsResponse> {
|
|
100
100
|
return lastValueFrom(
|
|
101
|
-
_request<DatasetsResponse>(this.#client, this.#httpRequest, {uri: '/datasets'})
|
|
101
|
+
_request<DatasetsResponse>(this.#client, this.#httpRequest, {uri: '/datasets'}),
|
|
102
102
|
)
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -108,7 +108,7 @@ function _modify<R = unknown>(
|
|
|
108
108
|
httpRequest: HttpRequest,
|
|
109
109
|
method: 'DELETE' | 'PATCH' | 'PUT',
|
|
110
110
|
name: string,
|
|
111
|
-
options?: {aclMode?: DatasetAclMode}
|
|
111
|
+
options?: {aclMode?: DatasetAclMode},
|
|
112
112
|
) {
|
|
113
113
|
validate.dataset(name)
|
|
114
114
|
return _request<R>(client, httpRequest, {method, uri: `/datasets/${name}`, body: options})
|
package/src/http/request.ts
CHANGED
|
@@ -32,7 +32,7 @@ export function defineHttpRequest(
|
|
|
32
32
|
{
|
|
33
33
|
maxRetries = 5,
|
|
34
34
|
retryDelay,
|
|
35
|
-
}: {maxRetries?: number; retryDelay?: (attemptNumber: number) => number}
|
|
35
|
+
}: {maxRetries?: number; retryDelay?: (attemptNumber: number) => number},
|
|
36
36
|
): HttpRequest {
|
|
37
37
|
const request = getIt([
|
|
38
38
|
maxRetries > 0
|
|
@@ -19,7 +19,7 @@ export function requestOptions(config: Any, overrides: Any = {}): Omit<RequestOp
|
|
|
19
19
|
const withCredentials = Boolean(
|
|
20
20
|
typeof overrides.withCredentials === 'undefined'
|
|
21
21
|
? config.token || config.withCredentials
|
|
22
|
-
: overrides.withCredentials
|
|
22
|
+
: overrides.withCredentials,
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
const timeout = typeof overrides.timeout === 'undefined' ? config.timeout : overrides.timeout
|
package/src/index.browser.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -44,7 +44,7 @@ export class ProjectsClient {
|
|
|
44
44
|
*/
|
|
45
45
|
list(): Promise<SanityProject[]> {
|
|
46
46
|
return lastValueFrom(
|
|
47
|
-
_request<SanityProject[]>(this.#client, this.#httpRequest, {uri: '/projects'})
|
|
47
|
+
_request<SanityProject[]>(this.#client, this.#httpRequest, {uri: '/projects'}),
|
|
48
48
|
)
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -55,7 +55,7 @@ export class ProjectsClient {
|
|
|
55
55
|
*/
|
|
56
56
|
getById(projectId: string): Promise<SanityProject> {
|
|
57
57
|
return lastValueFrom(
|
|
58
|
-
_request<SanityProject>(this.#client, this.#httpRequest, {uri: `/projects/${projectId}`})
|
|
58
|
+
_request<SanityProject>(this.#client, this.#httpRequest, {uri: `/projects/${projectId}`}),
|
|
59
59
|
)
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/users/UsersClient.ts
CHANGED
|
@@ -19,12 +19,12 @@ export class ObservableUsersClient {
|
|
|
19
19
|
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
20
20
|
*/
|
|
21
21
|
getById<T extends 'me' | string>(
|
|
22
|
-
id: T
|
|
22
|
+
id: T,
|
|
23
23
|
): Observable<T extends 'me' ? CurrentSanityUser : SanityUser> {
|
|
24
24
|
return _request<T extends 'me' ? CurrentSanityUser : SanityUser>(
|
|
25
25
|
this.#client,
|
|
26
26
|
this.#httpRequest,
|
|
27
|
-
{uri: `/users/${id}`}
|
|
27
|
+
{uri: `/users/${id}`},
|
|
28
28
|
)
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -44,12 +44,12 @@ export class UsersClient {
|
|
|
44
44
|
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
45
45
|
*/
|
|
46
46
|
getById<T extends 'me' | string>(
|
|
47
|
-
id: T
|
|
47
|
+
id: T,
|
|
48
48
|
): Promise<T extends 'me' ? CurrentSanityUser : SanityUser> {
|
|
49
49
|
return lastValueFrom(
|
|
50
50
|
_request<T extends 'me' ? CurrentSanityUser : SanityUser>(this.#client, this.#httpRequest, {
|
|
51
51
|
uri: `/users/${id}`,
|
|
52
|
-
})
|
|
52
|
+
}),
|
|
53
53
|
)
|
|
54
54
|
}
|
|
55
55
|
}
|
package/src/validators.ts
CHANGED
|
@@ -6,7 +6,7 @@ const VALID_INSERT_LOCATIONS = ['before', 'after', 'replace']
|
|
|
6
6
|
export const dataset = (name: string) => {
|
|
7
7
|
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
|
|
8
8
|
throw new Error(
|
|
9
|
-
'Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters'
|
|
9
|
+
'Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters',
|
|
10
10
|
)
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -70,7 +70,7 @@ export const hasDataset = (config: InitializedClientConfig): string => {
|
|
|
70
70
|
export const requestTag = (tag: string) => {
|
|
71
71
|
if (typeof tag !== 'string' || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
|
|
72
72
|
throw new Error(
|
|
73
|
-
`Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long
|
|
73
|
+
`Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.`,
|
|
74
74
|
)
|
|
75
75
|
}
|
|
76
76
|
|