@sanity/client 6.1.2 → 6.1.3-perspective.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "6.1.2",
3
+ "version": "6.1.3-perspective.1",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -96,31 +96,31 @@
96
96
  },
97
97
  "devDependencies": {
98
98
  "@edge-runtime/types": "^2.0.8",
99
- "@edge-runtime/vm": "^2.1.2",
99
+ "@edge-runtime/vm": "^3.0.0",
100
100
  "@rollup/plugin-commonjs": "^25.0.0",
101
- "@rollup/plugin-node-resolve": "^15.0.1",
102
- "@sanity/pkg-utils": "^2.2.13",
103
- "@sanity/semantic-release-preset": "^4.1.0",
104
- "@types/node": "^18.15.10",
105
- "@typescript-eslint/eslint-plugin": "^5.57.0",
106
- "@typescript-eslint/parser": "^5.57.0",
107
- "@vitest/coverage-c8": "^0.31.0",
108
- "eslint": "^8.36.0",
101
+ "@rollup/plugin-node-resolve": "^15.0.2",
102
+ "@sanity/pkg-utils": "^2.2.16",
103
+ "@sanity/semantic-release-preset": "^4.1.1",
104
+ "@types/node": "^20.2.3",
105
+ "@typescript-eslint/eslint-plugin": "^5.59.7",
106
+ "@typescript-eslint/parser": "^5.59.7",
107
+ "@vitest/coverage-v8": "^0.32.0",
108
+ "eslint": "^8.41.0",
109
109
  "eslint-config-prettier": "^8.8.0",
110
110
  "eslint-plugin-prettier": "^4.2.1",
111
111
  "eslint-plugin-simple-import-sort": "^10.0.0",
112
112
  "faucet": "^0.0.4",
113
- "happy-dom": "^9.0.0",
113
+ "happy-dom": "^9.20.1",
114
114
  "ls-engines": "^0.9.0",
115
- "nock": "^13.3.0",
116
- "prettier": "^2.8.7",
115
+ "nock": "^13.3.1",
116
+ "prettier": "^2.8.8",
117
117
  "prettier-plugin-packagejson": "^2.4.3",
118
- "rimraf": "^5.0.0",
119
- "rollup": "^3.20.2",
118
+ "rimraf": "^5.0.1",
119
+ "rollup": "^3.23.0",
120
120
  "sse-channel": "^4.0.0",
121
- "terser": "^5.16.8",
122
- "typescript": "^5.0.2",
123
- "vitest": "^0.31.0",
121
+ "terser": "^5.17.6",
122
+ "typescript": "^5.0.4",
123
+ "vitest": "^0.32.0",
124
124
  "vitest-github-actions-reporter": "^0.10.0"
125
125
  },
