@stacksjs/defaults 0.75.687 → 0.75.690

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.
@@ -38,6 +38,12 @@ buddy migrate:align --relax-constraints # also plan lossless removal of obsolete
38
38
  buddy migrate:align --apply # rename legacy indexes, add missing indexes/FKs/columns, widen losslessly
39
39
  ```
40
40
 
41
+ `generate:db-types` types each table from its model and replays the corpus for
42
+ the rest: a table no model owns is typed from the migrations alone, and a
43
+ column a hand-written migration adds to a model's table (`ALTER TABLE ... ADD
44
+ COLUMN`) is typed as SQLite stores it. Where both declare a column, the model's
45
+ type wins, so an enum stays a union.
46
+
41
47
  An app that develops on one dialect and deploys on another keeps a corpus per
42
48
  dialect (`database/migrations/<dialect>/`, each with its own snapshot). A plain
43
49
  `generate:migrations` moves only the connected dialect and then warns, naming
@@ -86,7 +86,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
86
86
  | `@stacksjs/skills` | [`stacks-skills`](../stacks-skills/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/skills/src/index.ts) | 1 |
87
87
  | `@stacksjs/slug` | [`stacks-slug`](../stacks-slug/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/slug/src/index.ts) | 5 |
88
88
  | `@stacksjs/sms` | [`stacks-sms`](../stacks-sms/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/sms/src/index.ts) | 7 |
89
- | `@stacksjs/socials` | [`stacks-socials`](../stacks-socials/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/index.ts) | 21 |
89
+ | `@stacksjs/socials` | [`stacks-socials`](../stacks-socials/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/index.ts) | 23 |
90
90
  | `@stacksjs/storage` | [`stacks-storage`](../stacks-storage/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/storage/src/index.ts) | 54 |
91
91
  | `@stacksjs/strings` | [`stacks-strings`](../stacks-strings/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/strings/src/index.ts) | 12 |
92
92
  | `@stacksjs/support` | [`stacks-support`](../stacks-support/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/support/src/index.ts) | 6 |
@@ -847,9 +847,9 @@ Guidance: [`stacks-socials`](../stacks-socials/SKILL.md). Source: [storage/frame
847
847
 
848
848
  Read the entrypoint and package export map for re-exported or type-only surfaces.
849
849
 
850
- Local source modules: [src/abstract.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/abstract.ts), [src/authorize.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/authorize.ts), [src/drivers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/drivers/index.ts), [src/exceptions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/exceptions.ts), [src/flows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/flows.ts), [src/handoff.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/handoff.ts), [src/identities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/identities.ts), [src/media.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/media.ts), [src/meta-graph.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/meta-graph.ts), [src/publish-errors.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish-errors.ts), [src/publish.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish.ts), [src/registry.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/registry.ts), [src/text.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/text.ts), [src/token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/token.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/types.ts).
850
+ Local source modules: [src/abstract.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/abstract.ts), [src/authorize.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/authorize.ts), [src/drivers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/drivers/index.ts), [src/errors.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/errors.ts), [src/exceptions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/exceptions.ts), [src/flows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/flows.ts), [src/handoff.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/handoff.ts), [src/identities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/identities.ts), [src/media.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/media.ts), [src/meta-graph.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/meta-graph.ts), [src/publish-errors.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish-errors.ts), [src/publish.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish.ts), [src/registry.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/registry.ts), [src/text.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/text.ts), [src/token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/token.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/types.ts).
851
851
 
852
- Evidence directory: [21 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
852
+ Evidence directory: [23 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
853
853
 
854
854
  ### @stacksjs/storage
855
855
 
@@ -149,6 +149,30 @@ A driver error's isAuthError is narrow; classifySocialError in
149
149
  publish-errors.ts sorts any failure by status and body, and only `expired`
150
150
  means the account must sign in again (a duplicate post on X is a 403).
151
151
 
152
+ Every driver error (BlueskyApiError, TwitterApiError, ...) is a SocialApiError
153
+ from errors.ts: `network`, `status`, the raw `body`, `kind` (the
154
+ classification), `reason` (the network's own sentence) and `retryAfterMs`. Its
155
+ message is the network's reason or the status text, never the raw body.
156
+ `retryAfterMs` reads Retry-After on any answer and, on a rate limit, X's
157
+ `x-rate-limit-reset`, Bluesky's `ratelimit-reset`, Mastodon's
158
+ `x-ratelimit-reset` and Meta's `estimated_time_to_regain_access`. Meta answers
159
+ a rate limit with a 400 ("(#4) Application request limit reached"), which still
160
+ classifies as `rate-limited`.
161
+
162
+ Engagement is a separate capability, like deletion: `supportsMetrics(driver)`,
163
+ then `driver.metrics(identity, uris)` with any number of `PublishedPost.uri`s,
164
+ answering `PostMetrics` (`likes`, `reposts`, `replies`, `quotes`, `views`,
165
+ `shares`). A count the network does not report is absent, not zero, and a post
166
+ that is gone is left out. Bluesky batches 25 a request (no views). Mastodon
167
+ batches 40 with `GET /api/v1/statuses?id[]=` and falls back to one status at a
168
+ time before 4.3 (no views; quotes from 4.5). Threads asks one post at a time
169
+ (`/{id}/insights`, the threads_manage_insights permission). Instagram asks one
170
+ post at a time too (`/{id}/insights`, instagram_manage_insights) and adds
171
+ `reach` and `saves`. LinkedIn batches 20 through Social Metadata: `likes` is
172
+ every reaction together, and it needs r_organization_social_feed for a Page
173
+ (r_member_social_feed for a member, granted to select developers only). X has
174
+ no metrics driver; its counts come with the session driver (#3372).
175
+
152
176
  ## Authorization and operational limits
153
177
 
154
178
  The native terminal consent helper in authorize.ts currently supports X only.
@@ -6,7 +6,7 @@ import { safeGet } from '../../../../resources/functions/dashboard/data'
6
6
  import { resolveDashboardModel } from '../../../../resources/functions/dashboard/model-access'
7
7
  import { dashboardOperationalError } from '../dashboard-response'
8
8
  import { modelActionApplies, modelActionOutcome, modelActions } from './model-actions'
9
- import { humanizeIdentifier, isErasureSubject, isValidModelSlug, modelSchemaColumns, parseRowId, slugToPascal } from './model-write'
9
+ import { humanizeIdentifier, isErasureSubject, isValidModelSlug, modelSchemaColumns, parseRowKey, slugToPascal } from './model-write'
10
10
 
11
11
  /**
12
12
  * `POST /api/dashboard/models/{dashboardModel}/{id}/actions/{dashboardAction}`.
@@ -34,18 +34,19 @@ export default new Action({
34
34
  const slug = String(request.getParam('dashboardModel') ?? '')
35
35
  if (!isValidModelSlug(slug))
36
36
  return response.json({ message: 'Model slug must be lowercase kebab-case.' }, 400)
37
- const id = parseRowId(request.getParam('id'))
38
- if (id === null)
39
- return response.json({ message: 'A numeric row id is required.' }, 400)
40
-
41
37
  const modelName = slugToPascal(slug)
42
38
  const name = String(request.getParam('dashboardAction') ?? '')
43
39
  let Model: any
44
40
  let row: unknown
41
+ let id: string | number | null = null
45
42
  try {
46
43
  Model = await resolveDashboardModel(modelName)
47
44
  if (!Model || typeof Model.find !== 'function')
48
45
  return response.json({ message: `No ORM model named ${modelName}.` }, 404)
46
+ // The model's own key: a number, or the value of one it declares (stacksjs/stacks#3350).
47
+ id = parseRowKey(Model, request.getParam('id'))
48
+ if (id === null)
49
+ return response.json({ message: Model.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
49
50
  row = await Model.find(id)
50
51
  }
51
52
  catch (error) {
@@ -2,7 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions/runtime'
3
3
  import { response } from '@stacksjs/router'
4
4
  import { destroyModelRow, requestAccountId, rowRefusalResponse } from './model-row-writes'
5
- import { parseRowId, resolveWritableModel } from './model-write'
5
+ import { parseRowKey, resolveWritableModel } from './model-write'
6
6
 
7
7
  /**
8
8
  * `DELETE /api/dashboard/models/{slug}/{id}`.
@@ -22,9 +22,10 @@ export default new Action({
22
22
  if ('error' in resolved)
23
23
  return response.json({ message: resolved.error }, resolved.status)
24
24
 
25
- const id = parseRowId(request.getParam('id'))
25
+ // The model's own key: a number, or the value of one it declares (stacksjs/stacks#3350).
26
+ const id = parseRowKey(resolved.Model, request.getParam('id'))
26
27
  if (id === null)
27
- return response.json({ message: 'A numeric row id is required.' }, 400)
28
+ return response.json({ message: resolved.Model?.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
28
29
 
29
30
  const result = await destroyModelRow(resolved, id, await requestAccountId(request))
30
31
  return result.ok ? { ok: true, id, anonymized: result.anonymized } : rowRefusalResponse(result)
@@ -6,7 +6,7 @@ import { resolveDashboardModel } from '../../../../resources/functions/dashboard
6
6
  import { dashboardOperationalError } from '../dashboard-response'
7
7
  import { optionsFromRows } from './model-options'
8
8
  import { modelHintColumn, modelLabelColumn } from './model-relations'
9
- import { humanizeIdentifier, isValidModelSlug, slugToPascal } from './model-write'
9
+ import { humanizeIdentifier, isValidModelSlug, modelRowKey, slugToPascal } from './model-write'
10
10
 
11
11
  /** How many records a search offers. A picker is for finding one, not browsing. */
12
12
  const OPTION_LIMIT = 20
@@ -18,10 +18,12 @@ interface OptionsInput {
18
18
  ids?: unknown
19
19
  }
20
20
 
21
- function parseIds(raw: unknown): number[] {
21
+ /** The ids asked about: numbers, or for a model keyed by a string it declares, those strings. */
22
+ function parseIds(raw: unknown, keyedByString = false): Array<number | string> {
22
23
  const parts = Array.isArray(raw) ? raw : String(raw ?? '').split(',')
23
- const ids = parts.map(part => Number.parseInt(String(part).trim(), 10)).filter(id => Number.isSafeInteger(id) && id > 0)
24
- return [...new Set(ids)].slice(0, ID_LIMIT)
24
+ if (keyedByString)
25
+ return [...new Set(parts.map(part => String(part).trim()).filter(id => id.length > 0 && id.length <= 512))].slice(0, ID_LIMIT)
26
+ return [...new Set(parts.map(part => Number.parseInt(String(part).trim(), 10)).filter(id => Number.isSafeInteger(id) && id > 0))].slice(0, ID_LIMIT)
25
27
  }
26
28
 
27
29
  /**
@@ -58,7 +60,9 @@ export default new Action({
58
60
 
59
61
  const input = request.all()
60
62
  const q = String(input.q ?? '').trim().slice(0, 100)
61
- const ids = parseIds(input.ids)
63
+ const keyedByString = Model.autoIncrement === false
64
+ const key = modelRowKey(Model)
65
+ const ids = parseIds(input.ids, keyedByString)
62
66
  const labelColumn = modelLabelColumn(Model)
63
67
  const hintColumn = modelHintColumn(Model)
64
68
  const modelLabel = humanizeIdentifier(modelName)
@@ -68,7 +72,7 @@ export default new Action({
68
72
  // own query, with raw conditions inside the group.
69
73
  let query = Model.query() as any
70
74
  if (ids.length > 0) {
71
- query = query.whereIn('id', ids)
75
+ query = query.whereIn(key, ids)
72
76
  }
73
77
  else if (q) {
74
78
  const numeric = /^\d+$/.test(q) ? Number(q) : null
@@ -77,8 +81,11 @@ export default new Action({
77
81
  // Lowercased on both sides: a model query's LIKE is case-sensitive
78
82
  // on PostgreSQL (stacksjs/stacks#3202).
79
83
  .map(column => [`LOWER(${column}) LIKE LOWER(?)`, `%${q}%`])
80
- if (numeric !== null)
81
- conditions.push(['id = ?', numeric])
84
+ // The record's own key, typed in: an id, or a declared key's value.
85
+ if (keyedByString)
86
+ conditions.push([`${key} = ?`, q])
87
+ else if (numeric !== null)
88
+ conditions.push([`${key} = ?`, numeric])
82
89
  // Nothing to search by name and the term is not an id: no match, not everything.
83
90
  if (conditions.length === 0)
84
91
  return { options: [], modelLabel, labelColumn }
@@ -89,7 +96,7 @@ export default new Action({
89
96
  })
90
97
  }
91
98
 
92
- const rows = await query.orderBy(labelColumn ?? 'id', 'asc').take(ids.length > 0 ? ID_LIMIT : OPTION_LIMIT).get() as any[]
99
+ const rows = await query.orderBy(labelColumn ?? key, 'asc').take(ids.length > 0 ? ID_LIMIT : OPTION_LIMIT).get() as any[]
93
100
  const list = Array.isArray(rows) ? rows : []
94
101
 
95
102
  const options: ModelOption[] = await optionsFromRows(Model, modelName, list)
@@ -4,7 +4,7 @@ import { response } from '@stacksjs/router'
4
4
  import { resolveDashboardModel } from '../../../../resources/functions/dashboard/model-access'
5
5
  import { dashboardOperationalError } from '../dashboard-response'
6
6
  import { relatedPanels } from './model-related'
7
- import { isValidModelSlug, parseRowId, slugToPascal } from './model-write'
7
+ import { isValidModelSlug, parseRowKey, slugToPascal } from './model-write'
8
8
 
9
9
  /**
10
10
  * `GET /api/dashboard/models/{slug}/{id}/related`.
@@ -22,15 +22,15 @@ export default new Action({
22
22
  const slug = String(request.getParam('slug') ?? '')
23
23
  if (!isValidModelSlug(slug))
24
24
  return response.json({ message: 'Model slug must be lowercase kebab-case.' }, 400)
25
- const id = parseRowId(request.getParam('id'))
26
- if (id === null)
27
- return response.json({ message: 'A numeric row id is required.' }, 400)
28
-
29
25
  const modelName = slugToPascal(slug)
30
26
  try {
31
27
  const Model = await resolveDashboardModel(modelName)
32
28
  if (!Model || typeof Model.find !== 'function')
33
29
  return response.json({ message: `No ORM model named ${modelName}.` }, 404)
30
+ // The model's own key: a number, or the value of one it declares (stacksjs/stacks#3350).
31
+ const id = parseRowKey(Model, request.getParam('id'))
32
+ if (id === null)
33
+ return response.json({ message: Model.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
34
34
  if (!(await Model.find(id)))
35
35
  return response.json({ message: `${modelName} ${id} not found.` }, 404)
36
36
  return { panels: await relatedPanels(Model, modelName, id) }
@@ -10,7 +10,8 @@ import { hasRelations } from './model-relations'
10
10
  import type { RowRefusal } from './model-row-writes'
11
11
  import { destroyModelRow, formFields, requestAccountId, storeModelRow, updateModelRow } from './model-row-writes'
12
12
  import type { ResolvedModel } from './model-write'
13
- import { isValidModelSlug, parseRowId, resolveWritableModel } from './model-write'
13
+ import type { RowKey } from './model-write'
14
+ import { isValidModelSlug, parseRowKey, resolveWritableModel, rowKeyShape } from './model-write'
14
15
 
15
16
  /** What one related panel is asked to change. */
16
17
  interface PanelChanges {
@@ -18,8 +19,9 @@ interface PanelChanges {
18
19
  slug: string
19
20
  /** New rows. `key` is the form's own name for each, so a refusal can say which. */
20
21
  create: Array<{ key: string, fields: Record<string, unknown> }>
21
- update: Array<{ id: number, fields: Record<string, unknown> }>
22
- destroy: number[]
22
+ /** Rows by key: a number, or the value of a key the related model declares. */
23
+ update: Array<{ id: RowKey, fields: Record<string, unknown> }>
24
+ destroy: RowKey[]
23
25
  }
24
26
 
25
27
  /** Where a save was refused: the record's own fields, or one row of one panel. */
@@ -40,10 +42,10 @@ interface PanelPlan {
40
42
  interface SavedPanel {
41
43
  slug: string
42
44
  created: Array<{ key: string, id: unknown }>
43
- updated: number[]
44
- destroyed: number[]
45
+ updated: RowKey[]
46
+ destroyed: RowKey[]
45
47
  /** Of the destroyed: kept, with their personal details removed. */
46
- anonymized: number[]
48
+ anonymized: RowKey[]
47
49
  }
48
50
 
49
51
  /** Thrown inside the transaction to roll it back at the first refusal, carrying where it was. */
@@ -80,23 +82,25 @@ function readRelatedChanges(raw: unknown): PanelChanges[] | string {
80
82
  return `Two new ${entry.slug} rows were sent as ${row.key}.`
81
83
  create.push({ key: row.key, fields: row.fields })
82
84
  }
85
+ // Checked for shape here; read against the related model's own key once
86
+ // its panel is planned (stacksjs/stacks#3350).
83
87
  const update: PanelChanges['update'] = []
84
88
  for (const row of Array.isArray(entry.update) ? entry.update : []) {
85
- const id = isRecord(row) ? parseRowId(row.id) : null
89
+ const id = isRecord(row) ? rowKeyShape(row.id) : null
86
90
  if (id === null || !isRecord(row.fields))
87
91
  return `Each edited ${entry.slug} row needs its id and its fields.`
88
- if (update.some(other => other.id === id))
92
+ if (update.some(other => String(other.id) === String(id)))
89
93
  return `${entry.slug} ${id} was edited twice.`
90
94
  update.push({ id, fields: row.fields })
91
95
  }
92
- const destroy: number[] = []
96
+ const destroy: RowKey[] = []
93
97
  for (const raw of Array.isArray(entry.destroy) ? entry.destroy : []) {
94
- const id = parseRowId(raw)
98
+ const id = rowKeyShape(raw)
95
99
  if (id === null)
96
100
  return `Each deleted ${entry.slug} row needs its id.`
97
- if (update.some(row => row.id === id))
101
+ if (update.some(row => String(row.id) === String(id)))
98
102
  return `${entry.slug} ${id} cannot be both edited and deleted.`
99
- if (!destroy.includes(id))
103
+ if (!destroy.some(other => String(other) === String(id)))
100
104
  destroy.push(id)
101
105
  }
102
106
  panels.push({ slug: entry.slug, create, update, destroy })
@@ -158,10 +162,6 @@ export default new Action({
158
162
  method: 'PATCH',
159
163
  apiResponse: true,
160
164
  async handle(request: RequestInstance) {
161
- const id = parseRowId(request.getParam('id'))
162
- if (id === null)
163
- return response.json({ message: 'A numeric row id is required.' }, 400)
164
-
165
165
  const input = request.all()
166
166
  const fields = formFields(input.fields)
167
167
  const related = readRelatedChanges(input.related)
@@ -176,6 +176,10 @@ export default new Action({
176
176
  const resolved = await resolveWritableModel(request.getParam('slug'), editsRecord ? 'update' : undefined)
177
177
  if ('error' in resolved)
178
178
  return response.json({ message: resolved.error }, resolved.status)
179
+ // The record's own key: a number, or the value of one its model declares (stacksjs/stacks#3350).
180
+ const id = parseRowKey(resolved.Model, request.getParam('id'))
181
+ if (id === null)
182
+ return response.json({ message: resolved.Model?.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
179
183
 
180
184
  try {
181
185
  if (!(await resolved.Model.find(id)))
@@ -197,11 +201,26 @@ export default new Action({
197
201
  const target = await resolveWritableModel(changes.slug)
198
202
  if ('error' in target)
199
203
  return response.json({ message: target.error, at: { operation: 'update', panel: changes.slug } }, target.status)
200
- plans.push({ changes, panel, target })
204
+ // Each row's key read the way its own model is keyed.
205
+ const update: PanelChanges['update'] = []
206
+ for (const row of changes.update) {
207
+ const key = parseRowKey(target.Model, row.id)
208
+ if (key === null)
209
+ return refusedBefore(422, `${panel.label} ${row.id} is not a ${panel.label.toLowerCase()} key.`, { operation: 'update', panel: changes.slug, row: String(row.id) })
210
+ update.push({ id: key, fields: row.fields })
211
+ }
212
+ const destroy: RowKey[] = []
213
+ for (const raw of changes.destroy) {
214
+ const key = parseRowKey(target.Model, raw)
215
+ if (key === null)
216
+ return refusedBefore(422, `${panel.label} ${raw} is not a ${panel.label.toLowerCase()} key.`, { operation: 'destroy', panel: changes.slug, row: String(raw) })
217
+ destroy.push(key)
218
+ }
219
+ plans.push({ changes: { ...changes, update, destroy }, panel, target })
201
220
  }
202
221
 
203
222
  const viewer = await requestAccountId(request)
204
- const own = async (plan: PanelPlan, rowId: number, operation: SaveLocation['operation']): Promise<void> => {
223
+ const own = async (plan: PanelPlan, rowId: RowKey, operation: SaveLocation['operation']): Promise<void> => {
205
224
  const row = await plan.target.Model.find(rowId)
206
225
  if (!row || String(safeGet(row, plan.panel.foreignKey, '')) !== String(id))
207
226
  throw new SaveStopped(refusal(404, `${plan.panel.label} ${rowId} is not one of this ${resolved.modelName.toLowerCase()}'s.`), { operation, panel: plan.changes.slug, row: String(rowId) })
