@sanity/client 6.14.1 → 6.14.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.
Files changed (61) hide show
  1. package/dist/_chunks/browserMiddleware-B_0VHs-S.js +1476 -0
  2. package/dist/_chunks/browserMiddleware-B_0VHs-S.js.map +1 -0
  3. package/dist/_chunks/browserMiddleware-wr3kZwY7.cjs +1493 -0
  4. package/dist/_chunks/browserMiddleware-wr3kZwY7.cjs.map +1 -0
  5. package/dist/_chunks/nodeMiddleware-C0pzwo72.js +1493 -0
  6. package/dist/_chunks/nodeMiddleware-C0pzwo72.js.map +1 -0
  7. package/dist/_chunks/nodeMiddleware-SsjaLQfQ.cjs +1510 -0
  8. package/dist/_chunks/nodeMiddleware-SsjaLQfQ.cjs.map +1 -0
  9. package/dist/_chunks/resolveEditInfo-BNCwZySb.cjs +284 -0
  10. package/dist/_chunks/{resolveEditInfo-BB1WiUDY.cjs.map → resolveEditInfo-BNCwZySb.cjs.map} +1 -1
  11. package/dist/_chunks/resolveEditInfo-C01qsbyy.js +285 -0
  12. package/dist/_chunks/{resolveEditInfo-Cf8D1Agp.js.map → resolveEditInfo-C01qsbyy.js.map} +1 -1
  13. package/dist/_chunks/stegaEncodeSourceMap-BbnAw_7a.js +168 -0
  14. package/dist/_chunks/{stegaEncodeSourceMap-DU95idpa.js.map → stegaEncodeSourceMap-BbnAw_7a.js.map} +1 -1
  15. package/dist/_chunks/stegaEncodeSourceMap-D5HvcZ8_.cjs +329 -0
  16. package/dist/_chunks/{stegaEncodeSourceMap-DIcuvN0P.cjs.map → stegaEncodeSourceMap-D5HvcZ8_.cjs.map} +1 -1
  17. package/dist/_chunks/stegaEncodeSourceMap-SLOvEWQZ.cjs +166 -0
  18. package/dist/_chunks/{stegaEncodeSourceMap-8TjLXjYU.cjs.map → stegaEncodeSourceMap-SLOvEWQZ.cjs.map} +1 -1
  19. package/dist/_chunks/stegaEncodeSourceMap-Z_1_DmND.js +330 -0
  20. package/dist/_chunks/{stegaEncodeSourceMap-DLon0Yls.js.map → stegaEncodeSourceMap-Z_1_DmND.js.map} +1 -1
  21. package/dist/csm.cjs +22 -56
  22. package/dist/csm.cjs.map +1 -1
  23. package/dist/csm.js +36 -54
  24. package/dist/csm.js.map +1 -1
  25. package/dist/index.browser.cjs +15 -21
  26. package/dist/index.browser.cjs.map +1 -1
  27. package/dist/index.browser.js +24 -15
  28. package/dist/index.browser.js.map +1 -1
  29. package/dist/index.cjs +15 -21
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.js +24 -15
  33. package/dist/index.js.map +1 -1
  34. package/dist/stega.browser.cjs +12 -17
  35. package/dist/stega.browser.cjs.map +1 -1
  36. package/dist/stega.browser.js +26 -11
  37. package/dist/stega.browser.js.map +1 -1
  38. package/dist/stega.cjs +12 -17
  39. package/dist/stega.cjs.map +1 -1
  40. package/dist/stega.d.ts +6 -0
  41. package/dist/stega.js +26 -11
  42. package/dist/stega.js.map +1 -1
  43. package/package.json +4 -4
  44. package/src/config.ts +1 -1
  45. package/src/types.ts +10 -1
  46. package/umd/sanityClient.js +2676 -3364
  47. package/umd/sanityClient.min.js +3 -3
  48. package/dist/_chunks/browserMiddleware-DhUBf_19.js +0 -1761
  49. package/dist/_chunks/browserMiddleware-DhUBf_19.js.map +0 -1
  50. package/dist/_chunks/browserMiddleware-FpdqDQ1o.cjs +0 -1777
  51. package/dist/_chunks/browserMiddleware-FpdqDQ1o.cjs.map +0 -1
  52. package/dist/_chunks/nodeMiddleware-BSZoKrW0.js +0 -1780
  53. package/dist/_chunks/nodeMiddleware-BSZoKrW0.js.map +0 -1
  54. package/dist/_chunks/nodeMiddleware-DmcqX3kz.cjs +0 -1796
  55. package/dist/_chunks/nodeMiddleware-DmcqX3kz.cjs.map +0 -1
  56. package/dist/_chunks/resolveEditInfo-BB1WiUDY.cjs +0 -422
  57. package/dist/_chunks/resolveEditInfo-Cf8D1Agp.js +0 -406
  58. package/dist/_chunks/stegaEncodeSourceMap-8TjLXjYU.cjs +0 -229
  59. package/dist/_chunks/stegaEncodeSourceMap-DIcuvN0P.cjs +0 -486
  60. package/dist/_chunks/stegaEncodeSourceMap-DLon0Yls.js +0 -482
  61. package/dist/_chunks/stegaEncodeSourceMap-DU95idpa.js +0 -225
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var nodeMiddleware = require("./nodeMiddleware-SsjaLQfQ.cjs"), resolveEditInfo = require("./resolveEditInfo-BNCwZySb.cjs");
3
+ function encodeIntoResult(result, csm, encoder) {
4
+ return resolveEditInfo.walkMap(result, (value, path) => {
5
+ if (typeof value != "string")
6
+ return value;
7
+ const resolveMappingResult = resolveEditInfo.resolveMapping(path, csm);
8
+ if (!resolveMappingResult)
9
+ return value;
10
+ const { mapping, matchedPath } = resolveMappingResult;
11
+ if (mapping.type !== "value" || mapping.source.type !== "documentValue")
12
+ return value;
13
+ const sourceDocument = csm.documents[mapping.source.document], sourcePath = csm.paths[mapping.source.path], matchPathSegments = resolveEditInfo.parseJsonPath(matchedPath), fullSourceSegments = resolveEditInfo.parseJsonPath(sourcePath).concat(path.slice(matchPathSegments.length));
14
+ return encoder({
15
+ sourcePath: fullSourceSegments,
16
+ sourceDocument,
17
+ resultPath: path,
18
+ value
19
+ });
20
+ });
21
+ }
22
+ const filterDefault = ({ sourcePath, value }) => {
23
+ if (isValidDate(value) || isValidURL(value))
24
+ return !1;
25
+ const endPath = sourcePath.at(-1);
26
+ return !(sourcePath.at(-2) === "slug" && endPath === "current" || typeof endPath == "string" && endPath.startsWith("_") || typeof endPath == "number" && sourcePath.at(-2) === "marks" || endPath === "href" && typeof sourcePath.at(-2) == "number" && sourcePath.at(-3) === "markDefs" || endPath === "style" || endPath === "listItem" || sourcePath.some(
27
+ (path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo"
28
+ ) || typeof endPath == "string" && denylist.has(endPath));
29
+ }, denylist = /* @__PURE__ */ new Set([
30
+ "color",
31
+ "colour",
32
+ "currency",
33
+ "email",
34
+ "format",
35
+ "gid",
36
+ "hex",
37
+ "href",
38
+ "hsl",
39
+ "hsla",
40
+ "icon",
41
+ "id",
42
+ "index",
43
+ "key",
44
+ "language",
45
+ "layout",
46
+ "link",
47
+ "linkAction",
48
+ "locale",
49
+ "lqip",
50
+ "page",
51
+ "path",
52
+ "ref",
53
+ "rgb",
54
+ "rgba",
55
+ "route",
56
+ "secret",
57
+ "slug",
58
+ "status",
59
+ "tag",
60
+ "template",
61
+ "theme",
62
+ "type",
63
+ "unit",
64
+ "url",
65
+ "username",
66
+ "variant",
67
+ "website"
68
+ ]);
69
+ function isValidDate(dateString) {
70
+ return /^\d{4}-\d{2}-\d{2}/.test(dateString) ? !!Date.parse(dateString) : !1;
71
+ }
72
+ function isValidURL(url) {
73
+ try {
74
+ new URL(url, url.startsWith("/") ? "https://acme.com" : void 0);
75
+ } catch {
76
+ return !1;
77
+ }
78
+ return !0;
79
+ }
80
+ const TRUNCATE_LENGTH = 20;
81
+ function stegaEncodeSourceMap(result, resultSourceMap, config) {
82
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
83
+ const { filter, logger, enabled } = config;
84
+ if (!enabled) {
85
+ const msg = "config.enabled must be true, don't call this function otherwise";
86
+ throw (_a = logger == null ? void 0 : logger.error) == null || _a.call(logger, `[@sanity/client]: ${msg}`, { result, resultSourceMap, config }), new TypeError(msg);
87
+ }
88
+ if (!resultSourceMap)
89
+ return (_b = logger == null ? void 0 : logger.error) == null || _b.call(logger, "[@sanity/client]: Missing Content Source Map from response body", {
90
+ result,
91
+ resultSourceMap,
92
+ config
93
+ }), result;
94
+ if (!config.studioUrl) {
95
+ const msg = "config.studioUrl must be defined";
96
+ throw (_c = logger == null ? void 0 : logger.error) == null || _c.call(logger, `[@sanity/client]: ${msg}`, { result, resultSourceMap, config }), new TypeError(msg);
97
+ }
98
+ const report = {
99
+ encoded: [],
100
+ skipped: []
101
+ }, resultWithStega = encodeIntoResult(
102
+ result,
103
+ resultSourceMap,
104
+ ({ sourcePath, sourceDocument, resultPath, value }) => {
105
+ if ((typeof filter == "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === !1)
106
+ return logger && report.skipped.push({
107
+ path: prettyPathForLogging(sourcePath),
108
+ value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? "..." : ""}`,
109
+ length: value.length
110
+ }), value;
111
+ logger && report.encoded.push({
112
+ path: prettyPathForLogging(sourcePath),
113
+ value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? "..." : ""}`,
114
+ length: value.length
115
+ });
116
+ const { baseUrl, workspace, tool } = resolveEditInfo.resolveStudioBaseRoute(
117
+ typeof config.studioUrl == "function" ? config.studioUrl(sourceDocument) : config.studioUrl
118
+ );
119
+ if (!baseUrl)
120
+ return value;
121
+ const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
122
+ return nodeMiddleware.b(
123
+ value,
124
+ {
125
+ origin: "sanity.io",
126
+ href: resolveEditInfo.createEditUrl({
127
+ baseUrl,
128
+ workspace,
129
+ tool,
130
+ id,
131
+ type,
132
+ path: sourcePath,
133
+ ...!config.omitCrossDatasetReferenceData && { dataset, projectId }
134
+ })
135
+ },
136
+ // We use custom logic to determine if we should skip encoding
137
+ !1
138
+ );
139
+ }
140
+ );
141
+ if (logger) {
142
+ const isSkipping = report.skipped.length, isEncoding = report.encoded.length;
143
+ if ((isSkipping || isEncoding) && ((_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null || _d("[@sanity/client]: Encoding source map into result"), (_e = logger.log) == null || _e.call(
144
+ logger,
145
+ `[@sanity/client]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`
146
+ )), report.encoded.length > 0 && ((_f = logger == null ? void 0 : logger.log) == null || _f.call(logger, "[@sanity/client]: Table of encoded paths"), (_g = (logger == null ? void 0 : logger.table) || logger.log) == null || _g(report.encoded)), report.skipped.length > 0) {
147
+ const skipped = /* @__PURE__ */ new Set();
148
+ for (const { path } of report.skipped)
149
+ skipped.add(path.replace(resolveEditInfo.reKeySegment, "0").replace(/\[\d+\]/g, "[]"));
150
+ (_h = logger == null ? void 0 : logger.log) == null || _h.call(logger, "[@sanity/client]: List of skipped paths", [...skipped.values()]);
151
+ }
152
+ (isSkipping || isEncoding) && ((_i = logger == null ? void 0 : logger.groupEnd) == null || _i.call(logger));
153
+ }
154
+ return resultWithStega;
155
+ }
156
+ function prettyPathForLogging(path) {
157
+ return resolveEditInfo.toString(resolveEditInfo.jsonPathToStudioPath(path));
158
+ }
159
+ var stegaEncodeSourceMap$1 = /* @__PURE__ */ Object.freeze({
160
+ __proto__: null,
161
+ stegaEncodeSourceMap
162
+ });
163
+ exports.encodeIntoResult = encodeIntoResult;
164
+ exports.stegaEncodeSourceMap = stegaEncodeSourceMap;
165
+ exports.stegaEncodeSourceMap$1 = stegaEncodeSourceMap$1;
166
+ //# sourceMappingURL=stegaEncodeSourceMap-SLOvEWQZ.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"stegaEncodeSourceMap-8TjLXjYU.cjs","sources":["../../src/stega/encodeIntoResult.ts","../../src/stega/filterDefault.ts","../../src/stega/stegaEncodeSourceMap.ts"],"sourcesContent":["import {parseJsonPath} from '../csm/jsonPath'\nimport {resolveMapping} from '../csm/resolveMapping'\nimport type {ContentSourceMap} from '../csm/types'\nimport {walkMap} from '../csm/walkMap'\nimport type {Encoder} from './types'\n\n/**\n * @internal\n */\nexport function encodeIntoResult<Result>(\n result: Result,\n csm: ContentSourceMap,\n encoder: Encoder,\n): Result {\n return walkMap(result, (value, path) => {\n // Only map strings, we could extend this in the future to support other types like integers...\n if (typeof value !== 'string') {\n return value\n }\n\n const resolveMappingResult = resolveMapping(path, csm)\n if (!resolveMappingResult) {\n return value\n }\n\n const {mapping, matchedPath} = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument = csm.documents[mapping.source.document!]\n const sourcePath = csm.paths[mapping.source.path]\n\n const matchPathSegments = parseJsonPath(matchedPath)\n const sourcePathSegments = parseJsonPath(sourcePath)\n const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length))\n\n return encoder({\n sourcePath: fullSourceSegments,\n sourceDocument,\n resultPath: path,\n value,\n })\n }) as Result\n}\n","import type {FilterDefault} from './types'\n\nexport const filterDefault: FilterDefault = ({sourcePath, value}) => {\n // Skips encoding on URL or Date strings, similar to the `skip: 'auto'` parameter in vercelStegaCombine()\n if (isValidDate(value) || isValidURL(value)) {\n return false\n }\n\n const endPath = sourcePath.at(-1)\n // Never encode slugs\n if (sourcePath.at(-2) === 'slug' && endPath === 'current') {\n return false\n }\n\n // Skip underscored keys, needs better heuristics but it works for now\n if (typeof endPath === 'string' && endPath.startsWith('_')) {\n return false\n }\n\n /**\n * Best effort infer Portable Text paths that should not be encoded.\n * Nothing is for certain, and the below implementation may cause paths that aren't Portable Text and otherwise be safe to encode to be skipped.\n * However, that's ok as userland can always opt-in with the `encodeSourceMapAtPath` option and mark known safe paths as such, which will override this heuristic.\n */\n // If the path ends in marks[number] it's likely a PortableTextSpan: https://github.com/portabletext/types/blob/e54eb24f136d8efd51a46c6a190e7c46e79b5380/src/portableText.ts#LL154C16-L154C16\n if (typeof endPath === 'number' && sourcePath.at(-2) === 'marks') {\n return false\n }\n // Or if it's [number].markDefs[number].href it's likely a PortableTextLink: https://github.com/portabletext/types/blob/e54eb24f136d8efd51a46c6a190e7c46e79b5380/src/portableText.ts#L163\n if (\n endPath === 'href' &&\n typeof sourcePath.at(-2) === 'number' &&\n sourcePath.at(-3) === 'markDefs'\n ) {\n return false\n }\n // Otherwise we have to deal with special properties of PortableTextBlock, and we can't confidently know if it's actually a `_type: 'block'` array item or not.\n // All we know is that if it is indeed a block, and we encode the strings on these keys it'll for sure break the PortableText rendering and thus we skip encoding.\n // https://github.com/portabletext/types/blob/e54eb24f136d8efd51a46c6a190e7c46e79b5380/src/portableText.ts#L48-L58\n if (endPath === 'style' || endPath === 'listItem') {\n return false\n }\n\n // Don't encode into anything that is suggested it'll render for SEO in meta tags\n if (\n sourcePath.some(\n (path) => path === 'meta' || path === 'metadata' || path === 'openGraph' || path === 'seo',\n )\n ) {\n return false\n }\n\n // Finally, we ignore a bunch of paths that are typically used for page building\n if (typeof endPath === 'string' && denylist.has(endPath)) {\n return false\n }\n\n return true\n}\n\nconst denylist = new Set([\n 'color',\n 'colour',\n 'currency',\n 'email',\n 'format',\n 'gid',\n 'hex',\n 'href',\n 'hsl',\n 'hsla',\n 'icon',\n 'id',\n 'index',\n 'key',\n 'language',\n 'layout',\n 'link',\n 'linkAction',\n 'locale',\n 'lqip',\n 'page',\n 'path',\n 'ref',\n 'rgb',\n 'rgba',\n 'route',\n 'secret',\n 'slug',\n 'status',\n 'tag',\n 'template',\n 'theme',\n 'type',\n 'unit',\n 'url',\n 'username',\n 'variant',\n 'website',\n])\n\nfunction isValidDate(dateString: string) {\n return /^\\d{4}-\\d{2}-\\d{2}/.test(dateString) ? Boolean(Date.parse(dateString)) : false\n}\n\nfunction isValidURL(url: string) {\n try {\n new URL(url, url.startsWith('/') ? 'https://acme.com' : undefined)\n } catch {\n return false\n }\n return true\n}\n","import {vercelStegaCombine} from '@vercel/stega'\n\nimport {createEditUrl} from '../csm/createEditUrl'\nimport {jsonPathToStudioPath} from '../csm/jsonPath'\nimport {resolveStudioBaseRoute} from '../csm/resolveEditInfo'\nimport {reKeySegment, toString as studioPathToString} from '../csm/studioPath'\nimport {encodeIntoResult} from './encodeIntoResult'\nimport {filterDefault} from './filterDefault'\nimport {ContentSourceMap, ContentSourceMapParsedPath, InitializedStegaConfig} from './types'\n\nconst TRUNCATE_LENGTH = 20\n\n/**\n * Uses `@vercel/stega` to embed edit info JSON into strings in your query result.\n * The JSON payloads are added using invisible characters so they don't show up visually.\n * The edit info is generated from the Content Source Map (CSM) that is returned from Sanity for the query.\n * @public\n */\nexport function stegaEncodeSourceMap<Result = unknown>(\n result: Result,\n resultSourceMap: ContentSourceMap | undefined,\n config: InitializedStegaConfig,\n): Result {\n const {filter, logger, enabled} = config\n if (!enabled) {\n const msg = \"config.enabled must be true, don't call this function otherwise\"\n logger?.error?.(`[@sanity/client]: ${msg}`, {result, resultSourceMap, config})\n throw new TypeError(msg)\n }\n\n if (!resultSourceMap) {\n logger?.error?.('[@sanity/client]: Missing Content Source Map from response body', {\n result,\n resultSourceMap,\n config,\n })\n return result\n }\n\n if (!config.studioUrl) {\n const msg = 'config.studioUrl must be defined'\n logger?.error?.(`[@sanity/client]: ${msg}`, {result, resultSourceMap, config})\n throw new TypeError(msg)\n }\n\n const report: Record<'encoded' | 'skipped', {path: string; length: number; value: string}[]> = {\n encoded: [],\n skipped: [],\n }\n\n const resultWithStega = encodeIntoResult(\n result,\n resultSourceMap,\n ({sourcePath, sourceDocument, resultPath, value}) => {\n // Allow userland to control when to opt-out of encoding\n if (\n (typeof filter === 'function'\n ? filter({sourcePath, resultPath, filterDefault, sourceDocument, value})\n : filterDefault({sourcePath, resultPath, filterDefault, sourceDocument, value})) === false\n ) {\n if (logger) {\n report.skipped.push({\n path: prettyPathForLogging(sourcePath),\n value: `${value.slice(0, TRUNCATE_LENGTH)}${\n value.length > TRUNCATE_LENGTH ? '...' : ''\n }`,\n length: value.length,\n })\n }\n return value\n }\n\n if (logger) {\n report.encoded.push({\n path: prettyPathForLogging(sourcePath),\n value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? '...' : ''}`,\n length: value.length,\n })\n }\n\n const {baseUrl, workspace, tool} = resolveStudioBaseRoute(\n typeof config.studioUrl === 'function'\n ? config.studioUrl(sourceDocument)\n : config.studioUrl!,\n )\n if (!baseUrl) return value\n const {_id: id, _type: type, _projectId: projectId, _dataset: dataset} = sourceDocument\n\n return vercelStegaCombine(\n value,\n {\n origin: 'sanity.io',\n href: createEditUrl({\n baseUrl,\n workspace,\n tool,\n id,\n type,\n path: sourcePath,\n ...(!config.omitCrossDatasetReferenceData && {dataset, projectId}),\n }),\n },\n // We use custom logic to determine if we should skip encoding\n false,\n )\n },\n )\n\n if (logger) {\n const isSkipping = report.skipped.length\n const isEncoding = report.encoded.length\n if (isSkipping || isEncoding) {\n ;(logger?.groupCollapsed || logger.log)?.('[@sanity/client]: Encoding source map into result')\n logger.log?.(\n `[@sanity/client]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`,\n )\n }\n if (report.encoded.length > 0) {\n logger?.log?.(`[@sanity/client]: Table of encoded paths`)\n ;(logger?.table || logger.log)?.(report.encoded)\n }\n if (report.skipped.length > 0) {\n const skipped = new Set<string>()\n for (const {path} of report.skipped) {\n skipped.add(path.replace(reKeySegment, '0').replace(/\\[\\d+\\]/g, '[]'))\n }\n logger?.log?.(`[@sanity/client]: List of skipped paths`, [...skipped.values()])\n }\n\n if (isSkipping || isEncoding) {\n logger?.groupEnd?.()\n }\n }\n\n return resultWithStega\n}\n\nfunction prettyPathForLogging(path: ContentSourceMapParsedPath): string {\n return studioPathToString(jsonPathToStudioPath(path))\n}\n"],"names":["walkMap","resolveMapping","parseJsonPath","resolveStudioBaseRoute","vercelStegaCombine","createEditUrl","reKeySegment","studioPathToString","jsonPathToStudioPath"],"mappings":";;;;;AASgB,SAAA,gBAAA,CACd,MACA,EAAA,GAAA,EACA,OACQ,EAAA;AACR,EAAA,OAAOA,uBAAQ,CAAA,MAAA,EAAQ,CAAC,KAAA,EAAO,IAAS,KAAA;AAEtC,IAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC7B,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAEA,IAAM,MAAA,oBAAA,GAAuBC,8BAAe,CAAA,IAAA,EAAM,GAAG,CAAA,CAAA;AACrD,IAAA,IAAI,CAAC,oBAAsB,EAAA;AACzB,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAEA,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;;;;;"}
1
+ {"version":3,"file":"stegaEncodeSourceMap-SLOvEWQZ.cjs","sources":["../../src/stega/encodeIntoResult.ts","../../src/stega/filterDefault.ts","../../src/stega/stegaEncodeSourceMap.ts"],"sourcesContent":["import {parseJsonPath} from '../csm/jsonPath'\nimport {resolveMapping} from '../csm/resolveMapping'\nimport type {ContentSourceMap} from '../csm/types'\nimport {walkMap} from '../csm/walkMap'\nimport type {Encoder} from './types'\n\n/**\n * @internal\n */\nexport function encodeIntoResult<Result>(\n result: Result,\n csm: ContentSourceMap,\n encoder: Encoder,\n): Result {\n return walkMap(result, (value, path) => {\n // Only map strings, we could extend this in the future to support other types like integers...\n if (typeof value !== 'string') {\n return value\n }\n\n const resolveMappingResult = resolveMapping(path, csm)\n if (!resolveMappingResult) {\n return value\n }\n\n const {mapping, matchedPath} = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument = csm.documents[mapping.source.document!]\n const sourcePath = csm.paths[mapping.source.path]\n\n const matchPathSegments = parseJsonPath(matchedPath)\n const sourcePathSegments = parseJsonPath(sourcePath)\n const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length))\n\n return encoder({\n sourcePath: fullSourceSegments,\n sourceDocument,\n resultPath: path,\n value,\n })\n }) as Result\n}\n","import type {FilterDefault} from './types'\n\nexport const filterDefault: FilterDefault = ({sourcePath, value}) => {\n // Skips encoding on URL or Date strings, similar to the `skip: 'auto'` parameter in vercelStegaCombine()\n if (isValidDate(value) || isValidURL(value)) {\n return false\n }\n\n const endPath = sourcePath.at(-1)\n // Never encode slugs\n if (sourcePath.at(-2) === 'slug' && endPath === 'current') {\n return false\n }\n\n // Skip underscored keys, needs better heuristics but it works for now\n if (typeof endPath === 'string' && endPath.startsWith('_')) {\n return false\n }\n\n /**\n * Best effort infer Portable Text paths that should not be encoded.\n * Nothing is for certain, and the below implementation may cause paths that aren't Portable Text and otherwise be safe to encode to be skipped.\n * However, that's ok as userland can always opt-in with the `encodeSourceMapAtPath` option and mark known safe paths as such, which will override this heuristic.\n */\n // If the path ends in marks[number] it's likely a PortableTextSpan: https://github.com/portabletext/types/blob/e54eb24f136d8efd51a46c6a190e7c46e79b5380/src/portableText.ts#LL154C16-L154C16\n if (typeof endPath === 'number' && sourcePath.at(-2) === 'marks') {\n return false\n }\n // Or if it's [number].markDefs[number].href it's likely a PortableTextLink: https://github.com/portabletext/types/blob/e54eb24f136d8efd51a46c6a190e7c46e79b5380/src/portableText.ts#L163\n if (\n endPath === 'href' &&\n typeof sourcePath.at(-2) === 'number' &&\n sourcePath.at(-3) === 'markDefs'\n ) {\n return false\n }\n // Otherwise we have to deal with special properties of PortableTextBlock, and we can't confidently know if it's actually a `_type: 'block'` array item or not.\n // All we know is that if it is indeed a block, and we encode the strings on these keys it'll for sure break the PortableText rendering and thus we skip encoding.\n // https://github.com/portabletext/types/blob/e54eb24f136d8efd51a46c6a190e7c46e79b5380/src/portableText.ts#L48-L58\n if (endPath === 'style' || endPath === 'listItem') {\n return false\n }\n\n // Don't encode into anything that is suggested it'll render for SEO in meta tags\n if (\n sourcePath.some(\n (path) => path === 'meta' || path === 'metadata' || path === 'openGraph' || path === 'seo',\n )\n ) {\n return false\n }\n\n // Finally, we ignore a bunch of paths that are typically used for page building\n if (typeof endPath === 'string' && denylist.has(endPath)) {\n return false\n }\n\n return true\n}\n\nconst denylist = new Set([\n 'color',\n 'colour',\n 'currency',\n 'email',\n 'format',\n 'gid',\n 'hex',\n 'href',\n 'hsl',\n 'hsla',\n 'icon',\n 'id',\n 'index',\n 'key',\n 'language',\n 'layout',\n 'link',\n 'linkAction',\n 'locale',\n 'lqip',\n 'page',\n 'path',\n 'ref',\n 'rgb',\n 'rgba',\n 'route',\n 'secret',\n 'slug',\n 'status',\n 'tag',\n 'template',\n 'theme',\n 'type',\n 'unit',\n 'url',\n 'username',\n 'variant',\n 'website',\n])\n\nfunction isValidDate(dateString: string) {\n return /^\\d{4}-\\d{2}-\\d{2}/.test(dateString) ? Boolean(Date.parse(dateString)) : false\n}\n\nfunction isValidURL(url: string) {\n try {\n new URL(url, url.startsWith('/') ? 'https://acme.com' : undefined)\n } catch {\n return false\n }\n return true\n}\n","import {vercelStegaCombine} from '@vercel/stega'\n\nimport {createEditUrl} from '../csm/createEditUrl'\nimport {jsonPathToStudioPath} from '../csm/jsonPath'\nimport {resolveStudioBaseRoute} from '../csm/resolveEditInfo'\nimport {reKeySegment, toString as studioPathToString} from '../csm/studioPath'\nimport {encodeIntoResult} from './encodeIntoResult'\nimport {filterDefault} from './filterDefault'\nimport {ContentSourceMap, ContentSourceMapParsedPath, InitializedStegaConfig} from './types'\n\nconst TRUNCATE_LENGTH = 20\n\n/**\n * Uses `@vercel/stega` to embed edit info JSON into strings in your query result.\n * The JSON payloads are added using invisible characters so they don't show up visually.\n * The edit info is generated from the Content Source Map (CSM) that is returned from Sanity for the query.\n * @public\n */\nexport function stegaEncodeSourceMap<Result = unknown>(\n result: Result,\n resultSourceMap: ContentSourceMap | undefined,\n config: InitializedStegaConfig,\n): Result {\n const {filter, logger, enabled} = config\n if (!enabled) {\n const msg = \"config.enabled must be true, don't call this function otherwise\"\n logger?.error?.(`[@sanity/client]: ${msg}`, {result, resultSourceMap, config})\n throw new TypeError(msg)\n }\n\n if (!resultSourceMap) {\n logger?.error?.('[@sanity/client]: Missing Content Source Map from response body', {\n result,\n resultSourceMap,\n config,\n })\n return result\n }\n\n if (!config.studioUrl) {\n const msg = 'config.studioUrl must be defined'\n logger?.error?.(`[@sanity/client]: ${msg}`, {result, resultSourceMap, config})\n throw new TypeError(msg)\n }\n\n const report: Record<'encoded' | 'skipped', {path: string; length: number; value: string}[]> = {\n encoded: [],\n skipped: [],\n }\n\n const resultWithStega = encodeIntoResult(\n result,\n resultSourceMap,\n ({sourcePath, sourceDocument, resultPath, value}) => {\n // Allow userland to control when to opt-out of encoding\n if (\n (typeof filter === 'function'\n ? filter({sourcePath, resultPath, filterDefault, sourceDocument, value})\n : filterDefault({sourcePath, resultPath, filterDefault, sourceDocument, value})) === false\n ) {\n if (logger) {\n report.skipped.push({\n path: prettyPathForLogging(sourcePath),\n value: `${value.slice(0, TRUNCATE_LENGTH)}${\n value.length > TRUNCATE_LENGTH ? '...' : ''\n }`,\n length: value.length,\n })\n }\n return value\n }\n\n if (logger) {\n report.encoded.push({\n path: prettyPathForLogging(sourcePath),\n value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? '...' : ''}`,\n length: value.length,\n })\n }\n\n const {baseUrl, workspace, tool} = resolveStudioBaseRoute(\n typeof config.studioUrl === 'function'\n ? config.studioUrl(sourceDocument)\n : config.studioUrl!,\n )\n if (!baseUrl) return value\n const {_id: id, _type: type, _projectId: projectId, _dataset: dataset} = sourceDocument\n\n return vercelStegaCombine(\n value,\n {\n origin: 'sanity.io',\n href: createEditUrl({\n baseUrl,\n workspace,\n tool,\n id,\n type,\n path: sourcePath,\n ...(!config.omitCrossDatasetReferenceData && {dataset, projectId}),\n }),\n },\n // We use custom logic to determine if we should skip encoding\n false,\n )\n },\n )\n\n if (logger) {\n const isSkipping = report.skipped.length\n const isEncoding = report.encoded.length\n if (isSkipping || isEncoding) {\n ;(logger?.groupCollapsed || logger.log)?.('[@sanity/client]: Encoding source map into result')\n logger.log?.(\n `[@sanity/client]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`,\n )\n }\n if (report.encoded.length > 0) {\n logger?.log?.(`[@sanity/client]: Table of encoded paths`)\n ;(logger?.table || logger.log)?.(report.encoded)\n }\n if (report.skipped.length > 0) {\n const skipped = new Set<string>()\n for (const {path} of report.skipped) {\n skipped.add(path.replace(reKeySegment, '0').replace(/\\[\\d+\\]/g, '[]'))\n }\n logger?.log?.(`[@sanity/client]: List of skipped paths`, [...skipped.values()])\n }\n\n if (isSkipping || isEncoding) {\n logger?.groupEnd?.()\n }\n }\n\n return resultWithStega\n}\n\nfunction prettyPathForLogging(path: ContentSourceMapParsedPath): string {\n return studioPathToString(jsonPathToStudioPath(path))\n}\n"],"names":["walkMap","resolveMapping","parseJsonPath","resolveStudioBaseRoute","vercelStegaCombine","createEditUrl","reKeySegment","studioPathToString","jsonPathToStudioPath"],"mappings":";;AASgB,SAAA,iBACd,QACA,KACA,SACQ;AACR,SAAOA,wBAAQ,QAAQ,CAAC,OAAO,SAAS;AAEtC,QAAI,OAAO,SAAU;AACZ,aAAA;AAGH,UAAA,uBAAuBC,gBAAAA,eAAe,MAAM,GAAG;AACrD,QAAI,CAAC;AACI,aAAA;AAGH,UAAA,EAAC,SAAS,YAAe,IAAA;AAK/B,QAJI,QAAQ,SAAS,WAIjB,QAAQ,OAAO,SAAS;AACnB,aAAA;AAGH,UAAA,iBAAiB,IAAI,UAAU,QAAQ,OAAO,QAAS,GACvD,aAAa,IAAI,MAAM,QAAQ,OAAO,IAAI,GAE1C,oBAAoBC,gBAAc,cAAA,WAAW,GAE7C,qBADqBA,gBAAc,cAAA,UAAU,EACL,OAAO,KAAK,MAAM,kBAAkB,MAAM,CAAC;AAEzF,WAAO,QAAQ;AAAA,MACb,YAAY;AAAA,MACZ;AAAA,MACA,YAAY;AAAA,MACZ;AAAA,IAAA,CACD;AAAA,EAAA,CACF;AACH;AC9CO,MAAM,gBAA+B,CAAC,EAAC,YAAY,YAAW;AAEnE,MAAI,YAAY,KAAK,KAAK,WAAW,KAAK;AACjC,WAAA;AAGH,QAAA,UAAU,WAAW,GAAG,EAAE;AA6ChC,SA3CI,aAAW,GAAG,EAAE,MAAM,UAAU,YAAY,aAK5C,OAAO,WAAY,YAAY,QAAQ,WAAW,GAAG,KAUrD,OAAO,WAAY,YAAY,WAAW,GAAG,EAAE,MAAM,WAKvD,YAAY,UACZ,OAAO,WAAW,GAAG,EAAE,KAAM,YAC7B,WAAW,GAAG,EAAE,MAAM,cAOpB,YAAY,WAAW,YAAY,cAMrC,WAAW;AAAA,IACT,CAAC,SAAS,SAAS,UAAU,SAAS,cAAc,SAAS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AC;AACtD;;;;;;;;"}
@@ -0,0 +1,330 @@
1
+ import { g as b } from "./browserMiddleware-B_0VHs-S.js";
2
+ const reKeySegment = /_key\s*==\s*['"](.*)['"]/;
3
+ function isKeySegment(segment) {
4
+ return typeof segment == "string" ? reKeySegment.test(segment.trim()) : typeof segment == "object" && "_key" in segment;
5
+ }
6
+ function toString(path) {
7
+ if (!Array.isArray(path))
8
+ throw new Error("Path is not an array");
9
+ return path.reduce((target, segment, i) => {
10
+ const segmentType = typeof segment;
11
+ if (segmentType === "number")
12
+ return `${target}[${segment}]`;
13
+ if (segmentType === "string")
14
+ return `${target}${i === 0 ? "" : "."}${segment}`;
15
+ if (isKeySegment(segment) && segment._key)
16
+ return `${target}[_key=="${segment._key}"]`;
17
+ if (Array.isArray(segment)) {
18
+ const [from, to] = segment;
19
+ return `${target}[${from}:${to}]`;
20
+ }
21
+ throw new Error(`Unsupported path segment \`${JSON.stringify(segment)}\``);
22
+ }, "");
23
+ }
24
+ const ESCAPE = {
25
+ "\f": "\\f",
26
+ "\n": "\\n",
27
+ "\r": "\\r",
28
+ " ": "\\t",
29
+ "'": "\\'",
30
+ "\\": "\\\\"
31
+ }, UNESCAPE = {
32
+ "\\f": "\f",
33
+ "\\n": `
34
+ `,
35
+ "\\r": "\r",
36
+ "\\t": " ",
37
+ "\\'": "'",
38
+ "\\\\": "\\"
39
+ };
40
+ function jsonPath(path) {
41
+ return `$${path.map((segment) => typeof segment == "string" ? `['${segment.replace(/[\f\n\r\t'\\]/g, (match) => ESCAPE[match])}']` : typeof segment == "number" ? `[${segment}]` : segment._key !== "" ? `[?(@._key=='${segment._key.replace(/['\\]/g, (match) => ESCAPE[match])}')]` : `[${segment._index}]`).join("")}`;
42
+ }
43
+ function parseJsonPath(path) {
44
+ const parsed = [], parseRe = /\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;
45
+ let match;
46
+ for (; (match = parseRe.exec(path)) !== null; ) {
47
+ if (match[1] !== void 0) {
48
+ const key = match[1].replace(/\\(\\|f|n|r|t|')/g, (m) => UNESCAPE[m]);
49
+ parsed.push(key);
50
+ continue;
51
+ }
52
+ if (match[2] !== void 0) {
53
+ parsed.push(parseInt(match[2], 10));
54
+ continue;
55
+ }
56
+ if (match[3] !== void 0) {
57
+ const _key = match[3].replace(/\\(\\')/g, (m) => UNESCAPE[m]);
58
+ parsed.push({
59
+ _key,
60
+ _index: -1
61
+ });
62
+ continue;
63
+ }
64
+ }
65
+ return parsed;
66
+ }
67
+ function jsonPathToStudioPath(path) {
68
+ return path.map((segment) => {
69
+ if (typeof segment == "string" || typeof segment == "number")
70
+ return segment;
71
+ if (segment._key !== "")
72
+ return { _key: segment._key };
73
+ if (segment._index !== -1)
74
+ return segment._index;
75
+ throw new Error(`invalid segment:${JSON.stringify(segment)}`);
76
+ });
77
+ }
78
+ function jsonPathToMappingPath(path) {
79
+ return path.map((segment) => {
80
+ if (typeof segment == "string" || typeof segment == "number")
81
+ return segment;
82
+ if (segment._index !== -1)
83
+ return segment._index;
84
+ throw new Error(`invalid segment:${JSON.stringify(segment)}`);
85
+ });
86
+ }
87
+ function resolveMapping(resultPath, csm) {
88
+ if (!(csm != null && csm.mappings))
89
+ return;
90
+ const resultMappingPath = jsonPath(jsonPathToMappingPath(resultPath));
91
+ if (csm.mappings[resultMappingPath] !== void 0)
92
+ return {
93
+ mapping: csm.mappings[resultMappingPath],
94
+ matchedPath: resultMappingPath,
95
+ pathSuffix: ""
96
+ };
97
+ const mappings = Object.entries(csm.mappings).filter(([key]) => resultMappingPath.startsWith(key)).sort(([key1], [key2]) => key2.length - key1.length);
98
+ if (mappings.length == 0)
99
+ return;
100
+ const [matchedPath, mapping] = mappings[0], pathSuffix = resultMappingPath.substring(matchedPath.length);
101
+ return { mapping, matchedPath, pathSuffix };
102
+ }
103
+ function isArray(value) {
104
+ return value !== null && Array.isArray(value);
105
+ }
106
+ function isRecord(value) {
107
+ return typeof value == "object" && value !== null;
108
+ }
109
+ function walkMap(value, mappingFn, path = []) {
110
+ return isArray(value) ? value.map((v, idx) => {
111
+ if (isRecord(v)) {
112
+ const _key = v._key;
113
+ if (typeof _key == "string")
114
+ return walkMap(v, mappingFn, path.concat({ _key, _index: idx }));
115
+ }
116
+ return walkMap(v, mappingFn, path.concat(idx));
117
+ }) : isRecord(value) ? Object.fromEntries(
118
+ Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))])
119
+ ) : mappingFn(value, path);
120
+ }
121
+ function encodeIntoResult(result, csm, encoder) {
122
+ return walkMap(result, (value, path) => {
123
+ if (typeof value != "string")
124
+ return value;
125
+ const resolveMappingResult = resolveMapping(path, csm);
126
+ if (!resolveMappingResult)
127
+ return value;
128
+ const { mapping, matchedPath } = resolveMappingResult;
129
+ if (mapping.type !== "value" || mapping.source.type !== "documentValue")
130
+ return value;
131
+ const sourceDocument = csm.documents[mapping.source.document], sourcePath = csm.paths[mapping.source.path], matchPathSegments = parseJsonPath(matchedPath), fullSourceSegments = parseJsonPath(sourcePath).concat(path.slice(matchPathSegments.length));
132
+ return encoder({
133
+ sourcePath: fullSourceSegments,
134
+ sourceDocument,
135
+ resultPath: path,
136
+ value
137
+ });
138
+ });
139
+ }
140
+ const DRAFTS_PREFIX = "drafts.";
141
+ function getPublishedId(id) {
142
+ return id.startsWith(DRAFTS_PREFIX) ? id.slice(DRAFTS_PREFIX.length) : id;
143
+ }
144
+ function createEditUrl(options) {
145
+ const {
146
+ baseUrl,
147
+ workspace: _workspace = "default",
148
+ tool: _tool = "default",
149
+ id: _id,
150
+ type,
151
+ path,
152
+ projectId,
153
+ dataset
154
+ } = options;
155
+ if (!baseUrl)
156
+ throw new Error("baseUrl is required");
157
+ if (!path)
158
+ throw new Error("path is required");
159
+ if (!_id)
160
+ throw new Error("id is required");
161
+ if (baseUrl !== "/" && baseUrl.endsWith("/"))
162
+ throw new Error("baseUrl must not end with a slash");
163
+ const workspace = _workspace === "default" ? void 0 : _workspace, tool = _tool === "default" ? void 0 : _tool, id = getPublishedId(_id), stringifiedPath = Array.isArray(path) ? toString(jsonPathToStudioPath(path)) : path, searchParams = new URLSearchParams({
164
+ baseUrl,
165
+ id,
166
+ type,
167
+ path: stringifiedPath
168
+ });
169
+ workspace && searchParams.set("workspace", workspace), tool && searchParams.set("tool", tool), projectId && searchParams.set("projectId", projectId), dataset && searchParams.set("dataset", dataset);
170
+ const segments = [baseUrl === "/" ? "" : baseUrl];
171
+ workspace && segments.push(workspace);
172
+ const routerParams = [
173
+ "mode=presentation",
174
+ `id=${id}`,
175
+ `type=${type}`,
176
+ `path=${encodeURIComponent(stringifiedPath)}`
177
+ ];
178
+ return tool && routerParams.push(`tool=${tool}`), segments.push("intent", "edit", `${routerParams.join(";")}?${searchParams}`), segments.join("/");
179
+ }
180
+ function resolveStudioBaseRoute(studioUrl) {
181
+ let baseUrl = typeof studioUrl == "string" ? studioUrl : studioUrl.baseUrl;
182
+ return baseUrl !== "/" && (baseUrl = baseUrl.replace(/\/$/, "")), typeof studioUrl == "string" ? { baseUrl } : { ...studioUrl, baseUrl };
183
+ }
184
+ const filterDefault = ({ sourcePath, value }) => {
185
+ if (isValidDate(value) || isValidURL(value))
186
+ return !1;
187
+ const endPath = sourcePath.at(-1);
188
+ return !(sourcePath.at(-2) === "slug" && endPath === "current" || typeof endPath == "string" && endPath.startsWith("_") || typeof endPath == "number" && sourcePath.at(-2) === "marks" || endPath === "href" && typeof sourcePath.at(-2) == "number" && sourcePath.at(-3) === "markDefs" || endPath === "style" || endPath === "listItem" || sourcePath.some(
189
+ (path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo"
190
+ ) || typeof endPath == "string" && denylist.has(endPath));
191
+ }, denylist = /* @__PURE__ */ new Set([
192
+ "color",
193
+ "colour",
194
+ "currency",
195
+ "email",
196
+ "format",
197
+ "gid",
198
+ "hex",
199
+ "href",
200
+ "hsl",
201
+ "hsla",
202
+ "icon",
203
+ "id",
204
+ "index",
205
+ "key",
206
+ "language",
207
+ "layout",
208
+ "link",
209
+ "linkAction",
210
+ "locale",
211
+ "lqip",
212
+ "page",
213
+ "path",
214
+ "ref",
215
+ "rgb",
216
+ "rgba",
217
+ "route",
218
+ "secret",
219
+ "slug",
220
+ "status",
221
+ "tag",
222
+ "template",
223
+ "theme",
224
+ "type",
225
+ "unit",
226
+ "url",
227
+ "username",
228
+ "variant",
229
+ "website"
230
+ ]);
231
+ function isValidDate(dateString) {
232
+ return /^\d{4}-\d{2}-\d{2}/.test(dateString) ? !!Date.parse(dateString) : !1;
233
+ }
234
+ function isValidURL(url) {
235
+ try {
236
+ new URL(url, url.startsWith("/") ? "https://acme.com" : void 0);
237
+ } catch {
238
+ return !1;
239
+ }
240
+ return !0;
241
+ }
242
+ const TRUNCATE_LENGTH = 20;
243
+ function stegaEncodeSourceMap(result, resultSourceMap, config) {
244
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
245
+ const { filter, logger, enabled } = config;
246
+ if (!enabled) {
247
+ const msg = "config.enabled must be true, don't call this function otherwise";
248
+ throw (_a = logger == null ? void 0 : logger.error) == null || _a.call(logger, `[@sanity/client]: ${msg}`, { result, resultSourceMap, config }), new TypeError(msg);
249
+ }
250
+ if (!resultSourceMap)
251
+ return (_b = logger == null ? void 0 : logger.error) == null || _b.call(logger, "[@sanity/client]: Missing Content Source Map from response body", {
252
+ result,
253
+ resultSourceMap,
254
+ config
255
+ }), result;
256
+ if (!config.studioUrl) {
257
+ const msg = "config.studioUrl must be defined";
258
+ throw (_c = logger == null ? void 0 : logger.error) == null || _c.call(logger, `[@sanity/client]: ${msg}`, { result, resultSourceMap, config }), new TypeError(msg);
259
+ }
260
+ const report = {
261
+ encoded: [],
262
+ skipped: []
263
+ }, resultWithStega = encodeIntoResult(
264
+ result,
265
+ resultSourceMap,
266
+ ({ sourcePath, sourceDocument, resultPath, value }) => {
267
+ if ((typeof filter == "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === !1)
268
+ return logger && report.skipped.push({
269
+ path: prettyPathForLogging(sourcePath),
270
+ value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? "..." : ""}`,
271
+ length: value.length
272
+ }), value;
273
+ logger && report.encoded.push({
274
+ path: prettyPathForLogging(sourcePath),
275
+ value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? "..." : ""}`,
276
+ length: value.length
277
+ });
278
+ const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
279
+ typeof config.studioUrl == "function" ? config.studioUrl(sourceDocument) : config.studioUrl
280
+ );
281
+ if (!baseUrl)
282
+ return value;
283
+ const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
284
+ return b(
285
+ value,
286
+ {
287
+ origin: "sanity.io",
288
+ href: createEditUrl({
289
+ baseUrl,
290
+ workspace,
291
+ tool,
292
+ id,
293
+ type,
294
+ path: sourcePath,
295
+ ...!config.omitCrossDatasetReferenceData && { dataset, projectId }
296
+ })
297
+ },
298
+ // We use custom logic to determine if we should skip encoding
299
+ !1
300
+ );
301
+ }
302
+ );
303
+ if (logger) {
304
+ const isSkipping = report.skipped.length, isEncoding = report.encoded.length;
305
+ if ((isSkipping || isEncoding) && ((_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null || _d("[@sanity/client]: Encoding source map into result"), (_e = logger.log) == null || _e.call(
306
+ logger,
307
+ `[@sanity/client]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`
308
+ )), report.encoded.length > 0 && ((_f = logger == null ? void 0 : logger.log) == null || _f.call(logger, "[@sanity/client]: Table of encoded paths"), (_g = (logger == null ? void 0 : logger.table) || logger.log) == null || _g(report.encoded)), report.skipped.length > 0) {
309
+ const skipped = /* @__PURE__ */ new Set();
310
+ for (const { path } of report.skipped)
311
+ skipped.add(path.replace(reKeySegment, "0").replace(/\[\d+\]/g, "[]"));
312
+ (_h = logger == null ? void 0 : logger.log) == null || _h.call(logger, "[@sanity/client]: List of skipped paths", [...skipped.values()]);
313
+ }
314
+ (isSkipping || isEncoding) && ((_i = logger == null ? void 0 : logger.groupEnd) == null || _i.call(logger));
315
+ }
316
+ return resultWithStega;
317
+ }
318
+ function prettyPathForLogging(path) {
319
+ return toString(jsonPathToStudioPath(path));
320
+ }
321
+ var stegaEncodeSourceMap$1 = /* @__PURE__ */ Object.freeze({
322
+ __proto__: null,
323
+ stegaEncodeSourceMap
324
+ });
325
+ export {
326
+ stegaEncodeSourceMap$1 as a,
327
+ encodeIntoResult as e,
328
+ stegaEncodeSourceMap as s
329
+ };
330
+ //# sourceMappingURL=stegaEncodeSourceMap-Z_1_DmND.js.map