@checkstack/cache-api 0.2.4 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,133 @@
1
1
  # @checkstack/cache-api
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @checkstack/backend-api@0.15.2
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - aa89bc5: Replace the bespoke `registerInfrastructureTab()` registry with a standard
14
+ slot-extension contract (`InfrastructureTabsSlot` from
15
+ `@checkstack/infrastructure-common`). Plugins now contribute infrastructure
16
+ tabs via `createSlotExtension`, depending only on the slot owner.
17
+
18
+ The slot system in `@checkstack/frontend-api` gains a second type parameter
19
+ on `createSlot<TContext, TMetadata>` so extensions can declare typed static
20
+ metadata at registration time (label, icon, access rules, ordering for the
21
+ infrastructure tab bar). A new `useSlotExtensions(slot)` hook returns typed
22
+ extensions and subscribes to plugin lifecycle changes.
23
+
24
+ Each tab body now stacks a **Runtime** sub-section (live state, read-only)
25
+ on top of a **Configuration** sub-section (settings, gated by `canUpdate`).
26
+
27
+ **Queue runtime panel.** Surfaces aggregated counts (pending / processing /
28
+ completed / failed) plus three sub-tabs of recent jobs: **Active**, **Recent
29
+ failed** (with the failure message), and **Recent completed** (with
30
+ duration). Job payloads are deliberately not surfaced — they may carry
31
+ secrets and need a separate manage-access gate to be shown.
32
+
33
+ To support this, `Queue<T>` gains a required `listJobs(opts)` method
34
+ returning `JobSummary[]` (no payloads), and `QueueStats` gains a
35
+ `scope: "instance" | "cluster"` field. The in-memory queue keeps rolling
36
+ ring buffers (200 entries) for completed/failed history and tracks active
37
+ jobs by id; BullMQ uses native `getJobs`. `QueueManager.listJobs` aggregates
38
+ across queues and sorts (most-recent-first for terminal states, FIFO for
39
+ active/waiting/delayed).
40
+
41
+ **Cache runtime panel.** Lists the top N entries by size (or by recency) so
42
+ operators can debug a cache filling up. Values are deliberately omitted —
43
+ PII / secret risk. Backends opt in via an optional `listEntries?` method on
44
+ `CacheProvider`; non-supporting backends return `{ supported: false }` and
45
+ the UI renders a "not supported by this backend" hint. The in-memory cache
46
+ implements it using its existing per-entry byte tracking.
47
+
48
+ `CacheStats` also gains `scope: "instance" | "cluster"`.
49
+
50
+ **Multi-instance scope warning.** A new `<InstanceScopeBanner>` component in
51
+ `@checkstack/ui` renders a yellow banner above any runtime panel whose
52
+ backend reports `scope: "instance"` — i.e. in-memory queue or cache running
53
+ in a horizontally scaled deployment. The banner explains the metrics are
54
+ local to the responding replica and recommends switching to a clustered
55
+ backend (Redis-backed queue / cache) for cluster-wide visibility.
56
+
57
+ **Bug fix — stable cache provider proxy.** `CacheManagerImpl.getProvider()`
58
+ now returns a single stable proxy that delegates to whatever provider is
59
+ currently active. Previously, consumers of `createCachedScope` (and any
60
+ direct `cacheManager.getProvider()` caller) captured the active provider
61
+ reference at plugin-init time. After any `setActiveBackend` call — including
62
+ saving the same memory config in the new Cache tab, which reconstructs the
63
+ in-memory cache — those scopes wrote to an orphaned old provider while the
64
+ runtime panel read stats from the new (empty) one, making the runtime panel
65
+ appear to report 0 keys. With the proxy, all consumers share a single stable
66
+ identity and writes always land in the active provider.
67
+
68
+ **Bytes tracking on the in-memory cache.** `InMemoryCache.getStats().sizeBytes`
69
+ now returns a running approximation (UTF-8 bytes of the key plus
70
+ `v8.serialize(value).byteLength`, with a JSON fallback) that's kept in sync
71
+ across all eviction paths. Treat the number as a sanity gauge; it doesn't
72
+ include `Map` per-entry overhead.
73
+
74
+ **Pagination.** Both `Queue<T>.listJobs` and `CacheProvider.listEntries?`
75
+ are offset-paginated. Inputs gain an `offset: number`; outputs change to
76
+ `{ items, total: number | null, hasMore: boolean }`. `total` is nullable
77
+ so backends that can't compute it cheaply still paginate via `hasMore`.
78
+ The UI uses the existing `<Pagination>` component with a 25-row default
79
+ page size. `QueueManager.listJobs` aggregates by over-fetching
80
+ `[0, offset+limit)` per queue, merge-sorting, then slicing the window —
81
+ optimal for the single-queue case, acceptable for the multi-queue case
82
+ within the UI's reasonable page-depth bounds. BullMQ uses native offset
83
+ ranges via `getJobs(types, start, end)` plus `getJobCounts` for `total`.
84
+
85
+ **Pending tab.** The Queue runtime panel exposes a virtual `"pending"`
86
+ state (waiting ∪ delayed, FIFO). It's now the default sub-tab, since
87
+ "what's queued up?" is the most common question. Per-row state is shown
88
+ when viewing the combined list.
89
+
90
+ **Recurring schedules visible under Pending.** Cron- and interval-based
91
+ recurring jobs (e.g. healthchecks) are surfaced under Pending/Delayed
92
+ between fires, with a `nextRunAt` countdown column and a "(recurring)"
93
+ label. `JobSummary` gains optional `nextRunAt: Date` and `recurring:
94
+ boolean` fields. The in-memory queue synthesises these rows from its
95
+ `recurringJobs` registry; BullMQ already materialises the next fire of
96
+ each scheduler as a delayed job and we now surface its trigger time and
97
+ the `repeatJobKey`-derived `recurring` flag.
98
+
99
+ **Bug fix — drop hook emits with no listeners.** `EventBus.emit` no
100
+ longer enqueues a job when zero listeners (distributed or instance-local)
101
+ are registered for the hook. Previously, hooks like
102
+ `core.plugin.initialized` — emitted on every plugin init but subscribed
103
+ to by nothing in the core repo — accumulated one waiting job per emit
104
+ forever. The in-memory queue's `processNext` short-circuits when there
105
+ are zero consumer groups, so its post-loop cleanup never ran for these
106
+ orphaned jobs. The fix drops the emit at the source and logs a debug
107
+ line. Note: in distributed deployments using a Redis-backed queue, this
108
+ means a subscriber on another replica won't receive an event if no
109
+ replica that emits it has a local listener. Plugins needing cross-process
110
+ delivery must register their listener on every replica that should
111
+ receive the hook.
112
+
113
+ **Breaking notes (treated as minor under beta semantics)**:
114
+
115
+ - `@checkstack/infrastructure-common` removes `registerInfrastructureTab`
116
+ and `getInfrastructureTabs`; former callers must register an extension
117
+ into `InfrastructureTabsSlot`.
118
+ - `@checkstack/queue-api`'s `Queue<T>` interface requires the new
119
+ `listJobs(opts)` method returning `ListJobsResult` (paginated). Both
120
+ bundled queue backends (memory, BullMQ) are updated; out-of-tree
121
+ implementations will need to add it.
122
+ - `QueueStats` and `CacheStats` add a required `scope` field.
123
+ - `CacheProvider.listEntries?` (when implemented) now returns
124
+ `ListEntriesResult` instead of `CacheEntrySummary[]`.
125
+ - `JobState` adds a `"pending"` variant.
126
+
127
+ ### Patch Changes
128
+
129
+ - @checkstack/backend-api@0.15.1
130
+
3
131
  ## 0.2.4
