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