@stacksjs/defaults 0.75.487 → 0.75.489

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.
@@ -688,6 +688,12 @@ that remain exposed.
688
688
 
689
689
  ## Application observability
690
690
 
691
+ The standalone dashboard registers its guarded JSON API even when the application
692
+ skips default route bundles. Its STX state lives in
693
+ `storage/framework/runtime/dashboard/stx`, so opening it does not replace the
694
+ application's generated routes or layout types. Built-in module links follow
695
+ the native schema inventory, including private operational models.
696
+
691
697
  The sidebar, model catalog and global search use the database's native model
692
698
  scope: application overrides and discovered package models, with framework
693
699
  models as a fallback. Global search uses the configured ORM connection on
@@ -706,8 +712,9 @@ model scope and generate/migrate its schema before using worker metrics. The
706
712
  dashboard reads snapshots across processes. A heartbeat older than 60 seconds
707
713
  marks the worker stopped and clears live throughput; sessions are retained for
708
714
  seven days. Completion/failure totals describe those retained worker sessions,
709
- not a durable per-job completion history. Queues containing only failed jobs
710
- stay visible. Database queue rows are authoritative for pending/reserved work.
715
+ not a durable per-job completion history. Declared job queues appear before
716
+ their first dispatch, and queues containing only failed jobs stay visible.
717
+ Database queue rows are authoritative for pending/reserved work.
711
718
 
712
719
  The local error page reads `errors`. An Error model does not capture exceptions
713
720
  by itself: configure `createDatabaseErrorReporter()` from
@@ -1,8 +1,8 @@
1
1
  import { Action } from '@stacksjs/actions/runtime'
2
2
  import { FailedJob, Job } from '@stacksjs/orm'
3
- import { aggregateWorkerMetrics, readWorkerSnapshots } from '@stacksjs/queue'
3
+ import { aggregateWorkerMetrics, discoverJobs, readWorkerSnapshots } from '@stacksjs/queue'
4
4
  import { dashboardOperationalError } from '../dashboard-response'
5
- import { readQueueCounts } from './queue-stats'
5
+ import { readQueueCounts, withDeclaredQueues } from './queue-stats'
6
6
 
7
7
  // A queued job has no `status` column - `queuedJobState` in @stacksjs/queue
8
8
  // holds the rule (reserved_at means a worker has it; available_at in the
@@ -12,7 +12,7 @@ import { readQueueCounts } from './queue-stats'
12
12
 
