@sanity/client 5.0.0-esm.0 → 5.0.0-esm.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/dist/index.browser.cjs +161 -118
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +162 -118
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +162 -119
- package/dist/index.cjs.js +0 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +56 -51
- package/dist/index.js +163 -119
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/SanityClient.ts +89 -75
- package/src/auth/AuthClient.ts +41 -23
- package/umd/sanityClient.js +161 -118
- package/umd/sanityClient.min.js +3 -3
package/dist/index.browser.cjs
CHANGED
|
@@ -208,23 +208,23 @@ var encodeQueryString = _ref => {
|
|
|
208
208
|
return options[option] ? "".concat(qs, "&").concat(enc(option), "=").concat(enc(options[option])) : qs;
|
|
209
209
|
}, qString);
|
|
210
210
|
};
|
|
211
|
-
var __accessCheck$
|
|
211
|
+
var __accessCheck$5 = (obj, member, msg) => {
|
|
212
212
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
213
213
|
};
|
|
214
|
-
var __privateGet$
|
|
215
|
-
__accessCheck$
|
|
214
|
+
var __privateGet$4 = (obj, member, getter) => {
|
|
215
|
+
__accessCheck$5(obj, member, "read from private field");
|
|
216
216
|
return getter ? getter.call(obj) : member.get(obj);
|
|
217
217
|
};
|
|
218
|
-
var __privateAdd$
|
|
218
|
+
var __privateAdd$5 = (obj, member, value) => {
|
|
219
219
|
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
220
220
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
221
221
|
};
|
|
222
|
-
var __privateSet$
|
|
223
|
-
__accessCheck$
|
|
222
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
|
223
|
+
__accessCheck$5(obj, member, "write to private field");
|
|
224
224
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
225
225
|
return value;
|
|
226
226
|
};
|
|
227
|
-
var _client$
|
|
227
|
+
var _client$3, _client2$3;
|
|
228
228
|
class BasePatch {
|
|
229
229
|
constructor(selection) {
|
|
230
230
|
let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -315,16 +315,16 @@ class BasePatch {
|
|
|
315
315
|
const _ObservablePatch = class extends BasePatch {
|
|
316
316
|
constructor(selection, operations, client) {
|
|
317
317
|
super(selection, operations);
|
|
318
|
-
__privateAdd$
|
|
319
|
-
__privateSet$
|
|
318
|
+
__privateAdd$5(this, _client$3, void 0);
|
|
319
|
+
__privateSet$4(this, _client$3, client);
|
|
320
320
|
}
|
|
321
321
|
clone() {
|
|
322
322
|
return new _ObservablePatch(this.selection, {
|
|
323
323
|
...this.operations
|
|
324
|
-
}, __privateGet$
|
|
324
|
+
}, __privateGet$4(this, _client$3));
|
|
325
325
|
}
|
|
326
326
|
commit(options) {
|
|
327
|
-
if (!__privateGet$
|
|
327
|
+
if (!__privateGet$4(this, _client$3)) {
|
|
328
328
|
throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
329
329
|
}
|
|
330
330
|
const returnFirst = typeof this.selection === "string";
|
|
@@ -332,26 +332,26 @@ const _ObservablePatch = class extends BasePatch {
|
|
|
332
332
|
returnFirst,
|
|
333
333
|
returnDocuments: true
|
|
334
334
|
}, options);
|
|
335
|
-
return __privateGet$
|
|
335
|
+
return __privateGet$4(this, _client$3).mutate({
|
|
336
336
|
patch: this.serialize()
|
|
337
337
|
}, opts);
|
|
338
338
|
}
|
|
339
339
|
};
|
|
340
340
|
let ObservablePatch = _ObservablePatch;
|
|
341
|
-
_client$
|
|
341
|
+
_client$3 = new WeakMap();
|
|
342
342
|
const _Patch = class extends BasePatch {
|
|
343
343
|
constructor(selection, operations, client) {
|
|
344
344
|
super(selection, operations);
|
|
345
|
-
__privateAdd$
|
|
346
|
-
__privateSet$
|
|
345
|
+
__privateAdd$5(this, _client2$3, void 0);
|
|
346
|
+
__privateSet$4(this, _client2$3, client);
|
|
347
347
|
}
|
|
348
348
|
clone() {
|
|
349
349
|
return new _Patch(this.selection, {
|
|
350
350
|
...this.operations
|
|
351
|
-
}, __privateGet$
|
|
351
|
+
}, __privateGet$4(this, _client2$3));
|
|
352
352
|
}
|
|
353
353
|
commit(options) {
|
|
354
|
-
if (!__privateGet$
|
|
354
|
+
if (!__privateGet$4(this, _client2$3)) {
|
|
355
355
|
throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
356
356
|
}
|
|
357
357
|
const returnFirst = typeof this.selection === "string";
|
|
@@ -359,30 +359,30 @@ const _Patch = class extends BasePatch {
|
|
|
359
359
|
returnFirst,
|
|
360
360
|
returnDocuments: true
|
|
361
361
|
}, options);
|
|
362
|
-
return __privateGet$
|
|
362
|
+
return __privateGet$4(this, _client2$3).mutate({
|
|
363
363
|
patch: this.serialize()
|
|
364
364
|
}, opts);
|
|
365
365
|
}
|
|
366
366
|
};
|
|
367
367
|
let Patch = _Patch;
|
|
368
|
-
_client2$
|
|
369
|
-
var __accessCheck$
|
|
368
|
+
_client2$3 = new WeakMap();
|
|
369
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
|
370
370
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
371
371
|
};
|
|
372
|
-
var __privateGet$
|
|
373
|
-
__accessCheck$
|
|
372
|
+
var __privateGet$3 = (obj, member, getter) => {
|
|
373
|
+
__accessCheck$4(obj, member, "read from private field");
|
|
374
374
|
return getter ? getter.call(obj) : member.get(obj);
|
|
375
375
|
};
|
|
376
|
-
var __privateAdd$
|
|
376
|
+
var __privateAdd$4 = (obj, member, value) => {
|
|
377
377
|
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
378
378
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
379
379
|
};
|
|
380
|
-
var __privateSet$
|
|
381
|
-
__accessCheck$
|
|
380
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
|
381
|
+
__accessCheck$4(obj, member, "write to private field");
|
|
382
382
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
383
383
|
return value;
|
|
384
384
|
};
|
|
385
|
-
var _client$
|
|
385
|
+
var _client$2, _client2$2;
|
|
386
386
|
const defaultMutateOptions = {
|
|
387
387
|
returnDocuments: false
|
|
388
388
|
};
|
|
@@ -448,17 +448,17 @@ class BaseTransaction {
|
|
|
448
448
|
const _Transaction = class extends BaseTransaction {
|
|
449
449
|
constructor(operations, client, transactionId) {
|
|
450
450
|
super(operations, transactionId);
|
|
451
|
-
__privateAdd$
|
|
452
|
-
__privateSet$
|
|
451
|
+
__privateAdd$4(this, _client$2, void 0);
|
|
452
|
+
__privateSet$3(this, _client$2, client);
|
|
453
453
|
}
|
|
454
454
|
clone() {
|
|
455
|
-
return new _Transaction([...this.operations], __privateGet$
|
|
455
|
+
return new _Transaction([...this.operations], __privateGet$3(this, _client$2), this.trxId);
|
|
456
456
|
}
|
|
457
457
|
commit(options) {
|
|
458
|
-
if (!__privateGet$
|
|
458
|
+
if (!__privateGet$3(this, _client$2)) {
|
|
459
459
|
throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
460
460
|
}
|
|
461
|
-
return __privateGet$
|
|
461
|
+
return __privateGet$3(this, _client$2).mutate(this.serialize(), Object.assign({
|
|
462
462
|
transactionId: this.trxId
|
|
463
463
|
}, defaultMutateOptions, options || {}));
|
|
464
464
|
}
|
|
@@ -471,7 +471,7 @@ const _Transaction = class extends BaseTransaction {
|
|
|
471
471
|
});
|
|
472
472
|
}
|
|
473
473
|
if (isBuilder) {
|
|
474
|
-
const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$
|
|
474
|
+
const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$3(this, _client$2)));
|
|
475
475
|
if (!(patch instanceof Patch)) {
|
|
476
476
|
throw new Error("function passed to `patch()` must return the patch");
|
|
477
477
|
}
|
|
@@ -488,21 +488,21 @@ const _Transaction = class extends BaseTransaction {
|
|
|
488
488
|
}
|
|
489
489
|
};
|
|
490
490
|
let Transaction = _Transaction;
|
|
491
|
-
_client$
|
|
491
|
+
_client$2 = new WeakMap();
|
|
492
492
|
const _ObservableTransaction = class extends BaseTransaction {
|
|
493
493
|
constructor(operations, client, transactionId) {
|
|
494
494
|
super(operations, transactionId);
|
|
495
|
-
__privateAdd$
|
|
496
|
-
__privateSet$
|
|
495
|
+
__privateAdd$4(this, _client2$2, void 0);
|
|
496
|
+
__privateSet$3(this, _client2$2, client);
|
|
497
497
|
}
|
|
498
498
|
clone() {
|
|
499
|
-
return new _ObservableTransaction([...this.operations], __privateGet$
|
|
499
|
+
return new _ObservableTransaction([...this.operations], __privateGet$3(this, _client2$2), this.trxId);
|
|
500
500
|
}
|
|
501
501
|
commit(options) {
|
|
502
|
-
if (!__privateGet$
|
|
502
|
+
if (!__privateGet$3(this, _client2$2)) {
|
|
503
503
|
throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
504
504
|
}
|
|
505
|
-
return __privateGet$
|
|
505
|
+
return __privateGet$3(this, _client2$2).mutate(this.serialize(), Object.assign({
|
|
506
506
|
transactionId: this.trxId
|
|
507
507
|
}, defaultMutateOptions, options || {}));
|
|
508
508
|
}
|
|
@@ -515,7 +515,7 @@ const _ObservableTransaction = class extends BaseTransaction {
|
|
|
515
515
|
});
|
|
516
516
|
}
|
|
517
517
|
if (isBuilder) {
|
|
518
|
-
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$
|
|
518
|
+
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$3(this, _client2$2)));
|
|
519
519
|
if (!(patch instanceof ObservablePatch)) {
|
|
520
520
|
throw new Error("function passed to `patch()` must return the patch");
|
|
521
521
|
}
|
|
@@ -532,7 +532,7 @@ const _ObservableTransaction = class extends BaseTransaction {
|
|
|
532
532
|
}
|
|
533
533
|
};
|
|
534
534
|
let ObservableTransaction = _ObservableTransaction;
|
|
535
|
-
_client2$
|
|
535
|
+
_client2$2 = new WeakMap();
|
|
536
536
|
const excludeFalsey = (param, defValue) => {
|
|
537
537
|
const value = typeof param === "undefined" ? defValue : param;
|
|
538
538
|
return param === false ? void 0 : value;
|
|
@@ -686,50 +686,50 @@ function _request(client, httpRequest, options) {
|
|
|
686
686
|
const observable = _requestObservable(client, httpRequest, options).pipe(operators.filter(event => event.type === "response"), operators.map(event => event.body));
|
|
687
687
|
return observable;
|
|
688
688
|
}
|
|
689
|
-
var __accessCheck$
|
|
689
|
+
var __accessCheck$3 = (obj, member, msg) => {
|
|
690
690
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
691
691
|
};
|
|
692
|
-
var __privateGet$
|
|
693
|
-
__accessCheck$
|
|
692
|
+
var __privateGet$2 = (obj, member, getter) => {
|
|
693
|
+
__accessCheck$3(obj, member, "read from private field");
|
|
694
694
|
return getter ? getter.call(obj) : member.get(obj);
|
|
695
695
|
};
|
|
696
|
-
var __privateAdd$
|
|
696
|
+
var __privateAdd$3 = (obj, member, value) => {
|
|
697
697
|
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
698
698
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
699
699
|
};
|
|
700
|
-
var __privateSet$
|
|
701
|
-
__accessCheck$
|
|
700
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
|
701
|
+
__accessCheck$3(obj, member, "write to private field");
|
|
702
702
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
703
703
|
return value;
|
|
704
704
|
};
|
|
705
|
-
var _client, _httpRequest$
|
|
705
|
+
var _client$1, _httpRequest$2, _client2$1, _httpRequest2$2;
|
|
706
706
|
class ObservableAssetsClient {
|
|
707
707
|
constructor(client, httpRequest) {
|
|
708
|
-
__privateAdd$
|
|
709
|
-
__privateAdd$
|
|
710
|
-
__privateSet$
|
|
711
|
-
__privateSet$
|
|
708
|
+
__privateAdd$3(this, _client$1, void 0);
|
|
709
|
+
__privateAdd$3(this, _httpRequest$2, void 0);
|
|
710
|
+
__privateSet$2(this, _client$1, client);
|
|
711
|
+
__privateSet$2(this, _httpRequest$2, httpRequest);
|
|
712
712
|
}
|
|
713
713
|
upload(assetType, body, options) {
|
|
714
|
-
return _upload(__privateGet$
|
|
714
|
+
return _upload(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), assetType, body, options);
|
|
715
715
|
}
|
|
716
716
|
}
|
|
717
|
-
_client = new WeakMap();
|
|
718
|
-
_httpRequest$
|
|
717
|
+
_client$1 = new WeakMap();
|
|
718
|
+
_httpRequest$2 = new WeakMap();
|
|
719
719
|
class AssetsClient {
|
|
720
720
|
constructor(client, httpRequest) {
|
|
721
|
-
__privateAdd$
|
|
722
|
-
__privateAdd$
|
|
723
|
-
__privateSet$
|
|
724
|
-
__privateSet$
|
|
721
|
+
__privateAdd$3(this, _client2$1, void 0);
|
|
722
|
+
__privateAdd$3(this, _httpRequest2$2, void 0);
|
|
723
|
+
__privateSet$2(this, _client2$1, client);
|
|
724
|
+
__privateSet$2(this, _httpRequest2$2, httpRequest);
|
|
725
725
|
}
|
|
726
726
|
upload(assetType, body, options) {
|
|
727
|
-
const observable = _upload(__privateGet$
|
|
727
|
+
const observable = _upload(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), assetType, body, options);
|
|
728
728
|
return rxjs.lastValueFrom(observable.pipe(operators.filter(event => event.type === "response"), operators.map(event => event.body.document)));
|
|
729
729
|
}
|
|
730
730
|
}
|
|
731
|
-
_client2 = new WeakMap();
|
|
732
|
-
_httpRequest2$
|
|
731
|
+
_client2$1 = new WeakMap();
|
|
732
|
+
_httpRequest2$2 = new WeakMap();
|
|
733
733
|
function _upload(client, httpRequest, assetType, body) {
|
|
734
734
|
let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
735
735
|
validateAssetType(assetType);
|
|
@@ -783,31 +783,65 @@ function optionsFromFile(opts, file) {
|
|
|
783
783
|
contentType: file.type
|
|
784
784
|
}, opts);
|
|
785
785
|
}
|
|
786
|
-
|
|
786
|
+
var __accessCheck$2 = (obj, member, msg) => {
|
|
787
|
+
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
788
|
+
};
|
|
789
|
+
var __privateGet$1 = (obj, member, getter) => {
|
|
790
|
+
__accessCheck$2(obj, member, "read from private field");
|
|
791
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
792
|
+
};
|
|
793
|
+
var __privateAdd$2 = (obj, member, value) => {
|
|
794
|
+
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
795
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
796
|
+
};
|
|
797
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
|
798
|
+
__accessCheck$2(obj, member, "write to private field");
|
|
799
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
800
|
+
return value;
|
|
801
|
+
};
|
|
802
|
+
var _client, _httpRequest$1, _client2, _httpRequest2$1;
|
|
803
|
+
class ObservableAuthClient {
|
|
804
|
+
constructor(client, httpRequest) {
|
|
805
|
+
__privateAdd$2(this, _client, void 0);
|
|
806
|
+
__privateAdd$2(this, _httpRequest$1, void 0);
|
|
807
|
+
__privateSet$1(this, _client, client);
|
|
808
|
+
__privateSet$1(this, _httpRequest$1, httpRequest);
|
|
809
|
+
}
|
|
787
810
|
getLoginProviders() {
|
|
788
|
-
return this
|
|
811
|
+
return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
|
|
789
812
|
uri: "/auth/providers"
|
|
790
813
|
});
|
|
791
814
|
}
|
|
792
815
|
logout() {
|
|
793
|
-
return this
|
|
816
|
+
return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
|
|
794
817
|
uri: "/auth/logout",
|
|
795
818
|
method: "POST"
|
|
796
819
|
});
|
|
797
820
|
}
|
|
798
821
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
822
|
+
_client = new WeakMap();
|
|
823
|
+
_httpRequest$1 = new WeakMap();
|
|
824
|
+
class AuthClient {
|
|
825
|
+
constructor(client, httpRequest) {
|
|
826
|
+
__privateAdd$2(this, _client2, void 0);
|
|
827
|
+
__privateAdd$2(this, _httpRequest2$1, void 0);
|
|
828
|
+
__privateSet$1(this, _client2, client);
|
|
829
|
+
__privateSet$1(this, _httpRequest2$1, httpRequest);
|
|
803
830
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
831
|
+
getLoginProviders() {
|
|
832
|
+
return rxjs.lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
|
|
833
|
+
uri: "/auth/providers"
|
|
834
|
+
}));
|
|
835
|
+
}
|
|
836
|
+
logout() {
|
|
837
|
+
return rxjs.lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
|
|
838
|
+
uri: "/auth/logout",
|
|
839
|
+
method: "POST"
|
|
840
|
+
}));
|
|
809
841
|
}
|
|
810
842
|
}
|
|
843
|
+
_client2 = new WeakMap();
|
|
844
|
+
_httpRequest2$1 = new WeakMap();
|
|
811
845
|
const BASE_URL = "https://docs.sanity.io/help/";
|
|
812
846
|
function generateHelpUrl(slug) {
|
|
813
847
|
return BASE_URL + slug;
|
|
@@ -1151,11 +1185,21 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1151
1185
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1152
1186
|
return value;
|
|
1153
1187
|
};
|
|
1154
|
-
var _clientConfig, _httpRequest, _httpRequest2;
|
|
1155
|
-
class
|
|
1156
|
-
constructor(config) {
|
|
1188
|
+
var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
|
|
1189
|
+
const _ObservableSanityClient = class {
|
|
1190
|
+
constructor(httpRequest, config) {
|
|
1157
1191
|
__privateAdd(this, _clientConfig, void 0);
|
|
1192
|
+
__privateAdd(this, _httpRequest, void 0);
|
|
1158
1193
|
this.config(config);
|
|
1194
|
+
__privateSet(this, _httpRequest, httpRequest);
|
|
1195
|
+
this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
|
|
1196
|
+
this.auth = new ObservableAuthClient(this, __privateGet(this, _httpRequest));
|
|
1197
|
+
this.datasets = new ObservableDatasetsClient(this);
|
|
1198
|
+
this.projects = new ObservableProjectsClient(this);
|
|
1199
|
+
this.users = new ObservableUsersClient(this);
|
|
1200
|
+
}
|
|
1201
|
+
clone() {
|
|
1202
|
+
return new _ObservableSanityClient(__privateGet(this, _httpRequest), this.config());
|
|
1159
1203
|
}
|
|
1160
1204
|
config(newConfig) {
|
|
1161
1205
|
if (newConfig === void 0) {
|
|
@@ -1169,40 +1213,6 @@ class BaseSanityClient {
|
|
|
1169
1213
|
__privateSet(this, _clientConfig, initConfig(newConfig, __privateGet(this, _clientConfig) || {}));
|
|
1170
1214
|
return this;
|
|
1171
1215
|
}
|
|
1172
|
-
isPromiseAPI() {
|
|
1173
|
-
return this instanceof SanityClient;
|
|
1174
|
-
}
|
|
1175
|
-
getUrl(uri) {
|
|
1176
|
-
let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1177
|
-
const base = canUseCdn ? __privateGet(this, _clientConfig).cdnUrl : __privateGet(this, _clientConfig).url;
|
|
1178
|
-
return "".concat(base, "/").concat(uri.replace(/^\//, ""));
|
|
1179
|
-
}
|
|
1180
|
-
getDataUrl(operation, path) {
|
|
1181
|
-
const config = this.config();
|
|
1182
|
-
const catalog = hasDataset(config);
|
|
1183
|
-
const baseUri = "/".concat(operation, "/").concat(catalog);
|
|
1184
|
-
const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
|
|
1185
|
-
return "/data".concat(uri).replace(/\/($|\?)/, "$1");
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
_clientConfig = new WeakMap();
|
|
1189
|
-
const _ObservableSanityClient = class extends BaseSanityClient {
|
|
1190
|
-
constructor(httpRequest, config) {
|
|
1191
|
-
super(config);
|
|
1192
|
-
__privateAdd(this, _httpRequest, void 0);
|
|
1193
|
-
__privateSet(this, _httpRequest, httpRequest);
|
|
1194
|
-
this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
|
|
1195
|
-
this.auth = new ObservableAuthClient(this);
|
|
1196
|
-
this.datasets = new ObservableDatasetsClient(this);
|
|
1197
|
-
this.projects = new ObservableProjectsClient(this);
|
|
1198
|
-
this.users = new ObservableUsersClient(this);
|
|
1199
|
-
}
|
|
1200
|
-
clone() {
|
|
1201
|
-
return new _ObservableSanityClient(__privateGet(this, _httpRequest), this.config());
|
|
1202
|
-
}
|
|
1203
|
-
config(newConfig) {
|
|
1204
|
-
return super.config(newConfig);
|
|
1205
|
-
}
|
|
1206
1216
|
withConfig(newConfig) {
|
|
1207
1217
|
return new _ObservableSanityClient(__privateGet(this, _httpRequest), {
|
|
1208
1218
|
...this.config(),
|
|
@@ -1243,30 +1253,51 @@ const _ObservableSanityClient = class extends BaseSanityClient {
|
|
|
1243
1253
|
request(options) {
|
|
1244
1254
|
return _request(this, __privateGet(this, _httpRequest), options);
|
|
1245
1255
|
}
|
|
1256
|
+
getUrl(uri) {
|
|
1257
|
+
let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1258
|
+
const base = canUseCdn ? __privateGet(this, _clientConfig).cdnUrl : __privateGet(this, _clientConfig).url;
|
|
1259
|
+
return "".concat(base, "/").concat(uri.replace(/^\//, ""));
|
|
1260
|
+
}
|
|
1261
|
+
getDataUrl(operation, path) {
|
|
1262
|
+
const config = this.config();
|
|
1263
|
+
const catalog = hasDataset(config);
|
|
1264
|
+
const baseUri = "/".concat(operation, "/").concat(catalog);
|
|
1265
|
+
const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
|
|
1266
|
+
return "/data".concat(uri).replace(/\/($|\?)/, "$1");
|
|
1267
|
+
}
|
|
1246
1268
|
};
|
|
1247
1269
|
let ObservableSanityClient = _ObservableSanityClient;
|
|
1270
|
+
_clientConfig = new WeakMap();
|
|
1248
1271
|
_httpRequest = new WeakMap();
|
|
1249
|
-
const _SanityClient = class
|
|
1272
|
+
const _SanityClient = class {
|
|
1250
1273
|
constructor(httpRequest, config) {
|
|
1251
|
-
|
|
1274
|
+
__privateAdd(this, _clientConfig2, void 0);
|
|
1252
1275
|
__privateAdd(this, _httpRequest2, void 0);
|
|
1253
1276
|
this.listen = _listen;
|
|
1277
|
+
this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1278
|
+
this.config(config);
|
|
1254
1279
|
__privateSet(this, _httpRequest2, httpRequest);
|
|
1255
1280
|
this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
|
|
1256
|
-
this.auth = new AuthClient(this);
|
|
1281
|
+
this.auth = new AuthClient(this, __privateGet(this, _httpRequest2));
|
|
1257
1282
|
this.datasets = new DatasetsClient(this);
|
|
1258
1283
|
this.projects = new ProjectsClient(this);
|
|
1259
1284
|
this.users = new UsersClient(this);
|
|
1260
|
-
this.observable = new ObservableSanityClient(httpRequest, this.config());
|
|
1261
1285
|
}
|
|
1262
1286
|
clone() {
|
|
1263
1287
|
return new _SanityClient(__privateGet(this, _httpRequest2), this.config());
|
|
1264
1288
|
}
|
|
1265
1289
|
config(newConfig) {
|
|
1266
|
-
if (newConfig) {
|
|
1267
|
-
|
|
1290
|
+
if (newConfig === void 0) {
|
|
1291
|
+
return {
|
|
1292
|
+
...__privateGet(this, _clientConfig2)
|
|
1293
|
+
};
|
|
1268
1294
|
}
|
|
1269
|
-
|
|
1295
|
+
if (__privateGet(this, _clientConfig2) && __privateGet(this, _clientConfig2).allowReconfigure === false) {
|
|
1296
|
+
throw new Error("Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client");
|
|
1297
|
+
}
|
|
1298
|
+
this.observable.config(newConfig);
|
|
1299
|
+
__privateSet(this, _clientConfig2, initConfig(newConfig, __privateGet(this, _clientConfig2) || {}));
|
|
1300
|
+
return this;
|
|
1270
1301
|
}
|
|
1271
1302
|
withConfig(newConfig) {
|
|
1272
1303
|
return new _SanityClient(__privateGet(this, _httpRequest2), {
|
|
@@ -1311,8 +1342,21 @@ const _SanityClient = class extends BaseSanityClient {
|
|
|
1311
1342
|
dataRequest(endpoint, body, options) {
|
|
1312
1343
|
return rxjs.lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
|
|
1313
1344
|
}
|
|
1345
|
+
getUrl(uri) {
|
|
1346
|
+
let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1347
|
+
const base = canUseCdn ? __privateGet(this, _clientConfig2).cdnUrl : __privateGet(this, _clientConfig2).url;
|
|
1348
|
+
return "".concat(base, "/").concat(uri.replace(/^\//, ""));
|
|
1349
|
+
}
|
|
1350
|
+
getDataUrl(operation, path) {
|
|
1351
|
+
const config = this.config();
|
|
1352
|
+
const catalog = hasDataset(config);
|
|
1353
|
+
const baseUri = "/".concat(operation, "/").concat(catalog);
|
|
1354
|
+
const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
|
|
1355
|
+
return "/data".concat(uri).replace(/\/($|\?)/, "$1");
|
|
1356
|
+
}
|
|
1314
1357
|
};
|
|
1315
1358
|
let SanityClient = _SanityClient;
|
|
1359
|
+
_clientConfig2 = new WeakMap();
|
|
1316
1360
|
_httpRequest2 = new WeakMap();
|
|
1317
1361
|
const httpRequest = defineHttpRequest(envMiddleware);
|
|
1318
1362
|
const requester = httpRequest.defaultRequester;
|
|
@@ -1320,7 +1364,6 @@ function createClient(config) {
|
|
|
1320
1364
|
return new SanityClient(httpRequest, config);
|
|
1321
1365
|
}
|
|
1322
1366
|
exports.BasePatch = BasePatch;
|
|
1323
|
-
exports.BaseSanityClient = BaseSanityClient;
|
|
1324
1367
|
exports.BaseTransaction = BaseTransaction;
|
|
1325
1368
|
exports.ClientError = ClientError;
|
|
1326
1369
|
exports.ObservablePatch = ObservablePatch;
|