@@ -4,7 +4,7 @@ const { DatabaseSync } = require('node:sqlite')
44const { Writable } = require ( 'stream' )
55const { assertCacheKey, assertCacheValue } = require ( '../util/cache.js' )
66
7- const VERSION = 2
7+ const VERSION = 3
88
99/**
1010 * @typedef {import('../../types/cache-interceptor.d.ts').default.CacheStore } CacheStore
@@ -17,7 +17,7 @@ const VERSION = 2
1717 * body: string
1818 * } & import('../../types/cache-interceptor.d.ts').default.CacheValue } SqliteStoreValue
1919 */
20- class SqliteCacheStore {
20+ module . exports = class SqliteCacheStore {
2121 #maxEntrySize = Infinity
2222 #maxCount = Infinity
2323
@@ -103,7 +103,7 @@ class SqliteCacheStore {
103103 method TEXT NOT NULL,
104104
105105 -- Data returned to the interceptor
106- body TEXT NULL,
106+ body BUF NULL,
107107 deleteAt INTEGER NOT NULL,
108108 statusCode INTEGER NOT NULL,
109109 statusMessage TEXT NOT NULL,
@@ -222,7 +222,7 @@ class SqliteCacheStore {
222222 * @type {import('../../types/cache-interceptor.d.ts').default.GetResult }
223223 */
224224 const result = {
225- body : value . body ? parseBufferArray ( JSON . parse ( value . body ) ) : null ,
225+ body : Buffer . from ( value . body ) ,
226226 statusCode : value . statusCode ,
227227 statusMessage : value . statusMessage ,
228228 headers : value . headers ? JSON . parse ( value . headers ) : undefined ,
@@ -276,7 +276,7 @@ class SqliteCacheStore {
276276 if ( existingValue ) {
277277 // Updating an existing response, let's overwrite it
278278 store . #updateValueQuery. run (
279- JSON . stringify ( stringifyBufferArray ( body ) ) ,
279+ Buffer . concat ( body ) ,
280280 value . deleteAt ,
281281 value . statusCode ,
282282 value . statusMessage ,
@@ -294,7 +294,7 @@ class SqliteCacheStore {
294294 store . #insertValueQuery. run (
295295 url ,
296296 key . method ,
297- JSON . stringify ( stringifyBufferArray ( body ) ) ,
297+ Buffer . concat ( body ) ,
298298 value . deleteAt ,
299299 value . statusCode ,
300300 value . statusMessage ,
@@ -435,32 +435,3 @@ function headerValueEquals (lhs, rhs) {
435435
436436 return lhs === rhs
437437}
438-
439- /**
440- * @param {Buffer[] } buffers
441- * @returns {string[] }
442- */
443- function stringifyBufferArray ( buffers ) {
444- const output = new Array ( buffers . length )
445- for ( let i = 0 ; i < buffers . length ; i ++ ) {
446- output [ i ] = buffers [ i ] . toString ( )
447- }
448-
449- return output
450- }
451-
452- /**
453- * @param {string[] } strings
454- * @returns {Buffer[] }
455- */
456- function parseBufferArray ( strings ) {
457- const output = new Array ( strings . length )
458-
459- for ( let i = 0 ; i < strings . length ; i ++ ) {
460- output [ i ] = Buffer . from ( strings [ i ] )
461- }
462-
463- return output
464- }
465-
466- module . exports = SqliteCacheStore
0 commit comments