@sanity/client 4.0.0-alpha.esm.6 → 4.0.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.
Files changed (68) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +23 -16
  3. package/dist/{browser/sanityClient.js → sanityClient.browser.mjs} +305 -1513
  4. package/dist/sanityClient.browser.mjs.map +7 -0
  5. package/index.js +7 -0
  6. package/lib/assets/assetsClient.js +100 -141
  7. package/lib/auth/authClient.js +20 -35
  8. package/lib/config.js +21 -43
  9. package/lib/data/dataMethods.js +32 -55
  10. package/lib/data/encodeQueryString.js +9 -15
  11. package/lib/data/listen.js +24 -53
  12. package/lib/data/patch.js +114 -167
  13. package/lib/data/transaction.js +95 -139
  14. package/lib/datasets/datasetsClient.js +31 -56
  15. package/lib/generateHelpUrl.js +11 -0
  16. package/lib/http/browserMiddleware.js +4 -3
  17. package/lib/http/errors.js +9 -15
  18. package/lib/http/nodeMiddleware.js +6 -10
  19. package/lib/http/queryString.js +4 -7
  20. package/lib/http/request.js +14 -28
  21. package/lib/http/requestOptions.js +7 -10
  22. package/lib/projects/projectsClient.js +19 -34
  23. package/lib/sanityClient.js +98 -153
  24. package/lib/users/usersClient.js +14 -27
  25. package/lib/util/defaults.js +6 -8
  26. package/lib/util/getSelection.js +3 -5
  27. package/lib/util/observable.js +0 -3
  28. package/lib/util/once.js +4 -6
  29. package/lib/util/pick.js +4 -6
  30. package/lib/validators.js +0 -26
  31. package/lib/warnings.js +9 -13
  32. package/package.json +49 -38
  33. package/sanityClient.d.ts +256 -99
  34. package/umd/sanityClient.js +165 -103
  35. package/umd/sanityClient.min.js +1 -1
  36. package/dist/node/sanityClient.js +0 -969
  37. package/src/assets/assetsClient.js +0 -132
  38. package/src/auth/authClient.js +0 -13
  39. package/src/config.js +0 -93
  40. package/src/data/dataMethods.js +0 -182
  41. package/src/data/encodeQueryString.js +0 -18
  42. package/src/data/listen.js +0 -159
  43. package/src/data/patch.js +0 -119
  44. package/src/data/transaction.js +0 -103
  45. package/src/datasets/datasetsClient.js +0 -28
  46. package/src/http/browserMiddleware.js +0 -1
  47. package/src/http/errors.js +0 -53
  48. package/src/http/nodeMiddleware.js +0 -11
  49. package/src/http/queryString.js +0 -10
  50. package/src/http/request.js +0 -50
  51. package/src/http/requestOptions.js +0 -29
  52. package/src/projects/projectsClient.js +0 -13
  53. package/src/sanityClient.js +0 -124
  54. package/src/users/usersClient.js +0 -9
  55. package/src/util/defaults.js +0 -9
  56. package/src/util/getSelection.js +0 -17
  57. package/src/util/observable.js +0 -6
  58. package/src/util/once.js +0 -12
  59. package/src/util/pick.js +0 -9
  60. package/src/validators.js +0 -76
  61. package/src/warnings.js +0 -25
  62. package/test/client.test.js +0 -2561
  63. package/test/encodeQueryString.test.js +0 -38
  64. package/test/fixtures/horsehead-nebula.jpg +0 -0
  65. package/test/fixtures/pdf-sample.pdf +0 -0
  66. package/test/helpers/sseServer.js +0 -27
  67. package/test/listen.test.js +0 -207
  68. package/test/warnings.test.disabled.js +0 -84
package/lib/data/patch.js CHANGED
@@ -1,174 +1,121 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.Patch = void 0;
7
-
8
- var _getSelection = require("../util/getSelection");
9
-
7
+ exports.default = void 0;
8
+ var _getSelection = _interopRequireDefault(require("../util/getSelection"));
10
9
  var _validators = require("../validators");
