@sanity/client 6.11.2 → 6.11.3
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-hi8PGbSU.cjs → browserMiddleware-1MULg59S.cjs} +377 -420
- package/dist/_chunks/{browserMiddleware-hi8PGbSU.cjs.map → browserMiddleware-1MULg59S.cjs.map} +1 -1
- package/dist/_chunks/{browserMiddleware-eLzHI4Fk.js → browserMiddleware-heyg-fDk.js} +377 -420
- package/dist/_chunks/{browserMiddleware-eLzHI4Fk.js.map → browserMiddleware-heyg-fDk.js.map} +1 -1
- package/dist/_chunks/{nodeMiddleware-SFcV9llR.cjs → nodeMiddleware-CHxg1-zH.cjs} +396 -440
- package/dist/_chunks/{nodeMiddleware-SFcV9llR.cjs.map → nodeMiddleware-CHxg1-zH.cjs.map} +1 -1
- package/dist/_chunks/{nodeMiddleware-dn4ZacKV.js → nodeMiddleware-u_fUUnxa.js} +396 -440
- package/dist/_chunks/{nodeMiddleware-dn4ZacKV.js.map → nodeMiddleware-u_fUUnxa.js.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-TYjTkHKU.cjs → resolveEditInfo-dELeeJBE.cjs} +47 -70
- package/dist/_chunks/{resolveEditInfo-TYjTkHKU.cjs.map → resolveEditInfo-dELeeJBE.cjs.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-FaeuCV4M.js → resolveEditInfo-uXvm6eWd.js} +47 -70
- package/dist/_chunks/{resolveEditInfo-FaeuCV4M.js.map → resolveEditInfo-uXvm6eWd.js.map} +1 -1
- package/dist/csm.cjs +20 -30
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js +19 -28
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +8 -10
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +5 -2
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +8 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.cjs +224 -257
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js +221 -249
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +193 -217
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.js +190 -209
- package/dist/stega.js.map +1 -1
- package/package.json +3 -3
- package/umd/sanityClient.js +494 -528
- package/umd/sanityClient.min.js +3 -3
package/dist/stega.browser.js
CHANGED
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import { ObservableSanityClient, defaultConfig, SanityClient, defineCreateClientExports, envMiddleware } from './_chunks/browserMiddleware-
|
|
2
|
-
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/browserMiddleware-
|
|
1
|
+
import { ObservableSanityClient, defaultConfig, SanityClient, defineCreateClientExports, envMiddleware } from './_chunks/browserMiddleware-heyg-fDk.js';
|
|
2
|
+
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/browserMiddleware-heyg-fDk.js';
|
|
3
3
|
import { map } from 'rxjs/operators';
|
|
4
4
|
import { vercelStegaCombine, vercelStegaSplit } from '@vercel/stega';
|
|
5
5
|
export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it';
|
|
6
|
+
|
|
6
7
|
const defaultStegaConfig = {
|
|
7
8
|
enabled: false,
|
|
8
|
-
filter: props => props.filterDefault(props)
|
|
9
|
+
filter: (props) => props.filterDefault(props)
|
|
9
10
|
};
|
|
10
11
|
function splitConfig(config) {
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
-
...clientConfig
|
|
14
|
-
} = config;
|
|
15
|
-
return {
|
|
16
|
-
clientConfig,
|
|
17
|
-
stegaConfig: typeof stega === "boolean" ? {
|
|
18
|
-
enabled: stega
|
|
19
|
-
} : stega
|
|
20
|
-
};
|
|
12
|
+
const { stega = {}, ...clientConfig } = config;
|
|
13
|
+
return { clientConfig, stegaConfig: typeof stega === "boolean" ? { enabled: stega } : stega };
|
|
21
14
|
}
|
|
22
15
|
const initStegaConfig = (config, prevConfig) => {
|
|
23
16
|
const specifiedConfig = Object.assign({}, prevConfig, config);
|
|
24
17
|
const newConfig = Object.assign({}, defaultStegaConfig, specifiedConfig);
|
|
25
18
|
if ("encodeSourceMap" in newConfig) {
|
|
26
|
-
throw new Error(
|
|
19
|
+
throw new Error(
|
|
20
|
+
"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'?"
|
|
21
|
+
);
|
|
27
22
|
}
|
|
28
23
|
if ("encodeSourceMapAtPath" in newConfig) {
|
|
29
|
-
throw new Error(
|
|
24
|
+
throw new Error(
|
|
25
|
+
"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'?"
|
|
26
|
+
);
|
|
30
27
|
}
|
|
31
28
|
if (typeof newConfig.enabled !== "boolean") {
|
|
32
29
|
throw new Error("config.enabled must be a boolean, received ".concat(newConfig.enabled));
|
|
@@ -35,23 +32,21 @@ const initStegaConfig = (config, prevConfig) => {
|
|
|
35
32
|
throw new Error("config.studioUrl must be defined when config.enabled is true");
|
|
36
33
|
}
|
|
37
34
|
if (newConfig.enabled && typeof newConfig.studioUrl !== "string" && typeof newConfig.studioUrl !== "function") {
|
|
38
|
-
throw new Error(
|
|
35
|
+
throw new Error(
|
|
36
|
+
"config.studioUrl must be a string or a function, received ".concat(newConfig.studioUrl)
|
|
37
|
+
);
|
|
39
38
|
}
|
|
40
39
|
return newConfig;
|
|
41
40
|
};
|
|
42
41
|
function splitStegaConfigFromFetchOptions(options, initializedStegaConfig) {
|
|
43
|
-
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} : stega, initializedStegaConfig);
|
|
50
|
-
return {
|
|
51
|
-
fetchOptions,
|
|
52
|
-
stegaConfig
|
|
53
|
-
};
|
|
42
|
+
const { stega = {}, ...fetchOptions } = options;
|
|
43
|
+
const stegaConfig = initStegaConfig(
|
|
44
|
+
typeof stega === "boolean" ? { enabled: stega } : stega,
|
|
45
|
+
initializedStegaConfig
|
|
46
|
+
);
|
|
47
|
+
return { fetchOptions, stegaConfig };
|
|
54
48
|
}
|
|
49
|
+
|
|
55
50
|
const DRAFTS_PREFIX = "drafts.";
|
|
56
51
|
function getPublishedId(id) {
|
|
57
52
|
if (id.startsWith(DRAFTS_PREFIX)) {
|
|
@@ -59,6 +54,7 @@ function getPublishedId(id) {
|
|
|
59
54
|
}
|
|
60
55
|
return id;
|
|
61
56
|
}
|
|
57
|
+
|
|
62
58
|
const reKeySegment = /_key\s*==\s*['"](.*)['"]/;
|
|
63
59
|
function isKeySegment(segment) {
|
|
64
60
|
if (typeof segment === "string") {
|
|
@@ -89,6 +85,7 @@ function toString(path) {
|
|
|
89
85
|
throw new Error("Unsupported path segment `".concat(JSON.stringify(segment), "`"));
|
|
90
86
|
}, "");
|
|
91
87
|
}
|
|
88
|
+
|
|
92
89
|
const ESCAPE = {
|
|
93
90
|
"\f": "\\f",
|
|
94
91
|
"\n": "\\n",
|
|
@@ -106,9 +103,9 @@ const UNESCAPE = {
|
|
|
106
103
|
"\\\\": "\\"
|
|
107
104
|
};
|
|
108
105
|
function jsonPath(path) {
|
|
109
|
-
return "$".concat(path.map(segment => {
|
|
106
|
+
return "$".concat(path.map((segment) => {
|
|
110
107
|
if (typeof segment === "string") {
|
|
111
|
-
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, match => {
|
|
108
|
+
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, (match) => {
|
|
112
109
|
return ESCAPE[match];
|
|
113
110
|
});
|
|
114
111
|
return "['".concat(escapedKey, "']");
|
|
@@ -117,7 +114,7 @@ function jsonPath(path) {
|
|
|
117
114
|
return "[".concat(segment, "]");
|
|
118
115
|
}
|
|
119
116
|
if (segment._key !== "") {
|
|
120
|
-
const escapedKey = segment._key.replace(/['\\]/g, match => {
|
|
117
|
+
const escapedKey = segment._key.replace(/['\\]/g, (match) => {
|
|
121
118
|
return ESCAPE[match];
|
|
122
119
|
});
|
|
123
120
|
return "[?(@._key=='".concat(escapedKey, "')]");
|
|
@@ -131,7 +128,7 @@ function parseJsonPath(path) {
|
|
|
131
128
|
let match;
|
|
132
129
|
while ((match = parseRe.exec(path)) !== null) {
|
|
133
130
|
if (match[1] !== void 0) {
|
|
134
|
-
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, m => {
|
|
131
|
+
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, (m) => {
|
|
135
132
|
return UNESCAPE[m];
|
|
136
133
|
});
|
|
137
134
|
parsed.push(key);
|
|
@@ -142,7 +139,7 @@ function parseJsonPath(path) {
|
|
|
142
139
|
continue;
|
|
143
140
|
}
|
|
144
141
|
if (match[3] !== void 0) {
|
|
145
|
-
const _key = match[3].replace(/\\(\\')/g, m => {
|
|
142
|
+
const _key = match[3].replace(/\\(\\')/g, (m) => {
|
|
146
143
|
return UNESCAPE[m];
|
|
147
144
|
});
|
|
148
145
|
parsed.push({
|
|
@@ -155,7 +152,7 @@ function parseJsonPath(path) {
|
|
|
155
152
|
return parsed;
|
|
156
153
|
}
|
|
157
154
|
function jsonPathToStudioPath(path) {
|
|
158
|
-
return path.map(segment => {
|
|
155
|
+
return path.map((segment) => {
|
|
159
156
|
if (typeof segment === "string") {
|
|
160
157
|
return segment;
|
|
161
158
|
}
|
|
@@ -163,9 +160,7 @@ function jsonPathToStudioPath(path) {
|
|
|
163
160
|
return segment;
|
|
164
161
|
}
|
|
165
162
|
if (segment._key !== "") {
|
|
166
|
-
return {
|
|
167
|
-
_key: segment._key
|
|
168
|
-
};
|
|
163
|
+
return { _key: segment._key };
|
|
169
164
|
}
|
|
170
165
|
if (segment._index !== -1) {
|
|
171
166
|
return segment._index;
|
|
@@ -174,7 +169,7 @@ function jsonPathToStudioPath(path) {
|
|
|
174
169
|
});
|
|
175
170
|
}
|
|
176
171
|
function jsonPathToMappingPath(path) {
|
|
177
|
-
return path.map(segment => {
|
|
172
|
+
return path.map((segment) => {
|
|
178
173
|
if (typeof segment === "string") {
|
|
179
174
|
return segment;
|
|
180
175
|
}
|
|
@@ -187,6 +182,7 @@ function jsonPathToMappingPath(path) {
|
|
|
187
182
|
throw new Error("invalid segment:".concat(JSON.stringify(segment)));
|
|
188
183
|
});
|
|
189
184
|
}
|
|
185
|
+
|
|
190
186
|
function createEditUrl(options) {
|
|
191
187
|
const {
|
|
192
188
|
baseUrl,
|
|
@@ -228,13 +224,19 @@ function createEditUrl(options) {
|
|
|
228
224
|
if (workspace) {
|
|
229
225
|
segments.push(workspace);
|
|
230
226
|
}
|
|
231
|
-
const routerParams = [
|
|
227
|
+
const routerParams = [
|
|
228
|
+
"mode=presentation",
|
|
229
|
+
"id=".concat(id),
|
|
230
|
+
"type=".concat(type),
|
|
231
|
+
"path=".concat(encodeURIComponent(stringifiedPath))
|
|
232
|
+
];
|
|
232
233
|
if (tool) {
|
|
233
234
|
routerParams.push("tool=".concat(tool));
|
|
234
235
|
}
|
|
235
236
|
segments.push("intent", "edit", "".concat(routerParams.join(";"), "?").concat(searchParams));
|
|
236
237
|
return segments.join("/");
|
|
237
238
|
}
|
|
239
|
+
|
|
238
240
|
function resolveMapping(resultPath, csm) {
|
|
239
241
|
if (!(csm == null ? void 0 : csm.mappings)) {
|
|
240
242
|
return void 0;
|
|
@@ -247,70 +249,54 @@ function resolveMapping(resultPath, csm) {
|
|
|
247
249
|
pathSuffix: ""
|
|
248
250
|
};
|
|
249
251
|
}
|
|
250
|
-
const mappings = Object.entries(csm.mappings).filter(
|
|
251
|
-
let [key] = _ref;
|
|
252
|
-
return resultMappingPath.startsWith(key);
|
|
253
|
-
}).sort((_ref2, _ref3) => {
|
|
254
|
-
let [key1] = _ref2;
|
|
255
|
-
let [key2] = _ref3;
|
|
256
|
-
return key2.length - key1.length;
|
|
257
|
-
});
|
|
252
|
+
const mappings = Object.entries(csm.mappings).filter(([key]) => resultMappingPath.startsWith(key)).sort(([key1], [key2]) => key2.length - key1.length);
|
|
258
253
|
if (mappings.length == 0) {
|
|
259
254
|
return void 0;
|
|
260
255
|
}
|
|
261
256
|
const [matchedPath, mapping] = mappings[0];
|
|
262
257
|
const pathSuffix = resultMappingPath.substring(matchedPath.length);
|
|
263
|
-
return {
|
|
264
|
-
mapping,
|
|
265
|
-
matchedPath,
|
|
266
|
-
pathSuffix
|
|
267
|
-
};
|
|
258
|
+
return { mapping, matchedPath, pathSuffix };
|
|
268
259
|
}
|
|
260
|
+
|
|
269
261
|
function resolveStudioBaseRoute(studioUrl) {
|
|
270
262
|
let baseUrl = typeof studioUrl === "string" ? studioUrl : studioUrl.baseUrl;
|
|
271
263
|
if (baseUrl !== "/") {
|
|
272
264
|
baseUrl = baseUrl.replace(/\/$/, "");
|
|
273
265
|
}
|
|
274
266
|
if (typeof studioUrl === "string") {
|
|
275
|
-
return {
|
|
276
|
-
baseUrl
|
|
277
|
-
};
|
|
267
|
+
return { baseUrl };
|
|
278
268
|
}
|
|
279
|
-
return {
|
|
280
|
-
...studioUrl,
|
|
281
|
-
baseUrl
|
|
282
|
-
};
|
|
269
|
+
return { ...studioUrl, baseUrl };
|
|
283
270
|
}
|
|
271
|
+
|
|
284
272
|
function isArray(value) {
|
|
285
273
|
return value !== null && Array.isArray(value);
|
|
286
274
|
}
|
|
275
|
+
|
|
287
276
|
function isRecord(value) {
|
|
288
277
|
return typeof value === "object" && value !== null;
|
|
289
278
|
}
|
|
290
|
-
|
|
291
|
-
|
|
279
|
+
|
|
280
|
+
function walkMap(value, mappingFn, path = []) {
|
|
292
281
|
if (isArray(value)) {
|
|
293
282
|
return value.map((v, idx) => {
|
|
294
283
|
if (isRecord(v)) {
|
|
295
284
|
const _key = v["_key"];
|
|
296
285
|
if (typeof _key === "string") {
|
|
297
|
-
return walkMap(v, mappingFn, path.concat({
|
|
298
|
-
_key,
|
|
299
|
-
_index: idx
|
|
300
|
-
}));
|
|
286
|
+
return walkMap(v, mappingFn, path.concat({ _key, _index: idx }));
|
|
301
287
|
}
|
|
302
288
|
}
|
|
303
289
|
return walkMap(v, mappingFn, path.concat(idx));
|
|
304
290
|
});
|
|
305
291
|
}
|
|
306
292
|
if (isRecord(value)) {
|
|
307
|
-
return Object.fromEntries(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}));
|
|
293
|
+
return Object.fromEntries(
|
|
294
|
+
Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))])
|
|
295
|
+
);
|
|
311
296
|
}
|
|
312
297
|
return mappingFn(value, path);
|
|
313
298
|
}
|
|
299
|
+
|
|
314
300
|
function encodeIntoResult(result, csm, encoder) {
|
|
315
301
|
return walkMap(result, (value, path) => {
|
|
316
302
|
if (typeof value !== "string") {
|
|
@@ -320,10 +306,7 @@ function encodeIntoResult(result, csm, encoder) {
|
|
|
320
306
|
if (!resolveMappingResult) {
|
|
321
307
|
return value;
|
|
322
308
|
}
|
|
323
|
-
const {
|
|
324
|
-
mapping,
|
|
325
|
-
matchedPath
|
|
326
|
-
} = resolveMappingResult;
|
|
309
|
+
const { mapping, matchedPath } = resolveMappingResult;
|
|
327
310
|
if (mapping.type !== "value") {
|
|
328
311
|
return value;
|
|
329
312
|
}
|
|
@@ -343,11 +326,8 @@ function encodeIntoResult(result, csm, encoder) {
|
|
|
343
326
|
});
|
|
344
327
|
});
|
|
345
328
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
sourcePath,
|
|
349
|
-
value
|
|
350
|
-
} = _ref5;
|
|
329
|
+
|
|
330
|
+
const filterDefault = ({ sourcePath, value }) => {
|
|
351
331
|
if (isValidDate(value) || isValidURL(value)) {
|
|
352
332
|
return false;
|
|
353
333
|
}
|
|
@@ -367,7 +347,9 @@ const filterDefault = _ref5 => {
|
|
|
367
347
|
if (endPath === "style" || endPath === "listItem") {
|
|
368
348
|
return false;
|
|
369
349
|
}
|
|
370
|
-
if (sourcePath.some(
|
|
350
|
+
if (sourcePath.some(
|
|
351
|
+
(path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo"
|
|
352
|
+
)) {
|
|
371
353
|
return false;
|
|
372
354
|
}
|
|
373
355
|
if (typeof endPath === "string" && denylist.has(endPath)) {
|
|
@@ -375,7 +357,46 @@ const filterDefault = _ref5 => {
|
|
|
375
357
|
}
|
|
376
358
|
return true;
|
|
377
359
|
};
|
|
378
|
-
const denylist = /* @__PURE__ */new Set([
|
|
360
|
+
const denylist = /* @__PURE__ */ new Set([
|
|
361
|
+
"color",
|
|
362
|
+
"colour",
|
|
363
|
+
"currency",
|
|
364
|
+
"email",
|
|
365
|
+
"format",
|
|
366
|
+
"gid",
|
|
367
|
+
"hex",
|
|
368
|
+
"href",
|
|
369
|
+
"hsl",
|
|
370
|
+
"hsla",
|
|
371
|
+
"icon",
|
|
372
|
+
"id",
|
|
373
|
+
"index",
|
|
374
|
+
"key",
|
|
375
|
+
"language",
|
|
376
|
+
"layout",
|
|
377
|
+
"link",
|
|
378
|
+
"linkAction",
|
|
379
|
+
"locale",
|
|
380
|
+
"lqip",
|
|
381
|
+
"page",
|
|
382
|
+
"path",
|
|
383
|
+
"ref",
|
|
384
|
+
"rgb",
|
|
385
|
+
"rgba",
|
|
386
|
+
"route",
|
|
387
|
+
"secret",
|
|
388
|
+
"slug",
|
|
389
|
+
"status",
|
|
390
|
+
"tag",
|
|
391
|
+
"template",
|
|
392
|
+
"theme",
|
|
393
|
+
"type",
|
|
394
|
+
"unit",
|
|
395
|
+
"url",
|
|
396
|
+
"username",
|
|
397
|
+
"variant",
|
|
398
|
+
"website"
|
|
399
|
+
]);
|
|
379
400
|
function isValidDate(dateString) {
|
|
380
401
|
return Number.isNaN(Number(dateString)) ? Boolean(Date.parse(dateString)) : false;
|
|
381
402
|
}
|
|
@@ -387,21 +408,14 @@ function isValidURL(url) {
|
|
|
387
408
|
}
|
|
388
409
|
return true;
|
|
389
410
|
}
|
|
411
|
+
|
|
390
412
|
const TRUNCATE_LENGTH = 20;
|
|
391
413
|
function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
392
414
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
393
|
-
const {
|
|
394
|
-
filter,
|
|
395
|
-
logger,
|
|
396
|
-
enabled
|
|
397
|
-
} = config;
|
|
415
|
+
const { filter, logger, enabled } = config;
|
|
398
416
|
if (!enabled) {
|
|
399
417
|
const msg = "config.enabled must be true, don't call this function otherwise";
|
|
400
|
-
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), {
|
|
401
|
-
result,
|
|
402
|
-
resultSourceMap,
|
|
403
|
-
config
|
|
404
|
-
});
|
|
418
|
+
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config });
|
|
405
419
|
throw new TypeError(msg);
|
|
406
420
|
}
|
|
407
421
|
if (!resultSourceMap) {
|
|
@@ -414,93 +428,77 @@ function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
|
414
428
|
}
|
|
415
429
|
if (!config.studioUrl) {
|
|
416
430
|
const msg = "config.studioUrl must be defined";
|
|
417
|
-
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), {
|
|
418
|
-
result,
|
|
419
|
-
resultSourceMap,
|
|
420
|
-
config
|
|
421
|
-
});
|
|
431
|
+
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config });
|
|
422
432
|
throw new TypeError(msg);
|
|
423
433
|
}
|
|
424
434
|
const report = {
|
|
425
435
|
encoded: [],
|
|
426
436
|
skipped: []
|
|
427
437
|
};
|
|
428
|
-
const resultWithStega = encodeIntoResult(
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
resultPath,
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
sourcePath,
|
|
443
|
-
resultPath,
|
|
444
|
-
filterDefault,
|
|
445
|
-
sourceDocument,
|
|
446
|
-
value
|
|
447
|
-
})) === false) {
|
|
438
|
+
const resultWithStega = encodeIntoResult(
|
|
439
|
+
result,
|
|
440
|
+
resultSourceMap,
|
|
441
|
+
({ sourcePath, sourceDocument, resultPath, value }) => {
|
|
442
|
+
if ((typeof filter === "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === false) {
|
|
443
|
+
if (logger) {
|
|
444
|
+
report.skipped.push({
|
|
445
|
+
path: prettyPathForLogging(sourcePath),
|
|
446
|
+
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
|
|
447
|
+
length: value.length
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
return value;
|
|
451
|
+
}
|
|
448
452
|
if (logger) {
|
|
449
|
-
report.
|
|
453
|
+
report.encoded.push({
|
|
450
454
|
path: prettyPathForLogging(sourcePath),
|
|
451
455
|
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
|
|
452
456
|
length: value.length
|
|
453
457
|
});
|
|
454
458
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
459
|
+
const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
|
|
460
|
+
typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl
|
|
461
|
+
);
|
|
462
|
+
if (!baseUrl)
|
|
463
|
+
return value;
|
|
464
|
+
const { _id: id, _type: type } = sourceDocument;
|
|
465
|
+
return vercelStegaCombine(
|
|
466
|
+
value,
|
|
467
|
+
{
|
|
468
|
+
origin: "sanity.io",
|
|
469
|
+
href: createEditUrl({
|
|
470
|
+
baseUrl,
|
|
471
|
+
workspace,
|
|
472
|
+
tool,
|
|
473
|
+
id,
|
|
474
|
+
type,
|
|
475
|
+
path: sourcePath
|
|
476
|
+
})
|
|
477
|
+
},
|
|
478
|
+
// We use custom logic to determine if we should skip encoding
|
|
479
|
+
false
|
|
480
|
+
);
|
|
463
481
|
}
|
|
464
|
-
|
|
465
|
-
baseUrl,
|
|
466
|
-
workspace,
|
|
467
|
-
tool
|
|
468
|
-
} = resolveStudioBaseRoute(typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl);
|
|
469
|
-
if (!baseUrl) return value;
|
|
470
|
-
const {
|
|
471
|
-
_id: id,
|
|
472
|
-
_type: type
|
|
473
|
-
} = sourceDocument;
|
|
474
|
-
return vercelStegaCombine(value, {
|
|
475
|
-
origin: "sanity.io",
|
|
476
|
-
href: createEditUrl({
|
|
477
|
-
baseUrl,
|
|
478
|
-
workspace,
|
|
479
|
-
tool,
|
|
480
|
-
id,
|
|
481
|
-
type,
|
|
482
|
-
path: sourcePath
|
|
483
|
-
})
|
|
484
|
-
},
|
|
485
|
-
// We use custom logic to determine if we should skip encoding
|
|
486
|
-
false);
|
|
487
|
-
});
|
|
482
|
+
);
|
|
488
483
|
if (logger) {
|
|
489
484
|
const isSkipping = report.skipped.length;
|
|
490
485
|
const isEncoding = report.encoded.length;
|
|
491
486
|
if (isSkipping || isEncoding) {
|
|
492
|
-
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d(
|
|
493
|
-
|
|
487
|
+
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d(
|
|
488
|
+
"[@sanity/client/stega]: Encoding source map into result"
|
|
489
|
+
);
|
|
490
|
+
(_e = logger.log) == null ? void 0 : _e.call(
|
|
491
|
+
logger,
|
|
492
|
+
"[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length)
|
|
493
|
+
);
|
|
494
494
|
}
|
|
495
495
|
if (report.encoded.length > 0) {
|
|
496
496
|
(_f = logger == null ? void 0 : logger.log) == null ? void 0 : _f.call(logger, "[@sanity/client/stega]: Table of encoded paths");
|
|
497
497
|
(_g = (logger == null ? void 0 : logger.table) || logger.log) == null ? void 0 : _g(report.encoded);
|
|
498
498
|
}
|
|
499
499
|
if (report.skipped.length > 0) {
|
|
500
|
-
const skipped = /* @__PURE__ */new Set();
|
|
501
|
-
for (const {
|
|
502
|
-
path
|
|
503
|
-
} of report.skipped) {
|
|
500
|
+
const skipped = /* @__PURE__ */ new Set();
|
|
501
|
+
for (const { path } of report.skipped) {
|
|
504
502
|
skipped.add(path.replace(reKeySegment, "0").replace(/\[\d+\]/g, "[]"));
|
|
505
503
|
}
|
|
506
504
|
(_h = logger == null ? void 0 : logger.log) == null ? void 0 : _h.call(logger, "[@sanity/client/stega]: List of skipped paths", [...skipped.values()]);
|
|
@@ -514,25 +512,32 @@ function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
|
514
512
|
function prettyPathForLogging(path) {
|
|
515
513
|
return toString(jsonPathToStudioPath(path));
|
|
516
514
|
}
|
|
515
|
+
|
|
517
516
|
function vercelStegaCleanAll(result) {
|
|
518
517
|
try {
|
|
519
|
-
return JSON.parse(
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
518
|
+
return JSON.parse(
|
|
519
|
+
JSON.stringify(result, (key, value) => {
|
|
520
|
+
if (typeof value !== "string")
|
|
521
|
+
return value;
|
|
522
|
+
return vercelStegaSplit(value).cleaned;
|
|
523
|
+
})
|
|
524
|
+
);
|
|
523
525
|
} catch {
|
|
524
526
|
return result;
|
|
525
527
|
}
|
|
526
528
|
}
|
|
529
|
+
|
|
527
530
|
var __accessCheck = (obj, member, msg) => {
|
|
528
|
-
if (!member.has(obj))
|
|
531
|
+
if (!member.has(obj))
|
|
532
|
+
throw TypeError("Cannot " + msg);
|
|
529
533
|
};
|
|
530
534
|
var __privateGet = (obj, member, getter) => {
|
|
531
535
|
__accessCheck(obj, member, "read from private field");
|
|
532
536
|
return getter ? getter.call(obj) : member.get(obj);
|
|
533
537
|
};
|
|
534
538
|
var __privateAdd = (obj, member, value) => {
|
|
535
|
-
if (member.has(obj))
|
|
539
|
+
if (member.has(obj))
|
|
540
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
536
541
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
537
542
|
};
|
|
538
543
|
var __privateSet = (obj, member, value, setter) => {
|
|
@@ -542,12 +547,8 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
542
547
|
};
|
|
543
548
|
var _httpRequest, _httpRequest2;
|
|
544
549
|
const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends ObservableSanityClient {
|
|
545
|
-
constructor(httpRequest) {
|
|
546
|
-
|
|
547
|
-
const {
|
|
548
|
-
clientConfig,
|
|
549
|
-
stegaConfig
|
|
550
|
-
} = splitConfig(config);
|
|
550
|
+
constructor(httpRequest, config = defaultConfig) {
|
|
551
|
+
const { clientConfig, stegaConfig } = splitConfig(config);
|
|
551
552
|
super(httpRequest, clientConfig);
|
|
552
553
|
/**
|
|
553
554
|
* Private properties
|
|
@@ -564,17 +565,9 @@ const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends
|
|
|
564
565
|
}
|
|
565
566
|
config(newConfig) {
|
|
566
567
|
if (newConfig === void 0) {
|
|
567
|
-
return {
|
|
568
|
-
...super.config(),
|
|
569
|
-
stega: {
|
|
570
|
-
...this.stegaConfig
|
|
571
|
-
}
|
|
572
|
-
};
|
|
568
|
+
return { ...super.config(), stega: { ...this.stegaConfig } };
|
|
573
569
|
}
|
|
574
|
-
const {
|
|
575
|
-
clientConfig,
|
|
576
|
-
stegaConfig
|
|
577
|
-
} = splitConfig(newConfig);
|
|
570
|
+
const { clientConfig, stegaConfig } = splitConfig(newConfig);
|
|
578
571
|
super.config(clientConfig);
|
|
579
572
|
this.stegaConfig = initStegaConfig(stegaConfig, this.stegaConfig || {});
|
|
580
573
|
return this;
|
|
@@ -586,56 +579,47 @@ const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends
|
|
|
586
579
|
*/
|
|
587
580
|
withConfig(newConfig) {
|
|
588
581
|
const thisConfig = this.config();
|
|
589
|
-
const {
|
|
590
|
-
stegaConfig
|
|
591
|
-
} = splitConfig(newConfig || {});
|
|
582
|
+
const { stegaConfig } = splitConfig(newConfig || {});
|
|
592
583
|
return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), {
|
|
593
584
|
...thisConfig,
|
|
594
585
|
...newConfig,
|
|
595
586
|
stega: {
|
|
596
|
-
...
|
|
597
|
-
...
|
|
587
|
+
...thisConfig.stega || {},
|
|
588
|
+
...stegaConfig || {}
|
|
598
589
|
}
|
|
599
590
|
});
|
|
600
591
|
}
|
|
601
|
-
fetch(query, _params) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
stegaConfig
|
|
605
|
-
|
|
606
|
-
} = splitStegaConfigFromFetchOptions(_options, this.stegaConfig);
|
|
592
|
+
fetch(query, _params, _options = {}) {
|
|
593
|
+
const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions(
|
|
594
|
+
_options,
|
|
595
|
+
this.stegaConfig
|
|
596
|
+
);
|
|
607
597
|
const params = _params ? vercelStegaCleanAll(_params) : _params;
|
|
608
598
|
if (!stegaConfig.enabled) {
|
|
609
599
|
return super.fetch(query, params, options);
|
|
610
600
|
}
|
|
611
|
-
const {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
};
|
|
627
|
-
}));
|
|
601
|
+
const { filterResponse: originalFilterResponse = true } = options;
|
|
602
|
+
return super.fetch(
|
|
603
|
+
query,
|
|
604
|
+
params,
|
|
605
|
+
Object.assign({}, options, {
|
|
606
|
+
filterResponse: false,
|
|
607
|
+
resultSourceMap: "withKeyArraySelector"
|
|
608
|
+
})
|
|
609
|
+
).pipe(
|
|
610
|
+
map((res) => {
|
|
611
|
+
const { result: _result, resultSourceMap } = res;
|
|
612
|
+
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig);
|
|
613
|
+
return originalFilterResponse ? result : { ...res, result };
|
|
614
|
+
})
|
|
615
|
+
);
|
|
628
616
|
}
|
|
629
617
|
};
|
|
630
618
|
_httpRequest = new WeakMap();
|
|
631
619
|
let ObservableSanityStegaClient = _ObservableSanityStegaClient;
|
|
632
620
|
const _SanityStegaClient = class _SanityStegaClient extends SanityClient {
|
|
633
|
-
constructor(httpRequest) {
|
|
634
|
-
|
|
635
|
-
const {
|
|
636
|
-
clientConfig,
|
|
637
|
-
stegaConfig
|
|
638
|
-
} = splitConfig(config);
|
|
621
|
+
constructor(httpRequest, config = defaultConfig) {
|
|
622
|
+
const { clientConfig, stegaConfig } = splitConfig(config);
|
|
639
623
|
super(httpRequest, clientConfig);
|
|
640
624
|
/**
|
|
641
625
|
* Private properties
|
|
@@ -653,21 +637,11 @@ const _SanityStegaClient = class _SanityStegaClient extends SanityClient {
|
|
|
653
637
|
}
|
|
654
638
|
config(newConfig) {
|
|
655
639
|
if (newConfig === void 0) {
|
|
656
|
-
return {
|
|
657
|
-
...super.config(),
|
|
658
|
-
stega: {
|
|
659
|
-
...this.stegaConfig
|
|
660
|
-
}
|
|
661
|
-
};
|
|
640
|
+
return { ...super.config(), stega: { ...this.stegaConfig } };
|
|
662
641
|
}
|
|
663
|
-
const {
|
|
664
|
-
clientConfig,
|
|
665
|
-
stegaConfig
|
|
666
|
-
} = splitConfig(newConfig);
|
|
642
|
+
const { clientConfig, stegaConfig } = splitConfig(newConfig);
|
|
667
643
|
super.config(clientConfig);
|
|
668
|
-
this.stegaConfig = initStegaConfig(stegaConfig, {
|
|
669
|
-
...(this.stegaConfig || {})
|
|
670
|
-
});
|
|
644
|
+
this.stegaConfig = initStegaConfig(stegaConfig, { ...this.stegaConfig || {} });
|
|
671
645
|
return this;
|
|
672
646
|
}
|
|
673
647
|
/**
|
|
@@ -677,51 +651,49 @@ const _SanityStegaClient = class _SanityStegaClient extends SanityClient {
|
|
|
677
651
|
*/
|
|
678
652
|
withConfig(newConfig) {
|
|
679
653
|
const thisConfig = this.config();
|
|
680
|
-
const {
|
|
681
|
-
stegaConfig
|
|
682
|
-
} = splitConfig(newConfig || {});
|
|
654
|
+
const { stegaConfig } = splitConfig(newConfig || {});
|
|
683
655
|
return new _SanityStegaClient(__privateGet(this, _httpRequest2), {
|
|
684
656
|
...thisConfig,
|
|
685
657
|
...newConfig,
|
|
686
658
|
stega: {
|
|
687
|
-
...
|
|
688
|
-
...
|
|
659
|
+
...thisConfig.stega || {},
|
|
660
|
+
...stegaConfig || {}
|
|
689
661
|
}
|
|
690
662
|
});
|
|
691
663
|
}
|
|
692
|
-
fetch(query, _params) {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
stegaConfig
|
|
696
|
-
|
|
697
|
-
} = splitStegaConfigFromFetchOptions(_options, this.stegaConfig);
|
|
664
|
+
fetch(query, _params, _options = {}) {
|
|
665
|
+
const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions(
|
|
666
|
+
_options,
|
|
667
|
+
this.stegaConfig
|
|
668
|
+
);
|
|
698
669
|
const params = _params ? vercelStegaCleanAll(_params) : _params;
|
|
699
670
|
if (!stegaConfig.enabled) {
|
|
700
671
|
return super.fetch(query, params, options);
|
|
701
672
|
}
|
|
702
|
-
const {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
} = res;
|
|
673
|
+
const { filterResponse: originalFilterResponse = true } = options;
|
|
674
|
+
return super.fetch(
|
|
675
|
+
query,
|
|
676
|
+
params,
|
|
677
|
+
Object.assign({}, options, {
|
|
678
|
+
filterResponse: false,
|
|
679
|
+
resultSourceMap: "withKeyArraySelector"
|
|
680
|
+
})
|
|
681
|
+
).then((res) => {
|
|
682
|
+
const { result: _result, resultSourceMap } = res;
|
|
713
683
|
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig);
|
|
714
|
-
return originalFilterResponse ? result : {
|
|
715
|
-
...res,
|
|
716
|
-
result
|
|
717
|
-
};
|
|
684
|
+
return originalFilterResponse ? result : { ...res, result };
|
|
718
685
|
});
|
|
719
686
|
}
|
|
720
687
|
};
|
|
721
688
|
_httpRequest2 = new WeakMap();
|
|
722
689
|
let SanityStegaClient = _SanityStegaClient;
|
|
723
|
-
|
|
690
|
+
|
|
691
|
+
const exp = defineCreateClientExports(
|
|
692
|
+
envMiddleware,
|
|
693
|
+
SanityStegaClient
|
|
694
|
+
);
|
|
724
695
|
const requester = exp.requester;
|
|
725
696
|
const createClient = exp.createClient;
|
|
697
|
+
|
|
726
698
|
export { ObservableSanityClient, ObservableSanityStegaClient, SanityClient, SanityStegaClient, createClient, encodeIntoResult, requester, stegaEncodeSourceMap, vercelStegaCleanAll };
|
|
727
699
|
//# sourceMappingURL=stega.browser.js.map
|