@sanity/client 7.23.2 → 7.25.0
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 +42 -1
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/index.browser.cjs +26 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +26 -0
- package/dist/index.browser.d.ts +26 -0
- package/dist/index.browser.js +26 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +27 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.cjs +4 -0
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.d.cts +176 -1
- package/dist/stega.browser.d.ts +176 -1
- package/dist/stega.browser.js +4 -0
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +4 -0
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.d.cts +176 -1
- package/dist/stega.d.ts +176 -1
- package/dist/stega.js +4 -0
- package/dist/stega.js.map +1 -1
- package/package.json +2 -1
- package/src/data/dataMethods.ts +40 -0
- package/src/stega/index.ts +2 -1
- package/src/stega/stegaBrand.ts +111 -0
- package/src/stega/stegaClean.ts +23 -2
- package/src/types.ts +26 -0
- package/umd/sanityClient.js +26 -1
- package/umd/sanityClient.min.js +2 -2
package/README.md
CHANGED
|
@@ -77,6 +77,7 @@ export async function updateDocumentTitle(_id, title) {
|
|
|
77
77
|
- [`raw`](#raw)
|
|
78
78
|
- [Fetching Content Source Maps](#fetching-content-source-maps)
|
|
79
79
|
- [Using Visual editing with steganography](#using-visual-editing-with-steganography)
|
|
80
|
+
- [Catching unsafe string comparisons at compile time](#catching-unsafe-string-comparisons-at-compile-time)
|
|
80
81
|
- [Creating Studio edit intent links](#creating-studio-edit-intent-links)
|
|
81
82
|
- [Listening to queries](#listening-to-queries)
|
|
82
83
|
- [Fetch a single document](#fetch-a-single-document)
|
|
@@ -189,7 +190,7 @@ pnpm install @sanity/client
|
|
|
189
190
|
|
|
190
191
|
`const client = createClient(options)`
|
|
191
192
|
|
|
192
|
-
Initializes a new Sanity Client. Required options are `projectId`, `dataset`, and `apiVersion`. [We encourage setting `useCdn` to either `true` or `false`.](https://www.sanity.io/help/js-client-cdn-configuration) The default is `true`. If you're not sure which option to choose we recommend starting with `true` and revise later if you find that you require uncached content. [Our awesome
|
|
193
|
+
Initializes a new Sanity Client. Required options are `projectId`, `dataset`, and `apiVersion`. [We encourage setting `useCdn` to either `true` or `false`.](https://www.sanity.io/help/js-client-cdn-configuration) The default is `true`. If you're not sure which option to choose we recommend starting with `true` and revise later if you find that you require uncached content. [Our awesome Discord community can help guide you on how to avoid stale data tailored to your tech stack and architecture.](https://snty.link/community)
|
|
193
194
|
|
|
194
195
|
#### [ESM](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/)
|
|
195
196
|
|
|
@@ -892,6 +893,46 @@ const result = await client.fetch('*[_type == "video"][0]')
|
|
|
892
893
|
const videoAsset = stegaClean(result.videoAsset)
|
|
893
894
|
```
|
|
894
895
|
|
|
896
|
+
#### Catching unsafe string comparisons at compile time
|
|
897
|
+
|
|
898
|
+
Strings with stega payloads contain invisible characters, so comparing them against string literals fails in surprising ways: `imageLocation === 'left'` is `false` even though `imageLocation` looks exactly like `'left'` when logged. The branded types available on `@sanity/client/stega` turn these bugs into compile errors.
|
|
899
|
+
|
|
900
|
+
If you use [Sanity TypeGen](https://www.sanity.io/docs/sanity-typegen), pass `ClientReturnStega` as the first generic to `client.fetch` and every string in the result that may contain stega payloads is branded as `StegaString`:
|
|
901
|
+
|
|
902
|
+
```ts
|
|
903
|
+
import {createClient} from '@sanity/client'
|
|
904
|
+
import {type ClientReturnStega, stegaClean} from '@sanity/client/stega'
|
|
905
|
+
|
|
906
|
+
const query = `*[_type == "post"][0]{title, imageLocation, "slug": slug.current}`
|
|
907
|
+
const post = await client.fetch<ClientReturnStega<typeof query>>(query)
|
|
908
|
+
|
|
909
|
+
// Rendering strings is allowed, stega payloads are meant to end up in text nodes
|
|
910
|
+
document.querySelector('h1')!.textContent = post.title
|
|
911
|
+
|
|
912
|
+
// Comparing against literals without cleaning is now a compile error:
|
|
913
|
+
// "This comparison appears to be unintentional because the types have no overlap"
|
|
914
|
+
if (post.imageLocation === 'left') {
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
// Cleaning the value removes the brand and recovers the original type, e.g. 'left' | 'right'
|
|
918
|
+
if (stegaClean(post.imageLocation) === 'left') {
|
|
919
|
+
}
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
Properties that are never stega encoded keep their plain string types: keys starting with `_` (`_id`, `_type`, `_createdAt`, `_updatedAt`, `_key`, `_ref` and friends, so narrowing unions on `_type` keeps working), `slug.current` patterns, and Portable Text properties like `style`, `listItem` and `marks`. Everything else is assumed to be "poisoned", even if the stega `filter` skips it at runtime (URLs, dates and such), as a redundant `stegaClean` is harmless while a missing one is a bug.
|
|
923
|
+
|
|
924
|
+
If you type your query results manually, brand them with the `StegaBranded` helper type, or re-type already fetched data with the `stegaBrand` identity function:
|
|
925
|
+
|
|
926
|
+
```ts
|
|
927
|
+
import {type StegaBranded, stegaBrand} from '@sanity/client/stega'
|
|
928
|
+
|
|
929
|
+
const post = await client.fetch<StegaBranded<Post>>(query)
|
|
930
|
+
// or
|
|
931
|
+
const branded = stegaBrand(await loadQuery<Post>(query))
|
|
932
|
+
```
|
|
933
|
+
|
|
934
|
+
Note that branded strings stay assignable to `string`, that's what keeps JSX text nodes, template literals and string methods working, so props typed as plain `string` (like `className` or `href`) still accept them. The brand catches comparisons, `switch` cases and assignments to literal unions.
|
|
935
|
+
|
|
895
936
|
#### Creating Studio edit intent links
|
|
896
937
|
|
|
897
938
|
If you want to create an edit link to something that isn't a string, or a field that isn't rendered directly, like a `slug` used in a URL but not rendered on the page, you can use the `resolveEditUrl` function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stegaClean.cjs","sources":["../../src/util/isRecord.ts","../../node_modules/@vercel/stega/dist/index.mjs","../../src/stega/stegaClean.ts"],"sourcesContent":["/** @internal */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n","var p={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},l={0:8203,1:8204,2:8205,3:65279},d={0:String.fromCodePoint(l[0]),1:String.fromCodePoint(l[1]),2:String.fromCodePoint(l[2]),3:String.fromCodePoint(l[3])},u=new Array(4).fill(String.fromCodePoint(l[0])).join(\"\"),g=String.fromCharCode(0);function A(e){let r=JSON.stringify(e),t=new TextEncoder().encode(r),i=\"\";for(let c=0;c<t.length;c++){let n=t[c];i+=d[n>>6&3]+d[n>>4&3]+d[n>>2&3]+d[n&3]}return u+i}function C(e){let r=JSON.stringify(e);return Array.from(r).map(t=>{let i=t.charCodeAt(0);if(i>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${r} on character ${t} (${i})`);return Array.from(i.toString(16).padStart(2,\"0\")).map(c=>String.fromCodePoint(p[c])).join(\"\")}).join(\"\")}function I(e){return!Number.isNaN(Number(e))||/[a-z]/i.test(e)&&!/\\d+(?:[-:\\/]\\d+){2}(?:T\\d+(?:[-:\\/]\\d+){1,2}(\\.\\d+)?Z?)?/.test(e)?!1:!!Date.parse(e)}function S(e){try{new URL(e,e.startsWith(\"/\")?\"https://acme.com\":void 0)}catch{return!1}return!0}function y(e,r,t=\"auto\"){return t===!0||t===\"auto\"&&(I(e)||S(e))?e:`${e}${A(r)}`}var m=Object.fromEntries(Object.entries(d).map(e=>[e[1],+e[0]])),T=Object.fromEntries(Object.entries(p).map(e=>e.reverse())),h=`${Object.values(p).map(e=>`\\\\u{${e.toString(16)}}`).join(\"\")}`,x=new RegExp(`[${h}]{4,}`,\"gu\");function X(e){let r=e.match(x);if(r)return E(r[0],!0)[0]}function M(e){let r=e.match(x);if(r)return r.map(t=>E(t)).flat()}function E(e,r=!1){let t=Array.from(e),i=1/0,c=-1;for(let n=0;n<t.length;++n)t[n]===u[0]&&t[n+1]===u[1]&&t[n+2]===u[2]&&t[n+3]===u[3]&&(i=Math.min(i,n),c=Math.max(c,n));if(c===-1)return _(t,r);for(let n=i;n<=c;++n)if(!((t.length-n)%4))try{let f=t.slice(n+4),s=new Uint8Array(f.length/4);for(let o=0;o<s.length;o++)s[o]=m[f[o*4]]<<6|m[f[o*4+1]]<<4|m[f[o*4+2]]<<2|m[f[o*4+3]];let a=new TextDecoder().decode(s);if(r){let o=a.indexOf(g);return o===-1&&(o=a.length),[JSON.parse(a.slice(0,o))]}return a.split(g).filter(Boolean).map(o=>JSON.parse(o))}catch{}return[]}function _(e,r){var f;let t=[];for(let s=e.length*.5;s--;){let a=`${T[e[s*2].codePointAt(0)]}${T[e[s*2+1].codePointAt(0)]}`;t.unshift(String.fromCharCode(parseInt(a,16)))}let i=[],c=[t.join(\"\")],n=10;for(;c.length;){let s=c.shift();try{if(i.push(JSON.parse(s)),r)return i}catch(a){if(!n--)throw a;let o=+((f=a.message.match(/\\sposition\\s(\\d+)$/))==null?void 0:f[1]);if(!o)throw a;c.unshift(s.substring(0,o),s.substring(o))}}return i}function P(e){var r;return{cleaned:e.replace(x,\"\"),encoded:((r=e.match(x))==null?void 0:r[0])||\"\"}}function w(e){return e&&JSON.parse(P(JSON.stringify(e)).cleaned)}export{x as VERCEL_STEGA_REGEX,C as legacyStegaEncode,w as vercelStegaClean,y as vercelStegaCombine,X as vercelStegaDecode,M as vercelStegaDecodeAll,A as vercelStegaEncode,P as vercelStegaSplit};\n","import {vercelStegaClean} from '@vercel/stega'\n\n/**\n * Can take a `result` JSON from a `const {result} = client.fetch(query, params, {filterResponse: false})`\n * and remove all stega-encoded data from it.\n * @public\n */\nexport function stegaClean<Result = unknown>(result: Result): Result {\n return vercelStegaClean
|
|
1
|
+
{"version":3,"file":"stegaClean.cjs","sources":["../../src/util/isRecord.ts","../../node_modules/@vercel/stega/dist/index.mjs","../../src/stega/stegaClean.ts"],"sourcesContent":["/** @internal */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n","var p={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},l={0:8203,1:8204,2:8205,3:65279},d={0:String.fromCodePoint(l[0]),1:String.fromCodePoint(l[1]),2:String.fromCodePoint(l[2]),3:String.fromCodePoint(l[3])},u=new Array(4).fill(String.fromCodePoint(l[0])).join(\"\"),g=String.fromCharCode(0);function A(e){let r=JSON.stringify(e),t=new TextEncoder().encode(r),i=\"\";for(let c=0;c<t.length;c++){let n=t[c];i+=d[n>>6&3]+d[n>>4&3]+d[n>>2&3]+d[n&3]}return u+i}function C(e){let r=JSON.stringify(e);return Array.from(r).map(t=>{let i=t.charCodeAt(0);if(i>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${r} on character ${t} (${i})`);return Array.from(i.toString(16).padStart(2,\"0\")).map(c=>String.fromCodePoint(p[c])).join(\"\")}).join(\"\")}function I(e){return!Number.isNaN(Number(e))||/[a-z]/i.test(e)&&!/\\d+(?:[-:\\/]\\d+){2}(?:T\\d+(?:[-:\\/]\\d+){1,2}(\\.\\d+)?Z?)?/.test(e)?!1:!!Date.parse(e)}function S(e){try{new URL(e,e.startsWith(\"/\")?\"https://acme.com\":void 0)}catch{return!1}return!0}function y(e,r,t=\"auto\"){return t===!0||t===\"auto\"&&(I(e)||S(e))?e:`${e}${A(r)}`}var m=Object.fromEntries(Object.entries(d).map(e=>[e[1],+e[0]])),T=Object.fromEntries(Object.entries(p).map(e=>e.reverse())),h=`${Object.values(p).map(e=>`\\\\u{${e.toString(16)}}`).join(\"\")}`,x=new RegExp(`[${h}]{4,}`,\"gu\");function X(e){let r=e.match(x);if(r)return E(r[0],!0)[0]}function M(e){let r=e.match(x);if(r)return r.map(t=>E(t)).flat()}function E(e,r=!1){let t=Array.from(e),i=1/0,c=-1;for(let n=0;n<t.length;++n)t[n]===u[0]&&t[n+1]===u[1]&&t[n+2]===u[2]&&t[n+3]===u[3]&&(i=Math.min(i,n),c=Math.max(c,n));if(c===-1)return _(t,r);for(let n=i;n<=c;++n)if(!((t.length-n)%4))try{let f=t.slice(n+4),s=new Uint8Array(f.length/4);for(let o=0;o<s.length;o++)s[o]=m[f[o*4]]<<6|m[f[o*4+1]]<<4|m[f[o*4+2]]<<2|m[f[o*4+3]];let a=new TextDecoder().decode(s);if(r){let o=a.indexOf(g);return o===-1&&(o=a.length),[JSON.parse(a.slice(0,o))]}return a.split(g).filter(Boolean).map(o=>JSON.parse(o))}catch{}return[]}function _(e,r){var f;let t=[];for(let s=e.length*.5;s--;){let a=`${T[e[s*2].codePointAt(0)]}${T[e[s*2+1].codePointAt(0)]}`;t.unshift(String.fromCharCode(parseInt(a,16)))}let i=[],c=[t.join(\"\")],n=10;for(;c.length;){let s=c.shift();try{if(i.push(JSON.parse(s)),r)return i}catch(a){if(!n--)throw a;let o=+((f=a.message.match(/\\sposition\\s(\\d+)$/))==null?void 0:f[1]);if(!o)throw a;c.unshift(s.substring(0,o),s.substring(o))}}return i}function P(e){var r;return{cleaned:e.replace(x,\"\"),encoded:((r=e.match(x))==null?void 0:r[0])||\"\"}}function w(e){return e&&JSON.parse(P(JSON.stringify(e)).cleaned)}export{x as VERCEL_STEGA_REGEX,C as legacyStegaEncode,w as vercelStegaClean,y as vercelStegaCombine,X as vercelStegaDecode,M as vercelStegaDecodeAll,A as vercelStegaEncode,P as vercelStegaSplit};\n","import {vercelStegaClean} from '@vercel/stega'\n\n/**\n * The result of removing stega-encoded data from a value with `stegaClean()`: strings that were\n * branded as `StegaString` are returned to their original type, everything else is left as-is.\n * @public\n */\nexport type StegaCleaned<T> = 0 extends 1 & T\n ? T\n : T extends {readonly ' stegaBrand': infer Original extends string}\n ? Original\n : T extends string | number | bigint | boolean | null | undefined\n ? T\n : T extends Date | RegExp | ((...args: never[]) => unknown)\n ? T\n : T extends readonly unknown[]\n ? {[Index in keyof T]: StegaCleaned<T[Index]>}\n : T extends object\n ? {[K in keyof T]: StegaCleaned<T[K]>}\n : T\n\n/**\n * Can take a `result` JSON from a `const {result} = client.fetch(query, params, {filterResponse: false})`\n * and remove all stega-encoded data from it.\n * If the result type has strings branded as `StegaString` (by `ClientReturnStega` or `stegaBrand()`),\n * the brand is stripped and the original string type is restored.\n * @public\n */\nexport function stegaClean<Result = unknown>(result: Result): StegaCleaned<Result> {\n return vercelStegaClean(result) as StegaCleaned<Result>\n}\n\n/**\n * Can take a `result` JSON from a `const {result} = client.fetch(query, params, {filterResponse: false})`\n * and remove all stega-encoded data from it.\n * @alpha\n * @deprecated Use `stegaClean` instead\n */\nexport const vercelStegaCleanAll = stegaClean\n"],"names":["vercelStegaClean"],"mappings":";AACO,SAAS,SAAS,OAAkD;AACzE,SAAO,OAAO,SAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;ACHG,IAAC,IAAE,EAAC,GAAE,MAAK,GAAE,MAAK,GAAE,MAAK,GAAE,MAAK,GAAE,MAAK,GAAE,MAAK,GAAE,OAAM,GAAE,MAAK,GAAE,QAAO,GAAE,QAAO,GAAE,QAAO,GAAE,QAAO,GAAE,QAAO,GAAE,QAAO,GAAE,QAAO,GAAE,OAAM,GAAE,IAAE,EAAC,GAAE,MAAK,GAAE,MAAK,GAAE,MAAK,GAAE,MAAK,GAAE,IAAE,EAAC,GAAE,OAAO,cAAc,EAAE,CAAC,CAAC,GAAE,GAAE,OAAO,cAAc,EAAE,CAAC,CAAC,GAAE,GAAE,OAAO,cAAc,EAAE,CAAC,CAAC,GAAE,GAAE,OAAO,cAAc,EAAE,CAAC,CAAC,E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GAAG,EAAE,KAAK,EAAE,CAAC,IAAG,IAAE,IAAI,OAAO,IAAI,CAAC,SAAQ,IAAI;AAA6lC,SAAS,EAAE,GAAE;AAAC,MAAI;AAAE,SAAM,EAAC,SAAQ,EAAE,QAAQ,GAAE,EAAE,GAAE,WAAU,IAAE,EAAE,MAAM,CAAC,MAAI,OAAK,SAAO,EAAE,CAAC,MAAI,GAAE;AAAC;AAAC,SAAS,EAAE,GAAE;AAAC,SAAO,KAAG,KAAK,MAAM,EAAE,KAAK,UAAU,CAAC,CAAC,EAAE,OAAO;AAAC;AC4BlnF,SAAS,WAA6B,QAAsC;AACjF,SAAOA,EAAiB,MAAM;AAChC;AAQO,MAAM,sBAAsB;;;;;","x_google_ignoreList":[1]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stegaClean.js","sources":["../../src/util/isRecord.ts","../../node_modules/@vercel/stega/dist/index.mjs","../../src/stega/stegaClean.ts"],"sourcesContent":["/** @internal */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n","var p={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},l={0:8203,1:8204,2:8205,3:65279},d={0:String.fromCodePoint(l[0]),1:String.fromCodePoint(l[1]),2:String.fromCodePoint(l[2]),3:String.fromCodePoint(l[3])},u=new Array(4).fill(String.fromCodePoint(l[0])).join(\"\"),g=String.fromCharCode(0);function A(e){let r=JSON.stringify(e),t=new TextEncoder().encode(r),i=\"\";for(let c=0;c<t.length;c++){let n=t[c];i+=d[n>>6&3]+d[n>>4&3]+d[n>>2&3]+d[n&3]}return u+i}function C(e){let r=JSON.stringify(e);return Array.from(r).map(t=>{let i=t.charCodeAt(0);if(i>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${r} on character ${t} (${i})`);return Array.from(i.toString(16).padStart(2,\"0\")).map(c=>String.fromCodePoint(p[c])).join(\"\")}).join(\"\")}function I(e){return!Number.isNaN(Number(e))||/[a-z]/i.test(e)&&!/\\d+(?:[-:\\/]\\d+){2}(?:T\\d+(?:[-:\\/]\\d+){1,2}(\\.\\d+)?Z?)?/.test(e)?!1:!!Date.parse(e)}function S(e){try{new URL(e,e.startsWith(\"/\")?\"https://acme.com\":void 0)}catch{return!1}return!0}function y(e,r,t=\"auto\"){return t===!0||t===\"auto\"&&(I(e)||S(e))?e:`${e}${A(r)}`}var m=Object.fromEntries(Object.entries(d).map(e=>[e[1],+e[0]])),T=Object.fromEntries(Object.entries(p).map(e=>e.reverse())),h=`${Object.values(p).map(e=>`\\\\u{${e.toString(16)}}`).join(\"\")}`,x=new RegExp(`[${h}]{4,}`,\"gu\");function X(e){let r=e.match(x);if(r)return E(r[0],!0)[0]}function M(e){let r=e.match(x);if(r)return r.map(t=>E(t)).flat()}function E(e,r=!1){let t=Array.from(e),i=1/0,c=-1;for(let n=0;n<t.length;++n)t[n]===u[0]&&t[n+1]===u[1]&&t[n+2]===u[2]&&t[n+3]===u[3]&&(i=Math.min(i,n),c=Math.max(c,n));if(c===-1)return _(t,r);for(let n=i;n<=c;++n)if(!((t.length-n)%4))try{let f=t.slice(n+4),s=new Uint8Array(f.length/4);for(let o=0;o<s.length;o++)s[o]=m[f[o*4]]<<6|m[f[o*4+1]]<<4|m[f[o*4+2]]<<2|m[f[o*4+3]];let a=new TextDecoder().decode(s);if(r){let o=a.indexOf(g);return o===-1&&(o=a.length),[JSON.parse(a.slice(0,o))]}return a.split(g).filter(Boolean).map(o=>JSON.parse(o))}catch{}return[]}function _(e,r){var f;let t=[];for(let s=e.length*.5;s--;){let a=`${T[e[s*2].codePointAt(0)]}${T[e[s*2+1].codePointAt(0)]}`;t.unshift(String.fromCharCode(parseInt(a,16)))}let i=[],c=[t.join(\"\")],n=10;for(;c.length;){let s=c.shift();try{if(i.push(JSON.parse(s)),r)return i}catch(a){if(!n--)throw a;let o=+((f=a.message.match(/\\sposition\\s(\\d+)$/))==null?void 0:f[1]);if(!o)throw a;c.unshift(s.substring(0,o),s.substring(o))}}return i}function P(e){var r;return{cleaned:e.replace(x,\"\"),encoded:((r=e.match(x))==null?void 0:r[0])||\"\"}}function w(e){return e&&JSON.parse(P(JSON.stringify(e)).cleaned)}export{x as VERCEL_STEGA_REGEX,C as legacyStegaEncode,w as vercelStegaClean,y as vercelStegaCombine,X as vercelStegaDecode,M as vercelStegaDecodeAll,A as vercelStegaEncode,P as vercelStegaSplit};\n","import {vercelStegaClean} from '@vercel/stega'\n\n/**\n * Can take a `result` JSON from a `const {result} = client.fetch(query, params, {filterResponse: false})`\n * and remove all stega-encoded data from it.\n * @public\n */\nexport function stegaClean<Result = unknown>(result: Result): Result {\n return vercelStegaClean
|
|
1
|
+
{"version":3,"file":"stegaClean.js","sources":["../../src/util/isRecord.ts","../../node_modules/@vercel/stega/dist/index.mjs","../../src/stega/stegaClean.ts"],"sourcesContent":["/** @internal */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n","var p={0:8203,1:8204,2:8205,3:8290,4:8291,5:8288,6:65279,7:8289,8:119155,9:119156,a:119157,b:119158,c:119159,d:119160,e:119161,f:119162},l={0:8203,1:8204,2:8205,3:65279},d={0:String.fromCodePoint(l[0]),1:String.fromCodePoint(l[1]),2:String.fromCodePoint(l[2]),3:String.fromCodePoint(l[3])},u=new Array(4).fill(String.fromCodePoint(l[0])).join(\"\"),g=String.fromCharCode(0);function A(e){let r=JSON.stringify(e),t=new TextEncoder().encode(r),i=\"\";for(let c=0;c<t.length;c++){let n=t[c];i+=d[n>>6&3]+d[n>>4&3]+d[n>>2&3]+d[n&3]}return u+i}function C(e){let r=JSON.stringify(e);return Array.from(r).map(t=>{let i=t.charCodeAt(0);if(i>255)throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${r} on character ${t} (${i})`);return Array.from(i.toString(16).padStart(2,\"0\")).map(c=>String.fromCodePoint(p[c])).join(\"\")}).join(\"\")}function I(e){return!Number.isNaN(Number(e))||/[a-z]/i.test(e)&&!/\\d+(?:[-:\\/]\\d+){2}(?:T\\d+(?:[-:\\/]\\d+){1,2}(\\.\\d+)?Z?)?/.test(e)?!1:!!Date.parse(e)}function S(e){try{new URL(e,e.startsWith(\"/\")?\"https://acme.com\":void 0)}catch{return!1}return!0}function y(e,r,t=\"auto\"){return t===!0||t===\"auto\"&&(I(e)||S(e))?e:`${e}${A(r)}`}var m=Object.fromEntries(Object.entries(d).map(e=>[e[1],+e[0]])),T=Object.fromEntries(Object.entries(p).map(e=>e.reverse())),h=`${Object.values(p).map(e=>`\\\\u{${e.toString(16)}}`).join(\"\")}`,x=new RegExp(`[${h}]{4,}`,\"gu\");function X(e){let r=e.match(x);if(r)return E(r[0],!0)[0]}function M(e){let r=e.match(x);if(r)return r.map(t=>E(t)).flat()}function E(e,r=!1){let t=Array.from(e),i=1/0,c=-1;for(let n=0;n<t.length;++n)t[n]===u[0]&&t[n+1]===u[1]&&t[n+2]===u[2]&&t[n+3]===u[3]&&(i=Math.min(i,n),c=Math.max(c,n));if(c===-1)return _(t,r);for(let n=i;n<=c;++n)if(!((t.length-n)%4))try{let f=t.slice(n+4),s=new Uint8Array(f.length/4);for(let o=0;o<s.length;o++)s[o]=m[f[o*4]]<<6|m[f[o*4+1]]<<4|m[f[o*4+2]]<<2|m[f[o*4+3]];let a=new TextDecoder().decode(s);if(r){let o=a.indexOf(g);return o===-1&&(o=a.length),[JSON.parse(a.slice(0,o))]}return a.split(g).filter(Boolean).map(o=>JSON.parse(o))}catch{}return[]}function _(e,r){var f;let t=[];for(let s=e.length*.5;s--;){let a=`${T[e[s*2].codePointAt(0)]}${T[e[s*2+1].codePointAt(0)]}`;t.unshift(String.fromCharCode(parseInt(a,16)))}let i=[],c=[t.join(\"\")],n=10;for(;c.length;){let s=c.shift();try{if(i.push(JSON.parse(s)),r)return i}catch(a){if(!n--)throw a;let o=+((f=a.message.match(/\\sposition\\s(\\d+)$/))==null?void 0:f[1]);if(!o)throw a;c.unshift(s.substring(0,o),s.substring(o))}}return i}function P(e){var r;return{cleaned:e.replace(x,\"\"),encoded:((r=e.match(x))==null?void 0:r[0])||\"\"}}function w(e){return e&&JSON.parse(P(JSON.stringify(e)).cleaned)}export{x as VERCEL_STEGA_REGEX,C as legacyStegaEncode,w as vercelStegaClean,y as vercelStegaCombine,X as vercelStegaDecode,M as vercelStegaDecodeAll,A as vercelStegaEncode,P as vercelStegaSplit};\n","import {vercelStegaClean} from '@vercel/stega'\n\n/**\n * The result of removing stega-encoded data from a value with `stegaClean()`: strings that were\n * branded as `StegaString` are returned to their original type, everything else is left as-is.\n * @public\n */\nexport type StegaCleaned<T> = 0 extends 1 & T\n ? T\n : T extends {readonly ' stegaBrand': infer Original extends string}\n ? Original\n : T extends string | number | bigint | boolean | null | undefined\n ? T\n : T extends Date | RegExp | ((...args: never[]) => unknown)\n ? T\n : T extends readonly unknown[]\n ? {[Index in keyof T]: StegaCleaned<T[Index]>}\n : T extends object\n ? {[K in keyof T]: StegaCleaned<T[K]>}\n : T\n\n/**\n * Can take a `result` JSON from a `const {result} = client.fetch(query, params, {filterResponse: false})`\n * and remove all stega-encoded data from it.\n * If the result type has strings branded as `StegaString` (by `ClientReturnStega` or `stegaBrand()`),\n * the brand is stripped and the original string type is restored.\n * @public\n */\nexport function stegaClean<Result = unknown>(result: Result): StegaCleaned<Result> {\n return vercelStegaClean(result) as StegaCleaned<Result>\n}\n\n/**\n * Can take a `result` JSON from a `const {result} = client.fetch(query, params, {filterResponse: false})`\n * and remove all stega-encoded data from it.\n * @alpha\n * @deprecated Use `stegaClean` instead\n */\nexport const vercelStegaCleanAll = stegaClean\n"],"names":["vercelStegaClean"],"mappings":"AACO,SAAS,SAAS,OAAkD;AACzE,SAAO,OAAO,SAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;ACHG,IAAC,IAAE,EAAC,GAAE,MAAK,GA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E,GAAE,IAAE,QAAO;AAAC,SAAO,MAAI,MAAI,MAAI,WAAS,EAAE,CAAC,KAAG,EAAE,CAAC,KAAG,IAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;AAAE;AAAO,OAAO,YAAY,OAAO,QAAQ,CAAC,EAAE,IAAI,OAAG,CAAC,EAAE,CAAC,GAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAAI,OAAO,YAAY,OAAO,QAAQ,CAAC,EAAE,IAAI,OAAG,EAAE,QAAO,CAAE,CAAC;AAAC,IAAC,IAAE,GAAG,OAAO,OAAO,CAAC,EAAE,IAAI,OAAG,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,IAAG,IAAE,IAAI,OAAO,IAAI,CAAC,SAAQ,IAAI;AAA6lC,SAAS,EAAE,GAAE;AAAC,MAAI;AAAE,SAAM,EAAC,SAAQ,EAAE,QAAQ,GAAE,EAAE,GAAE,WAAU,IAAE,EAAE,MAAM,CAAC,MAAI,OAAK,SAAO,EAAE,CAAC,MAAI,GAAE;AAAC;AAAC,SAAS,EAAE,GAAE;AAAC,SAAO,KAAG,KAAK,MAAM,EAAE,KAAK,UAAU,CAAC,CAAC,EAAE,OAAO;AAAC;AC4BlnF,SAAS,WAA6B,QAAsC;AACjF,SAAOA,EAAiB,MAAM;AAChC;AAQO,MAAM,sBAAsB;","x_google_ignoreList":[1]}
|
package/dist/index.browser.cjs
CHANGED
|
@@ -1126,6 +1126,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
1126
1126
|
tag,
|
|
1127
1127
|
returnQuery,
|
|
1128
1128
|
perspective: options.perspective,
|
|
1129
|
+
variant: options.variant,
|
|
1129
1130
|
resultSourceMap: options.resultSourceMap,
|
|
1130
1131
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
1131
1132
|
cacheMode,
|
|
@@ -1173,7 +1174,25 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
1173
1174
|
perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
|
|
1174
1175
|
...options.query
|
|
1175
1176
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
1176
|
-
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()))
|
|
1177
|
+
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
1178
|
+
const variantOption = options.variant || config.variant;
|
|
1179
|
+
if (typeof variantOption < "u" && (typeof variantOption == "string" && (options.query = {
|
|
1180
|
+
variant: variantOption,
|
|
1181
|
+
...options.query
|
|
1182
|
+
}), typeof variantOption == "object")) {
|
|
1183
|
+
const variantConditions = Object.entries(variantOption), searchParams = variantConditionPairsToSearchParams(variantConditions).slice(0, 1);
|
|
1184
|
+
if (variantConditions.length > 1) {
|
|
1185
|
+
const formatter = new Intl.ListFormat("en");
|
|
1186
|
+
console.warn(
|
|
1187
|
+
`The Sanity client's beta \`variant\` option currently only supports one condition. Dropped: ${formatter.format(variantConditions.slice(1).map(([subject]) => JSON.stringify(subject)))}.`
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
options.query = {
|
|
1191
|
+
...Object.fromEntries(searchParams),
|
|
1192
|
+
...options.query
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
|
|
1177
1196
|
}
|
|
1178
1197
|
const reqOptions = requestOptions(
|
|
1179
1198
|
config,
|
|
@@ -1248,6 +1267,12 @@ const resourceDataBase = (config) => {
|
|
|
1248
1267
|
throw new Error(`Unsupported resource type: ${type.toString()}`);
|
|
1249
1268
|
}
|
|
1250
1269
|
};
|
|
1270
|
+
function variantConditionPairsToSearchParams(variantConditionPairs) {
|
|
1271
|
+
return variantConditionPairs.map(([condition, value]) => [
|
|
1272
|
+
"variantCondition",
|
|
1273
|
+
`${condition}:${value}`
|
|
1274
|
+
]);
|
|
1275
|
+
}
|
|
1251
1276
|
function _generate(client, httpRequest, request) {
|
|
1252
1277
|
const dataset2 = hasDataset(client.config());
|
|
1253
1278
|
return _request(client, httpRequest, {
|