UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.17 kB
import{utf8ToBytes as e}from"@noble/hashes/utils.js";import{sha256 as t}from"@noble/hashes/sha2.js";const n=`h:`,r=e=>{if(e===void 0||e===!1)return``;if(e.length===0)throw Error(`KV namespace cannot be an empty string. Use false to disable namespacing.`);return`${e}:`},i=e=>{let t=``,n=32768;for(let r=0;r<e.length;r+=n){let i=e.subarray(r,r+n);t+=String.fromCharCode(...i)}return(typeof btoa==`function`?btoa(t):Buffer.from(e).toString(`base64`)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)},a=n=>`h:${i(t(e(n)))}`,o=e=>typeof Buffer<`u`?Buffer.byteLength(e,`utf8`):new globalThis.TextEncoder().encode(e).byteLength,s=e=>{let t=typeof e==`number`?{maxKeyBytes:e}:e??{};return{...t,namespacePrefix:r(t.namespace)}},c=(e,t,n)=>{let{maxKeyBytes:r,namespacePrefix:i}=s(n),c=`${i}${e}`,l=t?.hash||typeof r==`number`&&r>0&&o(c)>r?`${i}${a(e)}`:c;if(typeof r==`number`&&r>0&&o(l)>r)throw Error(`Resolved KV key exceeds the maximum size of ${r} bytes. Use a shorter KV namespace.`);return l},l=e=>typeof e.increment==`function`;export{n as HASH_PREFIX,r as getNamespacePrefix,a as hashKey,c as resolveKey,l as supportsKVIncrement}; //# sourceMappingURL=utils.mjs.map