@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.cjs
CHANGED
|
@@ -737,11 +737,20 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
737
737
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
|
|
738
738
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
739
739
|
}
|
|
740
|
+
function _resourceBase(resource) {
|
|
741
|
+
return `/${resource.type}/${resource.id}`;
|
|
742
|
+
}
|
|
743
|
+
function isDataRequestUri(uri, resource) {
|
|
744
|
+
return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/`) === 0 : uri.indexOf("/data/") === 0;
|
|
745
|
+
}
|
|
746
|
+
function isDataQueryRequestUri(uri, resource) {
|
|
747
|
+
return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/query`) === 0 : uri.indexOf("/data/query") === 0;
|
|
748
|
+
}
|
|
740
749
|
function _requestObservable(client, httpRequest, options) {
|
|
741
|
-
const uri = options.url || options.uri, config$1 = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.
|
|
750
|
+
const uri = options.url || options.uri, config$1 = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isDataRequestUri(uri, config$1.experimental_resource) : options.canUseCdn;
|
|
742
751
|
let useCdn = (options.useCdn ?? config$1.useCdn) && canUseCdn;
|
|
743
752
|
const tag = options.tag && config$1.requestTagPrefix ? [config$1.requestTagPrefix, options.tag].join(".") : options.tag || config$1.requestTagPrefix;
|
|
744
|
-
if (tag && options.tag !== null && (options.query = { tag: config.requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.
|
|
753
|
+
if (tag && options.tag !== null && (options.query = { tag: config.requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isDataQueryRequestUri(uri, config$1.experimental_resource)) {
|
|
745
754
|
const resultSourceMap = options.resultSourceMap ?? config$1.resultSourceMap;
|
|
746
755
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
747
756
|
const perspectiveOption = options.perspective || config$1.perspective;
|
|
@@ -768,12 +777,18 @@ function _request(client, httpRequest, options) {
|
|
|
768
777
|
);
|
|
769
778
|
}
|
|
770
779
|
function _getDataUrl(client, operation, path) {
|
|
771
|
-
const config$1 = client.config()
|
|
780
|
+
const config$1 = client.config();
|
|
781
|
+
if (config$1.experimental_resource) {
|
|
782
|
+
const baseUri2 = `/${operation}`;
|
|
783
|
+
return (path ? `${baseUri2}/${path}` : baseUri2).replace(/\/($|\?)/, "$1");
|
|
784
|
+
}
|
|
785
|
+
const catalog = config.hasDataset(config$1), baseUri = `/${operation}/${catalog}`;
|
|
772
786
|
return `/data${path ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
773
787
|
}
|
|
774
788
|
function _getUrl(client, uri, canUseCdn = !1) {
|
|
775
|
-
const { url, cdnUrl } = client.config();
|
|
776
|
-
|
|
789
|
+
const { url, cdnUrl, experimental_resource } = client.config();
|
|
790
|
+
let base = canUseCdn ? cdnUrl : url;
|
|
791
|
+
return experimental_resource && (uri.indexOf("/users") !== -1 || uri.indexOf("/assets") !== -1) && (base = base.replace(_resourceBase(experimental_resource), "")), `${base}/${uri.replace(/^\//, "")}`;
|
|
777
792
|
}
|
|
778
793
|
function _withAbortSignal(signal) {
|
|
779
794
|
return (input) => new rxjs.Observable((observer) => {
|
|
@@ -827,7 +842,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
827
842
|
config.validateAssetType(assetType);
|
|
828
843
|
let meta = opts.extract || void 0;
|
|
829
844
|
meta && !meta.length && (meta = ["none"]);
|
|
830
|
-
const dataset = config.hasDataset(
|
|
845
|
+
const config$1 = client.config(), resource = config$1.experimental_resource, dataset = resource ? void 0 : config.hasDataset(config$1), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
|
|
831
846
|
label,
|
|
832
847
|
title,
|
|
833
848
|
description,
|
|
@@ -839,7 +854,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
839
854
|
tag,
|
|
840
855
|
method: "POST",
|
|
841
856
|
timeout: options.timeout || 0,
|
|
842
|
-
uri: `/assets/${assetEndpoint}/${dataset}`,
|
|
857
|
+
uri: resource ? `/assets/${resource.type}/${resource.id}/${assetEndpoint}` : `/assets/${assetEndpoint}/${dataset}`,
|
|
843
858
|
headers: options.contentType ? { "Content-Type": options.contentType } : {},
|
|
844
859
|
query,
|
|
845
860
|
body
|
|
@@ -854,42 +869,6 @@ function optionsFromFile(opts, file) {
|
|
|
854
869
|
opts
|
|
855
870
|
);
|
|
856
871
|
}
|
|
857
|
-
function _instruct(client, httpRequest, request) {
|
|
858
|
-
const dataset = config.hasDataset(client.config());
|
|
859
|
-
return _request(client, httpRequest, {
|
|
860
|
-
method: "POST",
|
|
861
|
-
uri: `/assist/tasks/instruct/${dataset}`,
|
|
862
|
-
body: request
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
class ObservableAssistClient {
|
|
866
|
-
#client;
|
|
867
|
-
#httpRequest;
|
|
868
|
-
constructor(client, httpRequest) {
|
|
869
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
* Run an ad-hoc instruction for a target document.
|
|
873
|
-
* @param request instruction request
|
|
874
|
-
*/
|
|
875
|
-
instruct(request) {
|
|
876
|
-
return _instruct(this.#client, this.#httpRequest, request);
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
class AssistClient {
|
|
880
|
-
#client;
|
|
881
|
-
#httpRequest;
|
|
882
|
-
constructor(client, httpRequest) {
|
|
883
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
884
|
-
}
|
|
885
|
-
/**
|
|
886
|
-
* Run an ad-hoc instruction for a target document.
|
|
887
|
-
* @param request instruction request
|
|
888
|
-
*/
|
|
889
|
-
instruct(request) {
|
|
890
|
-
return rxjs.lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
872
|
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), {});
|
|
894
873
|
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = rxjs.defer(() => import("@sanity/eventsource")).pipe(
|
|
895
874
|
operators.map(({ default: EventSource2 }) => EventSource2),
|
|
@@ -1130,6 +1109,23 @@ class DatasetsClient {
|
|
|
1130
1109
|
);
|
|
1131
1110
|
}
|
|
1132
1111
|
}
|
|
1112
|
+
class ThrowingDatasetsClient extends DatasetsClient {
|
|
1113
|
+
constructor(client, httpRequest) {
|
|
1114
|
+
super(client, httpRequest);
|
|
1115
|
+
}
|
|
1116
|
+
create() {
|
|
1117
|
+
throw new Error("cannot create dataset with the current client configuration");
|
|
1118
|
+
}
|
|
1119
|
+
edit() {
|
|
1120
|
+
throw new Error("cannot edit dataset with the current client configuration");
|
|
1121
|
+
}
|
|
1122
|
+
delete() {
|
|
1123
|
+
throw new Error("cannot delete dataset with the current client configuration");
|
|
1124
|
+
}
|
|
1125
|
+
list() {
|
|
1126
|
+
throw new Error("cannot list dataset with the current client configuration");
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1133
1129
|
function _modify(client, httpRequest, method, name2, options) {
|
|
1134
1130
|
return config.dataset(name2), _request(client, httpRequest, {
|
|
1135
1131
|
method,
|
|
@@ -1222,7 +1218,6 @@ class ObservableSanityClient {
|
|
|
1222
1218
|
live;
|
|
1223
1219
|
projects;
|
|
1224
1220
|
users;
|
|
1225
|
-
assist;
|
|
1226
1221
|
/**
|
|
1227
1222
|
* Private properties
|
|
1228
1223
|
*/
|
|
@@ -1233,7 +1228,7 @@ class ObservableSanityClient {
|
|
|
1233
1228
|
*/
|
|
1234
1229
|
listen = _listen;
|
|
1235
1230
|
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
1236
|
-
this.config(config$1), 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)
|
|
1231
|
+
this.config(config$1), 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);
|
|
1237
1232
|
}
|
|
1238
1233
|
/**
|
|
1239
1234
|
* Clone the client - returns a new instance
|
|
@@ -1372,7 +1367,6 @@ class SanityClient {
|
|
|
1372
1367
|
live;
|
|
1373
1368
|
projects;
|
|
1374
1369
|
users;
|
|
1375
|
-
assist;
|
|
1376
1370
|
/**
|
|
1377
1371
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1378
1372
|
*/
|
|
@@ -1387,7 +1381,7 @@ class SanityClient {
|
|
|
1387
1381
|
*/
|
|
1388
1382
|
listen = _listen;
|
|
1389
1383
|
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
1390
|
-
this.config(config$1), 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.
|
|
1384
|
+
this.config(config$1), 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$1);
|
|
1391
1385
|
}
|
|
1392
1386
|
/**
|
|
1393
1387
|
* Clone the client - returns a new instance
|
|
@@ -1563,7 +1557,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
1563
1557
|
return config.printNoDefaultExport(), createClient2(config$1);
|
|
1564
1558
|
};
|
|
1565
1559
|
}
|
|
1566
|
-
var name = "@sanity/client", version = "6.28.0-
|
|
1560
|
+
var name = "@sanity/client", version = "6.28.0-resources-projects.0";
|
|
1567
1561
|
const middleware = [
|
|
1568
1562
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1569
1563
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|