@sanity/client 6.28.3-instruct.0 → 6.28.3-resources.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 +25 -16
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +25 -16
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +69 -74
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +7 -240
- package/dist/index.browser.d.ts +7 -240
- package/dist/index.browser.js +69 -74
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +47 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -229
- package/dist/index.d.ts +7 -229
- package/dist/index.js +48 -60
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +7 -234
- package/dist/stega.browser.d.ts +7 -234
- package/dist/stega.d.cts +7 -234
- package/dist/stega.d.ts +7 -234
- package/package.json +20 -20
- package/src/SanityClient.ts +1 -5
- package/src/assets/AssetsClient.ts +15 -3
- package/src/config.ts +15 -20
- package/src/data/dataMethods.ts +45 -5
- package/src/data/listen.ts +1 -1
- package/src/data/live.ts +2 -0
- package/src/datasets/DatasetsClient.ts +5 -0
- package/src/http/requestOptions.ts +1 -1
- package/src/projects/ProjectsClient.ts +5 -0
- package/src/types.ts +8 -10
- package/src/validators.ts +23 -0
- package/src/warnings.ts +5 -0
- package/umd/sanityClient.js +76 -79
- package/umd/sanityClient.min.js +2 -2
- package/src/assist/AssistClient.ts +0 -87
- package/src/assist/types.ts +0 -203
package/dist/index.browser.cjs
CHANGED
|
@@ -123,8 +123,8 @@ function defineHttpRequest(envMiddleware2) {
|
|
|
123
123
|
}
|
|
124
124
|
function shouldRetry(err, attempt, options) {
|
|
125
125
|
if (options.maxRetries === 0) return !1;
|
|
126
|
-
const isSafe = options.method === "GET" || options.method === "HEAD",
|
|
127
|
-
return (isSafe ||
|
|
126
|
+
const isSafe = options.method === "GET" || options.method === "HEAD", isQuery2 = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
127
|
+
return (isSafe || isQuery2) && isRetriableResponse ? !0 : middleware.retry.shouldRetry(err, attempt, options);
|
|
128
128
|
}
|
|
129
129
|
const BASE_URL = "https://www.sanity.io/help/";
|
|
130
130
|
function generateHelpUrl(slug) {
|
|
@@ -171,6 +171,20 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
171
171
|
"Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long."
|
|
172
172
|
);
|
|
173
173
|
return tag;
|
|
174
|
+
}, resourceBase = (config) => {
|
|
175
|
+
if (!config["~experimental_resource"])
|
|
176
|
+
throw new Error("`resource` must be provided to perform queries");
|
|
177
|
+
const resourceConfig = config["~experimental_resource"];
|
|
178
|
+
if (resourceConfig.type === "dataset") {
|
|
179
|
+
const segments = resourceConfig.id.split(".");
|
|
180
|
+
if (segments.length !== 2)
|
|
181
|
+
throw new Error('Dataset ID must be in the format "project.dataset"');
|
|
182
|
+
return `/projects/${segments[0]}/datasets/${segments[1]}`;
|
|
183
|
+
}
|
|
184
|
+
return `/${resourceConfig.type}/${resourceConfig.id}`;
|
|
185
|
+
}, resourceGuard = (service, config) => {
|
|
186
|
+
if (config["~experimental_resource"])
|
|
187
|
+
throw new Error(`\`${service}\` does not support resource-based operations`);
|
|
174
188
|
};
|
|
175
189
|
function once(fn) {
|
|
176
190
|
let didCall = !1, returnValue;
|
|
@@ -196,6 +210,9 @@ const createWarningPrinter = (message) => (
|
|
|
196
210
|
`See ${generateHelpUrl(
|
|
197
211
|
"js-client-browser-token"
|
|
198
212
|
)} for more information and how to hide this warning.`
|
|
213
|
+
]), printCredentialedTokenWarning = createWarningPrinter([
|
|
214
|
+
"You have configured Sanity client to use a token, but also provided `withCredentials: true`.",
|
|
215
|
+
"This is no longer supported - only token will be used - remove `withCredentials: true`."
|
|
199
216
|
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
200
217
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
201
218
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
@@ -214,21 +231,11 @@ function validateApiVersion(apiVersion) {
|
|
|
214
231
|
if (!(/^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0))
|
|
215
232
|
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
216
233
|
}
|
|
217
|
-
const VALID_PERSPECTIVE = /^[a-z0-9_]+$/i;
|
|
218
234
|
function validateApiPerspective(perspective) {
|
|
219
|
-
if (Array.isArray(perspective) && perspective.includes("raw"))
|
|
235
|
+
if (Array.isArray(perspective) && perspective.length > 1 && perspective.includes("raw"))
|
|
220
236
|
throw new TypeError(
|
|
221
237
|
'Invalid API perspective value: "raw". The raw-perspective can not be combined with other perspectives'
|
|
222
238
|
);
|
|
223
|
-
const invalid = (Array.isArray(perspective) ? perspective : [perspective]).filter(
|
|
224
|
-
(perspectiveName) => typeof perspectiveName != "string" || !VALID_PERSPECTIVE.test(perspectiveName)
|
|
225
|
-
);
|
|
226
|
-
if (invalid.length > 0) {
|
|
227
|
-
const formatted = invalid.map((v) => JSON.stringify(v));
|
|
228
|
-
throw new TypeError(
|
|
229
|
-
`Invalid API perspective value${invalid.length === 1 ? "" : "s"}: ${formatted.join(", ")}, expected \`published\`, \`drafts\`, \`raw\` or a release identifier string`
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
239
|
}
|
|
233
240
|
const initConfig = (config, prevConfig) => {
|
|
234
241
|
const specifiedConfig = {
|
|
@@ -243,14 +250,14 @@ const initConfig = (config, prevConfig) => {
|
|
|
243
250
|
const newConfig = {
|
|
244
251
|
...defaultConfig,
|
|
245
252
|
...specifiedConfig
|
|
246
|
-
}, projectBased = newConfig.useProjectHostname;
|
|
253
|
+
}, projectBased = newConfig.useProjectHostname && !newConfig["~experimental_resource"];
|
|
247
254
|
if (typeof Promise > "u") {
|
|
248
255
|
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
249
256
|
throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`);
|
|
250
257
|
}
|
|
251
258
|
if (projectBased && !newConfig.projectId)
|
|
252
259
|
throw new Error("Configuration must contain `projectId`");
|
|
253
|
-
if (typeof newConfig.perspective < "u" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
|
|
260
|
+
if (newConfig["~experimental_resource"] && resourceBase(newConfig), typeof newConfig.perspective < "u" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
|
|
254
261
|
throw new Error(
|
|
255
262
|
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client'. Did you mean 'stega.enabled'?"
|
|
256
263
|
);
|
|
@@ -266,10 +273,10 @@ const initConfig = (config, prevConfig) => {
|
|
|
266
273
|
throw new Error(
|
|
267
274
|
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
268
275
|
);
|
|
269
|
-
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
270
|
-
|
|
276
|
+
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname), hasToken = !!newConfig.token;
|
|
277
|
+
newConfig.withCredentials && hasToken && (printCredentialedTokenWarning(), newConfig.withCredentials = !1), isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== !0 ? printBrowserTokenWarning() : typeof newConfig.useCdn > "u" && printCdnWarning(), projectBased && projectId(newConfig.projectId), newConfig.dataset && dataset(newConfig.dataset), "requestTagPrefix" in newConfig && (newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0), newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, ""), newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost, newConfig.useCdn === !0 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== !1 && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
271
278
|
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
272
|
-
return
|
|
279
|
+
return projectBased ? (newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`, newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`) : (newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`, newConfig.cdnUrl = newConfig.url), newConfig;
|
|
273
280
|
};
|
|
274
281
|
class ConnectionFailedError extends Error {
|
|
275
282
|
name = "ConnectionFailedError";
|
|
@@ -715,7 +722,7 @@ const projectHeader = "X-Sanity-Project-ID";
|
|
|
715
722
|
function requestOptions(config, overrides = {}) {
|
|
716
723
|
const headers = {}, token = overrides.token || config.token;
|
|
717
724
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
718
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.
|
|
725
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
719
726
|
return Object.assign({}, overrides, {
|
|
720
727
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
721
728
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
@@ -839,7 +846,7 @@ function _action(client, httpRequest, actions, options) {
|
|
|
839
846
|
);
|
|
840
847
|
}
|
|
841
848
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
842
|
-
const isMutation = endpoint === "mutate", isAction = endpoint === "actions",
|
|
849
|
+
const isMutation = endpoint === "mutate", isAction = endpoint === "actions", isQuery2 = endpoint === "query", strQuery = isMutation || isAction ? "" : encodeQueryString(body), useGet = !isMutation && !isAction && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId, cacheMode } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
|
|
843
850
|
method: useGet ? "GET" : "POST",
|
|
844
851
|
uri,
|
|
845
852
|
json: !0,
|
|
@@ -854,7 +861,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
854
861
|
resultSourceMap: options.resultSourceMap,
|
|
855
862
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
856
863
|
cacheMode,
|
|
857
|
-
canUseCdn:
|
|
864
|
+
canUseCdn: isQuery2,
|
|
858
865
|
signal: options.signal,
|
|
859
866
|
fetch: options.fetch,
|
|
860
867
|
useAbortSignal: options.useAbortSignal,
|
|
@@ -882,11 +889,22 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
882
889
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
|
|
883
890
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
884
891
|
}
|
|
892
|
+
const isQuery = (config, uri) => uri.startsWith("/data/query/") || config["~experimental_resource"] && uri.startsWith(
|
|
893
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/query`
|
|
894
|
+
), isMutate = (config, uri) => uri.startsWith("/data/mutate/") || config["~experimental_resource"] && uri.startsWith(
|
|
895
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/mutate`
|
|
896
|
+
), isDoc = (config, uri) => uri.startsWith("/data/doc/") || config["~experimental_resource"] && uri.startsWith(
|
|
897
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/doc/`
|
|
898
|
+
), isListener = (config, uri) => uri.startsWith("/data/listen/") || config["~experimental_resource"] && uri.startsWith(
|
|
899
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/listen`
|
|
900
|
+
), isHistory = (config, uri) => uri.startsWith("/data/history/") || config["~experimental_resource"] && uri.startsWith(
|
|
901
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/history/`
|
|
902
|
+
), isData = (config, uri) => uri.startsWith("/data/") || isQuery(config, uri) || isMutate(config, uri) || isDoc(config, uri) || isListener(config, uri) || isHistory(config, uri);
|
|
885
903
|
function _requestObservable(client, httpRequest, options) {
|
|
886
|
-
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri
|
|
904
|
+
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(config, uri) : options.canUseCdn;
|
|
887
905
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
888
906
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
889
|
-
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 &&
|
|
907
|
+
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(config, uri)) {
|
|
890
908
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
891
909
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
892
910
|
const perspectiveOption = options.perspective || config.perspective;
|
|
@@ -913,7 +931,12 @@ function _request(client, httpRequest, options) {
|
|
|
913
931
|
);
|
|
914
932
|
}
|
|
915
933
|
function _getDataUrl(client, operation, path) {
|
|
916
|
-
const config = client.config()
|
|
934
|
+
const config = client.config();
|
|
935
|
+
if (config["~experimental_resource"]) {
|
|
936
|
+
const resourceBase$1 = resourceBase(config), uri2 = path ? `${operation}/${path}` : operation;
|
|
937
|
+
return `${resourceBase$1}/${uri2}`.replace(/\/($|\?)/, "$1");
|
|
938
|
+
}
|
|
939
|
+
const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
917
940
|
return `/data${path ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
918
941
|
}
|
|
919
942
|
function _getUrl(client, uri, canUseCdn = !1) {
|
|
@@ -972,7 +995,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
972
995
|
validateAssetType(assetType);
|
|
973
996
|
let meta = opts.extract || void 0;
|
|
974
997
|
meta && !meta.length && (meta = ["none"]);
|
|
975
|
-
const
|
|
998
|
+
const config = client.config(), options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
|
|
976
999
|
label,
|
|
977
1000
|
title,
|
|
978
1001
|
description,
|
|
@@ -984,12 +1007,19 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
984
1007
|
tag,
|
|
985
1008
|
method: "POST",
|
|
986
1009
|
timeout: options.timeout || 0,
|
|
987
|
-
uri:
|
|
1010
|
+
uri: buildAssetUploadUrl(config, assetType),
|
|
988
1011
|
headers: options.contentType ? { "Content-Type": options.contentType } : {},
|
|
989
1012
|
query,
|
|
990
1013
|
body
|
|
991
1014
|
});
|
|
992
1015
|
}
|
|
1016
|
+
function buildAssetUploadUrl(config, assetType) {
|
|
1017
|
+
const assetTypeEndpoint = assetType === "image" ? "images" : "files";
|
|
1018
|
+
if (config["~experimental_resource"])
|
|
1019
|
+
return `${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/assets/${assetTypeEndpoint}`;
|
|
1020
|
+
const dataset2 = hasDataset(config);
|
|
1021
|
+
return `assets/${assetTypeEndpoint}/${dataset2}`;
|
|
1022
|
+
}
|
|
993
1023
|
function optionsFromFile(opts, file) {
|
|
994
1024
|
return typeof File > "u" || !(file instanceof File) ? opts : Object.assign(
|
|
995
1025
|
{
|
|
@@ -999,42 +1029,6 @@ function optionsFromFile(opts, file) {
|
|
|
999
1029
|
opts
|
|
1000
1030
|
);
|
|
1001
1031
|
}
|
|
1002
|
-
function _instruct(client, httpRequest, request) {
|
|
1003
|
-
const dataset2 = hasDataset(client.config());
|
|
1004
|
-
return _request(client, httpRequest, {
|
|
1005
|
-
method: "POST",
|
|
1006
|
-
uri: `/assist/tasks/instruct/${dataset2}`,
|
|
1007
|
-
body: request
|
|
1008
|
-
});
|
|
1009
|
-
}
|
|
1010
|
-
class ObservableAssistClient {
|
|
1011
|
-
#client;
|
|
1012
|
-
#httpRequest;
|
|
1013
|
-
constructor(client, httpRequest) {
|
|
1014
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
1015
|
-
}
|
|
1016
|
-
/**
|
|
1017
|
-
* Run an ad-hoc instruction for a target document.
|
|
1018
|
-
* @param request instruction request
|
|
1019
|
-
*/
|
|
1020
|
-
instruct(request) {
|
|
1021
|
-
return _instruct(this.#client, this.#httpRequest, request);
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
class AssistClient {
|
|
1025
|
-
#client;
|
|
1026
|
-
#httpRequest;
|
|
1027
|
-
constructor(client, httpRequest) {
|
|
1028
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
1029
|
-
}
|
|
1030
|
-
/**
|
|
1031
|
-
* Run an ad-hoc instruction for a target document.
|
|
1032
|
-
* @param request instruction request
|
|
1033
|
-
*/
|
|
1034
|
-
instruct(request) {
|
|
1035
|
-
return rxjs.lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
1032
|
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), {});
|
|
1039
1033
|
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = rxjs.defer(() => import("@sanity/eventsource")).pipe(
|
|
1040
1034
|
operators.map(({ default: EventSource2 }) => EventSource2),
|
|
@@ -1063,7 +1057,7 @@ function _listen(query, params, opts = {}) {
|
|
|
1063
1057
|
if (uri.length > MAX_URL_LENGTH)
|
|
1064
1058
|
return rxjs.throwError(() => new Error("Query too large for listener"));
|
|
1065
1059
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
1066
|
-
return
|
|
1060
|
+
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
1067
1061
|
Authorization: `Bearer ${token}`
|
|
1068
1062
|
}), connectEventSource(() => (
|
|
1069
1063
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
@@ -1117,6 +1111,7 @@ class LiveClient {
|
|
|
1117
1111
|
includeDrafts = !1,
|
|
1118
1112
|
tag: _tag
|
|
1119
1113
|
} = {}) {
|
|
1114
|
+
resourceGuard("live", this.#client.config());
|
|
1120
1115
|
const {
|
|
1121
1116
|
projectId: projectId2,
|
|
1122
1117
|
apiVersion: _apiVersion,
|
|
@@ -1246,7 +1241,7 @@ class DatasetsClient {
|
|
|
1246
1241
|
* @param options - Options for the dataset
|
|
1247
1242
|
*/
|
|
1248
1243
|
create(name, options) {
|
|
1249
|
-
return rxjs.lastValueFrom(
|
|
1244
|
+
return resourceGuard("dataset", this.#client.config()), rxjs.lastValueFrom(
|
|
1250
1245
|
_modify(this.#client, this.#httpRequest, "PUT", name, options)
|
|
1251
1246
|
);
|
|
1252
1247
|
}
|
|
@@ -1257,7 +1252,7 @@ class DatasetsClient {
|
|
|
1257
1252
|
* @param options - New options for the dataset
|
|
1258
1253
|
*/
|
|
1259
1254
|
edit(name, options) {
|
|
1260
|
-
return rxjs.lastValueFrom(
|
|
1255
|
+
return resourceGuard("dataset", this.#client.config()), rxjs.lastValueFrom(
|
|
1261
1256
|
_modify(this.#client, this.#httpRequest, "PATCH", name, options)
|
|
1262
1257
|
);
|
|
1263
1258
|
}
|
|
@@ -1267,19 +1262,19 @@ class DatasetsClient {
|
|
|
1267
1262
|
* @param name - Name of the dataset to delete
|
|
1268
1263
|
*/
|
|
1269
1264
|
delete(name) {
|
|
1270
|
-
return rxjs.lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
|
|
1265
|
+
return resourceGuard("dataset", this.#client.config()), rxjs.lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
|
|
1271
1266
|
}
|
|
1272
1267
|
/**
|
|
1273
1268
|
* Fetch a list of datasets for the configured project
|
|
1274
1269
|
*/
|
|
1275
1270
|
list() {
|
|
1276
|
-
return rxjs.lastValueFrom(
|
|
1271
|
+
return resourceGuard("dataset", this.#client.config()), rxjs.lastValueFrom(
|
|
1277
1272
|
_request(this.#client, this.#httpRequest, { uri: "/datasets", tag: null })
|
|
1278
1273
|
);
|
|
1279
1274
|
}
|
|
1280
1275
|
}
|
|
1281
1276
|
function _modify(client, httpRequest, method, name, options) {
|
|
1282
|
-
return dataset(name), _request(client, httpRequest, {
|
|
1277
|
+
return resourceGuard("dataset", client.config()), dataset(name), _request(client, httpRequest, {
|
|
1283
1278
|
method,
|
|
1284
1279
|
uri: `/datasets/${name}`,
|
|
1285
1280
|
body: options,
|
|
@@ -1293,6 +1288,7 @@ class ObservableProjectsClient {
|
|
|
1293
1288
|
this.#client = client, this.#httpRequest = httpRequest;
|
|
1294
1289
|
}
|
|
1295
1290
|
list(options) {
|
|
1291
|
+
resourceGuard("projects", this.#client.config());
|
|
1296
1292
|
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1297
1293
|
return _request(this.#client, this.#httpRequest, { uri });
|
|
1298
1294
|
}
|
|
@@ -1302,7 +1298,7 @@ class ObservableProjectsClient {
|
|
|
1302
1298
|
* @param projectId - ID of the project to fetch
|
|
1303
1299
|
*/
|
|
1304
1300
|
getById(projectId2) {
|
|
1305
|
-
return _request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` });
|
|
1301
|
+
return resourceGuard("projects", this.#client.config()), _request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` });
|
|
1306
1302
|
}
|
|
1307
1303
|
}
|
|
1308
1304
|
class ProjectsClient {
|
|
@@ -1312,6 +1308,7 @@ class ProjectsClient {
|
|
|
1312
1308
|
this.#client = client, this.#httpRequest = httpRequest;
|
|
1313
1309
|
}
|
|
1314
1310
|
list(options) {
|
|
1311
|
+
resourceGuard("projects", this.#client.config());
|
|
1315
1312
|
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1316
1313
|
return rxjs.lastValueFrom(_request(this.#client, this.#httpRequest, { uri }));
|
|
1317
1314
|
}
|
|
@@ -1321,7 +1318,7 @@ class ProjectsClient {
|
|
|
1321
1318
|
* @param projectId - ID of the project to fetch
|
|
1322
1319
|
*/
|
|
1323
1320
|
getById(projectId2) {
|
|
1324
|
-
return rxjs.lastValueFrom(
|
|
1321
|
+
return resourceGuard("projects", this.#client.config()), rxjs.lastValueFrom(
|
|
1325
1322
|
_request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` })
|
|
1326
1323
|
);
|
|
1327
1324
|
}
|
|
@@ -1370,7 +1367,6 @@ class ObservableSanityClient {
|
|
|
1370
1367
|
live;
|
|
1371
1368
|
projects;
|
|
1372
1369
|
users;
|
|
1373
|
-
assist;
|
|
1374
1370
|
/**
|
|
1375
1371
|
* Private properties
|
|
1376
1372
|
*/
|
|
@@ -1381,7 +1377,7 @@ class ObservableSanityClient {
|
|
|
1381
1377
|
*/
|
|
1382
1378
|
listen = _listen;
|
|
1383
1379
|
constructor(httpRequest, config = defaultConfig) {
|
|
1384
|
-
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)
|
|
1380
|
+
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);
|
|
1385
1381
|
}
|
|
1386
1382
|
/**
|
|
1387
1383
|
* Clone the client - returns a new instance
|
|
@@ -1520,7 +1516,6 @@ class SanityClient {
|
|
|
1520
1516
|
live;
|
|
1521
1517
|
projects;
|
|
1522
1518
|
users;
|
|
1523
|
-
assist;
|
|
1524
1519
|
/**
|
|
1525
1520
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1526
1521
|
*/
|
|
@@ -1535,7 +1530,7 @@ class SanityClient {
|
|
|
1535
1530
|
*/
|
|
1536
1531
|
listen = _listen;
|
|
1537
1532
|
constructor(httpRequest, config = defaultConfig) {
|
|
1538
|
-
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.
|
|
1533
|
+
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);
|
|
1539
1534
|
}
|
|
1540
1535
|
/**
|
|
1541
1536
|
* Clone the client - returns a new instance
|