@sanity/client 5.0.0-esm.7 → 5.0.0-esm.9
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/README.md +110 -57
- package/dist/index.browser.cjs +6 -4
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +6 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +7 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +127 -121
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/SanityClient.ts +84 -83
- package/src/assets/AssetsClient.ts +4 -3
- package/src/config.ts +1 -0
- package/src/data/dataMethods.ts +28 -26
- package/src/data/encodeQueryString.ts +4 -4
- package/src/data/listen.ts +9 -9
- package/src/data/patch.ts +18 -17
- package/src/data/transaction.ts +15 -12
- package/src/http/errors.ts +7 -7
- package/src/http/request.ts +4 -4
- package/src/http/requestOptions.ts +4 -2
- package/src/types.ts +36 -30
- package/src/util/defaults.ts +4 -2
- package/src/util/once.ts +5 -3
- package/src/util/pick.ts +4 -2
- package/src/validators.ts +4 -4
- package/src/warnings.ts +2 -1
- package/umd/sanityClient.js +4990 -5753
- package/umd/sanityClient.min.js +12 -12
|
@@ -4,6 +4,7 @@ import {filter, map} from 'rxjs/operators'
|
|
|
4
4
|
import {_requestObservable} from '../data/dataMethods'
|
|
5
5
|
import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
6
6
|
import type {
|
|
7
|
+
FIXME,
|
|
7
8
|
HttpRequest,
|
|
8
9
|
HttpRequestEvent,
|
|
9
10
|
ResponseEvent,
|
|
@@ -97,7 +98,7 @@ export class AssetsClient {
|
|
|
97
98
|
const observable = _upload(this.#client, this.#httpRequest, assetType, body, options)
|
|
98
99
|
return lastValueFrom(
|
|
99
100
|
observable.pipe(
|
|
100
|
-
filter((event:
|
|
101
|
+
filter((event: FIXME) => event.type === 'response'),
|
|
101
102
|
map(
|
|
102
103
|
(event) =>
|
|
103
104
|
(event as ResponseEvent<{document: SanityAssetDocument | SanityImageAssetDocument}>)
|
|
@@ -127,7 +128,7 @@ function _upload(
|
|
|
127
128
|
const assetEndpoint = assetType === 'image' ? 'images' : 'files'
|
|
128
129
|
const options = optionsFromFile(opts, body)
|
|
129
130
|
const {tag, label, title, description, creditLine, filename, source} = options
|
|
130
|
-
const query:
|
|
131
|
+
const query: FIXME = {
|
|
131
132
|
label,
|
|
132
133
|
title,
|
|
133
134
|
description,
|
|
@@ -151,7 +152,7 @@ function _upload(
|
|
|
151
152
|
})
|
|
152
153
|
}
|
|
153
154
|
|
|
154
|
-
function optionsFromFile(opts: Record<string,
|
|
155
|
+
function optionsFromFile(opts: Record<string, FIXME>, file: FIXME) {
|
|
155
156
|
if (typeof window === 'undefined' || !(file instanceof window.File)) {
|
|
156
157
|
return opts
|
|
157
158
|
}
|
package/src/config.ts
CHANGED
package/src/data/dataMethods.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
FilteredResponseQueryOptions,
|
|
11
11
|
FirstDocumentIdMutationOptions,
|
|
12
12
|
FirstDocumentMutationOptions,
|
|
13
|
+
FIXME,
|
|
13
14
|
HttpRequest,
|
|
14
15
|
HttpRequestEvent,
|
|
15
16
|
IdentifiedSanityDocumentStub,
|
|
@@ -31,7 +32,7 @@ import encodeQueryString from './encodeQueryString'
|
|
|
31
32
|
import {ObservablePatch, Patch} from './patch'
|
|
32
33
|
import {ObservableTransaction, Transaction} from './transaction'
|
|
33
34
|
|
|
34
|
-
const excludeFalsey = (param:
|
|
35
|
+
const excludeFalsey = (param: FIXME, defValue: FIXME) => {
|
|
35
36
|
const value = typeof param === 'undefined' ? defValue : param
|
|
36
37
|
return param === false ? undefined : value
|
|
37
38
|
}
|
|
@@ -47,10 +48,10 @@ const getMutationQuery = (options: BaseMutationOptions = {}) => {
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
const isResponse = (event:
|
|
51
|
-
const getBody = (event:
|
|
51
|
+
const isResponse = (event: FIXME) => event.type === 'response'
|
|
52
|
+
const getBody = (event: FIXME) => event.body
|
|
52
53
|
|
|
53
|
-
const indexBy = (docs:
|
|
54
|
+
const indexBy = (docs: FIXME[], attr: FIXME) =>
|
|
54
55
|
docs.reduce((indexed, doc) => {
|
|
55
56
|
indexed[attr(doc)] = doc
|
|
56
57
|
return indexed
|
|
@@ -67,13 +68,13 @@ export function _fetch<R>(
|
|
|
67
68
|
options: FilteredResponseQueryOptions | UnfilteredResponseQueryOptions = {}
|
|
68
69
|
): Observable<RawQueryResponse<R> | R> {
|
|
69
70
|
const mapResponse =
|
|
70
|
-
options.filterResponse === false ? (res:
|
|
71
|
+
options.filterResponse === false ? (res: FIXME) => res : (res: FIXME) => res.result
|
|
71
72
|
|
|
72
73
|
return _dataRequest(client, httpRequest, 'query', {query, params}, options).pipe(map(mapResponse))
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/** @internal */
|
|
76
|
-
export function _getDocument<R extends Record<string,
|
|
77
|
+
export function _getDocument<R extends Record<string, FIXME>>(
|
|
77
78
|
client: ObservableSanityClient | SanityClient,
|
|
78
79
|
httpRequest: HttpRequest,
|
|
79
80
|
id: string,
|
|
@@ -87,7 +88,7 @@ export function _getDocument<R extends Record<string, any>>(
|
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
/** @internal */
|
|
90
|
-
export function _getDocuments<R extends Record<string,
|
|
91
|
+
export function _getDocuments<R extends Record<string, FIXME>>(
|
|
91
92
|
client: ObservableSanityClient | SanityClient,
|
|
92
93
|
httpRequest: HttpRequest,
|
|
93
94
|
ids: string[],
|
|
@@ -96,15 +97,15 @@ export function _getDocuments<R extends Record<string, any>>(
|
|
|
96
97
|
const options = {uri: _getDataUrl(client, 'doc', ids.join(',')), json: true, tag: opts.tag}
|
|
97
98
|
return _requestObservable<(SanityDocument<R> | null)[]>(client, httpRequest, options).pipe(
|
|
98
99
|
filter(isResponse),
|
|
99
|
-
map((event:
|
|
100
|
-
const indexed = indexBy(event.body.documents || [], (doc:
|
|
100
|
+
map((event: FIXME) => {
|
|
101
|
+
const indexed = indexBy(event.body.documents || [], (doc: FIXME) => doc._id)
|
|
101
102
|
return ids.map((id) => indexed[id] || null)
|
|
102
103
|
})
|
|
103
104
|
)
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
/** @internal */
|
|
107
|
-
export function _createIfNotExists<R extends Record<string,
|
|
108
|
+
export function _createIfNotExists<R extends Record<string, FIXME>>(
|
|
108
109
|
client: ObservableSanityClient | SanityClient,
|
|
109
110
|
httpRequest: HttpRequest,
|
|
110
111
|
doc: IdentifiedSanityDocumentStub<R>,
|
|
@@ -122,7 +123,7 @@ export function _createIfNotExists<R extends Record<string, any>>(
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
/** @internal */
|
|
125
|
-
export function _createOrReplace<R extends Record<string,
|
|
126
|
+
export function _createOrReplace<R extends Record<string, FIXME>>(
|
|
126
127
|
client: ObservableSanityClient | SanityClient,
|
|
127
128
|
httpRequest: HttpRequest,
|
|
128
129
|
doc: IdentifiedSanityDocumentStub<R>,
|
|
@@ -140,7 +141,7 @@ export function _createOrReplace<R extends Record<string, any>>(
|
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
/** @internal */
|
|
143
|
-
export function _delete<R extends Record<string,
|
|
144
|
+
export function _delete<R extends Record<string, FIXME>>(
|
|
144
145
|
client: ObservableSanityClient | SanityClient,
|
|
145
146
|
httpRequest: HttpRequest,
|
|
146
147
|
selection: string | MutationSelection,
|
|
@@ -163,7 +164,7 @@ export function _delete<R extends Record<string, any>>(
|
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
/** @internal */
|
|
166
|
-
export function _mutate<R extends Record<string,
|
|
167
|
+
export function _mutate<R extends Record<string, FIXME>>(
|
|
167
168
|
client: SanityClient | ObservableSanityClient,
|
|
168
169
|
httpRequest: HttpRequest,
|
|
169
170
|
mutations: Mutation<R>[] | Patch | ObservablePatch | Transaction | ObservableTransaction,
|
|
@@ -185,7 +186,7 @@ export function _mutate<R extends Record<string, any>>(
|
|
|
185
186
|
: mutations
|
|
186
187
|
|
|
187
188
|
const muts = Array.isArray(mut) ? mut : [mut]
|
|
188
|
-
const transactionId = options && (options as
|
|
189
|
+
const transactionId = options && (options as FIXME).transactionId
|
|
189
190
|
return _dataRequest(client, httpRequest, 'mutate', {mutations: muts, transactionId}, options)
|
|
190
191
|
}
|
|
191
192
|
|
|
@@ -196,9 +197,9 @@ export function _dataRequest(
|
|
|
196
197
|
client: SanityClient | ObservableSanityClient,
|
|
197
198
|
httpRequest: HttpRequest,
|
|
198
199
|
endpoint: string,
|
|
199
|
-
body:
|
|
200
|
-
options:
|
|
201
|
-
):
|
|
200
|
+
body: FIXME,
|
|
201
|
+
options: FIXME = {}
|
|
202
|
+
): FIXME {
|
|
202
203
|
const isMutation = endpoint === 'mutate'
|
|
203
204
|
const isQuery = endpoint === 'query'
|
|
204
205
|
|
|
@@ -238,12 +239,12 @@ export function _dataRequest(
|
|
|
238
239
|
if (options.returnDocuments) {
|
|
239
240
|
return returnFirst
|
|
240
241
|
? results[0] && results[0].document
|
|
241
|
-
: results.map((mut:
|
|
242
|
+
: results.map((mut: FIXME) => mut.document)
|
|
242
243
|
}
|
|
243
244
|
|
|
244
245
|
// Return a reduced subset
|
|
245
246
|
const key = returnFirst ? 'documentId' : 'documentIds'
|
|
246
|
-
const ids = returnFirst ? results[0] && results[0].id : results.map((mut:
|
|
247
|
+
const ids = returnFirst ? results[0] && results[0].id : results.map((mut: FIXME) => mut.id)
|
|
247
248
|
return {
|
|
248
249
|
transactionId: res.transactionId,
|
|
249
250
|
results: results,
|
|
@@ -256,12 +257,12 @@ export function _dataRequest(
|
|
|
256
257
|
/**
|
|
257
258
|
* @internal
|
|
258
259
|
*/
|
|
259
|
-
export function _create<R extends Record<string,
|
|
260
|
+
export function _create<R extends Record<string, FIXME>>(
|
|
260
261
|
client: SanityClient | ObservableSanityClient,
|
|
261
262
|
httpRequest: HttpRequest,
|
|
262
|
-
doc:
|
|
263
|
-
op:
|
|
264
|
-
options:
|
|
263
|
+
doc: FIXME,
|
|
264
|
+
op: FIXME,
|
|
265
|
+
options: FIXME = {}
|
|
265
266
|
): Observable<
|
|
266
267
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
267
268
|
> {
|
|
@@ -307,6 +308,7 @@ export function _requestObservable<R>(
|
|
|
307
308
|
) as RequestOptions
|
|
308
309
|
|
|
309
310
|
return new Observable<HttpRequestEvent<R>>((subscriber) =>
|
|
311
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- the typings thinks it's optional because it's not required to specify it when calling createClient, but it's always defined in practice since SanityClient provides a default
|
|
310
312
|
httpRequest(reqOptions, config.requester!).subscribe(subscriber)
|
|
311
313
|
)
|
|
312
314
|
}
|
|
@@ -317,11 +319,11 @@ export function _requestObservable<R>(
|
|
|
317
319
|
export function _request<R>(
|
|
318
320
|
client: SanityClient | ObservableSanityClient,
|
|
319
321
|
httpRequest: HttpRequest,
|
|
320
|
-
options:
|
|
322
|
+
options: FIXME
|
|
321
323
|
): Observable<R> {
|
|
322
324
|
const observable = _requestObservable<R>(client, httpRequest, options).pipe(
|
|
323
|
-
filter((event:
|
|
324
|
-
map((event:
|
|
325
|
+
filter((event: FIXME) => event.type === 'response'),
|
|
326
|
+
map((event: FIXME) => event.body)
|
|
325
327
|
)
|
|
326
328
|
|
|
327
329
|
return observable
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type {QueryParams} from '../types'
|
|
1
|
+
import type {FIXME, QueryParams} from '../types'
|
|
2
2
|
|
|
3
3
|
const enc = encodeURIComponent
|
|
4
4
|
|
|
5
5
|
export default ({
|
|
6
6
|
query,
|
|
7
|
-
params = {} as
|
|
8
|
-
options = {} as
|
|
7
|
+
params = {} as FIXME,
|
|
8
|
+
options = {} as FIXME,
|
|
9
9
|
}: {
|
|
10
10
|
query: string
|
|
11
11
|
params?: QueryParams
|
|
12
|
-
options?:
|
|
12
|
+
options?: FIXME
|
|
13
13
|
}) => {
|
|
14
14
|
// We generally want tag at the start of the query string
|
|
15
15
|
const {tag, ...opts} = options
|
package/src/data/listen.ts
CHANGED
|
@@ -2,7 +2,7 @@ import polyfilledEventSource from '@sanity/eventsource'
|
|
|
2
2
|
import {Observable} from 'rxjs'
|
|
3
3
|
|
|
4
4
|
import type {SanityClient} from '../SanityClient'
|
|
5
|
-
import type {ListenEvent, ListenOptions, MutationEvent, QueryParams} from '../types'
|
|
5
|
+
import type {FIXME, ListenEvent, ListenOptions, MutationEvent, QueryParams} from '../types'
|
|
6
6
|
import defaults from '../util/defaults'
|
|
7
7
|
import pick from '../util/pick'
|
|
8
8
|
import {_getDataUrl} from './dataMethods'
|
|
@@ -34,7 +34,7 @@ const defaultOptions = {
|
|
|
34
34
|
* @param options - Listener options
|
|
35
35
|
* @internal
|
|
36
36
|
*/
|
|
37
|
-
export function _listen<R extends Record<string,
|
|
37
|
+
export function _listen<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
38
38
|
this: SanityClient,
|
|
39
39
|
query: string,
|
|
40
40
|
params?: QueryParams
|
|
@@ -47,14 +47,14 @@ export function _listen<R extends Record<string, any> = Record<string, any>>(
|
|
|
47
47
|
* @param options - Listener options
|
|
48
48
|
* @internal
|
|
49
49
|
*/
|
|
50
|
-
export function _listen<R extends Record<string,
|
|
50
|
+
export function _listen<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
51
51
|
this: SanityClient,
|
|
52
52
|
query: string,
|
|
53
53
|
params?: QueryParams,
|
|
54
54
|
options?: ListenOptions
|
|
55
55
|
): Observable<ListenEvent<R>>
|
|
56
56
|
/** @internal */
|
|
57
|
-
export function _listen<R extends Record<string,
|
|
57
|
+
export function _listen<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
58
58
|
this: SanityClient,
|
|
59
59
|
query: string,
|
|
60
60
|
params?: QueryParams,
|
|
@@ -114,11 +114,11 @@ export function _listen<R extends Record<string, any> = Record<string, any>>(
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
function onChannelError(err:
|
|
117
|
+
function onChannelError(err: FIXME) {
|
|
118
118
|
observer.error(cooerceError(err))
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
function onMessage(evt:
|
|
121
|
+
function onMessage(evt: FIXME) {
|
|
122
122
|
const event = parseEvent(evt)
|
|
123
123
|
return event instanceof Error ? observer.error(event) : observer.next(event)
|
|
124
124
|
}
|
|
@@ -165,7 +165,7 @@ export function _listen<R extends Record<string, any> = Record<string, any>>(
|
|
|
165
165
|
})
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
function parseEvent(event:
|
|
168
|
+
function parseEvent(event: FIXME) {
|
|
169
169
|
try {
|
|
170
170
|
const data = (event.data && JSON.parse(event.data)) || {}
|
|
171
171
|
return Object.assign({type: event.type}, data)
|
|
@@ -174,7 +174,7 @@ function parseEvent(event: any) {
|
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
function cooerceError(err:
|
|
177
|
+
function cooerceError(err: FIXME) {
|
|
178
178
|
if (err instanceof Error) {
|
|
179
179
|
return err
|
|
180
180
|
}
|
|
@@ -183,7 +183,7 @@ function cooerceError(err: any) {
|
|
|
183
183
|
return evt instanceof Error ? evt : new Error(extractErrorMessage(evt))
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
function extractErrorMessage(err:
|
|
186
|
+
function extractErrorMessage(err: FIXME) {
|
|
187
187
|
if (!err.error) {
|
|
188
188
|
return err.message || 'Unknown listener error'
|
|
189
189
|
}
|
package/src/data/patch.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
BaseMutationOptions,
|
|
9
9
|
FirstDocumentIdMutationOptions,
|
|
10
10
|
FirstDocumentMutationOptions,
|
|
11
|
+
FIXME,
|
|
11
12
|
MultipleMutationResult,
|
|
12
13
|
PatchMutationOperation,
|
|
13
14
|
PatchOperations,
|
|
@@ -110,7 +111,7 @@ export class BasePatch {
|
|
|
110
111
|
* @param selector - JSONPath expression, eg `comments[-1]` or `blocks[_key=="abc123"]`
|
|
111
112
|
* @param items - Array of items to insert/replace
|
|
112
113
|
*/
|
|
113
|
-
insert(at: 'before' | 'after' | 'replace', selector: string, items:
|
|
114
|
+
insert(at: 'before' | 'after' | 'replace', selector: string, items: FIXME[]): this {
|
|
114
115
|
validateInsert(at, selector, items)
|
|
115
116
|
return this._assign('insert', {[at]: selector, items})
|
|
116
117
|
}
|
|
@@ -121,7 +122,7 @@ export class BasePatch {
|
|
|
121
122
|
* @param selector - Attribute/path to append to, eg `comments` or `person.hobbies`
|
|
122
123
|
* @param items - Array of items to append to the array
|
|
123
124
|
*/
|
|
124
|
-
append(selector: string, items:
|
|
125
|
+
append(selector: string, items: FIXME[]): this {
|
|
125
126
|
return this.insert('after', `${selector}[-1]`, items)
|
|
126
127
|
}
|
|
127
128
|
|
|
@@ -131,7 +132,7 @@ export class BasePatch {
|
|
|
131
132
|
* @param selector - Attribute/path to prepend to, eg `comments` or `person.hobbies`
|
|
132
133
|
* @param items - Array of items to prepend to the array
|
|
133
134
|
*/
|
|
134
|
-
prepend(selector: string, items:
|
|
135
|
+
prepend(selector: string, items: FIXME[]): this {
|
|
135
136
|
return this.insert('before', `${selector}[0]`, items)
|
|
136
137
|
}
|
|
137
138
|
|
|
@@ -141,9 +142,9 @@ export class BasePatch {
|
|
|
141
142
|
* @param selector - Attribute or JSONPath expression for array
|
|
142
143
|
* @param start - Index at which to start changing the array (with origin 0). If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end of the array (with origin -1) and will be set to 0 if absolute value is greater than the length of the array.x
|
|
143
144
|
* @param deleteCount - An integer indicating the number of old array elements to remove.
|
|
144
|
-
* @param items - The elements to add to the array, beginning at the start index. If you don't specify
|
|
145
|
+
* @param items - The elements to add to the array, beginning at the start index. If you don't specify FIXME elements, splice() will only remove elements from the array.
|
|
145
146
|
*/
|
|
146
|
-
splice(selector: string, start: number, deleteCount?: number, items?:
|
|
147
|
+
splice(selector: string, start: number, deleteCount?: number, items?: FIXME[]): this {
|
|
147
148
|
// Negative indexes doesn't mean the same in Sanity as they do in JS;
|
|
148
149
|
// -1 means "actually at the end of the array", which allows inserting
|
|
149
150
|
// at the end of the array without knowing its length. We therefore have
|
|
@@ -189,7 +190,7 @@ export class BasePatch {
|
|
|
189
190
|
return this
|
|
190
191
|
}
|
|
191
192
|
|
|
192
|
-
protected _assign(op: keyof PatchOperations, props:
|
|
193
|
+
protected _assign(op: keyof PatchOperations, props: FIXME, merge = true): this {
|
|
193
194
|
validateObject(op, props)
|
|
194
195
|
this.operations = Object.assign({}, this.operations, {
|
|
195
196
|
[op]: Object.assign({}, (merge && this.operations[op]) || {}, props),
|
|
@@ -197,7 +198,7 @@ export class BasePatch {
|
|
|
197
198
|
return this
|
|
198
199
|
}
|
|
199
200
|
|
|
200
|
-
protected _set(op: keyof PatchOperations, props:
|
|
201
|
+
protected _set(op: keyof PatchOperations, props: FIXME): this {
|
|
201
202
|
return this._assign(op, props, false)
|
|
202
203
|
}
|
|
203
204
|
}
|
|
@@ -227,7 +228,7 @@ export class ObservablePatch extends BasePatch {
|
|
|
227
228
|
*
|
|
228
229
|
* @param options - Options for the mutation operation
|
|
229
230
|
*/
|
|
230
|
-
commit<R extends Record<string,
|
|
231
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
231
232
|
options: FirstDocumentMutationOptions
|
|
232
233
|
): Observable<SanityDocument<R>>
|
|
233
234
|
/**
|
|
@@ -235,7 +236,7 @@ export class ObservablePatch extends BasePatch {
|
|
|
235
236
|
*
|
|
236
237
|
* @param options - Options for the mutation operation
|
|
237
238
|
*/
|
|
238
|
-
commit<R extends Record<string,
|
|
239
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
239
240
|
options: AllDocumentsMutationOptions
|
|
240
241
|
): Observable<SanityDocument<R>[]>
|
|
241
242
|
/**
|
|
@@ -255,10 +256,10 @@ export class ObservablePatch extends BasePatch {
|
|
|
255
256
|
*
|
|
256
257
|
* @param options - Options for the mutation operation
|
|
257
258
|
*/
|
|
258
|
-
commit<R extends Record<string,
|
|
259
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
259
260
|
options?: BaseMutationOptions
|
|
260
261
|
): Observable<SanityDocument<R>>
|
|
261
|
-
commit<R extends Record<string,
|
|
262
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
262
263
|
options?:
|
|
263
264
|
| FirstDocumentMutationOptions
|
|
264
265
|
| AllDocumentsMutationOptions
|
|
@@ -277,7 +278,7 @@ export class ObservablePatch extends BasePatch {
|
|
|
277
278
|
|
|
278
279
|
const returnFirst = typeof this.selection === 'string'
|
|
279
280
|
const opts = Object.assign({returnFirst, returnDocuments: true}, options)
|
|
280
|
-
return this.#client.mutate<R>({patch: this.serialize()} as
|
|
281
|
+
return this.#client.mutate<R>({patch: this.serialize()} as FIXME, opts)
|
|
281
282
|
}
|
|
282
283
|
}
|
|
283
284
|
|
|
@@ -301,7 +302,7 @@ export class Patch extends BasePatch {
|
|
|
301
302
|
*
|
|
302
303
|
* @param options - Options for the mutation operation
|
|
303
304
|
*/
|
|
304
|
-
commit<R extends Record<string,
|
|
305
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
305
306
|
options: FirstDocumentMutationOptions
|
|
306
307
|
): Promise<SanityDocument<R>>
|
|
307
308
|
/**
|
|
@@ -309,7 +310,7 @@ export class Patch extends BasePatch {
|
|
|
309
310
|
*
|
|
310
311
|
* @param options - Options for the mutation operation
|
|
311
312
|
*/
|
|
312
|
-
commit<R extends Record<string,
|
|
313
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
313
314
|
options: AllDocumentsMutationOptions
|
|
314
315
|
): Promise<SanityDocument<R>[]>
|
|
315
316
|
/**
|
|
@@ -329,10 +330,10 @@ export class Patch extends BasePatch {
|
|
|
329
330
|
*
|
|
330
331
|
* @param options - Options for the mutation operation
|
|
331
332
|
*/
|
|
332
|
-
commit<R extends Record<string,
|
|
333
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
333
334
|
options?: BaseMutationOptions
|
|
334
335
|
): Promise<SanityDocument<R>>
|
|
335
|
-
commit<R extends Record<string,
|
|
336
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
336
337
|
options?:
|
|
337
338
|
| FirstDocumentMutationOptions
|
|
338
339
|
| AllDocumentsMutationOptions
|
|
@@ -351,6 +352,6 @@ export class Patch extends BasePatch {
|
|
|
351
352
|
|
|
352
353
|
const returnFirst = typeof this.selection === 'string'
|
|
353
354
|
const opts = Object.assign({returnFirst, returnDocuments: true}, options)
|
|
354
|
-
return this.#client.mutate<R>({patch: this.serialize()} as
|
|
355
|
+
return this.#client.mutate<R>({patch: this.serialize()} as FIXME, opts)
|
|
355
356
|
}
|
|
356
357
|
}
|
package/src/data/transaction.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {Observable} from 'rxjs'
|
|
|
3
3
|
import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
4
4
|
import type {
|
|
5
5
|
BaseMutationOptions,
|
|
6
|
+
FIXME,
|
|
6
7
|
IdentifiedSanityDocumentStub,
|
|
7
8
|
MultipleMutationResult,
|
|
8
9
|
Mutation,
|
|
@@ -39,7 +40,9 @@ export class BaseTransaction {
|
|
|
39
40
|
*
|
|
40
41
|
* @param doc - Document to create. Requires a `_type` property.
|
|
41
42
|
*/
|
|
42
|
-
create<R extends Record<string,
|
|
43
|
+
create<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
44
|
+
doc: SanityDocumentStub<R>
|
|
45
|
+
): this {
|
|
43
46
|
validators.validateObject('create', doc)
|
|
44
47
|
return this._add({create: doc})
|
|
45
48
|
}
|
|
@@ -50,7 +53,7 @@ export class BaseTransaction {
|
|
|
50
53
|
*
|
|
51
54
|
* @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
|
|
52
55
|
*/
|
|
53
|
-
createIfNotExists<R extends Record<string,
|
|
56
|
+
createIfNotExists<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
54
57
|
doc: IdentifiedSanityDocumentStub<R>
|
|
55
58
|
): this {
|
|
56
59
|
const op = 'createIfNotExists'
|
|
@@ -65,7 +68,7 @@ export class BaseTransaction {
|
|
|
65
68
|
*
|
|
66
69
|
* @param doc - Document to create or replace. Requires `_id` and `_type` properties.
|
|
67
70
|
*/
|
|
68
|
-
createOrReplace<R extends Record<string,
|
|
71
|
+
createOrReplace<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
69
72
|
doc: IdentifiedSanityDocumentStub<R>
|
|
70
73
|
): this {
|
|
71
74
|
const op = 'createOrReplace'
|
|
@@ -86,7 +89,7 @@ export class BaseTransaction {
|
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
/**
|
|
89
|
-
* Gets the current transaction ID, if
|
|
92
|
+
* Gets the current transaction ID, if FIXME
|
|
90
93
|
*/
|
|
91
94
|
transactionId(): string | undefined
|
|
92
95
|
/**
|
|
@@ -152,7 +155,7 @@ export class Transaction extends BaseTransaction {
|
|
|
152
155
|
*
|
|
153
156
|
* @param options - Options for the mutation operation
|
|
154
157
|
*/
|
|
155
|
-
commit<R extends Record<string,
|
|
158
|
+
commit<R extends Record<string, FIXME>>(
|
|
156
159
|
options: TransactionFirstDocumentMutationOptions
|
|
157
160
|
): Promise<SanityDocument<R>>
|
|
158
161
|
/**
|
|
@@ -160,7 +163,7 @@ export class Transaction extends BaseTransaction {
|
|
|
160
163
|
*
|
|
161
164
|
* @param options - Options for the mutation operation
|
|
162
165
|
*/
|
|
163
|
-
commit<R extends Record<string,
|
|
166
|
+
commit<R extends Record<string, FIXME>>(
|
|
164
167
|
options: TransactionAllDocumentsMutationOptions
|
|
165
168
|
): Promise<SanityDocument<R>[]>
|
|
166
169
|
/**
|
|
@@ -181,7 +184,7 @@ export class Transaction extends BaseTransaction {
|
|
|
181
184
|
* @param options - Options for the mutation operation
|
|
182
185
|
*/
|
|
183
186
|
commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
|
|
184
|
-
commit<R extends Record<string,
|
|
187
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
185
188
|
options?:
|
|
186
189
|
| TransactionFirstDocumentMutationOptions
|
|
187
190
|
| TransactionAllDocumentsMutationOptions
|
|
@@ -199,7 +202,7 @@ export class Transaction extends BaseTransaction {
|
|
|
199
202
|
}
|
|
200
203
|
|
|
201
204
|
return this.#client.mutate<R>(
|
|
202
|
-
this.serialize() as
|
|
205
|
+
this.serialize() as FIXME,
|
|
203
206
|
Object.assign({transactionId: this.trxId}, defaultMutateOptions, options || {})
|
|
204
207
|
)
|
|
205
208
|
}
|
|
@@ -262,7 +265,7 @@ export class ObservableTransaction extends BaseTransaction {
|
|
|
262
265
|
*
|
|
263
266
|
* @param options - Options for the mutation operation
|
|
264
267
|
*/
|
|
265
|
-
commit<R extends Record<string,
|
|
268
|
+
commit<R extends Record<string, FIXME>>(
|
|
266
269
|
options: TransactionFirstDocumentMutationOptions
|
|
267
270
|
): Observable<SanityDocument<R>>
|
|
268
271
|
/**
|
|
@@ -270,7 +273,7 @@ export class ObservableTransaction extends BaseTransaction {
|
|
|
270
273
|
*
|
|
271
274
|
* @param options - Options for the mutation operation
|
|
272
275
|
*/
|
|
273
|
-
commit<R extends Record<string,
|
|
276
|
+
commit<R extends Record<string, FIXME>>(
|
|
274
277
|
options: TransactionAllDocumentsMutationOptions
|
|
275
278
|
): Observable<SanityDocument<R>[]>
|
|
276
279
|
/**
|
|
@@ -291,7 +294,7 @@ export class ObservableTransaction extends BaseTransaction {
|
|
|
291
294
|
* @param options - Options for the mutation operation
|
|
292
295
|
*/
|
|
293
296
|
commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
|
|
294
|
-
commit<R extends Record<string,
|
|
297
|
+
commit<R extends Record<string, FIXME> = Record<string, FIXME>>(
|
|
295
298
|
options?:
|
|
296
299
|
| TransactionFirstDocumentMutationOptions
|
|
297
300
|
| TransactionAllDocumentsMutationOptions
|
|
@@ -309,7 +312,7 @@ export class ObservableTransaction extends BaseTransaction {
|
|
|
309
312
|
}
|
|
310
313
|
|
|
311
314
|
return this.#client.mutate<R>(
|
|
312
|
-
this.serialize() as
|
|
315
|
+
this.serialize() as FIXME,
|
|
313
316
|
Object.assign({transactionId: this.trxId}, defaultMutateOptions, options || {})
|
|
314
317
|
)
|
|
315
318
|
}
|
package/src/http/errors.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {BaseError} from 'make-error'
|
|
2
2
|
|
|
3
|
-
import {ErrorProps} from '../types'
|
|
3
|
+
import {ErrorProps, FIXME} from '../types'
|
|
4
4
|
|
|
5
5
|
/** @public */
|
|
6
6
|
export class ClientError extends BaseError {
|
|
@@ -9,7 +9,7 @@ export class ClientError extends BaseError {
|
|
|
9
9
|
responseBody: ErrorProps['responseBody']
|
|
10
10
|
details: ErrorProps['details']
|
|
11
11
|
|
|
12
|
-
constructor(res:
|
|
12
|
+
constructor(res: FIXME) {
|
|
13
13
|
const props = extractErrorProps(res)
|
|
14
14
|
super(props.message)
|
|
15
15
|
Object.assign(this, props)
|
|
@@ -23,21 +23,21 @@ export class ServerError extends BaseError {
|
|
|
23
23
|
responseBody: ErrorProps['responseBody']
|
|
24
24
|
details: ErrorProps['details']
|
|
25
25
|
|
|
26
|
-
constructor(res:
|
|
26
|
+
constructor(res: FIXME) {
|
|
27
27
|
const props = extractErrorProps(res)
|
|
28
28
|
super(props.message)
|
|
29
29
|
Object.assign(this, props)
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function extractErrorProps(res:
|
|
33
|
+
function extractErrorProps(res: FIXME): ErrorProps {
|
|
34
34
|
const body = res.body
|
|
35
35
|
const props = {
|
|
36
36
|
response: res,
|
|
37
37
|
statusCode: res.statusCode,
|
|
38
38
|
responseBody: stringifyBody(body, res),
|
|
39
39
|
message: '',
|
|
40
|
-
details: undefined as
|
|
40
|
+
details: undefined as FIXME,
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// API/Boom style errors ({statusCode, error, message})
|
|
@@ -58,12 +58,12 @@ function extractErrorProps(res: any): ErrorProps {
|
|
|
58
58
|
return props
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function httpErrorMessage(res:
|
|
61
|
+
function httpErrorMessage(res: FIXME) {
|
|
62
62
|
const statusMessage = res.statusMessage ? ` ${res.statusMessage}` : ''
|
|
63
63
|
return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}`
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
function stringifyBody(body:
|
|
66
|
+
function stringifyBody(body: FIXME, res: FIXME) {
|
|
67
67
|
const contentType = (res.headers['content-type'] || '').toLowerCase()
|
|
68
68
|
const isJson = contentType.indexOf('application/json') !== -1
|
|
69
69
|
return isJson ? JSON.stringify(body, null, 2) : body
|
package/src/http/request.ts
CHANGED
|
@@ -2,11 +2,11 @@ import {type Middlewares, getIt} from 'get-it'
|
|
|
2
2
|
import {jsonRequest, jsonResponse, observable, progress} from 'get-it/middleware'
|
|
3
3
|
import {Observable} from 'rxjs'
|
|
4
4
|
|
|
5
|
-
import type {HttpRequest, RequestOptions} from '../types'
|
|
5
|
+
import type {FIXME, HttpRequest, RequestOptions} from '../types'
|
|
6
6
|
import {ClientError, ServerError} from './errors'
|
|
7
7
|
|
|
8
8
|
const httpError = {
|
|
9
|
-
onResponse: (res:
|
|
9
|
+
onResponse: (res: FIXME) => {
|
|
10
10
|
if (res.statusCode >= 500) {
|
|
11
11
|
throw new ServerError(res)
|
|
12
12
|
} else if (res.statusCode >= 400) {
|
|
@@ -18,7 +18,7 @@ const httpError = {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const printWarnings = {
|
|
21
|
-
onResponse: (res:
|
|
21
|
+
onResponse: (res: FIXME) => {
|
|
22
22
|
const warn = res.headers['x-sanity-warning']
|
|
23
23
|
const warnings = Array.isArray(warn) ? warn : [warn]
|
|
24
24
|
warnings.filter(Boolean).forEach((msg) => console.warn(msg)) // eslint-disable-line no-console
|
|
@@ -39,7 +39,7 @@ export function defineHttpRequest(envMiddleware: Middlewares): HttpRequest {
|
|
|
39
39
|
])
|
|
40
40
|
|
|
41
41
|
function httpRequest(options: RequestOptions, requester = request) {
|
|
42
|
-
return requester({maxRedirects: 0, ...options} as
|
|
42
|
+
return requester({maxRedirects: 0, ...options} as FIXME)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
httpRequest.defaultRequester = request
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type {RequestOptions} from 'get-it'
|
|
2
2
|
|
|
3
|
+
import type {FIXME} from '../types'
|
|
4
|
+
|
|
3
5
|
const projectHeader = 'X-Sanity-Project-ID'
|
|
4
6
|
|
|
5
|
-
export default (config:
|
|
6
|
-
const headers:
|
|
7
|
+
export default (config: FIXME, overrides: FIXME = {}): Omit<RequestOptions, 'url'> => {
|
|
8
|
+
const headers: FIXME = {}
|
|
7
9
|
|
|
8
10
|
const token = overrides.token || config.token
|
|
9
11
|
if (token) {
|