@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
package/src/types.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type {Requester} from 'get-it'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export type FIXME = any // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
8
|
+
|
|
3
9
|
/** @public */
|
|
4
10
|
export interface RequestOptions {
|
|
5
11
|
timeout?: number
|
|
@@ -7,8 +13,8 @@ export interface RequestOptions {
|
|
|
7
13
|
tag?: string
|
|
8
14
|
headers?: Record<string, string>
|
|
9
15
|
method?: string
|
|
10
|
-
query?:
|
|
11
|
-
body?:
|
|
16
|
+
query?: FIXME
|
|
17
|
+
body?: FIXME
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
/** @public */
|
|
@@ -45,17 +51,16 @@ export interface InitializedClientConfig extends ClientConfig {
|
|
|
45
51
|
useProjectHostname: boolean
|
|
46
52
|
useCdn: boolean
|
|
47
53
|
// These are added by the initConfig function
|
|
48
|
-
// @TODO consider moving these to private properties on the class instead of adding them to the config
|
|
49
54
|
/**
|
|
50
|
-
* @deprecated
|
|
55
|
+
* @deprecated Internal, don't use
|
|
51
56
|
*/
|
|
52
57
|
isDefaultApi: boolean
|
|
53
58
|
/**
|
|
54
|
-
* @deprecated
|
|
59
|
+
* @deprecated Internal, don't use
|
|
55
60
|
*/
|
|
56
61
|
url: string
|
|
57
62
|
/**
|
|
58
|
-
* @deprecated
|
|
63
|
+
* @deprecated Internal, don't use
|
|
59
64
|
*/
|
|
60
65
|
cdnUrl: string
|
|
61
66
|
}
|
|
@@ -149,7 +154,7 @@ export interface SanityReference {
|
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
/** @internal */
|
|
152
|
-
export type SanityDocument<T extends Record<string,
|
|
157
|
+
export type SanityDocument<T extends Record<string, FIXME> = Record<string, FIXME>> = {
|
|
153
158
|
[P in keyof T]: T[P]
|
|
154
159
|
} & {
|
|
155
160
|
_id: string
|
|
@@ -206,11 +211,11 @@ export interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
|
206
211
|
}
|
|
207
212
|
image?: {
|
|
208
213
|
_type: 'sanity.imageExifTags'
|
|
209
|
-
[key: string]:
|
|
214
|
+
[key: string]: FIXME
|
|
210
215
|
}
|
|
211
216
|
exif?: {
|
|
212
217
|
_type: 'sanity.imageExifMetadata'
|
|
213
|
-
[key: string]:
|
|
218
|
+
[key: string]: FIXME
|
|
214
219
|
}
|
|
215
220
|
}
|
|
216
221
|
}
|
|
@@ -218,10 +223,10 @@ export interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
|
218
223
|
/** @public */
|
|
219
224
|
export interface ErrorProps {
|
|
220
225
|
message: string
|
|
221
|
-
response:
|
|
226
|
+
response: FIXME
|
|
222
227
|
statusCode: number
|
|
223
|
-
responseBody:
|
|
224
|
-
details:
|
|
228
|
+
responseBody: FIXME
|
|
229
|
+
details: FIXME
|
|
225
230
|
}
|
|
226
231
|
|
|
227
232
|
/** @public */
|
|
@@ -331,31 +336,32 @@ export interface CurrentSanityUser {
|
|
|
331
336
|
}
|
|
332
337
|
|
|
333
338
|
/** @public */
|
|
334
|
-
export type SanityDocumentStub<T extends Record<string,
|
|
339
|
+
export type SanityDocumentStub<T extends Record<string, FIXME> = Record<string, FIXME>> = {
|
|
335
340
|
[P in keyof T]: T[P]
|
|
336
341
|
} & {
|
|
337
342
|
_type: string
|
|
338
343
|
}
|
|
339
344
|
|
|
340
345
|
/** @public */
|
|
341
|
-
export type IdentifiedSanityDocumentStub<T extends Record<string,
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
+
export type IdentifiedSanityDocumentStub<T extends Record<string, FIXME> = Record<string, FIXME>> =
|
|
347
|
+
{
|
|
348
|
+
[P in keyof T]: T[P]
|
|
349
|
+
} & {
|
|
350
|
+
_id: string
|
|
351
|
+
} & SanityDocumentStub
|
|
346
352
|
|
|
347
353
|
/** @internal */
|
|
348
354
|
export type InsertPatch =
|
|
349
|
-
| {before: string; items:
|
|
350
|
-
| {after: string; items:
|
|
351
|
-
| {replace: string; items:
|
|
355
|
+
| {before: string; items: FIXME[]}
|
|
356
|
+
| {after: string; items: FIXME[]}
|
|
357
|
+
| {replace: string; items: FIXME[]}
|
|
352
358
|
|
|
353
359
|
// Note: this is actually incorrect/invalid, but implemented as-is for backwards compatibility
|
|
354
360
|
/** @internal */
|
|
355
361
|
export interface PatchOperations {
|
|
356
|
-
set?: {[key: string]:
|
|
357
|
-
setIfMissing?: {[key: string]:
|
|
358
|
-
diffMatchPatch?: {[key: string]:
|
|
362
|
+
set?: {[key: string]: FIXME}
|
|
363
|
+
setIfMissing?: {[key: string]: FIXME}
|
|
364
|
+
diffMatchPatch?: {[key: string]: FIXME}
|
|
359
365
|
unset?: string[]
|
|
360
366
|
inc?: {[key: string]: number}
|
|
361
367
|
dec?: {[key: string]: number}
|
|
@@ -364,7 +370,7 @@ export interface PatchOperations {
|
|
|
364
370
|
}
|
|
365
371
|
|
|
366
372
|
/** @public */
|
|
367
|
-
export type QueryParams = {[key: string]:
|
|
373
|
+
export type QueryParams = {[key: string]: FIXME}
|
|
368
374
|
/** @internal */
|
|
369
375
|
export type MutationSelection = {query: string; params?: QueryParams} | {id: string | string[]}
|
|
370
376
|
/** @internal */
|
|
@@ -373,7 +379,7 @@ export type PatchSelection = string | string[] | MutationSelection
|
|
|
373
379
|
export type PatchMutationOperation = PatchOperations & MutationSelection
|
|
374
380
|
|
|
375
381
|
/** @public */
|
|
376
|
-
export type Mutation<R extends Record<string,
|
|
382
|
+
export type Mutation<R extends Record<string, FIXME> = Record<string, FIXME>> =
|
|
377
383
|
| {create: SanityDocumentStub<R>}
|
|
378
384
|
| {createOrReplace: IdentifiedSanityDocumentStub<R>}
|
|
379
385
|
| {createIfNotExists: IdentifiedSanityDocumentStub<R>}
|
|
@@ -381,7 +387,7 @@ export type Mutation<R extends Record<string, any> = Record<string, any>> =
|
|
|
381
387
|
| {patch: PatchMutationOperation}
|
|
382
388
|
|
|
383
389
|
/** @public */
|
|
384
|
-
export type MutationEvent<R extends Record<string,
|
|
390
|
+
export type MutationEvent<R extends Record<string, FIXME> = Record<string, FIXME>> = {
|
|
385
391
|
type: 'mutation'
|
|
386
392
|
documentId: string
|
|
387
393
|
eventId: string
|
|
@@ -421,7 +427,7 @@ export type WelcomeEvent = {
|
|
|
421
427
|
}
|
|
422
428
|
|
|
423
429
|
/** @public */
|
|
424
|
-
export type ListenEvent<R extends Record<string,
|
|
430
|
+
export type ListenEvent<R extends Record<string, FIXME>> =
|
|
425
431
|
| MutationEvent<R>
|
|
426
432
|
| ChannelErrorEvent
|
|
427
433
|
| DisconnectEvent
|
|
@@ -510,7 +516,7 @@ export type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
|
510
516
|
}
|
|
511
517
|
|
|
512
518
|
/** @internal */
|
|
513
|
-
export type AttributeSet = {[key: string]:
|
|
519
|
+
export type AttributeSet = {[key: string]: FIXME}
|
|
514
520
|
|
|
515
521
|
/** @internal */
|
|
516
522
|
export type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
|
|
@@ -557,6 +563,6 @@ export interface RawRequestOptions {
|
|
|
557
563
|
headers?: {[key: string]: string}
|
|
558
564
|
timeout?: number
|
|
559
565
|
proxy?: string
|
|
560
|
-
body?:
|
|
566
|
+
body?: FIXME
|
|
561
567
|
maxRedirects?: number
|
|
562
568
|
}
|
package/src/util/defaults.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import type {FIXME} from '../types'
|
|
2
|
+
|
|
3
|
+
export default (obj: FIXME, defaults: FIXME) =>
|
|
2
4
|
Object.keys(defaults)
|
|
3
5
|
.concat(Object.keys(obj))
|
|
4
6
|
.reduce((target, prop) => {
|
|
5
7
|
target[prop] = typeof obj[prop] === 'undefined' ? defaults[prop] : obj[prop]
|
|
6
8
|
|
|
7
9
|
return target
|
|
8
|
-
}, {} as
|
|
10
|
+
}, {} as FIXME)
|
package/src/util/once.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type {FIXME} from '../types'
|
|
2
|
+
|
|
3
|
+
export default (fn: FIXME) => {
|
|
2
4
|
let didCall = false
|
|
3
|
-
let returnValue:
|
|
4
|
-
return (...args:
|
|
5
|
+
let returnValue: FIXME
|
|
6
|
+
return (...args: FIXME[]) => {
|
|
5
7
|
if (didCall) {
|
|
6
8
|
return returnValue
|
|
7
9
|
}
|
package/src/util/pick.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {FIXME} from '../types'
|
|
2
|
+
|
|
3
|
+
export default (obj: FIXME, props: FIXME) =>
|
|
4
|
+
props.reduce((selection: FIXME, prop: FIXME) => {
|
|
3
5
|
if (typeof obj[prop] === 'undefined') {
|
|
4
6
|
return selection
|
|
5
7
|
}
|
package/src/validators.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {InitializedClientConfig} from './types'
|
|
1
|
+
import type {FIXME, InitializedClientConfig} from './types'
|
|
2
2
|
|
|
3
3
|
const VALID_ASSET_TYPES = ['image', 'file']
|
|
4
4
|
const VALID_INSERT_LOCATIONS = ['before', 'after', 'replace']
|
|
@@ -23,7 +23,7 @@ export const validateAssetType = (type: string) => {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export const validateObject = (op: string, val:
|
|
26
|
+
export const validateObject = (op: string, val: FIXME) => {
|
|
27
27
|
if (val === null || typeof val !== 'object' || Array.isArray(val)) {
|
|
28
28
|
throw new Error(`${op}() takes an object of properties`)
|
|
29
29
|
}
|
|
@@ -35,7 +35,7 @@ export const validateDocumentId = (op: string, id: string) => {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export const requireDocumentId = (op: string, doc: Record<string,
|
|
38
|
+
export const requireDocumentId = (op: string, doc: Record<string, FIXME>) => {
|
|
39
39
|
if (!doc._id) {
|
|
40
40
|
throw new Error(`${op}() requires that the document contains an ID ("_id" property)`)
|
|
41
41
|
}
|
|
@@ -43,7 +43,7 @@ export const requireDocumentId = (op: string, doc: Record<string, any>) => {
|
|
|
43
43
|
validateDocumentId(op, doc._id)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export const validateInsert = (at: string, selector: string, items:
|
|
46
|
+
export const validateInsert = (at: string, selector: string, items: FIXME[]) => {
|
|
47
47
|
const signature = 'insert(at, selector, items)'
|
|
48
48
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
49
49
|
const valid = VALID_INSERT_LOCATIONS.map((loc) => `"${loc}"`).join(', ')
|
package/src/warnings.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import generateHelpUrl from './generateHelpUrl'
|
|
2
|
+
import {FIXME} from './types'
|
|
2
3
|
import once from './util/once'
|
|
3
4
|
|
|
4
5
|
const createWarningPrinter = (message: string[]) =>
|
|
5
6
|
// eslint-disable-next-line no-console
|
|
6
|
-
once((...args:
|
|
7
|
+
once((...args: FIXME[]) => console.warn(message.join(' '), ...args))
|
|
7
8
|
|
|
8
9
|
export const printCdnWarning = createWarningPrinter([
|
|
9
10
|
'You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and',
|