@sanity/client 3.3.0 → 4.0.0-alpha.esm.3

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 (62) hide show
  1. package/README.md +10 -10
  2. package/dist/browser/sanityClient.js +2243 -0
  3. package/dist/node/sanityClient.js +7075 -0
  4. package/lib/assets/assetsClient.js +132 -106
  5. package/lib/auth/authClient.js +38 -19
  6. package/lib/config.js +25 -13
  7. package/lib/data/dataMethods.js +32 -24
  8. package/lib/data/encodeQueryString.js +8 -2
  9. package/lib/data/listen.js +25 -21
  10. package/lib/data/patch.js +169 -118
  11. package/lib/data/transaction.js +134 -88
  12. package/lib/datasets/datasetsClient.js +63 -32
  13. package/lib/http/browserMiddleware.js +6 -1
  14. package/lib/http/errors.js +12 -8
  15. package/lib/http/nodeMiddleware.js +16 -9
  16. package/lib/http/queryString.js +9 -2
  17. package/lib/http/request.js +27 -24
  18. package/lib/http/requestOptions.js +10 -6
  19. package/lib/projects/projectsClient.js +37 -18
  20. package/lib/sanityClient.js +143 -105
  21. package/lib/users/usersClient.js +28 -11
  22. package/lib/util/defaults.js +12 -4
  23. package/lib/util/getSelection.js +7 -2
  24. package/lib/util/observable.js +24 -13
  25. package/lib/util/once.js +9 -2
  26. package/lib/util/pick.js +9 -2
  27. package/lib/validators.js +38 -15
  28. package/lib/warnings.js +14 -6
  29. package/package.json +22 -3
  30. package/sanityClient.d.ts +1 -13
  31. package/src/assets/assetsClient.js +132 -0
  32. package/src/auth/authClient.js +13 -0
  33. package/src/config.js +93 -0
  34. package/src/data/dataMethods.js +182 -0
  35. package/src/data/encodeQueryString.js +18 -0
  36. package/src/data/listen.js +159 -0
  37. package/src/data/patch.js +119 -0
  38. package/src/data/transaction.js +103 -0
  39. package/src/datasets/datasetsClient.js +28 -0
  40. package/src/http/browserMiddleware.js +1 -0
  41. package/src/http/errors.js +53 -0
  42. package/src/http/nodeMiddleware.js +11 -0
  43. package/src/http/queryString.js +10 -0
  44. package/src/http/request.js +50 -0
  45. package/src/http/requestOptions.js +29 -0
  46. package/src/projects/projectsClient.js +13 -0
  47. package/src/sanityClient.js +124 -0
  48. package/src/users/usersClient.js +9 -0
  49. package/src/util/defaults.js +9 -0
  50. package/src/util/getSelection.js +17 -0
  51. package/src/util/observable.js +6 -0
  52. package/src/util/once.js +12 -0
  53. package/src/util/pick.js +9 -0
  54. package/src/validators.js +76 -0
  55. package/src/warnings.js +25 -0
  56. package/test/client.test.js +37 -37
  57. package/test/encodeQueryString.test.js +3 -1
  58. package/test/helpers/sseServer.js +2 -1
  59. package/test/listen.test.js +4 -2
  60. package/test/warnings.test.disabled.js +8 -4
  61. package/umd/sanityClient.js +38 -38
  62. package/umd/sanityClient.min.js +1 -1
@@ -1,5 +1,22 @@
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); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.AssetsClient = void 0;
9
+
10
+ var _observable = require("../util/observable");
11
+
12
+ var _queryString = require("../http/queryString");
13
+
14
+ var validators = _interopRequireWildcard(require("../validators"));
15
+
16
+ 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); }
17
+
18
+ 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; }
19
+
3
20
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
21
 
5
22
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -12,32 +29,18 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
12
29
 
13
30
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
31
 
15
- var assign = require('object-assign');
32
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
33
 
17
- var _require = require('../util/observable'),
18
- map = _require.map,
19
- filter = _require.filter;
34
+ 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); } }
20
35
 
21
- var queryString = require('../http/queryString');
36
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
22
37
 
23
- var validators = require('../validators');
38
+ var AssetsClient = /*#__PURE__*/function () {
39
+ function AssetsClient(client) {
40
+ _classCallCheck(this, AssetsClient);
24
41
 
25
- function AssetsClient(client) {
26
- this.client = client;
27
- }
28
-
29
- function optionsFromFile(opts, file) {
30
- if (typeof window === 'undefined' || !(file instanceof window.File)) {
31
- return opts;
42
+ this.client = client;
32
43
  }
33
-
34
- return assign({
35
- filename: opts.preserveFilename === false ? undefined : file.name,
36
- contentType: file.type
37
- }, opts);
38
- }
39
-
40
- assign(AssetsClient.prototype, {
41
44
  /**
42
45
  * Upload an asset
43
46
  *
@@ -63,97 +66,120 @@ assign(AssetsClient.prototype, {
63
66
  * Optional
64
67
  * @return {Promise} Resolves with the created asset document
65
68
  */
66
- upload: function upload(assetType, body) {
67
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
68
- validators.validateAssetType(assetType); // If an empty array is given, explicitly set `none` to override API defaults
69
69
 
70
- var meta = opts.extract || undefined;
71
70
 
72
- if (meta && !meta.length) {
73
- meta = ['none'];
71
+ _createClass(AssetsClient, [{
72
+ key: "upload",
73
+ value: function upload(assetType, body) {
74
+ var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
75
+ validators.validateAssetType(assetType); // If an empty array is given, explicitly set `none` to override API defaults
76
+
77
+ var meta = opts.extract || undefined;
78
+
79
+ if (meta && !meta.length) {
80
+ meta = ['none'];
81
+ }
82
+
83
+ var dataset = validators.hasDataset(this.client.clientConfig);
84
+ var assetEndpoint = assetType === 'image' ? 'images' : 'files';
85
+ var options = optionsFromFile(opts, body);
86
+ var tag = options.tag,
87
+ label = options.label,
88
+ title = options.title,
89
+ description = options.description,
90
+ creditLine = options.creditLine,
91
+ filename = options.filename,
92
+ source = options.source;
93
+ var query = {
94
+ label: label,
95
+ title: title,
96
+ description: description,
97
+ filename: filename,
98
+ meta: meta,
99
+ creditLine: creditLine
100
+ };
101
+
102
+ if (source) {
103
+ query.sourceId = source.id;
104
+ query.sourceName = source.name;
105
+ query.sourceUrl = source.url;
106
+ }
107
+
108
+ var observable = this.client._requestObservable({
109
+ tag: tag,
110
+ method: 'POST',
111
+ timeout: options.timeout || 0,
112
+ uri: "/assets/".concat(assetEndpoint, "/").concat(dataset),
113
+ headers: options.contentType ? {
114
+ 'Content-Type': options.contentType
115
+ } : {},
116
+ query: query,
117
+ body: body
118
+ });
119
+
120
+ return this.client.isPromiseAPI() ? observable.pipe((0, _observable.filter)(function (event) {
121
+ return event.type === 'response';
122
+ }), (0, _observable.map)(function (event) {
123
+ return event.body.document;
124
+ })).toPromise() : observable;
74
125
  }
75
-
76
- var dataset = validators.hasDataset(this.client.clientConfig);
77
- var assetEndpoint = assetType === 'image' ? 'images' : 'files';
78
- var options = optionsFromFile(opts, body);
79
- var tag = options.tag,
80
- label = options.label,
81
- title = options.title,
82
- description = options.description,
83
- creditLine = options.creditLine,
84
- filename = options.filename,
85
- source = options.source;
86
- var query = {
87
- label: label,
88
- title: title,
89
- description: description,
90
- filename: filename,
91
- meta: meta,
92
- creditLine: creditLine
93
- };
94
-
95
- if (source) {
96
- query.sourceId = source.id;
97
- query.sourceName = source.name;
98
- query.sourceUrl = source.url;
126
+ }, {
127
+ key: "delete",
128
+ value: function _delete(type, id) {
129
+ // eslint-disable-next-line no-console
130
+ console.warn('client.assets.delete() is deprecated, please use client.delete(<document-id>)');
131
+ var docId = id || '';
132
+
133
+ if (!/^(image|file)-/.test(docId)) {
134
+ docId = "".concat(type, "-").concat(docId);
135
+ } else if (type._id) {
136
+ // We could be passing an entire asset document instead of an ID
137
+ docId = type._id;
138
+ }
139
+
140
+ validators.hasDataset(this.client.clientConfig);
141
+ return this.client.delete(docId);
99
142
  }
100
-
101
- var observable = this.client._requestObservable({
102
- tag: tag,
103
- method: 'POST',
104
- timeout: options.timeout || 0,
105
- uri: "/assets/".concat(assetEndpoint, "/").concat(dataset),
106
- headers: options.contentType ? {
107
- 'Content-Type': options.contentType
108
- } : {},
109
- query: query,
110
- body: body
111
- });
112
-
113
- return this.client.isPromiseAPI() ? observable.pipe(filter(function (event) {
114
- return event.type === 'response';
115
- }), map(function (event) {
116
- return event.body.document;
117
- })).toPromise() : observable;
118
- },
119
- delete: function _delete(type, id) {
120
- // eslint-disable-next-line no-console
121
- console.warn('client.assets.delete() is deprecated, please use client.delete(<document-id>)');
122
- var docId = id || '';
123
-
124
- if (!/^(image|file)-/.test(docId)) {
125
- docId = "".concat(type, "-").concat(docId);
126
- } else if (type._id) {
127
- // We could be passing an entire asset document instead of an ID
128
- docId = type._id;
143
+ }, {
144
+ key: "getImageUrl",
145
+ value: function getImageUrl(ref, query) {
146
+ var id = ref._ref || ref;
147
+
148
+ if (typeof id !== 'string') {
149
+ throw new Error('getImageUrl() needs either an object with a _ref, or a string with an asset document ID');
150
+ }
151
+
152
+ if (!/^image-[A-Za-z0-9_]+-\d+x\d+-[a-z]{1,5}$/.test(id)) {
153
+ throw new Error("Unsupported asset ID \"".concat(id, "\". URL generation only works for auto-generated IDs."));
154
+ }
155
+
156
+ var _id$split = id.split('-'),
157
+ _id$split2 = _slicedToArray(_id$split, 4),
158
+ assetId = _id$split2[1],
159
+ size = _id$split2[2],
160
+ format = _id$split2[3];
161
+
162
+ validators.hasDataset(this.client.clientConfig);
163
+ var _this$client$clientCo = this.client.clientConfig,
164
+ projectId = _this$client$clientCo.projectId,
165
+ dataset = _this$client$clientCo.dataset;
166
+ var qs = query ? (0, _queryString.queryString)(query) : '';
167
+ return "https://cdn.sanity.io/images/".concat(projectId, "/").concat(dataset, "/").concat(assetId, "-").concat(size, ".").concat(format).concat(qs);
129
168
  }
169
+ }]);
130
170
 
131
- validators.hasDataset(this.client.clientConfig);
132
- return this.client.delete(docId);
133
- },
134
- getImageUrl: function getImageUrl(ref, query) {
135
- var id = ref._ref || ref;
171
+ return AssetsClient;
172
+ }();
136
173
 
137
- if (typeof id !== 'string') {
138
- throw new Error('getImageUrl() needs either an object with a _ref, or a string with an asset document ID');
139
- }
140
-
141
- if (!/^image-[A-Za-z0-9_]+-\d+x\d+-[a-z]{1,5}$/.test(id)) {
142
- throw new Error("Unsupported asset ID \"".concat(id, "\". URL generation only works for auto-generated IDs."));
143
- }
174
+ exports.AssetsClient = AssetsClient;
144
175
 
145
- var _id$split = id.split('-'),
146
- _id$split2 = _slicedToArray(_id$split, 4),
147
- assetId = _id$split2[1],
148
- size = _id$split2[2],
149
- format = _id$split2[3];
150
-
151
- validators.hasDataset(this.client.clientConfig);
152
- var _this$client$clientCo = this.client.clientConfig,
153
- projectId = _this$client$clientCo.projectId,
154
- dataset = _this$client$clientCo.dataset;
155
- var qs = query ? queryString(query) : '';
156
- return "https://cdn.sanity.io/images/".concat(projectId, "/").concat(dataset, "/").concat(assetId, "-").concat(size, ".").concat(format).concat(qs);
176
+ function optionsFromFile(opts, file) {
177
+ if (typeof window === 'undefined' || !(file instanceof window.File)) {
178
+ return opts;
157
179
  }
158
- });
159
- module.exports = AssetsClient;
180
+
181
+ return Object.assign({
182
+ filename: opts.preserveFilename === false ? undefined : file.name,
183
+ contentType: file.type
184
+ }, opts);
185
+ }
@@ -1,22 +1,41 @@
1
1
  "use strict";
2
2
 
3
- var assign = require('object-assign');
4
-
5
- function AuthClient(client) {
6
- this.client = client;
7
- }
8
-
9
- assign(AuthClient.prototype, {
10
- getLoginProviders: function getLoginProviders() {
11
- return this.client.request({
12
- uri: '/auth/providers'
13
- });
14
- },
15
- logout: function logout() {
16
- return this.client.request({
17
- uri: '/auth/logout',
18
- method: 'POST'
19
- });
20
- }
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
21
5
  });
22
- module.exports = AuthClient;
6
+ exports.AuthClient = void 0;
7
+
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+
10
+ 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); } }
11
+
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+
14
+ var AuthClient = /*#__PURE__*/function () {
15
+ function AuthClient(client) {
16
+ _classCallCheck(this, AuthClient);
17
+
18
+ this.client = client;
19
+ }
20
+
21
+ _createClass(AuthClient, [{
22
+ key: "getLoginProviders",
23
+ value: function getLoginProviders() {
24
+ return this.client.request({
25
+ uri: '/auth/providers'
26
+ });
27
+ }
28
+ }, {
29
+ key: "logout",
30
+ value: function logout() {
31
+ return this.client.request({
32
+ uri: '/auth/logout',
33
+ method: 'POST'
34
+ });
35
+ }
36
+ }]);
37
+
38
+ return AuthClient;
39
+ }();
40
+
41
+ exports.AuthClient = AuthClient;
package/lib/config.js CHANGED
@@ -1,12 +1,22 @@
1
1
  "use strict";
2
2
 
3
- var generateHelpUrl = require('@sanity/generate-help-url').generateHelpUrl;
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
4
 
5
- var assign = require('object-assign');
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.initConfig = exports.defaultConfig = void 0;
9
+ exports.validateApiVersion = validateApiVersion;
6
10
 
7
- var validate = require('./validators');
11
+ var _generateHelpUrl = require("@sanity/generate-help-url");
8
12
 
9
- var warnings = require('./warnings');
13
+ var validate = _interopRequireWildcard(require("./validators"));
14
+
15
+ var warnings = _interopRequireWildcard(require("./warnings"));
16
+
17
+ 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); }
18
+
19
+ 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; }
10
20
 
