@checkstack/queue-common 0.1.0 → 0.2.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,83 @@
1
1
  # @checkstack/queue-common
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 180be38: # Queue Lag Warning
8
+
9
+ Added a queue lag warning system that displays alerts when pending jobs exceed configurable thresholds.
10
+
11
+ ## Features
12
+
13
+ - **Backend Stats API**: New `getStats`, `getLagStatus`, and `updateLagThresholds` RPC endpoints
14
+ - **Signal-based Updates**: `QUEUE_LAG_CHANGED` signal for real-time frontend updates
15
+ - **Aggregated Stats**: `QueueManager.getAggregatedStats()` sums stats across all queues
16
+ - **Configurable Thresholds**: Warning (default 100) and Critical (default 500) thresholds stored in config
17
+ - **Dashboard Integration**: Queue lag alert displayed on main Dashboard (access-gated)
18
+ - **Queue Settings Page**: Lag alert and Performance Tuning guidance card with concurrency tips
19
+
20
+ ## UI Changes
21
+
22
+ - Queue lag alert banner appears on Dashboard and Queue Settings when pending jobs exceed thresholds
23
+ - New "Performance Tuning" card with concurrency settings guidance and bottleneck indicators
24
+
25
+ - 7a23261: ## TanStack Query Integration
26
+
27
+ Migrated all frontend components to use `usePluginClient` hook with TanStack Query integration, replacing the legacy `forPlugin()` pattern.
28
+
29
+ ### New Features
30
+
31
+ - **`usePluginClient` hook**: Provides type-safe access to plugin APIs with `.useQuery()` and `.useMutation()` methods
32
+ - **Automatic request deduplication**: Multiple components requesting the same data share a single network request
33
+ - **Built-in caching**: Configurable stale time and cache duration per query
34
+ - **Loading/error states**: TanStack Query provides `isLoading`, `error`, `isRefetching` states automatically
35
+ - **Background refetching**: Stale data is automatically refreshed when components mount
36
+
37
+ ### Contract Changes
38
+
39
+ All RPC contracts now require `operationType: "query"` or `operationType: "mutation"` metadata:
40
+
41
+ ```typescript
42
+ const getItems = proc()
43
+ .meta({ operationType: "query", access: [access.read] })
44
+ .output(z.array(itemSchema))
45
+ .query();
46
+
47
+ const createItem = proc()
48
+ .meta({ operationType: "mutation", access: [access.manage] })
49
+ .input(createItemSchema)
50
+ .output(itemSchema)
51
+ .mutation();
52
+ ```
53
+
54
+ ### Migration
55
+
56
+ ```typescript
57
+ // Before (forPlugin pattern)
58
+ const api = useApi(myPluginApiRef);
59
+ const [items, setItems] = useState<Item[]>([]);
60
+ useEffect(() => {
61
+ api.getItems().then(setItems);
62
+ }, [api]);
63
+
64
+ // After (usePluginClient pattern)
65
+ const client = usePluginClient(MyPluginApi);
66
+ const { data: items, isLoading } = client.getItems.useQuery({});
67
+ ```
68
+
69
+ ### Bug Fixes
70
+
71
+ - Fixed `rpc.test.ts` test setup for middleware type inference
72
+ - Fixed `SearchDialog` to use `setQuery` instead of deprecated `search` method
73
+ - Fixed null→undefined warnings in notification and queue frontends
74
+
75
+ ### Patch Changes
76
+
77
+ - Updated dependencies [7a23261]
78
+ - @checkstack/common@0.3.0
79
+ - @checkstack/signal-common@0.1.1
80
+
3
81
  ## 0.1.0
4
82
 
5
83
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/queue-common",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -14,6 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@checkstack/common": "workspace:*",
17
+ "@checkstack/signal-common": "workspace:*",
17
18
  "@orpc/contract": "^1.13.2",
18
19
  "zod": "^4.0.0"
19
20
  },
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@ export * from "./access";
3
3
  export { queueContract, QueueApi, type QueueContract } from "./rpc-contract";
4
4
  export * from "./plugin-metadata";
5
5
  export { queueRoutes } from "./routes";
6
+ export * from "./signals";
@@ -1,8 +1,4 @@
1
- import { oc } from "@orpc/contract";
2
- import {
3
- createClientDefinition,
4
- type ProcedureMetadata,
5
- } from "@checkstack/common";
1
+ import { createClientDefinition, proc } from "@checkstack/common";
6
2
  import { z } from "zod";
7
3
  import { queueAccess } from "./access";
8
4
  import { pluginMetadata } from "./plugin-metadata";
@@ -10,36 +6,57 @@ import {
10
6
  QueuePluginDtoSchema,
11
7
  QueueConfigurationDtoSchema,
12
8
  UpdateQueueConfigurationSchema,
9
+ QueueStatsDtoSchema,
10
+ QueueLagStatusSchema,
11
+ QueueLagThresholdsSchema,
13
12
  } from "./schemas";
14
13
 
