Skip to content

Commit

Permalink
fixup types and add test
Browse files Browse the repository at this point in the history
Signed-off-by: flakey5 <[email protected]>
  • Loading branch information
flakey5 committed Oct 25, 2024
1 parent 5a04bcb commit 19b0eaf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/cache/sqlite-cache-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ class SqliteCacheStore {
this.#db = new DatabaseSync(opts?.location ?? ':memory:')

/**
* @see https://sqlite.org/schematab.html#interpretation_of_the_schema_table
* @type {{
* type: 'table' | 'index' | (string & {}),
* name: string,
* tbl_name: string,
* sql: number
* sql: string
* }[]}
*/
const items = this.#db.prepare(
Expand Down
27 changes: 27 additions & 0 deletions test/cache-interceptor/cache-stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if (
(env.NODE_OPTIONS && env.NODE_OPTIONS.match(/experimental(-|_)sqlite/)) ||
execArgv.some(argv => argv.match(/experimental(-|_)sqlite/))
) {
const { DatabaseSync } = require('node:sqlite')
const SqliteCacheStore = require('../../lib/cache/sqlite-cache-store.js')

cacheStoreTests(SqliteCacheStore)
Expand Down Expand Up @@ -81,6 +82,32 @@ if (
rawTrailers: requestTrailers
})
})

test('SqliteCacheStore ignores unknown types tied to cacheInterceptor table when sql is right', async (t) => {
const sqliteLocation = 'cache-interceptor.sqlite'

t.after(async () => {
await rm(sqliteLocation)
})

// eslint-disable-next-line no-unused-vars
const _ = new SqliteCacheStore({
location: sqliteLocation
})

const db = new DatabaseSync(sqliteLocation)
db.exec('CREATE VIEW cacheInterceptorView AS SELECT * FROM cacheInterceptor')

// eslint-disable-next-line no-unused-vars
const _2 = new SqliteCacheStore({
location: sqliteLocation
})

equal(
db.prepare('SELECT * FROM sqlite_master WHERE type = \'view\' AND name = \'cacheInterceptorView\'').all().length,
1
)
})
}

/**
Expand Down
1 change: 0 additions & 1 deletion test/types/cache-interceptor.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ expectAssignable<CacheInterceptor.MemoryCacheStoreOpts>({
expectAssignable<CacheInterceptor.SqliteCacheStoreOpts>({})
expectAssignable<CacheInterceptor.SqliteCacheStoreOpts>({
location: '',
maxEntries: 0,
maxEntrySize: 0,
errorCallback: (_: Error) => {}
})
4 changes: 0 additions & 4 deletions types/cache-interceptor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ declare namespace CacheHandler {
* @default ':memory:'
*/
location?: string
/**
* @default Infinity
*/
maxEntries?: number
/**
* @default Infinity
*/
Expand Down

0 comments on commit 19b0eaf

Please sign in to comment.