11
21
  var defaultCdnHost = 'apicdn.sanity.io';
12
22
  var defaultConfig = {
@@ -15,26 +25,26 @@ var defaultConfig = {
15
25
  useProjectHostname: true,
16
26
  isPromiseAPI: true
17
27
  };
28
+ exports.defaultConfig = defaultConfig;
18
29
  var LOCALHOSTS = ['localhost', '127.0.0.1', '0.0.0.0'];
19
30
 
20
31
  var isLocal = function isLocal(host) {
21
32
  return LOCALHOSTS.indexOf(host) !== -1;
22
- };
33
+ }; // eslint-disable-next-line complexity
23
34
 
24
- exports.defaultConfig = defaultConfig; // eslint-disable-next-line complexity
25
35
 
26
- exports.initConfig = function (config, prevConfig) {
27
- var specifiedConfig = assign({}, prevConfig, config);
36
+ var initConfig = function initConfig(config, prevConfig) {
37
+ var specifiedConfig = Object.assign({}, prevConfig, config);
28
38
 
29
39
  if (!specifiedConfig.apiVersion) {
30
40
  warnings.printNoApiVersionSpecifiedWarning();
31
41
  }
32
42
 
33
- var newConfig = assign({}, defaultConfig, specifiedConfig);
43
+ var newConfig = Object.assign({}, defaultConfig, specifiedConfig);
34
44
  var projectBased = newConfig.useProjectHostname;
35
45
 
36
46
  if (typeof Promise === 'undefined') {
37
- var helpUrl = generateHelpUrl('js-client-promise-polyfill');
47
+ var helpUrl = (0, _generateHelpUrl.generateHelpUrl)('js-client-promise-polyfill');
38
48
  throw new Error("No native Promise-implementation found, polyfill needed - see ".concat(helpUrl));
39
49
  }
40
50
 
@@ -67,7 +77,7 @@ exports.initConfig = function (config, prevConfig) {
67
77
  newConfig.apiVersion = "".concat(newConfig.apiVersion).replace(/^v/, '');
68
78
  newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
69
79
  newConfig.useCdn = Boolean(newConfig.useCdn) && !newConfig.withCredentials;
70
- exports.validateApiVersion(newConfig.apiVersion);
80
+ validateApiVersion(newConfig.apiVersion);
71
81
  var hostParts = newConfig.apiHost.split('://', 2);
72
82
  var protocol = hostParts[0];
73
83
  var host = hostParts[1];
@@ -84,7 +94,9 @@ exports.initConfig = function (config, prevConfig) {
84
94
  return newConfig;
85
95
  };
86
96
 
87
- exports.validateApiVersion = function validateApiVersion(apiVersion) {
97
+ exports.initConfig = initConfig;
98
+
99
+ function validateApiVersion(apiVersion) {
88
100
  if (apiVersion === '1' || apiVersion === 'X') {
89
101
  return;
90
102
  }
@@ -95,4 +107,4 @@ exports.validateApiVersion = function validateApiVersion(apiVersion) {
95
107
  if (!apiVersionValid) {
96
108
  throw new Error('Invalid API version string, expected `1` or date in format `YYYY-MM-DD`');
97
109
  }
98
- };
110
+ }
@@ -1,24 +1,31 @@
1
1
  "use strict";
2
2
 
3
- 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; }
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
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.dataMethods = void 0;
9
+
10
+ var _observable = require("../util/observable");
4
11
 
5
- var assign = require('object-assign');
12
+ var validators = _interopRequireWildcard(require("../validators"));
6
13
 
7
- var _require = require('../util/observable'),
8
- map = _require.map,
9
- filter = _require.filter;
14
+ var _getSelection = require("../util/getSelection");
10
15
 
11
- var validators = require('../validators');
16
+ var _encodeQueryString = require("./encodeQueryString");
12
17
 
13
- var getSelection = require('../util/getSelection');
18
+ var _transaction = require("./transaction");
14
19
 
15
- var encodeQueryString = require('./encodeQueryString');
20
+ var _patch = require("./patch");
16
21
 
17
- var Transaction = require('./transaction');
22
+ var _listen = require("./listen");
18
23
 
19
- var Patch = require('./patch');
24
+ 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); }
20
25
 
21
- var listen = require('./listen');
26
+ 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; }
27
+
28
+ 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; }
22
29
 
