@sanity/client 3.3.0 → 3.3.3-next.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@sanity/client.svg?style=flat-square)](https://www.npmjs.com/package/@sanity/client)
4
4
 
5
- Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a [Promise polyfill](https://www.sanity.io/help/js-client-promise-polyfill)).
5
+ Javascript client for Sanity. Works in node.js and modern browsers (older browsers need a [Promise polyfill](https://www.sanity.io/help/js-client-promise-polyfill)).
6
6
 
7
7
  ## Requirements
8
8
 
@@ -260,13 +260,11 @@ 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
- const {nanoid} = require('nanoid')
264
-
265
263
  client
266
264
  .patch('bike-123')
267
265
  .setIfMissing({reviews: []})
268
- .append('reviews', [{_key: nanoid(), title: 'Great bike!', stars: 5}])
269
- .commit()
266
+ .append('reviews', [{title: 'Great bike!', stars: 5}])
267
+ .commit({autoGenerateArrayKeys: true})
270
268
  ```
271
269
 
272
270
  ### Deleting an element from an array
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "3.3.0",
3
+ "version": "3.3.3-next.0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "main": "lib/sanityClient.js",
6
6
  "umd": "umd/sanityClient.min.js",
@@ -26,30 +26,30 @@
26
26
  "node": ">=12"
27
27
  },
28
28
  "dependencies": {
29
- "@sanity/eventsource": "^3.0.2",
29
+ "@sanity/eventsource": "^4.0.0",
30
30
  "@sanity/generate-help-url": "^3.0.0",
31
- "get-it": "^6.0.1",
31
+ "get-it": "^6.1.1",
32
32
  "make-error": "^1.3.0",
33
33
  "object-assign": "^4.1.1",
34
34
  "rxjs": "^6.0.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@babel/cli": "^7.17.6",
38
- "@babel/core": "^7.17.7",
39
- "@babel/preset-env": "^7.11.5",
37
+ "@babel/cli": "^7.18.10",
38
+ "@babel/core": "^7.18.10",
39
+ "@babel/preset-env": "^7.18.10",
40
40
  "browserify": "^17.0.0",
41
41
  "envify": "^4.0.0",
42
- "eslint": "^8.11.0",
42
+ "eslint": "^8.21.0",
43
43
  "eslint-config-prettier": "^8.5.0",
44
- "eslint-config-sanity": "^5.1.0",
45
- "nock": "^13.2.4",
44
+ "eslint-config-sanity": "^6.0.0",
45
+ "nock": "^13.2.9",
46
46
  "nyc": "^15.1.0",
47
- "prettier": "^2.6.0",
47
+ "prettier": "^2.7.1",
48
48
  "rimraf": "^3.0.2",
49
49
  "sse-channel": "^4.0.0",
50
- "tape": "^5.5.2",
50
+ "tape": "^5.5.3",
51
51
  "terser": "^5.12.1",
52
- "uglifyify": "^5.0.1",
52
+ "uglifyify": "^5.0.0",
53
53
  "xtend": "4.0.2"
54
54
  },
55
55
  "repository": {
package/sanityClient.d.ts CHANGED
@@ -12,6 +12,7 @@ export type AssetMetadataType =
12
12
  export type DatasetAclMode = 'public' | 'private' | 'custom'
13
13
  export type ListenVisibility = 'sync' | 'async' | 'query'
14
14
  export type ListenEventName = 'mutation' | 'welcome' | 'reconnect'
15
+ export type MutationOperation = 'create' | 'delete' | 'update' | 'none'
15
16
 
16
17
  export interface ResponseEvent<T = unknown> {
17
18
  type: 'response'
@@ -214,13 +215,13 @@ export type Mutation<R = any> =
214
215
  export interface SingleMutationResult {
215
216
  transactionId: string
216
217
  documentId: string
217
- results: {id: string}[]
218
+ results: {id: string; operation: MutationOperation}[]
218
219
  }
219
220
 
220
221
  export interface MultipleMutationResult {
221
222
  transactionId: string
222
223
  documentIds: string[]
223
- results: {id: string}[]
224
+ results: {id: string; operation: MutationOperation}[]
224
225
  }
225
226
 
226
227
  export class Patch {
@@ -379,6 +380,48 @@ export class Patch {
379
380
  reset(): this
380
381
  }
381
382
 
383
+ export class ObservablePatch extends Patch {
384
+ /**
385
+ * Clones the patch
386
+ */
387
+ clone(): ObservablePatch
388
+
389
+ /**
390
+ * Commit the patch, returning an observable that produces the first patched document
391
+ *
392
+ * @param options Options for the mutation operation
393
+ */
394
+ commit<R = any>(options: FirstDocumentMutationOptions): Observable<SanityDocument<R>>
395
+
396
+ /**
397
+ * Commit the patch, returning an observable that produces an array of the mutated documents
398
+ *
399
+ * @param options Options for the mutation operation
400
+ */
401
+ commit<R = any>(options: AllDocumentsMutationOptions): Observable<SanityDocument<R>[]>
402
+
403
+ /**
404
+ * Commit the patch, returning an observable that produces a mutation result object
405
+ *
406
+ * @param options Options for the mutation operation
407
+ */
408
+ commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
409
+
410
+ /**
411
+ * Commit the patch, returning an observable that produces a mutation result object
412
+ *
413
+ * @param options Options for the mutation operation
414
+ */
415
+ commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
416
+
417
+ /**
418
+ * Commit the patch, returning an observable that produces the first patched document
419
+ *
420
+ * @param options Options for the mutation operation
421
+ */
422
+ commit<R = any>(options?: BaseMutationOptions): Observable<SanityDocument<R>>
423
+ }
424
+
382
425
  export class Transaction {
383
426
  constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
384
427
  clone(): Transaction
@@ -492,6 +535,45 @@ export class Transaction {
492
535
  reset(): this
493
536
  }
494
537
 
538
+ export class ObservableTransaction extends Transaction {
539
+ clone(): ObservableTransaction
540
+
541
+ /**
542
+ * Commit the transaction, returning an observable that produces the first mutated document
543
+ *
544
+ * @param options Options for the mutation operation
545
+ */
546
+ commit<R>(options: TransactionFirstDocumentMutationOptions): Observable<SanityDocument<R>>
547
+
548
+ /**
549
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
550
+ *
551
+ * @param options Options for the mutation operation
552
+ */
553
+ commit<R>(options: TransactionAllDocumentsMutationOptions): Observable<SanityDocument<R>[]>
554
+
555
+ /**
556
+ * Commit the transaction, returning an observable that produces a mutation result object
557
+ *
558
+ * @param options Options for the mutation operation
559
+ */
560
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
561
+
562
+ /**
563
+ * Commit the transaction, returning an observable that produces a mutation result object
564
+ *
565
+ * @param options Options for the mutation operation
566
+ */
567
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
568
+
569
+ /**
570
+ * Commit the transaction, returning an observable that produces a mutation result object
571
+ *
572
+ * @param options Options for the mutation operation
573
+ */
574
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
575
+ }
576
+
495
577
  export interface ClientConfig {
496
578
  projectId?: string
497
579
  dataset?: string
@@ -1384,14 +1466,14 @@ export class ObservableSanityClient {
1384
1466
  * @param documentId Document ID to patch
1385
1467
  * @param operations Optional object of patch operations to initialize the patch instance with
1386
1468
  */
1387
- patch(documentId: string | MutationSelection, operations?: PatchOperations): Patch
1469
+ patch(documentId: string | MutationSelection, operations?: PatchOperations): ObservablePatch
1388
1470
 
1389
1471
  /**
1390
1472
  * Create a new transaction of mutations
1391
1473
  *
1392
1474
  * @param operations Optional array of mutation operations to initialize the transaction instance with
1393
1475
  */
1394
- transaction<R = any>(operations?: Mutation<R>[]): Transaction
1476
+ transaction<R = any>(operations?: Mutation<R>[]): ObservableTransaction
1395
1477
 
1396
1478
  // "Internals", should generally not be used externally
1397
1479
  /**
@@ -14,7 +14,7 @@ const getClient = (options) =>
14
14
  {
15
15
  dataset: 'prod',
16
16
  namespace: 'beerns',
17
- apiHost: `http://localhost:${options.port}`,
17
+ apiHost: `http://127.0.0.1:${options.port}`,
18
18
  useProjectHostname: false,
19
19
  useCdn: false,
20
20
  apiVersion: '1',