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