4
132
 
5
133
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/cache-api",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
4
4
  "license": "Elastic-2.0",
5
5
  "checkstack": {
6
6
  "type": "tooling"
@@ -8,12 +8,12 @@
8
8
  "type": "module",
9
9
  "main": "src/index.ts",
10
10
  "dependencies": {
11
- "@checkstack/backend-api": "0.14.1",
11
+ "@checkstack/backend-api": "0.15.1",
12
12
  "zod": "^4.0.0"
13
13
  },
14
14
  "devDependencies": {
15
- "@checkstack/tsconfig": "0.0.6",
16
- "@checkstack/scripts": "0.1.2"
15
+ "@checkstack/tsconfig": "0.0.7",
16
+ "@checkstack/scripts": "0.3.1"
17
17
  },
18
18
  "scripts": {
19
19
  "typecheck": "tsgo -b",
@@ -1,3 +1,59 @@
1
+ /**
2
+ * Coarse runtime statistics about a cache backend.
3
+ *
4
+ * All numeric fields are nullable: a value of `null` means "the backend
5
+ * cannot report this metric cheaply" (e.g. a remote cache where counting
6
+ * keys would scan the whole keyspace). The Infrastructure UI renders
7
+ * `null` as "—".
8
+ */
9
+ export interface CacheStats {
10
+ /** Number of cached keys, or `null` if the backend can't report it cheaply. */
11
+ keyCount: number | null;
12
+ /** Approximate memory footprint in bytes, or `null` if unknown. */
13
+ sizeBytes: number | null;
14
+ /** Hit count since the provider started, or `null` if not tracked. */
15
+ hits: number | null;
16
+ /** Miss count since the provider started, or `null` if not tracked. */
17
+ misses: number | null;
18
+ /**
19
+ * `"instance"` if these stats reflect just this process's cache,
20
+ * `"cluster"` if they're shared across the deployment.
21
+ */
22
+ scope: "instance" | "cluster";
23
+ }
24
+
25
+ /**
26
+ * Inspection summary for a single cache entry. Used by the Infrastructure
27
+ * runtime panel to surface "biggest values" / "newest entries". Values are
28
+ * deliberately omitted: cached payloads can carry secrets and PII.
29
+ */
30
+ export interface CacheEntrySummary {
31
+ /** Fully-qualified key as stored (already plugin-prefixed). */
32
+ key: string;
33
+ /** Approximate byte footprint of the entry. */
34
+ byteSize: number;
35
+ /** Absolute expiration time, or `null` for entries with no TTL. */
36
+ expiresAt: Date | null;
37
+ }
38
+
39
+ export interface ListEntriesOptions {
40
+ /** Zero-based offset into the sorted result set. */
41
+ offset: number;
42
+ limit: number;
43
+ sortBy: "biggest" | "newest";
44
+ }
45
+
46
+ /**
47
+ * Paginated result for {@link CacheProvider.listEntries}.
48
+ */
49
+ export interface ListEntriesResult {
50
+ items: CacheEntrySummary[];
51
+ /** Total entry count, or `null` if the backend can't compute it cheaply. */
52
+ total: number | null;
53
+ /** Whether more items exist past `offset + items.length`. */
54
+ hasMore: boolean;
55
+ }
56
+
1
57
  /**
2
58
  * Cache provider interface for key-value storage with optional TTL.
3
59
  *
@@ -36,6 +92,28 @@ export interface CacheProvider {
36
92
  * Check if a key exists and has not expired.
37
93
  */
38
94
  has(key: string): Promise<boolean>;
95
+
96
+ /**
97
+ * Optional: return coarse runtime statistics for the Infrastructure UI.
98
+ *
99
+ * Implementations that can answer this cheaply (in-process caches, or
100
+ * remote caches with a built-in stats command) should implement it.
101
+ * Backends without an affordable stats path should leave it unset; the
102
+ * UI will report "stats unavailable" and the router returns all-null
103
+ * fields.
104
+ */
105
+ getStats?(): Promise<CacheStats>;
106
+
107
+ /**
108
+ * Optional: list cache entries (without values) for the Infrastructure
109
+ * runtime panel, paginated. Used to surface the biggest entries when the
110
+ * cache fills up.
111
+ *
112
+ * Implementations should NOT return values — only key, size, and TTL.
113
+ * Backends that can't enumerate keys cheaply (e.g. some remote caches)
114
+ * should leave this unset.
115
+ */
116
+ listEntries?(opts: ListEntriesOptions): Promise<ListEntriesResult>;
39
117
  }
40
118
 
41
119
  /**