126
126
  "engines": {
@@ -307,7 +307,7 @@ export function _requestObservable<R>(
307
307
  if (config.resultSourceMap) {
308
308
  options.query = {resultSourceMap: true, ...options.query}
309
309
  }
310
- if (typeof config.perspective === 'string' && config.perspective !== 'all') {
310
+ if (typeof config.perspective === 'string' && config.perspective !== 'raw') {
311
311
  options.query = {perspective: config.perspective, ...options.query}
312
312
  }
313
313
  }
package/src/types.ts CHANGED
@@ -28,6 +28,9 @@ export interface RequestOptions {
28
28
  signal?: AbortSignal
29
29
  }
30
30
 
31
+ /** @public */
32
+ export type ClientPerspective = 'previewDrafts' | 'published' | 'raw'
33
+
31
34
  /** @public */
32
35
  export interface ClientConfig {
33
36
  projectId?: string
@@ -35,7 +38,8 @@ export interface ClientConfig {
35
38
  /** @defaultValue true */
36
39
  useCdn?: boolean
37
40
  token?: string
38
- perspective?: 'previewDrafts' | 'published' | 'all'
41
+ /** @defaultValue 'raw' */
42
+ perspective?: ClientPerspective
39
43
  apiHost?: string
40
44
  apiVersion?: string
41
45
  proxy?: string
@@ -193,6 +197,10 @@ export type SanityDocument<T extends Record<string, Any> = Record<string, Any>>
193
197
  _type: string
194
198
  _createdAt: string
195
199
  _updatedAt: string
200
+ /**
201
+ * Present when `perspective` is set to `previewDrafts`
202
+ */
203
+ _originalId?: string
196
204
  }
197
205
 
198
206
  /** @internal */
@@ -1408,74 +1408,74 @@
1408
1408
  };
1409
1409
  retry.shouldRetry = defaultShouldRetry;
1410
1410
 
1411
- /******************************************************************************
1412
- Copyright (c) Microsoft Corporation.
1413
-
1414
- Permission to use, copy, modify, and/or distribute this software for any
1415
- purpose with or without fee is hereby granted.
1416
-
1417
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1418
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1419
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1420
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1421
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1422
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1423
- PERFORMANCE OF THIS SOFTWARE.
1424
- ***************************************************************************** */
1425
- /* global Reflect, Promise */
1426
-
1427
- var extendStatics = function(d, b) {
1428
- extendStatics = Object.setPrototypeOf ||
1429
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1430
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1431
- return extendStatics(d, b);
1432
- };
1433
-
1434
- function __extends(d, b) {
1435
- if (typeof b !== "function" && b !== null)
1436
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1437
- extendStatics(d, b);
1438
- function __() { this.constructor = d; }
1439
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1440
- }
1441
-
1442
- function __values(o) {
1443
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1444
- if (m) return m.call(o);
1445
- if (o && typeof o.length === "number") return {
1446
- next: function () {
1447
- if (o && i >= o.length) o = void 0;
1448
- return { value: o && o[i++], done: !o };
1449
- }
1450
- };
1451
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1452
- }
1453
-
1454
- function __read(o, n) {
1455
- var m = typeof Symbol === "function" && o[Symbol.iterator];
1456
- if (!m) return o;
1457
- var i = m.call(o), r, ar = [], e;
1458
- try {
1459
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
1460
- }
1461
- catch (error) { e = { error: error }; }
1462
- finally {
1463
- try {
1464
- if (r && !r.done && (m = i["return"])) m.call(i);
1465
- }
1466
- finally { if (e) throw e.error; }
1467
- }
1468
- return ar;
1469
- }
1470
-
1471
- function __spreadArray(to, from, pack) {
1472
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1473
- if (ar || !(i in from)) {
1474
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1475
- ar[i] = from[i];
1476
- }
1477
- }
1478
- return to.concat(ar || Array.prototype.slice.call(from));
1411
+ /******************************************************************************
1412
+ Copyright (c) Microsoft Corporation.
1413
+
1414
+ Permission to use, copy, modify, and/or distribute this software for any
1415
+ purpose with or without fee is hereby granted.
1416
+
1417
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1418
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1419
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1420
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1421
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1422
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1423
+ PERFORMANCE OF THIS SOFTWARE.
1424
+ ***************************************************************************** */
1425
+ /* global Reflect, Promise */
1426
+
1427
+ var extendStatics = function(d, b) {
1428
+ extendStatics = Object.setPrototypeOf ||
1429
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1430
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1431
+ return extendStatics(d, b);
1432
+ };
1433
+
1434
+ function __extends(d, b) {
1435
+ if (typeof b !== "function" && b !== null)
1436
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1437
+ extendStatics(d, b);
1438
+ function __() { this.constructor = d; }
1439
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1440
+ }
1441
+
1442
+ function __values(o) {
1443
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1444
+ if (m) return m.call(o);
1445
+ if (o && typeof o.length === "number") return {
1446
+ next: function () {
1447
+ if (o && i >= o.length) o = void 0;
1448
+ return { value: o && o[i++], done: !o };
1449
+ }
1450
+ };
1451
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1452
+ }
1453
+
1454
+ function __read(o, n) {
1455
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
1456
+ if (!m) return o;
1457
+ var i = m.call(o), r, ar = [], e;
1458
+ try {
1459
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
1460
+ }
1461
+ catch (error) { e = { error: error }; }
1462
+ finally {
1463
+ try {
1464
+ if (r && !r.done && (m = i["return"])) m.call(i);
1465
+ }
1466
+ finally { if (e) throw e.error; }
1467
+ }
1468
+ return ar;
1469
+ }
1470
+
1471
+ function __spreadArray(to, from, pack) {
1472
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1473
+ if (ar || !(i in from)) {
1474
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1475
+ ar[i] = from[i];
1476
+ }
1477
+ }
1478
+ return to.concat(ar || Array.prototype.slice.call(from));
1479
1479
  }
1480
1480
 
1481
1481
  function isFunction(value) {
@@ -2090,12 +2090,26 @@
2090
2090
  }
2091
2091
 
2092
2092
  var envMiddleware = [];
2093
+ var __defProp$3 = Object.defineProperty;
2094
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, {
2095
+ enumerable: true,
2096
+ configurable: true,
2097
+ writable: true,
2098
+ value
2099
+ }) : obj[key] = value;
2100
+ var __publicField$3 = (obj, key, value) => {
2101
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
2102
+ return value;
2103
+ };
2093
2104
  const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
2094
2105
  class ClientError extends Error {
2095
2106
  constructor(res) {
2096
2107
  const props = extractErrorProps(res);
2097
2108
  super(props.message);
2098
- this.statusCode = 400;
2109
+ __publicField$3(this, "response");
2110
+ __publicField$3(this, "statusCode", 400);
2111
+ __publicField$3(this, "responseBody");
2112
+ __publicField$3(this, "details");
2099
2113
  Object.assign(this, props);
2100
2114
  }
2101
2115
  }
@@ -2103,7 +2117,10 @@
2103
2117
  constructor(res) {
2104
2118
  const props = extractErrorProps(res);
2105
2119
  super(props.message);
2106
- this.statusCode = 500;
2120
+ __publicField$3(this, "response");
2121
+ __publicField$3(this, "statusCode", 500);
2122
+ __publicField$3(this, "responseBody");
2123
+ __publicField$3(this, "details");
2107
2124
  Object.assign(this, props);
2108
2125
  }
2109
2126
  }
@@ -2324,6 +2341,17 @@
2324
2341
  }
2325
2342
  return "?".concat(searchParams);
2326
2343
  };
2344
+ var __defProp$2 = Object.defineProperty;
2345
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, {
2346
+ enumerable: true,
2347
+ configurable: true,
2348
+ writable: true,
2349
+ value
2350
+ }) : obj[key] = value;
2351
+ var __publicField$2 = (obj, key, value) => {
2352
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
2353
+ return value;
2354
+ };
2327
2355
  var __accessCheck$6 = (obj, member, msg) => {
2328
2356
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
2329
2357
  };
@@ -2344,6 +2372,8 @@
2344
2372
  class BasePatch {
2345
2373
  constructor(selection) {
2346
2374
  let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2375
+ __publicField$2(this, "selection");
2376
+ __publicField$2(this, "operations");
2347
2377
  this.selection = selection;
2348
2378
  this.operations = operations;
2349
2379
  }
@@ -2497,7 +2527,7 @@
2497
2527
  return this._assign(op, props, false);
2498
2528
  }
2499
2529
  }
2500
- const _ObservablePatch = class extends BasePatch {
2530
+ const _ObservablePatch = class _ObservablePatch extends BasePatch {
2501
2531
  constructor(selection, operations, client) {
2502
2532
  super(selection, operations);
2503
2533
  __privateAdd$6(this, _client$5, void 0);
@@ -2525,9 +2555,9 @@
2525
2555
  }, opts);
2526
2556
  }
2527
2557
  };
2528
- let ObservablePatch = _ObservablePatch;
2529
2558
  _client$5 = new WeakMap();
2530
- const _Patch = class extends BasePatch {
2559
+ let ObservablePatch = _ObservablePatch;
2560
+ const _Patch = class _Patch extends BasePatch {
2531
2561
  constructor(selection, operations, client) {
2532
2562
  super(selection, operations);
2533
2563
  __privateAdd$6(this, _client2$5, void 0);
@@ -2555,8 +2585,19 @@
2555
2585
  }, opts);
2556
2586
  }
2557
2587
  };
2558
- let Patch = _Patch;
2559
2588
  _client2$5 = new WeakMap();
2589
+ let Patch = _Patch;
2590
+ var __defProp$1 = Object.defineProperty;
2591
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, {
2592
+ enumerable: true,
2593
+ configurable: true,
2594
+ writable: true,
2595
+ value
2596
+ }) : obj[key] = value;
2597
+ var __publicField$1 = (obj, key, value) => {
2598
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2599
+ return value;
2600
+ };
2560
2601
  var __accessCheck$5 = (obj, member, msg) => {
2561
2602
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
2562
2603
  };
@@ -2581,6 +2622,8 @@
2581
2622
  constructor() {
2582
2623
  let operations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2583
2624
  let transactionId = arguments.length > 1 ? arguments[1] : undefined;
2625
+ __publicField$1(this, "operations");
2626
+ __publicField$1(this, "trxId");
2584
2627
  this.operations = operations;
2585
2628
  this.trxId = transactionId;
2586
2629
  }
@@ -2669,7 +2712,7 @@
2669
2712
  return this;
2670
2713
  }
2671
2714
  }
2672
- const _Transaction = class extends BaseTransaction {
2715
+ const _Transaction = class _Transaction extends BaseTransaction {
2673
2716
  constructor(operations, client, transactionId) {
2674
2717
  super(operations, transactionId);
2675
2718
  __privateAdd$5(this, _client$4, void 0);
@@ -2714,9 +2757,9 @@
2714
2757
  });
2715
2758
  }
2716
2759
  };
2717
- let Transaction = _Transaction;
2718
2760
  _client$4 = new WeakMap();
