@sanity/client 6.21.1 → 6.21.3-bundle-perspective
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 +3 -3
- package/dist/_chunks-cjs/resolveEditInfo.cjs +2 -3
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +1 -2
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +9 -12
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/resolveEditInfo.js +2 -3
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +1 -2
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +9 -12
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/csm.cjs +1 -2
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js +1 -2
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +188 -213
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +16 -3
- package/dist/index.browser.d.ts +16 -3
- package/dist/index.browser.js +188 -214
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +189 -214
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.js +189 -215
- package/dist/index.js.map +1 -1
- package/package.json +18 -18
- package/src/SanityClient.ts +2 -2
- package/src/data/dataMethods.ts +23 -4
- package/src/types.ts +14 -1
- package/umd/sanityClient.js +212 -975
- package/umd/sanityClient.min.js +2 -8
package/dist/index.browser.cjs
CHANGED
|
@@ -19,17 +19,25 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
19
|
mod
|
|
20
20
|
));
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
22
|
-
var getIt = require("get-it"), middleware = require("get-it/middleware"), rxjs = require("rxjs"),
|
|
22
|
+
var getIt = require("get-it"), middleware = require("get-it/middleware"), rxjs = require("rxjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"), operators = require("rxjs/operators");
|
|
23
23
|
class ClientError extends Error {
|
|
24
|
+
response;
|
|
25
|
+
statusCode = 400;
|
|
26
|
+
responseBody;
|
|
27
|
+
details;
|
|
24
28
|
constructor(res) {
|
|
25
29
|
const props = extractErrorProps(res);
|
|
26
|
-
super(props.message),
|
|
30
|
+
super(props.message), Object.assign(this, props);
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
class ServerError extends Error {
|
|
34
|
+
response;
|
|
35
|
+
statusCode = 500;
|
|
36
|
+
responseBody;
|
|
37
|
+
details;
|
|
30
38
|
constructor(res) {
|
|
31
39
|
const props = extractErrorProps(res);
|
|
32
|
-
super(props.message),
|
|
40
|
+
super(props.message), Object.assign(this, props);
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
function extractErrorProps(res) {
|
|
@@ -43,10 +51,7 @@ function extractErrorProps(res) {
|
|
|
43
51
|
if (body.error && body.message)
|
|
44
52
|
return props.message = `${body.error} - ${body.message}`, props;
|
|
45
53
|
if (isMutationError(body) || isActionError(body)) {
|
|
46
|
-
const allItems = body.error.items || [], items = allItems.slice(0, 5).map((item) =>
|
|
47
|
-
var _a;
|
|
48
|
-
return (_a = item.error) == null ? void 0 : _a.description;
|
|
49
|
-
}).filter(Boolean);
|
|
54
|
+
const allItems = body.error.items || [], items = allItems.slice(0, 5).map((item) => item.error?.description).filter(Boolean);
|
|
50
55
|
let itemsStr = items.length ? `:
|
|
51
56
|
- ${items.join(`
|
|
52
57
|
- `)}` : "";
|
|
@@ -98,8 +103,7 @@ function defineHttpRequest(envMiddleware2) {
|
|
|
98
103
|
]);
|
|
99
104
|
}
|
|
100
105
|
function shouldRetry(err, attempt, options) {
|
|
101
|
-
if (options.maxRetries === 0)
|
|
102
|
-
return !1;
|
|
106
|
+
if (options.maxRetries === 0) return !1;
|
|
103
107
|
const isSafe = options.method === "GET" || options.method === "HEAD", isQuery = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
104
108
|
return (isSafe || isQuery) && isRetriableResponse ? !0 : middleware.retry.shouldRetry(err, attempt, options);
|
|
105
109
|
}
|
|
@@ -162,17 +166,11 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
162
166
|
);
|
|
163
167
|
return tag;
|
|
164
168
|
};
|
|
165
|
-
var __defProp$2 = Object.defineProperty, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$2 = (obj, key, value) => (__defNormalProp$2(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$7 = (obj, member, msg) => {
|
|
166
|
-
if (!member.has(obj))
|
|
167
|
-
throw TypeError("Cannot " + msg);
|
|
168
|
-
}, __privateGet$7 = (obj, member, getter) => (__accessCheck$7(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$7 = (obj, member, value) => {
|
|
169
|
-
if (member.has(obj))
|
|
170
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
171
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
172
|
-
}, __privateSet$7 = (obj, member, value, setter) => (__accessCheck$7(obj, member, "write to private field"), member.set(obj, value), value);
|
|
173
169
|
class BasePatch {
|
|
170
|
+
selection;
|
|
171
|
+
operations;
|
|
174
172
|
constructor(selection, operations = {}) {
|
|
175
|
-
|
|
173
|
+
this.selection = selection, this.operations = operations;
|
|
176
174
|
}
|
|
177
175
|
/**
|
|
178
176
|
* Sets the given attributes to the document. Does NOT merge objects.
|
|
@@ -303,62 +301,52 @@ class BasePatch {
|
|
|
303
301
|
return this._assign(op, props, !1);
|
|
304
302
|
}
|
|
305
303
|
}
|
|
306
|
-
|
|
307
|
-
|
|
304
|
+
class ObservablePatch extends BasePatch {
|
|
305
|
+
#client;
|
|
308
306
|
constructor(selection, operations, client) {
|
|
309
|
-
super(selection, operations),
|
|
307
|
+
super(selection, operations), this.#client = client;
|
|
310
308
|
}
|
|
311
309
|
/**
|
|
312
310
|
* Clones the patch
|
|
313
311
|
*/
|
|
314
312
|
clone() {
|
|
315
|
-
return new
|
|
313
|
+
return new ObservablePatch(this.selection, { ...this.operations }, this.#client);
|
|
316
314
|
}
|
|
317
315
|
commit(options) {
|
|
318
|
-
if (!
|
|
316
|
+
if (!this.#client)
|
|
319
317
|
throw new Error(
|
|
320
318
|
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
321
319
|
);
|
|
322
320
|
const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
|
|
323
|
-
return
|
|
321
|
+
return this.#client.mutate({ patch: this.serialize() }, opts);
|
|
324
322
|
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
var _client2$5;
|
|
329
|
-
const _Patch = class _Patch2 extends BasePatch {
|
|
323
|
+
}
|
|
324
|
+
class Patch extends BasePatch {
|
|
325
|
+
#client;
|
|
330
326
|
constructor(selection, operations, client) {
|
|
331
|
-
super(selection, operations),
|
|
327
|
+
super(selection, operations), this.#client = client;
|
|
332
328
|
}
|
|
333
329
|
/**
|
|
334
330
|
* Clones the patch
|
|
335
331
|
*/
|
|
336
332
|
clone() {
|
|
337
|
-
return new
|
|
333
|
+
return new Patch(this.selection, { ...this.operations }, this.#client);
|
|
338
334
|
}
|
|
339
335
|
commit(options) {
|
|
340
|
-
if (!
|
|
336
|
+
if (!this.#client)
|
|
341
337
|
throw new Error(
|
|
342
338
|
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
343
339
|
);
|
|
344
340
|
const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
|
|
345
|
-
return
|
|
341
|
+
return this.#client.mutate({ patch: this.serialize() }, opts);
|
|
346
342
|
}
|
|
347
|
-
}
|
|
348
|
-
_client2$5 = /* @__PURE__ */ new WeakMap();
|
|
349
|
-
let Patch = _Patch;
|
|
350
|
-
var __defProp$1 = Object.defineProperty, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$1 = (obj, key, value) => (__defNormalProp$1(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$6 = (obj, member, msg) => {
|
|
351
|
-
if (!member.has(obj))
|
|
352
|
-
throw TypeError("Cannot " + msg);
|
|
353
|
-
}, __privateGet$6 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$6 = (obj, member, value) => {
|
|
354
|
-
if (member.has(obj))
|
|
355
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
356
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
357
|
-
}, __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
|
|
343
|
+
}
|
|
358
344
|
const defaultMutateOptions = { returnDocuments: !1 };
|
|
359
345
|
class BaseTransaction {
|
|
346
|
+
operations;
|
|
347
|
+
trxId;
|
|
360
348
|
constructor(operations = [], transactionId) {
|
|
361
|
-
|
|
349
|
+
this.operations = operations, this.trxId = transactionId;
|
|
362
350
|
}
|
|
363
351
|
/**
|
|
364
352
|
* Creates a new Sanity document. If `_id` is provided and already exists, the mutation will fail. If no `_id` is given, one will automatically be generated by the database.
|
|
@@ -423,23 +411,23 @@ class BaseTransaction {
|
|
|
423
411
|
return this.operations.push(mut), this;
|
|
424
412
|
}
|
|
425
413
|
}
|
|
426
|
-
|
|
427
|
-
|
|
414
|
+
class Transaction extends BaseTransaction {
|
|
415
|
+
#client;
|
|
428
416
|
constructor(operations, client, transactionId) {
|
|
429
|
-
super(operations, transactionId),
|
|
417
|
+
super(operations, transactionId), this.#client = client;
|
|
430
418
|
}
|
|
431
419
|
/**
|
|
432
420
|
* Clones the transaction
|
|
433
421
|
*/
|
|
434
422
|
clone() {
|
|
435
|
-
return new
|
|
423
|
+
return new Transaction([...this.operations], this.#client, this.trxId);
|
|
436
424
|
}
|
|
437
425
|
commit(options) {
|
|
438
|
-
if (!
|
|
426
|
+
if (!this.#client)
|
|
439
427
|
throw new Error(
|
|
440
428
|
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
441
429
|
);
|
|
442
|
-
return
|
|
430
|
+
return this.#client.mutate(
|
|
443
431
|
this.serialize(),
|
|
444
432
|
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
445
433
|
);
|
|
@@ -449,33 +437,31 @@ const _Transaction = class _Transaction2 extends BaseTransaction {
|
|
|
449
437
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch)
|
|
450
438
|
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
451
439
|
if (isBuilder) {
|
|
452
|
-
const patch = patchOps(new Patch(patchOrDocumentId, {},
|
|
440
|
+
const patch = patchOps(new Patch(patchOrDocumentId, {}, this.#client));
|
|
453
441
|
if (!(patch instanceof Patch))
|
|
454
442
|
throw new Error("function passed to `patch()` must return the patch");
|
|
455
443
|
return this._add({ patch: patch.serialize() });
|
|
456
444
|
}
|
|
457
445
|
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
458
446
|
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
var _client2$4;
|
|
463
|
-
const _ObservableTransaction = class _ObservableTransaction2 extends BaseTransaction {
|
|
447
|
+
}
|
|
448
|
+
class ObservableTransaction extends BaseTransaction {
|
|
449
|
+
#client;
|
|
464
450
|
constructor(operations, client, transactionId) {
|
|
465
|
-
super(operations, transactionId),
|
|
451
|
+
super(operations, transactionId), this.#client = client;
|
|
466
452
|
}
|
|
467
453
|
/**
|
|
468
454
|
* Clones the transaction
|
|
469
455
|
*/
|
|
470
456
|
clone() {
|
|
471
|
-
return new
|
|
457
|
+
return new ObservableTransaction([...this.operations], this.#client, this.trxId);
|
|
472
458
|
}
|
|
473
459
|
commit(options) {
|
|
474
|
-
if (!
|
|
460
|
+
if (!this.#client)
|
|
475
461
|
throw new Error(
|
|
476
462
|
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
477
463
|
);
|
|
478
|
-
return
|
|
464
|
+
return this.#client.mutate(
|
|
479
465
|
this.serialize(),
|
|
480
466
|
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
481
467
|
);
|
|
@@ -485,16 +471,14 @@ const _ObservableTransaction = class _ObservableTransaction2 extends BaseTransac
|
|
|
485
471
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof ObservablePatch)
|
|
486
472
|
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
487
473
|
if (isBuilder) {
|
|
488
|
-
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {},
|
|
474
|
+
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, this.#client));
|
|
489
475
|
if (!(patch instanceof ObservablePatch))
|
|
490
476
|
throw new Error("function passed to `patch()` must return the patch");
|
|
491
477
|
return this._add({ patch: patch.serialize() });
|
|
492
478
|
}
|
|
493
479
|
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
494
480
|
}
|
|
495
|
-
}
|
|
496
|
-
_client2$4 = /* @__PURE__ */ new WeakMap();
|
|
497
|
-
let ObservableTransaction = _ObservableTransaction;
|
|
481
|
+
}
|
|
498
482
|
const BASE_URL = "https://www.sanity.io/help/";
|
|
499
483
|
function generateHelpUrl(slug) {
|
|
500
484
|
return BASE_URL + slug;
|
|
@@ -660,14 +644,24 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
660
644
|
) : $request.pipe(operators.map(mapResponse));
|
|
661
645
|
}
|
|
662
646
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
663
|
-
const options = {
|
|
647
|
+
const options = {
|
|
648
|
+
uri: _getDataUrl(client, "doc", id),
|
|
649
|
+
json: !0,
|
|
650
|
+
tag: opts.tag,
|
|
651
|
+
signal: opts.signal
|
|
652
|
+
};
|
|
664
653
|
return _requestObservable(client, httpRequest, options).pipe(
|
|
665
654
|
operators.filter(isResponse),
|
|
666
655
|
operators.map((event) => event.body.documents && event.body.documents[0])
|
|
667
656
|
);
|
|
668
657
|
}
|
|
669
658
|
function _getDocuments(client, httpRequest, ids, opts = {}) {
|
|
670
|
-
const options = {
|
|
659
|
+
const options = {
|
|
660
|
+
uri: _getDataUrl(client, "doc", ids.join(",")),
|
|
661
|
+
json: !0,
|
|
662
|
+
tag: opts.tag,
|
|
663
|
+
signal: opts.signal
|
|
664
|
+
};
|
|
671
665
|
return _requestObservable(client, httpRequest, options).pipe(
|
|
672
666
|
operators.filter(isResponse),
|
|
673
667
|
operators.map((event) => {
|
|
@@ -720,6 +714,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
720
714
|
tag,
|
|
721
715
|
returnQuery,
|
|
722
716
|
perspective: options.perspective,
|
|
717
|
+
bundlePerspective: options.bundlePerspective,
|
|
723
718
|
resultSourceMap: options.resultSourceMap,
|
|
724
719
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
725
720
|
canUseCdn: isQuery,
|
|
@@ -751,15 +746,14 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
751
746
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
752
747
|
}
|
|
753
748
|
function _requestObservable(client, httpRequest, options) {
|
|
754
|
-
var _a, _b;
|
|
755
749
|
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
|
|
756
|
-
let useCdn = (
|
|
750
|
+
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
757
751
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
758
752
|
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
759
|
-
const resultSourceMap =
|
|
753
|
+
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
760
754
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
761
|
-
const perspective = options.perspective || config.perspective;
|
|
762
|
-
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
|
|
755
|
+
const perspective = options.perspective || config.perspective, bundlePerspective = options.bundlePerspective || config.bundlePerspective;
|
|
756
|
+
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), typeof bundlePerspective == "string" && (options.query = { perspective: void 0, bundlePerspective, ...options.query }), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
|
|
763
757
|
}
|
|
764
758
|
const reqOptions = requestOptions(
|
|
765
759
|
config,
|
|
@@ -800,36 +794,29 @@ function _withAbortSignal(signal) {
|
|
|
800
794
|
}
|
|
801
795
|
const isDomExceptionSupported = !!globalThis.DOMException;
|
|
802
796
|
function _createAbortError(signal) {
|
|
803
|
-
var _a, _b;
|
|
804
797
|
if (isDomExceptionSupported)
|
|
805
|
-
return new DOMException(
|
|
806
|
-
const error = new Error(
|
|
798
|
+
return new DOMException(signal?.reason ?? "The operation was aborted.", "AbortError");
|
|
799
|
+
const error = new Error(signal?.reason ?? "The operation was aborted.");
|
|
807
800
|
return error.name = "AbortError", error;
|
|
808
801
|
}
|
|
809
|
-
var __accessCheck$5 = (obj, member, msg) => {
|
|
810
|
-
if (!member.has(obj))
|
|
811
|
-
throw TypeError("Cannot " + msg);
|
|
812
|
-
}, __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$5 = (obj, member, value) => {
|
|
813
|
-
if (member.has(obj))
|
|
814
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
815
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
816
|
-
}, __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value), _client$4, _httpRequest$4;
|
|
817
802
|
class ObservableAssetsClient {
|
|
803
|
+
#client;
|
|
804
|
+
#httpRequest;
|
|
818
805
|
constructor(client, httpRequest) {
|
|
819
|
-
|
|
806
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
820
807
|
}
|
|
821
808
|
upload(assetType, body, options) {
|
|
822
|
-
return _upload(
|
|
809
|
+
return _upload(this.#client, this.#httpRequest, assetType, body, options);
|
|
823
810
|
}
|
|
824
811
|
}
|
|
825
|
-
_client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap();
|
|
826
|
-
var _client2$3, _httpRequest2$4;
|
|
827
812
|
class AssetsClient {
|
|
813
|
+
#client;
|
|
814
|
+
#httpRequest;
|
|
828
815
|
constructor(client, httpRequest) {
|
|
829
|
-
|
|
816
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
830
817
|
}
|
|
831
818
|
upload(assetType, body, options) {
|
|
832
|
-
const observable = _upload(
|
|
819
|
+
const observable = _upload(this.#client, this.#httpRequest, assetType, body, options);
|
|
833
820
|
return rxjs.lastValueFrom(
|
|
834
821
|
observable.pipe(
|
|
835
822
|
operators.filter((event) => event.type === "response"),
|
|
@@ -840,7 +827,6 @@ class AssetsClient {
|
|
|
840
827
|
);
|
|
841
828
|
}
|
|
842
829
|
}
|
|
843
|
-
_client2$3 = /* @__PURE__ */ new WeakMap(), _httpRequest2$4 = /* @__PURE__ */ new WeakMap();
|
|
844
830
|
function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
845
831
|
validateAssetType(assetType);
|
|
846
832
|
let meta = opts.extract || void 0;
|
|
@@ -949,30 +935,22 @@ function cooerceError(err) {
|
|
|
949
935
|
function extractErrorMessage(err) {
|
|
950
936
|
return err.error ? err.error.description ? err.error.description : typeof err.error == "string" ? err.error : JSON.stringify(err.error, null, 2) : err.message || "Unknown listener error";
|
|
951
937
|
}
|
|
952
|
-
var __accessCheck$4 = (obj, member, msg) => {
|
|
953
|
-
if (!member.has(obj))
|
|
954
|
-
throw TypeError("Cannot " + msg);
|
|
955
|
-
}, __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$4 = (obj, member, value) => {
|
|
956
|
-
if (member.has(obj))
|
|
957
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
958
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
959
|
-
}, __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
|
|
960
938
|
const requiredApiVersion = "2021-03-26";
|
|
961
|
-
var _client$3;
|
|
962
939
|
class LiveClient {
|
|
940
|
+
#client;
|
|
963
941
|
constructor(client) {
|
|
964
|
-
|
|
942
|
+
this.#client = client;
|
|
965
943
|
}
|
|
966
944
|
/**
|
|
967
945
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
968
946
|
*/
|
|
969
947
|
events() {
|
|
970
|
-
const apiVersion =
|
|
948
|
+
const apiVersion = this.#client.config().apiVersion.replace(/^v/, "");
|
|
971
949
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
972
950
|
throw new Error(
|
|
973
951
|
`The live events API requires API version ${requiredApiVersion} or later. The current API version is ${apiVersion}. Please update your API version to use this feature.`
|
|
974
952
|
);
|
|
975
|
-
const path = _getDataUrl(
|
|
953
|
+
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), listenFor = ["restart", "message"];
|
|
976
954
|
return new rxjs.Observable((observer) => {
|
|
977
955
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
978
956
|
open();
|
|
@@ -1021,7 +999,6 @@ class LiveClient {
|
|
|
1021
999
|
});
|
|
1022
1000
|
}
|
|
1023
1001
|
}
|
|
1024
|
-
_client$3 = /* @__PURE__ */ new WeakMap();
|
|
1025
1002
|
function parseEvent(event) {
|
|
1026
1003
|
try {
|
|
1027
1004
|
const data = event.data && JSON.parse(event.data) || {};
|
|
@@ -1030,17 +1007,11 @@ function parseEvent(event) {
|
|
|
1030
1007
|
return err;
|
|
1031
1008
|
}
|
|
1032
1009
|
}
|
|
1033
|
-
var __accessCheck$3 = (obj, member, msg) => {
|
|
1034
|
-
if (!member.has(obj))
|
|
1035
|
-
throw TypeError("Cannot " + msg);
|
|
1036
|
-
}, __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$3 = (obj, member, value) => {
|
|
1037
|
-
if (member.has(obj))
|
|
1038
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
1039
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1040
|
-
}, __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value), _client$2, _httpRequest$3;
|
|
1041
1010
|
class ObservableDatasetsClient {
|
|
1011
|
+
#client;
|
|
1012
|
+
#httpRequest;
|
|
1042
1013
|
constructor(client, httpRequest) {
|
|
1043
|
-
|
|
1014
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1044
1015
|
}
|
|
1045
1016
|
/**
|
|
1046
1017
|
* Create a new dataset with the given name
|
|
@@ -1049,7 +1020,7 @@ class ObservableDatasetsClient {
|
|
|
1049
1020
|
* @param options - Options for the dataset
|
|
1050
1021
|
*/
|
|
1051
1022
|
create(name, options) {
|
|
1052
|
-
return _modify(
|
|
1023
|
+
return _modify(this.#client, this.#httpRequest, "PUT", name, options);
|
|
1053
1024
|
}
|
|
1054
1025
|
/**
|
|
1055
1026
|
* Edit a dataset with the given name
|
|
@@ -1058,7 +1029,7 @@ class ObservableDatasetsClient {
|
|
|
1058
1029
|
* @param options - New options for the dataset
|
|
1059
1030
|
*/
|
|
1060
1031
|
edit(name, options) {
|
|
1061
|
-
return _modify(
|
|
1032
|
+
return _modify(this.#client, this.#httpRequest, "PATCH", name, options);
|
|
1062
1033
|
}
|
|
1063
1034
|
/**
|
|
1064
1035
|
* Delete a dataset with the given name
|
|
@@ -1066,23 +1037,23 @@ class ObservableDatasetsClient {
|
|
|
1066
1037
|
* @param name - Name of the dataset to delete
|
|
1067
1038
|
*/
|
|
1068
1039
|
delete(name) {
|
|
1069
|
-
return _modify(
|
|
1040
|
+
return _modify(this.#client, this.#httpRequest, "DELETE", name);
|
|
1070
1041
|
}
|
|
1071
1042
|
/**
|
|
1072
1043
|
* Fetch a list of datasets for the configured project
|
|
1073
1044
|
*/
|
|
1074
1045
|
list() {
|
|
1075
|
-
return _request(
|
|
1046
|
+
return _request(this.#client, this.#httpRequest, {
|
|
1076
1047
|
uri: "/datasets",
|
|
1077
1048
|
tag: null
|
|
1078
1049
|
});
|
|
1079
1050
|
}
|
|
1080
1051
|
}
|
|
1081
|
-
_client$2 = /* @__PURE__ */ new WeakMap(), _httpRequest$3 = /* @__PURE__ */ new WeakMap();
|
|
1082
|
-
var _client2$2, _httpRequest2$3;
|
|
1083
1052
|
class DatasetsClient {
|
|
1053
|
+
#client;
|
|
1054
|
+
#httpRequest;
|
|
1084
1055
|
constructor(client, httpRequest) {
|
|
1085
|
-
|
|
1056
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1086
1057
|
}
|
|
1087
1058
|
/**
|
|
1088
1059
|
* Create a new dataset with the given name
|
|
@@ -1092,7 +1063,7 @@ class DatasetsClient {
|
|
|
1092
1063
|
*/
|
|
1093
1064
|
create(name, options) {
|
|
1094
1065
|
return rxjs.lastValueFrom(
|
|
1095
|
-
_modify(
|
|
1066
|
+
_modify(this.#client, this.#httpRequest, "PUT", name, options)
|
|
1096
1067
|
);
|
|
1097
1068
|
}
|
|
1098
1069
|
/**
|
|
@@ -1103,7 +1074,7 @@ class DatasetsClient {
|
|
|
1103
1074
|
*/
|
|
1104
1075
|
edit(name, options) {
|
|
1105
1076
|
return rxjs.lastValueFrom(
|
|
1106
|
-
_modify(
|
|
1077
|
+
_modify(this.#client, this.#httpRequest, "PATCH", name, options)
|
|
1107
1078
|
);
|
|
1108
1079
|
}
|
|
1109
1080
|
/**
|
|
@@ -1112,18 +1083,17 @@ class DatasetsClient {
|
|
|
1112
1083
|
* @param name - Name of the dataset to delete
|
|
1113
1084
|
*/
|
|
1114
1085
|
delete(name) {
|
|
1115
|
-
return rxjs.lastValueFrom(_modify(
|
|
1086
|
+
return rxjs.lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
|
|
1116
1087
|
}
|
|
1117
1088
|
/**
|
|
1118
1089
|
* Fetch a list of datasets for the configured project
|
|
1119
1090
|
*/
|
|
1120
1091
|
list() {
|
|
1121
1092
|
return rxjs.lastValueFrom(
|
|
1122
|
-
_request(
|
|
1093
|
+
_request(this.#client, this.#httpRequest, { uri: "/datasets", tag: null })
|
|
1123
1094
|
);
|
|
1124
1095
|
}
|
|
1125
1096
|
}
|
|
1126
|
-
_client2$2 = /* @__PURE__ */ new WeakMap(), _httpRequest2$3 = /* @__PURE__ */ new WeakMap();
|
|
1127
1097
|
function _modify(client, httpRequest, method, name, options) {
|
|
1128
1098
|
return dataset(name), _request(client, httpRequest, {
|
|
1129
1099
|
method,
|
|
@@ -1132,21 +1102,15 @@ function _modify(client, httpRequest, method, name, options) {
|
|
|
1132
1102
|
tag: null
|
|
1133
1103
|
});
|
|
1134
1104
|
}
|
|
1135
|
-
var __accessCheck$2 = (obj, member, msg) => {
|
|
1136
|
-
if (!member.has(obj))
|
|
1137
|
-
throw TypeError("Cannot " + msg);
|
|
1138
|
-
}, __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$2 = (obj, member, value) => {
|
|
1139
|
-
if (member.has(obj))
|
|
1140
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
1141
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1142
|
-
}, __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value), _client$1, _httpRequest$2;
|
|
1143
1105
|
class ObservableProjectsClient {
|
|
1106
|
+
#client;
|
|
1107
|
+
#httpRequest;
|
|
1144
1108
|
constructor(client, httpRequest) {
|
|
1145
|
-
|
|
1109
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1146
1110
|
}
|
|
1147
1111
|
list(options) {
|
|
1148
|
-
const uri =
|
|
1149
|
-
return _request(
|
|
1112
|
+
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1113
|
+
return _request(this.#client, this.#httpRequest, { uri });
|
|
1150
1114
|
}
|
|
1151
1115
|
/**
|
|
1152
1116
|
* Fetch a project by project ID
|
|
@@ -1154,18 +1118,18 @@ class ObservableProjectsClient {
|
|
|
1154
1118
|
* @param projectId - ID of the project to fetch
|
|
1155
1119
|
*/
|
|
1156
1120
|
getById(projectId2) {
|
|
1157
|
-
return _request(
|
|
1121
|
+
return _request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` });
|
|
1158
1122
|
}
|
|
1159
1123
|
}
|
|
1160
|
-
_client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */ new WeakMap();
|
|
1161
|
-
var _client2$1, _httpRequest2$2;
|
|
1162
1124
|
class ProjectsClient {
|
|
1125
|
+
#client;
|
|
1126
|
+
#httpRequest;
|
|
1163
1127
|
constructor(client, httpRequest) {
|
|
1164
|
-
|
|
1128
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1165
1129
|
}
|
|
1166
1130
|
list(options) {
|
|
1167
|
-
const uri =
|
|
1168
|
-
return rxjs.lastValueFrom(_request(
|
|
1131
|
+
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1132
|
+
return rxjs.lastValueFrom(_request(this.#client, this.#httpRequest, { uri }));
|
|
1169
1133
|
}
|
|
1170
1134
|
/**
|
|
1171
1135
|
* Fetch a project by project ID
|
|
@@ -1174,22 +1138,15 @@ class ProjectsClient {
|
|
|
1174
1138
|
*/
|
|
1175
1139
|
getById(projectId2) {
|
|
1176
1140
|
return rxjs.lastValueFrom(
|
|
1177
|
-
_request(
|
|
1141
|
+
_request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` })
|
|
1178
1142
|
);
|
|
1179
1143
|
}
|
|
1180
1144
|
}
|
|
1181
|
-
_client2$1 = /* @__PURE__ */ new WeakMap(), _httpRequest2$2 = /* @__PURE__ */ new WeakMap();
|
|
1182
|
-
var __accessCheck$1 = (obj, member, msg) => {
|
|
1183
|
-
if (!member.has(obj))
|
|
1184
|
-
throw TypeError("Cannot " + msg);
|
|
1185
|
-
}, __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$1 = (obj, member, value) => {
|
|
1186
|
-
if (member.has(obj))
|
|
1187
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
1188
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1189
|
-
}, __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value), _client, _httpRequest$1;
|
|
1190
1145
|
class ObservableUsersClient {
|
|
1146
|
+
#client;
|
|
1147
|
+
#httpRequest;
|
|
1191
1148
|
constructor(client, httpRequest) {
|
|
1192
|
-
|
|
1149
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1193
1150
|
}
|
|
1194
1151
|
/**
|
|
1195
1152
|
* Fetch a user by user ID
|
|
@@ -1198,17 +1155,17 @@ class ObservableUsersClient {
|
|
|
1198
1155
|
*/
|
|
1199
1156
|
getById(id) {
|
|
1200
1157
|
return _request(
|
|
1201
|
-
|
|
1202
|
-
|
|
1158
|
+
this.#client,
|
|
1159
|
+
this.#httpRequest,
|
|
1203
1160
|
{ uri: `/users/${id}` }
|
|
1204
1161
|
);
|
|
1205
1162
|
}
|
|
1206
1163
|
}
|
|
1207
|
-
_client = /* @__PURE__ */ new WeakMap(), _httpRequest$1 = /* @__PURE__ */ new WeakMap();
|
|
1208
|
-
var _client2, _httpRequest2$1;
|
|
1209
1164
|
class UsersClient {
|
|
1165
|
+
#client;
|
|
1166
|
+
#httpRequest;
|
|
1210
1167
|
constructor(client, httpRequest) {
|
|
1211
|
-
|
|
1168
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1212
1169
|
}
|
|
1213
1170
|
/**
|
|
1214
1171
|
* Fetch a user by user ID
|
|
@@ -1217,39 +1174,44 @@ class UsersClient {
|
|
|
1217
1174
|
*/
|
|
1218
1175
|
getById(id) {
|
|
1219
1176
|
return rxjs.lastValueFrom(
|
|
1220
|
-
_request(
|
|
1177
|
+
_request(this.#client, this.#httpRequest, {
|
|
1221
1178
|
uri: `/users/${id}`
|
|
1222
1179
|
})
|
|
1223
1180
|
);
|
|
1224
1181
|
}
|
|
1225
1182
|
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1183
|
+
class ObservableSanityClient {
|
|
1184
|
+
assets;
|
|
1185
|
+
datasets;
|
|
1186
|
+
live;
|
|
1187
|
+
projects;
|
|
1188
|
+
users;
|
|
1189
|
+
/**
|
|
1190
|
+
* Private properties
|
|
1191
|
+
*/
|
|
1192
|
+
#clientConfig;
|
|
1193
|
+
#httpRequest;
|
|
1194
|
+
/**
|
|
1195
|
+
* Instance properties
|
|
1196
|
+
*/
|
|
1197
|
+
listen = _listen;
|
|
1236
1198
|
constructor(httpRequest, config = defaultConfig) {
|
|
1237
|
-
|
|
1199
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest);
|
|
1238
1200
|
}
|
|
1239
1201
|
/**
|
|
1240
1202
|
* Clone the client - returns a new instance
|
|
1241
1203
|
*/
|
|
1242
1204
|
clone() {
|
|
1243
|
-
return new
|
|
1205
|
+
return new ObservableSanityClient(this.#httpRequest, this.config());
|
|
1244
1206
|
}
|
|
1245
1207
|
config(newConfig) {
|
|
1246
1208
|
if (newConfig === void 0)
|
|
1247
|
-
return { ...
|
|
1248
|
-
if (
|
|
1209
|
+
return { ...this.#clientConfig };
|
|
1210
|
+
if (this.#clientConfig && this.#clientConfig.allowReconfigure === !1)
|
|
1249
1211
|
throw new Error(
|
|
1250
1212
|
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1251
1213
|
);
|
|
1252
|
-
return
|
|
1214
|
+
return this.#clientConfig = initConfig(newConfig, this.#clientConfig || {}), this;
|
|
1253
1215
|
}
|
|
1254
1216
|
/**
|
|
1255
1217
|
* Clone the client with a new (partial) configuration.
|
|
@@ -1258,20 +1220,20 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1258
1220
|
*/
|
|
1259
1221
|
withConfig(newConfig) {
|
|
1260
1222
|
const thisConfig = this.config();
|
|
1261
|
-
return new
|
|
1223
|
+
return new ObservableSanityClient(this.#httpRequest, {
|
|
1262
1224
|
...thisConfig,
|
|
1263
1225
|
...newConfig,
|
|
1264
1226
|
stega: {
|
|
1265
1227
|
...thisConfig.stega || {},
|
|
1266
|
-
...typeof
|
|
1228
|
+
...typeof newConfig?.stega == "boolean" ? { enabled: newConfig.stega } : newConfig?.stega || {}
|
|
1267
1229
|
}
|
|
1268
1230
|
});
|
|
1269
1231
|
}
|
|
1270
1232
|
fetch(query, params, options) {
|
|
1271
1233
|
return _fetch(
|
|
1272
1234
|
this,
|
|
1273
|
-
|
|
1274
|
-
|
|
1235
|
+
this.#httpRequest,
|
|
1236
|
+
this.#clientConfig.stega,
|
|
1275
1237
|
query,
|
|
1276
1238
|
params,
|
|
1277
1239
|
options
|
|
@@ -1284,7 +1246,7 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1284
1246
|
* @param options - Request options
|
|
1285
1247
|
*/
|
|
1286
1248
|
getDocument(id, options) {
|
|
1287
|
-
return _getDocument(this,
|
|
1249
|
+
return _getDocument(this, this.#httpRequest, id, options);
|
|
1288
1250
|
}
|
|
1289
1251
|
/**
|
|
1290
1252
|
* Fetch multiple documents in one request.
|
|
@@ -1296,22 +1258,22 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1296
1258
|
* @param options - Request options
|
|
1297
1259
|
*/
|
|
1298
1260
|
getDocuments(ids, options) {
|
|
1299
|
-
return _getDocuments(this,
|
|
1261
|
+
return _getDocuments(this, this.#httpRequest, ids, options);
|
|
1300
1262
|
}
|
|
1301
1263
|
create(document, options) {
|
|
1302
|
-
return _create(this,
|
|
1264
|
+
return _create(this, this.#httpRequest, document, "create", options);
|
|
1303
1265
|
}
|
|
1304
1266
|
createIfNotExists(document, options) {
|
|
1305
|
-
return _createIfNotExists(this,
|
|
1267
|
+
return _createIfNotExists(this, this.#httpRequest, document, options);
|
|
1306
1268
|
}
|
|
1307
1269
|
createOrReplace(document, options) {
|
|
1308
|
-
return _createOrReplace(this,
|
|
1270
|
+
return _createOrReplace(this, this.#httpRequest, document, options);
|
|
1309
1271
|
}
|
|
1310
1272
|
delete(selection, options) {
|
|
1311
|
-
return _delete(this,
|
|
1273
|
+
return _delete(this, this.#httpRequest, selection, options);
|
|
1312
1274
|
}
|
|
1313
1275
|
mutate(operations, options) {
|
|
1314
|
-
return _mutate(this,
|
|
1276
|
+
return _mutate(this, this.#httpRequest, operations, options);
|
|
1315
1277
|
}
|
|
1316
1278
|
/**
|
|
1317
1279
|
* Create a new buildable patch of operations to perform
|
|
@@ -1338,7 +1300,7 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1338
1300
|
* @param options - Action options
|
|
1339
1301
|
*/
|
|
1340
1302
|
action(operations, options) {
|
|
1341
|
-
return _action(this,
|
|
1303
|
+
return _action(this, this.#httpRequest, operations, options);
|
|
1342
1304
|
}
|
|
1343
1305
|
/**
|
|
1344
1306
|
* Perform an HTTP request against the Sanity API
|
|
@@ -1346,7 +1308,7 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1346
1308
|
* @param options - Request options
|
|
1347
1309
|
*/
|
|
1348
1310
|
request(options) {
|
|
1349
|
-
return _request(this,
|
|
1311
|
+
return _request(this, this.#httpRequest, options);
|
|
1350
1312
|
}
|
|
1351
1313
|
/**
|
|
1352
1314
|
* Get a Sanity API URL for the URI provided
|
|
@@ -1366,28 +1328,43 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1366
1328
|
getDataUrl(operation, path) {
|
|
1367
1329
|
return _getDataUrl(this, operation, path);
|
|
1368
1330
|
}
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1331
|
+
}
|
|
1332
|
+
class SanityClient {
|
|
1333
|
+
assets;
|
|
1334
|
+
datasets;
|
|
1335
|
+
live;
|
|
1336
|
+
projects;
|
|
1337
|
+
users;
|
|
1338
|
+
/**
|
|
1339
|
+
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1340
|
+
*/
|
|
1341
|
+
observable;
|
|
1342
|
+
/**
|
|
1343
|
+
* Private properties
|
|
1344
|
+
*/
|
|
1345
|
+
#clientConfig;
|
|
1346
|
+
#httpRequest;
|
|
1347
|
+
/**
|
|
1348
|
+
* Instance properties
|
|
1349
|
+
*/
|
|
1350
|
+
listen = _listen;
|
|
1374
1351
|
constructor(httpRequest, config = defaultConfig) {
|
|
1375
|
-
|
|
1352
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1376
1353
|
}
|
|
1377
1354
|
/**
|
|
1378
1355
|
* Clone the client - returns a new instance
|
|
1379
1356
|
*/
|
|
1380
1357
|
clone() {
|
|
1381
|
-
return new
|
|
1358
|
+
return new SanityClient(this.#httpRequest, this.config());
|
|
1382
1359
|
}
|
|
1383
1360
|
config(newConfig) {
|
|
1384
1361
|
if (newConfig === void 0)
|
|
1385
|
-
return { ...
|
|
1386
|
-
if (
|
|
1362
|
+
return { ...this.#clientConfig };
|
|
1363
|
+
if (this.#clientConfig && this.#clientConfig.allowReconfigure === !1)
|
|
1387
1364
|
throw new Error(
|
|
1388
1365
|
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1389
1366
|
);
|
|
1390
|
-
return this.observable && this.observable.config(newConfig),
|
|
1367
|
+
return this.observable && this.observable.config(newConfig), this.#clientConfig = initConfig(newConfig, this.#clientConfig || {}), this;
|
|
1391
1368
|
}
|
|
1392
1369
|
/**
|
|
1393
1370
|
* Clone the client with a new (partial) configuration.
|
|
@@ -1396,12 +1373,12 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1396
1373
|
*/
|
|
1397
1374
|
withConfig(newConfig) {
|
|
1398
1375
|
const thisConfig = this.config();
|
|
1399
|
-
return new
|
|
1376
|
+
return new SanityClient(this.#httpRequest, {
|
|
1400
1377
|
...thisConfig,
|
|
1401
1378
|
...newConfig,
|
|
1402
1379
|
stega: {
|
|
1403
1380
|
...thisConfig.stega || {},
|
|
1404
|
-
...typeof
|
|
1381
|
+
...typeof newConfig?.stega == "boolean" ? { enabled: newConfig.stega } : newConfig?.stega || {}
|
|
1405
1382
|
}
|
|
1406
1383
|
});
|
|
1407
1384
|
}
|
|
@@ -1409,8 +1386,8 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1409
1386
|
return rxjs.lastValueFrom(
|
|
1410
1387
|
_fetch(
|
|
1411
1388
|
this,
|
|
1412
|
-
|
|
1413
|
-
|
|
1389
|
+
this.#httpRequest,
|
|
1390
|
+
this.#clientConfig.stega,
|
|
1414
1391
|
query,
|
|
1415
1392
|
params,
|
|
1416
1393
|
options
|
|
@@ -1424,7 +1401,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1424
1401
|
* @param options - Request options
|
|
1425
1402
|
*/
|
|
1426
1403
|
getDocument(id, options) {
|
|
1427
|
-
return rxjs.lastValueFrom(_getDocument(this,
|
|
1404
|
+
return rxjs.lastValueFrom(_getDocument(this, this.#httpRequest, id, options));
|
|
1428
1405
|
}
|
|
1429
1406
|
/**
|
|
1430
1407
|
* Fetch multiple documents in one request.
|
|
@@ -1436,28 +1413,28 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1436
1413
|
* @param options - Request options
|
|
1437
1414
|
*/
|
|
1438
1415
|
getDocuments(ids, options) {
|
|
1439
|
-
return rxjs.lastValueFrom(_getDocuments(this,
|
|
1416
|
+
return rxjs.lastValueFrom(_getDocuments(this, this.#httpRequest, ids, options));
|
|
1440
1417
|
}
|
|
1441
1418
|
create(document, options) {
|
|
1442
1419
|
return rxjs.lastValueFrom(
|
|
1443
|
-
_create(this,
|
|
1420
|
+
_create(this, this.#httpRequest, document, "create", options)
|
|
1444
1421
|
);
|
|
1445
1422
|
}
|
|
1446
1423
|
createIfNotExists(document, options) {
|
|
1447
1424
|
return rxjs.lastValueFrom(
|
|
1448
|
-
_createIfNotExists(this,
|
|
1425
|
+
_createIfNotExists(this, this.#httpRequest, document, options)
|
|
1449
1426
|
);
|
|
1450
1427
|
}
|
|
1451
1428
|
createOrReplace(document, options) {
|
|
1452
1429
|
return rxjs.lastValueFrom(
|
|
1453
|
-
_createOrReplace(this,
|
|
1430
|
+
_createOrReplace(this, this.#httpRequest, document, options)
|
|
1454
1431
|
);
|
|
1455
1432
|
}
|
|
1456
1433
|
delete(selection, options) {
|
|
1457
|
-
return rxjs.lastValueFrom(_delete(this,
|
|
1434
|
+
return rxjs.lastValueFrom(_delete(this, this.#httpRequest, selection, options));
|
|
1458
1435
|
}
|
|
1459
1436
|
mutate(operations, options) {
|
|
1460
|
-
return rxjs.lastValueFrom(_mutate(this,
|
|
1437
|
+
return rxjs.lastValueFrom(_mutate(this, this.#httpRequest, operations, options));
|
|
1461
1438
|
}
|
|
1462
1439
|
/**
|
|
1463
1440
|
* Create a new buildable patch of operations to perform
|
|
@@ -1485,7 +1462,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1485
1462
|
* @param options - Action options
|
|
1486
1463
|
*/
|
|
1487
1464
|
action(operations, options) {
|
|
1488
|
-
return rxjs.lastValueFrom(_action(this,
|
|
1465
|
+
return rxjs.lastValueFrom(_action(this, this.#httpRequest, operations, options));
|
|
1489
1466
|
}
|
|
1490
1467
|
/**
|
|
1491
1468
|
* Perform a request against the Sanity API
|
|
@@ -1495,7 +1472,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1495
1472
|
* @returns Promise resolving to the response body
|
|
1496
1473
|
*/
|
|
1497
1474
|
request(options) {
|
|
1498
|
-
return rxjs.lastValueFrom(_request(this,
|
|
1475
|
+
return rxjs.lastValueFrom(_request(this, this.#httpRequest, options));
|
|
1499
1476
|
}
|
|
1500
1477
|
/**
|
|
1501
1478
|
* Perform an HTTP request a `/data` sub-endpoint
|
|
@@ -1508,7 +1485,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1508
1485
|
* @internal
|
|
1509
1486
|
*/
|
|
1510
1487
|
dataRequest(endpoint, body, options) {
|
|
1511
|
-
return rxjs.lastValueFrom(_dataRequest(this,
|
|
1488
|
+
return rxjs.lastValueFrom(_dataRequest(this, this.#httpRequest, endpoint, body, options));
|
|
1512
1489
|
}
|
|
1513
1490
|
/**
|
|
1514
1491
|
* Get a Sanity API URL for the URI provided
|
|
@@ -1528,9 +1505,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1528
1505
|
getDataUrl(operation, path) {
|
|
1529
1506
|
return _getDataUrl(this, operation, path);
|
|
1530
1507
|
}
|
|
1531
|
-
}
|
|
1532
|
-
_clientConfig2 = /* @__PURE__ */ new WeakMap(), _httpRequest2 = /* @__PURE__ */ new WeakMap();
|
|
1533
|
-
let SanityClient = _SanityClient;
|
|
1508
|
+
}
|
|
1534
1509
|
function defineCreateClientExports(envMiddleware2, ClassConstructor) {
|
|
1535
1510
|
const defaultRequester = defineHttpRequest(envMiddleware2);
|
|
1536
1511
|
return { requester: defaultRequester, createClient: (config) => new ClassConstructor(
|