@sanity/client 6.28.0-instruct.0 → 6.28.0-resources-projects.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks-cjs/config.cjs +16 -2
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +16 -2
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +57 -49
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +13 -215
- package/dist/index.browser.d.ts +13 -215
- package/dist/index.browser.js +57 -49
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +42 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -204
- package/dist/index.d.ts +13 -204
- package/dist/index.js +42 -48
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +13 -209
- package/dist/stega.browser.d.ts +13 -209
- package/dist/stega.d.cts +13 -209
- package/dist/stega.d.ts +13 -209
- package/package.json +1 -1
- package/src/SanityClient.ts +10 -7
- package/src/assets/AssetsClient.ts +6 -2
- package/src/config.ts +29 -0
- package/src/data/dataMethods.ts +39 -4
- package/src/datasets/DatasetsClient.ts +22 -0
- package/src/types.ts +7 -10
- package/umd/sanityClient.js +57 -49
- package/umd/sanityClient.min.js +2 -2
- package/src/assist/AssistClient.ts +0 -87
- package/src/assist/types.ts +0 -178
package/dist/index.js
CHANGED
|
@@ -720,11 +720,20 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
720
720
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
|
|
721
721
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
722
722
|
}
|
|
723
|
+
function _resourceBase(resource) {
|
|
724
|
+
return `/${resource.type}/${resource.id}`;
|
|
725
|
+
}
|
|
726
|
+
function isDataRequestUri(uri, resource) {
|
|
727
|
+
return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/`) === 0 : uri.indexOf("/data/") === 0;
|
|
728
|
+
}
|
|
729
|
+
function isDataQueryRequestUri(uri, resource) {
|
|
730
|
+
return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/query`) === 0 : uri.indexOf("/data/query") === 0;
|
|
731
|
+
}
|
|
723
732
|
function _requestObservable(client, httpRequest, options) {
|
|
724
|
-
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.
|
|
733
|
+
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isDataRequestUri(uri, config.experimental_resource) : options.canUseCdn;
|
|
725
734
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
726
735
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
727
|
-
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.
|
|
736
|
+
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isDataQueryRequestUri(uri, config.experimental_resource)) {
|
|
728
737
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
729
738
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
730
739
|
const perspectiveOption = options.perspective || config.perspective;
|
|
@@ -751,12 +760,18 @@ function _request(client, httpRequest, options) {
|
|
|
751
760
|
);
|
|
752
761
|
}
|
|
753
762
|
function _getDataUrl(client, operation, path) {
|
|
754
|
-
const config = client.config()
|
|
763
|
+
const config = client.config();
|
|
764
|
+
if (config.experimental_resource) {
|
|
765
|
+
const baseUri2 = `/${operation}`;
|
|
766
|
+
return (path ? `${baseUri2}/${path}` : baseUri2).replace(/\/($|\?)/, "$1");
|
|
767
|
+
}
|
|
768
|
+
const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
755
769
|
return `/data${path ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
756
770
|
}
|
|
757
771
|
function _getUrl(client, uri, canUseCdn = !1) {
|
|
758
|
-
const { url, cdnUrl } = client.config();
|
|
759
|
-
|
|
772
|
+
const { url, cdnUrl, experimental_resource } = client.config();
|
|
773
|
+
let base = canUseCdn ? cdnUrl : url;
|
|
774
|
+
return experimental_resource && (uri.indexOf("/users") !== -1 || uri.indexOf("/assets") !== -1) && (base = base.replace(_resourceBase(experimental_resource), "")), `${base}/${uri.replace(/^\//, "")}`;
|
|
760
775
|
}
|
|
761
776
|
function _withAbortSignal(signal) {
|
|
762
777
|
return (input) => new Observable((observer) => {
|
|
@@ -810,7 +825,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
810
825
|
validateAssetType(assetType);
|
|
811
826
|
let meta = opts.extract || void 0;
|
|
812
827
|
meta && !meta.length && (meta = ["none"]);
|
|
813
|
-
const
|
|
828
|
+
const config = client.config(), resource = config.experimental_resource, dataset2 = resource ? void 0 : hasDataset(config), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
|
|
814
829
|
label,
|
|
815
830
|
title,
|
|
816
831
|
description,
|
|
@@ -822,7 +837,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
822
837
|
tag,
|
|
823
838
|
method: "POST",
|
|
824
839
|
timeout: options.timeout || 0,
|
|
825
|
-
uri: `/assets/${assetEndpoint}/${dataset2}`,
|
|
840
|
+
uri: resource ? `/assets/${resource.type}/${resource.id}/${assetEndpoint}` : `/assets/${assetEndpoint}/${dataset2}`,
|
|
826
841
|
headers: options.contentType ? { "Content-Type": options.contentType } : {},
|
|
827
842
|
query,
|
|
828
843
|
body
|
|
@@ -837,42 +852,6 @@ function optionsFromFile(opts, file) {
|
|
|
837
852
|
opts
|
|
838
853
|
);
|
|
839
854
|
}
|
|
840
|
-
function _instruct(client, httpRequest, request) {
|
|
841
|
-
const dataset2 = hasDataset(client.config());
|
|
842
|
-
return _request(client, httpRequest, {
|
|
843
|
-
method: "POST",
|
|
844
|
-
uri: `/assist/tasks/instruct/${dataset2}`,
|
|
845
|
-
body: request
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
class ObservableAssistClient {
|
|
849
|
-
#client;
|
|
850
|
-
#httpRequest;
|
|
851
|
-
constructor(client, httpRequest) {
|
|
852
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
* Run an ad-hoc instruction for a target document.
|
|
856
|
-
* @param request instruction request
|
|
857
|
-
*/
|
|
858
|
-
instruct(request) {
|
|
859
|
-
return _instruct(this.#client, this.#httpRequest, request);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
class AssistClient {
|
|
863
|
-
#client;
|
|
864
|
-
#httpRequest;
|
|
865
|
-
constructor(client, httpRequest) {
|
|
866
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
867
|
-
}
|
|
868
|
-
/**
|
|
869
|
-
* Run an ad-hoc instruction for a target document.
|
|
870
|
-
* @param request instruction request
|
|
871
|
-
*/
|
|
872
|
-
instruct(request) {
|
|
873
|
-
return lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
855
|
var defaults = (obj, defaults2) => Object.keys(defaults2).concat(Object.keys(obj)).reduce((target, prop) => (target[prop] = typeof obj[prop] > "u" ? defaults2[prop] : obj[prop], target), {});
|
|
877
856
|
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = defer(() => import("@sanity/eventsource")).pipe(
|
|
878
857
|
map(({ default: EventSource2 }) => EventSource2),
|
|
@@ -1113,6 +1092,23 @@ class DatasetsClient {
|
|
|
1113
1092
|
);
|
|
1114
1093
|
}
|
|
1115
1094
|
}
|
|
1095
|
+
class ThrowingDatasetsClient extends DatasetsClient {
|
|
1096
|
+
constructor(client, httpRequest) {
|
|
1097
|
+
super(client, httpRequest);
|
|
1098
|
+
}
|
|
1099
|
+
create() {
|
|
1100
|
+
throw new Error("cannot create dataset with the current client configuration");
|
|
1101
|
+
}
|
|
1102
|
+
edit() {
|
|
1103
|
+
throw new Error("cannot edit dataset with the current client configuration");
|
|
1104
|
+
}
|
|
1105
|
+
delete() {
|
|
1106
|
+
throw new Error("cannot delete dataset with the current client configuration");
|
|
1107
|
+
}
|
|
1108
|
+
list() {
|
|
1109
|
+
throw new Error("cannot list dataset with the current client configuration");
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1116
1112
|
function _modify(client, httpRequest, method, name2, options) {
|
|
1117
1113
|
return dataset(name2), _request(client, httpRequest, {
|
|
1118
1114
|
method,
|
|
@@ -1205,7 +1201,6 @@ class ObservableSanityClient {
|
|
|
1205
1201
|
live;
|
|
1206
1202
|
projects;
|
|
1207
1203
|
users;
|
|
1208
|
-
assist;
|
|
1209
1204
|
/**
|
|
1210
1205
|
* Private properties
|
|
1211
1206
|
*/
|
|
@@ -1216,7 +1211,7 @@ class ObservableSanityClient {
|
|
|
1216
1211
|
*/
|
|
1217
1212
|
listen = _listen;
|
|
1218
1213
|
constructor(httpRequest, config = defaultConfig) {
|
|
1219
|
-
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)
|
|
1214
|
+
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
1215
|
}
|
|
1221
1216
|
/**
|
|
1222
1217
|
* Clone the client - returns a new instance
|
|
@@ -1355,7 +1350,6 @@ class SanityClient {
|
|
|
1355
1350
|
live;
|
|
1356
1351
|
projects;
|
|
1357
1352
|
users;
|
|
1358
|
-
assist;
|
|
1359
1353
|
/**
|
|
1360
1354
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1361
1355
|
*/
|
|
@@ -1370,7 +1364,7 @@ class SanityClient {
|
|
|
1370
1364
|
*/
|
|
1371
1365
|
listen = _listen;
|
|
1372
1366
|
constructor(httpRequest, config = defaultConfig) {
|
|
1373
|
-
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.
|
|
1367
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = this.#clientConfig.experimental_resource ? new ThrowingDatasetsClient(this, this.#httpRequest) : 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);
|
|
1374
1368
|
}
|
|
1375
1369
|
/**
|
|
1376
1370
|
* Clone the client - returns a new instance
|
|
@@ -1546,7 +1540,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1546
1540
|
return printNoDefaultExport(), createClient2(config);
|
|
1547
1541
|
};
|
|
1548
1542
|
}
|
|
1549
|
-
var name = "@sanity/client", version = "6.28.0-
|
|
1543
|
+
var name = "@sanity/client", version = "6.28.0-resources-projects.0";
|
|
1550
1544
|
const middleware = [
|
|
1551
1545
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1552
1546
|
headers({ "User-Agent": `${name} ${version}` }),
|