@sanity/client 6.7.1 → 6.8.0-pink-lizard.1
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/README.md +79 -2
- package/dist/_chunks/browserMiddleware-Oa7zKwEN.js +1862 -0
- package/dist/_chunks/browserMiddleware-Oa7zKwEN.js.map +1 -0
- package/dist/_chunks/browserMiddleware-zle5A-pb.cjs +1877 -0
- package/dist/_chunks/browserMiddleware-zle5A-pb.cjs.map +1 -0
- package/dist/_chunks/createEditLink-FiifjNgi.cjs +222 -0
- package/dist/_chunks/createEditLink-FiifjNgi.cjs.map +1 -0
- package/dist/_chunks/createEditLink-f3l2nngi.js +212 -0
- package/dist/_chunks/createEditLink-f3l2nngi.js.map +1 -0
- package/dist/_chunks/nodeMiddleware-S6QZVGmT.cjs +1897 -0
- package/dist/_chunks/nodeMiddleware-S6QZVGmT.cjs.map +1 -0
- package/dist/_chunks/nodeMiddleware-XodpBhbR.js +1882 -0
- package/dist/_chunks/nodeMiddleware-XodpBhbR.js.map +1 -0
- package/dist/csm.cjs +71 -0
- package/dist/csm.cjs.map +1 -0
- package/dist/csm.d.ts +248 -0
- package/dist/csm.js +58 -0
- package/dist/csm.js.map +1 -0
- package/dist/index.browser.cjs +13 -1868
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +3 -1858
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +13 -1888
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1878
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.cjs +629 -0
- package/dist/stega.browser.cjs.map +1 -0
- package/dist/stega.browser.js +598 -0
- package/dist/stega.browser.js.map +1 -0
- package/dist/stega.cjs +424 -0
- package/dist/stega.cjs.js +21 -0
- package/dist/stega.cjs.map +1 -0
- package/dist/stega.d.ts +2872 -0
- package/dist/stega.js +393 -0
- package/dist/stega.js.map +1 -0
- package/package.json +42 -2
- package/src/config.ts +6 -0
- package/src/csm/applySourceDocuments.test.ts +820 -0
- package/src/csm/applySourceDocuments.ts +87 -0
- package/src/csm/createEditLink.ts +75 -0
- package/src/csm/getPublishedId.ts +12 -0
- package/src/csm/index.ts +9 -0
- package/src/csm/isArray.ts +3 -0
- package/src/csm/isRecord.ts +3 -0
- package/src/csm/jsonpath.test.ts +33 -0
- package/src/csm/jsonpath.ts +93 -0
- package/src/csm/resolveMapping.ts +41 -0
- package/src/csm/resolvedKeyedSourcePath.ts +23 -0
- package/src/csm/simplifyPath.ts +20 -0
- package/src/csm/types.ts +72 -0
- package/src/csm/walkMap.ts +30 -0
- package/src/stega/SanityStegaClient.ts +244 -0
- package/src/stega/config.ts +56 -0
- package/src/stega/encodeIntoResult.test.ts +268 -0
- package/src/stega/encodeIntoResult.ts +59 -0
- package/src/stega/filterDefault.ts +49 -0
- package/src/stega/index.browser.ts +19 -0
- package/src/stega/index.ts +19 -0
- package/src/stega/shared.ts +4 -0
- package/src/stega/stegaEncodeSourceMap.ts +128 -0
- package/src/stega/types.ts +139 -0
- package/umd/sanityClient.js +5 -1
- package/umd/sanityClient.min.js +1 -1
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import { ObservableSanityClient, defaultConfig, SanityClient, defineCreateClientExports, envMiddleware } from './_chunks/browserMiddleware-Oa7zKwEN.js';
|
|
2
|
+
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/browserMiddleware-Oa7zKwEN.js';
|
|
3
|
+
import { map } from 'rxjs/operators';
|
|
4
|
+
import { vercelStegaCombine } from '@vercel/stega';
|
|
5
|
+
export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it';
|
|
6
|
+
const defaultStegaConfig = {
|
|
7
|
+
enabled: false,
|
|
8
|
+
filter: props => props.filterDefault(props),
|
|
9
|
+
vercelStegaCombineSkip: "auto"
|
|
10
|
+
};
|
|
11
|
+
function splitConfig(config) {
|
|
12
|
+
const {
|
|
13
|
+
stega = {},
|
|
14
|
+
...clientConfig
|
|
15
|
+
} = config;
|
|
16
|
+
return {
|
|
17
|
+
clientConfig,
|
|
18
|
+
stegaConfig: stega
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const initStegaConfig = (config, prevConfig) => {
|
|
22
|
+
const specifiedConfig = Object.assign({}, prevConfig, config);
|
|
23
|
+
const newConfig = Object.assign({}, defaultStegaConfig, specifiedConfig);
|
|
24
|
+
if ("encodeSourceMap" in newConfig) {
|
|
25
|
+
throw new Error("It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client/stega'. Did you mean 'enabled'?");
|
|
26
|
+
}
|
|
27
|
+
if ("encodeSourceMapAtPath" in newConfig) {
|
|
28
|
+
throw new Error("It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client/stega'. Did you mean 'filter'?");
|
|
29
|
+
}
|
|
30
|
+
if (typeof newConfig.enabled !== "boolean") {
|
|
31
|
+
throw new Error("config.enabled must be a boolean, received ".concat(newConfig.enabled));
|
|
32
|
+
}
|
|
33
|
+
if (newConfig.enabled && newConfig.studioUrl === void 0) {
|
|
34
|
+
throw new Error("config.studioUrl must be defined when config.enabled is true");
|
|
35
|
+
}
|
|
36
|
+
if (newConfig.enabled && typeof newConfig.studioUrl !== "string" && typeof newConfig.studioUrl !== "function") {
|
|
37
|
+
throw new Error("config.studioUrl must be a string or a function, received ".concat(newConfig.studioUrl));
|
|
38
|
+
}
|
|
39
|
+
return newConfig;
|
|
40
|
+
};
|
|
41
|
+
const DRAFTS_PREFIX = "drafts.";
|
|
42
|
+
function getPublishedId(id) {
|
|
43
|
+
if (id.startsWith(DRAFTS_PREFIX)) {
|
|
44
|
+
return id.slice(DRAFTS_PREFIX.length);
|
|
45
|
+
}
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
const ESCAPE = {
|
|
49
|
+
"\f": "\\f",
|
|
50
|
+
"\n": "\\n",
|
|
51
|
+
"\r": "\\r",
|
|
52
|
+
" ": "\\t",
|
|
53
|
+
"'": "\\'",
|
|
54
|
+
"\\": "\\\\"
|
|
55
|
+
};
|
|
56
|
+
const UNESCAPE = {
|
|
57
|
+
"\\f": "\f",
|
|
58
|
+
"\\n": "\n",
|
|
59
|
+
"\\r": "\r",
|
|
60
|
+
"\\t": " ",
|
|
61
|
+
"\\'": "'",
|
|
62
|
+
"\\\\": "\\"
|
|
63
|
+
};
|
|
64
|
+
function jsonPath(path, opts) {
|
|
65
|
+
return "$".concat(path.map(segment => {
|
|
66
|
+
if (typeof segment === "string") {
|
|
67
|
+
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, match => {
|
|
68
|
+
return ESCAPE[match];
|
|
69
|
+
});
|
|
70
|
+
return "['".concat(escapedKey, "']");
|
|
71
|
+
}
|
|
72
|
+
if (typeof segment === "number") {
|
|
73
|
+
return "[".concat(segment, "]");
|
|
74
|
+
}
|
|
75
|
+
if ((opts == null ? void 0 : opts.keyArraySelectors) && segment.key !== "") {
|
|
76
|
+
const escapedKey = segment.key.replace(/['\\]/g, match => {
|
|
77
|
+
return ESCAPE[match];
|
|
78
|
+
});
|
|
79
|
+
return "[?(@._key=='".concat(escapedKey, "')]");
|
|
80
|
+
}
|
|
81
|
+
return "[".concat(segment.index, "]");
|
|
82
|
+
}).join(""));
|
|
83
|
+
}
|
|
84
|
+
function parseJsonPath(path) {
|
|
85
|
+
const parsed = [];
|
|
86
|
+
const parseRe = /\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;
|
|
87
|
+
let match;
|
|
88
|
+
while ((match = parseRe.exec(path)) !== null) {
|
|
89
|
+
if (match[1] !== void 0) {
|
|
90
|
+
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, m => {
|
|
91
|
+
return UNESCAPE[m];
|
|
92
|
+
});
|
|
93
|
+
parsed.push(key);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (match[2] !== void 0) {
|
|
97
|
+
parsed.push(parseInt(match[2], 10));
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (match[3] !== void 0) {
|
|
101
|
+
const key = match[3].replace(/\\(\\')/g, m => {
|
|
102
|
+
return UNESCAPE[m];
|
|
103
|
+
});
|
|
104
|
+
parsed.push({
|
|
105
|
+
key,
|
|
106
|
+
index: -1
|
|
107
|
+
});
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return parsed;
|
|
112
|
+
}
|
|
113
|
+
function resolvedKeyedSourcePath(options) {
|
|
114
|
+
const {
|
|
115
|
+
keyedResultPath,
|
|
116
|
+
pathSuffix,
|
|
117
|
+
sourceBasePath
|
|
118
|
+
} = options;
|
|
119
|
+
const inferredResultPath = pathSuffix === void 0 ? [] : parseJsonPath(pathSuffix);
|
|
120
|
+
const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length);
|
|
121
|
+
const inferredPathSuffix = inferredPath.length ? jsonPath(inferredPath, {
|
|
122
|
+
keyArraySelectors: true
|
|
123
|
+
}).slice(1) : "";
|
|
124
|
+
return parseJsonPath(sourceBasePath + inferredPathSuffix);
|
|
125
|
+
}
|
|
126
|
+
function resolveMapping(resultPath, csm) {
|
|
127
|
+
if (!(csm == null ? void 0 : csm.mappings)) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
const resultJsonPath = jsonPath(resultPath);
|
|
131
|
+
if (csm.mappings[resultJsonPath] !== void 0) {
|
|
132
|
+
return {
|
|
133
|
+
mapping: csm.mappings[resultJsonPath],
|
|
134
|
+
matchedPath: resultJsonPath,
|
|
135
|
+
pathSuffix: ""
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const mappings = Object.entries(csm.mappings).filter(_ref => {
|
|
139
|
+
let [key] = _ref;
|
|
140
|
+
return resultJsonPath.startsWith(key);
|
|
141
|
+
}).sort((_ref2, _ref3) => {
|
|
142
|
+
let [key1] = _ref2;
|
|
143
|
+
let [key2] = _ref3;
|
|
144
|
+
return key2.length - key1.length;
|
|
145
|
+
});
|
|
146
|
+
if (mappings.length == 0) {
|
|
147
|
+
return void 0;
|
|
148
|
+
}
|
|
149
|
+
const [matchedPath, mapping] = mappings[0];
|
|
150
|
+
const pathSuffix = resultJsonPath.substring(matchedPath.length);
|
|
151
|
+
return {
|
|
152
|
+
mapping,
|
|
153
|
+
matchedPath,
|
|
154
|
+
pathSuffix
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function simplifyPath(path) {
|
|
158
|
+
return path.map((segment, index) => {
|
|
159
|
+
if (typeof segment === "number") {
|
|
160
|
+
return "[".concat(segment, "]");
|
|
161
|
+
}
|
|
162
|
+
if (typeof segment === "string") {
|
|
163
|
+
return index === 0 ? segment : ".".concat(segment);
|
|
164
|
+
}
|
|
165
|
+
return '[_key=="'.concat(segment.key, '"]');
|
|
166
|
+
}).join("");
|
|
167
|
+
}
|
|
168
|
+
function createEditLink(options) {
|
|
169
|
+
const {
|
|
170
|
+
studioUrl: resolveStudioUrl,
|
|
171
|
+
resultSourceMap: csm,
|
|
172
|
+
resultPath
|
|
173
|
+
} = options;
|
|
174
|
+
const {
|
|
175
|
+
mapping,
|
|
176
|
+
pathSuffix
|
|
177
|
+
} = resolveMapping(resultPath, csm) || {};
|
|
178
|
+
if (!mapping) {
|
|
179
|
+
return void 0;
|
|
180
|
+
}
|
|
181
|
+
if (mapping.source.type === "literal") {
|
|
182
|
+
return void 0;
|
|
183
|
+
}
|
|
184
|
+
if (mapping.source.type === "unknown") {
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
const sourceDoc = csm.documents[mapping.source.document];
|
|
188
|
+
const sourceBasePath = csm.paths[mapping.source.path];
|
|
189
|
+
if (sourceDoc && sourceBasePath) {
|
|
190
|
+
const studioUrl = typeof resolveStudioUrl === "function" ? resolveStudioUrl(sourceDoc, parseJsonPath(sourceBasePath)) : resolveStudioUrl;
|
|
191
|
+
if (!studioUrl) return void 0;
|
|
192
|
+
const _studioUrl = studioUrl.replace(/\/$/, "");
|
|
193
|
+
const _path = encodeURIComponent(simplifyPath(resolvedKeyedSourcePath({
|
|
194
|
+
keyedResultPath: parseJsonPath(sourceBasePath),
|
|
195
|
+
pathSuffix,
|
|
196
|
+
sourceBasePath
|
|
197
|
+
})));
|
|
198
|
+
const {
|
|
199
|
+
_id,
|
|
200
|
+
_type
|
|
201
|
+
} = sourceDoc;
|
|
202
|
+
const params = new URLSearchParams();
|
|
203
|
+
if (sourceDoc._projectId) {
|
|
204
|
+
params.set("projectId", sourceDoc._projectId);
|
|
205
|
+
}
|
|
206
|
+
if (sourceDoc._dataset) {
|
|
207
|
+
params.set("dataset", sourceDoc._dataset);
|
|
208
|
+
}
|
|
209
|
+
params.set("id", getPublishedId(sourceDoc._id));
|
|
210
|
+
params.set("type", sourceDoc._type);
|
|
211
|
+
params.set("path", decodeURIComponent(_path));
|
|
212
|
+
params.set("baseUrl", _studioUrl);
|
|
213
|
+
return "".concat(_studioUrl, "/intent/edit/id=").concat(getPublishedId(_id), ";type=").concat(_type, ";path=").concat(_path, "?").concat(params);
|
|
214
|
+
}
|
|
215
|
+
return void 0;
|
|
216
|
+
}
|
|
217
|
+
function isArray(value) {
|
|
218
|
+
return value !== null && Array.isArray(value);
|
|
219
|
+
}
|
|
220
|
+
function isRecord(value) {
|
|
221
|
+
return typeof value === "object" && value !== null;
|
|
222
|
+
}
|
|
223
|
+
function walkMap(value, mappingFn) {
|
|
224
|
+
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
225
|
+
if (isArray(value)) {
|
|
226
|
+
return value.map((v, idx) => {
|
|
227
|
+
if (isRecord(v)) {
|
|
228
|
+
const key = v["_key"];
|
|
229
|
+
if (typeof key === "string") {
|
|
230
|
+
return walkMap(v, mappingFn, path.concat({
|
|
231
|
+
key,
|
|
232
|
+
index: idx
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return walkMap(v, mappingFn, path.concat(idx));
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
if (isRecord(value)) {
|
|
240
|
+
return Object.fromEntries(Object.entries(value).map(_ref4 => {
|
|
241
|
+
let [k, v] = _ref4;
|
|
242
|
+
return [k, walkMap(v, mappingFn, path.concat(k))];
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
return mappingFn(value, path);
|
|
246
|
+
}
|
|
247
|
+
function encodeIntoResult(result, csm, encoder, options) {
|
|
248
|
+
return walkMap(result, (value, path) => {
|
|
249
|
+
if (typeof value !== "string") {
|
|
250
|
+
return value;
|
|
251
|
+
}
|
|
252
|
+
const resolveMappingResult = resolveMapping(path, csm);
|
|
253
|
+
if (!resolveMappingResult) {
|
|
254
|
+
return value;
|
|
255
|
+
}
|
|
256
|
+
const {
|
|
257
|
+
mapping,
|
|
258
|
+
matchedPath,
|
|
259
|
+
pathSuffix
|
|
260
|
+
} = resolveMappingResult;
|
|
261
|
+
if (mapping.type !== "value") {
|
|
262
|
+
return value;
|
|
263
|
+
}
|
|
264
|
+
if (mapping.source.type !== "documentValue") {
|
|
265
|
+
return value;
|
|
266
|
+
}
|
|
267
|
+
const sourceDocument = csm.documents[mapping.source.document];
|
|
268
|
+
const sourcePath = csm.paths[mapping.source.path];
|
|
269
|
+
if (options == null ? void 0 : options.keyArraySelectors) {
|
|
270
|
+
const matchPathSegments = parseJsonPath(matchedPath);
|
|
271
|
+
const sourcePathSegments = parseJsonPath(sourcePath);
|
|
272
|
+
const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length));
|
|
273
|
+
return encoder({
|
|
274
|
+
sourcePath: fullSourceSegments,
|
|
275
|
+
sourceDocument,
|
|
276
|
+
resultPath: path,
|
|
277
|
+
value
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return encoder({
|
|
281
|
+
sourcePath: parseJsonPath(sourcePath + pathSuffix),
|
|
282
|
+
sourceDocument,
|
|
283
|
+
resultPath: path,
|
|
284
|
+
value
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
const filterDefault = _ref5 => {
|
|
289
|
+
let {
|
|
290
|
+
sourcePath
|
|
291
|
+
} = _ref5;
|
|
292
|
+
const endPath = sourcePath.at(-1);
|
|
293
|
+
if (sourcePath.at(-2) === "slug" && endPath === "current") {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
if (typeof endPath === "string" && endPath.startsWith("_")) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
if (typeof endPath === "number" && sourcePath.at(-2) === "marks" && typeof sourcePath.at(-3) === "number" && sourcePath.at(-4) === "children" && typeof sourcePath.at(-5) === "number") {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
if (endPath === "href" && typeof sourcePath.at(-2) === "number" && sourcePath.at(-3) === "markDefs" && typeof sourcePath.at(-4) === "number") {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
if (typeof endPath === "string" && typeof sourcePath.at(-2) === "number") {
|
|
306
|
+
if (endPath === "style" || endPath === "listItem") {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return true;
|
|
311
|
+
};
|
|
312
|
+
const TRUNCATE_LENGTH = 20;
|
|
313
|
+
function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
314
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
315
|
+
const {
|
|
316
|
+
filter,
|
|
317
|
+
vercelStegaCombineSkip,
|
|
318
|
+
logger,
|
|
319
|
+
studioUrl,
|
|
320
|
+
enabled
|
|
321
|
+
} = config;
|
|
322
|
+
if (!enabled) {
|
|
323
|
+
const msg = "config.enabled must be true, don't call this function otherwise";
|
|
324
|
+
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), {
|
|
325
|
+
result,
|
|
326
|
+
resultSourceMap,
|
|
327
|
+
config
|
|
328
|
+
});
|
|
329
|
+
throw new TypeError(msg);
|
|
330
|
+
}
|
|
331
|
+
if (!resultSourceMap) {
|
|
332
|
+
(_b = logger == null ? void 0 : logger.error) == null ? void 0 : _b.call(logger, "[@sanity/client/stega]: Missing Content Source Map from response body", {
|
|
333
|
+
result,
|
|
334
|
+
resultSourceMap,
|
|
335
|
+
config
|
|
336
|
+
});
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
339
|
+
if (!studioUrl) {
|
|
340
|
+
const msg = "config.studioUrl must be defined";
|
|
341
|
+
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), {
|
|
342
|
+
result,
|
|
343
|
+
resultSourceMap,
|
|
344
|
+
config
|
|
345
|
+
});
|
|
346
|
+
throw new TypeError(msg);
|
|
347
|
+
}
|
|
348
|
+
const report = {
|
|
349
|
+
encoded: [],
|
|
350
|
+
skipped: []
|
|
351
|
+
};
|
|
352
|
+
const resultWithStega = encodeIntoResult(result, resultSourceMap, _ref6 => {
|
|
353
|
+
let {
|
|
354
|
+
sourcePath,
|
|
355
|
+
sourceDocument,
|
|
356
|
+
resultPath,
|
|
357
|
+
value
|
|
358
|
+
} = _ref6;
|
|
359
|
+
if ((typeof filter === "function" ? filter({
|
|
360
|
+
sourcePath,
|
|
361
|
+
resultPath,
|
|
362
|
+
filterDefault,
|
|
363
|
+
sourceDocument,
|
|
364
|
+
value
|
|
365
|
+
}) : filterDefault({
|
|
366
|
+
sourcePath,
|
|
367
|
+
resultPath,
|
|
368
|
+
filterDefault,
|
|
369
|
+
sourceDocument,
|
|
370
|
+
value
|
|
371
|
+
})) === false) {
|
|
372
|
+
if (logger) {
|
|
373
|
+
report.skipped.push({
|
|
374
|
+
path: prettyPathForLogging(sourcePath),
|
|
375
|
+
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
|
|
376
|
+
length: value.length
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
return value;
|
|
380
|
+
}
|
|
381
|
+
if (logger) {
|
|
382
|
+
report.encoded.push({
|
|
383
|
+
path: prettyPathForLogging(sourcePath),
|
|
384
|
+
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
|
|
385
|
+
length: value.length
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
return vercelStegaCombine(value, {
|
|
389
|
+
origin: "sanity.io",
|
|
390
|
+
href: createEditLink({
|
|
391
|
+
studioUrl,
|
|
392
|
+
resultSourceMap,
|
|
393
|
+
resultPath
|
|
394
|
+
})
|
|
395
|
+
}, vercelStegaCombineSkip);
|
|
396
|
+
}, {
|
|
397
|
+
keyArraySelectors: true
|
|
398
|
+
});
|
|
399
|
+
if (logger) {
|
|
400
|
+
const isSkipping = report.skipped.length;
|
|
401
|
+
const isEncoding = report.encoded.length;
|
|
402
|
+
if (isSkipping || isEncoding) {
|
|
403
|
+
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d("[@sanity/client/stega]: Encoding source map into result");
|
|
404
|
+
(_e = logger.log) == null ? void 0 : _e.call(logger, "[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length));
|
|
405
|
+
}
|
|
406
|
+
if (report.encoded.length > 0) {
|
|
407
|
+
(_f = logger == null ? void 0 : logger.log) == null ? void 0 : _f.call(logger, "[@sanity/client/stega]: Table of encoded paths");
|
|
408
|
+
(_g = (logger == null ? void 0 : logger.table) || logger.log) == null ? void 0 : _g(report.encoded);
|
|
409
|
+
}
|
|
410
|
+
if (report.skipped.length > 0) {
|
|
411
|
+
const skipped = /* @__PURE__ */new Set();
|
|
412
|
+
for (const {
|
|
413
|
+
path
|
|
414
|
+
} of report.skipped) {
|
|
415
|
+
skipped.add(path.replace(/\[\d+\]/g, "[]"));
|
|
416
|
+
}
|
|
417
|
+
(_h = logger == null ? void 0 : logger.log) == null ? void 0 : _h.call(logger, "[@sanity/client/stega]: List of skipped paths", [...skipped.values()]);
|
|
418
|
+
}
|
|
419
|
+
if (isSkipping || isEncoding) {
|
|
420
|
+
(_i = logger == null ? void 0 : logger.groupEnd) == null ? void 0 : _i.call(logger);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return resultWithStega;
|
|
424
|
+
}
|
|
425
|
+
function prettyPathForLogging(path) {
|
|
426
|
+
return path.map((segment, index) => typeof segment === "number" ? "[".concat(segment, "]") : index > 0 ? ".".concat(segment) : segment).join("");
|
|
427
|
+
}
|
|
428
|
+
var __accessCheck = (obj, member, msg) => {
|
|
429
|
+
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
430
|
+
};
|
|
431
|
+
var __privateGet = (obj, member, getter) => {
|
|
432
|
+
__accessCheck(obj, member, "read from private field");
|
|
433
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
434
|
+
};
|
|
435
|
+
var __privateAdd = (obj, member, value) => {
|
|
436
|
+
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
437
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
438
|
+
};
|
|
439
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
440
|
+
__accessCheck(obj, member, "write to private field");
|
|
441
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
442
|
+
return value;
|
|
443
|
+
};
|
|
444
|
+
var _httpRequest, _httpRequest2;
|
|
445
|
+
const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends ObservableSanityClient {
|
|
446
|
+
constructor(httpRequest) {
|
|
447
|
+
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
448
|
+
const {
|
|
449
|
+
clientConfig,
|
|
450
|
+
stegaConfig
|
|
451
|
+
} = splitConfig(config);
|
|
452
|
+
super(httpRequest, clientConfig);
|
|
453
|
+
/**
|
|
454
|
+
* Private properties
|
|
455
|
+
*/
|
|
456
|
+
__privateAdd(this, _httpRequest, void 0);
|
|
457
|
+
__privateSet(this, _httpRequest, httpRequest);
|
|
458
|
+
this.stegaConfig = initStegaConfig(stegaConfig, defaultStegaConfig);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Clone the client - returns a new instance
|
|
462
|
+
*/
|
|
463
|
+
clone() {
|
|
464
|
+
return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), this.config());
|
|
465
|
+
}
|
|
466
|
+
config(newConfig) {
|
|
467
|
+
if (newConfig === void 0) {
|
|
468
|
+
return {
|
|
469
|
+
...super.config(),
|
|
470
|
+
stega: {
|
|
471
|
+
...this.stegaConfig
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
super.config(newConfig);
|
|
476
|
+
const {
|
|
477
|
+
stegaConfig
|
|
478
|
+
} = splitConfig(newConfig);
|
|
479
|
+
this.stegaConfig = initStegaConfig(stegaConfig, this.stegaConfig || {});
|
|
480
|
+
return this;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Clone the client with a new (partial) configuration.
|
|
484
|
+
*
|
|
485
|
+
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
486
|
+
*/
|
|
487
|
+
withConfig(newConfig) {
|
|
488
|
+
return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), {
|
|
489
|
+
...this.config(),
|
|
490
|
+
...newConfig
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
fetch(query, params) {
|
|
494
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
495
|
+
const {
|
|
496
|
+
filterResponse: originalFilterResponse = true
|
|
497
|
+
} = options;
|
|
498
|
+
return super.fetch(query, params, Object.assign({}, options, {
|
|
499
|
+
filterResponse: false
|
|
500
|
+
})).pipe(map(res => {
|
|
501
|
+
const {
|
|
502
|
+
result: _result,
|
|
503
|
+
resultSourceMap
|
|
504
|
+
} = res;
|
|
505
|
+
let result = _result;
|
|
506
|
+
if (this.stegaConfig.enabled) {
|
|
507
|
+
result = stegaEncodeSourceMap(_result, resultSourceMap, this.stegaConfig);
|
|
508
|
+
}
|
|
509
|
+
return originalFilterResponse ? result : {
|
|
510
|
+
...res,
|
|
511
|
+
result
|
|
512
|
+
};
|
|
513
|
+
}));
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
_httpRequest = new WeakMap();
|
|
517
|
+
let ObservableSanityStegaClient = _ObservableSanityStegaClient;
|
|
518
|
+
const _SanityStegaClient = class _SanityStegaClient extends SanityClient {
|
|
519
|
+
constructor(httpRequest) {
|
|
520
|
+
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
521
|
+
const {
|
|
522
|
+
clientConfig,
|
|
523
|
+
stegaConfig
|
|
524
|
+
} = splitConfig(config);
|
|
525
|
+
super(httpRequest, clientConfig);
|
|
526
|
+
/**
|
|
527
|
+
* Private properties
|
|
528
|
+
*/
|
|
529
|
+
__privateAdd(this, _httpRequest2, void 0);
|
|
530
|
+
__privateSet(this, _httpRequest2, httpRequest);
|
|
531
|
+
this.stegaConfig = initStegaConfig(stegaConfig, defaultStegaConfig);
|
|
532
|
+
this.observable = new ObservableSanityStegaClient(httpRequest, config);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Clone the client - returns a new instance
|
|
536
|
+
*/
|
|
537
|
+
clone() {
|
|
538
|
+
return new _SanityStegaClient(__privateGet(this, _httpRequest2), this.config());
|
|
539
|
+
}
|
|
540
|
+
config(newConfig) {
|
|
541
|
+
if (newConfig === void 0) {
|
|
542
|
+
return {
|
|
543
|
+
...super.config(),
|
|
544
|
+
stega: {
|
|
545
|
+
...this.stegaConfig
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
super.config(newConfig);
|
|
550
|
+
const {
|
|
551
|
+
stegaConfig
|
|
552
|
+
} = splitConfig(newConfig);
|
|
553
|
+
this.stegaConfig = initStegaConfig(stegaConfig, {
|
|
554
|
+
...(this.stegaConfig || {})
|
|
555
|
+
});
|
|
556
|
+
return this;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Clone the client with a new (partial) configuration.
|
|
560
|
+
*
|
|
561
|
+
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
562
|
+
*/
|
|
563
|
+
withConfig(newConfig) {
|
|
564
|
+
return new _SanityStegaClient(__privateGet(this, _httpRequest2), {
|
|
565
|
+
...this.config(),
|
|
566
|
+
...newConfig
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
fetch(query, params) {
|
|
570
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
571
|
+
const {
|
|
572
|
+
filterResponse: originalFilterResponse = true
|
|
573
|
+
} = options;
|
|
574
|
+
return super.fetch(query, params, Object.assign({}, options, {
|
|
575
|
+
filterResponse: false
|
|
576
|
+
})).then(res => {
|
|
577
|
+
const {
|
|
578
|
+
result: _result,
|
|
579
|
+
resultSourceMap
|
|
580
|
+
} = res;
|
|
581
|
+
let result = _result;
|
|
582
|
+
if (this.stegaConfig.enabled) {
|
|
583
|
+
result = stegaEncodeSourceMap(_result, resultSourceMap, this.stegaConfig);
|
|
584
|
+
}
|
|
585
|
+
return originalFilterResponse ? result : {
|
|
586
|
+
...res,
|
|
587
|
+
result
|
|
588
|
+
};
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
_httpRequest2 = new WeakMap();
|
|
593
|
+
let SanityStegaClient = _SanityStegaClient;
|
|
594
|
+
const exp = defineCreateClientExports(envMiddleware, SanityStegaClient);
|
|
595
|
+
const requester = exp.requester;
|
|
596
|
+
const createClient = exp.createClient;
|
|
597
|
+
export { ObservableSanityClient, ObservableSanityStegaClient, SanityClient, SanityStegaClient, createClient, encodeIntoResult, requester, stegaEncodeSourceMap };
|
|
598
|
+
//# sourceMappingURL=stega.browser.js.map
|