Rocky_Mountain_Vending/.pnpm-store/v10/files/6c/e128303d362eb138a6b7d8f8cc336014eef09c1c9d6290aad9cca68a8ecc9514a4aac94f1f70347dae3378411792d935dc436f439956985ca514baf2c9fb16
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

70 lines
No EOL
2.8 KiB
Text

import { arrayBufferToString, stringToUint8Array } from '../app-render/encryption-utils';
import { DYNAMIC_EXPIRE } from '../use-cache/constants';
/**
* Parses serialized cache entries into a UseCacheCacheStore
* @param entries - The serialized entries to parse
* @returns A new UseCacheCacheStore containing the parsed entries
*/ export function parseUseCacheCacheStore(entries) {
const store = new Map();
for (const [key, { value, tags, stale, timestamp, expire, revalidate }] of entries){
store.set(key, Promise.resolve({
// Create a ReadableStream from the Uint8Array
value: new ReadableStream({
start (controller) {
// Enqueue the Uint8Array to the stream
controller.enqueue(stringToUint8Array(atob(value)));
// Close the stream
controller.close();
}
}),
tags,
stale,
timestamp,
expire,
revalidate
}));
}
return store;
}
/**
* Serializes UseCacheCacheStore entries into an array of key-value pairs
* @param entries - The store entries to stringify
* @returns A promise that resolves to an array of key-value pairs with serialized values
*/ export async function serializeUseCacheCacheStore(entries, isCacheComponentsEnabled) {
return Promise.all(Array.from(entries).map(([key, value])=>{
return value.then(async (entry)=>{
if (isCacheComponentsEnabled && (entry.revalidate === 0 || entry.expire < DYNAMIC_EXPIRE)) {
// The entry was omitted from the prerender result, and subsequently
// does not need to be included in the serialized RDC.
return null;
}
const [left, right] = entry.value.tee();
entry.value = right;
let binaryString = '';
// We want to encode the value as a string, but we aren't sure if the
// value is a a stream of UTF-8 bytes or not, so let's just encode it
// as a string using base64.
for await (const chunk of left){
binaryString += arrayBufferToString(chunk);
}
return [
key,
{
// Encode the value as a base64 string.
value: btoa(binaryString),
tags: entry.tags,
stale: entry.stale,
timestamp: entry.timestamp,
expire: entry.expire,
revalidate: entry.revalidate
}
];
}).catch(()=>{
// Any failed cache writes should be ignored as to not discard the
// entire cache.
return null;
});
}));
}
//# sourceMappingURL=cache-store.js.map