15
- // Base builder with metadata support
16
- const _base = oc.$meta<ProcedureMetadata>({});
17
-
18
14
  // Queue RPC Contract with access metadata
19
15
  export const queueContract = {
20
16
  // Queue plugin queries - Read access
21
- getPlugins: _base
22
- .meta({
23
- userType: "authenticated",
24
- access: [queueAccess.settings.read],
25
- })
26
- .output(z.array(QueuePluginDtoSchema)),
27
-
28
- getConfiguration: _base
29
- .meta({
30
- userType: "authenticated",
31
- access: [queueAccess.settings.read],
32
- })
33
- .output(QueueConfigurationDtoSchema),
17
+ getPlugins: proc({
18
+ operationType: "query",
19
+ userType: "authenticated",
20
+ access: [queueAccess.settings.read],
21
+ }).output(z.array(QueuePluginDtoSchema)),
22
+
23
+ getConfiguration: proc({
24
+ operationType: "query",
25
+ userType: "authenticated",
26
+ access: [queueAccess.settings.read],
27
+ }).output(QueueConfigurationDtoSchema),
34
28
 
35
29
  // Queue configuration updates - Manage access
36
- updateConfiguration: _base
37
- .meta({
38
- userType: "authenticated",
39
- access: [queueAccess.settings.manage],
40
- })
30
+ updateConfiguration: proc({
31
+ operationType: "mutation",
32
+ userType: "authenticated",
33
+ access: [queueAccess.settings.manage],
34
+ })
41
35
  .input(UpdateQueueConfigurationSchema)
42
36
  .output(QueueConfigurationDtoSchema),
37
+
38
+ // Queue statistics - Read access
39
+ getStats: proc({
40
+ operationType: "query",
41
+ userType: "authenticated",
42
+ access: [queueAccess.settings.read],
43
+ }).output(QueueStatsDtoSchema),
44
+
45
+ // Queue lag status (includes thresholds) - Read access
46
+ getLagStatus: proc({
47
+ operationType: "query",
48
+ userType: "authenticated",
49
+ access: [queueAccess.settings.read],
50
+ }).output(QueueLagStatusSchema),
51
+
52
+ // Update lag thresholds - Manage access
53
+ updateLagThresholds: proc({
54
+ operationType: "mutation",
55
+ userType: "authenticated",
56
+ access: [queueAccess.settings.manage],
57
+ })
58
+ .input(QueueLagThresholdsSchema)
59
+ .output(QueueLagThresholdsSchema),
43
60
  };
44
61
 
45
62
  // Export contract type
package/src/schemas.ts CHANGED
@@ -36,3 +36,50 @@ export const UpdateQueueConfigurationSchema = z.object({
36
36
  export type UpdateQueueConfiguration = z.infer<
37
37
  typeof UpdateQueueConfigurationSchema
38
38
  >;
39
+
40
+ /**
41
+ * Queue statistics DTO
42
+ */
43
+ export const QueueStatsDtoSchema = z.object({
44
+ pending: z.number(),
45
+ processing: z.number(),
46
+ completed: z.number(),
47
+ failed: z.number(),
48
+ });
49
+
50
+ export type QueueStatsDto = z.infer<typeof QueueStatsDtoSchema>;
51
+
52
+ /**
53
+ * Lag severity levels
54
+ */
55
+ export const LagSeveritySchema = z.enum(["none", "warning", "critical"]);
56
+ export type LagSeverity = z.infer<typeof LagSeveritySchema>;
57
+
58
+ /**
59
+ * Queue lag thresholds configuration
60
+ */
61
+ export const QueueLagThresholdsSchema = z.object({
62
+ warningThreshold: z
63
+ .number()
64
+ .min(1)
65
+ .default(100)
66
+ .describe("Pending job count to trigger warning"),
67
+ criticalThreshold: z
68
+ .number()
69
+ .min(1)
70
+ .default(500)
71
+ .describe("Pending job count to trigger critical alert"),
72
+ });
73
+
74
+ export type QueueLagThresholds = z.infer<typeof QueueLagThresholdsSchema>;
75
+
76
+ /**
77
+ * Queue lag status response
78
+ */
79
+ export const QueueLagStatusSchema = z.object({
80
+ pending: z.number(),
81
+ severity: LagSeveritySchema,
82
+ thresholds: QueueLagThresholdsSchema,
83
+ });
84
+
85
+ export type QueueLagStatus = z.infer<typeof QueueLagStatusSchema>;
package/src/signals.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { z } from "zod";
2
+ import { createSignal } from "@checkstack/signal-common";
3
+ import { LagSeveritySchema } from "./schemas";
4
+
5
+ /**
6
+ * Signal broadcast when queue lag status changes.
7
+ * Frontend listens to update lag warning UI in real-time.
8
+ */
9
+ export const QUEUE_LAG_CHANGED = createSignal(
10
+ "queue.lag.changed",
11
+ z.object({
12
+ pending: z.number(),
13
+ severity: LagSeveritySchema,
14
+ })
15
+ );