Initial commit
This commit is contained in:
commit
78f8d225ee
21173 changed files with 2907774 additions and 0 deletions
64
node_modules/next/dist/esm/server/resume-data-cache/cache-store.js
generated
vendored
Normal file
64
node_modules/next/dist/esm/server/resume-data-cache/cache-store.js
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import { arrayBufferToString, stringToUint8Array } from '../app-render/encryption-utils';
|
||||
/**
|
||||
* 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) {
|
||||
return Promise.all(Array.from(entries).map(([key, value])=>{
|
||||
return value.then(async (entry)=>{
|
||||
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
|
||||
1
node_modules/next/dist/esm/server/resume-data-cache/cache-store.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/server/resume-data-cache/cache-store.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
84
node_modules/next/dist/esm/server/resume-data-cache/resume-data-cache.js
generated
vendored
Normal file
84
node_modules/next/dist/esm/server/resume-data-cache/resume-data-cache.js
generated
vendored
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
import { InvariantError } from '../../shared/lib/invariant-error';
|
||||
import { serializeUseCacheCacheStore, parseUseCacheCacheStore } from './cache-store';
|
||||
/**
|
||||
* Serializes a resume data cache into a JSON string for storage or
|
||||
* transmission. Handles 'use cache' values, fetch responses, and encrypted
|
||||
* bound args for inline server functions.
|
||||
*
|
||||
* @param resumeDataCache - The immutable cache to serialize
|
||||
* @returns A Promise that resolves to the serialized cache as a JSON string, or
|
||||
* 'null' if empty
|
||||
*/ export async function stringifyResumeDataCache(resumeDataCache) {
|
||||
if (process.env.NEXT_RUNTIME === 'edge') {
|
||||
throw Object.defineProperty(new InvariantError('`stringifyResumeDataCache` should not be called in edge runtime.'), "__NEXT_ERROR_CODE", {
|
||||
value: "E602",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
} else {
|
||||
if (resumeDataCache.fetch.size === 0 && resumeDataCache.cache.size === 0) {
|
||||
return 'null';
|
||||
}
|
||||
const json = {
|
||||
store: {
|
||||
fetch: Object.fromEntries(Array.from(resumeDataCache.fetch.entries())),
|
||||
cache: Object.fromEntries((await serializeUseCacheCacheStore(resumeDataCache.cache.entries())).filter((entry)=>entry !== null)),
|
||||
encryptedBoundArgs: Object.fromEntries(Array.from(resumeDataCache.encryptedBoundArgs.entries()))
|
||||
}
|
||||
};
|
||||
// Compress the JSON string using zlib. As the data we already want to
|
||||
// decompress is in memory, we use the synchronous deflateSync function.
|
||||
const { deflateSync } = require('node:zlib');
|
||||
return deflateSync(JSON.stringify(json)).toString('base64');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new empty mutable resume data cache for pre-rendering.
|
||||
* Initializes fresh Map instances for both the 'use cache' and fetch caches.
|
||||
* Used at the start of pre-rendering to begin collecting cached values.
|
||||
*
|
||||
* @returns A new empty PrerenderResumeDataCache instance
|
||||
*/ export function createPrerenderResumeDataCache() {
|
||||
return {
|
||||
cache: new Map(),
|
||||
fetch: new Map(),
|
||||
encryptedBoundArgs: new Map(),
|
||||
decryptedBoundArgs: new Map()
|
||||
};
|
||||
}
|
||||
export function createRenderResumeDataCache(prerenderResumeDataCacheOrPersistedCache) {
|
||||
if (process.env.NEXT_RUNTIME === 'edge') {
|
||||
throw Object.defineProperty(new InvariantError('`createRenderResumeDataCache` should not be called in edge runtime.'), "__NEXT_ERROR_CODE", {
|
||||
value: "E556",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
} else {
|
||||
if (typeof prerenderResumeDataCacheOrPersistedCache !== 'string') {
|
||||
// If the cache is already a prerender cache, we can return it directly,
|
||||
// we're just performing a type change.
|
||||
return prerenderResumeDataCacheOrPersistedCache;
|
||||
}
|
||||
if (prerenderResumeDataCacheOrPersistedCache === 'null') {
|
||||
return {
|
||||
cache: new Map(),
|
||||
fetch: new Map(),
|
||||
encryptedBoundArgs: new Map(),
|
||||
decryptedBoundArgs: new Map()
|
||||
};
|
||||
}
|
||||
// This should be a compressed string. Let's decompress it using zlib.
|
||||
// As the data we already want to decompress is in memory, we use the
|
||||
// synchronous inflateSync function.
|
||||
const { inflateSync } = require('node:zlib');
|
||||
const json = JSON.parse(inflateSync(Buffer.from(prerenderResumeDataCacheOrPersistedCache, 'base64')).toString('utf-8'));
|
||||
return {
|
||||
cache: parseUseCacheCacheStore(Object.entries(json.store.cache)),
|
||||
fetch: new Map(Object.entries(json.store.fetch)),
|
||||
encryptedBoundArgs: new Map(Object.entries(json.store.encryptedBoundArgs)),
|
||||
decryptedBoundArgs: new Map()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=resume-data-cache.js.map
|
||||
1
node_modules/next/dist/esm/server/resume-data-cache/resume-data-cache.js.map
generated
vendored
Normal file
1
node_modules/next/dist/esm/server/resume-data-cache/resume-data-cache.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue