Skip to content

Commit 7805bb7

Browse files
committed
docs: add some JSDocs on exported function
Nice to have for IDE usage
1 parent 2a0cf63 commit 7805bb7

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/index.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ import fastifyPlugin from "fastify-plugin";
44
import { createOnRequestHook } from "./hooks/onRequest";
55
import { createOnSendHook } from "./hooks/onSend";
66

7-
export interface PluginOptions {
7+
/**
8+
* Plugin options for fastify-aws-dynamodb-cache.
9+
*
10+
* @property {string} dynamoDbRegion - AWS region for DynamoDB client configuration.
11+
* @property {string} [dynamoDbAddress] - Optional custom endpoint (useful for local development/testing).
12+
* @property {string} tableName - DynamoDB table name used for storing cache entries.
13+
* @property {number} defaultTTLSeconds - Global default TTL (in seconds) for all cache entries.
14+
* @property {boolean} [disableCache=false] - If true, disables caching plugin-wide.
15+
* @property {string} [passthroughQueryParam] - If defined, this query parameter will bypass cache when present in a request.
16+
*/
17+
export interface DynamodbCachePluginOptions {
818
dynamoDbRegion: string;
919
dynamoDbAddress?: string;
1020
tableName: string;
@@ -13,7 +23,31 @@ export interface PluginOptions {
1323
passthroughQueryParam?: string;
1424
}
1525

16-
export const dynamodbCache: FastifyPluginAsync<PluginOptions> = (
26+
/**
27+
* Fastify plugin for caching responses in DynamoDB.
28+
*
29+
* Adds support for per-route caching via a shared DynamoDB table.
30+
*
31+
* Use route-level `config.cache` to control TTL and caching behavior:
32+
*
33+
* @example
34+
* ```ts
35+
* fastify.get('/my-route', {
36+
* config: {
37+
* cache: {
38+
* cacheEnabled: true,
39+
* ttlSeconds: 120
40+
* }
41+
* }
42+
* }, async (req, reply) => {
43+
* return { hello: 'world' };
44+
* });
45+
* ```
46+
*
47+
* @param fastify - Fastify instance
48+
* @param opts - Plugin options for DynamoDB caching
49+
*/
50+
export const dynamodbCache: FastifyPluginAsync<DynamodbCachePluginOptions> = (
1751
fastify,
1852
opts
1953
) => {
@@ -65,8 +99,17 @@ export const dynamodbCache: FastifyPluginAsync<PluginOptions> = (
6599

66100
declare module "fastify" {
67101
interface FastifyContextConfig {
102+
/**
103+
* Route-specific cache configuration.
104+
*/
68105
cache?: {
106+
/**
107+
* Enable or disable cache for this route. Defaults to false.
108+
*/
69109
cacheEnabled?: boolean;
110+
/**
111+
* TTL in seconds for the cached response. Overrides global defaultTTLSeconds if set.
112+
*/
70113
ttlSeconds?: number;
71114
};
72115
}

0 commit comments

Comments
 (0)