next
Version:
The React Framework
88 lines (87 loc) • 2.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
parseFetchCacheStore: null,
parseUseCacheCacheStore: null,
stringifyFetchCacheStore: null,
stringifyUseCacheCacheStore: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
parseFetchCacheStore: function() {
return parseFetchCacheStore;
},
parseUseCacheCacheStore: function() {
return parseUseCacheCacheStore;
},
stringifyFetchCacheStore: function() {
return stringifyFetchCacheStore;
},
stringifyUseCacheCacheStore: function() {
return stringifyUseCacheCacheStore;
}
});
const _encryptionutils = require("../app-render/encryption-utils");
function parseFetchCacheStore(entries) {
return new Map(entries);
}
function stringifyFetchCacheStore(entries) {
return Array.from(entries);
}
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((0, _encryptionutils.stringToUint8Array)(atob(value)));
// Close the stream
controller.close();
}
}),
tags,
stale,
timestamp,
expire,
revalidate
}));
}
return store;
}
async function stringifyUseCacheCacheStore(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 += (0, _encryptionutils.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
}
];
});
}));
}
//# sourceMappingURL=cache-store.js.map