11
-
12
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
-
14
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
-
16
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
17
-
18
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
-
20
- var Patch = /*#__PURE__*/function () {
21
- function Patch(selection) {
22
- var operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
23
- var client = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
24
-
25
- _classCallCheck(this, Patch);
26
-
27
- this.selection = selection;
28
- this.operations = Object.assign({}, operations);
29
- this.client = client;
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
14
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
15
+ function Patch(selection) {
16
+ var operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
+ var client = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
18
+ this.selection = selection;
19
+ this.operations = _extends({}, operations);
20
+ this.client = client;
21
+ }
22
+ _extends(Patch.prototype, {
23
+ clone: function clone() {
24
+ return new Patch(this.selection, _extends({}, this.operations), this.client);
25
+ },
26
+ set: function set(props) {
27
+ return this.assign('set', props);
28
+ },
29
+ diffMatchPatch: function diffMatchPatch(props) {
30
+ (0, _validators.validateObject)('diffMatchPatch', props);
31
+ return this.assign('diffMatchPatch', props);
32
+ },
33
+ unset: function unset(attrs) {
34
+ if (!Array.isArray(attrs)) {
35
+ throw new Error('unset(attrs) takes an array of attributes to unset, non-array given');
36
+ }
37
+ this.operations = _extends({}, this.operations, {
38
+ unset: attrs
39
+ });
40
+ return this;
41
+ },
42
+ setIfMissing: function setIfMissing(props) {
43
+ return this.assign('setIfMissing', props);
44
+ },
45
+ replace: function replace(props) {
46
+ (0, _validators.validateObject)('replace', props);
47
+ return this._set('set', {
48
+ $: props
49
+ }); // eslint-disable-line id-length
50
+ },
51
+ inc: function inc(props) {
52
+ return this.assign('inc', props);
53
+ },
54
+ dec: function dec(props) {
55
+ return this.assign('dec', props);
56
+ },
57
+ insert: function insert(at, selector, items) {
58
+ var _this$assign;
59
+ (0, _validators.validateInsert)(at, selector, items);
60
+ return this.assign('insert', (_this$assign = {}, _defineProperty(_this$assign, at, selector), _defineProperty(_this$assign, "items", items), _this$assign));
61
+ },
62
+ append: function append(selector, items) {
63
+ return this.insert('after', "".concat(selector, "[-1]"), items);
64
+ },
65
+ prepend: function prepend(selector, items) {
66
+ return this.insert('before', "".concat(selector, "[0]"), items);
67
+ },
68
+ splice: function splice(selector, start, deleteCount, items) {
69
+ // Negative indexes doesn't mean the same in Sanity as they do in JS;
70
+ // -1 means "actually at the end of the array", which allows inserting
71
+ // at the end of the array without knowing its length. We therefore have
72
+ // to substract negative indexes by one to match JS. If you want Sanity-
73
+ // behaviour, just use `insert('replace', selector, items)` directly
74
+ var delAll = typeof deleteCount === 'undefined' || deleteCount === -1;
75
+ var startIndex = start < 0 ? start - 1 : start;
76
+ var delCount = delAll ? -1 : Math.max(0, start + deleteCount);
77
+ var delRange = startIndex < 0 && delCount >= 0 ? '' : delCount;
78
+ var rangeSelector = "".concat(selector, "[").concat(startIndex, ":").concat(delRange, "]");
79
+ return this.insert('replace', rangeSelector, items || []);
80
+ },
81
+ ifRevisionId: function ifRevisionId(rev) {
82
+ this.operations.ifRevisionID = rev;
83
+ return this;
84
+ },
85
+ serialize: function serialize() {
86
+ return _extends((0, _getSelection.default)(this.selection), this.operations);
87
+ },
88
+ toJSON: function toJSON() {
89
+ return this.serialize();
90
+ },
91
+ commit: function commit() {
92
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
93
+ if (!this.client) {
94
+ throw new Error('No `client` passed to patch, either provide one or pass the ' + 'patch to a clients `mutate()` method');
95
+ }
96
+ var returnFirst = typeof this.selection === 'string';
97
+ var opts = _extends({
98
+ returnFirst: returnFirst,
99
+ returnDocuments: true
100
+ }, options);
101
+ return this.client.mutate({
102
+ patch: this.serialize()
103
+ }, opts);
104
+ },
105
+ reset: function reset() {
106
+ this.operations = {};
107
+ return this;
108
+ },
109
+ _set: function _set(op, props) {
110
+ return this.assign(op, props, false);
111
+ },
112
+ assign: function assign(op, props) {
113
+ var merge = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
114
+ (0, _validators.validateObject)(op, props);
115
+ this.operations = _extends({}, this.operations, _defineProperty({}, op, _extends({}, merge && this.operations[op] || {}, props)));
116
+ return this;
30
117
  }
31
-
32
- _createClass(Patch, [{
33
- key: "clone",
34
- value: function clone() {
35
- return new Patch(this.selection, Object.assign({}, this.operations), this.client);
36
- }
37
- }, {
38
- key: "set",
39
- value: function set(props) {
40
- return this._assign('set', props);
41
- }
42
- }, {
43
- key: "diffMatchPatch",
44
- value: function diffMatchPatch(props) {
45
- (0, _validators.validateObject)('diffMatchPatch', props);
46
- return this._assign('diffMatchPatch', props);
47
- }
48
- }, {
49
- key: "unset",
50
- value: function unset(attrs) {
51
- if (!Array.isArray(attrs)) {
52
- throw new Error('unset(attrs) takes an array of attributes to unset, non-array given');
53
- }
54
-
55
- this.operations = Object.assign({}, this.operations, {
56
- unset: attrs
57
- });
58
- return this;
59
- }
60
- }, {
61
- key: "setIfMissing",
62
- value: function setIfMissing(props) {
63
- return this._assign('setIfMissing', props);
64
- }
65
- }, {
66
- key: "replace",
67
- value: function replace(props) {
68
- (0, _validators.validateObject)('replace', props);
69
- return this._set('set', {
70
- $: props
71
- }); // eslint-disable-line id-length
72
- }
73
- }, {
74
- key: "inc",
75
- value: function inc(props) {
76
- return this._assign('inc', props);
77
- }
78
- }, {
79
- key: "dec",
80
- value: function dec(props) {
81
- return this._assign('dec', props);
82
- }
83
- }, {
84
- key: "insert",
85
- value: function insert(at, selector, items) {
86
- var _this$_assign;
87
-
88
- (0, _validators.validateInsert)(at, selector, items);
89
- return this._assign('insert', (_this$_assign = {}, _defineProperty(_this$_assign, at, selector), _defineProperty(_this$_assign, "items", items), _this$_assign));
90
- }
91
- }, {
92
- key: "append",
93
- value: function append(selector, items) {
94
- return this.insert('after', "".concat(selector, "[-1]"), items);
95
- }
96
- }, {
97
- key: "prepend",
98
- value: function prepend(selector, items) {
99
- return this.insert('before', "".concat(selector, "[0]"), items);
100
- }
101
- }, {
102
- key: "splice",
103
- value: function splice(selector, start, deleteCount, items) {
104
- // Negative indexes doesn't mean the same in Sanity as they do in JS;
105
- // -1 means "actually at the end of the array", which allows inserting
106
- // at the end of the array without knowing its length. We therefore have
107
- // to substract negative indexes by one to match JS. If you want Sanity-
108
- // behaviour, just use `insert('replace', selector, items)` directly
109
- var delAll = typeof deleteCount === 'undefined' || deleteCount === -1;
110
- var startIndex = start < 0 ? start - 1 : start;
111
- var delCount = delAll ? -1 : Math.max(0, start + deleteCount);
112
- var delRange = startIndex < 0 && delCount >= 0 ? '' : delCount;
113
- var rangeSelector = "".concat(selector, "[").concat(startIndex, ":").concat(delRange, "]");
114
- return this.insert('replace', rangeSelector, items || []);
115
- }
116
- }, {
117
- key: "ifRevisionId",
118
- value: function ifRevisionId(rev) {
119
- this.operations.ifRevisionID = rev;
120
- return this;
121
- }
122
- }, {
123
- key: "serialize",
124
- value: function serialize() {
125
- return Object.assign((0, _getSelection.getSelection)(this.selection), this.operations);
126
- }
127
- }, {
128
- key: "toJSON",
129
- value: function toJSON() {
130
- return this.serialize();
131
- }
132
- }, {
133
- key: "commit",
134
- value: function commit() {
135
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
136
-
137
- if (!this.client) {
138
- throw new Error('No `client` passed to patch, either provide one or pass the ' + 'patch to a clients `mutate()` method');
139
- }
140
-
141
- var returnFirst = typeof this.selection === 'string';
142
- var opts = Object.assign({
143
- returnFirst: returnFirst,
144
- returnDocuments: true
145
- }, options);
146
- return this.client.mutate({
147
- patch: this.serialize()
148
- }, opts);
149
- }
150
- }, {
151
- key: "reset",
152
- value: function reset() {
153
- this.operations = {};
154
- return this;
155
- }
156
- }, {
157
- key: "_set",
158
- value: function _set(op, props) {
159
- return this._assign(op, props, false);
160
- }
161
- }, {
162
- key: "_assign",
163
- value: function _assign(op, props) {
164
- var merge = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
165
- (0, _validators.validateObject)(op, props);
166
- this.operations = Object.assign({}, this.operations, _defineProperty({}, op, Object.assign({}, merge && this.operations[op] || {}, props)));
167
- return this;
168
- }
169
- }]);
170
-
171
- return Patch;
172
- }();
173
-
174
- exports.Patch = Patch;
118
+ });
119
+ var _default = Patch;
120
+ exports.default = _default;
121
+ module.exports = exports.default;
@@ -1,161 +1,117 @@
1
1
  "use strict";
2
2
 
3
3
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.Transaction = void 0;
9
-
7
+ exports.default = void 0;
10
8
  var validators = _interopRequireWildcard(require("../validators"));
11
-
12
- var _patch = require("./patch");
13
-
9
+ var _patch = _interopRequireDefault(require("./patch"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
11
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
12
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
-
20
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
-
22
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23
-
24
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
25
-
13
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
15
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
16
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
26
17
  var defaultMutateOptions = {
27
18
  returnDocuments: false
28
19
  };
29
-
30
- var Transaction = /*#__PURE__*/function () {
31
- function Transaction() {
32
- var operations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
33
- var client = arguments.length > 1 ? arguments[1] : undefined;
34
- var transactionId = arguments.length > 2 ? arguments[2] : undefined;
35
-
36
- _classCallCheck(this, Transaction);
37
-
38
- this.trxId = transactionId;
39
- this.operations = operations;
40
- this.client = client;
41
- }
42
-
43
- _createClass(Transaction, [{
44
- key: "clone",
45
- value: function clone() {
46
- return new Transaction(this.operations.slice(0), this.client, this.trxId);
47
- }
48
- }, {
49
- key: "create",
50
- value: function create(doc) {
51
- validators.validateObject('create', doc);
52
- return this._add({
53
- create: doc
54
- });
55
- }
56
- }, {
57
- key: "createIfNotExists",
58
- value: function createIfNotExists(doc) {
59
- var op = 'createIfNotExists';
60
- validators.validateObject(op, doc);
61
- validators.requireDocumentId(op, doc);
62
- return this._add(_defineProperty({}, op, doc));
63
- }
64
- }, {
65
- key: "createOrReplace",
66
- value: function createOrReplace(doc) {
67
- var op = 'createOrReplace';
68
- validators.validateObject(op, doc);
69
- validators.requireDocumentId(op, doc);
70
- return this._add(_defineProperty({}, op, doc));
71
- }
72
- }, {
73
- key: "delete",
74
- value: function _delete(documentId) {
75
- validators.validateDocumentId('delete', documentId);
20
+ function Transaction() {
21
+ var operations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
22
+ var client = arguments.length > 1 ? arguments[1] : undefined;
23
+ var transactionId = arguments.length > 2 ? arguments[2] : undefined;
24
+ this.trxId = transactionId;
25
+ this.operations = operations;
26
+ this.client = client;
27
+ }
28
+ _extends(Transaction.prototype, {
29
+ clone: function clone() {
30
+ return new Transaction(this.operations.slice(0), this.client, this.trxId);
31
+ },
32
+ create: function create(doc) {
33
+ validators.validateObject('create', doc);
34
+ return this._add({
35
+ create: doc
36
+ });
37
+ },
38
+ createIfNotExists: function createIfNotExists(doc) {
39
+ var op = 'createIfNotExists';
40
+ validators.validateObject(op, doc);
41
+ validators.requireDocumentId(op, doc);
42
+ return this._add(_defineProperty({}, op, doc));
43
+ },
44
+ createOrReplace: function createOrReplace(doc) {
45
+ var op = 'createOrReplace';
46
+ validators.validateObject(op, doc);
47
+ validators.requireDocumentId(op, doc);
48
+ return this._add(_defineProperty({}, op, doc));
49
+ },
50
+ delete: function _delete(documentId) {
51
+ validators.validateDocumentId('delete', documentId);
52
+ return this._add({
53
+ delete: {
54
+ id: documentId
55
+ }
56
+ });
57
+ },
58
+ patch: function patch(documentId, patchOps) {
59
+ var isBuilder = typeof patchOps === 'function';
60
+ var isPatch = documentId instanceof _patch.default;
61
+
62
+ // transaction.patch(client.patch('documentId').inc({visits: 1}))
63
+ if (isPatch) {
76
64
  return this._add({
77
- delete: {
78
- id: documentId
79
- }
65
+ patch: documentId.serialize()
80
66
  });
81
67
  }
82
- }, {
83
- key: "patch",
84
- value: function patch(documentId, patchOps) {
85
- var isBuilder = typeof patchOps === 'function';
86
- var isPatch = documentId instanceof _patch.Patch; // transaction.patch(client.patch('documentId').inc({visits: 1}))
87
-
88
- if (isPatch) {
89
- return this._add({
90
- patch: documentId.serialize()
91
- });
92
- } // patch => patch.inc({visits: 1}).set({foo: 'bar'})
93
-
94
-
95
- if (isBuilder) {
96
- var patch = patchOps(new _patch.Patch(documentId, {}, this.client));
97
68
 
98
- if (!(patch instanceof _patch.Patch)) {
99
- throw new Error('function passed to `patch()` must return the patch');
100
- }
101
-
102
- return this._add({
103
- patch: patch.serialize()
104
- });
69
+ // patch => patch.inc({visits: 1}).set({foo: 'bar'})
70
+ if (isBuilder) {
71
+ var patch = patchOps(new _patch.default(documentId, {}, this.client));
72
+ if (!(patch instanceof _patch.default)) {
73
+ throw new Error('function passed to `patch()` must return the patch');
105
74
  }
106
-
107
75
  return this._add({
108
- patch: Object.assign({
109
- id: documentId
110
- }, patchOps)
76
+ patch: patch.serialize()
111
77
  });
112
78
  }
113
- }, {
114
- key: "transactionId",
115
- value: function transactionId(id) {
116
- if (!id) {
117
- return this.trxId;
118
- }
119
-
120
- this.trxId = id;
121
- return this;
122
- }
123
- }, {
124
- key: "serialize",
125
- value: function serialize() {
126
- return this.operations.slice();
79
+ return this._add({
80
+ patch: _extends({
81
+ id: documentId
82
+ }, patchOps)
83
+ });
84
+ },
85
+ transactionId: function transactionId(id) {
86
+ if (!id) {
87
+ return this.trxId;
127
88
  }
128
- }, {
129
- key: "toJSON",
130
- value: function toJSON() {
131
- return this.serialize();
89
+ this.trxId = id;
90
+ return this;
91
+ },
92
+ serialize: function serialize() {
93
+ return this.operations.slice();
94
+ },
95
+ toJSON: function toJSON() {
96
+ return this.serialize();
97
+ },
98
+ commit: function commit(options) {
99
+ if (!this.client) {
100
+ throw new Error('No `client` passed to transaction, either provide one or pass the ' + 'transaction to a clients `mutate()` method');
132
101
  }
133
- }, {
134
- key: "commit",
135
- value: function commit(options) {
136
- if (!this.client) {
137
- throw new Error('No `client` passed to transaction, either provide one or pass the ' + 'transaction to a clients `mutate()` method');
138
- }
139
-
140
- return this.client.mutate(this.serialize(), Object.assign({
141
- transactionId: this.trxId
142
- }, defaultMutateOptions, options || {}));
143
- }
144
- }, {
145
- key: "reset",
146
- value: function reset() {
147
- this.operations = [];
148
- return this;
149
- }
150
- }, {
151
- key: "_add",
152
- value: function _add(mut) {
153
- this.operations.push(mut);
154
- return this;
155
- }
156
- }]);
157
-
158
- return Transaction;
159
- }();
160
-
161
- exports.Transaction = Transaction;
102
+ return this.client.mutate(this.serialize(), _extends({
103
+ transactionId: this.trxId
104
+ }, defaultMutateOptions, options || {}));
105
+ },
106
+ reset: function reset() {
107
+ this.operations = [];
108
+ return this;
109
+ },
110
+ _add: function _add(mut) {
111
+ this.operations.push(mut);
112
+ return this;
113
+ }
114
+ });
115
+ var _default = Transaction;
116
+ exports.default = _default;
117
+ module.exports = exports.default;
@@ -1,66 +1,41 @@
1
1
  "use strict";
2
2
 
3
3
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.DatasetsClient = void 0;
9
-
7
+ exports.default = void 0;
10
8
  var validate = _interopRequireWildcard(require("../validators"));
11
-
12
9
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
10
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
-
18
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
19
-
20
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
-
22
- var DatasetsClient = /*#__PURE__*/function () {
23
- function DatasetsClient(client) {
24
- _classCallCheck(this, DatasetsClient);
25
-
26
- this.request = client.request.bind(client);
11
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
12
+ function DatasetsClient(client) {
13
+ this.request = client.request.bind(client);
14
+ }
15
+ _extends(DatasetsClient.prototype, {
16
+ create: function create(name, options) {
17
+ return this._modify('PUT', name, options);
18
+ },
19
+ edit: function edit(name, options) {
20
+ return this._modify('PATCH', name, options);
21
+ },
22
+ delete: function _delete(name) {
23
+ return this._modify('DELETE', name);
24
+ },
25
+ list: function list() {
26
+ return this.request({
27
+ uri: '/datasets'
28
+ });
29
+ },
30
+ _modify: function _modify(method, name, body) {
31
+ validate.dataset(name);
32
+ return this.request({
33
+ method: method,
34
+ uri: "/datasets/".concat(name),
35
+ body: body
36
+ });
27
37
  }
28
-
29
- _createClass(DatasetsClient, [{
30
- key: "create",
31
- value: function create(name, options) {
32
- return this._modify('PUT', name, options);
33
- }
34
- }, {
35
- key: "edit",
36
- value: function edit(name, options) {
37
- return this._modify('PATCH', name, options);
38
- }
39
- }, {
40
- key: "delete",
41
- value: function _delete(name) {
42
- return this._modify('DELETE', name);
43
- }
44
- }, {
45
- key: "list",
46
- value: function list() {
47
- return this.request({
48
- uri: '/datasets'
49
- });
50
- }
51
- }, {
52
- key: "_modify",
53
- value: function _modify(method, name, body) {
54
- validate.dataset(name);
55
- return this.request({
56
- method: method,
57
- uri: "/datasets/".concat(name),
58
- body: body
59
- });
60
- }
61
- }]);
62
-
63
- return DatasetsClient;
64
- }();
65
-
66
- exports.DatasetsClient = DatasetsClient;
38
+ });
39
+ var _default = DatasetsClient;
40
+ exports.default = _default;
41
+ module.exports = exports.default;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = generateHelpUrl;
7
+ var BASE_URL = 'https://docs.sanity.io/help/';
8
+ function generateHelpUrl(slug) {
9
+ return BASE_URL + slug;
10
+ }
11
+ module.exports = exports.default;