@sanity/client 6.14.1 → 6.14.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/_chunks/browserMiddleware-BHXO2Lcy.cjs +1491 -0
- package/dist/_chunks/{browserMiddleware-FpdqDQ1o.cjs.map → browserMiddleware-BHXO2Lcy.cjs.map} +1 -1
- package/dist/_chunks/browserMiddleware-jPnXCUlp.js +1474 -0
- package/dist/_chunks/{browserMiddleware-DhUBf_19.js.map → browserMiddleware-jPnXCUlp.js.map} +1 -1
- package/dist/_chunks/nodeMiddleware-CrO2pNEp.js +1491 -0
- package/dist/_chunks/{nodeMiddleware-BSZoKrW0.js.map → nodeMiddleware-CrO2pNEp.js.map} +1 -1
- package/dist/_chunks/nodeMiddleware-JJNfI4Rf.cjs +1508 -0
- package/dist/_chunks/{nodeMiddleware-DmcqX3kz.cjs.map → nodeMiddleware-JJNfI4Rf.cjs.map} +1 -1
- package/dist/_chunks/resolveEditInfo-BNCwZySb.cjs +284 -0
- package/dist/_chunks/{resolveEditInfo-BB1WiUDY.cjs.map → resolveEditInfo-BNCwZySb.cjs.map} +1 -1
- package/dist/_chunks/resolveEditInfo-qA5twkfC.js +285 -0
- package/dist/_chunks/{resolveEditInfo-Cf8D1Agp.js.map → resolveEditInfo-qA5twkfC.js.map} +1 -1
- package/dist/_chunks/stegaEncodeSourceMap-B9_uz7Zb.cjs +166 -0
- package/dist/_chunks/{stegaEncodeSourceMap-8TjLXjYU.cjs.map → stegaEncodeSourceMap-B9_uz7Zb.cjs.map} +1 -1
- package/dist/_chunks/stegaEncodeSourceMap-BvBJpbrr.cjs +329 -0
- package/dist/_chunks/{stegaEncodeSourceMap-DIcuvN0P.cjs.map → stegaEncodeSourceMap-BvBJpbrr.cjs.map} +1 -1
- package/dist/_chunks/stegaEncodeSourceMap-De3F_oJN.js +330 -0
- package/dist/_chunks/{stegaEncodeSourceMap-DLon0Yls.js.map → stegaEncodeSourceMap-De3F_oJN.js.map} +1 -1
- package/dist/_chunks/stegaEncodeSourceMap-bRxIGJ-b.js +168 -0
- package/dist/_chunks/{stegaEncodeSourceMap-DU95idpa.js.map → stegaEncodeSourceMap-bRxIGJ-b.js.map} +1 -1
- package/dist/csm.cjs +22 -56
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js +36 -54
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +15 -21
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +24 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +15 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -15
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.cjs +12 -17
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js +26 -11
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +12 -17
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.js +26 -11
- package/dist/stega.js.map +1 -1
- package/package.json +3 -3
- package/umd/sanityClient.js +2670 -3360
- package/umd/sanityClient.min.js +3 -3
- package/dist/_chunks/browserMiddleware-DhUBf_19.js +0 -1761
- package/dist/_chunks/browserMiddleware-FpdqDQ1o.cjs +0 -1777
- package/dist/_chunks/nodeMiddleware-BSZoKrW0.js +0 -1780
- package/dist/_chunks/nodeMiddleware-DmcqX3kz.cjs +0 -1796
- package/dist/_chunks/resolveEditInfo-BB1WiUDY.cjs +0 -422
- package/dist/_chunks/resolveEditInfo-Cf8D1Agp.js +0 -406
- package/dist/_chunks/stegaEncodeSourceMap-8TjLXjYU.cjs +0 -229
- package/dist/_chunks/stegaEncodeSourceMap-DIcuvN0P.cjs +0 -486
- package/dist/_chunks/stegaEncodeSourceMap-DLon0Yls.js +0 -482
- package/dist/_chunks/stegaEncodeSourceMap-DU95idpa.js +0 -225
|
@@ -1,1777 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var rxjs = require('rxjs');
|
|
4
|
-
var operators = require('rxjs/operators');
|
|
5
|
-
var getIt = require('get-it');
|
|
6
|
-
var middleware = require('get-it/middleware');
|
|
7
|
-
|
|
8
|
-
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
9
|
-
class ClientError extends Error {
|
|
10
|
-
constructor(res) {
|
|
11
|
-
const props = extractErrorProps(res);
|
|
12
|
-
super(props.message);
|
|
13
|
-
this.statusCode = 400;
|
|
14
|
-
Object.assign(this, props);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
class ServerError extends Error {
|
|
18
|
-
constructor(res) {
|
|
19
|
-
const props = extractErrorProps(res);
|
|
20
|
-
super(props.message);
|
|
21
|
-
this.statusCode = 500;
|
|
22
|
-
Object.assign(this, props);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function extractErrorProps(res) {
|
|
26
|
-
const body = res.body;
|
|
27
|
-
const props = {
|
|
28
|
-
response: res,
|
|
29
|
-
statusCode: res.statusCode,
|
|
30
|
-
responseBody: stringifyBody(body, res),
|
|
31
|
-
message: "",
|
|
32
|
-
details: void 0
|
|
33
|
-
};
|
|
34
|
-
if (body.error && body.message) {
|
|
35
|
-
props.message = `${body.error} - ${body.message}`;
|
|
36
|
-
return props;
|
|
37
|
-
}
|
|
38
|
-
if (isMutationError(body)) {
|
|
39
|
-
const allItems = body.error.items || [];
|
|
40
|
-
const items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map((item) => {
|
|
41
|
-
var _a;
|
|
42
|
-
return (_a = item.error) == null ? void 0 : _a.description;
|
|
43
|
-
}).filter(Boolean);
|
|
44
|
-
let itemsStr = items.length ? `:
|
|
45
|
-
- ${items.join("\n- ")}` : "";
|
|
46
|
-
if (allItems.length > MAX_ITEMS_IN_ERROR_MESSAGE) {
|
|
47
|
-
itemsStr += `
|
|
48
|
-
...and ${allItems.length - MAX_ITEMS_IN_ERROR_MESSAGE} more`;
|
|
49
|
-
}
|
|
50
|
-
props.message = `${body.error.description}${itemsStr}`;
|
|
51
|
-
props.details = body.error;
|
|
52
|
-
return props;
|
|
53
|
-
}
|
|
54
|
-
if (body.error && body.error.description) {
|
|
55
|
-
props.message = body.error.description;
|
|
56
|
-
props.details = body.error;
|
|
57
|
-
return props;
|
|
58
|
-
}
|
|
59
|
-
props.message = body.error || body.message || httpErrorMessage(res);
|
|
60
|
-
return props;
|
|
61
|
-
}
|
|
62
|
-
function isMutationError(body) {
|
|
63
|
-
return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "mutationError" && typeof body.error.description === "string";
|
|
64
|
-
}
|
|
65
|
-
function isPlainObject(obj) {
|
|
66
|
-
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
67
|
-
}
|
|
68
|
-
function httpErrorMessage(res) {
|
|
69
|
-
const statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
|
|
70
|
-
return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}`;
|
|
71
|
-
}
|
|
72
|
-
function stringifyBody(body, res) {
|
|
73
|
-
const contentType = (res.headers["content-type"] || "").toLowerCase();
|
|
74
|
-
const isJson = contentType.indexOf("application/json") !== -1;
|
|
75
|
-
return isJson ? JSON.stringify(body, null, 2) : body;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const httpError = {
|
|
79
|
-
onResponse: (res) => {
|
|
80
|
-
if (res.statusCode >= 500) {
|
|
81
|
-
throw new ServerError(res);
|
|
82
|
-
} else if (res.statusCode >= 400) {
|
|
83
|
-
throw new ClientError(res);
|
|
84
|
-
}
|
|
85
|
-
return res;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const printWarnings = {
|
|
89
|
-
onResponse: (res) => {
|
|
90
|
-
const warn = res.headers["x-sanity-warning"];
|
|
91
|
-
const warnings = Array.isArray(warn) ? warn : [warn];
|
|
92
|
-
warnings.filter(Boolean).forEach((msg) => console.warn(msg));
|
|
93
|
-
return res;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
function defineHttpRequest(envMiddleware, {
|
|
97
|
-
maxRetries = 5,
|
|
98
|
-
retryDelay
|
|
99
|
-
}) {
|
|
100
|
-
const request = getIt.getIt([
|
|
101
|
-
maxRetries > 0 ? middleware.retry({
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
-
retryDelay,
|
|
104
|
-
// This option is typed incorrectly in get-it.
|
|
105
|
-
maxRetries,
|
|
106
|
-
shouldRetry
|
|
107
|
-
}) : {},
|
|
108
|
-
...envMiddleware,
|
|
109
|
-
printWarnings,
|
|
110
|
-
middleware.jsonRequest(),
|
|
111
|
-
middleware.jsonResponse(),
|
|
112
|
-
middleware.progress(),
|
|
113
|
-
httpError,
|
|
114
|
-
middleware.observable({ implementation: rxjs.Observable })
|
|
115
|
-
]);
|
|
116
|
-
function httpRequest(options, requester = request) {
|
|
117
|
-
return requester({ maxRedirects: 0, ...options });
|
|
118
|
-
}
|
|
119
|
-
httpRequest.defaultRequester = request;
|
|
120
|
-
return httpRequest;
|
|
121
|
-
}
|
|
122
|
-
function shouldRetry(err, attempt, options) {
|
|
123
|
-
const isSafe = options.method === "GET" || options.method === "HEAD";
|
|
124
|
-
const uri = options.uri || options.url;
|
|
125
|
-
const isQuery = uri.startsWith("/data/query");
|
|
126
|
-
const isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
127
|
-
if ((isSafe || isQuery) && isRetriableResponse)
|
|
128
|
-
return true;
|
|
129
|
-
return middleware.retry.shouldRetry(err, attempt, options);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function getSelection(sel) {
|
|
133
|
-
if (typeof sel === "string") {
|
|
134
|
-
return { id: sel };
|
|
135
|
-
}
|
|
136
|
-
if (Array.isArray(sel)) {
|
|
137
|
-
return { query: "*[_id in $ids]", params: { ids: sel } };
|
|
138
|
-
}
|
|
139
|
-
if (typeof sel === "object" && sel !== null && "query" in sel && typeof sel.query === "string") {
|
|
140
|
-
return "params" in sel && typeof sel.params === "object" && sel.params !== null ? { query: sel.query, params: sel.params } : { query: sel.query };
|
|
141
|
-
}
|
|
142
|
-
const selectionOpts = [
|
|
143
|
-
"* Document ID (<docId>)",
|
|
144
|
-
"* Array of document IDs",
|
|
145
|
-
"* Object containing `query`"
|
|
146
|
-
].join("\n");
|
|
147
|
-
throw new Error(`Unknown selection - must be one of:
|
|
148
|
-
|
|
149
|
-
${selectionOpts}`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const VALID_ASSET_TYPES = ["image", "file"];
|
|
153
|
-
const VALID_INSERT_LOCATIONS = ["before", "after", "replace"];
|
|
154
|
-
const dataset = (name) => {
|
|
155
|
-
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
"Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters"
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const projectId = (id) => {
|
|
162
|
-
if (!/^[-a-z0-9]+$/i.test(id)) {
|
|
163
|
-
throw new Error("`projectId` can only contain only a-z, 0-9 and dashes");
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
const validateAssetType = (type) => {
|
|
167
|
-
if (VALID_ASSET_TYPES.indexOf(type) === -1) {
|
|
168
|
-
throw new Error(`Invalid asset type: ${type}. Must be one of ${VALID_ASSET_TYPES.join(", ")}`);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
const validateObject = (op, val) => {
|
|
172
|
-
if (val === null || typeof val !== "object" || Array.isArray(val)) {
|
|
173
|
-
throw new Error(`${op}() takes an object of properties`);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
const validateDocumentId = (op, id) => {
|
|
177
|
-
if (typeof id !== "string" || !/^[a-z0-9_][a-z0-9_.-]{0,127}$/i.test(id) || id.includes("..")) {
|
|
178
|
-
throw new Error(`${op}(): "${id}" is not a valid document ID`);
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
const requireDocumentId = (op, doc) => {
|
|
182
|
-
if (!doc._id) {
|
|
183
|
-
throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
|
|
184
|
-
}
|
|
185
|
-
validateDocumentId(op, doc._id);
|
|
186
|
-
};
|
|
187
|
-
const validateInsert = (at, selector, items) => {
|
|
188
|
-
const signature = "insert(at, selector, items)";
|
|
189
|
-
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
190
|
-
const valid = VALID_INSERT_LOCATIONS.map((loc) => `"${loc}"`).join(", ");
|
|
191
|
-
throw new Error(`${signature} takes an "at"-argument which is one of: ${valid}`);
|
|
192
|
-
}
|
|
193
|
-
if (typeof selector !== "string") {
|
|
194
|
-
throw new Error(`${signature} takes a "selector"-argument which must be a string`);
|
|
195
|
-
}
|
|
196
|
-
if (!Array.isArray(items)) {
|
|
197
|
-
throw new Error(`${signature} takes an "items"-argument which must be an array`);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
const hasDataset = (config) => {
|
|
201
|
-
if (!config.dataset) {
|
|
202
|
-
throw new Error("`dataset` must be provided to perform queries");
|
|
203
|
-
}
|
|
204
|
-
return config.dataset || "";
|
|
205
|
-
};
|
|
206
|
-
const requestTag = (tag) => {
|
|
207
|
-
if (typeof tag !== "string" || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
|
|
208
|
-
throw new Error(
|
|
209
|
-
`Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.`
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
return tag;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
class BasePatch {
|
|
216
|
-
constructor(selection, operations = {}) {
|
|
217
|
-
this.selection = selection;
|
|
218
|
-
this.operations = operations;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Sets the given attributes to the document. Does NOT merge objects.
|
|
222
|
-
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
223
|
-
*
|
|
224
|
-
* @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
|
|
225
|
-
*/
|
|
226
|
-
set(attrs) {
|
|
227
|
-
return this._assign("set", attrs);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Sets the given attributes to the document if they are not currently set. Does NOT merge objects.
|
|
231
|
-
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
232
|
-
*
|
|
233
|
-
* @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
|
|
234
|
-
*/
|
|
235
|
-
setIfMissing(attrs) {
|
|
236
|
-
return this._assign("setIfMissing", attrs);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Performs a "diff-match-patch" operation on the string attributes provided.
|
|
240
|
-
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
241
|
-
*
|
|
242
|
-
* @param attrs - Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "dmp"\}
|
|
243
|
-
*/
|
|
244
|
-
diffMatchPatch(attrs) {
|
|
245
|
-
validateObject("diffMatchPatch", attrs);
|
|
246
|
-
return this._assign("diffMatchPatch", attrs);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Unsets the attribute paths provided.
|
|
250
|
-
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
251
|
-
*
|
|
252
|
-
* @param attrs - Attribute paths to unset.
|
|
253
|
-
*/
|
|
254
|
-
unset(attrs) {
|
|
255
|
-
if (!Array.isArray(attrs)) {
|
|
256
|
-
throw new Error("unset(attrs) takes an array of attributes to unset, non-array given");
|
|
257
|
-
}
|
|
258
|
-
this.operations = Object.assign({}, this.operations, { unset: attrs });
|
|
259
|
-
return this;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Increment a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
|
|
263
|
-
*
|
|
264
|
-
* @param attrs - Object of attribute paths to increment, values representing the number to increment by.
|
|
265
|
-
*/
|
|
266
|
-
inc(attrs) {
|
|
267
|
-
return this._assign("inc", attrs);
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Decrement a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
|
|
271
|
-
*
|
|
272
|
-
* @param attrs - Object of attribute paths to decrement, values representing the number to decrement by.
|
|
273
|
-
*/
|
|
274
|
-
dec(attrs) {
|
|
275
|
-
return this._assign("dec", attrs);
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Provides methods for modifying arrays, by inserting, appending and replacing elements via a JSONPath expression.
|
|
279
|
-
*
|
|
280
|
-
* @param at - Location to insert at, relative to the given selector, or 'replace' the matched path
|
|
281
|
-
* @param selector - JSONPath expression, eg `comments[-1]` or `blocks[_key=="abc123"]`
|
|
282
|
-
* @param items - Array of items to insert/replace
|
|
283
|
-
*/
|
|
284
|
-
insert(at, selector, items) {
|
|
285
|
-
validateInsert(at, selector, items);
|
|
286
|
-
return this._assign("insert", { [at]: selector, items });
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Append the given items to the array at the given JSONPath
|
|
290
|
-
*
|
|
291
|
-
* @param selector - Attribute/path to append to, eg `comments` or `person.hobbies`
|
|
292
|
-
* @param items - Array of items to append to the array
|
|
293
|
-
*/
|
|
294
|
-
append(selector, items) {
|
|
295
|
-
return this.insert("after", `${selector}[-1]`, items);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Prepend the given items to the array at the given JSONPath
|
|
299
|
-
*
|
|
300
|
-
* @param selector - Attribute/path to prepend to, eg `comments` or `person.hobbies`
|
|
301
|
-
* @param items - Array of items to prepend to the array
|
|
302
|
-
*/
|
|
303
|
-
prepend(selector, items) {
|
|
304
|
-
return this.insert("before", `${selector}[0]`, items);
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Change the contents of an array by removing existing elements and/or adding new elements.
|
|
308
|
-
*
|
|
309
|
-
* @param selector - Attribute or JSONPath expression for array
|
|
310
|
-
* @param start - Index at which to start changing the array (with origin 0). If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end of the array (with origin -1) and will be set to 0 if absolute value is greater than the length of the array.x
|
|
311
|
-
* @param deleteCount - An integer indicating the number of old array elements to remove.
|
|
312
|
-
* @param items - The elements to add to the array, beginning at the start index. If you don't specify any elements, splice() will only remove elements from the array.
|
|
313
|
-
*/
|
|
314
|
-
splice(selector, start, deleteCount, items) {
|
|
315
|
-
const delAll = typeof deleteCount === "undefined" || deleteCount === -1;
|
|
316
|
-
const startIndex = start < 0 ? start - 1 : start;
|
|
317
|
-
const delCount = delAll ? -1 : Math.max(0, start + deleteCount);
|
|
318
|
-
const delRange = startIndex < 0 && delCount >= 0 ? "" : delCount;
|
|
319
|
-
const rangeSelector = `${selector}[${startIndex}:${delRange}]`;
|
|
320
|
-
return this.insert("replace", rangeSelector, items || []);
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Adds a revision clause, preventing the document from being patched if the `_rev` property does not match the given value
|
|
324
|
-
*
|
|
325
|
-
* @param rev - Revision to lock the patch to
|
|
326
|
-
*/
|
|
327
|
-
ifRevisionId(rev) {
|
|
328
|
-
this.operations.ifRevisionID = rev;
|
|
329
|
-
return this;
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Return a plain JSON representation of the patch
|
|
333
|
-
*/
|
|
334
|
-
serialize() {
|
|
335
|
-
return { ...getSelection(this.selection), ...this.operations };
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Return a plain JSON representation of the patch
|
|
339
|
-
*/
|
|
340
|
-
toJSON() {
|
|
341
|
-
return this.serialize();
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Clears the patch of all operations
|
|
345
|
-
*/
|
|
346
|
-
reset() {
|
|
347
|
-
this.operations = {};
|
|
348
|
-
return this;
|
|
349
|
-
}
|
|
350
|
-
_assign(op, props, merge = true) {
|
|
351
|
-
validateObject(op, props);
|
|
352
|
-
this.operations = Object.assign({}, this.operations, {
|
|
353
|
-
[op]: Object.assign({}, merge && this.operations[op] || {}, props)
|
|
354
|
-
});
|
|
355
|
-
return this;
|
|
356
|
-
}
|
|
357
|
-
_set(op, props) {
|
|
358
|
-
return this._assign(op, props, false);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
class ObservablePatch extends BasePatch {
|
|
362
|
-
#client;
|
|
363
|
-
constructor(selection, operations, client) {
|
|
364
|
-
super(selection, operations);
|
|
365
|
-
this.#client = client;
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Clones the patch
|
|
369
|
-
*/
|
|
370
|
-
clone() {
|
|
371
|
-
return new ObservablePatch(this.selection, { ...this.operations }, this.#client);
|
|
372
|
-
}
|
|
373
|
-
commit(options) {
|
|
374
|
-
if (!this.#client) {
|
|
375
|
-
throw new Error(
|
|
376
|
-
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
const returnFirst = typeof this.selection === "string";
|
|
380
|
-
const opts = Object.assign({ returnFirst, returnDocuments: true }, options);
|
|
381
|
-
return this.#client.mutate({ patch: this.serialize() }, opts);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
class Patch extends BasePatch {
|
|
385
|
-
#client;
|
|
386
|
-
constructor(selection, operations, client) {
|
|
387
|
-
super(selection, operations);
|
|
388
|
-
this.#client = client;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Clones the patch
|
|
392
|
-
*/
|
|
393
|
-
clone() {
|
|
394
|
-
return new Patch(this.selection, { ...this.operations }, this.#client);
|
|
395
|
-
}
|
|
396
|
-
commit(options) {
|
|
397
|
-
if (!this.#client) {
|
|
398
|
-
throw new Error(
|
|
399
|
-
"No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method"
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
const returnFirst = typeof this.selection === "string";
|
|
403
|
-
const opts = Object.assign({ returnFirst, returnDocuments: true }, options);
|
|
404
|
-
return this.#client.mutate({ patch: this.serialize() }, opts);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const defaultMutateOptions = { returnDocuments: false };
|
|
409
|
-
class BaseTransaction {
|
|
410
|
-
constructor(operations = [], transactionId) {
|
|
411
|
-
this.operations = operations;
|
|
412
|
-
this.trxId = transactionId;
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Creates a new Sanity document. If `_id` is provided and already exists, the mutation will fail. If no `_id` is given, one will automatically be generated by the database.
|
|
416
|
-
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
417
|
-
*
|
|
418
|
-
* @param doc - Document to create. Requires a `_type` property.
|
|
419
|
-
*/
|
|
420
|
-
create(doc) {
|
|
421
|
-
validateObject("create", doc);
|
|
422
|
-
return this._add({ create: doc });
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
|
|
426
|
-
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
427
|
-
*
|
|
428
|
-
* @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
|
|
429
|
-
*/
|
|
430
|
-
createIfNotExists(doc) {
|
|
431
|
-
const op = "createIfNotExists";
|
|
432
|
-
validateObject(op, doc);
|
|
433
|
-
requireDocumentId(op, doc);
|
|
434
|
-
return this._add({ [op]: doc });
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
|
|
438
|
-
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
439
|
-
*
|
|
440
|
-
* @param doc - Document to create or replace. Requires `_id` and `_type` properties.
|
|
441
|
-
*/
|
|
442
|
-
createOrReplace(doc) {
|
|
443
|
-
const op = "createOrReplace";
|
|
444
|
-
validateObject(op, doc);
|
|
445
|
-
requireDocumentId(op, doc);
|
|
446
|
-
return this._add({ [op]: doc });
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Deletes the document with the given document ID
|
|
450
|
-
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
451
|
-
*
|
|
452
|
-
* @param documentId - Document ID to delete
|
|
453
|
-
*/
|
|
454
|
-
delete(documentId) {
|
|
455
|
-
validateDocumentId("delete", documentId);
|
|
456
|
-
return this._add({ delete: { id: documentId } });
|
|
457
|
-
}
|
|
458
|
-
transactionId(id) {
|
|
459
|
-
if (!id) {
|
|
460
|
-
return this.trxId;
|
|
461
|
-
}
|
|
462
|
-
this.trxId = id;
|
|
463
|
-
return this;
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Return a plain JSON representation of the transaction
|
|
467
|
-
*/
|
|
468
|
-
serialize() {
|
|
469
|
-
return [...this.operations];
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Return a plain JSON representation of the transaction
|
|
473
|
-
*/
|
|
474
|
-
toJSON() {
|
|
475
|
-
return this.serialize();
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Clears the transaction of all operations
|
|
479
|
-
*/
|
|
480
|
-
reset() {
|
|
481
|
-
this.operations = [];
|
|
482
|
-
return this;
|
|
483
|
-
}
|
|
484
|
-
_add(mut) {
|
|
485
|
-
this.operations.push(mut);
|
|
486
|
-
return this;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
class Transaction extends BaseTransaction {
|
|
490
|
-
#client;
|
|
491
|
-
constructor(operations, client, transactionId) {
|
|
492
|
-
super(operations, transactionId);
|
|
493
|
-
this.#client = client;
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Clones the transaction
|
|
497
|
-
*/
|
|
498
|
-
clone() {
|
|
499
|
-
return new Transaction([...this.operations], this.#client, this.trxId);
|
|
500
|
-
}
|
|
501
|
-
commit(options) {
|
|
502
|
-
if (!this.#client) {
|
|
503
|
-
throw new Error(
|
|
504
|
-
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
return this.#client.mutate(
|
|
508
|
-
this.serialize(),
|
|
509
|
-
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
510
|
-
);
|
|
511
|
-
}
|
|
512
|
-
patch(patchOrDocumentId, patchOps) {
|
|
513
|
-
const isBuilder = typeof patchOps === "function";
|
|
514
|
-
const isPatch = typeof patchOrDocumentId !== "string" && patchOrDocumentId instanceof Patch;
|
|
515
|
-
if (isPatch) {
|
|
516
|
-
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
517
|
-
}
|
|
518
|
-
if (isBuilder) {
|
|
519
|
-
const patch = patchOps(new Patch(patchOrDocumentId, {}, this.#client));
|
|
520
|
-
if (!(patch instanceof Patch)) {
|
|
521
|
-
throw new Error("function passed to `patch()` must return the patch");
|
|
522
|
-
}
|
|
523
|
-
return this._add({ patch: patch.serialize() });
|
|
524
|
-
}
|
|
525
|
-
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
class ObservableTransaction extends BaseTransaction {
|
|
529
|
-
#client;
|
|
530
|
-
constructor(operations, client, transactionId) {
|
|
531
|
-
super(operations, transactionId);
|
|
532
|
-
this.#client = client;
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Clones the transaction
|
|
536
|
-
*/
|
|
537
|
-
clone() {
|
|
538
|
-
return new ObservableTransaction([...this.operations], this.#client, this.trxId);
|
|
539
|
-
}
|
|
540
|
-
commit(options) {
|
|
541
|
-
if (!this.#client) {
|
|
542
|
-
throw new Error(
|
|
543
|
-
"No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method"
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
return this.#client.mutate(
|
|
547
|
-
this.serialize(),
|
|
548
|
-
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
549
|
-
);
|
|
550
|
-
}
|
|
551
|
-
patch(patchOrDocumentId, patchOps) {
|
|
552
|
-
const isBuilder = typeof patchOps === "function";
|
|
553
|
-
const isPatch = typeof patchOrDocumentId !== "string" && patchOrDocumentId instanceof ObservablePatch;
|
|
554
|
-
if (isPatch) {
|
|
555
|
-
return this._add({ patch: patchOrDocumentId.serialize() });
|
|
556
|
-
}
|
|
557
|
-
if (isBuilder) {
|
|
558
|
-
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, this.#client));
|
|
559
|
-
if (!(patch instanceof ObservablePatch)) {
|
|
560
|
-
throw new Error("function passed to `patch()` must return the patch");
|
|
561
|
-
}
|
|
562
|
-
return this._add({ patch: patch.serialize() });
|
|
563
|
-
}
|
|
564
|
-
return this._add({ patch: { id: patchOrDocumentId, ...patchOps } });
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
const BASE_URL = "https://www.sanity.io/help/";
|
|
569
|
-
function generateHelpUrl(slug) {
|
|
570
|
-
return BASE_URL + slug;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
function once(fn) {
|
|
574
|
-
let didCall = false;
|
|
575
|
-
let returnValue;
|
|
576
|
-
return (...args) => {
|
|
577
|
-
if (didCall) {
|
|
578
|
-
return returnValue;
|
|
579
|
-
}
|
|
580
|
-
returnValue = fn(...args);
|
|
581
|
-
didCall = true;
|
|
582
|
-
return returnValue;
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
const createWarningPrinter = (message) => (
|
|
587
|
-
// eslint-disable-next-line no-console
|
|
588
|
-
once((...args) => console.warn(message.join(" "), ...args))
|
|
589
|
-
);
|
|
590
|
-
const printCdnWarning = createWarningPrinter([
|
|
591
|
-
`Since you haven't set a value for \`useCdn\`, we will deliver content using our`,
|
|
592
|
-
`global, edge-cached API-CDN. If you wish to have content delivered faster, set`,
|
|
593
|
-
`\`useCdn: false\` to use the Live API. Note: You may incur higher costs using the live API.`
|
|
594
|
-
]);
|
|
595
|
-
const printCdnPreviewDraftsWarning = createWarningPrinter([
|
|
596
|
-
`The Sanity client is configured with the \`perspective\` set to \`previewDrafts\`, which doesn't support the API-CDN.`,
|
|
597
|
-
`The Live API will be used instead. Set \`useCdn: false\` in your configuration to hide this warning.`
|
|
598
|
-
]);
|
|
599
|
-
const printBrowserTokenWarning = createWarningPrinter([
|
|
600
|
-
"You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
|
|
601
|
-
`See ${generateHelpUrl(
|
|
602
|
-
"js-client-browser-token"
|
|
603
|
-
)} for more information and how to hide this warning.`
|
|
604
|
-
]);
|
|
605
|
-
const printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
606
|
-
"Using the Sanity client without specifying an API version is deprecated.",
|
|
607
|
-
`See ${generateHelpUrl("js-client-api-version")}`
|
|
608
|
-
]);
|
|
609
|
-
const printNoDefaultExport = createWarningPrinter([
|
|
610
|
-
"The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."
|
|
611
|
-
]);
|
|
612
|
-
|
|
613
|
-
const defaultCdnHost = "apicdn.sanity.io";
|
|
614
|
-
const defaultConfig = {
|
|
615
|
-
apiHost: "https://api.sanity.io",
|
|
616
|
-
apiVersion: "1",
|
|
617
|
-
useProjectHostname: true,
|
|
618
|
-
stega: { enabled: false }
|
|
619
|
-
};
|
|
620
|
-
const LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
|
|
621
|
-
const isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
622
|
-
const validateApiVersion = function validateApiVersion2(apiVersion) {
|
|
623
|
-
if (apiVersion === "1" || apiVersion === "X") {
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
const apiDate = new Date(apiVersion);
|
|
627
|
-
const apiVersionValid = /^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0;
|
|
628
|
-
if (!apiVersionValid) {
|
|
629
|
-
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
const validateApiPerspective = function validateApiPerspective2(perspective) {
|
|
633
|
-
switch (perspective) {
|
|
634
|
-
case "previewDrafts":
|
|
635
|
-
case "published":
|
|
636
|
-
case "raw":
|
|
637
|
-
return;
|
|
638
|
-
default:
|
|
639
|
-
throw new TypeError(
|
|
640
|
-
"Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
|
|
641
|
-
);
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
const initConfig = (config, prevConfig) => {
|
|
645
|
-
const specifiedConfig = {
|
|
646
|
-
...prevConfig,
|
|
647
|
-
...config,
|
|
648
|
-
stega: {
|
|
649
|
-
...typeof prevConfig.stega === "boolean" ? { enabled: prevConfig.stega } : prevConfig.stega || defaultConfig.stega,
|
|
650
|
-
...typeof config.stega === "boolean" ? { enabled: config.stega } : config.stega || {}
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
|
-
if (!specifiedConfig.apiVersion) {
|
|
654
|
-
printNoApiVersionSpecifiedWarning();
|
|
655
|
-
}
|
|
656
|
-
const newConfig = {
|
|
657
|
-
...defaultConfig,
|
|
658
|
-
...specifiedConfig
|
|
659
|
-
};
|
|
660
|
-
const projectBased = newConfig.useProjectHostname;
|
|
661
|
-
if (typeof Promise === "undefined") {
|
|
662
|
-
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
663
|
-
throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`);
|
|
664
|
-
}
|
|
665
|
-
if (projectBased && !newConfig.projectId) {
|
|
666
|
-
throw new Error("Configuration must contain `projectId`");
|
|
667
|
-
}
|
|
668
|
-
if (typeof newConfig.perspective === "string") {
|
|
669
|
-
validateApiPerspective(newConfig.perspective);
|
|
670
|
-
}
|
|
671
|
-
if ("encodeSourceMap" in newConfig) {
|
|
672
|
-
throw new Error(
|
|
673
|
-
`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'?`
|
|
674
|
-
);
|
|
675
|
-
}
|
|
676
|
-
if ("encodeSourceMapAtPath" in newConfig) {
|
|
677
|
-
throw new Error(
|
|
678
|
-
`It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client'. Did you mean 'stega.filter'?`
|
|
679
|
-
);
|
|
680
|
-
}
|
|
681
|
-
if (typeof newConfig.stega.enabled !== "boolean") {
|
|
682
|
-
throw new Error(`stega.enabled must be a boolean, received ${newConfig.stega.enabled}`);
|
|
683
|
-
}
|
|
684
|
-
if (newConfig.stega.enabled && newConfig.stega.studioUrl === void 0) {
|
|
685
|
-
throw new Error(`stega.studioUrl must be defined when stega.enabled is true`);
|
|
686
|
-
}
|
|
687
|
-
if (newConfig.stega.enabled && typeof newConfig.stega.studioUrl !== "string" && typeof newConfig.stega.studioUrl !== "function") {
|
|
688
|
-
throw new Error(
|
|
689
|
-
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
const isBrowser = typeof window !== "undefined" && window.location && window.location.hostname;
|
|
693
|
-
const isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
694
|
-
if (isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true) {
|
|
695
|
-
printBrowserTokenWarning();
|
|
696
|
-
} else if (typeof newConfig.useCdn === "undefined") {
|
|
697
|
-
printCdnWarning();
|
|
698
|
-
}
|
|
699
|
-
if (projectBased) {
|
|
700
|
-
projectId(newConfig.projectId);
|
|
701
|
-
}
|
|
702
|
-
if (newConfig.dataset) {
|
|
703
|
-
dataset(newConfig.dataset);
|
|
704
|
-
}
|
|
705
|
-
if ("requestTagPrefix" in newConfig) {
|
|
706
|
-
newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0;
|
|
707
|
-
}
|
|
708
|
-
newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, "");
|
|
709
|
-
newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
|
|
710
|
-
newConfig.useCdn = newConfig.useCdn !== false && !newConfig.withCredentials;
|
|
711
|
-
validateApiVersion(newConfig.apiVersion);
|
|
712
|
-
const hostParts = newConfig.apiHost.split("://", 2);
|
|
713
|
-
const protocol = hostParts[0];
|
|
714
|
-
const host = hostParts[1];
|
|
715
|
-
const cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
716
|
-
if (newConfig.useProjectHostname) {
|
|
717
|
-
newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`;
|
|
718
|
-
newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`;
|
|
719
|
-
} else {
|
|
720
|
-
newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`;
|
|
721
|
-
newConfig.cdnUrl = newConfig.url;
|
|
722
|
-
}
|
|
723
|
-
return newConfig;
|
|
724
|
-
};
|
|
725
|
-
|
|
726
|
-
const projectHeader = "X-Sanity-Project-ID";
|
|
727
|
-
function requestOptions(config, overrides = {}) {
|
|
728
|
-
const headers = {};
|
|
729
|
-
const token = overrides.token || config.token;
|
|
730
|
-
if (token) {
|
|
731
|
-
headers.Authorization = `Bearer ${token}`;
|
|
732
|
-
}
|
|
733
|
-
if (!overrides.useGlobalApi && !config.useProjectHostname && config.projectId) {
|
|
734
|
-
headers[projectHeader] = config.projectId;
|
|
735
|
-
}
|
|
736
|
-
const withCredentials = Boolean(
|
|
737
|
-
typeof overrides.withCredentials === "undefined" ? config.token || config.withCredentials : overrides.withCredentials
|
|
738
|
-
);
|
|
739
|
-
const timeout = typeof overrides.timeout === "undefined" ? config.timeout : overrides.timeout;
|
|
740
|
-
return Object.assign({}, overrides, {
|
|
741
|
-
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
742
|
-
timeout: typeof timeout === "undefined" ? 5 * 60 * 1e3 : timeout,
|
|
743
|
-
proxy: overrides.proxy || config.proxy,
|
|
744
|
-
json: true,
|
|
745
|
-
withCredentials,
|
|
746
|
-
fetch: typeof overrides.fetch === "object" && typeof config.fetch === "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
var s={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},c={0:8203,1:8204,2:8205,3:65279},d=new Array(4).fill(String.fromCodePoint(c[0])).join("");function E(t){let e=JSON.stringify(t);return `${d}${Array.from(e).map(r=>{let n=r.charCodeAt(0);if(n>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);return Array.from(n.toString(4).padStart(4,"0")).map(o=>String.fromCodePoint(c[o])).join("")}).join("")}`}function I(t){return Number.isNaN(Number(t))?Boolean(Date.parse(t)):!1}function x(t){try{new URL(t,t.startsWith("/")?"https://acme.com":void 0);}catch{return !1}return !0}function b(t,e,r="auto"){return r===!0||r==="auto"&&(I(t)||x(t))?t:`${t}${E(e)}`}Object.fromEntries(Object.entries(c).map(t=>t.reverse()));Object.fromEntries(Object.entries(s).map(t=>t.reverse()));var S=`${Object.values(s).map(t=>`\\u{${t.toString(16)}}`).join("")}`,f=new RegExp(`[${S}]{4,}`,"gu");function X(t){var e;return {cleaned:t.replace(f,""),encoded:((e=t.match(f))==null?void 0:e[0])||""}}
|
|
751
|
-
|
|
752
|
-
function vercelStegaCleanAll(result) {
|
|
753
|
-
try {
|
|
754
|
-
return JSON.parse(
|
|
755
|
-
JSON.stringify(result, (key, value) => {
|
|
756
|
-
if (typeof value !== "string")
|
|
757
|
-
return value;
|
|
758
|
-
return X(value).cleaned;
|
|
759
|
-
})
|
|
760
|
-
);
|
|
761
|
-
} catch {
|
|
762
|
-
return result;
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
const encodeQueryString = ({
|
|
767
|
-
query,
|
|
768
|
-
params = {},
|
|
769
|
-
options = {}
|
|
770
|
-
}) => {
|
|
771
|
-
const searchParams = new URLSearchParams();
|
|
772
|
-
const { tag, returnQuery, ...opts } = options;
|
|
773
|
-
if (tag)
|
|
774
|
-
searchParams.append("tag", tag);
|
|
775
|
-
searchParams.append("query", query);
|
|
776
|
-
for (const [key, value] of Object.entries(params)) {
|
|
777
|
-
searchParams.append(`$${key}`, JSON.stringify(value));
|
|
778
|
-
}
|
|
779
|
-
for (const [key, value] of Object.entries(opts)) {
|
|
780
|
-
if (value)
|
|
781
|
-
searchParams.append(key, `${value}`);
|
|
782
|
-
}
|
|
783
|
-
if (returnQuery === false)
|
|
784
|
-
searchParams.append("returnQuery", "false");
|
|
785
|
-
return `?${searchParams}`;
|
|
786
|
-
};
|
|
787
|
-
|
|
788
|
-
const excludeFalsey = (param, defValue) => {
|
|
789
|
-
const value = typeof param === "undefined" ? defValue : param;
|
|
790
|
-
return param === false ? void 0 : value;
|
|
791
|
-
};
|
|
792
|
-
const getMutationQuery = (options = {}) => {
|
|
793
|
-
return {
|
|
794
|
-
dryRun: options.dryRun,
|
|
795
|
-
returnIds: true,
|
|
796
|
-
returnDocuments: excludeFalsey(options.returnDocuments, true),
|
|
797
|
-
visibility: options.visibility || "sync",
|
|
798
|
-
autoGenerateArrayKeys: options.autoGenerateArrayKeys,
|
|
799
|
-
skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
|
|
800
|
-
};
|
|
801
|
-
};
|
|
802
|
-
const isResponse = (event) => event.type === "response";
|
|
803
|
-
const getBody = (event) => event.body;
|
|
804
|
-
const indexBy = (docs, attr) => docs.reduce((indexed, doc) => {
|
|
805
|
-
indexed[attr(doc)] = doc;
|
|
806
|
-
return indexed;
|
|
807
|
-
}, /* @__PURE__ */ Object.create(null));
|
|
808
|
-
const getQuerySizeLimit = 11264;
|
|
809
|
-
function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
810
|
-
const stega = "stega" in options ? {
|
|
811
|
-
..._stega || {},
|
|
812
|
-
...typeof options.stega === "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
813
|
-
} : _stega;
|
|
814
|
-
const params = stega.enabled ? vercelStegaCleanAll(_params) : _params;
|
|
815
|
-
const mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result;
|
|
816
|
-
const { cache, next, ...opts } = {
|
|
817
|
-
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
818
|
-
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
819
|
-
useAbortSignal: typeof options.signal !== "undefined",
|
|
820
|
-
// Set `resultSourceMap' when stega is enabled, as it's required for encoding.
|
|
821
|
-
resultSourceMap: stega.enabled ? "withKeyArraySelector" : options.resultSourceMap,
|
|
822
|
-
...options,
|
|
823
|
-
// Default to not returning the query, unless `filterResponse` is `false`,
|
|
824
|
-
// or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
|
|
825
|
-
returnQuery: options.filterResponse === false && options.returnQuery !== false
|
|
826
|
-
};
|
|
827
|
-
const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? { ...opts, fetch: { cache, next } } : opts;
|
|
828
|
-
const $request = _dataRequest(client, httpRequest, "query", { query, params }, reqOpts);
|
|
829
|
-
return stega.enabled ? $request.pipe(
|
|
830
|
-
operators.combineLatestWith(
|
|
831
|
-
rxjs.from(
|
|
832
|
-
Promise.resolve().then(function () { return require('./stegaEncodeSourceMap-DIcuvN0P.cjs'); }).then(function (n) { return n.stegaEncodeSourceMap$1; }).then(
|
|
833
|
-
({ stegaEncodeSourceMap }) => stegaEncodeSourceMap
|
|
834
|
-
)
|
|
835
|
-
)
|
|
836
|
-
),
|
|
837
|
-
operators.map(
|
|
838
|
-
([res, stegaEncodeSourceMap]) => {
|
|
839
|
-
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
|
|
840
|
-
return mapResponse({ ...res, result });
|
|
841
|
-
}
|
|
842
|
-
)
|
|
843
|
-
) : $request.pipe(operators.map(mapResponse));
|
|
844
|
-
}
|
|
845
|
-
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
846
|
-
const options = { uri: _getDataUrl(client, "doc", id), json: true, tag: opts.tag };
|
|
847
|
-
return _requestObservable(client, httpRequest, options).pipe(
|
|
848
|
-
operators.filter(isResponse),
|
|
849
|
-
operators.map((event) => event.body.documents && event.body.documents[0])
|
|
850
|
-
);
|
|
851
|
-
}
|
|
852
|
-
function _getDocuments(client, httpRequest, ids, opts = {}) {
|
|
853
|
-
const options = { uri: _getDataUrl(client, "doc", ids.join(",")), json: true, tag: opts.tag };
|
|
854
|
-
return _requestObservable(client, httpRequest, options).pipe(
|
|
855
|
-
operators.filter(isResponse),
|
|
856
|
-
operators.map((event) => {
|
|
857
|
-
const indexed = indexBy(event.body.documents || [], (doc) => doc._id);
|
|
858
|
-
return ids.map((id) => indexed[id] || null);
|
|
859
|
-
})
|
|
860
|
-
);
|
|
861
|
-
}
|
|
862
|
-
function _createIfNotExists(client, httpRequest, doc, options) {
|
|
863
|
-
requireDocumentId("createIfNotExists", doc);
|
|
864
|
-
return _create(client, httpRequest, doc, "createIfNotExists", options);
|
|
865
|
-
}
|
|
866
|
-
function _createOrReplace(client, httpRequest, doc, options) {
|
|
867
|
-
requireDocumentId("createOrReplace", doc);
|
|
868
|
-
return _create(client, httpRequest, doc, "createOrReplace", options);
|
|
869
|
-
}
|
|
870
|
-
function _delete(client, httpRequest, selection, options) {
|
|
871
|
-
return _dataRequest(
|
|
872
|
-
client,
|
|
873
|
-
httpRequest,
|
|
874
|
-
"mutate",
|
|
875
|
-
{ mutations: [{ delete: getSelection(selection) }] },
|
|
876
|
-
options
|
|
877
|
-
);
|
|
878
|
-
}
|
|
879
|
-
function _mutate(client, httpRequest, mutations, options) {
|
|
880
|
-
let mut;
|
|
881
|
-
if (mutations instanceof Patch || mutations instanceof ObservablePatch) {
|
|
882
|
-
mut = { patch: mutations.serialize() };
|
|
883
|
-
} else if (mutations instanceof Transaction || mutations instanceof ObservableTransaction) {
|
|
884
|
-
mut = mutations.serialize();
|
|
885
|
-
} else {
|
|
886
|
-
mut = mutations;
|
|
887
|
-
}
|
|
888
|
-
const muts = Array.isArray(mut) ? mut : [mut];
|
|
889
|
-
const transactionId = options && options.transactionId || void 0;
|
|
890
|
-
return _dataRequest(client, httpRequest, "mutate", { mutations: muts, transactionId }, options);
|
|
891
|
-
}
|
|
892
|
-
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
893
|
-
const isMutation = endpoint === "mutate";
|
|
894
|
-
const isQuery = endpoint === "query";
|
|
895
|
-
const strQuery = isMutation ? "" : encodeQueryString(body);
|
|
896
|
-
const useGet = !isMutation && strQuery.length < getQuerySizeLimit;
|
|
897
|
-
const stringQuery = useGet ? strQuery : "";
|
|
898
|
-
const returnFirst = options.returnFirst;
|
|
899
|
-
const { timeout, token, tag, headers, returnQuery } = options;
|
|
900
|
-
const uri = _getDataUrl(client, endpoint, stringQuery);
|
|
901
|
-
const reqOptions = {
|
|
902
|
-
method: useGet ? "GET" : "POST",
|
|
903
|
-
uri,
|
|
904
|
-
json: true,
|
|
905
|
-
body: useGet ? void 0 : body,
|
|
906
|
-
query: isMutation && getMutationQuery(options),
|
|
907
|
-
timeout,
|
|
908
|
-
headers,
|
|
909
|
-
token,
|
|
910
|
-
tag,
|
|
911
|
-
returnQuery,
|
|
912
|
-
perspective: options.perspective,
|
|
913
|
-
resultSourceMap: options.resultSourceMap,
|
|
914
|
-
canUseCdn: isQuery,
|
|
915
|
-
signal: options.signal,
|
|
916
|
-
fetch: options.fetch,
|
|
917
|
-
useAbortSignal: options.useAbortSignal,
|
|
918
|
-
useCdn: options.useCdn
|
|
919
|
-
};
|
|
920
|
-
return _requestObservable(client, httpRequest, reqOptions).pipe(
|
|
921
|
-
operators.filter(isResponse),
|
|
922
|
-
operators.map(getBody),
|
|
923
|
-
operators.map((res) => {
|
|
924
|
-
if (!isMutation) {
|
|
925
|
-
return res;
|
|
926
|
-
}
|
|
927
|
-
const results = res.results || [];
|
|
928
|
-
if (options.returnDocuments) {
|
|
929
|
-
return returnFirst ? results[0] && results[0].document : results.map((mut) => mut.document);
|
|
930
|
-
}
|
|
931
|
-
const key = returnFirst ? "documentId" : "documentIds";
|
|
932
|
-
const ids = returnFirst ? results[0] && results[0].id : results.map((mut) => mut.id);
|
|
933
|
-
return {
|
|
934
|
-
transactionId: res.transactionId,
|
|
935
|
-
results,
|
|
936
|
-
[key]: ids
|
|
937
|
-
};
|
|
938
|
-
})
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
function _create(client, httpRequest, doc, op, options = {}) {
|
|
942
|
-
const mutation = { [op]: doc };
|
|
943
|
-
const opts = Object.assign({ returnFirst: true, returnDocuments: true }, options);
|
|
944
|
-
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
945
|
-
}
|
|
946
|
-
function _requestObservable(client, httpRequest, options) {
|
|
947
|
-
const uri = options.url || options.uri;
|
|
948
|
-
const config = client.config();
|
|
949
|
-
const canUseCdn = typeof options.canUseCdn === "undefined" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
|
|
950
|
-
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
951
|
-
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
952
|
-
if (tag && options.tag !== null) {
|
|
953
|
-
options.query = { tag: requestTag(tag), ...options.query };
|
|
954
|
-
}
|
|
955
|
-
if (["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
956
|
-
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
957
|
-
if (resultSourceMap !== void 0 && resultSourceMap !== false) {
|
|
958
|
-
options.query = { resultSourceMap, ...options.query };
|
|
959
|
-
}
|
|
960
|
-
const perspective = options.perspective || config.perspective;
|
|
961
|
-
if (typeof perspective === "string" && perspective !== "raw") {
|
|
962
|
-
validateApiPerspective(perspective);
|
|
963
|
-
options.query = { perspective, ...options.query };
|
|
964
|
-
if (perspective === "previewDrafts" && useCdn) {
|
|
965
|
-
useCdn = false;
|
|
966
|
-
printCdnPreviewDraftsWarning();
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
if (options.returnQuery === false) {
|
|
970
|
-
options.query = { returnQuery: "false", ...options.query };
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
const reqOptions = requestOptions(
|
|
974
|
-
config,
|
|
975
|
-
Object.assign({}, options, {
|
|
976
|
-
url: _getUrl(client, uri, useCdn)
|
|
977
|
-
})
|
|
978
|
-
);
|
|
979
|
-
const request = new rxjs.Observable(
|
|
980
|
-
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
981
|
-
);
|
|
982
|
-
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
983
|
-
}
|
|
984
|
-
function _request(client, httpRequest, options) {
|
|
985
|
-
const observable = _requestObservable(client, httpRequest, options).pipe(
|
|
986
|
-
operators.filter((event) => event.type === "response"),
|
|
987
|
-
operators.map((event) => event.body)
|
|
988
|
-
);
|
|
989
|
-
return observable;
|
|
990
|
-
}
|
|
991
|
-
function _getDataUrl(client, operation, path) {
|
|
992
|
-
const config = client.config();
|
|
993
|
-
const catalog = hasDataset(config);
|
|
994
|
-
const baseUri = `/${operation}/${catalog}`;
|
|
995
|
-
const uri = path ? `${baseUri}/${path}` : baseUri;
|
|
996
|
-
return `/data${uri}`.replace(/\/($|\?)/, "$1");
|
|
997
|
-
}
|
|
998
|
-
function _getUrl(client, uri, canUseCdn = false) {
|
|
999
|
-
const { url, cdnUrl } = client.config();
|
|
1000
|
-
const base = canUseCdn ? cdnUrl : url;
|
|
1001
|
-
return `${base}/${uri.replace(/^\//, "")}`;
|
|
1002
|
-
}
|
|
1003
|
-
function _withAbortSignal(signal) {
|
|
1004
|
-
return (input) => {
|
|
1005
|
-
return new rxjs.Observable((observer) => {
|
|
1006
|
-
const abort = () => observer.error(_createAbortError(signal));
|
|
1007
|
-
if (signal && signal.aborted) {
|
|
1008
|
-
abort();
|
|
1009
|
-
return;
|
|
1010
|
-
}
|
|
1011
|
-
const subscription = input.subscribe(observer);
|
|
1012
|
-
signal.addEventListener("abort", abort);
|
|
1013
|
-
return () => {
|
|
1014
|
-
signal.removeEventListener("abort", abort);
|
|
1015
|
-
subscription.unsubscribe();
|
|
1016
|
-
};
|
|
1017
|
-
});
|
|
1018
|
-
};
|
|
1019
|
-
}
|
|
1020
|
-
const isDomExceptionSupported = Boolean(globalThis.DOMException);
|
|
1021
|
-
function _createAbortError(signal) {
|
|
1022
|
-
if (isDomExceptionSupported) {
|
|
1023
|
-
return new DOMException((signal == null ? void 0 : signal.reason) ?? "The operation was aborted.", "AbortError");
|
|
1024
|
-
}
|
|
1025
|
-
const error = new Error((signal == null ? void 0 : signal.reason) ?? "The operation was aborted.");
|
|
1026
|
-
error.name = "AbortError";
|
|
1027
|
-
return error;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
class ObservableAssetsClient {
|
|
1031
|
-
#client;
|
|
1032
|
-
#httpRequest;
|
|
1033
|
-
constructor(client, httpRequest) {
|
|
1034
|
-
this.#client = client;
|
|
1035
|
-
this.#httpRequest = httpRequest;
|
|
1036
|
-
}
|
|
1037
|
-
upload(assetType, body, options) {
|
|
1038
|
-
return _upload(this.#client, this.#httpRequest, assetType, body, options);
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
class AssetsClient {
|
|
1042
|
-
#client;
|
|
1043
|
-
#httpRequest;
|
|
1044
|
-
constructor(client, httpRequest) {
|
|
1045
|
-
this.#client = client;
|
|
1046
|
-
this.#httpRequest = httpRequest;
|
|
1047
|
-
}
|
|
1048
|
-
upload(assetType, body, options) {
|
|
1049
|
-
const observable = _upload(this.#client, this.#httpRequest, assetType, body, options);
|
|
1050
|
-
return rxjs.lastValueFrom(
|
|
1051
|
-
observable.pipe(
|
|
1052
|
-
operators.filter((event) => event.type === "response"),
|
|
1053
|
-
operators.map(
|
|
1054
|
-
(event) => event.body.document
|
|
1055
|
-
)
|
|
1056
|
-
)
|
|
1057
|
-
);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
1061
|
-
validateAssetType(assetType);
|
|
1062
|
-
let meta = opts.extract || void 0;
|
|
1063
|
-
if (meta && !meta.length) {
|
|
1064
|
-
meta = ["none"];
|
|
1065
|
-
}
|
|
1066
|
-
const dataset = hasDataset(client.config());
|
|
1067
|
-
const assetEndpoint = assetType === "image" ? "images" : "files";
|
|
1068
|
-
const options = optionsFromFile(opts, body);
|
|
1069
|
-
const { tag, label, title, description, creditLine, filename, source } = options;
|
|
1070
|
-
const query = {
|
|
1071
|
-
label,
|
|
1072
|
-
title,
|
|
1073
|
-
description,
|
|
1074
|
-
filename,
|
|
1075
|
-
meta,
|
|
1076
|
-
creditLine
|
|
1077
|
-
};
|
|
1078
|
-
if (source) {
|
|
1079
|
-
query.sourceId = source.id;
|
|
1080
|
-
query.sourceName = source.name;
|
|
1081
|
-
query.sourceUrl = source.url;
|
|
1082
|
-
}
|
|
1083
|
-
return _requestObservable(client, httpRequest, {
|
|
1084
|
-
tag,
|
|
1085
|
-
method: "POST",
|
|
1086
|
-
timeout: options.timeout || 0,
|
|
1087
|
-
uri: `/assets/${assetEndpoint}/${dataset}`,
|
|
1088
|
-
headers: options.contentType ? { "Content-Type": options.contentType } : {},
|
|
1089
|
-
query,
|
|
1090
|
-
body
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
function optionsFromFile(opts, file) {
|
|
1094
|
-
if (typeof File === "undefined" || !(file instanceof File)) {
|
|
1095
|
-
return opts;
|
|
1096
|
-
}
|
|
1097
|
-
return Object.assign(
|
|
1098
|
-
{
|
|
1099
|
-
filename: opts.preserveFilename === false ? void 0 : file.name,
|
|
1100
|
-
contentType: file.type
|
|
1101
|
-
},
|
|
1102
|
-
opts
|
|
1103
|
-
);
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
var defaults = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj)).reduce((target, prop) => {
|
|
1107
|
-
target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
|
|
1108
|
-
return target;
|
|
1109
|
-
}, {});
|
|
1110
|
-
|
|
1111
|
-
const pick = (obj, props) => props.reduce((selection, prop) => {
|
|
1112
|
-
if (typeof obj[prop] === "undefined") {
|
|
1113
|
-
return selection;
|
|
1114
|
-
}
|
|
1115
|
-
selection[prop] = obj[prop];
|
|
1116
|
-
return selection;
|
|
1117
|
-
}, {});
|
|
1118
|
-
|
|
1119
|
-
const MAX_URL_LENGTH = 16e3 - 1200;
|
|
1120
|
-
const possibleOptions = [
|
|
1121
|
-
"includePreviousRevision",
|
|
1122
|
-
"includeResult",
|
|
1123
|
-
"visibility",
|
|
1124
|
-
"effectFormat",
|
|
1125
|
-
"tag"
|
|
1126
|
-
];
|
|
1127
|
-
const defaultOptions = {
|
|
1128
|
-
includeResult: true
|
|
1129
|
-
};
|
|
1130
|
-
function _listen(query, params, opts = {}) {
|
|
1131
|
-
const { url, token, withCredentials, requestTagPrefix } = this.config();
|
|
1132
|
-
const tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag;
|
|
1133
|
-
const options = { ...defaults(opts, defaultOptions), tag };
|
|
1134
|
-
const listenOpts = pick(options, possibleOptions);
|
|
1135
|
-
const qs = encodeQueryString({ query, params, options: { tag, ...listenOpts } });
|
|
1136
|
-
const uri = `${url}${_getDataUrl(this, "listen", qs)}`;
|
|
1137
|
-
if (uri.length > MAX_URL_LENGTH) {
|
|
1138
|
-
return new rxjs.Observable((observer) => observer.error(new Error("Query too large for listener")));
|
|
1139
|
-
}
|
|
1140
|
-
const listenFor = options.events ? options.events : ["mutation"];
|
|
1141
|
-
const shouldEmitReconnect = listenFor.indexOf("reconnect") !== -1;
|
|
1142
|
-
const esOptions = {};
|
|
1143
|
-
if (token || withCredentials) {
|
|
1144
|
-
esOptions.withCredentials = true;
|
|
1145
|
-
}
|
|
1146
|
-
if (token) {
|
|
1147
|
-
esOptions.headers = {
|
|
1148
|
-
Authorization: `Bearer ${token}`
|
|
1149
|
-
};
|
|
1150
|
-
}
|
|
1151
|
-
return new rxjs.Observable((observer) => {
|
|
1152
|
-
let es;
|
|
1153
|
-
getEventSource().then((eventSource) => {
|
|
1154
|
-
es = eventSource;
|
|
1155
|
-
}).catch((reason) => {
|
|
1156
|
-
observer.error(reason);
|
|
1157
|
-
stop();
|
|
1158
|
-
});
|
|
1159
|
-
let reconnectTimer;
|
|
1160
|
-
let stopped = false;
|
|
1161
|
-
function onError() {
|
|
1162
|
-
if (stopped) {
|
|
1163
|
-
return;
|
|
1164
|
-
}
|
|
1165
|
-
emitReconnect();
|
|
1166
|
-
if (stopped) {
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
if (es.readyState === es.CLOSED) {
|
|
1170
|
-
unsubscribe();
|
|
1171
|
-
clearTimeout(reconnectTimer);
|
|
1172
|
-
reconnectTimer = setTimeout(open, 100);
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
function onChannelError(err) {
|
|
1176
|
-
observer.error(cooerceError(err));
|
|
1177
|
-
}
|
|
1178
|
-
function onMessage(evt) {
|
|
1179
|
-
const event = parseEvent(evt);
|
|
1180
|
-
return event instanceof Error ? observer.error(event) : observer.next(event);
|
|
1181
|
-
}
|
|
1182
|
-
function onDisconnect() {
|
|
1183
|
-
stopped = true;
|
|
1184
|
-
unsubscribe();
|
|
1185
|
-
observer.complete();
|
|
1186
|
-
}
|
|
1187
|
-
function unsubscribe() {
|
|
1188
|
-
if (!es)
|
|
1189
|
-
return;
|
|
1190
|
-
es.removeEventListener("error", onError);
|
|
1191
|
-
es.removeEventListener("channelError", onChannelError);
|
|
1192
|
-
es.removeEventListener("disconnect", onDisconnect);
|
|
1193
|
-
listenFor.forEach((type) => es.removeEventListener(type, onMessage));
|
|
1194
|
-
es.close();
|
|
1195
|
-
}
|
|
1196
|
-
function emitReconnect() {
|
|
1197
|
-
if (shouldEmitReconnect) {
|
|
1198
|
-
observer.next({ type: "reconnect" });
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
async function getEventSource() {
|
|
1202
|
-
const { default: EventSource } = await import('@sanity/eventsource');
|
|
1203
|
-
const evs = new EventSource(uri, esOptions);
|
|
1204
|
-
evs.addEventListener("error", onError);
|
|
1205
|
-
evs.addEventListener("channelError", onChannelError);
|
|
1206
|
-
evs.addEventListener("disconnect", onDisconnect);
|
|
1207
|
-
listenFor.forEach((type) => evs.addEventListener(type, onMessage));
|
|
1208
|
-
return evs;
|
|
1209
|
-
}
|
|
1210
|
-
function open() {
|
|
1211
|
-
getEventSource().then((eventSource) => {
|
|
1212
|
-
es = eventSource;
|
|
1213
|
-
}).catch((reason) => {
|
|
1214
|
-
observer.error(reason);
|
|
1215
|
-
stop();
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
function stop() {
|
|
1219
|
-
stopped = true;
|
|
1220
|
-
unsubscribe();
|
|
1221
|
-
}
|
|
1222
|
-
return stop;
|
|
1223
|
-
});
|
|
1224
|
-
}
|
|
1225
|
-
function parseEvent(event) {
|
|
1226
|
-
try {
|
|
1227
|
-
const data = event.data && JSON.parse(event.data) || {};
|
|
1228
|
-
return Object.assign({ type: event.type }, data);
|
|
1229
|
-
} catch (err) {
|
|
1230
|
-
return err;
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
function cooerceError(err) {
|
|
1234
|
-
if (err instanceof Error) {
|
|
1235
|
-
return err;
|
|
1236
|
-
}
|
|
1237
|
-
const evt = parseEvent(err);
|
|
1238
|
-
return evt instanceof Error ? evt : new Error(extractErrorMessage(evt));
|
|
1239
|
-
}
|
|
1240
|
-
function extractErrorMessage(err) {
|
|
1241
|
-
if (!err.error) {
|
|
1242
|
-
return err.message || "Unknown listener error";
|
|
1243
|
-
}
|
|
1244
|
-
if (err.error.description) {
|
|
1245
|
-
return err.error.description;
|
|
1246
|
-
}
|
|
1247
|
-
return typeof err.error === "string" ? err.error : JSON.stringify(err.error, null, 2);
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
class ObservableDatasetsClient {
|
|
1251
|
-
#client;
|
|
1252
|
-
#httpRequest;
|
|
1253
|
-
constructor(client, httpRequest) {
|
|
1254
|
-
this.#client = client;
|
|
1255
|
-
this.#httpRequest = httpRequest;
|
|
1256
|
-
}
|
|
1257
|
-
/**
|
|
1258
|
-
* Create a new dataset with the given name
|
|
1259
|
-
*
|
|
1260
|
-
* @param name - Name of the dataset to create
|
|
1261
|
-
* @param options - Options for the dataset
|
|
1262
|
-
*/
|
|
1263
|
-
create(name, options) {
|
|
1264
|
-
return _modify(this.#client, this.#httpRequest, "PUT", name, options);
|
|
1265
|
-
}
|
|
1266
|
-
/**
|
|
1267
|
-
* Edit a dataset with the given name
|
|
1268
|
-
*
|
|
1269
|
-
* @param name - Name of the dataset to edit
|
|
1270
|
-
* @param options - New options for the dataset
|
|
1271
|
-
*/
|
|
1272
|
-
edit(name, options) {
|
|
1273
|
-
return _modify(this.#client, this.#httpRequest, "PATCH", name, options);
|
|
1274
|
-
}
|
|
1275
|
-
/**
|
|
1276
|
-
* Delete a dataset with the given name
|
|
1277
|
-
*
|
|
1278
|
-
* @param name - Name of the dataset to delete
|
|
1279
|
-
*/
|
|
1280
|
-
delete(name) {
|
|
1281
|
-
return _modify(this.#client, this.#httpRequest, "DELETE", name);
|
|
1282
|
-
}
|
|
1283
|
-
/**
|
|
1284
|
-
* Fetch a list of datasets for the configured project
|
|
1285
|
-
*/
|
|
1286
|
-
list() {
|
|
1287
|
-
return _request(this.#client, this.#httpRequest, {
|
|
1288
|
-
uri: "/datasets",
|
|
1289
|
-
tag: null
|
|
1290
|
-
});
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
class DatasetsClient {
|
|
1294
|
-
#client;
|
|
1295
|
-
#httpRequest;
|
|
1296
|
-
constructor(client, httpRequest) {
|
|
1297
|
-
this.#client = client;
|
|
1298
|
-
this.#httpRequest = httpRequest;
|
|
1299
|
-
}
|
|
1300
|
-
/**
|
|
1301
|
-
* Create a new dataset with the given name
|
|
1302
|
-
*
|
|
1303
|
-
* @param name - Name of the dataset to create
|
|
1304
|
-
* @param options - Options for the dataset
|
|
1305
|
-
*/
|
|
1306
|
-
create(name, options) {
|
|
1307
|
-
return rxjs.lastValueFrom(
|
|
1308
|
-
_modify(this.#client, this.#httpRequest, "PUT", name, options)
|
|
1309
|
-
);
|
|
1310
|
-
}
|
|
1311
|
-
/**
|
|
1312
|
-
* Edit a dataset with the given name
|
|
1313
|
-
*
|
|
1314
|
-
* @param name - Name of the dataset to edit
|
|
1315
|
-
* @param options - New options for the dataset
|
|
1316
|
-
*/
|
|
1317
|
-
edit(name, options) {
|
|
1318
|
-
return rxjs.lastValueFrom(
|
|
1319
|
-
_modify(this.#client, this.#httpRequest, "PATCH", name, options)
|
|
1320
|
-
);
|
|
1321
|
-
}
|
|
1322
|
-
/**
|
|
1323
|
-
* Delete a dataset with the given name
|
|
1324
|
-
*
|
|
1325
|
-
* @param name - Name of the dataset to delete
|
|
1326
|
-
*/
|
|
1327
|
-
delete(name) {
|
|
1328
|
-
return rxjs.lastValueFrom(_modify(this.#client, this.#httpRequest, "DELETE", name));
|
|
1329
|
-
}
|
|
1330
|
-
/**
|
|
1331
|
-
* Fetch a list of datasets for the configured project
|
|
1332
|
-
*/
|
|
1333
|
-
list() {
|
|
1334
|
-
return rxjs.lastValueFrom(
|
|
1335
|
-
_request(this.#client, this.#httpRequest, { uri: "/datasets", tag: null })
|
|
1336
|
-
);
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
function _modify(client, httpRequest, method, name, options) {
|
|
1340
|
-
dataset(name);
|
|
1341
|
-
return _request(client, httpRequest, {
|
|
1342
|
-
method,
|
|
1343
|
-
uri: `/datasets/${name}`,
|
|
1344
|
-
body: options,
|
|
1345
|
-
tag: null
|
|
1346
|
-
});
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
class ObservableProjectsClient {
|
|
1350
|
-
#client;
|
|
1351
|
-
#httpRequest;
|
|
1352
|
-
constructor(client, httpRequest) {
|
|
1353
|
-
this.#client = client;
|
|
1354
|
-
this.#httpRequest = httpRequest;
|
|
1355
|
-
}
|
|
1356
|
-
list(options) {
|
|
1357
|
-
const uri = (options == null ? void 0 : options.includeMembers) === false ? "/projects?includeMembers=false" : "/projects";
|
|
1358
|
-
return _request(this.#client, this.#httpRequest, { uri });
|
|
1359
|
-
}
|
|
1360
|
-
/**
|
|
1361
|
-
* Fetch a project by project ID
|
|
1362
|
-
*
|
|
1363
|
-
* @param projectId - ID of the project to fetch
|
|
1364
|
-
*/
|
|
1365
|
-
getById(projectId) {
|
|
1366
|
-
return _request(this.#client, this.#httpRequest, { uri: `/projects/${projectId}` });
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
class ProjectsClient {
|
|
1370
|
-
#client;
|
|
1371
|
-
#httpRequest;
|
|
1372
|
-
constructor(client, httpRequest) {
|
|
1373
|
-
this.#client = client;
|
|
1374
|
-
this.#httpRequest = httpRequest;
|
|
1375
|
-
}
|
|
1376
|
-
list(options) {
|
|
1377
|
-
const uri = (options == null ? void 0 : options.includeMembers) === false ? "/projects?includeMembers=false" : "/projects";
|
|
1378
|
-
return rxjs.lastValueFrom(_request(this.#client, this.#httpRequest, { uri }));
|
|
1379
|
-
}
|
|
1380
|
-
/**
|
|
1381
|
-
* Fetch a project by project ID
|
|
1382
|
-
*
|
|
1383
|
-
* @param projectId - ID of the project to fetch
|
|
1384
|
-
*/
|
|
1385
|
-
getById(projectId) {
|
|
1386
|
-
return rxjs.lastValueFrom(
|
|
1387
|
-
_request(this.#client, this.#httpRequest, { uri: `/projects/${projectId}` })
|
|
1388
|
-
);
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
class ObservableUsersClient {
|
|
1393
|
-
#client;
|
|
1394
|
-
#httpRequest;
|
|
1395
|
-
constructor(client, httpRequest) {
|
|
1396
|
-
this.#client = client;
|
|
1397
|
-
this.#httpRequest = httpRequest;
|
|
1398
|
-
}
|
|
1399
|
-
/**
|
|
1400
|
-
* Fetch a user by user ID
|
|
1401
|
-
*
|
|
1402
|
-
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
1403
|
-
*/
|
|
1404
|
-
getById(id) {
|
|
1405
|
-
return _request(
|
|
1406
|
-
this.#client,
|
|
1407
|
-
this.#httpRequest,
|
|
1408
|
-
{ uri: `/users/${id}` }
|
|
1409
|
-
);
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
class UsersClient {
|
|
1413
|
-
#client;
|
|
1414
|
-
#httpRequest;
|
|
1415
|
-
constructor(client, httpRequest) {
|
|
1416
|
-
this.#client = client;
|
|
1417
|
-
this.#httpRequest = httpRequest;
|
|
1418
|
-
}
|
|
1419
|
-
/**
|
|
1420
|
-
* Fetch a user by user ID
|
|
1421
|
-
*
|
|
1422
|
-
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
1423
|
-
*/
|
|
1424
|
-
getById(id) {
|
|
1425
|
-
return rxjs.lastValueFrom(
|
|
1426
|
-
_request(this.#client, this.#httpRequest, {
|
|
1427
|
-
uri: `/users/${id}`
|
|
1428
|
-
})
|
|
1429
|
-
);
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
class ObservableSanityClient {
|
|
1434
|
-
constructor(httpRequest, config = defaultConfig) {
|
|
1435
|
-
/**
|
|
1436
|
-
* Instance properties
|
|
1437
|
-
*/
|
|
1438
|
-
this.listen = _listen;
|
|
1439
|
-
this.config(config);
|
|
1440
|
-
this.#httpRequest = httpRequest;
|
|
1441
|
-
this.assets = new ObservableAssetsClient(this, this.#httpRequest);
|
|
1442
|
-
this.datasets = new ObservableDatasetsClient(this, this.#httpRequest);
|
|
1443
|
-
this.projects = new ObservableProjectsClient(this, this.#httpRequest);
|
|
1444
|
-
this.users = new ObservableUsersClient(this, this.#httpRequest);
|
|
1445
|
-
}
|
|
1446
|
-
/**
|
|
1447
|
-
* Private properties
|
|
1448
|
-
*/
|
|
1449
|
-
#clientConfig;
|
|
1450
|
-
#httpRequest;
|
|
1451
|
-
/**
|
|
1452
|
-
* Clone the client - returns a new instance
|
|
1453
|
-
*/
|
|
1454
|
-
clone() {
|
|
1455
|
-
return new ObservableSanityClient(this.#httpRequest, this.config());
|
|
1456
|
-
}
|
|
1457
|
-
config(newConfig) {
|
|
1458
|
-
if (newConfig === void 0) {
|
|
1459
|
-
return { ...this.#clientConfig };
|
|
1460
|
-
}
|
|
1461
|
-
if (this.#clientConfig && this.#clientConfig.allowReconfigure === false) {
|
|
1462
|
-
throw new Error(
|
|
1463
|
-
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1464
|
-
);
|
|
1465
|
-
}
|
|
1466
|
-
this.#clientConfig = initConfig(newConfig, this.#clientConfig || {});
|
|
1467
|
-
return this;
|
|
1468
|
-
}
|
|
1469
|
-
/**
|
|
1470
|
-
* Clone the client with a new (partial) configuration.
|
|
1471
|
-
*
|
|
1472
|
-
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1473
|
-
*/
|
|
1474
|
-
withConfig(newConfig) {
|
|
1475
|
-
const thisConfig = this.config();
|
|
1476
|
-
return new ObservableSanityClient(this.#httpRequest, {
|
|
1477
|
-
...thisConfig,
|
|
1478
|
-
...newConfig,
|
|
1479
|
-
stega: {
|
|
1480
|
-
...thisConfig.stega || {},
|
|
1481
|
-
...typeof (newConfig == null ? void 0 : newConfig.stega) === "boolean" ? { enabled: newConfig.stega } : (newConfig == null ? void 0 : newConfig.stega) || {}
|
|
1482
|
-
}
|
|
1483
|
-
});
|
|
1484
|
-
}
|
|
1485
|
-
fetch(query, params, options) {
|
|
1486
|
-
return _fetch(
|
|
1487
|
-
this,
|
|
1488
|
-
this.#httpRequest,
|
|
1489
|
-
this.#clientConfig.stega,
|
|
1490
|
-
query,
|
|
1491
|
-
params,
|
|
1492
|
-
options
|
|
1493
|
-
);
|
|
1494
|
-
}
|
|
1495
|
-
/**
|
|
1496
|
-
* Fetch a single document with the given ID.
|
|
1497
|
-
*
|
|
1498
|
-
* @param id - Document ID to fetch
|
|
1499
|
-
* @param options - Request options
|
|
1500
|
-
*/
|
|
1501
|
-
getDocument(id, options) {
|
|
1502
|
-
return _getDocument(this, this.#httpRequest, id, options);
|
|
1503
|
-
}
|
|
1504
|
-
/**
|
|
1505
|
-
* Fetch multiple documents in one request.
|
|
1506
|
-
* Should be used sparingly - performing a query is usually a better option.
|
|
1507
|
-
* The order/position of documents is preserved based on the original array of IDs.
|
|
1508
|
-
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
1509
|
-
*
|
|
1510
|
-
* @param ids - Document IDs to fetch
|
|
1511
|
-
* @param options - Request options
|
|
1512
|
-
*/
|
|
1513
|
-
getDocuments(ids, options) {
|
|
1514
|
-
return _getDocuments(this, this.#httpRequest, ids, options);
|
|
1515
|
-
}
|
|
1516
|
-
create(document, options) {
|
|
1517
|
-
return _create(this, this.#httpRequest, document, "create", options);
|
|
1518
|
-
}
|
|
1519
|
-
createIfNotExists(document, options) {
|
|
1520
|
-
return _createIfNotExists(this, this.#httpRequest, document, options);
|
|
1521
|
-
}
|
|
1522
|
-
createOrReplace(document, options) {
|
|
1523
|
-
return _createOrReplace(this, this.#httpRequest, document, options);
|
|
1524
|
-
}
|
|
1525
|
-
delete(selection, options) {
|
|
1526
|
-
return _delete(this, this.#httpRequest, selection, options);
|
|
1527
|
-
}
|
|
1528
|
-
mutate(operations, options) {
|
|
1529
|
-
return _mutate(this, this.#httpRequest, operations, options);
|
|
1530
|
-
}
|
|
1531
|
-
/**
|
|
1532
|
-
* Create a new buildable patch of operations to perform
|
|
1533
|
-
*
|
|
1534
|
-
* @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
|
|
1535
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1536
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1537
|
-
*/
|
|
1538
|
-
patch(selection, operations) {
|
|
1539
|
-
return new ObservablePatch(selection, operations, this);
|
|
1540
|
-
}
|
|
1541
|
-
/**
|
|
1542
|
-
* Create a new transaction of mutations
|
|
1543
|
-
*
|
|
1544
|
-
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
1545
|
-
*/
|
|
1546
|
-
transaction(operations) {
|
|
1547
|
-
return new ObservableTransaction(operations, this);
|
|
1548
|
-
}
|
|
1549
|
-
/**
|
|
1550
|
-
* Perform an HTTP request against the Sanity API
|
|
1551
|
-
*
|
|
1552
|
-
* @param options - Request options
|
|
1553
|
-
*/
|
|
1554
|
-
request(options) {
|
|
1555
|
-
return _request(this, this.#httpRequest, options);
|
|
1556
|
-
}
|
|
1557
|
-
/**
|
|
1558
|
-
* Get a Sanity API URL for the URI provided
|
|
1559
|
-
*
|
|
1560
|
-
* @param uri - URI/path to build URL for
|
|
1561
|
-
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1562
|
-
*/
|
|
1563
|
-
getUrl(uri, canUseCdn) {
|
|
1564
|
-
return _getUrl(this, uri, canUseCdn);
|
|
1565
|
-
}
|
|
1566
|
-
/**
|
|
1567
|
-
* Get a Sanity API URL for the data operation and path provided
|
|
1568
|
-
*
|
|
1569
|
-
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1570
|
-
* @param path - Path to append after the operation
|
|
1571
|
-
*/
|
|
1572
|
-
getDataUrl(operation, path) {
|
|
1573
|
-
return _getDataUrl(this, operation, path);
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
class SanityClient {
|
|
1577
|
-
constructor(httpRequest, config = defaultConfig) {
|
|
1578
|
-
/**
|
|
1579
|
-
* Instance properties
|
|
1580
|
-
*/
|
|
1581
|
-
this.listen = _listen;
|
|
1582
|
-
this.config(config);
|
|
1583
|
-
this.#httpRequest = httpRequest;
|
|
1584
|
-
this.assets = new AssetsClient(this, this.#httpRequest);
|
|
1585
|
-
this.datasets = new DatasetsClient(this, this.#httpRequest);
|
|
1586
|
-
this.projects = new ProjectsClient(this, this.#httpRequest);
|
|
1587
|
-
this.users = new UsersClient(this, this.#httpRequest);
|
|
1588
|
-
this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1589
|
-
}
|
|
1590
|
-
/**
|
|
1591
|
-
* Private properties
|
|
1592
|
-
*/
|
|
1593
|
-
#clientConfig;
|
|
1594
|
-
#httpRequest;
|
|
1595
|
-
/**
|
|
1596
|
-
* Clone the client - returns a new instance
|
|
1597
|
-
*/
|
|
1598
|
-
clone() {
|
|
1599
|
-
return new SanityClient(this.#httpRequest, this.config());
|
|
1600
|
-
}
|
|
1601
|
-
config(newConfig) {
|
|
1602
|
-
if (newConfig === void 0) {
|
|
1603
|
-
return { ...this.#clientConfig };
|
|
1604
|
-
}
|
|
1605
|
-
if (this.#clientConfig && this.#clientConfig.allowReconfigure === false) {
|
|
1606
|
-
throw new Error(
|
|
1607
|
-
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1608
|
-
);
|
|
1609
|
-
}
|
|
1610
|
-
if (this.observable) {
|
|
1611
|
-
this.observable.config(newConfig);
|
|
1612
|
-
}
|
|
1613
|
-
this.#clientConfig = initConfig(newConfig, this.#clientConfig || {});
|
|
1614
|
-
return this;
|
|
1615
|
-
}
|
|
1616
|
-
/**
|
|
1617
|
-
* Clone the client with a new (partial) configuration.
|
|
1618
|
-
*
|
|
1619
|
-
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1620
|
-
*/
|
|
1621
|
-
withConfig(newConfig) {
|
|
1622
|
-
const thisConfig = this.config();
|
|
1623
|
-
return new SanityClient(this.#httpRequest, {
|
|
1624
|
-
...thisConfig,
|
|
1625
|
-
...newConfig,
|
|
1626
|
-
stega: {
|
|
1627
|
-
...thisConfig.stega || {},
|
|
1628
|
-
...typeof (newConfig == null ? void 0 : newConfig.stega) === "boolean" ? { enabled: newConfig.stega } : (newConfig == null ? void 0 : newConfig.stega) || {}
|
|
1629
|
-
}
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
fetch(query, params, options) {
|
|
1633
|
-
return rxjs.lastValueFrom(
|
|
1634
|
-
_fetch(
|
|
1635
|
-
this,
|
|
1636
|
-
this.#httpRequest,
|
|
1637
|
-
this.#clientConfig.stega,
|
|
1638
|
-
query,
|
|
1639
|
-
params,
|
|
1640
|
-
options
|
|
1641
|
-
)
|
|
1642
|
-
);
|
|
1643
|
-
}
|
|
1644
|
-
/**
|
|
1645
|
-
* Fetch a single document with the given ID.
|
|
1646
|
-
*
|
|
1647
|
-
* @param id - Document ID to fetch
|
|
1648
|
-
* @param options - Request options
|
|
1649
|
-
*/
|
|
1650
|
-
getDocument(id, options) {
|
|
1651
|
-
return rxjs.lastValueFrom(_getDocument(this, this.#httpRequest, id, options));
|
|
1652
|
-
}
|
|
1653
|
-
/**
|
|
1654
|
-
* Fetch multiple documents in one request.
|
|
1655
|
-
* Should be used sparingly - performing a query is usually a better option.
|
|
1656
|
-
* The order/position of documents is preserved based on the original array of IDs.
|
|
1657
|
-
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
1658
|
-
*
|
|
1659
|
-
* @param ids - Document IDs to fetch
|
|
1660
|
-
* @param options - Request options
|
|
1661
|
-
*/
|
|
1662
|
-
getDocuments(ids, options) {
|
|
1663
|
-
return rxjs.lastValueFrom(_getDocuments(this, this.#httpRequest, ids, options));
|
|
1664
|
-
}
|
|
1665
|
-
create(document, options) {
|
|
1666
|
-
return rxjs.lastValueFrom(
|
|
1667
|
-
_create(this, this.#httpRequest, document, "create", options)
|
|
1668
|
-
);
|
|
1669
|
-
}
|
|
1670
|
-
createIfNotExists(document, options) {
|
|
1671
|
-
return rxjs.lastValueFrom(
|
|
1672
|
-
_createIfNotExists(this, this.#httpRequest, document, options)
|
|
1673
|
-
);
|
|
1674
|
-
}
|
|
1675
|
-
createOrReplace(document, options) {
|
|
1676
|
-
return rxjs.lastValueFrom(
|
|
1677
|
-
_createOrReplace(this, this.#httpRequest, document, options)
|
|
1678
|
-
);
|
|
1679
|
-
}
|
|
1680
|
-
delete(selection, options) {
|
|
1681
|
-
return rxjs.lastValueFrom(_delete(this, this.#httpRequest, selection, options));
|
|
1682
|
-
}
|
|
1683
|
-
mutate(operations, options) {
|
|
1684
|
-
return rxjs.lastValueFrom(_mutate(this, this.#httpRequest, operations, options));
|
|
1685
|
-
}
|
|
1686
|
-
/**
|
|
1687
|
-
* Create a new buildable patch of operations to perform
|
|
1688
|
-
*
|
|
1689
|
-
* @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
|
|
1690
|
-
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1691
|
-
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1692
|
-
*/
|
|
1693
|
-
patch(documentId, operations) {
|
|
1694
|
-
return new Patch(documentId, operations, this);
|
|
1695
|
-
}
|
|
1696
|
-
/**
|
|
1697
|
-
* Create a new transaction of mutations
|
|
1698
|
-
*
|
|
1699
|
-
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
1700
|
-
*/
|
|
1701
|
-
transaction(operations) {
|
|
1702
|
-
return new Transaction(operations, this);
|
|
1703
|
-
}
|
|
1704
|
-
/**
|
|
1705
|
-
* Perform a request against the Sanity API
|
|
1706
|
-
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
1707
|
-
*
|
|
1708
|
-
* @param options - Request options
|
|
1709
|
-
* @returns Promise resolving to the response body
|
|
1710
|
-
*/
|
|
1711
|
-
request(options) {
|
|
1712
|
-
return rxjs.lastValueFrom(_request(this, this.#httpRequest, options));
|
|
1713
|
-
}
|
|
1714
|
-
/**
|
|
1715
|
-
* Perform an HTTP request a `/data` sub-endpoint
|
|
1716
|
-
* NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
|
|
1717
|
-
*
|
|
1718
|
-
* @deprecated - Use `request()` or your own HTTP library instead
|
|
1719
|
-
* @param endpoint - Endpoint to hit (mutate, query etc)
|
|
1720
|
-
* @param body - Request body
|
|
1721
|
-
* @param options - Request options
|
|
1722
|
-
* @internal
|
|
1723
|
-
*/
|
|
1724
|
-
dataRequest(endpoint, body, options) {
|
|
1725
|
-
return rxjs.lastValueFrom(_dataRequest(this, this.#httpRequest, endpoint, body, options));
|
|
1726
|
-
}
|
|
1727
|
-
/**
|
|
1728
|
-
* Get a Sanity API URL for the URI provided
|
|
1729
|
-
*
|
|
1730
|
-
* @param uri - URI/path to build URL for
|
|
1731
|
-
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1732
|
-
*/
|
|
1733
|
-
getUrl(uri, canUseCdn) {
|
|
1734
|
-
return _getUrl(this, uri, canUseCdn);
|
|
1735
|
-
}
|
|
1736
|
-
/**
|
|
1737
|
-
* Get a Sanity API URL for the data operation and path provided
|
|
1738
|
-
*
|
|
1739
|
-
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1740
|
-
* @param path - Path to append after the operation
|
|
1741
|
-
*/
|
|
1742
|
-
getDataUrl(operation, path) {
|
|
1743
|
-
return _getDataUrl(this, operation, path);
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
function defineCreateClientExports(envMiddleware, ClassConstructor) {
|
|
1748
|
-
const httpRequest = defineHttpRequest(envMiddleware, {});
|
|
1749
|
-
const requester = httpRequest.defaultRequester;
|
|
1750
|
-
const createClient = (config) => new ClassConstructor(
|
|
1751
|
-
defineHttpRequest(envMiddleware, {
|
|
1752
|
-
maxRetries: config.maxRetries,
|
|
1753
|
-
retryDelay: config.retryDelay
|
|
1754
|
-
}),
|
|
1755
|
-
config
|
|
1756
|
-
);
|
|
1757
|
-
return { requester, createClient };
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
var envMiddleware = [];
|
|
1761
|
-
|
|
1762
|
-
exports.BasePatch = BasePatch;
|
|
1763
|
-
exports.BaseTransaction = BaseTransaction;
|
|
1764
|
-
exports.ClientError = ClientError;
|
|
1765
|
-
exports.ObservablePatch = ObservablePatch;
|
|
1766
|
-
exports.ObservableSanityClient = ObservableSanityClient;
|
|
1767
|
-
exports.ObservableTransaction = ObservableTransaction;
|
|
1768
|
-
exports.Patch = Patch;
|
|
1769
|
-
exports.SanityClient = SanityClient;
|
|
1770
|
-
exports.ServerError = ServerError;
|
|
1771
|
-
exports.Transaction = Transaction;
|
|
1772
|
-
exports.b = b;
|
|
1773
|
-
exports.defineCreateClientExports = defineCreateClientExports;
|
|
1774
|
-
exports.envMiddleware = envMiddleware;
|
|
1775
|
-
exports.printNoDefaultExport = printNoDefaultExport;
|
|
1776
|
-
exports.vercelStegaCleanAll = vercelStegaCleanAll;
|
|
1777
|
-
//# sourceMappingURL=browserMiddleware-FpdqDQ1o.cjs.map
|