• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

flyingsquirrel0419 / layercache / 24083938945

07 Apr 2026 01:28PM UTC coverage: 79.737%. First build
24083938945

push

github

flyingsquirrel0419
Harden cache export, invalidation, and coverage reporting

1180 of 1581 branches covered (74.64%)

Branch coverage included in aggregate %.

455 of 556 new or added lines in 18 files covered. (81.83%)

2220 of 2683 relevant lines covered (82.74%)

236.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.89
/src/integrations/fastify.ts
1
import type { CacheStack } from '../CacheStack'
2

3
interface FastifyLike {
4
  decorate: (name: string, value: unknown) => void
5
  get?: (path: string, handler: (request: unknown, reply: FastifyLikeReply) => unknown | Promise<unknown>) => void
6
}
7

8
interface FastifyLikeReply {
9
  header?: (name: string, value: string) => unknown
10
  send?: (body: unknown) => unknown
11
  statusCode?: number
12
}
13

14
interface FastifyLayercachePluginOptions {
15
  exposeStatsRoute?: boolean
16
  statsPath?: string
17
  allowPublicStatsRoute?: boolean
18
  authorizeStatsRoute?: (request: unknown) => boolean | Promise<boolean>
19
  unauthorizedStatusCode?: number
20
}
21

22
export function createFastifyLayercachePlugin(cache: CacheStack, options: FastifyLayercachePluginOptions = {}) {
3✔
23
  return async (fastify: FastifyLike): Promise<void> => {
3✔
24
    fastify.decorate('cache', cache)
3✔
25

26
    if (options.exposeStatsRoute === true && fastify.get) {
3✔
27
      fastify.get(options.statsPath ?? '/cache/stats', async (request, reply) => {
2✔
28
        const isAuthorized =
29
          options.allowPublicStatsRoute === true ||
1!
30
          (options.authorizeStatsRoute ? await options.authorizeStatsRoute(request) : false)
×
31

32
        reply.header?.('cache-control', 'no-store')
1✔
33
        reply.header?.('x-content-type-options', 'nosniff')
1✔
34

35
        if (!isAuthorized) {
1!
NEW
36
          reply.statusCode = options.unauthorizedStatusCode ?? 403
×
NEW
37
          const body = { error: 'Forbidden' }
×
NEW
38
          if (reply.send) {
×
NEW
39
            reply.send(body)
×
NEW
40
            return
×
41
          }
NEW
42
          return body
×
43
        }
44

45
        const body = cache.getStats()
1✔
46
        if (reply.send) {
1!
47
          reply.send(body)
1✔
48
          return
1✔
49
        }
NEW
50
        return body
×
51
      })
52
    }
53
  }
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc