@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.
- package/README.md +10 -10
- package/dist/browser/sanityClient.js +2243 -0
- package/dist/node/sanityClient.js +7075 -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 +22 -3
- package/sanityClient.d.ts +1 -13
- package/src/assets/assetsClient.js +132 -0
- package/src/auth/authClient.js +13 -0
- package/src/config.js +93 -0
- package/src/data/dataMethods.js +182 -0
- package/src/data/encodeQueryString.js +18 -0
- package/src/data/listen.js +159 -0
- package/src/data/patch.js +119 -0
- package/src/data/transaction.js +103 -0
- package/src/datasets/datasetsClient.js +28 -0
- package/src/http/browserMiddleware.js +1 -0
- package/src/http/errors.js +53 -0
- package/src/http/nodeMiddleware.js +11 -0
- package/src/http/queryString.js +10 -0
- package/src/http/request.js +50 -0
- package/src/http/requestOptions.js +29 -0
- package/src/projects/projectsClient.js +13 -0
- package/src/sanityClient.js +124 -0
- package/src/users/usersClient.js +9 -0
- package/src/util/defaults.js +9 -0
- package/src/util/getSelection.js +17 -0
- package/src/util/observable.js +6 -0
- package/src/util/once.js +12 -0
- package/src/util/pick.js +9 -0
- package/src/validators.js +76 -0
- package/src/warnings.js +25 -0
- 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/lib/sanityClient.js
CHANGED
|
@@ -1,137 +1,175 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function
|
|
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
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.SanityClient = void 0;
|
|
9
|
+
exports.createClient = createClient;
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
var _observable = require("./util/observable");
|
|
8
12
|
|
|
9
|
-
var
|
|
13
|
+
var _patch = require("./data/patch");
|
|
10
14
|
|
|
11
|
-
var
|
|
12
|
-
Observable = _require.Observable,
|
|
13
|
-
map = _require.map,
|
|
14
|
-
filter = _require.filter;
|
|
15
|
+
var _transaction = require("./data/transaction");
|
|
15
16
|
|
|
16
|
-
var
|
|
17
|
+
var _dataMethods = require("./data/dataMethods");
|
|
17
18
|
|
|
18
|
-
var
|
|
19
|
+
var _datasetsClient = require("./datasets/datasetsClient");
|
|
19
20
|
|
|
20
|
-
var
|
|
21
|
+
var _projectsClient = require("./projects/projectsClient");
|
|
21
22
|
|
|
22
|
-
var
|
|
23
|
+
var _assetsClient = require("./assets/assetsClient");
|
|
23
24
|
|
|
24
|
-
var
|
|
25
|
+
var _usersClient = require("./users/usersClient");
|
|
25
26
|
|
|
26
|
-
var
|
|
27
|
+
var _authClient = require("./auth/authClient");
|
|
27
28
|
|
|
28
|
-
var
|
|
29
|
+
var _request = require("./http/request");
|
|
29
30
|
|
|
30
|
-
var
|
|
31
|
+
var _requestOptions = require("./http/requestOptions");
|
|
31
32
|
|
|
32
|
-
var
|
|
33
|
+
var _config = require("./config");
|
|
33
34
|
|
|
34
|
-
var
|
|
35
|
+
var validate = _interopRequireWildcard(require("./validators"));
|
|
35
36
|
|
|
36
|
-
var
|
|
37
|
-
defaultConfig = _require2.defaultConfig,
|
|
38
|
-
initConfig = _require2.initConfig;
|
|
37
|
+
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); }
|
|
39
38
|
|
|
40
|
-
var
|
|
39
|
+
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; }
|
|
40
|
+
|
|
41
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
42
|
+
|
|
43
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
44
|
+
|
|
45
|
+
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; }
|
|
46
|
+
|
|
47
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
48
|
+
|
|
49
|
+
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); } }
|
|
50
|
+
|
|
51
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
41
52
|
|
|
42
53
|
var toPromise = function toPromise(observable) {
|
|
43
54
|
return observable.toPromise();
|
|
44
55
|
};
|
|
45
56
|
|
|
46
|
-
function
|
|
47
|
-
|
|
57
|
+
var SanityClient = /*#__PURE__*/function () {
|
|
58
|
+
function SanityClient() {
|
|
59
|
+
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _config.defaultConfig;
|
|
48
60
|
|
|
49
|
-
|
|
50
|
-
return new SanityClient(config);
|
|
51
|
-
}
|
|
61
|
+
_classCallCheck(this, SanityClient);
|
|
52
62
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (this.clientConfig.isPromiseAPI) {
|
|
61
|
-
var observableConfig = assign({}, this.clientConfig, {
|
|
62
|
-
isPromiseAPI: false
|
|
63
|
-
});
|
|
64
|
-
this.observable = new SanityClient(observableConfig);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
assign(SanityClient.prototype, dataMethods);
|
|
69
|
-
assign(SanityClient.prototype, {
|
|
70
|
-
clone: function clone() {
|
|
71
|
-
return new SanityClient(this.config());
|
|
72
|
-
},
|
|
73
|
-
config: function config(newConfig) {
|
|
74
|
-
if (typeof newConfig === 'undefined') {
|
|
75
|
-
return assign({}, this.clientConfig);
|
|
76
|
-
}
|
|
63
|
+
this.config(config);
|
|
64
|
+
this.assets = new _assetsClient.AssetsClient(this);
|
|
65
|
+
this.datasets = new _datasetsClient.DatasetsClient(this);
|
|
66
|
+
this.projects = new _projectsClient.ProjectsClient(this);
|
|
67
|
+
this.users = new _usersClient.UsersClient(this);
|
|
68
|
+
this.auth = new _authClient.AuthClient(this);
|
|
77
69
|
|
|
78
|
-
if (this.
|
|
79
|
-
var observableConfig = assign({},
|
|
70
|
+
if (this.clientConfig.isPromiseAPI) {
|
|
71
|
+
var observableConfig = Object.assign({}, this.clientConfig, {
|
|
80
72
|
isPromiseAPI: false
|
|
81
73
|
});
|
|
82
|
-
this.observable
|
|
74
|
+
this.observable = new SanityClient(observableConfig);
|
|
83
75
|
}
|
|
76
|
+
}
|
|
84
77
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
78
|
+
_createClass(SanityClient, [{
|
|
79
|
+
key: "clone",
|
|
80
|
+
value: function clone() {
|
|
81
|
+
return new SanityClient(this.config());
|
|
82
|
+
}
|
|
83
|
+
}, {
|
|
84
|
+
key: "config",
|
|
85
|
+
value: function config(newConfig) {
|
|
86
|
+
if (typeof newConfig === 'undefined') {
|
|
87
|
+
return Object.assign({}, this.clientConfig);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (this.observable) {
|
|
91
|
+
var observableConfig = Object.assign({}, newConfig, {
|
|
92
|
+
isPromiseAPI: false
|
|
93
|
+
});
|
|
94
|
+
this.observable.config(observableConfig);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.clientConfig = (0, _config.initConfig)(newConfig, this.clientConfig || {});
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "withConfig",
|
|
102
|
+
value: function withConfig(newConfig) {
|
|
103
|
+
return this.clone().config(newConfig);
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: "getUrl",
|
|
107
|
+
value: function getUrl(uri) {
|
|
108
|
+
var useCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
109
|
+
var base = useCdn ? this.clientConfig.cdnUrl : this.clientConfig.url;
|
|
110
|
+
return "".concat(base, "/").concat(uri.replace(/^\//, ''));
|
|
113
111
|
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "isPromiseAPI",
|
|
114
|
+
value: function isPromiseAPI() {
|
|
115
|
+
return this.clientConfig.isPromiseAPI;
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
key: "_requestObservable",
|
|
119
|
+
value: function _requestObservable(options) {
|
|
120
|
+
var _this = this;
|
|
121
|
+
|
|
122
|
+
var uri = options.url || options.uri; // If the `canUseCdn`-option is not set we detect it automatically based on the method + URL.
|
|
123
|
+
// Only the /data endpoint is currently available through API-CDN.
|
|
124
|
+
|
|
125
|
+
var canUseCdn = typeof options.canUseCdn === 'undefined' ? ['GET', 'HEAD'].indexOf(options.method || 'GET') >= 0 && uri.indexOf('/data/') === 0 : options.canUseCdn;
|
|
126
|
+
var useCdn = this.clientConfig.useCdn && canUseCdn;
|
|
127
|
+
var tag = options.tag && this.clientConfig.requestTagPrefix ? [this.clientConfig.requestTagPrefix, options.tag].join('.') : options.tag || this.clientConfig.requestTagPrefix;
|
|
128
|
+
|
|
129
|
+
if (tag) {
|
|
130
|
+
options.query = _objectSpread({
|
|
131
|
+
tag: validate.requestTag(tag)
|
|
132
|
+
}, options.query);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var reqOptions = (0, _requestOptions.requestOptions)(this.clientConfig, Object.assign({}, options, {
|
|
136
|
+
url: this.getUrl(uri, useCdn)
|
|
137
|
+
}));
|
|
138
|
+
return new _observable.Observable(function (subscriber) {
|
|
139
|
+
return (0, _request.httpRequest)(reqOptions, _this.clientConfig.requester).subscribe(subscriber);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}, {
|
|
143
|
+
key: "request",
|
|
144
|
+
value: function request(options) {
|
|
145
|
+
var observable = this._requestObservable(options).pipe((0, _observable.filter)(function (event) {
|
|
146
|
+
return event.type === 'response';
|
|
147
|
+
}), (0, _observable.map)(function (event) {
|
|
148
|
+
return event.body;
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
return this.isPromiseAPI() ? toPromise(observable) : observable;
|
|
152
|
+
}
|
|
153
|
+
}]);
|
|
154
|
+
|
|
155
|
+
return SanityClient;
|
|
156
|
+
}();
|
|
157
|
+
|
|
158
|
+
exports.SanityClient = SanityClient;
|
|
159
|
+
Object.assign(SanityClient.prototype, _dataMethods.dataMethods);
|
|
160
|
+
SanityClient.Patch = _patch.Patch;
|
|
161
|
+
SanityClient.Transaction = _transaction.Transaction;
|
|
162
|
+
SanityClient.ClientError = _request.httpRequest.ClientError;
|
|
163
|
+
SanityClient.ServerError = _request.httpRequest.ServerError;
|
|
164
|
+
SanityClient.requester = _request.httpRequest.defaultRequester; // Not using default exports is intentional, as it permits importing from both ESM and CJS node envs with less hazards
|
|
165
|
+
// https://nodejs.org/docs/latest/api/packages.html#writing-dual-packages-while-avoiding-or-minimizing-hazards
|
|
166
|
+
|
|
167
|
+
function createClient(config) {
|
|
168
|
+
return new SanityClient(config);
|
|
169
|
+
}
|
|
114
170
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
request: function request(options) {
|
|
123
|
-
var observable = this._requestObservable(options).pipe(filter(function (event) {
|
|
124
|
-
return event.type === 'response';
|
|
125
|
-
}), map(function (event) {
|
|
126
|
-
return event.body;
|
|
127
|
-
}));
|
|
128
|
-
|
|
129
|
-
return this.isPromiseAPI() ? toPromise(observable) : observable;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
SanityClient.Patch = Patch;
|
|
133
|
-
SanityClient.Transaction = Transaction;
|
|
134
|
-
SanityClient.ClientError = httpRequest.ClientError;
|
|
135
|
-
SanityClient.ServerError = httpRequest.ServerError;
|
|
136
|
-
SanityClient.requester = httpRequest.defaultRequester;
|
|
137
|
-
module.exports = SanityClient;
|
|
171
|
+
createClient.Patch = _patch.Patch;
|
|
172
|
+
createClient.Transaction = _transaction.Transaction;
|
|
173
|
+
createClient.ClientError = _request.httpRequest.ClientError;
|
|
174
|
+
createClient.ServerError = _request.httpRequest.ServerError;
|
|
175
|
+
createClient.requester = _request.httpRequest.defaultRequester;
|
package/lib/users/usersClient.js
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UsersClient = 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; }
|
|
4
13
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
var UsersClient = /*#__PURE__*/function () {
|
|
15
|
+
function UsersClient(client) {
|
|
16
|
+
_classCallCheck(this, UsersClient);
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
getById: function getById(id) {
|
|
11
|
-
return this.client.request({
|
|
12
|
-
uri: "/users/".concat(id)
|
|
13
|
-
});
|
|
18
|
+
this.client = client;
|
|
14
19
|
}
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
|
|
21
|
+
_createClass(UsersClient, [{
|
|
22
|
+
key: "getById",
|
|
23
|
+
value: function getById(id) {
|
|
24
|
+
return this.client.request({
|
|
25
|
+
uri: "/users/".concat(id)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}]);
|
|
29
|
+
|
|
30
|
+
return UsersClient;
|
|
31
|
+
}();
|
|
32
|
+
|
|
33
|
+
exports.UsersClient = UsersClient;
|
package/lib/util/defaults.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defaults = void 0;
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line no-shadow
|
|
9
|
+
var defaults = function defaults(obj, _defaults) {
|
|
10
|
+
return Object.keys(_defaults).concat(Object.keys(obj)).reduce(function (target, prop) {
|
|
11
|
+
target[prop] = typeof obj[prop] === 'undefined' ? _defaults[prop] : obj[prop];
|
|
6
12
|
return target;
|
|
7
13
|
}, {});
|
|
8
|
-
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.defaults = defaults;
|
package/lib/util/getSelection.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSelection = getSelection;
|
|
7
|
+
|
|
8
|
+
function getSelection(sel) {
|
|
4
9
|
if (typeof sel === 'string' || Array.isArray(sel)) {
|
|
5
10
|
return {
|
|
6
11
|
id: sel
|
|
@@ -18,4 +23,4 @@ module.exports = function getSelection(sel) {
|
|
|
18
23
|
|
|
19
24
|
var selectionOpts = ['* Document ID (<docId>)', '* Array of document IDs', '* Object containing `query`'].join('\n');
|
|
20
25
|
throw new Error("Unknown selection - must be one of:\n\n".concat(selectionOpts));
|
|
21
|
-
}
|
|
26
|
+
}
|
package/lib/util/observable.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Observable", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _Observable.Observable;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "filter", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _filter.filter;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "map", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _map.map;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
7
24
|
|
|
8
|
-
var
|
|
9
|
-
filter = _require2.filter;
|
|
25
|
+
var _Observable = require("rxjs/internal/Observable");
|
|
10
26
|
|
|
11
|
-
var
|
|
12
|
-
map = _require3.map;
|
|
27
|
+
var _filter = require("rxjs/internal/operators/filter");
|
|
13
28
|
|
|
14
|
-
|
|
15
|
-
Observable: Observable,
|
|
16
|
-
filter: filter,
|
|
17
|
-
map: map
|
|
18
|
-
};
|
|
29
|
+
var _map = require("rxjs/internal/operators/map");
|
package/lib/util/once.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.once = void 0;
|
|
7
|
+
|
|
8
|
+
var once = function once(fn) {
|
|
4
9
|
var didCall = false;
|
|
5
10
|
var returnValue;
|
|
6
11
|
return function () {
|
|
@@ -12,4 +17,6 @@ module.exports = function (fn) {
|
|
|
12
17
|
didCall = true;
|
|
13
18
|
return returnValue;
|
|
14
19
|
};
|
|
15
|
-
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.once = once;
|
package/lib/util/pick.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.pick = void 0;
|
|
7
|
+
|
|
8
|
+
var pick = function pick(obj, props) {
|
|
4
9
|
return props.reduce(function (selection, prop) {
|
|
5
10
|
if (typeof obj[prop] === 'undefined') {
|
|
6
11
|
return selection;
|
|
@@ -9,4 +14,6 @@ module.exports = function (obj, props) {
|
|
|
9
14
|
selection[prop] = obj[prop];
|
|
10
15
|
return selection;
|
|
11
16
|
}, {});
|
|
12
|
-
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.pick = pick;
|
package/lib/validators.js
CHANGED
|
@@ -1,49 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateObject = exports.validateInsert = exports.validateDocumentId = exports.validateAssetType = exports.requireDocumentId = exports.requestTag = exports.projectId = exports.hasDataset = exports.dataset = void 0;
|
|
7
|
+
|
|
3
8
|
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
9
|
|
|
5
10
|
var VALID_ASSET_TYPES = ['image', 'file'];
|
|
6
11
|
var VALID_INSERT_LOCATIONS = ['before', 'after', 'replace'];
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
var dataset = function dataset(name) {
|
|
9
14
|
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
|
|
10
15
|
throw new Error('Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters');
|
|
11
16
|
}
|
|
12
17
|
};
|
|
13
18
|
|
|
14
|
-
exports.
|
|
19
|
+
exports.dataset = dataset;
|
|
20
|
+
|
|
21
|
+
var projectId = function projectId(id) {
|
|
15
22
|
if (!/^[-a-z0-9]+$/i.test(id)) {
|
|
16
23
|
throw new Error('`projectId` can only contain only a-z, 0-9 and dashes');
|
|
17
24
|
}
|
|
18
25
|
};
|
|
19
26
|
|
|
20
|
-
exports.
|
|
27
|
+
exports.projectId = projectId;
|
|
28
|
+
|
|
29
|
+
var validateAssetType = function validateAssetType(type) {
|
|
21
30
|
if (VALID_ASSET_TYPES.indexOf(type) === -1) {
|
|
22
31
|
throw new Error("Invalid asset type: ".concat(type, ". Must be one of ").concat(VALID_ASSET_TYPES.join(', ')));
|
|
23
32
|
}
|
|
24
33
|
};
|
|
25
34
|
|
|
26
|
-
exports.
|
|
35
|
+
exports.validateAssetType = validateAssetType;
|
|
36
|
+
|
|
37
|
+
var validateObject = function validateObject(op, val) {
|
|
27
38
|
if (val === null || _typeof(val) !== 'object' || Array.isArray(val)) {
|
|
28
39
|
throw new Error("".concat(op, "() takes an object of properties"));
|
|
29
40
|
}
|
|
30
41
|
};
|
|
31
42
|
|
|
32
|
-
exports.
|
|
43
|
+
exports.validateObject = validateObject;
|
|
44
|
+
|
|
45
|
+
var validateDocumentId = function validateDocumentId(op, id) {
|
|
46
|
+
if (typeof id !== 'string' || !/^[a-z0-9_.-]+$/i.test(id)) {
|
|
47
|
+
throw new Error("".concat(op, "(): \"").concat(id, "\" is not a valid document ID"));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.validateDocumentId = validateDocumentId;
|
|
52
|
+
|
|
53
|
+
var requireDocumentId = function requireDocumentId(op, doc) {
|
|
33
54
|
if (!doc._id) {
|
|
34
55
|
throw new Error("".concat(op, "() requires that the document contains an ID (\"_id\" property)"));
|
|
35
56
|
}
|
|
36
57
|
|
|
37
|
-
|
|
58
|
+
validateDocumentId(op, doc._id);
|
|
38
59
|
};
|
|
39
60
|
|
|
40
|
-
exports.
|
|
41
|
-
if (typeof id !== 'string' || !/^[a-z0-9_.-]+$/i.test(id)) {
|
|
42
|
-
throw new Error("".concat(op, "(): \"").concat(id, "\" is not a valid document ID"));
|
|
43
|
-
}
|
|
44
|
-
};
|
|
61
|
+
exports.requireDocumentId = requireDocumentId;
|
|
45
62
|
|
|
46
|
-
|
|
63
|
+
var validateInsert = function validateInsert(at, selector, items) {
|
|
47
64
|
var signature = 'insert(at, selector, items)';
|
|
48
65
|
|
|
49
66
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
@@ -62,7 +79,9 @@ exports.validateInsert = function (at, selector, items) {
|
|
|
62
79
|
}
|
|
63
80
|
};
|
|
64
81
|
|
|
65
|
-
exports.
|
|
82
|
+
exports.validateInsert = validateInsert;
|
|
83
|
+
|
|
84
|
+
var hasDataset = function hasDataset(config) {
|
|
66
85
|
if (!config.dataset) {
|
|
67
86
|
throw new Error('`dataset` must be provided to perform queries');
|
|
68
87
|
}
|
|
@@ -70,10 +89,14 @@ exports.hasDataset = function (config) {
|
|
|
70
89
|
return config.dataset || '';
|
|
71
90
|
};
|
|
72
91
|
|
|
73
|
-
exports.
|
|
92
|
+
exports.hasDataset = hasDataset;
|
|
93
|
+
|
|
94
|
+
var requestTag = function requestTag(tag) {
|
|
74
95
|
if (typeof tag !== 'string' || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
|
|
75
96
|
throw new Error("Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.");
|
|
76
97
|
}
|
|
77
98
|
|
|
78
99
|
return tag;
|
|
79
|
-
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
exports.requestTag = requestTag;
|
package/lib/warnings.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.printNoApiVersionSpecifiedWarning = exports.printCdnWarning = exports.printBrowserTokenWarning = void 0;
|
|
4
7
|
|
|
5
|
-
var
|
|
8
|
+
var _generateHelpUrl = require("@sanity/generate-help-url");
|
|
9
|
+
|
|
10
|
+
var _once = require("./util/once");
|
|
6
11
|
|
|
7
12
|
var createWarningPrinter = function createWarningPrinter(message) {
|
|
8
13
|
return (// eslint-disable-next-line no-console
|
|
9
|
-
once(function () {
|
|
14
|
+
(0, _once.once)(function () {
|
|
10
15
|
var _console;
|
|
11
16
|
|
|
12
17
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -18,6 +23,9 @@ var createWarningPrinter = function createWarningPrinter(message) {
|
|
|
18
23
|
);
|
|
19
24
|
};
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
exports.
|
|
23
|
-
|
|
26
|
+
var printCdnWarning = createWarningPrinter(['You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and', "cheaper. Think about it! For more info, see ".concat((0, _generateHelpUrl.generateHelpUrl)('js-client-cdn-configuration'), "."), 'To hide this warning, please set the `useCdn` option to either `true` or `false` when creating', 'the client.']);
|
|
27
|
+
exports.printCdnWarning = printCdnWarning;
|
|
28
|
+
var printBrowserTokenWarning = createWarningPrinter(['You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.', "See ".concat((0, _generateHelpUrl.generateHelpUrl)('js-client-browser-token'), " for more information and how to hide this warning.")]);
|
|
29
|
+
exports.printBrowserTokenWarning = printBrowserTokenWarning;
|
|
30
|
+
var printNoApiVersionSpecifiedWarning = createWarningPrinter(['Using the Sanity client without specifying an API version is deprecated.', "See ".concat((0, _generateHelpUrl.generateHelpUrl)('js-client-api-version'))]);
|
|
31
|
+
exports.printNoApiVersionSpecifiedWarning = printNoApiVersionSpecifiedWarning;
|