13
13
  export default new Action({
14
14
  name: 'QueueStatsAction',
15
- description: 'Returns aggregated queue statistics from the jobs/failed_jobs tables and the in-memory metrics tracker.',
15
+ description: 'Returns declared queues, database job counts and shared worker metrics.',
16
16
  method: 'GET',
17
17
  async handle() {
18
18
  try {
@@ -22,7 +22,8 @@ export default new Action({
22
22
  readQueueCounts(),
23
23
  ])
24
24
 
25
- const queues = counts.map(queue => ({
25
+ const definitions = await discoverJobs()
26
+ const queues = withDeclaredQueues(counts, definitions.map(job => job.config.queue ?? 'default')).map(queue => ({
26
27
  name: queue.name,
27
28
  status: queue.active > 0 ? 'active' : 'idle',
28
29
  pending: queue.pending,
@@ -14,6 +14,16 @@ export interface QueueCounts {
14
14
 
15
15
  const queueName = (value: unknown): string => String(value || 'default')
16
16
 
17
+ /** Declared queues remain discoverable before their first job is dispatched. */
18
+ export function withDeclaredQueues(counts: QueueCounts[], names: Iterable<string>): QueueCounts[] {
19
+ const queues = new Map(counts.map(row => [row.name, row]))
20
+ for (const name of [...new Set(names)].sort()) {
21
+ const key = queueName(name)
22
+ if (!queues.has(key)) queues.set(key, { name: key, pending: 0, active: 0, failed: 0, total: 0 })
23
+ }
24
+ return [...queues.values()]
25
+ }
26
+
17
27
  /**
18
28
  * Every queue that has jobs, counted by the database (stacksjs/stacks#3200).
19
29
  *
@@ -7,6 +7,7 @@ export default defineModel({
7
7
  table: 'queue_workers',
8
8
  primaryKey: 'worker_id',
9
9
  autoIncrement: false,
10
+ traits: { useTimestamps: false },
10
11
  dashboard: { access: false },
11
12
  indexes: [{ name: 'queue_workers_heartbeat_at_index', columns: ['heartbeat_at'] }],
12
13
  attributes: {
package/bootstrap.ts CHANGED
@@ -22,6 +22,7 @@
22
22
  */
23
23
 
24
24
  import { config, feature } from '@stacksjs/config'
25
+ import process from 'node:process'
25
26
  import { frameworkPath } from '@stacksjs/path'
26
27
  import { log } from '@stacksjs/logging/runtime'
27
28
  import { bundleMounts, DEFAULT_ROUTE_BUNDLE_FEATURES, route, withRouteAdmission } from '@stacksjs/router'
@@ -108,7 +109,11 @@ async function registerDefaultBundles(): Promise<void> {
108
109
  await route.register(frameworkPath('defaults/routes/dashboard.ts'))
109
110
  // JSON endpoints for the dev dashboard UI. Kept separate from the view
110
111
  // routes above so the data layer is one obvious file to grep.
111
- await route.register(frameworkPath('defaults/routes/dashboard-api.ts'))
112
+ // The standalone dashboard registers this after the app loader finishes,
113
+ // outside table admission. Its home endpoint intentionally reports optional
114
+ // stores as unavailable instead of disappearing when Request is not used.
115
+ if (process.env.STACKS_DASHBOARD_WORKER !== '1')
116
+ await route.register(frameworkPath('defaults/routes/dashboard-api.ts'))
112
117
  // The dev dashboard boots through this file rather than the application
113
118
  // router's importRoutes() path, so load model-declared useApi routes here too.
114
119
  //
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.75.487",
5
+ "version": "0.75.489",
6
6
  "description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/chrisbbreuer",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/defaults",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.487",
5
+ "version": "0.75.489",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -45,7 +45,7 @@
45
45
  "dependencies": {
46
46
  "@iconify-json/f7": "^1.2.2",
47
47
  "@iconify-json/hugeicons": "^1.2.35",
48
- "@stacksjs/mobile": "0.75.487",
48
+ "@stacksjs/mobile": "0.75.489",
49
49
  "@stacksjs/sanitizer": "0.2.807",
50
50
  "@stacksjs/stx": "0.2.807",
51
51
  "@xterm/addon-fit": "^0.11.0",
@@ -134,7 +134,7 @@ onMount(() => {
134
134
  <div class="flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-neutral-700">
135
135
  <div>
136
136
  <h2 class="font-semibold text-gray-900 dark:text-white">Queue breakdown</h2>
137
- <p class="mt-1 text-gray-500 text-sm dark:text-neutral-400">Status totals come from Job records grouped by queue name.</p>
137
+ <p class="mt-1 text-gray-500 text-sm dark:text-neutral-400">Declared queues and recorded jobs, with totals grouped by queue name.</p>
138
138
  </div>
139
139
  <p class="text-gray-500 text-sm dark:text-neutral-400">{{ stats()?.throughputPerMinute || 0 }} jobs/min across reporting workers</p>
140
140
  </div>
@@ -74,6 +74,8 @@ export interface AppNavSection {
74
74
 
75
75
  export interface DiscoveredManifest {
76
76
  models: DiscoveredModel[]
77
+ /** Native schema inventory, including private operational models. */
78
+ schemaModels?: string[]
77
79
  sections: DashboardSectionToggles
78
80
  /** Sections this application declared. Empty for a project that declared none. */
79
81
  nav: AppNavSection[]
@@ -181,11 +183,34 @@ export function parseDiscoveredManifest(source: string): DiscoveredManifest {
181
183
 
182
184
  return {
183
185
  models,
186
+ ...(envelope.schemaModels === undefined ? {} : { schemaModels: normalizeSchemaModels(envelope.schemaModels) }),
184
187
  sections: normalizeManifestToggles(envelope.sections),
185
188
  nav: normalizeManifestNav(envelope.nav),
186
189
  }
187
190
  }
188
191
 
192
+ function normalizeSchemaModels(value: unknown): string[] {
193
+ if (!Array.isArray(value) || value.some(name => typeof name !== 'string'))
194
+ throw new TypeError('manifest schemaModels must be an array of model names')
195
+ return value as string[]
196
+ }
197
+
198
+ /** Hide built-in modules whose backing models are outside this app's schema. */
199
+ export function filterSchemaNavSections(sections: Array<[string, string, NavItem[]]>, schemaModels?: readonly string[]): Array<[string, string, NavItem[]]> {
200
+ if (!schemaModels) return sections
201
+ const available = new Set(schemaModels)
202
+ const required: Record<string, string[]> = {
203
+ '/activity': ['Activity'], '/teams': ['Team'], '/subscribers': ['Subscriber'],
204
+ '/releases': ['Release'], '/deployments': ['Deployment'], '/requests': ['Request'],
205
+ '/queries': ['QueryLog'], '/queries/slow': ['QueryLog'], '/queries/history': ['QueryLog'],
206
+ '/errors': ['Error'], '/notifications/dashboard': ['Notification'], '/logs': ['Log'],
207
+ '/management/permissions': ['Role', 'Permission'], '/kanban': ['Board', 'Card', 'Column'],
208
+ }
209
+ return sections.map(([id, label, items]): [string, string, NavItem[]] => [id, label, id.startsWith('app-nav-') ? items : items.filter(item =>
210
+ (required[item.to] ?? []).every(model => available.has(model)))])
211
+ .filter(([, , items]) => items.length > 0)
212
+ }
213
+
189
214
  /**
190
215
  * App-declared sections are validated at config load; this only has to survive
191
216
  * a manifest written by an older framework version, which has no `nav` key.
@@ -699,7 +724,7 @@ function loadAppNavFromConfig(configPath = resolve(process.cwd(), 'config/dashbo
699
724
  export function buildWebSidebarSections(): WebSidebarSection[] {
700
725
  const manifest = loadDiscoveredManifest()
701
726
  const appNav = manifest.nav.length > 0 ? manifest.nav : loadAppNavFromConfig()
702
- const sections = buildNavSections(manifest.models, manifest.sections, appNav)
727
+ const sections = filterSchemaNavSections(buildNavSections(manifest.models, manifest.sections, appNav), manifest.schemaModels)
703
728
 
704
729
  return [
705
730
  {