@@ -362,9 +362,8 @@ export default new Action({
362
362
  return dashboardOperationalError(error, `${modelName} records could not be loaded.`, 'ModelShowAction.query')
363
363
  }
364
364
 
365
- // The mutating dashboard routes still require a numeric id.
366
- if (response.primaryKey === 'id')
367
- response.writeCapabilities = modelWriteCapabilities(Model)
365
+ // Every dashboard route takes the model's own key (stacksjs/stacks#3350).
366
+ response.writeCapabilities = modelWriteCapabilities(Model)
368
367
  response.writable = Object.values(response.writeCapabilities).some(Boolean)
369
368
  // A relation is only worth a picker when the dashboard can list the model
370
369
  // it points at. One whose feature is off, or that is kept out of the
@@ -426,7 +425,7 @@ export default new Action({
426
425
  // The model's own actions, and the rows each is for. Decided here, where
427
426
  // the whole row is, so the page never has to be sent the rule. An erased
428
427
  // account is offered none: there is nobody left to act on.
429
- const actions = response.primaryKey === 'id' ? await modelActions(Model, modelName) : []
428
+ const actions = await modelActions(Model, modelName)
430
429
  response.actions = actions.map(publicModelAction)
431
430
  const erased = new Set((response.anonymizedIds ?? []).map(String))
432
431
  for (const [index, row] of stored.entries()) {
@@ -2,7 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions/runtime'
3
3
  import { response } from '@stacksjs/router'
4
4
  import { formFields, rowRefusalResponse, updateModelRow } from './model-row-writes'
5
- import { parseRowId, resolveWritableModel } from './model-write'
5
+ import { parseRowKey, resolveWritableModel } from './model-write'
6
6
 
7
7
  interface ModelWriteInput {
8
8
  fields?: unknown
@@ -26,9 +26,10 @@ export default new Action({
26
26
  if ('error' in resolved)
27
27
  return response.json({ message: resolved.error }, resolved.status)
28
28
 
29
- const id = parseRowId(request.getParam('id'))
29
+ // The model's own key: a number, or the value of one it declares (stacksjs/stacks#3350).
30
+ const id = parseRowKey(resolved.Model, request.getParam('id'))
30
31
  if (id === null)
31
- return response.json({ message: 'A numeric row id is required.' }, 400)
32
+ return response.json({ message: resolved.Model?.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
32
33
 
33
34
  // Nested under `fields`, apart from the URL's params (see `formFields`).
34
35
  const result = await updateModelRow(resolved, id, formFields(request.all().fields))
@@ -17,6 +17,7 @@
17
17
  * sign-ins revoked, and keeps the records that still refer to it.
18
18
  */
19
19
  import { isForeignKeyViolation } from '@stacksjs/error-handling'
20
+ import type { RowKey } from './model-write'
20
21
  import { isErasureSubject } from './model-write'
21
22
 
22
23
  export interface ErasureOutcome {
@@ -41,7 +42,7 @@ export type DestroyModelRecordResult
41
42
  | { ok: false, reason: 'failed', cause: unknown }
42
43
  | { ok: false, reason: 'erasure-failed', cause: unknown }
43
44
 
44
- export async function destroyModelRecord(id: number, dependencies: DestroyModelRecordDependencies): Promise<DestroyModelRecordResult> {
45
+ export async function destroyModelRecord(id: RowKey, dependencies: DestroyModelRecordDependencies): Promise<DestroyModelRecordResult> {
45
46
  const { Model } = dependencies
46
47
  try {
47
48
  const row = await Model.find(id)
@@ -53,7 +54,8 @@ export async function destroyModelRecord(id: number, dependencies: DestroyModelR
53
54
  catch (error) {
54
55
  if (!isForeignKeyViolation(error))
55
56
  return { ok: false, reason: 'failed', cause: error }
56
- if (!isErasureSubject(Model))
57
+ // Erasure is about the account model, which is keyed by number.
58
+ if (!isErasureSubject(Model) || typeof id !== 'number')
57
59
  return { ok: false, reason: 'referenced' }
58
60
  }
59
61
 
@@ -8,7 +8,7 @@ import { anonymizedRows } from '@stacksjs/orm'
8
8
  import { safeGet } from '../../../../resources/functions/dashboard/data'
9
9
  import { resolveDashboardModel } from '../../../../resources/functions/dashboard/model-access'
10
10
  import { modelHintColumn, modelLabelColumn } from './model-relations'
11
- import { humanizeIdentifier, isErasureSubject } from './model-write'
11
+ import { humanizeIdentifier, isErasureSubject, modelRowKey } from './model-write'
12
12
 
13
13
  /** A model's rows as the options a picker lists: an id, a name, and a line that tells two apart. */
14
14
  export async function optionsFromRows(Model: any, modelName: string, rows: unknown[]): Promise<ModelOption[]> {
@@ -21,8 +21,10 @@ export async function optionsFromRows(Model: any, modelName: string, rows: unkno
21
21
  ? await anonymizedRows(modelName, rows.map(row => ({ id: safeGet(row, 'id', 0), name: safeGet(row, 'name', null), email: safeGet(row, 'email', null), avatar: safeGet(row, 'avatar', null) }))).catch(() => [] as boolean[])
22
22
  : []
23
23
 
24
+ // A record is offered by its own key: `id`, or the one its model declares.
25
+ const key = modelRowKey(Model)
24
26
  return rows.map((row, index) => {
25
- const id = safeGet(row, 'id', 0) as number | string
27
+ const id = safeGet(row, key, 0) as number | string
26
28
  if (erased[index] === true)
27
29
  return { id, label: `Anonymized ${modelLabel.toLowerCase()}`, hint: `#${id}` }
28
30
  const named = labelColumn ? String(safeGet(row, labelColumn, '') ?? '').trim() : ''
@@ -38,14 +40,17 @@ export async function optionsFromRows(Model: any, modelName: string, rows: unkno
38
40
  */
39
41
  export async function recordNames(modelName: string, ids: Array<number | string>): Promise<Map<string, string>> {
40
42
  const names = new Map<string, string>()
41
- const wanted = [...new Set(ids.map(id => Number(id)).filter(id => Number.isSafeInteger(id) && id > 0))]
42
- if (wanted.length === 0)
43
- return names
44
43
  try {
45
44
  const Model = await resolveDashboardModel(modelName)
46
45
  if (!Model || typeof Model.query !== 'function')
47
46
  return names
48
- const rows = await Model.query().whereIn('id', wanted).get() as unknown[]
47
+ // Keys as the model has them: numbers, or the strings it declares.
48
+ const wanted = Model.autoIncrement === false
49
+ ? [...new Set(ids.map(id => String(id)).filter(id => id.length > 0 && id.length <= 512))]
50
+ : [...new Set(ids.map(id => Number(id)).filter(id => Number.isSafeInteger(id) && id > 0))]
51
+ if (wanted.length === 0)
52
+ return names
53
+ const rows = await Model.query().whereIn(modelRowKey(Model), wanted).get() as unknown[]
49
54
  for (const option of await optionsFromRows(Model, modelName, Array.isArray(rows) ? rows : []))
50
55
  names.set(String(option.id), option.label)
51
56
  }
@@ -22,7 +22,7 @@ import { recordNames } from './model-options'
22
22
  import { belongsToRelations, hasRelations, modelLabelColumn, pluralizeLabel, relatedForeignKey } from './model-relations'
23
23
  import type { ModelFieldDisplay } from './model-fields'
24
24
  import { modelFormFields } from './model-forms'
25
- import { humanizeIdentifier, type ModelCreateField, modelColumnDisplay, modelColumnLabel, modelListColumns, modelSchemaColumns, modelWriteCapabilities } from './model-write'
25
+ import { humanizeIdentifier, type ModelCreateField, modelColumnDisplay, modelColumnLabel, modelListColumns, modelRowKey, modelSchemaColumns, modelWriteCapabilities, type RowKey } from './model-write'
26
26
 
27
27
  /** How many of a panel's records the page shows before "View all". */
28
28
  export const RELATED_PREVIEW = 5
@@ -150,7 +150,7 @@ export function relatedSummaryColumns(Related: any, foreignKey: string, reachabl
150
150
  }
151
151
 
152
152
  /** One panel's worth, or null when the related model cannot be listed for this record. */
153
- export async function relatedPanel(parentName: string, parentId: number, relation: ModelHasRelation): Promise<RelatedPanel | null> {
153
+ export async function relatedPanel(parentName: string, parentId: RowKey, relation: ModelHasRelation): Promise<RelatedPanel | null> {
154
154
  const Related = await resolveDashboardModel(relation.model).catch(() => null)
155
155
  if (!Related || typeof Related.query !== 'function')
156
156
  return null
@@ -168,10 +168,13 @@ export async function relatedPanel(parentName: string, parentId: number, relatio
168
168
  const columns = relatedSummaryColumns(Related, foreignKey, reachable)
169
169
  const hidden = hiddenModelColumns(Related)
170
170
 
171
+ // A related model keyed by something other than `id` is keyed by that here
172
+ // too: a panel row's `id` is the key its edit and delete are sent with.
173
+ const rowKey = modelRowKey(Related)
171
174
  const total = Number(await Related.query().where(foreignKey, parentId).count()) || 0
172
175
  const found = total === 0
173
176
  ? []
174
- : await Related.query().where(foreignKey, parentId).orderBy('id', 'desc').take(relation.kind === 'one' ? 1 : RELATED_PREVIEW).get() as unknown[]
177
+ : await Related.query().where(foreignKey, parentId).orderBy(rowKey, 'desc').take(relation.kind === 'one' ? 1 : RELATED_PREVIEW).get() as unknown[]
175
178
  const list = Array.isArray(found) ? found : []
176
179
 
177
180
  // The records these rows point at, named in one lookup per model.
@@ -182,7 +185,7 @@ export async function relatedPanel(parentName: string, parentId: number, relatio
182
185
  }
183
186
 
184
187
  const rows = list.map((row) => {
185
- const shown: Record<string, unknown> = { id: safeGet(row, 'id', 0) }
188
+ const shown: Record<string, unknown> = { id: safeGet(row, rowKey, 0) }
186
189
  for (const column of columns) {
187
190
  const stored = safeGet(row, column.key, null)
188
191
  if (column.key === 'id')
@@ -211,7 +214,7 @@ export async function relatedPanel(parentName: string, parentId: number, relatio
211
214
  const values: Record<string, Record<string, unknown>> = {}
212
215
  if (capabilities.update) {
213
216
  for (const row of list)
214
- values[String(safeGet(row, 'id', ''))] = Object.fromEntries(fields.map(entry => [snakeCase(entry.name), safeGet(row, snakeCase(entry.name), null)]))
217
+ values[String(safeGet(row, rowKey, ''))] = Object.fromEntries(fields.map(entry => [snakeCase(entry.name), safeGet(row, snakeCase(entry.name), null)]))
215
218
  }
216
219
  return {
217
220
  kind: relation.kind,
@@ -234,7 +237,7 @@ export async function relatedPanel(parentName: string, parentId: number, relatio
234
237
  }
235
238
 
236
239
  /** Every panel a record's page shows, in the order the model declares them. */
237
- export async function relatedPanels(Model: any, parentName: string, parentId: number): Promise<RelatedPanel[]> {
240
+ export async function relatedPanels(Model: any, parentName: string, parentId: RowKey): Promise<RelatedPanel[]> {
238
241
  const panels: RelatedPanel[] = []
239
242
  for (const relation of hasRelations(Model)) {
240
243
  try {
@@ -17,8 +17,8 @@ import { dashboardOperationalError } from '../dashboard-response'
17
17
  import { destroyModelRecord } from './model-destroy'
18
18
  import { missingRelationErrors } from './model-relations'
19
19
  import { planSwitches, requestedSwitches, storedSwitches } from './model-switches'
20
- import type { ResolvedModel } from './model-write'
21
- import { duplicateFieldErrors, humanizeIdentifier, isAccountModel, prepareModelFields } from './model-write'
20
+ import type { ResolvedModel, RowKey } from './model-write'
21
+ import { duplicateFieldErrors, humanizeIdentifier, isAccountModel, modelRowKey, prepareModelFields, stringKeyedRelations } from './model-write'
22
22
 
23
23
  /** Why a row was not written: what the visitor is told, and for a failure, what went wrong. */
24
24
  export interface RowRefusal {
@@ -78,7 +78,7 @@ export function formFields(raw: unknown): Record<string, unknown> {
78
78
 
79
79
  /** Create one row. `fixed` are columns set by where it is created, not by the form: a related row's link back. */
80
80
  export async function storeModelRow(resolved: ResolvedModel, body: Record<string, unknown>, fixed: Record<string, unknown> = {}): Promise<RowWrite<{ id: unknown }>> {
81
- const { data, errors } = prepareModelFields(resolved.Model, body)
81
+ const { data, errors } = prepareModelFields(resolved.Model, body, false, await stringKeyedRelations(resolved.Model))
82
82
  if (Object.keys(errors).length > 0)
83
83
  return refused(422, 'Validation failed.', errors)
84
84
  if (Object.keys(data).length === 0)
@@ -87,7 +87,8 @@ export async function storeModelRow(resolved: ResolvedModel, body: Record<string
87
87
  const values = { ...toSnakeCaseKeys(data), ...fixed }
88
88
  try {
89
89
  const row = await resolved.Model.create(values)
90
- return { ok: true, id: row?.id ?? row?.attributes?.id ?? null }
90
+ const key = modelRowKey(resolved.Model)
91
+ return { ok: true, id: row?.[key] ?? row?.attributes?.[key] ?? null }
91
92
  }
92
93
  catch (error) {
93
94
  return fieldRefusal(resolved, error, Object.keys(values))
@@ -96,8 +97,8 @@ export async function storeModelRow(resolved: ResolvedModel, body: Record<string
96
97
  }
97
98
 
98
99
  /** Edit one row with the fields that changed, and the switches a trait keeps for itself. */
99
- export async function updateModelRow(resolved: ResolvedModel, id: number, body: Record<string, unknown>): Promise<RowWrite<{ id: number, changed: string[] }>> {
100
- const prepared = prepareModelFields(resolved.Model, body, true)
100
+ export async function updateModelRow(resolved: ResolvedModel, id: RowKey, body: Record<string, unknown>): Promise<RowWrite<{ id: RowKey, changed: string[] }>> {
101
+ const prepared = prepareModelFields(resolved.Model, body, true, await stringKeyedRelations(resolved.Model))
101
102
  if (Object.keys(prepared.errors).length > 0)
102
103
  return refused(422, 'Validation failed.', prepared.errors)
103
104
  const changes = toSnakeCaseKeys(prepared.data)
@@ -108,6 +109,9 @@ export async function updateModelRow(resolved: ResolvedModel, id: number, body:
108
109
  return refused(422, 'Validation failed.', unreadable)
109
110
  if (Object.keys(changes).length === 0 && asked.length === 0)
110
111
  return refused(422, 'No writable fields in the request body.')
112
+ // A switch belongs to a trait of the account models, which are keyed by number.
113
+ if (asked.length > 0 && typeof id !== 'number')
114
+ return refused(422, `${resolved.modelName} has no switches to turn.`)
111
115
 
112
116
  try {
113
117
  const row = await resolved.Model.find(id)
@@ -115,13 +119,13 @@ export async function updateModelRow(resolved: ResolvedModel, id: number, body:
115
119
  return refused(404, `${resolved.modelName} ${id} not found.`)
116
120
  // Refused before anything is written: a switch that cannot be turned
117
121
  // that way refuses the whole save, like any other field's rule.
118
- const { turning, errors } = planSwitches(resolved.Model, asked, asked.length > 0 ? await storedSwitches(resolved.Model, id) : {})
122
+ const { turning, errors } = planSwitches(resolved.Model, asked, asked.length > 0 && typeof id === 'number' ? await storedSwitches(resolved.Model, id) : {})
119
123
  if (Object.keys(errors).length > 0)
120
124
  return refused(422, 'Validation failed.', errors)
121
125
  if (Object.keys(changes).length > 0)
122
126
  await resolved.Model.update(id, changes)
123
127
  for (const request of turning)
124
- await request.switch.set(id, request.on)
128
+ await request.switch.set(id as number, request.on)
125
129
  return { ok: true, id, changed: [...Object.keys(changes), ...turning.map(request => request.switch.column)] }
126
130
  }
127
131
  catch (error) {
@@ -149,7 +153,7 @@ export async function requestAccountId(request: RequestInstance): Promise<number
149
153
  * `./model-destroy`. `viewer` is the account making the request, which is
150
154
  * not deleted from here.
151
155
  */
152
- export async function destroyModelRow(resolved: ResolvedModel, id: number, viewer: number | null): Promise<RowWrite<{ id: number, anonymized: boolean }>> {
156
+ export async function destroyModelRow(resolved: ResolvedModel, id: RowKey, viewer: number | null): Promise<RowWrite<{ id: RowKey, anonymized: boolean }>> {
153
157
  // Deleting the account you are signed in with ends your own access in the
154
158
  // middle of using it, and for the last admin there is no way back in.
155
159
  if (isAccountModel(resolved.Model) && viewer === id)
@@ -593,6 +593,8 @@ export function prepareModelFields(
593
593
  Model: any,
594
594
  body: Record<string, unknown>,
595
595
  partial = false,
596
+ /** Relation fields whose model is keyed by a string it declares ({@link stringKeyedRelations}). */
597
+ stringKeyed: ReadonlySet<string> = new Set(),
596
598
  ): PreparedModelFields {
597
599
  const data: Record<string, unknown> = {}
598
600
  const errors: Record<string, string[]> = {}
@@ -609,7 +611,11 @@ export function prepareModelFields(
609
611
  }
610
612
 
611
613
  const rawValue = hasAttribute ? body[field.name] : body[column]
612
- const value = normalizeModelValue(field.type, rawValue, attributes[field.name]?.validation?.rule)
614
+ // A link to a record keyed by a string it declares keeps that string.
615
+ const keyedByString = field.type === 'relation' && stringKeyed.has(field.name)
616
+ const value = keyedByString
617
+ ? (rawValue === '' || rawValue === null || rawValue === undefined ? null : String(rawValue))
618
+ : normalizeModelValue(field.type, rawValue, attributes[field.name]?.validation?.rule)
613
619
  if ((value === '' || value === null || value === undefined) && field.required) {
614
620
  errors[field.name] = [`${field.label} is required.`]
615
621
  continue
@@ -621,8 +627,12 @@ export function prepareModelFields(
621
627
  }
622
628
 
623
629
  // An id is a whole number above zero, whatever else the field's own rule
624
- // allows. Whether that record exists is the database's to say.
625
- if (field.type === 'relation' && !(typeof value === 'number' && Number.isSafeInteger(value) && value > 0)) {
630
+ // allows, unless the record it points at is keyed by a string (stacksjs/stacks#3350).
631
+ // Whether that record exists is the database's to say.
632
+ const validLink = keyedByString
633
+ ? rowKeyShape(value) !== null
634
+ : typeof value === 'number' && Number.isSafeInteger(value) && value > 0
635
+ if (field.type === 'relation' && !validLink) {
626
636
  errors[field.name] = [`${field.label} must be chosen from the list.`]
627
637
  continue
628
638
  }
@@ -685,6 +695,54 @@ export async function resolveWritableModel(slug: string, operation?: ModelWriteO
685
695
  return { Model, modelName }
686
696
  }
687
697
 
698
+ /** A row's key as a route names it: an auto-increment number, or a declared key's own value. */
699
+ export type RowKey = number | string
700
+
701
+ /** The column a model's rows are keyed by: its declared `primaryKey`, else `id`. */
702
+ export function modelRowKey(Model: any): string {
703
+ return snakeCase(String(Model?.primaryKey || 'id'))
704
+ }
705
+
706
+ /**
707
+ * The row key a dashboard route names, for this model (stacksjs/stacks#3350).
708
+ *
709
+ * An auto-incrementing key, `id` or a declared one, is a positive integer:
710
+ * Postgres will not compare an integer column with a string. A key the model
711
+ * declares with `autoIncrement: false` (`worker_id`, a slug, a UUID) is its
712
+ * value as given, up to 512 characters.
713
+ */
714
+ export function parseRowKey(Model: any, raw: unknown): RowKey | null {
715
+ if (Model?.autoIncrement !== false)
716
+ return parseRowId(raw)
717
+ const value = String(raw ?? '')
718
+ return value.length > 0 && value.length <= 512 ? value : null
719
+ }
720
+
721
+ /**
722
+ * The relation fields of a model whose related model is keyed by a string it
723
+ * declares (`autoIncrement: false`): those links are that string, not a number.
724
+ */
725
+ export async function stringKeyedRelations(Model: any): Promise<Set<string>> {
726
+ const keyed = new Set<string>()
727
+ for (const relation of belongsToRelations(Model)) {
728
+ const Related = await resolveDashboardModel(relation.model).catch(() => null)
729
+ if (Related?.autoIncrement === false)
730
+ keyed.add(relation.field)
731
+ }
732
+ return keyed
733
+ }
734
+
735
+ /**
736
+ * A row key's shape, before the model it belongs to is known: a positive
737
+ * integer, or a non-empty string of at most 512 characters. Read against the
738
+ * model with {@link parseRowKey} once it is.
739
+ */
740
+ export function rowKeyShape(raw: unknown): RowKey | null {
741
+ if (typeof raw === 'number')
742
+ return Number.isInteger(raw) && raw > 0 ? raw : null
743
+ return typeof raw === 'string' && raw.length > 0 && raw.length <= 512 ? raw : null
744
+ }
745
+
688
746
  export function parseRowId(raw: unknown): number | null {
689
747
  const id = Number.parseInt(String(raw ?? ''), 10)
690
748
  return Number.isFinite(id) && id > 0 ? id : null
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.75.687",
5
+ "version": "0.75.690",
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.687",
5
+ "version": "0.75.690",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -46,14 +46,14 @@
46
46
  "@iconify-json/f7": "^1.2.2",
47
47
  "@iconify-json/hugeicons": "^1.2.35",
48
48
  "@stacksjs/desktop": "^0.2.938",
49
- "@stacksjs/mobile": "0.75.687",
49
+ "@stacksjs/mobile": "0.75.690",
50
50
  "@stacksjs/sanitizer": "^0.2.938",
51
51
  "@stacksjs/stx": "^0.2.938",
52
- "@stacksjs/strings": "0.75.687",
52
+ "@stacksjs/strings": "0.75.690",
53
53
  "@xterm/addon-fit": "^0.11.0",
54
54
  "@xterm/xterm": "^6.0.0",
55
55
  "ts-qr-codes": "^0.1.8",
56
- "@stacksjs/support": "0.75.687",
57
- "@stacksjs/browser": "0.75.687"
56
+ "@stacksjs/support": "0.75.690",
57
+ "@stacksjs/browser": "0.75.690"
58
58
  }
59
59
  }
@@ -76,10 +76,7 @@ async function loadRecord(): Promise<void> {
76
76
  // For a component the app placed on this page: it follows the record.
77
77
  modelPageStore.showRecord(slug(), recordId(), loaded)
78
78
  // Not awaited, and a page whose panels cannot be read is still the record's page.
79
- if ((loaded.primaryKey ?? 'id') === 'id')
80
- void fetchModelRelated(slug(), recordId()).then(panels => related.set(panels)).catch(() => related.set([]))
81
- else
82
- related.set([])
79
+ void fetchModelRelated(slug(), recordId()).then(panels => related.set(panels)).catch(() => related.set([]))
83
80
  }
84
81
  catch (error) {
85
82
  record.set(null)
@@ -796,7 +796,9 @@ onDestroy(() => {
796
796
  <template #footer>
797
797
  <div class="px-3 py-2 text-neutral-600 text-xs dark:text-neutral-300" data-sidebar-order-controls data-dashboard-muted :data-sidebar-order-editing="sidebarReordering() ? 'true' : 'false'">
798
798
  <p role="status" aria-live="polite" :text="sidebarOrderStatus.message"></p>
799
- <Button :if="sidebarOrderStatus.ready" class="dashboard-sidebar-order-mode" variant="ghost" size="xs" @click="sidebarReordering.set(!sidebarReordering())">{{ sidebarReordering() ? 'Done reordering' : 'Reorder sidebar' }}</Button>
799
+ <Button :if="sidebarOrderStatus.ready" class="dashboard-sidebar-order-mode" variant="ghost" size="xs" @click="sidebarReordering.set(!sidebarReordering())">
800
+ <span :text="sidebarReordering() ? 'Done reordering' : 'Reorder sidebar'">Reorder sidebar</span>
801
+ </Button>
800
802
  <Button :if="!sidebarOrderStatus.ready" variant="ghost" size="xs" @click="sidebarOrder.load()">Retry loading order</Button>
801
803
  <Button :if="sidebarOrderStatus.ready" variant="ghost" size="xs" :disabled="sidebarOrderStatus.saving" @click="sidebarOrder.reset()">Reset order</Button>
802
804
  </div>