@sanity/client 6.11.3-canary.0 → 6.11.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/dist/_chunks/{browserMiddleware-hi8PGbSU.cjs → browserMiddleware-1MULg59S.cjs} +377 -420
- package/dist/_chunks/{browserMiddleware-hi8PGbSU.cjs.map → browserMiddleware-1MULg59S.cjs.map} +1 -1
- package/dist/_chunks/{browserMiddleware-eLzHI4Fk.js → browserMiddleware-heyg-fDk.js} +377 -420
- package/dist/_chunks/{browserMiddleware-eLzHI4Fk.js.map → browserMiddleware-heyg-fDk.js.map} +1 -1
- package/dist/_chunks/{nodeMiddleware-wRf5MzJM.cjs → nodeMiddleware-CHxg1-zH.cjs} +396 -440
- package/dist/_chunks/{nodeMiddleware-wRf5MzJM.cjs.map → nodeMiddleware-CHxg1-zH.cjs.map} +1 -1
- package/dist/_chunks/{nodeMiddleware-9L9Lk6DW.js → nodeMiddleware-u_fUUnxa.js} +396 -440
- package/dist/_chunks/{nodeMiddleware-9L9Lk6DW.js.map → nodeMiddleware-u_fUUnxa.js.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-TYjTkHKU.cjs → resolveEditInfo-dELeeJBE.cjs} +47 -70
- package/dist/_chunks/{resolveEditInfo-TYjTkHKU.cjs.map → resolveEditInfo-dELeeJBE.cjs.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-FaeuCV4M.js → resolveEditInfo-uXvm6eWd.js} +47 -70
- package/dist/_chunks/{resolveEditInfo-FaeuCV4M.js.map → resolveEditInfo-uXvm6eWd.js.map} +1 -1
- package/dist/csm.cjs +20 -30
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js +19 -28
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +8 -10
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +5 -2
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +8 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.cjs +224 -257
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js +221 -249
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +193 -217
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.d.ts +2 -2
- package/dist/stega.js +190 -209
- package/dist/stega.js.map +1 -1
- package/package.json +3 -3
- package/src/stega/types.ts +2 -2
- package/umd/sanityClient.js +494 -528
- package/umd/sanityClient.min.js +3 -3
|
@@ -4,6 +4,7 @@ var getIt = require('get-it');
|
|
|
4
4
|
var middleware = require('get-it/middleware');
|
|
5
5
|
var rxjs = require('rxjs');
|
|
6
6
|
var operators = require('rxjs/operators');
|
|
7
|
+
|
|
7
8
|
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
8
9
|
class ClientError extends Error {
|
|
9
10
|
constructor(res) {
|
|
@@ -36,7 +37,7 @@ function extractErrorProps(res) {
|
|
|
36
37
|
}
|
|
37
38
|
if (isMutationError(body)) {
|
|
38
39
|
const allItems = body.error.items || [];
|
|
39
|
-
const items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map(item => {
|
|
40
|
+
const items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map((item) => {
|
|
40
41
|
var _a;
|
|
41
42
|
return (_a = item.error) == null ? void 0 : _a.description;
|
|
42
43
|
}).filter(Boolean);
|
|
@@ -71,8 +72,9 @@ function stringifyBody(body, res) {
|
|
|
71
72
|
const isJson = contentType.indexOf("application/json") !== -1;
|
|
72
73
|
return isJson ? JSON.stringify(body, null, 2) : body;
|
|
73
74
|
}
|
|
75
|
+
|
|
74
76
|
const httpError = {
|
|
75
|
-
onResponse: res => {
|
|
77
|
+
onResponse: (res) => {
|
|
76
78
|
if (res.statusCode >= 500) {
|
|
77
79
|
throw new ServerError(res);
|
|
78
80
|
} else if (res.statusCode >= 400) {
|
|
@@ -82,33 +84,35 @@ const httpError = {
|
|
|
82
84
|
}
|
|
83
85
|
};
|
|
84
86
|
const printWarnings = {
|
|
85
|
-
onResponse: res => {
|
|
87
|
+
onResponse: (res) => {
|
|
86
88
|
const warn = res.headers["x-sanity-warning"];
|
|
87
89
|
const warnings = Array.isArray(warn) ? warn : [warn];
|
|
88
|
-
warnings.filter(Boolean).forEach(msg => console.warn(msg));
|
|
90
|
+
warnings.filter(Boolean).forEach((msg) => console.warn(msg));
|
|
89
91
|
return res;
|
|
90
92
|
}
|
|
91
93
|
};
|
|
92
|
-
function defineHttpRequest(envMiddleware,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
94
|
+
function defineHttpRequest(envMiddleware, {
|
|
95
|
+
maxRetries = 5,
|
|
96
|
+
retryDelay
|
|
97
|
+
}) {
|
|
98
|
+
const request = getIt.getIt([
|
|
99
|
+
maxRetries > 0 ? middleware.retry({
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
|
+
retryDelay,
|
|
102
|
+
// This option is typed incorrectly in get-it.
|
|
103
|
+
maxRetries,
|
|
104
|
+
shouldRetry
|
|
105
|
+
}) : {},
|
|
106
|
+
...envMiddleware,
|
|
107
|
+
printWarnings,
|
|
108
|
+
middleware.jsonRequest(),
|
|
109
|
+
middleware.jsonResponse(),
|
|
110
|
+
middleware.progress(),
|
|
111
|
+
httpError,
|
|
112
|
+
middleware.observable({ implementation: rxjs.Observable })
|
|
113
|
+
]);
|
|
114
|
+
function httpRequest(options, requester = request) {
|
|
115
|
+
return requester({ maxRedirects: 0, ...options });
|
|
112
116
|
}
|
|
113
117
|
httpRequest.defaultRequester = request;
|
|
114
118
|
return httpRequest;
|
|
@@ -118,39 +122,41 @@ function shouldRetry(err, attempt, options) {
|
|
|
118
122
|
const uri = options.uri || options.url;
|
|
119
123
|
const isQuery = uri.startsWith("/data/query");
|
|
120
124
|
const isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
121
|
-
if ((isSafe || isQuery) && isRetriableResponse)
|
|
125
|
+
if ((isSafe || isQuery) && isRetriableResponse)
|
|
126
|
+
return true;
|
|
122
127
|
return middleware.retry.shouldRetry(err, attempt, options);
|
|
123
128
|
}
|
|
129
|
+
|
|
124
130
|
function getSelection(sel) {
|
|
125
131
|
if (typeof sel === "string" || Array.isArray(sel)) {
|
|
126
|
-
return {
|
|
127
|
-
id: sel
|
|
128
|
-
};
|
|
132
|
+
return { id: sel };
|
|
129
133
|
}
|
|
130
134
|
if (typeof sel === "object" && sel !== null && "query" in sel && typeof sel.query === "string") {
|
|
131
|
-
return "params" in sel && typeof sel.params === "object" && sel.params !== null ? {
|
|
132
|
-
query: sel.query,
|
|
133
|
-
params: sel.params
|
|
134
|
-
} : {
|
|
135
|
-
query: sel.query
|
|
136
|
-
};
|
|
135
|
+
return "params" in sel && typeof sel.params === "object" && sel.params !== null ? { query: sel.query, params: sel.params } : { query: sel.query };
|
|
137
136
|
}
|
|
138
|
-
const selectionOpts = [
|
|
137
|
+
const selectionOpts = [
|
|
138
|
+
"* Document ID (<docId>)",
|
|
139
|
+
"* Array of document IDs",
|
|
140
|
+
"* Object containing `query`"
|
|
141
|
+
].join("\n");
|
|
139
142
|
throw new Error("Unknown selection - must be one of:\n\n".concat(selectionOpts));
|
|
140
143
|
}
|
|
144
|
+
|
|
141
145
|
const VALID_ASSET_TYPES = ["image", "file"];
|
|
142
146
|
const VALID_INSERT_LOCATIONS = ["before", "after", "replace"];
|
|
143
|
-
const dataset = name => {
|
|
147
|
+
const dataset = (name) => {
|
|
144
148
|
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
|
|
145
|
-
throw new Error(
|
|
149
|
+
throw new Error(
|
|
150
|
+
"Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters"
|
|
151
|
+
);
|
|
146
152
|
}
|
|
147
153
|
};
|
|
148
|
-
const projectId = id => {
|
|
154
|
+
const projectId = (id) => {
|
|
149
155
|
if (!/^[-a-z0-9]+$/i.test(id)) {
|
|
150
156
|
throw new Error("`projectId` can only contain only a-z, 0-9 and dashes");
|
|
151
157
|
}
|
|
152
158
|
};
|
|
153
|
-
const validateAssetType = type => {
|
|
159
|
+
const validateAssetType = (type) => {
|
|
154
160
|
if (VALID_ASSET_TYPES.indexOf(type) === -1) {
|
|
155
161
|
throw new Error("Invalid asset type: ".concat(type, ". Must be one of ").concat(VALID_ASSET_TYPES.join(", ")));
|
|
156
162
|
}
|
|
@@ -174,7 +180,7 @@ const requireDocumentId = (op, doc) => {
|
|
|
174
180
|
const validateInsert = (at, selector, items) => {
|
|
175
181
|
const signature = "insert(at, selector, items)";
|
|
176
182
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
177
|
-
const valid = VALID_INSERT_LOCATIONS.map(loc => '"'.concat(loc, '"')).join(", ");
|
|
183
|
+
const valid = VALID_INSERT_LOCATIONS.map((loc) => '"'.concat(loc, '"')).join(", ");
|
|
178
184
|
throw new Error("".concat(signature, ' takes an "at"-argument which is one of: ').concat(valid));
|
|
179
185
|
}
|
|
180
186
|
if (typeof selector !== "string") {
|
|
@@ -184,27 +190,32 @@ const validateInsert = (at, selector, items) => {
|
|
|
184
190
|
throw new Error("".concat(signature, ' takes an "items"-argument which must be an array'));
|
|
185
191
|
}
|
|
186
192
|
};
|
|
187
|
-
const hasDataset = config => {
|
|
193
|
+
const hasDataset = (config) => {
|
|
188
194
|
if (!config.dataset) {
|
|
189
195
|
throw new Error("`dataset` must be provided to perform queries");
|
|
190
196
|
}
|
|
191
197
|
return config.dataset || "";
|
|
192
198
|
};
|
|
193
|
-
const requestTag = tag => {
|
|
199
|
+
const requestTag = (tag) => {
|
|
194
200
|
if (typeof tag !== "string" || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
|
|
195
|
-
throw new Error(
|
|
201
|
+
throw new Error(
|
|
202
|
+
"Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long."
|
|
203
|
+
);
|
|
196
204
|
}
|
|
197
205
|
return tag;
|
|
198
206
|
};
|
|
207
|
+
|
|
199
208
|
var __accessCheck$6 = (obj, member, msg) => {
|
|
200
|
-
if (!member.has(obj))
|
|
209
|
+
if (!member.has(obj))
|
|
210
|
+
throw TypeError("Cannot " + msg);
|
|
201
211
|
};
|
|
202
212
|
var __privateGet$6 = (obj, member, getter) => {
|
|
203
213
|
__accessCheck$6(obj, member, "read from private field");
|
|
204
214
|
return getter ? getter.call(obj) : member.get(obj);
|
|
205
215
|
};
|
|
206
216
|
var __privateAdd$6 = (obj, member, value) => {
|
|
207
|
-
if (member.has(obj))
|
|
217
|
+
if (member.has(obj))
|
|
218
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
208
219
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
209
220
|
};
|
|
210
221
|
var __privateSet$6 = (obj, member, value, setter) => {
|
|
@@ -214,8 +225,7 @@ var __privateSet$6 = (obj, member, value, setter) => {
|
|
|
214
225
|
};
|
|
215
226
|
var _client$5, _client2$5;
|
|
216
227
|
class BasePatch {
|
|
217
|
-
constructor(selection) {
|
|
218
|
-
let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
228
|
+
constructor(selection, operations = {}) {
|
|
219
229
|
this.selection = selection;
|
|
220
230
|
this.operations = operations;
|
|
221
231
|
}
|
|
@@ -257,9 +267,7 @@ class BasePatch {
|
|
|
257
267
|
if (!Array.isArray(attrs)) {
|
|
258
268
|
throw new Error("unset(attrs) takes an array of attributes to unset, non-array given");
|
|
259
269
|
}
|
|
260
|
-
this.operations = Object.assign({}, this.operations, {
|
|
261
|
-
unset: attrs
|
|
262
|
-
});
|
|
270
|
+
this.operations = Object.assign({}, this.operations, { unset: attrs });
|
|
263
271
|
return this;
|
|
264
272
|
}
|
|
265
273
|
/**
|
|
@@ -287,10 +295,7 @@ class BasePatch {
|
|
|
287
295
|
*/
|
|
288
296
|
insert(at, selector, items) {
|
|
289
297
|
validateInsert(at, selector, items);
|
|
290
|
-
return this._assign("insert", {
|
|
291
|
-
[at]: selector,
|
|
292
|
-
items
|
|
293
|
-
});
|
|
298
|
+
return this._assign("insert", { [at]: selector, items });
|
|
294
299
|
}
|
|
295
300
|
/**
|
|
296
301
|
* Append the given items to the array at the given JSONPath
|
|
@@ -339,10 +344,7 @@ class BasePatch {
|
|
|
339
344
|
* Return a plain JSON representation of the patch
|
|
340
345
|
*/
|
|
341
346
|
serialize() {
|
|
342
|
-
return {
|
|
343
|
-
...getSelection(this.selection),
|
|
344
|
-
...this.operations
|
|
345
|
-
};
|
|
347
|
+
return { ...getSelection(this.selection), ...this.operations };
|
|
346
348
|
}
|
|
347
349
|
/**
|
|
348
350
|
* Return a plain JSON representation of the patch
|
|
@@ -357,8 +359,7 @@ class BasePatch {
|
|
|
357
359
|
this.operations = {};
|
|
358
360
|
return this;
|
|
359
361
|
}
|
|
360
|
-
_assign(op, props) {
|
|
361
|
-
let merge = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
362
|
+
_assign(op, props, merge = true) {
|
|
362
363
|
validateObject(op, props);
|
|
363
364
|
this.operations = Object.assign({}, this.operations, {
|
|
364
365
|
[op]: Object.assign({}, merge && this.operations[op] || {}, props)
|
|
@@ -379,22 +380,17 @@ const _ObservablePatch = class _ObservablePatch extends BasePatch {
|
|
|
379
380
|
* Clones the patch
|
|
380
381
|
*/
|
|
381
382
|
clone() {
|
|
382
|
-
return new _ObservablePatch(this.selection, {
|
|
383
|
-
...this.operations
|
|
384
|
-
}, __privateGet$6(this, _client$5));
|
|
383
|
+
return new _ObservablePatch(this.selection, { ...this.operations }, __privateGet$6(this, _client$5));
|
|
385
384
|
}
|
|
386
385
|
commit(options) {
|
|
387
386
|
if (!__privateGet$6(this, _client$5)) {
|
|
388
|
-
throw new Error(
|
|
387
|
+
throw new Error(
|
|
388
|
+
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
389
|
+
);
|
|
389
390
|
}
|
|
390
391
|
const returnFirst = typeof this.selection === "string";
|
|
391
|
-
const opts = Object.assign({
|
|
392
|
-
|
|
393
|
-
returnDocuments: true
|
|
394
|
-
}, options);
|
|
395
|
-
return __privateGet$6(this, _client$5).mutate({
|
|
396
|
-
patch: this.serialize()
|
|
397
|
-
}, opts);
|
|
392
|
+
const opts = Object.assign({ returnFirst, returnDocuments: true }, options);
|
|
393
|
+
return __privateGet$6(this, _client$5).mutate({ patch: this.serialize() }, opts);
|
|
398
394
|
}
|
|
399
395
|
};
|
|
400
396
|
_client$5 = new WeakMap();
|
|
@@ -409,35 +405,33 @@ const _Patch = class _Patch extends BasePatch {
|
|
|
409
405
|
* Clones the patch
|
|
410
406
|
*/
|
|
411
407
|
clone() {
|
|
412
|
-
return new _Patch(this.selection, {
|
|
413
|
-
...this.operations
|
|
414
|
-
}, __privateGet$6(this, _client2$5));
|
|
408
|
+
return new _Patch(this.selection, { ...this.operations }, __privateGet$6(this, _client2$5));
|
|
415
409
|
}
|
|
416
410
|
commit(options) {
|
|
417
411
|
if (!__privateGet$6(this, _client2$5)) {
|
|
418
|
-
throw new Error(
|
|
412
|
+
throw new Error(
|
|
413
|
+
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
414
|
+
);
|
|
419
415
|
}
|
|
420
416
|
const returnFirst = typeof this.selection === "string";
|
|
421
|
-
const opts = Object.assign({
|
|
422
|
-
|
|
423
|
-
returnDocuments: true
|
|
424
|
-
}, options);
|
|
425
|
-
return __privateGet$6(this, _client2$5).mutate({
|
|
426
|
-
patch: this.serialize()
|
|
427
|
-
}, opts);
|
|
417
|
+
const opts = Object.assign({ returnFirst, returnDocuments: true }, options);
|
|
418
|
+
return __privateGet$6(this, _client2$5).mutate({ patch: this.serialize() }, opts);
|
|
428
419
|
}
|
|
429
420
|
};
|
|
430
421
|
_client2$5 = new WeakMap();
|
|
431
422
|
let Patch = _Patch;
|
|
423
|
+
|
|
432
424
|
var __accessCheck$5 = (obj, member, msg) => {
|
|
433
|
-
if (!member.has(obj))
|
|
425
|
+
if (!member.has(obj))
|
|
426
|
+
throw TypeError("Cannot " + msg);
|
|
434
427
|
};
|
|
435
428
|
var __privateGet$5 = (obj, member, getter) => {
|
|
436
429
|
__accessCheck$5(obj, member, "read from private field");
|
|
437
430
|
return getter ? getter.call(obj) : member.get(obj);
|
|
438
431
|
};
|
|
439
432
|
var __privateAdd$5 = (obj, member, value) => {
|
|
440
|
-
if (member.has(obj))
|
|
433
|
+
if (member.has(obj))
|
|
434
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
441
435
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
442
436
|
};
|
|
443
437
|
var __privateSet$5 = (obj, member, value, setter) => {
|
|
@@ -446,13 +440,9 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
|
446
440
|
return value;
|
|
447
441
|
};
|
|
448
442
|
var _client$4, _client2$4;
|
|
449
|
-
const defaultMutateOptions = {
|
|
450
|
-
returnDocuments: false
|
|
451
|
-
};
|
|
443
|
+
const defaultMutateOptions = { returnDocuments: false };
|
|
452
444
|
class BaseTransaction {
|
|
453
|
-
constructor() {
|
|
454
|
-
let operations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
455
|
-
let transactionId = arguments.length > 1 ? arguments[1] : undefined;
|
|
445
|
+
constructor(operations = [], transactionId) {
|
|
456
446
|
this.operations = operations;
|
|
457
447
|
this.trxId = transactionId;
|
|
458
448
|
}
|
|
@@ -464,9 +454,7 @@ class BaseTransaction {
|
|
|
464
454
|
*/
|
|
465
455
|
create(doc) {
|
|
466
456
|
validateObject("create", doc);
|
|
467
|
-
return this._add({
|
|
468
|
-
create: doc
|
|
469
|
-
});
|
|
457
|
+
return this._add({ create: doc });
|
|
470
458
|
}
|
|
471
459
|
/**
|
|
472
460
|
* Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
|
|
@@ -478,9 +466,7 @@ class BaseTransaction {
|
|
|
478
466
|
const op = "createIfNotExists";
|
|
479
467
|
validateObject(op, doc);
|
|
480
468
|
requireDocumentId(op, doc);
|
|
481
|
-
return this._add({
|
|
482
|
-
[op]: doc
|
|
483
|
-
});
|
|
469
|
+
return this._add({ [op]: doc });
|
|
484
470
|
}
|
|
485
471
|
/**
|
|
486
472
|
* Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
|
|
@@ -492,9 +478,7 @@ class BaseTransaction {
|
|
|
492
478
|
const op = "createOrReplace";
|
|
493
479
|
validateObject(op, doc);
|
|
494
480
|
requireDocumentId(op, doc);
|
|
495
|
-
return this._add({
|
|
496
|
-
[op]: doc
|
|
497
|
-
});
|
|
481
|
+
return this._add({ [op]: doc });
|
|
498
482
|
}
|
|
499
483
|
/**
|
|
500
484
|
* Deletes the document with the given document ID
|
|
@@ -504,11 +488,7 @@ class BaseTransaction {
|
|
|
504
488
|
*/
|
|
505
489
|
delete(documentId) {
|
|
506
490
|
validateDocumentId("delete", documentId);
|
|
507
|
-
return this._add({
|
|
508
|
-
delete: {
|
|
509
|
-
id: documentId
|
|
510
|
-
}
|
|
511
|
-
});
|
|
491
|
+
return this._add({ delete: { id: documentId } });
|
|
512
492
|
}
|
|
513
493
|
transactionId(id) {
|
|
514
494
|
if (!id) {
|
|
@@ -555,35 +535,29 @@ const _Transaction = class _Transaction extends BaseTransaction {
|
|
|
555
535
|
}
|
|
556
536
|
commit(options) {
|
|
557
537
|
if (!__privateGet$5(this, _client$4)) {
|
|
558
|
-
throw new Error(
|
|
538
|
+
throw new Error(
|
|
539
|
+
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
540
|
+
);
|
|
559
541
|
}
|
|
560
|
-
return __privateGet$5(this, _client$4).mutate(
|
|
561
|
-
|
|
562
|
-
|
|
542
|
+
return __privateGet$5(this, _client$4).mutate(
|
|
543
|
+
this.serialize(),
|
|
544
|
+
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
545
|
+
);
|
|
563
546
|
}
|
|
564
547
|
patch(patchOrDocumentId, patchOps) {
|
|
565
548
|
const isBuilder = typeof patchOps === "function";
|
|
566
549
|
const isPatch = typeof patchOrDocumentId !== "string" && patchOrDocumentId instanceof Patch;
|
|
567
550
|
if (isPatch) {
|
|
568
|
-
return this._add({
|
|
569
|
-
patch: patchOrDocumentId.serialize()
|
|
570
|
-
});
|
|
551
|
+
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
571
552
|
}
|
|
572
553
|
if (isBuilder) {
|
|
573
554
|
const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$5(this, _client$4)));
|
|
574
555
|
if (!(patch instanceof Patch)) {
|
|
575
556
|
throw new Error("function passed to `patch()` must return the patch");
|
|
576
557
|
}
|
|
577
|
-
return this._add({
|
|
578
|
-
patch: patch.serialize()
|
|
579
|
-
});
|
|
558
|
+
return this._add({ patch: patch.serialize() });
|
|
580
559
|
}
|
|
581
|
-
return this._add({
|
|
582
|
-
patch: {
|
|
583
|
-
id: patchOrDocumentId,
|
|
584
|
-
...patchOps
|
|
585
|
-
}
|
|
586
|
-
});
|
|
560
|
+
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
587
561
|
}
|
|
588
562
|
};
|
|
589
563
|
_client$4 = new WeakMap();
|
|
@@ -602,68 +576,79 @@ const _ObservableTransaction = class _ObservableTransaction extends BaseTransact
|
|
|
602
576
|
}
|
|
603
577
|
commit(options) {
|
|
604
578
|
if (!__privateGet$5(this, _client2$4)) {
|
|
605
|
-
throw new Error(
|
|
579
|
+
throw new Error(
|
|
580
|
+
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
581
|
+
);
|
|
606
582
|
}
|
|
607
|
-
return __privateGet$5(this, _client2$4).mutate(
|
|
608
|
-
|
|
609
|
-
|
|
583
|
+
return __privateGet$5(this, _client2$4).mutate(
|
|
584
|
+
this.serialize(),
|
|
585
|
+
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
586
|
+
);
|
|
610
587
|
}
|
|
611
588
|
patch(patchOrDocumentId, patchOps) {
|
|
612
589
|
const isBuilder = typeof patchOps === "function";
|
|
613
590
|
const isPatch = typeof patchOrDocumentId !== "string" && patchOrDocumentId instanceof ObservablePatch;
|
|
614
591
|
if (isPatch) {
|
|
615
|
-
return this._add({
|
|
616
|
-
patch: patchOrDocumentId.serialize()
|
|
617
|
-
});
|
|
592
|
+
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
618
593
|
}
|
|
619
594
|
if (isBuilder) {
|
|
620
595
|
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$5(this, _client2$4)));
|
|
621
596
|
if (!(patch instanceof ObservablePatch)) {
|
|
622
597
|
throw new Error("function passed to `patch()` must return the patch");
|
|
623
598
|
}
|
|
624
|
-
return this._add({
|
|
625
|
-
patch: patch.serialize()
|
|
626
|
-
});
|
|
599
|
+
return this._add({ patch: patch.serialize() });
|
|
627
600
|
}
|
|
628
|
-
return this._add({
|
|
629
|
-
patch: {
|
|
630
|
-
id: patchOrDocumentId,
|
|
631
|
-
...patchOps
|
|
632
|
-
}
|
|
633
|
-
});
|
|
601
|
+
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
634
602
|
}
|
|
635
603
|
};
|
|
636
604
|
_client2$4 = new WeakMap();
|
|
637
605
|
let ObservableTransaction = _ObservableTransaction;
|
|
606
|
+
|
|
638
607
|
const BASE_URL = "https://www.sanity.io/help/";
|
|
639
608
|
function generateHelpUrl(slug) {
|
|
640
609
|
return BASE_URL + slug;
|
|
641
610
|
}
|
|
611
|
+
|
|
642
612
|
function once(fn) {
|
|
643
613
|
let didCall = false;
|
|
644
614
|
let returnValue;
|
|
645
|
-
return
|
|
615
|
+
return (...args) => {
|
|
646
616
|
if (didCall) {
|
|
647
617
|
return returnValue;
|
|
648
618
|
}
|
|
649
|
-
returnValue = fn(...
|
|
619
|
+
returnValue = fn(...args);
|
|
650
620
|
didCall = true;
|
|
651
621
|
return returnValue;
|
|
652
622
|
};
|
|
653
623
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
624
|
+
|
|
625
|
+
const createWarningPrinter = (message) => (
|
|
626
|
+
// eslint-disable-next-line no-console
|
|
627
|
+
once((...args) => console.warn(message.join(" "), ...args))
|
|
628
|
+
);
|
|
629
|
+
const printCdnWarning = createWarningPrinter([
|
|
630
|
+
"Since you haven't set a value for `useCdn`, we will deliver content using our",
|
|
631
|
+
"global, edge-cached API-CDN. If you wish to have content delivered faster, set",
|
|
632
|
+
"`useCdn: false` to use the Live API. Note: You may incur higher costs using the live API."
|
|
633
|
+
]);
|
|
634
|
+
const printCdnPreviewDraftsWarning = createWarningPrinter([
|
|
635
|
+
"The Sanity client is configured with the `perspective` set to `previewDrafts`, which doesn't support the API-CDN.",
|
|
636
|
+
"The Live API will be used instead. Set `useCdn: false` in your configuration to hide this warning."
|
|
637
|
+
]);
|
|
638
|
+
const printBrowserTokenWarning = createWarningPrinter([
|
|
639
|
+
"You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
|
|
640
|
+
"See ".concat(generateHelpUrl(
|
|
641
|
+
"js-client-browser-token"
|
|
642
|
+
), " for more information and how to hide this warning.")
|
|
643
|
+
]);
|
|
644
|
+
const printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
645
|
+
"Using the Sanity client without specifying an API version is deprecated.",
|
|
646
|
+
"See ".concat(generateHelpUrl("js-client-api-version"))
|
|
647
|
+
]);
|
|
648
|
+
const printNoDefaultExport = createWarningPrinter([
|
|
649
|
+
"The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."
|
|
650
|
+
]);
|
|
651
|
+
|
|
667
652
|
const defaultCdnHost = "apicdn.sanity.io";
|
|
668
653
|
const defaultConfig = {
|
|
669
654
|
apiHost: "https://api.sanity.io",
|
|
@@ -671,7 +656,7 @@ const defaultConfig = {
|
|
|
671
656
|
useProjectHostname: true
|
|
672
657
|
};
|
|
673
658
|
const LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
|
|
674
|
-
const isLocal = host => LOCALHOSTS.indexOf(host) !== -1;
|
|
659
|
+
const isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
675
660
|
const validateApiVersion = function validateApiVersion2(apiVersion) {
|
|
676
661
|
if (apiVersion === "1" || apiVersion === "X") {
|
|
677
662
|
return;
|
|
@@ -689,7 +674,9 @@ const validateApiPerspective = function validateApiPerspective2(perspective) {
|
|
|
689
674
|
case "raw":
|
|
690
675
|
return;
|
|
691
676
|
default:
|
|
692
|
-
throw new TypeError(
|
|
677
|
+
throw new TypeError(
|
|
678
|
+
"Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
|
|
679
|
+
);
|
|
693
680
|
}
|
|
694
681
|
};
|
|
695
682
|
const initConfig = (config, prevConfig) => {
|
|
@@ -710,10 +697,14 @@ const initConfig = (config, prevConfig) => {
|
|
|
710
697
|
validateApiPerspective(newConfig.perspective);
|
|
711
698
|
}
|
|
712
699
|
if ("encodeSourceMapAtPath" in newConfig || "encodeSourceMap" in newConfig || "studioUrl" in newConfig || "logger" in newConfig) {
|
|
713
|
-
throw new Error(
|
|
700
|
+
throw new Error(
|
|
701
|
+
"It looks like you're using options meant for '@sanity/preview-kit/client', such as 'encodeSourceMapAtPath', 'encodeSourceMap', 'studioUrl' and 'logger'. Make sure you're using the right import."
|
|
702
|
+
);
|
|
714
703
|
}
|
|
715
704
|
if ("stega" in newConfig && newConfig["stega"] !== void 0 && newConfig["stega"] !== false) {
|
|
716
|
-
throw new Error(
|
|
705
|
+
throw new Error(
|
|
706
|
+
"It looks like you're using options meant for '@sanity/client/stega'. Make sure you're using the right import. Or set 'stega' in 'createClient' to 'false'."
|
|
707
|
+
);
|
|
717
708
|
}
|
|
718
709
|
const isBrowser = typeof window !== "undefined" && window.location && window.location.hostname;
|
|
719
710
|
const isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
@@ -748,9 +739,9 @@ const initConfig = (config, prevConfig) => {
|
|
|
748
739
|
}
|
|
749
740
|
return newConfig;
|
|
750
741
|
};
|
|
742
|
+
|
|
751
743
|
const projectHeader = "X-Sanity-Project-ID";
|
|
752
|
-
function requestOptions(config) {
|
|
753
|
-
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
744
|
+
function requestOptions(config, overrides = {}) {
|
|
754
745
|
const headers = {};
|
|
755
746
|
const token = overrides.token || config.token;
|
|
756
747
|
if (token) {
|
|
@@ -759,7 +750,9 @@ function requestOptions(config) {
|
|
|
759
750
|
if (!overrides.useGlobalApi && !config.useProjectHostname && config.projectId) {
|
|
760
751
|
headers[projectHeader] = config.projectId;
|
|
761
752
|
}
|
|
762
|
-
const withCredentials = Boolean(
|
|
753
|
+
const withCredentials = Boolean(
|
|
754
|
+
typeof overrides.withCredentials === "undefined" ? config.token || config.withCredentials : overrides.withCredentials
|
|
755
|
+
);
|
|
763
756
|
const timeout = typeof overrides.timeout === "undefined" ? config.timeout : overrides.timeout;
|
|
764
757
|
return Object.assign({}, overrides, {
|
|
765
758
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
@@ -767,39 +760,35 @@ function requestOptions(config) {
|
|
|
767
760
|
proxy: overrides.proxy || config.proxy,
|
|
768
761
|
json: true,
|
|
769
762
|
withCredentials,
|
|
770
|
-
fetch: typeof overrides.fetch === "object" && typeof config.fetch === "object" ? {
|
|
771
|
-
...config.fetch,
|
|
772
|
-
...overrides.fetch
|
|
773
|
-
} : overrides.fetch || config.fetch
|
|
763
|
+
fetch: typeof overrides.fetch === "object" && typeof config.fetch === "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
|
|
774
764
|
});
|
|
775
765
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
766
|
+
|
|
767
|
+
const encodeQueryString = ({
|
|
768
|
+
query,
|
|
769
|
+
params = {},
|
|
770
|
+
options = {}
|
|
771
|
+
}) => {
|
|
782
772
|
const searchParams = new URLSearchParams();
|
|
783
|
-
const {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
} = options;
|
|
787
|
-
if (tag) searchParams.append("tag", tag);
|
|
773
|
+
const { tag, ...opts } = options;
|
|
774
|
+
if (tag)
|
|
775
|
+
searchParams.append("tag", tag);
|
|
788
776
|
searchParams.append("query", query);
|
|
789
777
|
for (const [key, value] of Object.entries(params)) {
|
|
790
778
|
searchParams.append("$".concat(key), JSON.stringify(value));
|
|
791
779
|
}
|
|
792
780
|
for (const [key, value] of Object.entries(opts)) {
|
|
793
|
-
if (value)
|
|
781
|
+
if (value)
|
|
782
|
+
searchParams.append(key, "".concat(value));
|
|
794
783
|
}
|
|
795
784
|
return "?".concat(searchParams);
|
|
796
785
|
};
|
|
786
|
+
|
|
797
787
|
const excludeFalsey = (param, defValue) => {
|
|
798
788
|
const value = typeof param === "undefined" ? defValue : param;
|
|
799
789
|
return param === false ? void 0 : value;
|
|
800
790
|
};
|
|
801
|
-
const getMutationQuery =
|
|
802
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
791
|
+
const getMutationQuery = (options = {}) => {
|
|
803
792
|
return {
|
|
804
793
|
dryRun: options.dryRun,
|
|
805
794
|
returnIds: true,
|
|
@@ -809,61 +798,45 @@ const getMutationQuery = function () {
|
|
|
809
798
|
skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
|
|
810
799
|
};
|
|
811
800
|
};
|
|
812
|
-
const isResponse = event => event.type === "response";
|
|
813
|
-
const getBody = event => event.body;
|
|
801
|
+
const isResponse = (event) => event.type === "response";
|
|
802
|
+
const getBody = (event) => event.body;
|
|
814
803
|
const indexBy = (docs, attr) => docs.reduce((indexed, doc) => {
|
|
815
804
|
indexed[attr(doc)] = doc;
|
|
816
805
|
return indexed;
|
|
817
|
-
}, /* @__PURE__ */Object.create(null));
|
|
806
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
818
807
|
const getQuerySizeLimit = 11264;
|
|
819
|
-
function _fetch(client, httpRequest, query, params) {
|
|
820
|
-
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
808
|
+
function _fetch(client, httpRequest, query, params, options = {}) {
|
|
821
809
|
if ("stega" in options && options["stega"] !== void 0 && options["stega"] !== false) {
|
|
822
|
-
throw new Error(
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
...opts
|
|
829
|
-
} = {
|
|
810
|
+
throw new Error(
|
|
811
|
+
"It looks like you're using options meant for '@sanity/client/stega'. Make sure you're using the right import. Or set 'stega' in 'fetch' to 'false'."
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
const mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result;
|
|
815
|
+
const { cache, next, ...opts } = {
|
|
830
816
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
831
817
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
832
818
|
useAbortSignal: typeof options.signal !== "undefined",
|
|
833
819
|
...options
|
|
834
820
|
};
|
|
835
|
-
const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? {
|
|
836
|
-
|
|
837
|
-
fetch: {
|
|
838
|
-
cache,
|
|
839
|
-
next
|
|
840
|
-
}
|
|
841
|
-
} : opts;
|
|
842
|
-
return _dataRequest(client, httpRequest, "query", {
|
|
843
|
-
query,
|
|
844
|
-
params
|
|
845
|
-
}, reqOpts).pipe(operators.map(mapResponse));
|
|
821
|
+
const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? { ...opts, fetch: { cache, next } } : opts;
|
|
822
|
+
return _dataRequest(client, httpRequest, "query", { query, params }, reqOpts).pipe(operators.map(mapResponse));
|
|
846
823
|
}
|
|
847
|
-
function _getDocument(client, httpRequest, id) {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
};
|
|
854
|
-
return _requestObservable(client, httpRequest, options).pipe(operators.filter(isResponse), operators.map(event => event.body.documents && event.body.documents[0]));
|
|
824
|
+
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
825
|
+
const options = { uri: _getDataUrl(client, "doc", id), json: true, tag: opts.tag };
|
|
826
|
+
return _requestObservable(client, httpRequest, options).pipe(
|
|
827
|
+
operators.filter(isResponse),
|
|
828
|
+
operators.map((event) => event.body.documents && event.body.documents[0])
|
|
829
|
+
);
|
|
855
830
|
}
|
|
856
|
-
function _getDocuments(client, httpRequest, ids) {
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
return ids.map(id => indexed[id] || null);
|
|
866
|
-
}));
|
|
831
|
+
function _getDocuments(client, httpRequest, ids, opts = {}) {
|
|
832
|
+
const options = { uri: _getDataUrl(client, "doc", ids.join(",")), json: true, tag: opts.tag };
|
|
833
|
+
return _requestObservable(client, httpRequest, options).pipe(
|
|
834
|
+
operators.filter(isResponse),
|
|
835
|
+
operators.map((event) => {
|
|
836
|
+
const indexed = indexBy(event.body.documents || [], (doc) => doc._id);
|
|
837
|
+
return ids.map((id) => indexed[id] || null);
|
|
838
|
+
})
|
|
839
|
+
);
|
|
867
840
|
}
|
|
868
841
|
function _createIfNotExists(client, httpRequest, doc, options) {
|
|
869
842
|
requireDocumentId("createIfNotExists", doc);
|
|
@@ -874,18 +847,18 @@ function _createOrReplace(client, httpRequest, doc, options) {
|
|
|
874
847
|
return _create(client, httpRequest, doc, "createOrReplace", options);
|
|
875
848
|
}
|
|
876
849
|
function _delete(client, httpRequest, selection, options) {
|
|
877
|
-
return _dataRequest(
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
850
|
+
return _dataRequest(
|
|
851
|
+
client,
|
|
852
|
+
httpRequest,
|
|
853
|
+
"mutate",
|
|
854
|
+
{ mutations: [{ delete: getSelection(selection) }] },
|
|
855
|
+
options
|
|
856
|
+
);
|
|
882
857
|
}
|
|
883
858
|
function _mutate(client, httpRequest, mutations, options) {
|
|
884
859
|
let mut;
|
|
885
860
|
if (mutations instanceof Patch || mutations instanceof ObservablePatch) {
|
|
886
|
-
mut = {
|
|
887
|
-
patch: mutations.serialize()
|
|
888
|
-
};
|
|
861
|
+
mut = { patch: mutations.serialize() };
|
|
889
862
|
} else if (mutations instanceof Transaction || mutations instanceof ObservableTransaction) {
|
|
890
863
|
mut = mutations.serialize();
|
|
891
864
|
} else {
|
|
@@ -893,25 +866,16 @@ function _mutate(client, httpRequest, mutations, options) {
|
|
|
893
866
|
}
|
|
894
867
|
const muts = Array.isArray(mut) ? mut : [mut];
|
|
895
868
|
const transactionId = options && options.transactionId || void 0;
|
|
896
|
-
return _dataRequest(client, httpRequest, "mutate", {
|
|
897
|
-
mutations: muts,
|
|
898
|
-
transactionId
|
|
899
|
-
}, options);
|
|
869
|
+
return _dataRequest(client, httpRequest, "mutate", { mutations: muts, transactionId }, options);
|
|
900
870
|
}
|
|
901
|
-
function _dataRequest(client, httpRequest, endpoint, body) {
|
|
902
|
-
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
871
|
+
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
903
872
|
const isMutation = endpoint === "mutate";
|
|
904
873
|
const isQuery = endpoint === "query";
|
|
905
874
|
const strQuery = isMutation ? "" : encodeQueryString(body);
|
|
906
875
|
const useGet = !isMutation && strQuery.length < getQuerySizeLimit;
|
|
907
876
|
const stringQuery = useGet ? strQuery : "";
|
|
908
877
|
const returnFirst = options.returnFirst;
|
|
909
|
-
const {
|
|
910
|
-
timeout,
|
|
911
|
-
token,
|
|
912
|
-
tag,
|
|
913
|
-
headers
|
|
914
|
-
} = options;
|
|
878
|
+
const { timeout, token, tag, headers } = options;
|
|
915
879
|
const uri = _getDataUrl(client, endpoint, stringQuery);
|
|
916
880
|
const reqOptions = {
|
|
917
881
|
method: useGet ? "GET" : "POST",
|
|
@@ -931,35 +895,31 @@ function _dataRequest(client, httpRequest, endpoint, body) {
|
|
|
931
895
|
useAbortSignal: options.useAbortSignal,
|
|
932
896
|
useCdn: options.useCdn
|
|
933
897
|
};
|
|
934
|
-
return _requestObservable(client, httpRequest, reqOptions).pipe(
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
results
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
898
|
+
return _requestObservable(client, httpRequest, reqOptions).pipe(
|
|
899
|
+
operators.filter(isResponse),
|
|
900
|
+
operators.map(getBody),
|
|
901
|
+
operators.map((res) => {
|
|
902
|
+
if (!isMutation) {
|
|
903
|
+
return res;
|
|
904
|
+
}
|
|
905
|
+
const results = res.results || [];
|
|
906
|
+
if (options.returnDocuments) {
|
|
907
|
+
return returnFirst ? results[0] && results[0].document : results.map((mut) => mut.document);
|
|
908
|
+
}
|
|
909
|
+
const key = returnFirst ? "documentId" : "documentIds";
|
|
910
|
+
const ids = returnFirst ? results[0] && results[0].id : results.map((mut) => mut.id);
|
|
911
|
+
return {
|
|
912
|
+
transactionId: res.transactionId,
|
|
913
|
+
results,
|
|
914
|
+
[key]: ids
|
|
915
|
+
};
|
|
916
|
+
})
|
|
917
|
+
);
|
|
950
918
|
}
|
|
951
|
-
function _create(client, httpRequest, doc, op) {
|
|
952
|
-
|
|
953
|
-
const
|
|
954
|
-
|
|
955
|
-
};
|
|
956
|
-
const opts = Object.assign({
|
|
957
|
-
returnFirst: true,
|
|
958
|
-
returnDocuments: true
|
|
959
|
-
}, options);
|
|
960
|
-
return _dataRequest(client, httpRequest, "mutate", {
|
|
961
|
-
mutations: [mutation]
|
|
962
|
-
}, opts);
|
|
919
|
+
function _create(client, httpRequest, doc, op, options = {}) {
|
|
920
|
+
const mutation = { [op]: doc };
|
|
921
|
+
const opts = Object.assign({ returnFirst: true, returnDocuments: true }, options);
|
|
922
|
+
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
963
923
|
}
|
|
964
924
|
function _requestObservable(client, httpRequest, options) {
|
|
965
925
|
var _a, _b;
|
|
@@ -969,40 +929,39 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
969
929
|
let useCdn = ((_a = options.useCdn) != null ? _a : config.useCdn) && canUseCdn;
|
|
970
930
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
971
931
|
if (tag && options.tag !== null) {
|
|
972
|
-
options.query = {
|
|
973
|
-
tag: requestTag(tag),
|
|
974
|
-
...options.query
|
|
975
|
-
};
|
|
932
|
+
options.query = { tag: requestTag(tag), ...options.query };
|
|
976
933
|
}
|
|
977
934
|
if (["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
978
935
|
const resultSourceMap = (_b = options.resultSourceMap) != null ? _b : config.resultSourceMap;
|
|
979
936
|
if (resultSourceMap !== void 0 && resultSourceMap !== false) {
|
|
980
|
-
options.query = {
|
|
981
|
-
resultSourceMap,
|
|
982
|
-
...options.query
|
|
983
|
-
};
|
|
937
|
+
options.query = { resultSourceMap, ...options.query };
|
|
984
938
|
}
|
|
985
939
|
const perspective = options.perspective || config.perspective;
|
|
986
940
|
if (typeof perspective === "string" && perspective !== "raw") {
|
|
987
941
|
validateApiPerspective(perspective);
|
|
988
|
-
options.query = {
|
|
989
|
-
perspective,
|
|
990
|
-
...options.query
|
|
991
|
-
};
|
|
942
|
+
options.query = { perspective, ...options.query };
|
|
992
943
|
if (perspective === "previewDrafts" && useCdn) {
|
|
993
944
|
useCdn = false;
|
|
994
945
|
printCdnPreviewDraftsWarning();
|
|
995
946
|
}
|
|
996
947
|
}
|
|
997
948
|
}
|
|
998
|
-
const reqOptions = requestOptions(
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
949
|
+
const reqOptions = requestOptions(
|
|
950
|
+
config,
|
|
951
|
+
Object.assign({}, options, {
|
|
952
|
+
url: _getUrl(client, uri, useCdn)
|
|
953
|
+
})
|
|
954
|
+
);
|
|
955
|
+
const request = new rxjs.Observable(
|
|
956
|
+
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
957
|
+
);
|
|
1002
958
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
1003
959
|
}
|
|
1004
960
|
function _request(client, httpRequest, options) {
|
|
1005
|
-
const observable = _requestObservable(client, httpRequest, options).pipe(
|
|
961
|
+
const observable = _requestObservable(client, httpRequest, options).pipe(
|
|
962
|
+
operators.filter((event) => event.type === "response"),
|
|
963
|
+
operators.map((event) => event.body)
|
|
964
|
+
);
|
|
1006
965
|
return observable;
|
|
1007
966
|
}
|
|
1008
967
|
function _getDataUrl(client, operation, path) {
|
|
@@ -1012,18 +971,14 @@ function _getDataUrl(client, operation, path) {
|
|
|
1012
971
|
const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
|
|
1013
972
|
return "/data".concat(uri).replace(/\/($|\?)/, "$1");
|
|
1014
973
|
}
|
|
1015
|
-
function _getUrl(client, uri) {
|
|
1016
|
-
|
|
1017
|
-
const {
|
|
1018
|
-
url,
|
|
1019
|
-
cdnUrl
|
|
1020
|
-
} = client.config();
|
|
974
|
+
function _getUrl(client, uri, canUseCdn = false) {
|
|
975
|
+
const { url, cdnUrl } = client.config();
|
|
1021
976
|
const base = canUseCdn ? cdnUrl : url;
|
|
1022
977
|
return "".concat(base, "/").concat(uri.replace(/^\//, ""));
|
|
1023
978
|
}
|
|
1024
979
|
function _withAbortSignal(signal) {
|
|
1025
|
-
return input => {
|
|
1026
|
-
return new rxjs.Observable(observer => {
|
|
980
|
+
return (input) => {
|
|
981
|
+
return new rxjs.Observable((observer) => {
|
|
1027
982
|
const abort = () => observer.error(_createAbortError(signal));
|
|
1028
983
|
if (signal && signal.aborted) {
|
|
1029
984
|
abort();
|
|
@@ -1048,15 +1003,18 @@ function _createAbortError(signal) {
|
|
|
1048
1003
|
error.name = "AbortError";
|
|
1049
1004
|
return error;
|
|
1050
1005
|
}
|
|
1006
|
+
|
|
1051
1007
|
var __accessCheck$4 = (obj, member, msg) => {
|
|
1052
|
-
if (!member.has(obj))
|
|
1008
|
+
if (!member.has(obj))
|
|
1009
|
+
throw TypeError("Cannot " + msg);
|
|
1053
1010
|
};
|
|
1054
1011
|
var __privateGet$4 = (obj, member, getter) => {
|
|
1055
1012
|
__accessCheck$4(obj, member, "read from private field");
|
|
1056
1013
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1057
1014
|
};
|
|
1058
1015
|
var __privateAdd$4 = (obj, member, value) => {
|
|
1059
|
-
if (member.has(obj))
|
|
1016
|
+
if (member.has(obj))
|
|
1017
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
1060
1018
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1061
1019
|
};
|
|
1062
1020
|
var __privateSet$4 = (obj, member, value, setter) => {
|
|
@@ -1087,13 +1045,19 @@ class AssetsClient {
|
|
|
1087
1045
|
}
|
|
1088
1046
|
upload(assetType, body, options) {
|
|
1089
1047
|
const observable = _upload(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), assetType, body, options);
|
|
1090
|
-
return rxjs.lastValueFrom(
|
|
1048
|
+
return rxjs.lastValueFrom(
|
|
1049
|
+
observable.pipe(
|
|
1050
|
+
operators.filter((event) => event.type === "response"),
|
|
1051
|
+
operators.map(
|
|
1052
|
+
(event) => event.body.document
|
|
1053
|
+
)
|
|
1054
|
+
)
|
|
1055
|
+
);
|
|
1091
1056
|
}
|
|
1092
1057
|
}
|
|
1093
1058
|
_client2$3 = new WeakMap();
|
|
1094
1059
|
_httpRequest2$4 = new WeakMap();
|
|
1095
|
-
function _upload(client, httpRequest, assetType, body) {
|
|
1096
|
-
let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1060
|
+
function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
1097
1061
|
validateAssetType(assetType);
|
|
1098
1062
|
let meta = opts.extract || void 0;
|
|
1099
1063
|
if (meta && !meta.length) {
|
|
@@ -1102,15 +1066,7 @@ function _upload(client, httpRequest, assetType, body) {
|
|
|
1102
1066
|
const dataset = hasDataset(client.config());
|
|
1103
1067
|
const assetEndpoint = assetType === "image" ? "images" : "files";
|
|
1104
1068
|
const options = optionsFromFile(opts, body);
|
|
1105
|
-
const {
|
|
1106
|
-
tag,
|
|
1107
|
-
label,
|
|
1108
|
-
title,
|
|
1109
|
-
description,
|
|
1110
|
-
creditLine,
|
|
1111
|
-
filename,
|
|
1112
|
-
source
|
|
1113
|
-
} = options;
|
|
1069
|
+
const { tag, label, title, description, creditLine, filename, source } = options;
|
|
1114
1070
|
const query = {
|
|
1115
1071
|
label,
|
|
1116
1072
|
title,
|
|
@@ -1129,9 +1085,7 @@ function _upload(client, httpRequest, assetType, body) {
|
|
|
1129
1085
|
method: "POST",
|
|
1130
1086
|
timeout: options.timeout || 0,
|
|
1131
1087
|
uri: "/assets/".concat(assetEndpoint, "/").concat(dataset),
|
|
1132
|
-
headers: options.contentType ? {
|
|
1133
|
-
"Content-Type": options.contentType
|
|
1134
|
-
} : {},
|
|
1088
|
+
headers: options.contentType ? { "Content-Type": options.contentType } : {},
|
|
1135
1089
|
query,
|
|
1136
1090
|
body
|
|
1137
1091
|
});
|
|
@@ -1140,15 +1094,20 @@ function optionsFromFile(opts, file) {
|
|
|
1140
1094
|
if (typeof File === "undefined" || !(file instanceof File)) {
|
|
1141
1095
|
return opts;
|
|
1142
1096
|
}
|
|
1143
|
-
return Object.assign(
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1097
|
+
return Object.assign(
|
|
1098
|
+
{
|
|
1099
|
+
filename: opts.preserveFilename === false ? void 0 : file.name,
|
|
1100
|
+
contentType: file.type
|
|
1101
|
+
},
|
|
1102
|
+
opts
|
|
1103
|
+
);
|
|
1147
1104
|
}
|
|
1105
|
+
|
|
1148
1106
|
var defaults = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj)).reduce((target, prop) => {
|
|
1149
1107
|
target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
|
|
1150
1108
|
return target;
|
|
1151
1109
|
}, {});
|
|
1110
|
+
|
|
1152
1111
|
const pick = (obj, props) => props.reduce((selection, prop) => {
|
|
1153
1112
|
if (typeof obj[prop] === "undefined") {
|
|
1154
1113
|
return selection;
|
|
@@ -1156,36 +1115,27 @@ const pick = (obj, props) => props.reduce((selection, prop) => {
|
|
|
1156
1115
|
selection[prop] = obj[prop];
|
|
1157
1116
|
return selection;
|
|
1158
1117
|
}, {});
|
|
1118
|
+
|
|
1159
1119
|
const MAX_URL_LENGTH = 16e3 - 1200;
|
|
1160
|
-
const possibleOptions = [
|
|
1120
|
+
const possibleOptions = [
|
|
1121
|
+
"includePreviousRevision",
|
|
1122
|
+
"includeResult",
|
|
1123
|
+
"visibility",
|
|
1124
|
+
"effectFormat",
|
|
1125
|
+
"tag"
|
|
1126
|
+
];
|
|
1161
1127
|
const defaultOptions = {
|
|
1162
1128
|
includeResult: true
|
|
1163
1129
|
};
|
|
1164
|
-
function _listen(query, params) {
|
|
1165
|
-
|
|
1166
|
-
const {
|
|
1167
|
-
url,
|
|
1168
|
-
token,
|
|
1169
|
-
withCredentials,
|
|
1170
|
-
requestTagPrefix
|
|
1171
|
-
} = this.config();
|
|
1130
|
+
function _listen(query, params, opts = {}) {
|
|
1131
|
+
const { url, token, withCredentials, requestTagPrefix } = this.config();
|
|
1172
1132
|
const tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag;
|
|
1173
|
-
const options = {
|
|
1174
|
-
...defaults(opts, defaultOptions),
|
|
1175
|
-
tag
|
|
1176
|
-
};
|
|
1133
|
+
const options = { ...defaults(opts, defaultOptions), tag };
|
|
1177
1134
|
const listenOpts = pick(options, possibleOptions);
|
|
1178
|
-
const qs = encodeQueryString({
|
|
1179
|
-
query,
|
|
1180
|
-
params,
|
|
1181
|
-
options: {
|
|
1182
|
-
tag,
|
|
1183
|
-
...listenOpts
|
|
1184
|
-
}
|
|
1185
|
-
});
|
|
1135
|
+
const qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } });
|
|
1186
1136
|
const uri = "".concat(url).concat(_getDataUrl(this, "listen", qs));
|
|
1187
1137
|
if (uri.length > MAX_URL_LENGTH) {
|
|
1188
|
-
return new rxjs.Observable(observer => observer.error(new Error("Query too large for listener")));
|
|
1138
|
+
return new rxjs.Observable((observer) => observer.error(new Error("Query too large for listener")));
|
|
1189
1139
|
}
|
|
1190
1140
|
const listenFor = options.events ? options.events : ["mutation"];
|
|
1191
1141
|
const shouldEmitReconnect = listenFor.indexOf("reconnect") !== -1;
|
|
@@ -1198,11 +1148,11 @@ function _listen(query, params) {
|
|
|
1198
1148
|
Authorization: "Bearer ".concat(token)
|
|
1199
1149
|
};
|
|
1200
1150
|
}
|
|
1201
|
-
return new rxjs.Observable(observer => {
|
|
1151
|
+
return new rxjs.Observable((observer) => {
|
|
1202
1152
|
let es;
|
|
1203
|
-
getEventSource().then(eventSource => {
|
|
1153
|
+
getEventSource().then((eventSource) => {
|
|
1204
1154
|
es = eventSource;
|
|
1205
|
-
}).catch(reason => {
|
|
1155
|
+
}).catch((reason) => {
|
|
1206
1156
|
observer.error(reason);
|
|
1207
1157
|
stop();
|
|
1208
1158
|
});
|
|
@@ -1235,35 +1185,32 @@ function _listen(query, params) {
|
|
|
1235
1185
|
observer.complete();
|
|
1236
1186
|
}
|
|
1237
1187
|
function unsubscribe() {
|
|
1238
|
-
if (!es)
|
|
1188
|
+
if (!es)
|
|
1189
|
+
return;
|
|
1239
1190
|
es.removeEventListener("error", onError);
|
|
1240
1191
|
es.removeEventListener("channelError", onChannelError);
|
|
1241
1192
|
es.removeEventListener("disconnect", onDisconnect);
|
|
1242
|
-
listenFor.forEach(type => es.removeEventListener(type, onMessage));
|
|
1193
|
+
listenFor.forEach((type) => es.removeEventListener(type, onMessage));
|
|
1243
1194
|
es.close();
|
|
1244
1195
|
}
|
|
1245
1196
|
function emitReconnect() {
|
|
1246
1197
|
if (shouldEmitReconnect) {
|
|
1247
|
-
observer.next({
|
|
1248
|
-
type: "reconnect"
|
|
1249
|
-
});
|
|
1198
|
+
observer.next({ type: "reconnect" });
|
|
1250
1199
|
}
|
|
1251
1200
|
}
|
|
1252
1201
|
async function getEventSource() {
|
|
1253
|
-
const {
|
|
1254
|
-
default: EventSource
|
|
1255
|
-
} = await import('@sanity/eventsource');
|
|
1202
|
+
const { default: EventSource } = await import('@sanity/eventsource');
|
|
1256
1203
|
const evs = new EventSource(uri, esOptions);
|
|
1257
1204
|
evs.addEventListener("error", onError);
|
|
1258
1205
|
evs.addEventListener("channelError", onChannelError);
|
|
1259
1206
|
evs.addEventListener("disconnect", onDisconnect);
|
|
1260
|
-
listenFor.forEach(type => evs.addEventListener(type, onMessage));
|
|
1207
|
+
listenFor.forEach((type) => evs.addEventListener(type, onMessage));
|
|
1261
1208
|
return evs;
|
|
1262
1209
|
}
|
|
1263
1210
|
function open() {
|
|
1264
|
-
getEventSource().then(eventSource => {
|
|
1211
|
+
getEventSource().then((eventSource) => {
|
|
1265
1212
|
es = eventSource;
|
|
1266
|
-
}).catch(reason => {
|
|
1213
|
+
}).catch((reason) => {
|
|
1267
1214
|
observer.error(reason);
|
|
1268
1215
|
stop();
|
|
1269
1216
|
});
|
|
@@ -1278,9 +1225,7 @@ function _listen(query, params) {
|
|
|
1278
1225
|
function parseEvent(event) {
|
|
1279
1226
|
try {
|
|
1280
1227
|
const data = event.data && JSON.parse(event.data) || {};
|
|
1281
|
-
return Object.assign({
|
|
1282
|
-
type: event.type
|
|
1283
|
-
}, data);
|
|
1228
|
+
return Object.assign({ type: event.type }, data);
|
|
1284
1229
|
} catch (err) {
|
|
1285
1230
|
return err;
|
|
1286
1231
|
}
|
|
@@ -1301,15 +1246,18 @@ function extractErrorMessage(err) {
|
|
|
1301
1246
|
}
|
|
1302
1247
|
return typeof err.error === "string" ? err.error : JSON.stringify(err.error, null, 2);
|
|
1303
1248
|
}
|
|
1249
|
+
|
|
1304
1250
|
var __accessCheck$3 = (obj, member, msg) => {
|
|
1305
|
-
if (!member.has(obj))
|
|
1251
|
+
if (!member.has(obj))
|
|
1252
|
+
throw TypeError("Cannot " + msg);
|
|
1306
1253
|
};
|
|
1307
1254
|
var __privateGet$3 = (obj, member, getter) => {
|
|
1308
1255
|
__accessCheck$3(obj, member, "read from private field");
|
|
1309
1256
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1310
1257
|
};
|
|
1311
1258
|
var __privateAdd$3 = (obj, member, value) => {
|
|
1312
|
-
if (member.has(obj))
|
|
1259
|
+
if (member.has(obj))
|
|
1260
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
1313
1261
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1314
1262
|
};
|
|
1315
1263
|
var __privateSet$3 = (obj, member, value, setter) => {
|
|
@@ -1377,7 +1325,9 @@ class DatasetsClient {
|
|
|
1377
1325
|
* @param options - Options for the dataset
|
|
1378
1326
|
*/
|
|
1379
1327
|
create(name, options) {
|
|
1380
|
-
return rxjs.lastValueFrom(
|
|
1328
|
+
return rxjs.lastValueFrom(
|
|
1329
|
+
_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "PUT", name, options)
|
|
1330
|
+
);
|
|
1381
1331
|
}
|
|
1382
1332
|
/**
|
|
1383
1333
|
* Edit a dataset with the given name
|
|
@@ -1386,7 +1336,9 @@ class DatasetsClient {
|
|
|
1386
1336
|
* @param options - New options for the dataset
|
|
1387
1337
|
*/
|
|
1388
1338
|
edit(name, options) {
|
|
1389
|
-
return rxjs.lastValueFrom(
|
|
1339
|
+
return rxjs.lastValueFrom(
|
|
1340
|
+
_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "PATCH", name, options)
|
|
1341
|
+
);
|
|
1390
1342
|
}
|
|
1391
1343
|
/**
|
|
1392
1344
|
* Delete a dataset with the given name
|
|
@@ -1400,10 +1352,9 @@ class DatasetsClient {
|
|
|
1400
1352
|
* Fetch a list of datasets for the configured project
|
|
1401
1353
|
*/
|
|
1402
1354
|
list() {
|
|
1403
|
-
return rxjs.lastValueFrom(
|
|
1404
|
-
uri: "/datasets",
|
|
1405
|
-
|
|
1406
|
-
}));
|
|
1355
|
+
return rxjs.lastValueFrom(
|
|
1356
|
+
_request(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), { uri: "/datasets", tag: null })
|
|
1357
|
+
);
|
|
1407
1358
|
}
|
|
1408
1359
|
}
|
|
1409
1360
|
_client2$2 = new WeakMap();
|
|
@@ -1417,15 +1368,18 @@ function _modify(client, httpRequest, method, name, options) {
|
|
|
1417
1368
|
tag: null
|
|
1418
1369
|
});
|
|
1419
1370
|
}
|
|
1371
|
+
|
|
1420
1372
|
var __accessCheck$2 = (obj, member, msg) => {
|
|
1421
|
-
if (!member.has(obj))
|
|
1373
|
+
if (!member.has(obj))
|
|
1374
|
+
throw TypeError("Cannot " + msg);
|
|
1422
1375
|
};
|
|
1423
1376
|
var __privateGet$2 = (obj, member, getter) => {
|
|
1424
1377
|
__accessCheck$2(obj, member, "read from private field");
|
|
1425
1378
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1426
1379
|
};
|
|
1427
1380
|
var __privateAdd$2 = (obj, member, value) => {
|
|
1428
|
-
if (member.has(obj))
|
|
1381
|
+
if (member.has(obj))
|
|
1382
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
1429
1383
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1430
1384
|
};
|
|
1431
1385
|
var __privateSet$2 = (obj, member, value, setter) => {
|
|
@@ -1443,9 +1397,7 @@ class ObservableProjectsClient {
|
|
|
1443
1397
|
}
|
|
1444
1398
|
list(options) {
|
|
1445
1399
|
const uri = (options == null ? void 0 : options.includeMembers) === false ? "/projects?includeMembers=false" : "/projects";
|
|
1446
|
-
return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), {
|
|
1447
|
-
uri
|
|
1448
|
-
});
|
|
1400
|
+
return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), { uri });
|
|
1449
1401
|
}
|
|
1450
1402
|
/**
|
|
1451
1403
|
* Fetch a project by project ID
|
|
@@ -1453,9 +1405,7 @@ class ObservableProjectsClient {
|
|
|
1453
1405
|
* @param projectId - ID of the project to fetch
|
|
1454
1406
|
*/
|
|
1455
1407
|
getById(projectId) {
|
|
1456
|
-
return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), {
|
|
1457
|
-
uri: "/projects/".concat(projectId)
|
|
1458
|
-
});
|
|
1408
|
+
return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), { uri: "/projects/".concat(projectId) });
|
|
1459
1409
|
}
|
|
1460
1410
|
}
|
|
1461
1411
|
_client$1 = new WeakMap();
|
|
@@ -1469,9 +1419,7 @@ class ProjectsClient {
|
|
|
1469
1419
|
}
|
|
1470
1420
|
list(options) {
|
|
1471
1421
|
const uri = (options == null ? void 0 : options.includeMembers) === false ? "/projects?includeMembers=false" : "/projects";
|
|
1472
|
-
return rxjs.lastValueFrom(_request(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), {
|
|
1473
|
-
uri
|
|
1474
|
-
}));
|
|
1422
|
+
return rxjs.lastValueFrom(_request(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), { uri }));
|
|
1475
1423
|
}
|
|
1476
1424
|
/**
|
|
1477
1425
|
* Fetch a project by project ID
|
|
@@ -1479,22 +1427,25 @@ class ProjectsClient {
|
|
|
1479
1427
|
* @param projectId - ID of the project to fetch
|
|
1480
1428
|
*/
|
|
1481
1429
|
getById(projectId) {
|
|
1482
|
-
return rxjs.lastValueFrom(
|
|
1483
|
-
uri: "/projects/".concat(projectId)
|
|
1484
|
-
|
|
1430
|
+
return rxjs.lastValueFrom(
|
|
1431
|
+
_request(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), { uri: "/projects/".concat(projectId) })
|
|
1432
|
+
);
|
|
1485
1433
|
}
|
|
1486
1434
|
}
|
|
1487
1435
|
_client2$1 = new WeakMap();
|
|
1488
1436
|
_httpRequest2$2 = new WeakMap();
|
|
1437
|
+
|
|
1489
1438
|
var __accessCheck$1 = (obj, member, msg) => {
|
|
1490
|
-
if (!member.has(obj))
|
|
1439
|
+
if (!member.has(obj))
|
|
1440
|
+
throw TypeError("Cannot " + msg);
|
|
1491
1441
|
};
|
|
1492
1442
|
var __privateGet$1 = (obj, member, getter) => {
|
|
1493
1443
|
__accessCheck$1(obj, member, "read from private field");
|
|
1494
1444
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1495
1445
|
};
|
|
1496
1446
|
var __privateAdd$1 = (obj, member, value) => {
|
|
1497
|
-
if (member.has(obj))
|
|
1447
|
+
if (member.has(obj))
|
|
1448
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
1498
1449
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1499
1450
|
};
|
|
1500
1451
|
var __privateSet$1 = (obj, member, value, setter) => {
|
|
@@ -1516,9 +1467,11 @@ class ObservableUsersClient {
|
|
|
1516
1467
|
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
1517
1468
|
*/
|
|
1518
1469
|
getById(id) {
|
|
1519
|
-
return _request(
|
|
1520
|
-
|
|
1521
|
-
|
|
1470
|
+
return _request(
|
|
1471
|
+
__privateGet$1(this, _client),
|
|
1472
|
+
__privateGet$1(this, _httpRequest$1),
|
|
1473
|
+
{ uri: "/users/".concat(id) }
|
|
1474
|
+
);
|
|
1522
1475
|
}
|
|
1523
1476
|
}
|
|
1524
1477
|
_client = new WeakMap();
|
|
@@ -1536,22 +1489,27 @@ class UsersClient {
|
|
|
1536
1489
|
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
1537
1490
|
*/
|
|
1538
1491
|
getById(id) {
|
|
1539
|
-
return rxjs.lastValueFrom(
|
|
1540
|
-
|
|
1541
|
-
|
|
1492
|
+
return rxjs.lastValueFrom(
|
|
1493
|
+
_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
|
|
1494
|
+
uri: "/users/".concat(id)
|
|
1495
|
+
})
|
|
1496
|
+
);
|
|
1542
1497
|
}
|
|
1543
1498
|
}
|
|
1544
1499
|
_client2 = new WeakMap();
|
|
1545
1500
|
_httpRequest2$1 = new WeakMap();
|
|
1501
|
+
|
|
1546
1502
|
var __accessCheck = (obj, member, msg) => {
|
|
1547
|
-
if (!member.has(obj))
|
|
1503
|
+
if (!member.has(obj))
|
|
1504
|
+
throw TypeError("Cannot " + msg);
|
|
1548
1505
|
};
|
|
1549
1506
|
var __privateGet = (obj, member, getter) => {
|
|
1550
1507
|
__accessCheck(obj, member, "read from private field");
|
|
1551
1508
|
return getter ? getter.call(obj) : member.get(obj);
|
|
1552
1509
|
};
|
|
1553
1510
|
var __privateAdd = (obj, member, value) => {
|
|
1554
|
-
if (member.has(obj))
|
|
1511
|
+
if (member.has(obj))
|
|
1512
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
1555
1513
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1556
1514
|
};
|
|
1557
1515
|
var __privateSet = (obj, member, value, setter) => {
|
|
@@ -1561,8 +1519,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1561
1519
|
};
|
|
1562
1520
|
var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
|
|
1563
1521
|
const _ObservableSanityClient = class _ObservableSanityClient {
|
|
1564
|
-
constructor(httpRequest) {
|
|
1565
|
-
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1522
|
+
constructor(httpRequest, config = defaultConfig) {
|
|
1566
1523
|
/**
|
|
1567
1524
|
* Private properties
|
|
1568
1525
|
*/
|
|
@@ -1587,12 +1544,12 @@ const _ObservableSanityClient = class _ObservableSanityClient {
|
|
|
1587
1544
|
}
|
|
1588
1545
|
config(newConfig) {
|
|
1589
1546
|
if (newConfig === void 0) {
|
|
1590
|
-
return {
|
|
1591
|
-
...__privateGet(this, _clientConfig)
|
|
1592
|
-
};
|
|
1547
|
+
return { ...__privateGet(this, _clientConfig) };
|
|
1593
1548
|
}
|
|
1594
1549
|
if (__privateGet(this, _clientConfig) && __privateGet(this, _clientConfig).allowReconfigure === false) {
|
|
1595
|
-
throw new Error(
|
|
1550
|
+
throw new Error(
|
|
1551
|
+
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1552
|
+
);
|
|
1596
1553
|
}
|
|
1597
1554
|
__privateSet(this, _clientConfig, initConfig(newConfig, __privateGet(this, _clientConfig) || {}));
|
|
1598
1555
|
return this;
|
|
@@ -1603,13 +1560,9 @@ const _ObservableSanityClient = class _ObservableSanityClient {
|
|
|
1603
1560
|
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1604
1561
|
*/
|
|
1605
1562
|
withConfig(newConfig) {
|
|
1606
|
-
return new _ObservableSanityClient(__privateGet(this, _httpRequest), {
|
|
1607
|
-
...this.config(),
|
|
1608
|
-
...newConfig
|
|
1609
|
-
});
|
|
1563
|
+
return new _ObservableSanityClient(__privateGet(this, _httpRequest), { ...this.config(), ...newConfig });
|
|
1610
1564
|
}
|
|
1611
|
-
fetch(query, params) {
|
|
1612
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1565
|
+
fetch(query, params, options = {}) {
|
|
1613
1566
|
return _fetch(this, __privateGet(this, _httpRequest), query, params, options);
|
|
1614
1567
|
}
|
|
1615
1568
|
/**
|
|
@@ -1697,8 +1650,7 @@ _clientConfig = new WeakMap();
|
|
|
1697
1650
|
_httpRequest = new WeakMap();
|
|
1698
1651
|
let ObservableSanityClient = _ObservableSanityClient;
|
|
1699
1652
|
const _SanityClient = class _SanityClient {
|
|
1700
|
-
constructor(httpRequest) {
|
|
1701
|
-
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1653
|
+
constructor(httpRequest, config = defaultConfig) {
|
|
1702
1654
|
/**
|
|
1703
1655
|
* Private properties
|
|
1704
1656
|
*/
|
|
@@ -1724,12 +1676,12 @@ const _SanityClient = class _SanityClient {
|
|
|
1724
1676
|
}
|
|
1725
1677
|
config(newConfig) {
|
|
1726
1678
|
if (newConfig === void 0) {
|
|
1727
|
-
return {
|
|
1728
|
-
...__privateGet(this, _clientConfig2)
|
|
1729
|
-
};
|
|
1679
|
+
return { ...__privateGet(this, _clientConfig2) };
|
|
1730
1680
|
}
|
|
1731
1681
|
if (__privateGet(this, _clientConfig2) && __privateGet(this, _clientConfig2).allowReconfigure === false) {
|
|
1732
|
-
throw new Error(
|
|
1682
|
+
throw new Error(
|
|
1683
|
+
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1684
|
+
);
|
|
1733
1685
|
}
|
|
1734
1686
|
if (this.observable) {
|
|
1735
1687
|
this.observable.config(newConfig);
|
|
@@ -1743,13 +1695,9 @@ const _SanityClient = class _SanityClient {
|
|
|
1743
1695
|
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1744
1696
|
*/
|
|
1745
1697
|
withConfig(newConfig) {
|
|
1746
|
-
return new _SanityClient(__privateGet(this, _httpRequest2), {
|
|
1747
|
-
...this.config(),
|
|
1748
|
-
...newConfig
|
|
1749
|
-
});
|
|
1698
|
+
return new _SanityClient(__privateGet(this, _httpRequest2), { ...this.config(), ...newConfig });
|
|
1750
1699
|
}
|
|
1751
|
-
fetch(query, params) {
|
|
1752
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1700
|
+
fetch(query, params, options = {}) {
|
|
1753
1701
|
return rxjs.lastValueFrom(_fetch(this, __privateGet(this, _httpRequest2), query, params, options));
|
|
1754
1702
|
}
|
|
1755
1703
|
/**
|
|
@@ -1774,13 +1722,19 @@ const _SanityClient = class _SanityClient {
|
|
|
1774
1722
|
return rxjs.lastValueFrom(_getDocuments(this, __privateGet(this, _httpRequest2), ids, options));
|
|
1775
1723
|
}
|
|
1776
1724
|
create(document, options) {
|
|
1777
|
-
return rxjs.lastValueFrom(
|
|
1725
|
+
return rxjs.lastValueFrom(
|
|
1726
|
+
_create(this, __privateGet(this, _httpRequest2), document, "create", options)
|
|
1727
|
+
);
|
|
1778
1728
|
}
|
|
1779
1729
|
createIfNotExists(document, options) {
|
|
1780
|
-
return rxjs.lastValueFrom(
|
|
1730
|
+
return rxjs.lastValueFrom(
|
|
1731
|
+
_createIfNotExists(this, __privateGet(this, _httpRequest2), document, options)
|
|
1732
|
+
);
|
|
1781
1733
|
}
|
|
1782
1734
|
createOrReplace(document, options) {
|
|
1783
|
-
return rxjs.lastValueFrom(
|
|
1735
|
+
return rxjs.lastValueFrom(
|
|
1736
|
+
_createOrReplace(this, __privateGet(this, _httpRequest2), document, options)
|
|
1737
|
+
);
|
|
1784
1738
|
}
|
|
1785
1739
|
delete(selection, options) {
|
|
1786
1740
|
return rxjs.lastValueFrom(_delete(this, __privateGet(this, _httpRequest2), selection, options));
|
|
@@ -1851,19 +1805,22 @@ const _SanityClient = class _SanityClient {
|
|
|
1851
1805
|
_clientConfig2 = new WeakMap();
|
|
1852
1806
|
_httpRequest2 = new WeakMap();
|
|
1853
1807
|
let SanityClient = _SanityClient;
|
|
1808
|
+
|
|
1854
1809
|
function defineCreateClientExports(envMiddleware, ClassConstructor) {
|
|
1855
1810
|
const httpRequest = defineHttpRequest(envMiddleware, {});
|
|
1856
1811
|
const requester = httpRequest.defaultRequester;
|
|
1857
|
-
const createClient = config => new ClassConstructor(
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
};
|
|
1812
|
+
const createClient = (config) => new ClassConstructor(
|
|
1813
|
+
defineHttpRequest(envMiddleware, {
|
|
1814
|
+
maxRetries: config.maxRetries,
|
|
1815
|
+
retryDelay: config.retryDelay
|
|
1816
|
+
}),
|
|
1817
|
+
config
|
|
1818
|
+
);
|
|
1819
|
+
return { requester, createClient };
|
|
1865
1820
|
}
|
|
1821
|
+
|
|
1866
1822
|
var envMiddleware = [];
|
|
1823
|
+
|
|
1867
1824
|
exports.BasePatch = BasePatch;
|
|
1868
1825
|
exports.BaseTransaction = BaseTransaction;
|
|
1869
1826
|
exports.ClientError = ClientError;
|
|
@@ -1878,4 +1835,4 @@ exports.defaultConfig = defaultConfig;
|
|
|
1878
1835
|
exports.defineCreateClientExports = defineCreateClientExports;
|
|
1879
1836
|
exports.envMiddleware = envMiddleware;
|
|
1880
1837
|
exports.printNoDefaultExport = printNoDefaultExport;
|
|
1881
|
-
//# sourceMappingURL=browserMiddleware-
|
|
1838
|
+
//# sourceMappingURL=browserMiddleware-1MULg59S.cjs.map
|