Skip to content

Commit 19b0eaf

Browse files
committed
fixup types and add test
Signed-off-by: flakey5 <[email protected]>
1 parent 5a04bcb commit 19b0eaf

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

lib/cache/sqlite-cache-store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,12 @@ class SqliteCacheStore {
128128
this.#db = new DatabaseSync(opts?.location ?? ':memory:')
129129

130130
/**
131+
* @see https://sqlite.org/schematab.html#interpretation_of_the_schema_table
131132
* @type {{
132133
* type: 'table' | 'index' | (string & {}),
133134
* name: string,
134135
* tbl_name: string,
135-
* sql: number
136+
* sql: string
136137
* }[]}
137138
*/
138139
const items = this.#db.prepare(

test/cache-interceptor/cache-stores.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if (
1313
(env.NODE_OPTIONS && env.NODE_OPTIONS.match(/experimental(-|_)sqlite/)) ||
1414
execArgv.some(argv => argv.match(/experimental(-|_)sqlite/))
1515
) {
16+
const { DatabaseSync } = require('node:sqlite')
1617
const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js')
1718

1819
cacheStoreTests(SqliteCacheStore)
@@ -81,6 +82,32 @@ if (
8182
rawTrailers: requestTrailers
8283
})
8384
})
85+
86+
test('SqliteCacheStore ignores unknown types tied to cacheInterceptor table when sql is right', async (t) => {
87+
const sqliteLocation = 'cache-interceptor.sqlite'
88+
89+
t.after(async () => {
90+
await rm(sqliteLocation)
91+
})
92+
93+
// eslint-disable-next-line no-unused-vars
94+
const _ = new SqliteCacheStore({
95+
location: sqliteLocation
96+
})
97+
98+
const db = new DatabaseSync(sqliteLocation)
99+
db.exec('CREATE VIEW cacheInterceptorView AS SELECT * FROM cacheInterceptor')
100+
101+
// eslint-disable-next-line no-unused-vars
102+
const _2 = new SqliteCacheStore({
103+
location: sqliteLocation
104+
})
105+
106+
equal(
107+
db.prepare('SELECT * FROM sqlite_master WHERE type = \'view\' AND name = \'cacheInterceptorView\'').all().length,
108+
1
109+
)
110+
})
84111
}
85112

86113
/**

test/types/cache-interceptor.test-d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ expectAssignable<CacheInterceptor.MemoryCacheStoreOpts>({
6565
expectAssignable<CacheInterceptor.SqliteCacheStoreOpts>({})
6666
expectAssignable<CacheInterceptor.SqliteCacheStoreOpts>({
6767
location: '',
68-
maxEntries: 0,
6968
maxEntrySize: 0,
7069
errorCallback: (_: Error) => {}
7170
})

types/cache-interceptor.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ declare namespace CacheHandler {
101101
* @default ':memory:'
102102
*/
103103
location?: string
104-
/**
105-
* @default Infinity
106-
*/
107-
maxEntries?: number
108104
/**
109105
* @default Infinity
110106
*/

0 commit comments

Comments
 (0)