@sanity/client 6.21.0 → 6.21.2
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 +5 -3
- package/dist/_chunks-cjs/resolveEditInfo.cjs +1 -1
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +8 -10
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/resolveEditInfo.js +1 -1
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +8 -10
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/index.browser.cjs +175 -209
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +6 -2
- package/dist/index.browser.d.ts +6 -2
- package/dist/index.browser.js +175 -210
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +176 -210
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +176 -211
- package/dist/index.js.map +1 -1
- package/package.json +18 -18
- package/src/data/encodeQueryString.ts +4 -1
- package/src/data/listen.ts +1 -0
- package/src/types.ts +7 -0
- package/umd/sanityClient.js +194 -965
- package/umd/sanityClient.min.js +2 -8
package/dist/index.js
CHANGED
|
@@ -2,19 +2,26 @@ import { getIt } from "get-it";
|
|
|
2
2
|
import { adapter, environment } from "get-it";
|
|
3
3
|
import { retry, jsonRequest, jsonResponse, progress, observable, debug, headers, agent } from "get-it/middleware";
|
|
4
4
|
import { Observable, from, lastValueFrom } from "rxjs";
|
|
5
|
-
import { combineLatestWith, map, filter } from "rxjs/operators";
|
|
6
5
|
import { stegaClean } from "./_chunks-es/stegaClean.js";
|
|
7
|
-
|
|
6
|
+
import { combineLatestWith, map, filter } from "rxjs/operators";
|
|
8
7
|
class ClientError extends Error {
|
|
8
|
+
response;
|
|
9
|
+
statusCode = 400;
|
|
10
|
+
responseBody;
|
|
11
|
+
details;
|
|
9
12
|
constructor(res) {
|
|
10
13
|
const props = extractErrorProps(res);
|
|
11
|
-
super(props.message),
|
|
14
|
+
super(props.message), Object.assign(this, props);
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
class ServerError extends Error {
|
|
18
|
+
response;
|
|
19
|
+
statusCode = 500;
|
|
20
|
+
responseBody;
|
|
21
|
+
details;
|
|
15
22
|
constructor(res) {
|
|
16
23
|
const props = extractErrorProps(res);
|
|
17
|
-
super(props.message),
|
|
24
|
+
super(props.message), Object.assign(this, props);
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
27
|
function extractErrorProps(res) {
|
|
@@ -28,10 +35,7 @@ function extractErrorProps(res) {
|
|
|
28
35
|
if (body.error && body.message)
|
|
29
36
|
return props.message = `${body.error} - ${body.message}`, props;
|
|
30
37
|
if (isMutationError(body) || isActionError(body)) {
|
|
31
|
-
const allItems = body.error.items || [], items = allItems.slice(0, 5).map((item) =>
|
|
32
|
-
var _a;
|
|
33
|
-
return (_a = item.error) == null ? void 0 : _a.description;
|
|
34
|
-
}).filter(Boolean);
|
|
38
|
+
const allItems = body.error.items || [], items = allItems.slice(0, 5).map((item) => item.error?.description).filter(Boolean);
|
|
35
39
|
let itemsStr = items.length ? `:
|
|
36
40
|
- ${items.join(`
|
|
37
41
|
- `)}` : "";
|
|
@@ -147,17 +151,11 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
147
151
|
);
|
|
148
152
|
return tag;
|
|
149
153
|
};
|
|
150
|
-
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) => {
|
|
151
|
-
if (!member.has(obj))
|
|
152
|
-
throw TypeError("Cannot " + msg);
|
|
153
|
-
}, __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) => {
|
|
154
|
-
if (member.has(obj))
|
|
155
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
156
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
157
|
-
}, __privateSet$7 = (obj, member, value, setter) => (__accessCheck$7(obj, member, "write to private field"), member.set(obj, value), value);
|
|
158
154
|
class BasePatch {
|
|
155
|
+
selection;
|
|
156
|
+
operations;
|
|
159
157
|
constructor(selection, operations = {}) {
|
|
160
|
-
|
|
158
|
+
this.selection = selection, this.operations = operations;
|
|
161
159
|
}
|
|
162
160
|
/**
|
|
163
161
|
* Sets the given attributes to the document. Does NOT merge objects.
|
|
@@ -288,62 +286,52 @@ class BasePatch {
|
|
|
288
286
|
return this._assign(op, props, !1);
|
|
289
287
|
}
|
|
290
288
|
}
|
|
291
|
-
|
|
292
|
-
|
|
289
|
+
class ObservablePatch extends BasePatch {
|
|
290
|
+
#client;
|
|
293
291
|
constructor(selection, operations, client) {
|
|
294
|
-
super(selection, operations),
|
|
292
|
+
super(selection, operations), this.#client = client;
|
|
295
293
|
}
|
|
296
294
|
/**
|
|
297
295
|
* Clones the patch
|
|
298
296
|
*/
|
|
299
297
|
clone() {
|
|
300
|
-
return new
|
|
298
|
+
return new ObservablePatch(this.selection, { ...this.operations }, this.#client);
|
|
301
299
|
}
|
|
302
300
|
commit(options) {
|
|
303
|
-
if (!
|
|
301
|
+
if (!this.#client)
|
|
304
302
|
throw new Error(
|
|
305
303
|
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
306
304
|
);
|
|
307
305
|
const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
|
|
308
|
-
return
|
|
306
|
+
return this.#client.mutate({ patch: this.serialize() }, opts);
|
|
309
307
|
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
var _client2$5;
|
|
314
|
-
const _Patch = class _Patch2 extends BasePatch {
|
|
308
|
+
}
|
|
309
|
+
class Patch extends BasePatch {
|
|
310
|
+
#client;
|
|
315
311
|
constructor(selection, operations, client) {
|
|
316
|
-
super(selection, operations),
|
|
312
|
+
super(selection, operations), this.#client = client;
|
|
317
313
|
}
|
|
318
314
|
/**
|
|
319
315
|
* Clones the patch
|
|
320
316
|
*/
|
|
321
317
|
clone() {
|
|
322
|
-
return new
|
|
318
|
+
return new Patch(this.selection, { ...this.operations }, this.#client);
|
|
323
319
|
}
|
|
324
320
|
commit(options) {
|
|
325
|
-
if (!
|
|
321
|
+
if (!this.#client)
|
|
326
322
|
throw new Error(
|
|
327
323
|
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
328
324
|
);
|
|
329
325
|
const returnFirst = typeof this.selection == "string", opts = Object.assign({ returnFirst, returnDocuments: !0 }, options);
|
|
330
|
-
return
|
|
326
|
+
return this.#client.mutate({ patch: this.serialize() }, opts);
|
|
331
327
|
}
|
|
332
|
-
}
|
|
333
|
-
_client2$5 = /* @__PURE__ */ new WeakMap();
|
|
334
|
-
let Patch = _Patch;
|
|
335
|
-
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) => {
|
|
336
|
-
if (!member.has(obj))
|
|
337
|
-
throw TypeError("Cannot " + msg);
|
|
338
|
-
}, __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) => {
|
|
339
|
-
if (member.has(obj))
|
|
340
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
341
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
342
|
-
}, __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
|
|
328
|
+
}
|
|
343
329
|
const defaultMutateOptions = { returnDocuments: !1 };
|
|
344
330
|
class BaseTransaction {
|
|
331
|
+
operations;
|
|
332
|
+
trxId;
|
|
345
333
|
constructor(operations = [], transactionId) {
|
|
346
|
-
|
|
334
|
+
this.operations = operations, this.trxId = transactionId;
|
|
347
335
|
}
|
|
348
336
|
/**
|
|
349
337
|
* 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.
|
|
@@ -408,23 +396,23 @@ class BaseTransaction {
|
|
|
408
396
|
return this.operations.push(mut), this;
|
|
409
397
|
}
|
|
410
398
|
}
|
|
411
|
-
|
|
412
|
-
|
|
399
|
+
class Transaction extends BaseTransaction {
|
|
400
|
+
#client;
|
|
413
401
|
constructor(operations, client, transactionId) {
|
|
414
|
-
super(operations, transactionId),
|
|
402
|
+
super(operations, transactionId), this.#client = client;
|
|
415
403
|
}
|
|
416
404
|
/**
|
|
417
405
|
* Clones the transaction
|
|
418
406
|
*/
|
|
419
407
|
clone() {
|
|
420
|
-
return new
|
|
408
|
+
return new Transaction([...this.operations], this.#client, this.trxId);
|
|
421
409
|
}
|
|
422
410
|
commit(options) {
|
|
423
|
-
if (!
|
|
411
|
+
if (!this.#client)
|
|
424
412
|
throw new Error(
|
|
425
413
|
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
426
414
|
);
|
|
427
|
-
return
|
|
415
|
+
return this.#client.mutate(
|
|
428
416
|
this.serialize(),
|
|
429
417
|
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
430
418
|
);
|
|
@@ -434,33 +422,31 @@ const _Transaction = class _Transaction2 extends BaseTransaction {
|
|
|
434
422
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch)
|
|
435
423
|
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
436
424
|
if (isBuilder) {
|
|
437
|
-
const patch = patchOps(new Patch(patchOrDocumentId, {},
|
|
425
|
+
const patch = patchOps(new Patch(patchOrDocumentId, {}, this.#client));
|
|
438
426
|
if (!(patch instanceof Patch))
|
|
439
427
|
throw new Error("function passed to `patch()` must return the patch");
|
|
440
428
|
return this._add({ patch: patch.serialize() });
|
|
441
429
|
}
|
|
442
430
|
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
443
431
|
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
var _client2$4;
|
|
448
|
-
const _ObservableTransaction = class _ObservableTransaction2 extends BaseTransaction {
|
|
432
|
+
}
|
|
433
|
+
class ObservableTransaction extends BaseTransaction {
|
|
434
|
+
#client;
|
|
449
435
|
constructor(operations, client, transactionId) {
|
|
450
|
-
super(operations, transactionId),
|
|
436
|
+
super(operations, transactionId), this.#client = client;
|
|
451
437
|
}
|
|
452
438
|
/**
|
|
453
439
|
* Clones the transaction
|
|
454
440
|
*/
|
|
455
441
|
clone() {
|
|
456
|
-
return new
|
|
442
|
+
return new ObservableTransaction([...this.operations], this.#client, this.trxId);
|
|
457
443
|
}
|
|
458
444
|
commit(options) {
|
|
459
|
-
if (!
|
|
445
|
+
if (!this.#client)
|
|
460
446
|
throw new Error(
|
|
461
447
|
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
462
448
|
);
|
|
463
|
-
return
|
|
449
|
+
return this.#client.mutate(
|
|
464
450
|
this.serialize(),
|
|
465
451
|
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
466
452
|
);
|
|
@@ -470,16 +456,14 @@ const _ObservableTransaction = class _ObservableTransaction2 extends BaseTransac
|
|
|
470
456
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof ObservablePatch)
|
|
471
457
|
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
472
458
|
if (isBuilder) {
|
|
473
|
-
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {},
|
|
459
|
+
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, this.#client));
|
|
474
460
|
if (!(patch instanceof ObservablePatch))
|
|
475
461
|
throw new Error("function passed to `patch()` must return the patch");
|
|
476
462
|
return this._add({ patch: patch.serialize() });
|
|
477
463
|
}
|
|
478
464
|
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
479
465
|
}
|
|
480
|
-
}
|
|
481
|
-
_client2$4 = /* @__PURE__ */ new WeakMap();
|
|
482
|
-
let ObservableTransaction = _ObservableTransaction;
|
|
466
|
+
}
|
|
483
467
|
const BASE_URL = "https://www.sanity.io/help/";
|
|
484
468
|
function generateHelpUrl(slug) {
|
|
485
469
|
return BASE_URL + slug;
|
|
@@ -594,13 +578,13 @@ const encodeQueryString = ({
|
|
|
594
578
|
params = {},
|
|
595
579
|
options = {}
|
|
596
580
|
}) => {
|
|
597
|
-
const searchParams = new URLSearchParams(), { tag, returnQuery, ...opts } = options;
|
|
581
|
+
const searchParams = new URLSearchParams(), { tag, includeMutations, returnQuery, ...opts } = options;
|
|
598
582
|
tag && searchParams.append("tag", tag), searchParams.append("query", query);
|
|
599
583
|
for (const [key, value] of Object.entries(params))
|
|
600
584
|
searchParams.append(`$${key}`, JSON.stringify(value));
|
|
601
585
|
for (const [key, value] of Object.entries(opts))
|
|
602
586
|
value && searchParams.append(key, `${value}`);
|
|
603
|
-
return returnQuery === !1 && searchParams.append("returnQuery", "false"), `?${searchParams}`;
|
|
587
|
+
return returnQuery === !1 && searchParams.append("returnQuery", "false"), includeMutations === !1 && searchParams.append("includeMutations", "false"), `?${searchParams}`;
|
|
604
588
|
}, excludeFalsey = (param, defValue) => param === !1 ? void 0 : typeof param > "u" ? defValue : param, getMutationQuery = (options = {}) => ({
|
|
605
589
|
dryRun: options.dryRun,
|
|
606
590
|
returnIds: !0,
|
|
@@ -734,12 +718,11 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
734
718
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
735
719
|
}
|
|
736
720
|
function _requestObservable(client, httpRequest, options) {
|
|
737
|
-
var _a, _b;
|
|
738
721
|
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;
|
|
739
|
-
let useCdn = (
|
|
722
|
+
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
740
723
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
741
724
|
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) {
|
|
742
|
-
const resultSourceMap =
|
|
725
|
+
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
743
726
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
744
727
|
const perspective = options.perspective || config.perspective;
|
|
745
728
|
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 });
|
|
@@ -783,36 +766,29 @@ function _withAbortSignal(signal) {
|
|
|
783
766
|
}
|
|
784
767
|
const isDomExceptionSupported = !!globalThis.DOMException;
|
|
785
768
|
function _createAbortError(signal) {
|
|
786
|
-
var _a, _b;
|
|
787
769
|
if (isDomExceptionSupported)
|
|
788
|
-
return new DOMException(
|
|
789
|
-
const error = new Error(
|
|
770
|
+
return new DOMException(signal?.reason ?? "The operation was aborted.", "AbortError");
|
|
771
|
+
const error = new Error(signal?.reason ?? "The operation was aborted.");
|
|
790
772
|
return error.name = "AbortError", error;
|
|
791
773
|
}
|
|
792
|
-
var __accessCheck$5 = (obj, member, msg) => {
|
|
793
|
-
if (!member.has(obj))
|
|
794
|
-
throw TypeError("Cannot " + msg);
|
|
795
|
-
}, __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) => {
|
|
796
|
-
if (member.has(obj))
|
|
797
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
798
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
799
|
-
}, __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value), _client$4, _httpRequest$4;
|
|
800
774
|
class ObservableAssetsClient {
|
|
775
|
+
#client;
|
|
776
|
+
#httpRequest;
|
|
801
777
|
constructor(client, httpRequest) {
|
|
802
|
-
|
|
778
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
803
779
|
}
|
|
804
780
|
upload(assetType, body, options) {
|
|
805
|
-
return _upload(
|
|
781
|
+
return _upload(this.#client, this.#httpRequest, assetType, body, options);
|
|
806
782
|
}
|
|
807
783
|
}
|
|
808
|
-
_client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap();
|
|
809
|
-
var _client2$3, _httpRequest2$4;
|
|
810
784
|
class AssetsClient {
|
|
785
|
+
#client;
|
|
786
|
+
#httpRequest;
|
|
811
787
|
constructor(client, httpRequest) {
|
|
812
|
-
|
|
788
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
813
789
|
}
|
|
814
790
|
upload(assetType, body, options) {
|
|
815
|
-
const observable2 = _upload(
|
|
791
|
+
const observable2 = _upload(this.#client, this.#httpRequest, assetType, body, options);
|
|
816
792
|
return lastValueFrom(
|
|
817
793
|
observable2.pipe(
|
|
818
794
|
filter((event) => event.type === "response"),
|
|
@@ -823,7 +799,6 @@ class AssetsClient {
|
|
|
823
799
|
);
|
|
824
800
|
}
|
|
825
801
|
}
|
|
826
|
-
_client2$3 = /* @__PURE__ */ new WeakMap(), _httpRequest2$4 = /* @__PURE__ */ new WeakMap();
|
|
827
802
|
function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
828
803
|
validateAssetType(assetType);
|
|
829
804
|
let meta = opts.extract || void 0;
|
|
@@ -859,6 +834,7 @@ var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj
|
|
|
859
834
|
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), MAX_URL_LENGTH = 14800, possibleOptions = [
|
|
860
835
|
"includePreviousRevision",
|
|
861
836
|
"includeResult",
|
|
837
|
+
"includeMutations",
|
|
862
838
|
"visibility",
|
|
863
839
|
"effectFormat",
|
|
864
840
|
"tag"
|
|
@@ -931,30 +907,22 @@ function cooerceError(err) {
|
|
|
931
907
|
function extractErrorMessage(err) {
|
|
932
908
|
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";
|
|
933
909
|
}
|
|
934
|
-
var __accessCheck$4 = (obj, member, msg) => {
|
|
935
|
-
if (!member.has(obj))
|
|
936
|
-
throw TypeError("Cannot " + msg);
|
|
937
|
-
}, __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) => {
|
|
938
|
-
if (member.has(obj))
|
|
939
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
940
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
941
|
-
}, __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
|
|
942
910
|
const requiredApiVersion = "2021-03-26";
|
|
943
|
-
var _client$3;
|
|
944
911
|
class LiveClient {
|
|
912
|
+
#client;
|
|
945
913
|
constructor(client) {
|
|
946
|
-
|
|
914
|
+
this.#client = client;
|
|
947
915
|
}
|
|
948
916
|
/**
|
|
949
917
|
* Requires `apiVersion` to be `2021-03-26` or later.
|
|
950
918
|
*/
|
|
951
919
|
events() {
|
|
952
|
-
const apiVersion =
|
|
920
|
+
const apiVersion = this.#client.config().apiVersion.replace(/^v/, "");
|
|
953
921
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion)
|
|
954
922
|
throw new Error(
|
|
955
923
|
`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.`
|
|
956
924
|
);
|
|
957
|
-
const path = _getDataUrl(
|
|
925
|
+
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), listenFor = ["restart", "message"];
|
|
958
926
|
return new Observable((observer) => {
|
|
959
927
|
let es, reconnectTimer, stopped = !1, unsubscribed = !1;
|
|
960
928
|
open();
|
|
@@ -1003,7 +971,6 @@ class LiveClient {
|
|
|
1003
971
|
});
|
|
1004
972
|
}
|
|
1005
973
|
}
|
|
1006
|
-
_client$3 = /* @__PURE__ */ new WeakMap();
|
|
1007
974
|
function parseEvent(event) {
|
|
1008
975
|
try {
|
|
1009
976
|
const data = event.data && JSON.parse(event.data) || {};
|
|
@@ -1012,17 +979,11 @@ function parseEvent(event) {
|
|
|
1012
979
|
return err;
|
|
1013
980
|
}
|
|
1014
981
|
}
|
|
1015
|
-
var __accessCheck$3 = (obj, member, msg) => {
|
|
1016
|
-
if (!member.has(obj))
|
|
1017
|
-
throw TypeError("Cannot " + msg);
|
|
1018
|
-
}, __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) => {
|
|
1019
|
-
if (member.has(obj))
|
|
1020
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
1021
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1022
|
-
}, __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value), _client$2, _httpRequest$3;
|
|
1023
982
|
class ObservableDatasetsClient {
|
|
983
|
+
#client;
|
|
984
|
+
#httpRequest;
|
|
1024
985
|
constructor(client, httpRequest) {
|
|
1025
|
-
|
|
986
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1026
987
|
}
|
|
1027
988
|
/**
|
|
1028
989
|
* Create a new dataset with the given name
|
|
@@ -1031,7 +992,7 @@ class ObservableDatasetsClient {
|
|
|
1031
992
|
* @param options - Options for the dataset
|
|
1032
993
|
*/
|
|
1033
994
|
create(name2, options) {
|
|
1034
|
-
return _modify(
|
|
995
|
+
return _modify(this.#client, this.#httpRequest, "PUT", name2, options);
|
|
1035
996
|
}
|
|
1036
997
|
/**
|
|
1037
998
|
* Edit a dataset with the given name
|
|
@@ -1040,7 +1001,7 @@ class ObservableDatasetsClient {
|
|
|
1040
1001
|
* @param options - New options for the dataset
|
|
1041
1002
|
*/
|
|
1042
1003
|
edit(name2, options) {
|
|
1043
|
-
return _modify(
|
|
1004
|
+
return _modify(this.#client, this.#httpRequest, "PATCH", name2, options);
|
|
1044
1005
|
}
|
|
1045
1006
|
/**
|
|
1046
1007
|
* Delete a dataset with the given name
|
|
@@ -1048,23 +1009,23 @@ class ObservableDatasetsClient {
|
|
|
1048
1009
|
* @param name - Name of the dataset to delete
|
|
1049
1010
|
*/
|
|
1050
1011
|
delete(name2) {
|
|
1051
|
-
return _modify(
|
|
1012
|
+
return _modify(this.#client, this.#httpRequest, "DELETE", name2);
|
|
1052
1013
|
}
|
|
1053
1014
|
/**
|
|
1054
1015
|
* Fetch a list of datasets for the configured project
|
|
1055
1016
|
*/
|
|
1056
1017
|
list() {
|
|
1057
|
-
return _request(
|
|
1018
|
+
return _request(this.#client, this.#httpRequest, {
|
|
1058
1019
|
uri: "/datasets",
|
|
1059
1020
|
tag: null
|
|
1060
1021
|
});
|
|
1061
1022
|
}
|
|
1062
1023
|
}
|
|
1063
|
-
_client$2 = /* @__PURE__ */ new WeakMap(), _httpRequest$3 = /* @__PURE__ */ new WeakMap();
|
|
1064
|
-
var _client2$2, _httpRequest2$3;
|
|
1065
1024
|
class DatasetsClient {
|
|
1025
|
+
#client;
|
|
1026
|
+
#httpRequest;
|
|
1066
1027
|
constructor(client, httpRequest) {
|
|
1067
|
-
|
|
1028
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1068
1029
|
}
|
|
1069
1030
|
/**
|
|
1070
1031
|
* Create a new dataset with the given name
|
|
@@ -1074,7 +1035,7 @@ class DatasetsClient {
|
|
|
1074
1035
|
*/
|
|
1075
1036
|
create(name2, options) {
|
|
1076
1037
|
return lastValueFrom(
|
|
1077
|
-
_modify(
|
|
1038
|
+
_modify(this.#client, this.#httpRequest, "PUT", name2, options)
|
|
1078
1039
|
);
|
|
1079
1040
|
}
|
|
1080
1041
|
/**
|
|
@@ -1085,7 +1046,7 @@ class DatasetsClient {
|
|
|
1085
1046
|
*/
|
|
1086
1047
|
edit(name2, options) {
|
|
1087
1048
|
return lastValueFrom(
|
|
1088
|
-
_modify(
|
|
1049
|
+
_modify(this.#client, this.#httpRequest, "PATCH", name2, options)
|
|
1089
1050
|
);
|
|
1090
1051
|
}
|
|
1091
1052
|
/**
|
|
@@ -1094,18 +1055,17 @@ class DatasetsClient {
|
|
|
1094
1055
|
* @param name - Name of the dataset to delete
|
|
1095
1056
|
*/
|
|
1096
1057
|
delete(name2) {
|
|
1097
|
-
return lastValueFrom(_modify(
|
|
1058
|
+
return lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name2));
|
|
1098
1059
|
}
|
|
1099
1060
|
/**
|
|
1100
1061
|
* Fetch a list of datasets for the configured project
|
|
1101
1062
|
*/
|
|
1102
1063
|
list() {
|
|
1103
1064
|
return lastValueFrom(
|
|
1104
|
-
_request(
|
|
1065
|
+
_request(this.#client, this.#httpRequest, { uri: "/datasets", tag: null })
|
|
1105
1066
|
);
|
|
1106
1067
|
}
|
|
1107
1068
|
}
|
|
1108
|
-
_client2$2 = /* @__PURE__ */ new WeakMap(), _httpRequest2$3 = /* @__PURE__ */ new WeakMap();
|
|
1109
1069
|
function _modify(client, httpRequest, method, name2, options) {
|
|
1110
1070
|
return dataset(name2), _request(client, httpRequest, {
|
|
1111
1071
|
method,
|
|
@@ -1114,21 +1074,15 @@ function _modify(client, httpRequest, method, name2, options) {
|
|
|
1114
1074
|
tag: null
|
|
1115
1075
|
});
|
|
1116
1076
|
}
|
|
1117
|
-
var __accessCheck$2 = (obj, member, msg) => {
|
|
1118
|
-
if (!member.has(obj))
|
|
1119
|
-
throw TypeError("Cannot " + msg);
|
|
1120
|
-
}, __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) => {
|
|
1121
|
-
if (member.has(obj))
|
|
1122
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
1123
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1124
|
-
}, __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value), _client$1, _httpRequest$2;
|
|
1125
1077
|
class ObservableProjectsClient {
|
|
1078
|
+
#client;
|
|
1079
|
+
#httpRequest;
|
|
1126
1080
|
constructor(client, httpRequest) {
|
|
1127
|
-
|
|
1081
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1128
1082
|
}
|
|
1129
1083
|
list(options) {
|
|
1130
|
-
const uri =
|
|
1131
|
-
return _request(
|
|
1084
|
+
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1085
|
+
return _request(this.#client, this.#httpRequest, { uri });
|
|
1132
1086
|
}
|
|
1133
1087
|
/**
|
|
1134
1088
|
* Fetch a project by project ID
|
|
@@ -1136,18 +1090,18 @@ class ObservableProjectsClient {
|
|
|
1136
1090
|
* @param projectId - ID of the project to fetch
|
|
1137
1091
|
*/
|
|
1138
1092
|
getById(projectId2) {
|
|
1139
|
-
return _request(
|
|
1093
|
+
return _request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` });
|
|
1140
1094
|
}
|
|
1141
1095
|
}
|
|
1142
|
-
_client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */ new WeakMap();
|
|
1143
|
-
var _client2$1, _httpRequest2$2;
|
|
1144
1096
|
class ProjectsClient {
|
|
1097
|
+
#client;
|
|
1098
|
+
#httpRequest;
|
|
1145
1099
|
constructor(client, httpRequest) {
|
|
1146
|
-
|
|
1100
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1147
1101
|
}
|
|
1148
1102
|
list(options) {
|
|
1149
|
-
const uri =
|
|
1150
|
-
return lastValueFrom(_request(
|
|
1103
|
+
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1104
|
+
return lastValueFrom(_request(this.#client, this.#httpRequest, { uri }));
|
|
1151
1105
|
}
|
|
1152
1106
|
/**
|
|
1153
1107
|
* Fetch a project by project ID
|
|
@@ -1156,22 +1110,15 @@ class ProjectsClient {
|
|
|
1156
1110
|
*/
|
|
1157
1111
|
getById(projectId2) {
|
|
1158
1112
|
return lastValueFrom(
|
|
1159
|
-
_request(
|
|
1113
|
+
_request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` })
|
|
1160
1114
|
);
|
|
1161
1115
|
}
|
|
1162
1116
|
}
|
|
1163
|
-
_client2$1 = /* @__PURE__ */ new WeakMap(), _httpRequest2$2 = /* @__PURE__ */ new WeakMap();
|
|
1164
|
-
var __accessCheck$1 = (obj, member, msg) => {
|
|
1165
|
-
if (!member.has(obj))
|
|
1166
|
-
throw TypeError("Cannot " + msg);
|
|
1167
|
-
}, __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) => {
|
|
1168
|
-
if (member.has(obj))
|
|
1169
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
1170
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1171
|
-
}, __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value), _client, _httpRequest$1;
|
|
1172
1117
|
class ObservableUsersClient {
|
|
1118
|
+
#client;
|
|
1119
|
+
#httpRequest;
|
|
1173
1120
|
constructor(client, httpRequest) {
|
|
1174
|
-
|
|
1121
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1175
1122
|
}
|
|
1176
1123
|
/**
|
|
1177
1124
|
* Fetch a user by user ID
|
|
@@ -1180,17 +1127,17 @@ class ObservableUsersClient {
|
|
|
1180
1127
|
*/
|
|
1181
1128
|
getById(id) {
|
|
1182
1129
|
return _request(
|
|
1183
|
-
|
|
1184
|
-
|
|
1130
|
+
this.#client,
|
|
1131
|
+
this.#httpRequest,
|
|
1185
1132
|
{ uri: `/users/${id}` }
|
|
1186
1133
|
);
|
|
1187
1134
|
}
|
|
1188
1135
|
}
|
|
1189
|
-
_client = /* @__PURE__ */ new WeakMap(), _httpRequest$1 = /* @__PURE__ */ new WeakMap();
|
|
1190
|
-
var _client2, _httpRequest2$1;
|
|
1191
1136
|
class UsersClient {
|
|
1137
|
+
#client;
|
|
1138
|
+
#httpRequest;
|
|
1192
1139
|
constructor(client, httpRequest) {
|
|
1193
|
-
|
|
1140
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
1194
1141
|
}
|
|
1195
1142
|
/**
|
|
1196
1143
|
* Fetch a user by user ID
|
|
@@ -1199,39 +1146,44 @@ class UsersClient {
|
|
|
1199
1146
|
*/
|
|
1200
1147
|
getById(id) {
|
|
1201
1148
|
return lastValueFrom(
|
|
1202
|
-
_request(
|
|
1149
|
+
_request(this.#client, this.#httpRequest, {
|
|
1203
1150
|
uri: `/users/${id}`
|
|
1204
1151
|
})
|
|
1205
1152
|
);
|
|
1206
1153
|
}
|
|
1207
1154
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1155
|
+
class ObservableSanityClient {
|
|
1156
|
+
assets;
|
|
1157
|
+
datasets;
|
|
1158
|
+
live;
|
|
1159
|
+
projects;
|
|
1160
|
+
users;
|
|
1161
|
+
/**
|
|
1162
|
+
* Private properties
|
|
1163
|
+
*/
|
|
1164
|
+
#clientConfig;
|
|
1165
|
+
#httpRequest;
|
|
1166
|
+
/**
|
|
1167
|
+
* Instance properties
|
|
1168
|
+
*/
|
|
1169
|
+
listen = _listen;
|
|
1218
1170
|
constructor(httpRequest, config = defaultConfig) {
|
|
1219
|
-
|
|
1171
|
+
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);
|
|
1220
1172
|
}
|
|
1221
1173
|
/**
|
|
1222
1174
|
* Clone the client - returns a new instance
|
|
1223
1175
|
*/
|
|
1224
1176
|
clone() {
|
|
1225
|
-
return new
|
|
1177
|
+
return new ObservableSanityClient(this.#httpRequest, this.config());
|
|
1226
1178
|
}
|
|
1227
1179
|
config(newConfig) {
|
|
1228
1180
|
if (newConfig === void 0)
|
|
1229
|
-
return { ...
|
|
1230
|
-
if (
|
|
1181
|
+
return { ...this.#clientConfig };
|
|
1182
|
+
if (this.#clientConfig && this.#clientConfig.allowReconfigure === !1)
|
|
1231
1183
|
throw new Error(
|
|
1232
1184
|
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1233
1185
|
);
|
|
1234
|
-
return
|
|
1186
|
+
return this.#clientConfig = initConfig(newConfig, this.#clientConfig || {}), this;
|
|
1235
1187
|
}
|
|
1236
1188
|
/**
|
|
1237
1189
|
* Clone the client with a new (partial) configuration.
|
|
@@ -1240,20 +1192,20 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1240
1192
|
*/
|
|
1241
1193
|
withConfig(newConfig) {
|
|
1242
1194
|
const thisConfig = this.config();
|
|
1243
|
-
return new
|
|
1195
|
+
return new ObservableSanityClient(this.#httpRequest, {
|
|
1244
1196
|
...thisConfig,
|
|
1245
1197
|
...newConfig,
|
|
1246
1198
|
stega: {
|
|
1247
1199
|
...thisConfig.stega || {},
|
|
1248
|
-
...typeof
|
|
1200
|
+
...typeof newConfig?.stega == "boolean" ? { enabled: newConfig.stega } : newConfig?.stega || {}
|
|
1249
1201
|
}
|
|
1250
1202
|
});
|
|
1251
1203
|
}
|
|
1252
1204
|
fetch(query, params, options) {
|
|
1253
1205
|
return _fetch(
|
|
1254
1206
|
this,
|
|
1255
|
-
|
|
1256
|
-
|
|
1207
|
+
this.#httpRequest,
|
|
1208
|
+
this.#clientConfig.stega,
|
|
1257
1209
|
query,
|
|
1258
1210
|
params,
|
|
1259
1211
|
options
|
|
@@ -1266,7 +1218,7 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1266
1218
|
* @param options - Request options
|
|
1267
1219
|
*/
|
|
1268
1220
|
getDocument(id, options) {
|
|
1269
|
-
return _getDocument(this,
|
|
1221
|
+
return _getDocument(this, this.#httpRequest, id, options);
|
|
1270
1222
|
}
|
|
1271
1223
|
/**
|
|
1272
1224
|
* Fetch multiple documents in one request.
|
|
@@ -1278,22 +1230,22 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1278
1230
|
* @param options - Request options
|
|
1279
1231
|
*/
|
|
1280
1232
|
getDocuments(ids, options) {
|
|
1281
|
-
return _getDocuments(this,
|
|
1233
|
+
return _getDocuments(this, this.#httpRequest, ids, options);
|
|
1282
1234
|
}
|
|
1283
1235
|
create(document, options) {
|
|
1284
|
-
return _create(this,
|
|
1236
|
+
return _create(this, this.#httpRequest, document, "create", options);
|
|
1285
1237
|
}
|
|
1286
1238
|
createIfNotExists(document, options) {
|
|
1287
|
-
return _createIfNotExists(this,
|
|
1239
|
+
return _createIfNotExists(this, this.#httpRequest, document, options);
|
|
1288
1240
|
}
|
|
1289
1241
|
createOrReplace(document, options) {
|
|
1290
|
-
return _createOrReplace(this,
|
|
1242
|
+
return _createOrReplace(this, this.#httpRequest, document, options);
|
|
1291
1243
|
}
|
|
1292
1244
|
delete(selection, options) {
|
|
1293
|
-
return _delete(this,
|
|
1245
|
+
return _delete(this, this.#httpRequest, selection, options);
|
|
1294
1246
|
}
|
|
1295
1247
|
mutate(operations, options) {
|
|
1296
|
-
return _mutate(this,
|
|
1248
|
+
return _mutate(this, this.#httpRequest, operations, options);
|
|
1297
1249
|
}
|
|
1298
1250
|
/**
|
|
1299
1251
|
* Create a new buildable patch of operations to perform
|
|
@@ -1320,7 +1272,7 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1320
1272
|
* @param options - Action options
|
|
1321
1273
|
*/
|
|
1322
1274
|
action(operations, options) {
|
|
1323
|
-
return _action(this,
|
|
1275
|
+
return _action(this, this.#httpRequest, operations, options);
|
|
1324
1276
|
}
|
|
1325
1277
|
/**
|
|
1326
1278
|
* Perform an HTTP request against the Sanity API
|
|
@@ -1328,7 +1280,7 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1328
1280
|
* @param options - Request options
|
|
1329
1281
|
*/
|
|
1330
1282
|
request(options) {
|
|
1331
|
-
return _request(this,
|
|
1283
|
+
return _request(this, this.#httpRequest, options);
|
|
1332
1284
|
}
|
|
1333
1285
|
/**
|
|
1334
1286
|
* Get a Sanity API URL for the URI provided
|
|
@@ -1348,28 +1300,43 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1348
1300
|
getDataUrl(operation, path) {
|
|
1349
1301
|
return _getDataUrl(this, operation, path);
|
|
1350
1302
|
}
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1303
|
+
}
|
|
1304
|
+
class SanityClient {
|
|
1305
|
+
assets;
|
|
1306
|
+
datasets;
|
|
1307
|
+
live;
|
|
1308
|
+
projects;
|
|
1309
|
+
users;
|
|
1310
|
+
/**
|
|
1311
|
+
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1312
|
+
*/
|
|
1313
|
+
observable;
|
|
1314
|
+
/**
|
|
1315
|
+
* Private properties
|
|
1316
|
+
*/
|
|
1317
|
+
#clientConfig;
|
|
1318
|
+
#httpRequest;
|
|
1319
|
+
/**
|
|
1320
|
+
* Instance properties
|
|
1321
|
+
*/
|
|
1322
|
+
listen = _listen;
|
|
1356
1323
|
constructor(httpRequest, config = defaultConfig) {
|
|
1357
|
-
|
|
1324
|
+
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);
|
|
1358
1325
|
}
|
|
1359
1326
|
/**
|
|
1360
1327
|
* Clone the client - returns a new instance
|
|
1361
1328
|
*/
|
|
1362
1329
|
clone() {
|
|
1363
|
-
return new
|
|
1330
|
+
return new SanityClient(this.#httpRequest, this.config());
|
|
1364
1331
|
}
|
|
1365
1332
|
config(newConfig) {
|
|
1366
1333
|
if (newConfig === void 0)
|
|
1367
|
-
return { ...
|
|
1368
|
-
if (
|
|
1334
|
+
return { ...this.#clientConfig };
|
|
1335
|
+
if (this.#clientConfig && this.#clientConfig.allowReconfigure === !1)
|
|
1369
1336
|
throw new Error(
|
|
1370
1337
|
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1371
1338
|
);
|
|
1372
|
-
return this.observable && this.observable.config(newConfig),
|
|
1339
|
+
return this.observable && this.observable.config(newConfig), this.#clientConfig = initConfig(newConfig, this.#clientConfig || {}), this;
|
|
1373
1340
|
}
|
|
1374
1341
|
/**
|
|
1375
1342
|
* Clone the client with a new (partial) configuration.
|
|
@@ -1378,12 +1345,12 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1378
1345
|
*/
|
|
1379
1346
|
withConfig(newConfig) {
|
|
1380
1347
|
const thisConfig = this.config();
|
|
1381
|
-
return new
|
|
1348
|
+
return new SanityClient(this.#httpRequest, {
|
|
1382
1349
|
...thisConfig,
|
|
1383
1350
|
...newConfig,
|
|
1384
1351
|
stega: {
|
|
1385
1352
|
...thisConfig.stega || {},
|
|
1386
|
-
...typeof
|
|
1353
|
+
...typeof newConfig?.stega == "boolean" ? { enabled: newConfig.stega } : newConfig?.stega || {}
|
|
1387
1354
|
}
|
|
1388
1355
|
});
|
|
1389
1356
|
}
|
|
@@ -1391,8 +1358,8 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1391
1358
|
return lastValueFrom(
|
|
1392
1359
|
_fetch(
|
|
1393
1360
|
this,
|
|
1394
|
-
|
|
1395
|
-
|
|
1361
|
+
this.#httpRequest,
|
|
1362
|
+
this.#clientConfig.stega,
|
|
1396
1363
|
query,
|
|
1397
1364
|
params,
|
|
1398
1365
|
options
|
|
@@ -1406,7 +1373,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1406
1373
|
* @param options - Request options
|
|
1407
1374
|
*/
|
|
1408
1375
|
getDocument(id, options) {
|
|
1409
|
-
return lastValueFrom(_getDocument(this,
|
|
1376
|
+
return lastValueFrom(_getDocument(this, this.#httpRequest, id, options));
|
|
1410
1377
|
}
|
|
1411
1378
|
/**
|
|
1412
1379
|
* Fetch multiple documents in one request.
|
|
@@ -1418,28 +1385,28 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1418
1385
|
* @param options - Request options
|
|
1419
1386
|
*/
|
|
1420
1387
|
getDocuments(ids, options) {
|
|
1421
|
-
return lastValueFrom(_getDocuments(this,
|
|
1388
|
+
return lastValueFrom(_getDocuments(this, this.#httpRequest, ids, options));
|
|
1422
1389
|
}
|
|
1423
1390
|
create(document, options) {
|
|
1424
1391
|
return lastValueFrom(
|
|
1425
|
-
_create(this,
|
|
1392
|
+
_create(this, this.#httpRequest, document, "create", options)
|
|
1426
1393
|
);
|
|
1427
1394
|
}
|
|
1428
1395
|
createIfNotExists(document, options) {
|
|
1429
1396
|
return lastValueFrom(
|
|
1430
|
-
_createIfNotExists(this,
|
|
1397
|
+
_createIfNotExists(this, this.#httpRequest, document, options)
|
|
1431
1398
|
);
|
|
1432
1399
|
}
|
|
1433
1400
|
createOrReplace(document, options) {
|
|
1434
1401
|
return lastValueFrom(
|
|
1435
|
-
_createOrReplace(this,
|
|
1402
|
+
_createOrReplace(this, this.#httpRequest, document, options)
|
|
1436
1403
|
);
|
|
1437
1404
|
}
|
|
1438
1405
|
delete(selection, options) {
|
|
1439
|
-
return lastValueFrom(_delete(this,
|
|
1406
|
+
return lastValueFrom(_delete(this, this.#httpRequest, selection, options));
|
|
1440
1407
|
}
|
|
1441
1408
|
mutate(operations, options) {
|
|
1442
|
-
return lastValueFrom(_mutate(this,
|
|
1409
|
+
return lastValueFrom(_mutate(this, this.#httpRequest, operations, options));
|
|
1443
1410
|
}
|
|
1444
1411
|
/**
|
|
1445
1412
|
* Create a new buildable patch of operations to perform
|
|
@@ -1467,7 +1434,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1467
1434
|
* @param options - Action options
|
|
1468
1435
|
*/
|
|
1469
1436
|
action(operations, options) {
|
|
1470
|
-
return lastValueFrom(_action(this,
|
|
1437
|
+
return lastValueFrom(_action(this, this.#httpRequest, operations, options));
|
|
1471
1438
|
}
|
|
1472
1439
|
/**
|
|
1473
1440
|
* Perform a request against the Sanity API
|
|
@@ -1477,7 +1444,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1477
1444
|
* @returns Promise resolving to the response body
|
|
1478
1445
|
*/
|
|
1479
1446
|
request(options) {
|
|
1480
|
-
return lastValueFrom(_request(this,
|
|
1447
|
+
return lastValueFrom(_request(this, this.#httpRequest, options));
|
|
1481
1448
|
}
|
|
1482
1449
|
/**
|
|
1483
1450
|
* Perform an HTTP request a `/data` sub-endpoint
|
|
@@ -1490,7 +1457,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1490
1457
|
* @internal
|
|
1491
1458
|
*/
|
|
1492
1459
|
dataRequest(endpoint, body, options) {
|
|
1493
|
-
return lastValueFrom(_dataRequest(this,
|
|
1460
|
+
return lastValueFrom(_dataRequest(this, this.#httpRequest, endpoint, body, options));
|
|
1494
1461
|
}
|
|
1495
1462
|
/**
|
|
1496
1463
|
* Get a Sanity API URL for the URI provided
|
|
@@ -1510,9 +1477,7 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1510
1477
|
getDataUrl(operation, path) {
|
|
1511
1478
|
return _getDataUrl(this, operation, path);
|
|
1512
1479
|
}
|
|
1513
|
-
}
|
|
1514
|
-
_clientConfig2 = /* @__PURE__ */ new WeakMap(), _httpRequest2 = /* @__PURE__ */ new WeakMap();
|
|
1515
|
-
let SanityClient = _SanityClient;
|
|
1480
|
+
}
|
|
1516
1481
|
function defineCreateClientExports(envMiddleware, ClassConstructor) {
|
|
1517
1482
|
const defaultRequester = defineHttpRequest(envMiddleware);
|
|
1518
1483
|
return { requester: defaultRequester, createClient: (config) => new ClassConstructor(
|
|
@@ -1530,7 +1495,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1530
1495
|
return printNoDefaultExport(), createClient2(config);
|
|
1531
1496
|
};
|
|
1532
1497
|
}
|
|
1533
|
-
var name = "@sanity/client", version = "6.21.
|
|
1498
|
+
var name = "@sanity/client", version = "6.21.2";
|
|
1534
1499
|
const middleware = [
|
|
1535
1500
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1536
1501
|
headers({ "User-Agent": `${name} ${version}` }),
|