@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.js
CHANGED
|
@@ -107,8 +107,8 @@ function defineHttpRequest(envMiddleware2) {
|
|
|
107
107
|
}
|
|
108
108
|
function shouldRetry(err, attempt, options) {
|
|
109
109
|
if (options.maxRetries === 0) return !1;
|
|
110
|
-
const isSafe = options.method === "GET" || options.method === "HEAD",
|
|
111
|
-
return (isSafe ||
|
|
110
|
+
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);
|
|
111
|
+
return (isSafe || isQuery2) && isRetriableResponse ? !0 : retry.shouldRetry(err, attempt, options);
|
|
112
112
|
}
|
|
113
113
|
const BASE_URL = "https://www.sanity.io/help/";
|
|
114
114
|
function generateHelpUrl(slug) {
|
|
@@ -155,6 +155,20 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
|
|
|
155
155
|
"Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long."
|
|
156
156
|
);
|
|
157
157
|
return tag;
|
|
158
|
+
}, resourceBase = (config) => {
|
|
159
|
+
if (!config["~experimental_resource"])
|
|
160
|
+
throw new Error("`resource` must be provided to perform queries");
|
|
161
|
+
const resourceConfig = config["~experimental_resource"];
|
|
162
|
+
if (resourceConfig.type === "dataset") {
|
|
163
|
+
const segments = resourceConfig.id.split(".");
|
|
164
|
+
if (segments.length !== 2)
|
|
165
|
+
throw new Error('Dataset ID must be in the format "project.dataset"');
|
|
166
|
+
return `/projects/${segments[0]}/datasets/${segments[1]}`;
|
|
167
|
+
}
|
|
168
|
+
return `/${resourceConfig.type}/${resourceConfig.id}`;
|
|
169
|
+
}, resourceGuard = (service, config) => {
|
|
170
|
+
if (config["~experimental_resource"])
|
|
171
|
+
throw new Error(`\`${service}\` does not support resource-based operations`);
|
|
158
172
|
};
|
|
159
173
|
function once(fn) {
|
|
160
174
|
let didCall = !1, returnValue;
|
|
@@ -180,6 +194,9 @@ const createWarningPrinter = (message) => (
|
|
|
180
194
|
`See ${generateHelpUrl(
|
|
181
195
|
"js-client-browser-token"
|
|
182
196
|
)} for more information and how to hide this warning.`
|
|
197
|
+
]), printCredentialedTokenWarning = createWarningPrinter([
|
|
198
|
+
"You have configured Sanity client to use a token, but also provided `withCredentials: true`.",
|
|
199
|
+
"This is no longer supported - only token will be used - remove `withCredentials: true`."
|
|
183
200
|
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
184
201
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
185
202
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
@@ -198,21 +215,11 @@ function validateApiVersion(apiVersion) {
|
|
|
198
215
|
if (!(/^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0))
|
|
199
216
|
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
200
217
|
}
|
|
201
|
-
const VALID_PERSPECTIVE = /^[a-z0-9_]+$/i;
|
|
202
218
|
function validateApiPerspective(perspective) {
|
|
203
|
-
if (Array.isArray(perspective) && perspective.includes("raw"))
|
|
219
|
+
if (Array.isArray(perspective) && perspective.length > 1 && perspective.includes("raw"))
|
|
204
220
|
throw new TypeError(
|
|
205
221
|
'Invalid API perspective value: "raw". The raw-perspective can not be combined with other perspectives'
|
|
206
222
|
);
|
|
207
|
-
const invalid = (Array.isArray(perspective) ? perspective : [perspective]).filter(
|
|
208
|
-
(perspectiveName) => typeof perspectiveName != "string" || !VALID_PERSPECTIVE.test(perspectiveName)
|
|
209
|
-
);
|
|
210
|
-
if (invalid.length > 0) {
|
|
211
|
-
const formatted = invalid.map((v) => JSON.stringify(v));
|
|
212
|
-
throw new TypeError(
|
|
213
|
-
`Invalid API perspective value${invalid.length === 1 ? "" : "s"}: ${formatted.join(", ")}, expected \`published\`, \`drafts\`, \`raw\` or a release identifier string`
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
223
|
}
|
|
217
224
|
const initConfig = (config, prevConfig) => {
|
|
218
225
|
const specifiedConfig = {
|
|
@@ -227,14 +234,14 @@ const initConfig = (config, prevConfig) => {
|
|
|
227
234
|
const newConfig = {
|
|
228
235
|
...defaultConfig,
|
|
229
236
|
...specifiedConfig
|
|
230
|
-
}, projectBased = newConfig.useProjectHostname;
|
|
237
|
+
}, projectBased = newConfig.useProjectHostname && !newConfig["~experimental_resource"];
|
|
231
238
|
if (typeof Promise > "u") {
|
|
232
239
|
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
233
240
|
throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`);
|
|
234
241
|
}
|
|
235
242
|
if (projectBased && !newConfig.projectId)
|
|
236
243
|
throw new Error("Configuration must contain `projectId`");
|
|
237
|
-
if (typeof newConfig.perspective < "u" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
|
|
244
|
+
if (newConfig["~experimental_resource"] && resourceBase(newConfig), typeof newConfig.perspective < "u" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
|
|
238
245
|
throw new Error(
|
|
239
246
|
"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'?"
|
|
240
247
|
);
|
|
@@ -250,10 +257,10 @@ const initConfig = (config, prevConfig) => {
|
|
|
250
257
|
throw new Error(
|
|
251
258
|
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
252
259
|
);
|
|
253
|
-
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
254
|
-
|
|
260
|
+
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname), hasToken = !!newConfig.token;
|
|
261
|
+
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);
|
|
255
262
|
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
256
|
-
return
|
|
263
|
+
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;
|
|
257
264
|
};
|
|
258
265
|
class ConnectionFailedError extends Error {
|
|
259
266
|
name = "ConnectionFailedError";
|
|
@@ -699,7 +706,7 @@ const projectHeader = "X-Sanity-Project-ID";
|
|
|
699
706
|
function requestOptions(config, overrides = {}) {
|
|
700
707
|
const headers = {}, token = overrides.token || config.token;
|
|
701
708
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
702
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.
|
|
709
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
703
710
|
return Object.assign({}, overrides, {
|
|
704
711
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
705
712
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
@@ -821,7 +828,7 @@ function _action(client, httpRequest, actions, options) {
|
|
|
821
828
|
);
|
|
822
829
|
}
|
|
823
830
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
824
|
-
const isMutation = endpoint === "mutate", isAction = endpoint === "actions",
|
|
831
|
+
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 = {
|
|
825
832
|
method: useGet ? "GET" : "POST",
|
|
826
833
|
uri,
|
|
827
834
|
json: !0,
|
|
@@ -836,7 +843,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
836
843
|
resultSourceMap: options.resultSourceMap,
|
|
837
844
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
838
845
|
cacheMode,
|
|
839
|
-
canUseCdn:
|
|
846
|
+
canUseCdn: isQuery2,
|
|
840
847
|
signal: options.signal,
|
|
841
848
|
fetch: options.fetch,
|
|
842
849
|
useAbortSignal: options.useAbortSignal,
|
|
@@ -864,11 +871,22 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
864
871
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
|
|
865
872
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
866
873
|
}
|
|
874
|
+
const isQuery = (config, uri) => uri.startsWith("/data/query/") || config["~experimental_resource"] && uri.startsWith(
|
|
875
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/query`
|
|
876
|
+
), isMutate = (config, uri) => uri.startsWith("/data/mutate/") || config["~experimental_resource"] && uri.startsWith(
|
|
877
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/mutate`
|
|
878
|
+
), isDoc = (config, uri) => uri.startsWith("/data/doc/") || config["~experimental_resource"] && uri.startsWith(
|
|
879
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/doc/`
|
|
880
|
+
), isListener = (config, uri) => uri.startsWith("/data/listen/") || config["~experimental_resource"] && uri.startsWith(
|
|
881
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/listen`
|
|
882
|
+
), isHistory = (config, uri) => uri.startsWith("/data/history/") || config["~experimental_resource"] && uri.startsWith(
|
|
883
|
+
`/${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/history/`
|
|
884
|
+
), isData = (config, uri) => uri.startsWith("/data/") || isQuery(config, uri) || isMutate(config, uri) || isDoc(config, uri) || isListener(config, uri) || isHistory(config, uri);
|
|
867
885
|
function _requestObservable(client, httpRequest, options) {
|
|
868
|
-
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri
|
|
886
|
+
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;
|
|
869
887
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
870
888
|
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
871
|
-
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 &&
|
|
889
|
+
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(config, uri)) {
|
|
872
890
|
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
873
891
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
874
892
|
const perspectiveOption = options.perspective || config.perspective;
|
|
@@ -895,7 +913,12 @@ function _request(client, httpRequest, options) {
|
|
|
895
913
|
);
|
|
896
914
|
}
|
|
897
915
|
function _getDataUrl(client, operation, path) {
|
|
898
|
-
const config = client.config()
|
|
916
|
+
const config = client.config();
|
|
917
|
+
if (config["~experimental_resource"]) {
|
|
918
|
+
const resourceBase$1 = resourceBase(config), uri2 = path ? `${operation}/${path}` : operation;
|
|
919
|
+
return `${resourceBase$1}/${uri2}`.replace(/\/($|\?)/, "$1");
|
|
920
|
+
}
|
|
921
|
+
const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
899
922
|
return `/data${path ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
900
923
|
}
|
|
901
924
|
function _getUrl(client, uri, canUseCdn = !1) {
|
|
@@ -954,7 +977,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
954
977
|
validateAssetType(assetType);
|
|
955
978
|
let meta = opts.extract || void 0;
|
|
956
979
|
meta && !meta.length && (meta = ["none"]);
|
|
957
|
-
const
|
|
980
|
+
const config = client.config(), options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
|
|
958
981
|
label,
|
|
959
982
|
title,
|
|
960
983
|
description,
|
|
@@ -966,12 +989,19 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
966
989
|
tag,
|
|
967
990
|
method: "POST",
|
|
968
991
|
timeout: options.timeout || 0,
|
|
969
|
-
uri:
|
|
992
|
+
uri: buildAssetUploadUrl(config, assetType),
|
|
970
993
|
headers: options.contentType ? { "Content-Type": options.contentType } : {},
|
|
971
994
|
query,
|
|
972
995
|
body
|
|
973
996
|
});
|
|
974
997
|
}
|
|
998
|
+
function buildAssetUploadUrl(config, assetType) {
|
|
999
|
+
const assetTypeEndpoint = assetType === "image" ? "images" : "files";
|
|
1000
|
+
if (config["~experimental_resource"])
|
|
1001
|
+
return `${config["~experimental_resource"].type}/${config["~experimental_resource"].id}/assets/${assetTypeEndpoint}`;
|
|
1002
|
+
const dataset2 = hasDataset(config);
|
|
1003
|
+
return `assets/${assetTypeEndpoint}/${dataset2}`;
|
|
1004
|
+
}
|
|
975
1005
|
function optionsFromFile(opts, file) {
|
|
976
1006
|
return typeof File > "u" || !(file instanceof File) ? opts : Object.assign(
|
|
977
1007
|
{
|
|
@@ -981,42 +1011,6 @@ function optionsFromFile(opts, file) {
|
|
|
981
1011
|
opts
|
|
982
1012
|
);
|
|
983
1013
|
}
|
|
984
|
-
function _instruct(client, httpRequest, request) {
|
|
985
|
-
const dataset2 = hasDataset(client.config());
|
|
986
|
-
return _request(client, httpRequest, {
|
|
987
|
-
method: "POST",
|
|
988
|
-
uri: `/assist/tasks/instruct/${dataset2}`,
|
|
989
|
-
body: request
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
class ObservableAssistClient {
|
|
993
|
-
#client;
|
|
994
|
-
#httpRequest;
|
|
995
|
-
constructor(client, httpRequest) {
|
|
996
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
997
|
-
}
|
|
998
|
-
/**
|
|
999
|
-
* Run an ad-hoc instruction for a target document.
|
|
1000
|
-
* @param request instruction request
|
|
1001
|
-
*/
|
|
1002
|
-
instruct(request) {
|
|
1003
|
-
return _instruct(this.#client, this.#httpRequest, request);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
class AssistClient {
|
|
1007
|
-
#client;
|
|
1008
|
-
#httpRequest;
|
|
1009
|
-
constructor(client, httpRequest) {
|
|
1010
|
-
this.#client = client, this.#httpRequest = httpRequest;
|
|
1011
|
-
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Run an ad-hoc instruction for a target document.
|
|
1014
|
-
* @param request instruction request
|
|
1015
|
-
*/
|
|
1016
|
-
instruct(request) {
|
|
1017
|
-
return lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
1014
|
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), {});
|
|
1021
1015
|
const pick = (obj, props) => props.reduce((selection, prop) => (typeof obj[prop] > "u" || (selection[prop] = obj[prop]), selection), {}), eventSourcePolyfill = defer(() => import("@sanity/eventsource")).pipe(
|
|
1022
1016
|
map(({ default: EventSource2 }) => EventSource2),
|
|
@@ -1045,7 +1039,7 @@ function _listen(query, params, opts = {}) {
|
|
|
1045
1039
|
if (uri.length > MAX_URL_LENGTH)
|
|
1046
1040
|
return throwError(() => new Error("Query too large for listener"));
|
|
1047
1041
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
1048
|
-
return
|
|
1042
|
+
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
1049
1043
|
Authorization: `Bearer ${token}`
|
|
1050
1044
|
}), connectEventSource(() => (
|
|
1051
1045
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
@@ -1099,6 +1093,7 @@ class LiveClient {
|
|
|
1099
1093
|
includeDrafts = !1,
|
|
1100
1094
|
tag: _tag
|
|
1101
1095
|
} = {}) {
|
|
1096
|
+
resourceGuard("live", this.#client.config());
|
|
1102
1097
|
const {
|
|
1103
1098
|
projectId: projectId2,
|
|
1104
1099
|
apiVersion: _apiVersion,
|
|
@@ -1228,7 +1223,7 @@ class DatasetsClient {
|
|
|
1228
1223
|
* @param options - Options for the dataset
|
|
1229
1224
|
*/
|
|
1230
1225
|
create(name, options) {
|
|
1231
|
-
return lastValueFrom(
|
|
1226
|
+
return resourceGuard("dataset", this.#client.config()), lastValueFrom(
|
|
1232
1227
|
_modify(this.#client, this.#httpRequest, "PUT", name, options)
|
|
1233
1228
|
);
|
|
1234
1229
|
}
|
|
@@ -1239,7 +1234,7 @@ class DatasetsClient {
|
|
|
1239
1234
|
* @param options - New options for the dataset
|
|
1240
1235
|
*/
|
|
1241
1236
|
edit(name, options) {
|
|
1242
|
-
return lastValueFrom(
|
|
1237
|
+
return resourceGuard("dataset", this.#client.config()), lastValueFrom(
|
|
1243
1238
|
_modify(this.#client, this.#httpRequest, "PATCH", name, options)
|
|
1244
1239
|
);
|
|
1245
1240
|
}
|
|
@@ -1249,19 +1244,19 @@ class DatasetsClient {
|
|
|
1249
1244
|
* @param name - Name of the dataset to delete
|
|
1250
1245
|
*/
|
|
1251
1246
|
delete(name) {
|
|
1252
|
-
return lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
|
|
1247
|
+
return resourceGuard("dataset", this.#client.config()), lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
|
|
1253
1248
|
}
|
|
1254
1249
|
/**
|
|
1255
1250
|
* Fetch a list of datasets for the configured project
|
|
1256
1251
|
*/
|
|
1257
1252
|
list() {
|
|
1258
|
-
return lastValueFrom(
|
|
1253
|
+
return resourceGuard("dataset", this.#client.config()), lastValueFrom(
|
|
1259
1254
|
_request(this.#client, this.#httpRequest, { uri: "/datasets", tag: null })
|
|
1260
1255
|
);
|
|
1261
1256
|
}
|
|
1262
1257
|
}
|
|
1263
1258
|
function _modify(client, httpRequest, method, name, options) {
|
|
1264
|
-
return dataset(name), _request(client, httpRequest, {
|
|
1259
|
+
return resourceGuard("dataset", client.config()), dataset(name), _request(client, httpRequest, {
|
|
1265
1260
|
method,
|
|
1266
1261
|
uri: `/datasets/${name}`,
|
|
1267
1262
|
body: options,
|
|
@@ -1275,6 +1270,7 @@ class ObservableProjectsClient {
|
|
|
1275
1270
|
this.#client = client, this.#httpRequest = httpRequest;
|
|
1276
1271
|
}
|
|
1277
1272
|
list(options) {
|
|
1273
|
+
resourceGuard("projects", this.#client.config());
|
|
1278
1274
|
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1279
1275
|
return _request(this.#client, this.#httpRequest, { uri });
|
|
1280
1276
|
}
|
|
@@ -1284,7 +1280,7 @@ class ObservableProjectsClient {
|
|
|
1284
1280
|
* @param projectId - ID of the project to fetch
|
|
1285
1281
|
*/
|
|
1286
1282
|
getById(projectId2) {
|
|
1287
|
-
return _request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` });
|
|
1283
|
+
return resourceGuard("projects", this.#client.config()), _request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` });
|
|
1288
1284
|
}
|
|
1289
1285
|
}
|
|
1290
1286
|
class ProjectsClient {
|
|
@@ -1294,6 +1290,7 @@ class ProjectsClient {
|
|
|
1294
1290
|
this.#client = client, this.#httpRequest = httpRequest;
|
|
1295
1291
|
}
|
|
1296
1292
|
list(options) {
|
|
1293
|
+
resourceGuard("projects", this.#client.config());
|
|
1297
1294
|
const uri = options?.includeMembers === !1 ? "/projects?includeMembers=false" : "/projects";
|
|
1298
1295
|
return lastValueFrom(_request(this.#client, this.#httpRequest, { uri }));
|
|
1299
1296
|
}
|
|
@@ -1303,7 +1300,7 @@ class ProjectsClient {
|
|
|
1303
1300
|
* @param projectId - ID of the project to fetch
|
|
1304
1301
|
*/
|
|
1305
1302
|
getById(projectId2) {
|
|
1306
|
-
return lastValueFrom(
|
|
1303
|
+
return resourceGuard("projects", this.#client.config()), lastValueFrom(
|
|
1307
1304
|
_request(this.#client, this.#httpRequest, { uri: `/projects/${projectId2}` })
|
|
1308
1305
|
);
|
|
1309
1306
|
}
|
|
@@ -1352,7 +1349,6 @@ class ObservableSanityClient {
|
|
|
1352
1349
|
live;
|
|
1353
1350
|
projects;
|
|
1354
1351
|
users;
|
|
1355
|
-
assist;
|
|
1356
1352
|
/**
|
|
1357
1353
|
* Private properties
|
|
1358
1354
|
*/
|
|
@@ -1363,7 +1359,7 @@ class ObservableSanityClient {
|
|
|
1363
1359
|
*/
|
|
1364
1360
|
listen = _listen;
|
|
1365
1361
|
constructor(httpRequest, config = defaultConfig) {
|
|
1366
|
-
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)
|
|
1362
|
+
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);
|
|
1367
1363
|
}
|
|
1368
1364
|
/**
|
|
1369
1365
|
* Clone the client - returns a new instance
|
|
@@ -1502,7 +1498,6 @@ class SanityClient {
|
|
|
1502
1498
|
live;
|
|
1503
1499
|
projects;
|
|
1504
1500
|
users;
|
|
1505
|
-
assist;
|
|
1506
1501
|
/**
|
|
1507
1502
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1508
1503
|
*/
|
|
@@ -1517,7 +1512,7 @@ class SanityClient {
|
|
|
1517
1512
|
*/
|
|
1518
1513
|
listen = _listen;
|
|
1519
1514
|
constructor(httpRequest, config = defaultConfig) {
|
|
1520
|
-
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.
|
|
1515
|
+
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);
|
|
1521
1516
|
}
|
|
1522
1517
|
/**
|
|
1523
1518
|
* Clone the client - returns a new instance
|