Skip to content

Commit 597c6be

Browse files
feat(jsdoc): add jsdoc
1 parent 8b353e7 commit 597c6be

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed

src/cache-key.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* Composes a cache key by optionally prefixing it with a namespace
3+
*
4+
* @param key - The base cache key
5+
* @param keyPrefix - Optional prefix to namespace the cache key
6+
* @returns The final cache key, either prefixed (`prefix:key`) or unchanged
7+
*/
18
export function buildCacheKey(key: string, keyPrefix?: string) {
29
return keyPrefix ? `${keyPrefix}:${key}` : key
310
}

src/drivers/better-sqlite3.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import type { Database } from "better-sqlite3"
33
import { buildCacheKey } from "../cache-key"
44
import type { CachifiedAdapterSqliteOptions } from "../index"
55

6+
/**
7+
* Creates a better-sqlite3 cache adapter for use with cachified
8+
*
9+
* @param options - {@linkcode CachifiedAdapterSqliteOptions} plus a database instance
10+
* @param options.database - The better-sqlite3 database instance
11+
* @param options.tableName - Name of the table to store cache entries
12+
* @param options.keyPrefix - Optional prefix to namespace cache keys
13+
* @param options.name - Optional name for the cache adapter
14+
* @returns A Cache instance that stores data in SQLite using better-sqlite3
15+
*/
616
export function betterSqlite3CacheAdapter<Value = unknown>(
717
options: CachifiedAdapterSqliteOptions & {
818
database: Database
@@ -64,6 +74,12 @@ export function betterSqlite3CacheAdapter<Value = unknown>(
6474
}
6575
}
6676

77+
/**
78+
* Creates a cache table in the SQLite database if it doesn't already exist
79+
*
80+
* @param database - The better-sqlite3 Database instance
81+
* @param tableName - Name of the cache table to create
82+
*/
6783
export function createBetterSqlite3CacheTable(
6884
database: Database,
6985
tableName: string,

src/drivers/bun.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { type Cache, totalTtl } from "@epic-web/cachified"
33
import { buildCacheKey } from "../cache-key"
44
import type { CachifiedAdapterSqliteOptions } from "../index"
55

6+
/**
7+
* Creates a Bun SQLite cache adapter for use with cachified
8+
*
9+
* @param options - {@linkcode CachifiedAdapterSqliteOptions} plus a database instance
10+
* @param options.database - The Bun SQLite database instance
11+
* @param options.tableName - Name of the table to store cache entries
12+
* @param options.keyPrefix - Optional prefix to namespace cache keys
13+
* @param options.name - Optional name for the cache adapter
14+
* @returns A Cache instance that stores data in SQLite using Bun's SQLite driver
15+
*/
616
export function bunSqliteCacheAdapter<Value = unknown>(
717
options: CachifiedAdapterSqliteOptions & {
818
database: Database
@@ -62,6 +72,12 @@ export function bunSqliteCacheAdapter<Value = unknown>(
6272
}
6373
}
6474

75+
/**
76+
* Creates a cache table in the SQLite database if it doesn't already exist
77+
*
78+
* @param database - The Bun SQLite Database instance
79+
* @param tableName - Name of the cache table to create
80+
*/
6581
export function createBunSqliteCacheTable(
6682
database: Database,
6783
tableName: string,

src/drivers/sqlite.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import type { Database } from "sqlite"
33
import { buildCacheKey } from "../cache-key"
44
import type { CachifiedAdapterSqliteOptions } from "../index"
55

6+
/**
7+
* Creates a sqlite cache adapter for use with cachified
8+
*
9+
* @param options - {@linkcode CachifiedAdapterSqliteOptions} plus a database instance
10+
* @param options.database - The sqlite database instance
11+
* @param options.tableName - Name of the table to store cache entries
12+
* @param options.keyPrefix - Optional prefix to namespace cache keys
13+
* @param options.name - Optional name for the cache adapter
14+
* @returns A Cache instance that stores data in SQLite using sqlite
15+
*/
616
export function sqliteCacheAdapter<Value = unknown>(
717
options: CachifiedAdapterSqliteOptions & {
818
database: Database
@@ -64,6 +74,12 @@ export function sqliteCacheAdapter<Value = unknown>(
6474
}
6575
}
6676

77+
/**
78+
* Creates a cache table in the SQLite database if it doesn't already exist
79+
*
80+
* @param database - The sqlite Database instance
81+
* @param tableName - Name of the cache table to create
82+
*/
6783
export function createSqliteCacheTable(database: Database, tableName: string) {
6884
return database.exec(`CREATE TABLE IF NOT EXISTS ${tableName} (
6985
key TEXT PRIMARY KEY,

src/drivers/sqlite3.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import type { Database } from "sqlite3"
33
import { buildCacheKey } from "../cache-key"
44
import type { CachifiedAdapterSqliteOptions } from "../index"
55

6+
/**
7+
* Creates a sqlite3 cache adapter for use with cachified
8+
*
9+
* @param options - {@linkcode CachifiedAdapterSqliteOptions} plus a database instance
10+
* @param options.database - The sqlite3 database instance
11+
* @param options.tableName - Name of the table to store cache entries
12+
* @param options.keyPrefix - Optional prefix to namespace cache keys
13+
* @param options.name - Optional name for the cache adapter
14+
* @returns A Cache instance that stores data in SQLite using sqlite3
15+
*/
616
export function sqlite3CacheAdapter<Value = unknown>(
717
options: CachifiedAdapterSqliteOptions & {
818
database: Database
@@ -95,6 +105,12 @@ export function sqlite3CacheAdapter<Value = unknown>(
95105
}
96106
}
97107

108+
/**
109+
* Creates a cache table in the SQLite database if it doesn't already exist
110+
*
111+
* @param database - The sqlite3 Database instance
112+
* @param tableName - Name of the cache table to create
113+
*/
98114
export async function createSqlite3CacheTable(
99115
database: Database,
100116
tableName: string,

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ export * from "./drivers/sqlite"
33
export * from "./drivers/better-sqlite3"
44
export * from "./drivers/bun"
55

6+
/**
7+
* Common options for all SQLite-based cache adapters
8+
*/
69
export type CachifiedAdapterSqliteOptions = {
10+
/** The name of the table to store cache entries */
711
tableName: string
12+
/** Optional prefix to namespace cache keys */
813
keyPrefix?: string
14+
/** Cache adapter name */
915
name?: string
1016
}

0 commit comments

Comments
 (0)