@sanity/client 3.3.0 → 4.0.0-alpha.esm.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/browser/sanityClient.js +956 -0
- package/dist/node/sanityClient.js +969 -0
- package/lib/assets/assetsClient.js +132 -106
- package/lib/auth/authClient.js +38 -19
- package/lib/config.js +25 -13
- package/lib/data/dataMethods.js +32 -24
- package/lib/data/encodeQueryString.js +8 -2
- package/lib/data/listen.js +25 -21
- package/lib/data/patch.js +169 -118
- package/lib/data/transaction.js +134 -88
- package/lib/datasets/datasetsClient.js +63 -32
- package/lib/http/browserMiddleware.js +6 -1
- package/lib/http/errors.js +12 -8
- package/lib/http/nodeMiddleware.js +16 -9
- package/lib/http/queryString.js +9 -2
- package/lib/http/request.js +27 -24
- package/lib/http/requestOptions.js +10 -6
- package/lib/projects/projectsClient.js +37 -18
- package/lib/sanityClient.js +143 -105
- package/lib/users/usersClient.js +28 -11
- package/lib/util/defaults.js +12 -4
- package/lib/util/getSelection.js +7 -2
- package/lib/util/observable.js +24 -13
- package/lib/util/once.js +9 -2
- package/lib/util/pick.js +9 -2
- package/lib/validators.js +38 -15
- package/lib/warnings.js +14 -6
- package/package.json +21 -3
- package/sanityClient.d.ts +1 -13
- package/test/client.test.js +37 -37
- package/test/encodeQueryString.test.js +3 -1
- package/test/helpers/sseServer.js +2 -1
- package/test/listen.test.js +4 -2
- package/test/warnings.test.disabled.js +8 -4
- package/umd/sanityClient.js +38 -38
- package/umd/sanityClient.min.js +1 -1
package/README.md
CHANGED
|
@@ -19,8 +19,8 @@ npm install -g @sanity/client
|
|
|
19
19
|
## API
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
|
|
23
|
-
const client =
|
|
22
|
+
import {createClient} from '@sanity/client'
|
|
23
|
+
const client = createClient({
|
|
24
24
|
projectId: 'your-project-id',
|
|
25
25
|
dataset: 'bikeshop',
|
|
26
26
|
apiVersion: '2021-03-25', // use current UTC date - see "specifying API version"!
|
|
@@ -29,7 +29,7 @@ const client = sanityClient({
|
|
|
29
29
|
})
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
`const client =
|
|
32
|
+
`const client = createClient(options)`
|
|
33
33
|
|
|
34
34
|
Initializes a new Sanity Client. Required options are `projectId`, `dataset`, and `apiVersion`. Setting a value for `useCdn` is encouraged.
|
|
35
35
|
|
|
@@ -260,7 +260,7 @@ client
|
|
|
260
260
|
The operations of appending and prepending to an array are so common that they have been given their own methods for better readability:
|
|
261
261
|
|
|
262
262
|
```js
|
|
263
|
-
|
|
263
|
+
import {nanoid} from 'nanoid'
|
|
264
264
|
|
|
265
265
|
client
|
|
266
266
|
.patch('bike-123')
|
|
@@ -372,27 +372,27 @@ A `patch` can be performed inline on a `transaction`.
|
|
|
372
372
|
Transactions and patches can also be built outside the scope of a client:
|
|
373
373
|
|
|
374
374
|
```js
|
|
375
|
-
|
|
376
|
-
const client =
|
|
375
|
+
import {SanityClient} from '@sanity/client'
|
|
376
|
+
const client = new SanityClient({
|
|
377
377
|
projectId: 'your-project-id',
|
|
378
378
|
dataset: 'bikeshop',
|
|
379
379
|
})
|
|
380
380
|
|
|
381
381
|
// Patches:
|
|
382
|
-
const patch = new
|
|
382
|
+
const patch = new SanityClient.Patch('<documentId>')
|
|
383
383
|
client.mutate(patch.inc({count: 1}).unset(['visits']))
|
|
384
384
|
|
|
385
385
|
// Transactions:
|
|
386
|
-
const transaction = new
|
|
386
|
+
const transaction = new SanityClient.Transaction()
|
|
387
387
|
.create({_id: '123', name: 'FooBike'})
|
|
388
388
|
.delete('someDocId')
|
|
389
389
|
|
|
390
390
|
client.mutate(transaction)
|
|
391
391
|
```
|
|
392
392
|
|
|
393
|
-
`const patch = new
|
|
393
|
+
`const patch = new SanityClient.Patch(docId)`
|
|
394
394
|
|
|
395
|
-
`const transaction = new
|
|
395
|
+
`const transaction = new SanityClient.Transaction()`
|
|
396
396
|
|
|
397
397
|
An important note on this approach is that you cannot call `commit()` on transactions or patches instantiated this way, instead you have to pass them to `client.mutate()`
|
|
398
398
|
|