2719
- const _ObservableTransaction = class extends BaseTransaction {
2761
+ let Transaction = _Transaction;
2762
+ const _ObservableTransaction = class _ObservableTransaction extends BaseTransaction {
2720
2763
  constructor(operations, client, transactionId) {
2721
2764
  super(operations, transactionId);
2722
2765
  __privateAdd$5(this, _client2$4, void 0);
@@ -2761,8 +2804,8 @@
2761
2804
  });
2762
2805
  }
2763
2806
  };
2764
- let ObservableTransaction = _ObservableTransaction;
2765
2807
  _client2$4 = new WeakMap();
2808
+ let ObservableTransaction = _ObservableTransaction;
2766
2809
  const excludeFalsey = (param, defValue) => {
2767
2810
  const value = typeof param === "undefined" ? defValue : param;
2768
2811
  return param === false ? void 0 : value;
@@ -2924,7 +2967,7 @@
2924
2967
  ...options.query
2925
2968
  };
2926
2969
  }
2927
- if (typeof config.perspective === "string" && config.perspective !== "all") {
2970
+ if (typeof config.perspective === "string" && config.perspective !== "raw") {
2928
2971
  options.query = {
2929
2972
  perspective: config.perspective,
2930
2973
  ...options.query
@@ -3575,6 +3618,17 @@
3575
3618
  }
3576
3619
  _client2 = new WeakMap();
3577
3620
  _httpRequest2$1 = new WeakMap();
3621
+ var __defProp = Object.defineProperty;
3622
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
3623
+ enumerable: true,
3624
+ configurable: true,
3625
+ writable: true,
3626
+ value
3627
+ }) : obj[key] = value;
3628
+ var __publicField = (obj, key, value) => {
3629
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
3630
+ return value;
3631
+ };
3578
3632
  var __accessCheck = (obj, member, msg) => {
3579
3633
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
3580
3634
  };
@@ -3592,9 +3646,13 @@
3592
3646
  return value;
3593
3647
  };
3594
3648
  var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
3595
- const _ObservableSanityClient = class {
3649
+ const _ObservableSanityClient = class _ObservableSanityClient {
3596
3650
  constructor(httpRequest) {
3597
3651
  let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
3652
+ __publicField(this, "assets");
3653
+ __publicField(this, "datasets");
3654
+ __publicField(this, "projects");
3655
+ __publicField(this, "users");
3598
3656
  /**
3599
3657
  * Private properties
3600
3658
  */
@@ -3603,7 +3661,7 @@
3603
3661
  /**
3604
3662
  * Instance properties
3605
3663
  */
3606
- this.listen = _listen;
3664
+ __publicField(this, "listen", _listen);
3607
3665
  this.config(config);
3608
3666
  __privateSet(this, _httpRequest, httpRequest);
3609
3667
  this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
@@ -3725,12 +3783,20 @@
3725
3783
  return _getDataUrl(this, operation, path);
3726
3784
  }
3727
3785
  };
3728
- let ObservableSanityClient = _ObservableSanityClient;
3729
3786
  _clientConfig = new WeakMap();
3730
3787
  _httpRequest = new WeakMap();
3731
- const _SanityClient = class {
3788
+ let ObservableSanityClient = _ObservableSanityClient;
3789
+ const _SanityClient = class _SanityClient {
3732
3790
  constructor(httpRequest) {
3733
3791
  let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
3792
+ __publicField(this, "assets");
3793
+ __publicField(this, "datasets");
3794
+ __publicField(this, "projects");
3795
+ __publicField(this, "users");
3796
+ /**
3797
+ * Observable version of the Sanity client, with the same configuration as the promise-based one
3798
+ */
3799
+ __publicField(this, "observable");
3734
3800
  /**
3735
3801
  * Private properties
3736
3802
  */
@@ -3739,7 +3805,7 @@
3739
3805
  /**
3740
3806
  * Instance properties
3741
3807
  */
3742
- this.listen = _listen;
3808
+ __publicField(this, "listen", _listen);
3743
3809
  this.config(config);
3744
3810
  __privateSet(this, _httpRequest2, httpRequest);
3745
3811
  this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
@@ -3879,9 +3945,9 @@
3879
3945
  return _getDataUrl(this, operation, path);
3880
3946
  }
3881
3947
  };
3882
- let SanityClient = _SanityClient;
3883
3948
  _clientConfig2 = new WeakMap();
3884
3949
  _httpRequest2 = new WeakMap();
3950
+ let SanityClient = _SanityClient;
3885
3951
  const httpRequest = defineHttpRequest(envMiddleware, {});
3886
3952
  const requester = httpRequest.defaultRequester;
3887
3953
  const createClient = config => new SanityClient(defineHttpRequest(envMiddleware, {