23
30
  var excludeFalsey = function excludeFalsey(param, defValue) {
24
31
  var value = typeof param === 'undefined' ? defValue : param;
@@ -57,8 +64,8 @@ var toPromise = function toPromise(observable) {
57
64
  };
58
65
 
59
66
  var getQuerySizeLimit = 11264;
60
- module.exports = {
61
- listen: listen,
67
+ var dataMethods = {
68
+ listen: _listen.listen,
62
69
  getDataUrl: function getDataUrl(operation, path) {
63
70
  var config = this.clientConfig;
64
71
  var catalog = validators.hasDataset(config);
@@ -77,7 +84,7 @@ module.exports = {
77
84
  var observable = this._dataRequest('query', {
78
85
  query: query,
79
86
  params: params
80
- }, options).pipe(map(mapResponse));
87
+ }, options).pipe((0, _observable.map)(mapResponse));
81
88
 
82
89
  return this.isPromiseAPI() ? toPromise(observable) : observable;
83
90
  },
@@ -89,7 +96,7 @@ module.exports = {
89
96
  tag: opts.tag
90
97
  };
91
98
 
92
- var observable = this._requestObservable(options).pipe(filter(isResponse), map(function (event) {
99
+ var observable = this._requestObservable(options).pipe((0, _observable.filter)(isResponse), (0, _observable.map)(function (event) {
93
100
  return event.body.documents && event.body.documents[0];
94
101
  }));
95
102
 
@@ -103,7 +110,7 @@ module.exports = {
103
110
  tag: opts.tag
104
111
  };
105
112
 
106
- var observable = this._requestObservable(options).pipe(filter(isResponse), map(function (event) {
113
+ var observable = this._requestObservable(options).pipe((0, _observable.filter)(isResponse), (0, _observable.map)(function (event) {
107
114
  var indexed = indexBy(event.body.documents || [], function (doc) {
108
115
  return doc._id;
109
116
  });
@@ -126,17 +133,17 @@ module.exports = {
126
133
  return this._create(doc, 'createOrReplace', options);
127
134
  },
128
135
  patch: function patch(selector, operations) {
129
- return new Patch(selector, operations, this);
136
+ return new _patch.Patch(selector, operations, this);
130
137
  },
131
138
  delete: function _delete(selection, options) {
132
139
  return this.dataRequest('mutate', {
133
140
  mutations: [{
134
- delete: getSelection(selection)
141
+ delete: (0, _getSelection.getSelection)(selection)
135
142
  }]
136
143
  }, options);
137
144
  },
138
145
  mutate: function mutate(mutations, options) {
139
- var mut = mutations instanceof Patch || mutations instanceof Transaction ? mutations.serialize() : mutations;
146
+ var mut = mutations instanceof _patch.Patch || mutations instanceof _transaction.Transaction ? mutations.serialize() : mutations;
140
147
  var muts = Array.isArray(mut) ? mut : [mut];
141
148
  var transactionId = options && options.transactionId;
142
149
  return this.dataRequest('mutate', {
@@ -145,7 +152,7 @@ module.exports = {
145
152
  }, options);
146
153
  },
147
154
  transaction: function transaction(operations) {
148
- return new Transaction(operations, this);
155
+ return new _transaction.Transaction(operations, this);
149
156
  },
150
157
  dataRequest: function dataRequest(endpoint, body) {
151
158
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -160,7 +167,7 @@ module.exports = {
160
167
  var isQuery = endpoint === 'query'; // Check if the query string is within a configured threshold,
161
168
  // in which case we can use GET. Otherwise, use POST.
162
169
 
163
- var strQuery = !isMutation && encodeQueryString(body);
170
+ var strQuery = !isMutation && (0, _encodeQueryString.encodeQueryString)(body);
164
171
  var useGet = !isMutation && strQuery.length < getQuerySizeLimit;
165
172
  var stringQuery = useGet ? strQuery : '';
166
173
  var returnFirst = options.returnFirst;
@@ -181,7 +188,7 @@ module.exports = {
181
188
  tag: tag,
182
189
  canUseCdn: isQuery
183
190
  };
184
- return this._requestObservable(reqOptions).pipe(filter(isResponse), map(getBody), map(function (res) {
191
+ return this._requestObservable(reqOptions).pipe((0, _observable.filter)(isResponse), (0, _observable.map)(getBody), (0, _observable.map)(function (res) {
185
192
  if (!isMutation) {
186
193
  return res;
187
194
  } // Should we return documents?
@@ -211,7 +218,7 @@ module.exports = {
211
218
 
212
219
  var mutation = _defineProperty({}, op, doc);
213
220
 
214
- var opts = assign({
221
+ var opts = Object.assign({
215
222
  returnFirst: true,
216
223
  returnDocuments: true
217
224
  }, options);
@@ -219,4 +226,5 @@ module.exports = {
219
226
  mutations: [mutation]
220
227
  }, opts);
221
228
  }
222
- };
229
+ };
230
+ exports.dataMethods = dataMethods;
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.encodeQueryString = void 0;
3
7
  var _excluded = ["tag"];
4
8
 
5
9
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
@@ -8,7 +12,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
8
12
 
9
13
  var enc = encodeURIComponent;
10
14
 
11
- module.exports = function (_ref) {
15
+ var encodeQueryString = function encodeQueryString(_ref) {
12
16
  var query = _ref.query,
13
17
  _ref$params = _ref.params,
14
18
  params = _ref$params === void 0 ? {} : _ref$params,
@@ -28,4 +32,6 @@ module.exports = function (_ref) {
28
32
  // Only include the option if it is truthy
29
33
  return options[option] ? "".concat(qs, "&").concat(enc(option), "=").concat(enc(options[option])) : qs;
30
34
  }, qString);
31
- };
35
+ };
36
+
37
+ exports.encodeQueryString = encodeQueryString;