@checkstack/cache-api 0.2.3 → 0.3.0

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