@sanity/client
Advanced tools
| import type {Any, ClientReturn} from '@sanity/client' | ||
| /** | ||
| * A string that might contain stega-encoded data, and is unsafe to compare against string literals | ||
| * until it's been cleaned with `stegaClean()`. | ||
| * | ||
| * The type intersects a template literal that has a human readable suffix, with a brand property | ||
| * that holds the original string type: | ||
| * - The suffix makes TypeScript report "This comparison appears to be unintentional" (TS2367) when | ||
| * the string is compared to a literal (`===`, `switch` cases), and makes it unassignable to | ||
| * literal unions like `'left' | 'right'`, while keeping it assignable to `string` so rendering, | ||
| * interpolation and string methods keep working. The suffix is a type-level fiction, the runtime | ||
| * value never ends with that text. | ||
| * - The brand property preserves the original type so `stegaClean()` can recover it exactly. It's | ||
| * a string-keyed property rather than a `unique symbol` so that branded types stay structurally | ||
| * compatible across duplicated copies of `@sanity/client` in `node_modules`. It only exists in | ||
| * the type system and is never present at runtime. | ||
| * | ||
| * @beta | ||
| */ | ||
| export type StegaString<T extends string = string> = | ||
| `${T} (may contain hidden stega characters)` & { | ||
| readonly ' stegaBrand': T | ||
| } | ||
| /** | ||
| * Deeply brands the string properties of a query result as `StegaString`, marking them as | ||
| * potentially containing stega-encoded data. | ||
| * | ||
| * String properties that the stega encoder is guaranteed to never encode keep their plain type: | ||
| * - keys starting with `_` (`_id`, `_type`, `_createdAt`, `_updatedAt`, `_key`, `_ref`, `_rev` and | ||
| * so on), which also preserves discriminated union narrowing on `_type` | ||
| * - `slug.current` patterns: a `current` key directly under a `slug` key, as well as string valued | ||
| * `slug` keys (covering `"slug": slug.current` projections) | ||
| * - Portable Text internals: the encoder only visits `children` of `_type: 'block'` objects and | ||
| * `text` of `_type: 'span'` objects, so properties like `style`, `listItem` and `marks` stay | ||
| * plain | ||
| * | ||
| * Every other string is assumed to be "poisoned", even if the runtime `filter` happens to skip it | ||
| * (URLs, dates, keys ending in `Id`, denylisted keys). Being conservative is safe: the worst case | ||
| * is a redundant `stegaClean()` call, whereas under-branding would hide real bugs. | ||
| * | ||
| * The `Key` and `ParentKey` type parameters track the key the current value is found under, and | ||
| * the key of the object containing it, they're only used internally during recursion. | ||
| * | ||
| * @beta | ||
| */ | ||
| export type StegaBranded< | ||
| T, | ||
| Key extends PropertyKey = number, | ||
| ParentKey extends PropertyKey = number, | ||
| > = 0 extends 1 & T | ||
| ? T | ||
| : T extends string | ||
| ? T extends {readonly ' stegaBrand': string} | ||
| ? T | ||
| : Key extends `_${string}` | 'slug' | ||
| ? T | ||
| : Key extends 'current' | ||
| ? ParentKey extends 'slug' | ||
| ? T | ||
| : StegaString<T> | ||
| : StegaString<T> | ||
| : T extends number | bigint | boolean | null | undefined | ||
| ? T | ||
| : T extends Date | RegExp | ((...args: never[]) => unknown) | ||
| ? T | ||
| : T extends readonly unknown[] | ||
| ? {[Index in keyof T]: StegaBranded<T[Index], number, number>} | ||
| : T extends {_type: 'block'} | ||
| ? {[K in keyof T]: K extends 'children' ? StegaBranded<T[K], K, Key> : T[K]} | ||
| : T extends {_type: 'span'} | ||
| ? {[K in keyof T]: K extends 'text' ? StegaBranded<T[K], K, Key> : T[K]} | ||
| : T extends object | ||
| ? {[K in keyof T]: StegaBranded<T[K], K, Key>} | ||
| : T | ||
| /** | ||
| * Drop-in replacement for `ClientReturn` that brands the result strings as `StegaString`, for use | ||
| * as the first generic of `client.fetch` when stega is enabled: | ||
| * ```ts | ||
| * import {createClient} from '@sanity/client' | ||
| * import type {ClientReturnStega} from '@sanity/client/stega' | ||
| * | ||
| * const query = '*[_type == "post"][0]' | ||
| * const post = await client.fetch<ClientReturnStega<typeof query>>(query) | ||
| * ``` | ||
| * When the query is registered in the `SanityQueries` interface (for example by `sanity typegen`), | ||
| * the result type is looked up and deeply branded with `StegaBranded`. Otherwise it falls back to | ||
| * `Fallback`, which defaults to `any`, just like `ClientReturn`. | ||
| * | ||
| * @beta | ||
| */ | ||
| export type ClientReturnStega<GroqString extends string, Fallback = Any> = StegaBranded< | ||
| ClientReturn<GroqString, Fallback> | ||
| > | ||
| /** | ||
| * Marks strings in an already fetched query result as potentially containing stega-encoded data, | ||
| * by re-typing them as `StegaString`. Comparing branded strings to string literals is a type error | ||
| * until they're cleaned with `stegaClean()`, which recovers the original type. | ||
| * | ||
| * This is an identity function, it only changes the type of the input, not its value. | ||
| * Prefer passing `ClientReturnStega` as the first generic to `client.fetch` when possible, and use | ||
| * this function for data that has already been fetched. | ||
| * | ||
| * @beta | ||
| */ | ||
| export function stegaBrand<Result>(result: Result): StegaBranded<Result> { | ||
| return result as StegaBranded<Result> | ||
| } |
@@ -1,1 +0,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<Result>(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,EAAC,GAAE,IAAE,IAAI,MAAM,CAAC,EAAE,KAAK,OAAO,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE;AAA2B,SAAS,EAAE,GAAE;AAAC,MAAI,IAAE,KAAK,UAAU,CAAC,GAAE,IAAE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,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;ACOlnF,SAAS,WAA6B,QAAwB;AACnE,SAAOA,EAAyB,MAAM;AACxC;AAQO,MAAM,sBAAsB;;;;;","x_google_ignoreList":[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,GAA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C,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]} |
@@ -1,1 +0,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<Result>(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,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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;ACOlnF,SAAS,WAA6B,QAAwB;AACnE,SAAOA,EAAyB,MAAM;AACxC;AAQO,MAAM,sBAAsB;","x_google_ignoreList":[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 vercelStegaCle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C;AAAC,SAAS,EAAE,GAAE;AAAC,MAAG;AAAC,QAAI,IAAI,GAAE,EAAE,WAAW,GAAG,IAAE,qBAAmB,MAAM;AAAA,EAAC,QAAM;AAAC,WAAM;AAAA,EAAE;AAAC;AAAQ;AAAC,SAAS,EAAE,GAAE,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]} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: !0 }); | ||
| var client = require("@sanity/client"), stegaEncodeSourceMap = require("./_chunks-cjs/stegaEncodeSourceMap.cjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"); | ||
| function stegaBrand(result) { | ||
| return result; | ||
| } | ||
| class SanityStegaClient extends client.SanityClient { | ||
@@ -17,2 +20,3 @@ } | ||
| exports.requester = requester; | ||
| exports.stegaBrand = stegaBrand; | ||
| Object.keys(client).forEach(function(k) { | ||
@@ -19,0 +23,0 @@ k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k) && Object.defineProperty(exports, k, { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"stega.browser.cjs","sources":["../src/stega/index.ts"],"sourcesContent":["export * from '@sanity/client'\nimport {\n createClient as originalCreateClient,\n ObservableSanityClient,\n requester as originalRequester,\n SanityClient,\n} from '@sanity/client'\n\nexport {encodeIntoResult} from './encodeIntoResult'\nexport {stegaClean, vercelStegaCleanAll} from './stegaClean'\nexport {stegaEncodeSourceMap} from './stegaEncodeSourceMap'\nexport * from './types'\n\n/**\n * @deprecated -- Use `import {SanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class SanityStegaClient extends SanityClient {}\n\n/**\n * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class ObservableSanityStegaClient extends ObservableSanityClient {}\n\n/**\n * @deprecated -- Use `import {requester} from '@sanity/client'` instead\n * @public\n */\nexport const requester = originalRequester\n\n/**\n * @deprecated -- Use `import {createClient} from '@sanity/client'` instead\n * @public\n */\nexport const createClient = originalCreateClient\n"],"names":["SanityClient","ObservableSanityClient","originalRequester","originalCreateClient"],"mappings":";;;AAiBO,MAAM,0BAA0BA,OAAAA,aAAa;AAAC;AAM9C,MAAM,oCAAoCC,OAAAA,uBAAuB;AAAC;AAMlE,MAAM,YAAYC,OAAAA,WAMZ,eAAeC,OAAAA;;;;;;;;;;;;;;;;;"} | ||
| {"version":3,"file":"stega.browser.cjs","sources":["../src/stega/stegaBrand.ts","../src/stega/index.ts"],"sourcesContent":["import type {Any, ClientReturn} from '@sanity/client'\n\n/**\n * A string that might contain stega-encoded data, and is unsafe to compare against string literals\n * until it's been cleaned with `stegaClean()`.\n *\n * The type intersects a template literal that has a human readable suffix, with a brand property\n * that holds the original string type:\n * - The suffix makes TypeScript report \"This comparison appears to be unintentional\" (TS2367) when\n * the string is compared to a literal (`===`, `switch` cases), and makes it unassignable to\n * literal unions like `'left' | 'right'`, while keeping it assignable to `string` so rendering,\n * interpolation and string methods keep working. The suffix is a type-level fiction, the runtime\n * value never ends with that text.\n * - The brand property preserves the original type so `stegaClean()` can recover it exactly. It's\n * a string-keyed property rather than a `unique symbol` so that branded types stay structurally\n * compatible across duplicated copies of `@sanity/client` in `node_modules`. It only exists in\n * the type system and is never present at runtime.\n *\n * @beta\n */\nexport type StegaString<T extends string = string> =\n `${T} (may contain hidden stega characters)` & {\n readonly ' stegaBrand': T\n }\n\n/**\n * Deeply brands the string properties of a query result as `StegaString`, marking them as\n * potentially containing stega-encoded data.\n *\n * String properties that the stega encoder is guaranteed to never encode keep their plain type:\n * - keys starting with `_` (`_id`, `_type`, `_createdAt`, `_updatedAt`, `_key`, `_ref`, `_rev` and\n * so on), which also preserves discriminated union narrowing on `_type`\n * - `slug.current` patterns: a `current` key directly under a `slug` key, as well as string valued\n * `slug` keys (covering `\"slug\": slug.current` projections)\n * - Portable Text internals: the encoder only visits `children` of `_type: 'block'` objects and\n * `text` of `_type: 'span'` objects, so properties like `style`, `listItem` and `marks` stay\n * plain\n *\n * Every other string is assumed to be \"poisoned\", even if the runtime `filter` happens to skip it\n * (URLs, dates, keys ending in `Id`, denylisted keys). Being conservative is safe: the worst case\n * is a redundant `stegaClean()` call, whereas under-branding would hide real bugs.\n *\n * The `Key` and `ParentKey` type parameters track the key the current value is found under, and\n * the key of the object containing it, they're only used internally during recursion.\n *\n * @beta\n */\nexport type StegaBranded<\n T,\n Key extends PropertyKey = number,\n ParentKey extends PropertyKey = number,\n> = 0 extends 1 & T\n ? T\n : T extends string\n ? T extends {readonly ' stegaBrand': string}\n ? T\n : Key extends `_${string}` | 'slug'\n ? T\n : Key extends 'current'\n ? ParentKey extends 'slug'\n ? T\n : StegaString<T>\n : StegaString<T>\n : T extends 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]: StegaBranded<T[Index], number, number>}\n : T extends {_type: 'block'}\n ? {[K in keyof T]: K extends 'children' ? StegaBranded<T[K], K, Key> : T[K]}\n : T extends {_type: 'span'}\n ? {[K in keyof T]: K extends 'text' ? StegaBranded<T[K], K, Key> : T[K]}\n : T extends object\n ? {[K in keyof T]: StegaBranded<T[K], K, Key>}\n : T\n\n/**\n * Drop-in replacement for `ClientReturn` that brands the result strings as `StegaString`, for use\n * as the first generic of `client.fetch` when stega is enabled:\n * ```ts\n * import {createClient} from '@sanity/client'\n * import type {ClientReturnStega} from '@sanity/client/stega'\n *\n * const query = '*[_type == \"post\"][0]'\n * const post = await client.fetch<ClientReturnStega<typeof query>>(query)\n * ```\n * When the query is registered in the `SanityQueries` interface (for example by `sanity typegen`),\n * the result type is looked up and deeply branded with `StegaBranded`. Otherwise it falls back to\n * `Fallback`, which defaults to `any`, just like `ClientReturn`.\n *\n * @beta\n */\nexport type ClientReturnStega<GroqString extends string, Fallback = Any> = StegaBranded<\n ClientReturn<GroqString, Fallback>\n>\n\n/**\n * Marks strings in an already fetched query result as potentially containing stega-encoded data,\n * by re-typing them as `StegaString`. Comparing branded strings to string literals is a type error\n * until they're cleaned with `stegaClean()`, which recovers the original type.\n *\n * This is an identity function, it only changes the type of the input, not its value.\n * Prefer passing `ClientReturnStega` as the first generic to `client.fetch` when possible, and use\n * this function for data that has already been fetched.\n *\n * @beta\n */\nexport function stegaBrand<Result>(result: Result): StegaBranded<Result> {\n return result as StegaBranded<Result>\n}\n","export * from '@sanity/client'\nimport {\n createClient as originalCreateClient,\n ObservableSanityClient,\n requester as originalRequester,\n SanityClient,\n} from '@sanity/client'\n\nexport {encodeIntoResult} from './encodeIntoResult'\nexport {type ClientReturnStega, stegaBrand, type StegaBranded, type StegaString} from './stegaBrand'\nexport {stegaClean, type StegaCleaned, vercelStegaCleanAll} from './stegaClean'\nexport {stegaEncodeSourceMap} from './stegaEncodeSourceMap'\nexport * from './types'\n\n/**\n * @deprecated -- Use `import {SanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class SanityStegaClient extends SanityClient {}\n\n/**\n * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class ObservableSanityStegaClient extends ObservableSanityClient {}\n\n/**\n * @deprecated -- Use `import {requester} from '@sanity/client'` instead\n * @public\n */\nexport const requester = originalRequester\n\n/**\n * @deprecated -- Use `import {createClient} from '@sanity/client'` instead\n * @public\n */\nexport const createClient = originalCreateClient\n"],"names":["SanityClient","ObservableSanityClient","originalRequester","originalCreateClient"],"mappings":";;;AA4GO,SAAS,WAAmB,QAAsC;AACvE,SAAO;AACT;AC5FO,MAAM,0BAA0BA,OAAAA,aAAa;AAAC;AAM9C,MAAM,oCAAoCC,OAAAA,uBAAuB;AAAC;AAMlE,MAAM,YAAYC,OAAAA,WAMZ,eAAeC,OAAAA;;;;;;;;;;;;;;;;;;"} |
@@ -5,2 +5,5 @@ import { createClient as createClient$1, requester as requester$1, ObservableSanityClient, SanityClient } from "@sanity/client"; | ||
| import { stegaClean, vercelStegaCleanAll } from "./_chunks-es/stegaClean.js"; | ||
| function stegaBrand(result) { | ||
| return result; | ||
| } | ||
| class SanityStegaClient extends SanityClient { | ||
@@ -17,2 +20,3 @@ } | ||
| requester, | ||
| stegaBrand, | ||
| stegaClean, | ||
@@ -19,0 +23,0 @@ stegaEncodeSourceMap, |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"stega.browser.js","sources":["../src/stega/index.ts"],"sourcesContent":["export * from '@sanity/client'\nimport {\n createClient as originalCreateClient,\n ObservableSanityClient,\n requester as originalRequester,\n SanityClient,\n} from '@sanity/client'\n\nexport {encodeIntoResult} from './encodeIntoResult'\nexport {stegaClean, vercelStegaCleanAll} from './stegaClean'\nexport {stegaEncodeSourceMap} from './stegaEncodeSourceMap'\nexport * from './types'\n\n/**\n * @deprecated -- Use `import {SanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class SanityStegaClient extends SanityClient {}\n\n/**\n * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class ObservableSanityStegaClient extends ObservableSanityClient {}\n\n/**\n * @deprecated -- Use `import {requester} from '@sanity/client'` instead\n * @public\n */\nexport const requester = originalRequester\n\n/**\n * @deprecated -- Use `import {createClient} from '@sanity/client'` instead\n * @public\n */\nexport const createClient = originalCreateClient\n"],"names":["originalRequester","originalCreateClient"],"mappings":";;;;AAiBO,MAAM,0BAA0B,aAAa;AAAC;AAM9C,MAAM,oCAAoC,uBAAuB;AAAC;AAMlE,MAAM,YAAYA,aAMZ,eAAeC;"} | ||
| {"version":3,"file":"stega.browser.js","sources":["../src/stega/stegaBrand.ts","../src/stega/index.ts"],"sourcesContent":["import type {Any, ClientReturn} from '@sanity/client'\n\n/**\n * A string that might contain stega-encoded data, and is unsafe to compare against string literals\n * until it's been cleaned with `stegaClean()`.\n *\n * The type intersects a template literal that has a human readable suffix, with a brand property\n * that holds the original string type:\n * - The suffix makes TypeScript report \"This comparison appears to be unintentional\" (TS2367) when\n * the string is compared to a literal (`===`, `switch` cases), and makes it unassignable to\n * literal unions like `'left' | 'right'`, while keeping it assignable to `string` so rendering,\n * interpolation and string methods keep working. The suffix is a type-level fiction, the runtime\n * value never ends with that text.\n * - The brand property preserves the original type so `stegaClean()` can recover it exactly. It's\n * a string-keyed property rather than a `unique symbol` so that branded types stay structurally\n * compatible across duplicated copies of `@sanity/client` in `node_modules`. It only exists in\n * the type system and is never present at runtime.\n *\n * @beta\n */\nexport type StegaString<T extends string = string> =\n `${T} (may contain hidden stega characters)` & {\n readonly ' stegaBrand': T\n }\n\n/**\n * Deeply brands the string properties of a query result as `StegaString`, marking them as\n * potentially containing stega-encoded data.\n *\n * String properties that the stega encoder is guaranteed to never encode keep their plain type:\n * - keys starting with `_` (`_id`, `_type`, `_createdAt`, `_updatedAt`, `_key`, `_ref`, `_rev` and\n * so on), which also preserves discriminated union narrowing on `_type`\n * - `slug.current` patterns: a `current` key directly under a `slug` key, as well as string valued\n * `slug` keys (covering `\"slug\": slug.current` projections)\n * - Portable Text internals: the encoder only visits `children` of `_type: 'block'` objects and\n * `text` of `_type: 'span'` objects, so properties like `style`, `listItem` and `marks` stay\n * plain\n *\n * Every other string is assumed to be \"poisoned\", even if the runtime `filter` happens to skip it\n * (URLs, dates, keys ending in `Id`, denylisted keys). Being conservative is safe: the worst case\n * is a redundant `stegaClean()` call, whereas under-branding would hide real bugs.\n *\n * The `Key` and `ParentKey` type parameters track the key the current value is found under, and\n * the key of the object containing it, they're only used internally during recursion.\n *\n * @beta\n */\nexport type StegaBranded<\n T,\n Key extends PropertyKey = number,\n ParentKey extends PropertyKey = number,\n> = 0 extends 1 & T\n ? T\n : T extends string\n ? T extends {readonly ' stegaBrand': string}\n ? T\n : Key extends `_${string}` | 'slug'\n ? T\n : Key extends 'current'\n ? ParentKey extends 'slug'\n ? T\n : StegaString<T>\n : StegaString<T>\n : T extends 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]: StegaBranded<T[Index], number, number>}\n : T extends {_type: 'block'}\n ? {[K in keyof T]: K extends 'children' ? StegaBranded<T[K], K, Key> : T[K]}\n : T extends {_type: 'span'}\n ? {[K in keyof T]: K extends 'text' ? StegaBranded<T[K], K, Key> : T[K]}\n : T extends object\n ? {[K in keyof T]: StegaBranded<T[K], K, Key>}\n : T\n\n/**\n * Drop-in replacement for `ClientReturn` that brands the result strings as `StegaString`, for use\n * as the first generic of `client.fetch` when stega is enabled:\n * ```ts\n * import {createClient} from '@sanity/client'\n * import type {ClientReturnStega} from '@sanity/client/stega'\n *\n * const query = '*[_type == \"post\"][0]'\n * const post = await client.fetch<ClientReturnStega<typeof query>>(query)\n * ```\n * When the query is registered in the `SanityQueries` interface (for example by `sanity typegen`),\n * the result type is looked up and deeply branded with `StegaBranded`. Otherwise it falls back to\n * `Fallback`, which defaults to `any`, just like `ClientReturn`.\n *\n * @beta\n */\nexport type ClientReturnStega<GroqString extends string, Fallback = Any> = StegaBranded<\n ClientReturn<GroqString, Fallback>\n>\n\n/**\n * Marks strings in an already fetched query result as potentially containing stega-encoded data,\n * by re-typing them as `StegaString`. Comparing branded strings to string literals is a type error\n * until they're cleaned with `stegaClean()`, which recovers the original type.\n *\n * This is an identity function, it only changes the type of the input, not its value.\n * Prefer passing `ClientReturnStega` as the first generic to `client.fetch` when possible, and use\n * this function for data that has already been fetched.\n *\n * @beta\n */\nexport function stegaBrand<Result>(result: Result): StegaBranded<Result> {\n return result as StegaBranded<Result>\n}\n","export * from '@sanity/client'\nimport {\n createClient as originalCreateClient,\n ObservableSanityClient,\n requester as originalRequester,\n SanityClient,\n} from '@sanity/client'\n\nexport {encodeIntoResult} from './encodeIntoResult'\nexport {type ClientReturnStega, stegaBrand, type StegaBranded, type StegaString} from './stegaBrand'\nexport {stegaClean, type StegaCleaned, vercelStegaCleanAll} from './stegaClean'\nexport {stegaEncodeSourceMap} from './stegaEncodeSourceMap'\nexport * from './types'\n\n/**\n * @deprecated -- Use `import {SanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class SanityStegaClient extends SanityClient {}\n\n/**\n * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class ObservableSanityStegaClient extends ObservableSanityClient {}\n\n/**\n * @deprecated -- Use `import {requester} from '@sanity/client'` instead\n * @public\n */\nexport const requester = originalRequester\n\n/**\n * @deprecated -- Use `import {createClient} from '@sanity/client'` instead\n * @public\n */\nexport const createClient = originalCreateClient\n"],"names":["originalRequester","originalCreateClient"],"mappings":";;;;AA4GO,SAAS,WAAmB,QAAsC;AACvE,SAAO;AACT;AC5FO,MAAM,0BAA0B,aAAa;AAAC;AAM9C,MAAM,oCAAoC,uBAAuB;AAAC;AAMlE,MAAM,YAAYA,aAMZ,eAAeC;"} |
+4
-0
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: !0 }); | ||
| var client = require("@sanity/client"), stegaEncodeSourceMap = require("./_chunks-cjs/stegaEncodeSourceMap.cjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"); | ||
| function stegaBrand(result) { | ||
| return result; | ||
| } | ||
| class SanityStegaClient extends client.SanityClient { | ||
@@ -17,2 +20,3 @@ } | ||
| exports.requester = requester; | ||
| exports.stegaBrand = stegaBrand; | ||
| Object.keys(client).forEach(function(k) { | ||
@@ -19,0 +23,0 @@ k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k) && Object.defineProperty(exports, k, { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"stega.cjs","sources":["../src/stega/index.ts"],"sourcesContent":["export * from '@sanity/client'\nimport {\n createClient as originalCreateClient,\n ObservableSanityClient,\n requester as originalRequester,\n SanityClient,\n} from '@sanity/client'\n\nexport {encodeIntoResult} from './encodeIntoResult'\nexport {stegaClean, vercelStegaCleanAll} from './stegaClean'\nexport {stegaEncodeSourceMap} from './stegaEncodeSourceMap'\nexport * from './types'\n\n/**\n * @deprecated -- Use `import {SanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class SanityStegaClient extends SanityClient {}\n\n/**\n * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class ObservableSanityStegaClient extends ObservableSanityClient {}\n\n/**\n * @deprecated -- Use `import {requester} from '@sanity/client'` instead\n * @public\n */\nexport const requester = originalRequester\n\n/**\n * @deprecated -- Use `import {createClient} from '@sanity/client'` instead\n * @public\n */\nexport const createClient = originalCreateClient\n"],"names":["SanityClient","ObservableSanityClient","originalRequester","originalCreateClient"],"mappings":";;;AAiBO,MAAM,0BAA0BA,OAAAA,aAAa;AAAC;AAM9C,MAAM,oCAAoCC,OAAAA,uBAAuB;AAAC;AAMlE,MAAM,YAAYC,OAAAA,WAMZ,eAAeC,OAAAA;;;;;;;;;;;;;;;;;"} | ||
| {"version":3,"file":"stega.cjs","sources":["../src/stega/stegaBrand.ts","../src/stega/index.ts"],"sourcesContent":["import type {Any, ClientReturn} from '@sanity/client'\n\n/**\n * A string that might contain stega-encoded data, and is unsafe to compare against string literals\n * until it's been cleaned with `stegaClean()`.\n *\n * The type intersects a template literal that has a human readable suffix, with a brand property\n * that holds the original string type:\n * - The suffix makes TypeScript report \"This comparison appears to be unintentional\" (TS2367) when\n * the string is compared to a literal (`===`, `switch` cases), and makes it unassignable to\n * literal unions like `'left' | 'right'`, while keeping it assignable to `string` so rendering,\n * interpolation and string methods keep working. The suffix is a type-level fiction, the runtime\n * value never ends with that text.\n * - The brand property preserves the original type so `stegaClean()` can recover it exactly. It's\n * a string-keyed property rather than a `unique symbol` so that branded types stay structurally\n * compatible across duplicated copies of `@sanity/client` in `node_modules`. It only exists in\n * the type system and is never present at runtime.\n *\n * @beta\n */\nexport type StegaString<T extends string = string> =\n `${T} (may contain hidden stega characters)` & {\n readonly ' stegaBrand': T\n }\n\n/**\n * Deeply brands the string properties of a query result as `StegaString`, marking them as\n * potentially containing stega-encoded data.\n *\n * String properties that the stega encoder is guaranteed to never encode keep their plain type:\n * - keys starting with `_` (`_id`, `_type`, `_createdAt`, `_updatedAt`, `_key`, `_ref`, `_rev` and\n * so on), which also preserves discriminated union narrowing on `_type`\n * - `slug.current` patterns: a `current` key directly under a `slug` key, as well as string valued\n * `slug` keys (covering `\"slug\": slug.current` projections)\n * - Portable Text internals: the encoder only visits `children` of `_type: 'block'` objects and\n * `text` of `_type: 'span'` objects, so properties like `style`, `listItem` and `marks` stay\n * plain\n *\n * Every other string is assumed to be \"poisoned\", even if the runtime `filter` happens to skip it\n * (URLs, dates, keys ending in `Id`, denylisted keys). Being conservative is safe: the worst case\n * is a redundant `stegaClean()` call, whereas under-branding would hide real bugs.\n *\n * The `Key` and `ParentKey` type parameters track the key the current value is found under, and\n * the key of the object containing it, they're only used internally during recursion.\n *\n * @beta\n */\nexport type StegaBranded<\n T,\n Key extends PropertyKey = number,\n ParentKey extends PropertyKey = number,\n> = 0 extends 1 & T\n ? T\n : T extends string\n ? T extends {readonly ' stegaBrand': string}\n ? T\n : Key extends `_${string}` | 'slug'\n ? T\n : Key extends 'current'\n ? ParentKey extends 'slug'\n ? T\n : StegaString<T>\n : StegaString<T>\n : T extends 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]: StegaBranded<T[Index], number, number>}\n : T extends {_type: 'block'}\n ? {[K in keyof T]: K extends 'children' ? StegaBranded<T[K], K, Key> : T[K]}\n : T extends {_type: 'span'}\n ? {[K in keyof T]: K extends 'text' ? StegaBranded<T[K], K, Key> : T[K]}\n : T extends object\n ? {[K in keyof T]: StegaBranded<T[K], K, Key>}\n : T\n\n/**\n * Drop-in replacement for `ClientReturn` that brands the result strings as `StegaString`, for use\n * as the first generic of `client.fetch` when stega is enabled:\n * ```ts\n * import {createClient} from '@sanity/client'\n * import type {ClientReturnStega} from '@sanity/client/stega'\n *\n * const query = '*[_type == \"post\"][0]'\n * const post = await client.fetch<ClientReturnStega<typeof query>>(query)\n * ```\n * When the query is registered in the `SanityQueries` interface (for example by `sanity typegen`),\n * the result type is looked up and deeply branded with `StegaBranded`. Otherwise it falls back to\n * `Fallback`, which defaults to `any`, just like `ClientReturn`.\n *\n * @beta\n */\nexport type ClientReturnStega<GroqString extends string, Fallback = Any> = StegaBranded<\n ClientReturn<GroqString, Fallback>\n>\n\n/**\n * Marks strings in an already fetched query result as potentially containing stega-encoded data,\n * by re-typing them as `StegaString`. Comparing branded strings to string literals is a type error\n * until they're cleaned with `stegaClean()`, which recovers the original type.\n *\n * This is an identity function, it only changes the type of the input, not its value.\n * Prefer passing `ClientReturnStega` as the first generic to `client.fetch` when possible, and use\n * this function for data that has already been fetched.\n *\n * @beta\n */\nexport function stegaBrand<Result>(result: Result): StegaBranded<Result> {\n return result as StegaBranded<Result>\n}\n","export * from '@sanity/client'\nimport {\n createClient as originalCreateClient,\n ObservableSanityClient,\n requester as originalRequester,\n SanityClient,\n} from '@sanity/client'\n\nexport {encodeIntoResult} from './encodeIntoResult'\nexport {type ClientReturnStega, stegaBrand, type StegaBranded, type StegaString} from './stegaBrand'\nexport {stegaClean, type StegaCleaned, vercelStegaCleanAll} from './stegaClean'\nexport {stegaEncodeSourceMap} from './stegaEncodeSourceMap'\nexport * from './types'\n\n/**\n * @deprecated -- Use `import {SanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class SanityStegaClient extends SanityClient {}\n\n/**\n * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class ObservableSanityStegaClient extends ObservableSanityClient {}\n\n/**\n * @deprecated -- Use `import {requester} from '@sanity/client'` instead\n * @public\n */\nexport const requester = originalRequester\n\n/**\n * @deprecated -- Use `import {createClient} from '@sanity/client'` instead\n * @public\n */\nexport const createClient = originalCreateClient\n"],"names":["SanityClient","ObservableSanityClient","originalRequester","originalCreateClient"],"mappings":";;;AA4GO,SAAS,WAAmB,QAAsC;AACvE,SAAO;AACT;AC5FO,MAAM,0BAA0BA,OAAAA,aAAa;AAAC;AAM9C,MAAM,oCAAoCC,OAAAA,uBAAuB;AAAC;AAMlE,MAAM,YAAYC,OAAAA,WAMZ,eAAeC,OAAAA;;;;;;;;;;;;;;;;;;"} |
+4
-0
@@ -5,2 +5,5 @@ import { createClient as createClient$1, requester as requester$1, ObservableSanityClient, SanityClient } from "@sanity/client"; | ||
| import { stegaClean, vercelStegaCleanAll } from "./_chunks-es/stegaClean.js"; | ||
| function stegaBrand(result) { | ||
| return result; | ||
| } | ||
| class SanityStegaClient extends SanityClient { | ||
@@ -17,2 +20,3 @@ } | ||
| requester, | ||
| stegaBrand, | ||
| stegaClean, | ||
@@ -19,0 +23,0 @@ stegaEncodeSourceMap, |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"stega.js","sources":["../src/stega/index.ts"],"sourcesContent":["export * from '@sanity/client'\nimport {\n createClient as originalCreateClient,\n ObservableSanityClient,\n requester as originalRequester,\n SanityClient,\n} from '@sanity/client'\n\nexport {encodeIntoResult} from './encodeIntoResult'\nexport {stegaClean, vercelStegaCleanAll} from './stegaClean'\nexport {stegaEncodeSourceMap} from './stegaEncodeSourceMap'\nexport * from './types'\n\n/**\n * @deprecated -- Use `import {SanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class SanityStegaClient extends SanityClient {}\n\n/**\n * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class ObservableSanityStegaClient extends ObservableSanityClient {}\n\n/**\n * @deprecated -- Use `import {requester} from '@sanity/client'` instead\n * @public\n */\nexport const requester = originalRequester\n\n/**\n * @deprecated -- Use `import {createClient} from '@sanity/client'` instead\n * @public\n */\nexport const createClient = originalCreateClient\n"],"names":["originalRequester","originalCreateClient"],"mappings":";;;;AAiBO,MAAM,0BAA0B,aAAa;AAAC;AAM9C,MAAM,oCAAoC,uBAAuB;AAAC;AAMlE,MAAM,YAAYA,aAMZ,eAAeC;"} | ||
| {"version":3,"file":"stega.js","sources":["../src/stega/stegaBrand.ts","../src/stega/index.ts"],"sourcesContent":["import type {Any, ClientReturn} from '@sanity/client'\n\n/**\n * A string that might contain stega-encoded data, and is unsafe to compare against string literals\n * until it's been cleaned with `stegaClean()`.\n *\n * The type intersects a template literal that has a human readable suffix, with a brand property\n * that holds the original string type:\n * - The suffix makes TypeScript report \"This comparison appears to be unintentional\" (TS2367) when\n * the string is compared to a literal (`===`, `switch` cases), and makes it unassignable to\n * literal unions like `'left' | 'right'`, while keeping it assignable to `string` so rendering,\n * interpolation and string methods keep working. The suffix is a type-level fiction, the runtime\n * value never ends with that text.\n * - The brand property preserves the original type so `stegaClean()` can recover it exactly. It's\n * a string-keyed property rather than a `unique symbol` so that branded types stay structurally\n * compatible across duplicated copies of `@sanity/client` in `node_modules`. It only exists in\n * the type system and is never present at runtime.\n *\n * @beta\n */\nexport type StegaString<T extends string = string> =\n `${T} (may contain hidden stega characters)` & {\n readonly ' stegaBrand': T\n }\n\n/**\n * Deeply brands the string properties of a query result as `StegaString`, marking them as\n * potentially containing stega-encoded data.\n *\n * String properties that the stega encoder is guaranteed to never encode keep their plain type:\n * - keys starting with `_` (`_id`, `_type`, `_createdAt`, `_updatedAt`, `_key`, `_ref`, `_rev` and\n * so on), which also preserves discriminated union narrowing on `_type`\n * - `slug.current` patterns: a `current` key directly under a `slug` key, as well as string valued\n * `slug` keys (covering `\"slug\": slug.current` projections)\n * - Portable Text internals: the encoder only visits `children` of `_type: 'block'` objects and\n * `text` of `_type: 'span'` objects, so properties like `style`, `listItem` and `marks` stay\n * plain\n *\n * Every other string is assumed to be \"poisoned\", even if the runtime `filter` happens to skip it\n * (URLs, dates, keys ending in `Id`, denylisted keys). Being conservative is safe: the worst case\n * is a redundant `stegaClean()` call, whereas under-branding would hide real bugs.\n *\n * The `Key` and `ParentKey` type parameters track the key the current value is found under, and\n * the key of the object containing it, they're only used internally during recursion.\n *\n * @beta\n */\nexport type StegaBranded<\n T,\n Key extends PropertyKey = number,\n ParentKey extends PropertyKey = number,\n> = 0 extends 1 & T\n ? T\n : T extends string\n ? T extends {readonly ' stegaBrand': string}\n ? T\n : Key extends `_${string}` | 'slug'\n ? T\n : Key extends 'current'\n ? ParentKey extends 'slug'\n ? T\n : StegaString<T>\n : StegaString<T>\n : T extends 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]: StegaBranded<T[Index], number, number>}\n : T extends {_type: 'block'}\n ? {[K in keyof T]: K extends 'children' ? StegaBranded<T[K], K, Key> : T[K]}\n : T extends {_type: 'span'}\n ? {[K in keyof T]: K extends 'text' ? StegaBranded<T[K], K, Key> : T[K]}\n : T extends object\n ? {[K in keyof T]: StegaBranded<T[K], K, Key>}\n : T\n\n/**\n * Drop-in replacement for `ClientReturn` that brands the result strings as `StegaString`, for use\n * as the first generic of `client.fetch` when stega is enabled:\n * ```ts\n * import {createClient} from '@sanity/client'\n * import type {ClientReturnStega} from '@sanity/client/stega'\n *\n * const query = '*[_type == \"post\"][0]'\n * const post = await client.fetch<ClientReturnStega<typeof query>>(query)\n * ```\n * When the query is registered in the `SanityQueries` interface (for example by `sanity typegen`),\n * the result type is looked up and deeply branded with `StegaBranded`. Otherwise it falls back to\n * `Fallback`, which defaults to `any`, just like `ClientReturn`.\n *\n * @beta\n */\nexport type ClientReturnStega<GroqString extends string, Fallback = Any> = StegaBranded<\n ClientReturn<GroqString, Fallback>\n>\n\n/**\n * Marks strings in an already fetched query result as potentially containing stega-encoded data,\n * by re-typing them as `StegaString`. Comparing branded strings to string literals is a type error\n * until they're cleaned with `stegaClean()`, which recovers the original type.\n *\n * This is an identity function, it only changes the type of the input, not its value.\n * Prefer passing `ClientReturnStega` as the first generic to `client.fetch` when possible, and use\n * this function for data that has already been fetched.\n *\n * @beta\n */\nexport function stegaBrand<Result>(result: Result): StegaBranded<Result> {\n return result as StegaBranded<Result>\n}\n","export * from '@sanity/client'\nimport {\n createClient as originalCreateClient,\n ObservableSanityClient,\n requester as originalRequester,\n SanityClient,\n} from '@sanity/client'\n\nexport {encodeIntoResult} from './encodeIntoResult'\nexport {type ClientReturnStega, stegaBrand, type StegaBranded, type StegaString} from './stegaBrand'\nexport {stegaClean, type StegaCleaned, vercelStegaCleanAll} from './stegaClean'\nexport {stegaEncodeSourceMap} from './stegaEncodeSourceMap'\nexport * from './types'\n\n/**\n * @deprecated -- Use `import {SanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class SanityStegaClient extends SanityClient {}\n\n/**\n * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead\n * @public\n */\nexport class ObservableSanityStegaClient extends ObservableSanityClient {}\n\n/**\n * @deprecated -- Use `import {requester} from '@sanity/client'` instead\n * @public\n */\nexport const requester = originalRequester\n\n/**\n * @deprecated -- Use `import {createClient} from '@sanity/client'` instead\n * @public\n */\nexport const createClient = originalCreateClient\n"],"names":["originalRequester","originalCreateClient"],"mappings":";;;;AA4GO,SAAS,WAAmB,QAAsC;AACvE,SAAO;AACT;AC5FO,MAAM,0BAA0B,aAAa;AAAC;AAM9C,MAAM,oCAAoC,uBAAuB;AAAC;AAMlE,MAAM,YAAYA,aAMZ,eAAeC;"} |
+2
-1
| { | ||
| "name": "@sanity/client", | ||
| "version": "7.24.0", | ||
| "version": "7.25.0", | ||
| "description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -148,2 +148,3 @@ "keywords": [ | ||
| "@types/node": "^22.9.0", | ||
| "@types/react": "^19.2.17", | ||
| "@typescript-eslint/eslint-plugin": "^8.29.1", | ||
@@ -150,0 +151,0 @@ "@typescript-eslint/parser": "^8.29.1", |
@@ -10,3 +10,4 @@ export * from '@sanity/client' | ||
| export {encodeIntoResult} from './encodeIntoResult' | ||
| export {stegaClean, vercelStegaCleanAll} from './stegaClean' | ||
| export {type ClientReturnStega, stegaBrand, type StegaBranded, type StegaString} from './stegaBrand' | ||
| export {stegaClean, type StegaCleaned, vercelStegaCleanAll} from './stegaClean' | ||
| export {stegaEncodeSourceMap} from './stegaEncodeSourceMap' | ||
@@ -13,0 +14,0 @@ export * from './types' |
| import {vercelStegaClean} from '@vercel/stega' | ||
| /** | ||
| * The result of removing stega-encoded data from a value with `stegaClean()`: strings that were | ||
| * branded as `StegaString` are returned to their original type, everything else is left as-is. | ||
| * @public | ||
| */ | ||
| export type StegaCleaned<T> = 0 extends 1 & T | ||
| ? T | ||
| : T extends {readonly ' stegaBrand': infer Original extends string} | ||
| ? Original | ||
| : T extends string | number | bigint | boolean | null | undefined | ||
| ? T | ||
| : T extends Date | RegExp | ((...args: never[]) => unknown) | ||
| ? T | ||
| : T extends readonly unknown[] | ||
| ? {[Index in keyof T]: StegaCleaned<T[Index]>} | ||
| : T extends object | ||
| ? {[K in keyof T]: StegaCleaned<T[K]>} | ||
| : T | ||
| /** | ||
| * Can take a `result` JSON from a `const {result} = client.fetch(query, params, {filterResponse: false})` | ||
| * and remove all stega-encoded data from it. | ||
| * If the result type has strings branded as `StegaString` (by `ClientReturnStega` or `stegaBrand()`), | ||
| * the brand is stripped and the original string type is restored. | ||
| * @public | ||
| */ | ||
| export function stegaClean<Result = unknown>(result: Result): Result { | ||
| return vercelStegaClean<Result>(result) | ||
| export function stegaClean<Result = unknown>(result: Result): StegaCleaned<Result> { | ||
| return vercelStegaClean(result) as StegaCleaned<Result> | ||
| } | ||
@@ -11,0 +32,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
5202960
1.11%131
0.77%60641
0.72%2857
1.46%38
2.7%