@nest-my-admin/core 0.6.0 → 0.7.3

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.
Files changed (160) hide show
  1. package/README.md +125 -6
  2. package/dist/api/action.service.js +2 -3
  3. package/dist/api/admin-api.service.d.ts +17 -2
  4. package/dist/api/admin-api.service.js +104 -44
  5. package/dist/api/menu.d.ts +35 -2
  6. package/dist/api/menu.js +51 -6
  7. package/dist/api/write-runner.d.ts +2 -2
  8. package/dist/api/write-runner.js +8 -2
  9. package/dist/audit/audit-participant.js +2 -1
  10. package/dist/audit/audit.service.js +5 -3
  11. package/dist/contract.d.ts +6 -0
  12. package/dist/crud/relation-writes.d.ts +6 -0
  13. package/dist/crud/relation-writes.js +32 -0
  14. package/dist/dashboard/dashboard.service.js +1 -2
  15. package/dist/decorators/admin-action.d.ts +3 -2
  16. package/dist/decorators/admin-action.js +9 -8
  17. package/dist/decorators/admin-print.d.ts +2 -1
  18. package/dist/decorators/admin-print.js +2 -3
  19. package/dist/decorators/admin-settings-page.d.ts +1 -0
  20. package/dist/http/admin-http.server.js +8 -1
  21. package/dist/http/ui-messages.d.ts +9 -0
  22. package/dist/http/ui-messages.js +43 -0
  23. package/dist/i18n/texts.d.ts +26 -0
  24. package/dist/i18n/texts.js +31 -0
  25. package/dist/index.d.ts +2 -1
  26. package/dist/inlines/inline-config.d.ts +6 -2
  27. package/dist/inlines/inline-config.js +9 -6
  28. package/dist/inlines/inline-writer.d.ts +1 -1
  29. package/dist/inlines/inline-writer.js +6 -2
  30. package/dist/options.d.ts +28 -5
  31. package/dist/options.js +15 -3
  32. package/dist/pages/page.service.js +5 -4
  33. package/dist/policy/admin-policy.service.d.ts +11 -2
  34. package/dist/policy/admin-policy.service.js +23 -11
  35. package/dist/policy/explain.js +2 -1
  36. package/dist/rbac/rbac.service.js +4 -2
  37. package/dist/registry/resource-registry.js +13 -3
  38. package/dist/resource/admin-context.d.ts +13 -1
  39. package/dist/resource/admin-context.js +10 -0
  40. package/dist/resource/admin-resource-base.d.ts +30 -8
  41. package/dist/resource/admin-resource-base.js +28 -1
  42. package/dist/schema/build-resource-schema.js +3 -3
  43. package/dist/schema/dto-form.d.ts +2 -2
  44. package/dist/schema/dto-form.js +2 -2
  45. package/dist/schema/field-config.d.ts +23 -5
  46. package/dist/schema/field-config.js +33 -18
  47. package/package.json +3 -4
  48. package/dist/admin.module.js.map +0 -1
  49. package/dist/api/action.service.js.map +0 -1
  50. package/dist/api/admin-api.service.js.map +0 -1
  51. package/dist/api/menu-routes.js.map +0 -1
  52. package/dist/api/menu.js.map +0 -1
  53. package/dist/api/write-participant.js.map +0 -1
  54. package/dist/api/write-queue.js.map +0 -1
  55. package/dist/api/write-runner.js.map +0 -1
  56. package/dist/appearance/appearance.service.js.map +0 -1
  57. package/dist/appearance/entities.js.map +0 -1
  58. package/dist/audit/audit-participant.js.map +0 -1
  59. package/dist/audit/audit-query.js.map +0 -1
  60. package/dist/audit/audit-reader.js.map +0 -1
  61. package/dist/audit/audit-routes.js.map +0 -1
  62. package/dist/audit/audit.service.js.map +0 -1
  63. package/dist/audit/diff.js.map +0 -1
  64. package/dist/audit/entities.js.map +0 -1
  65. package/dist/audit/login-failures.js.map +0 -1
  66. package/dist/audit/retention.js.map +0 -1
  67. package/dist/auth/auth-adapter.js.map +0 -1
  68. package/dist/auth/auth.service.js.map +0 -1
  69. package/dist/constants.js.map +0 -1
  70. package/dist/contract.js.map +0 -1
  71. package/dist/crud/computed-columns.js.map +0 -1
  72. package/dist/crud/count.js.map +0 -1
  73. package/dist/crud/cursor.js.map +0 -1
  74. package/dist/crud/list-query-builder.js.map +0 -1
  75. package/dist/crud/list-query.js.map +0 -1
  76. package/dist/crud/list-tabs.js.map +0 -1
  77. package/dist/crud/record-id.js.map +0 -1
  78. package/dist/crud/references.js.map +0 -1
  79. package/dist/crud/relation-writes.js.map +0 -1
  80. package/dist/crud/serialize-full.js.map +0 -1
  81. package/dist/crud/serialize.js.map +0 -1
  82. package/dist/crud/stored-row.js.map +0 -1
  83. package/dist/crud/validate-write.js.map +0 -1
  84. package/dist/dashboard/dashboard-routes.js.map +0 -1
  85. package/dist/dashboard/dashboard.service.js.map +0 -1
  86. package/dist/dashboard/widget-registry.js.map +0 -1
  87. package/dist/decorators/admin-action.js.map +0 -1
  88. package/dist/decorators/admin-field.js.map +0 -1
  89. package/dist/decorators/admin-group.js.map +0 -1
  90. package/dist/decorators/admin-print.js.map +0 -1
  91. package/dist/decorators/admin-resource.js.map +0 -1
  92. package/dist/decorators/admin-scope.js.map +0 -1
  93. package/dist/decorators/admin-settings-page.js.map +0 -1
  94. package/dist/decorators/admin-widget.js.map +0 -1
  95. package/dist/decorators/hooks.js.map +0 -1
  96. package/dist/errors.js.map +0 -1
  97. package/dist/export/export-cells.js.map +0 -1
  98. package/dist/export/xlsx.js.map +0 -1
  99. package/dist/files/admin-file.js.map +0 -1
  100. package/dist/files/admin-files.service.js.map +0 -1
  101. package/dist/files/entities.js.map +0 -1
  102. package/dist/files/file-owner.js.map +0 -1
  103. package/dist/files/file-routes.js.map +0 -1
  104. package/dist/files/files-participant.js.map +0 -1
  105. package/dist/files/files.service.js.map +0 -1
  106. package/dist/files/rich-text.js.map +0 -1
  107. package/dist/files/s3-storage.js.map +0 -1
  108. package/dist/files/sigv4.js.map +0 -1
  109. package/dist/files/sniff.js.map +0 -1
  110. package/dist/files/storage.js.map +0 -1
  111. package/dist/files/transaction-files.js.map +0 -1
  112. package/dist/http/admin-http.server.js.map +0 -1
  113. package/dist/http/cookies.js.map +0 -1
  114. package/dist/http/error-response.js.map +0 -1
  115. package/dist/http/http-io.js.map +0 -1
  116. package/dist/http/router.js.map +0 -1
  117. package/dist/http/session-user.js.map +0 -1
  118. package/dist/http/ui-assets.js.map +0 -1
  119. package/dist/i18n/localized-text.js.map +0 -1
  120. package/dist/i18n/persian.js.map +0 -1
  121. package/dist/index.js.map +0 -1
  122. package/dist/inlines/inline-config.js.map +0 -1
  123. package/dist/inlines/inline-reader.js.map +0 -1
  124. package/dist/inlines/inline-writer.js.map +0 -1
  125. package/dist/internal.js.map +0 -1
  126. package/dist/options.js.map +0 -1
  127. package/dist/pages/page-file-owner.js.map +0 -1
  128. package/dist/pages/page-registry.js.map +0 -1
  129. package/dist/pages/page-routes.js.map +0 -1
  130. package/dist/pages/page.service.js.map +0 -1
  131. package/dist/policy/admin-policy.service.js.map +0 -1
  132. package/dist/policy/catalog.js.map +0 -1
  133. package/dist/policy/effective.js.map +0 -1
  134. package/dist/policy/explain.js.map +0 -1
  135. package/dist/policy/roles.js.map +0 -1
  136. package/dist/print/html.js.map +0 -1
  137. package/dist/print/print-page.js.map +0 -1
  138. package/dist/rbac/entities.js.map +0 -1
  139. package/dist/rbac/escalation.js.map +0 -1
  140. package/dist/rbac/rbac-routes.js.map +0 -1
  141. package/dist/rbac/rbac.service.js.map +0 -1
  142. package/dist/registry/db-names.js.map +0 -1
  143. package/dist/registry/hook-warnings.js.map +0 -1
  144. package/dist/registry/resource-registry.js.map +0 -1
  145. package/dist/resource/admin-context.js.map +0 -1
  146. package/dist/resource/admin-resource-base.js.map +0 -1
  147. package/dist/schema/build-resource-schema.js.map +0 -1
  148. package/dist/schema/column-field.js.map +0 -1
  149. package/dist/schema/currency.js.map +0 -1
  150. package/dist/schema/dto-constraints.js.map +0 -1
  151. package/dist/schema/dto-fields.js.map +0 -1
  152. package/dist/schema/dto-form.js.map +0 -1
  153. package/dist/schema/field-config.js.map +0 -1
  154. package/dist/schema/field-paths.js.map +0 -1
  155. package/dist/schema/filter-operators.js.map +0 -1
  156. package/dist/schema/humanize.js.map +0 -1
  157. package/dist/schema/nested-fields.js.map +0 -1
  158. package/dist/schema/relation-fields.js.map +0 -1
  159. package/dist/schema/suggest.js.map +0 -1
  160. package/dist/schema/titles.js.map +0 -1
@@ -19,7 +19,6 @@ import { recordIdOf } from '../crud/record-id.js';
19
19
  import { getCanRules, getScopes } from '../decorators/admin-scope.js';
20
20
  import { AdminForbiddenError, AdminForbiddenFieldsError, AdminNotFoundError } from '../errors.js';
21
21
  import { AdminAuthService } from '../auth/auth.service.js';
22
- import { resolveText } from '../i18n/localized-text.js';
23
22
  import { PageRegistry, unknownPage } from '../pages/page-registry.js';
24
23
  import { ResourceRegistry } from '../registry/resource-registry.js';
25
24
  import { createAdminContext } from '../resource/admin-context.js';
@@ -29,6 +28,7 @@ import { printCode } from '../decorators/admin-print.js';
29
28
  import { EffectivePermissions } from './effective.js';
30
29
  import { explainPermissions } from './explain.js';
31
30
  import { RESOURCE_OPERATIONS, actionCode, checkRoles } from './roles.js';
31
+ import { scopedText } from '../i18n/texts.js';
32
32
  const RANK = { hidden: 0, view: 1, edit: 2 };
33
33
  const OPEN = new EffectivePermissions([], true);
34
34
  /**
@@ -129,7 +129,7 @@ let AdminPolicy = class AdminPolicy {
129
129
  ctx.locale = locale;
130
130
  const permissions = await this.forUser(user);
131
131
  ctx.permissions = permissions;
132
- const pages = this.pages.list().map((page) => ({ name: page.name, label: resolveText(page.label, locale ?? this.options.locale, this.options.locale) }));
132
+ const pages = this.pages.list().map((page) => ({ name: page.name, label: this.options.texts(page.label, locale ?? this.options.locale, `page.${page.name}`) }));
133
133
  return explainPermissions(this, { user, entry, labels, pages, ctx: ctx, sources: await this.roleSources(user), record });
134
134
  }
135
135
  permissionsOf(ctx) {
@@ -185,7 +185,7 @@ let AdminPolicy = class AdminPolicy {
185
185
  if (!this.canPage(page, 'view', ctx))
186
186
  throw unknownPage(page.name);
187
187
  if (operation === 'update' && !this.canPage(page, 'update', ctx)) {
188
- throw new AdminForbiddenError(`You may not change ${resolveText(page.label, ctx.locale ?? this.options.locale, this.options.locale)}`);
188
+ throw new AdminForbiddenError(`You may not change ${this.options.texts(page.label, ctx.locale ?? this.options.locale, `page.${page.name}`)}`);
189
189
  }
190
190
  }
191
191
  /** Levels of every field and path of the resource, for this user. */
@@ -536,6 +536,13 @@ let AdminPolicy = class AdminPolicy {
536
536
  }
537
537
  return true;
538
538
  }
539
+ /**
540
+ * Whether a row of the inline `child` may be added under `parent` (the parent entity as its resource reads it): every
541
+ * `@AdminCan('create')` rule of the child agrees; a rule that throws says no. True for a child without one.
542
+ */
543
+ createRule(child, parent, ctx) {
544
+ return this.recordRule(child, 'create', parent, ctx);
545
+ }
539
546
  /** 403 when `@AdminCan` says no for this record. */
540
547
  requireRecordRule(entry, operation, entity, ctx) {
541
548
  if (!this.recordRule(entry, operation, entity, ctx))
@@ -551,11 +558,14 @@ let AdminPolicy = class AdminPolicy {
551
558
  const perms = this.permissionsOf(ctx);
552
559
  const target = entry.resource.constructor;
553
560
  const recordActions = [...entry.actions.values()].filter((action) => action.target === 'record');
554
- const hasRules = ['update', 'delete', ...recordActions.map((action) => action.name)].some((name) => getCanRules(target, name).length > 0);
561
+ // Inline children with a create rule: whether a row may be added under each record.
562
+ const ruledInlines = entry.inlines.filter((inline) => getCanRules(inline.child.resource.constructor, 'create').length > 0);
563
+ const hasRules = ruledInlines.length > 0 || ['update', 'delete', ...recordActions.map((action) => action.name)].some((name) => getCanRules(target, name).length > 0);
555
564
  // Per-record labels are computed for everyone, superusers too.
556
565
  if (perms.superuser && !hasRules && !recordActions.some((action) => action.labelFor))
557
566
  return undefined;
558
567
  const locale = ctx.locale ?? this.options.locale;
568
+ const actionText = scopedText(this.options.texts, locale, `resource.${entry.schema.name}`);
559
569
  const keys = entry.schema.primaryKeys;
560
570
  const ids = entities.map((entity) => (keys.length === 1 ? entity[keys[0]] : Object.fromEntries(keys.map((key) => [key, entity[key]]))));
561
571
  const result = new Map();
@@ -575,11 +585,12 @@ let AdminPolicy = class AdminPolicy {
575
585
  ...(recordActions.length > 0
576
586
  ? {
577
587
  actions: Object.fromEntries(offered.map((action) => {
578
- const label = actionLabel(action, entity, locale, this.options.locale);
588
+ const label = actionLabel(action, entity, actionText);
579
589
  return [action.name, updatable && label !== null && this.recordRule(entry, action.name, entity, ctx) ? label : false];
580
590
  })),
581
591
  }
582
592
  : {}),
593
+ ...(ruledInlines.length > 0 ? { inlines: Object.fromEntries(ruledInlines.map((inline) => [inline.name, { create: this.createRule(inline.child, entity, ctx) }])) } : {}),
583
594
  });
584
595
  }
585
596
  return result;
@@ -667,12 +678,13 @@ export { AdminPolicy };
667
678
  export function topLevelFields(schema) {
668
679
  return schema.fields.filter((field) => !field.name.includes('.'));
669
680
  }
670
- /** An action's label on one record: `label.for(record)` in `locale` (`null` hides it there), else its label. */
671
- export function actionLabel(action, record, locale, defaultLocale) {
672
- if (!action.labelFor)
673
- return resolveText(action.label, locale, defaultLocale);
674
- const label = action.labelFor(record);
675
- return label === null ? null : resolveText(label, locale, defaultLocale);
681
+ /**
682
+ * An action's label on one record: `label.for(record)` (`null` hides it there), else its label, through `text`
683
+ * (the resource's texts; the key is the action's label key either way).
684
+ */
685
+ export function actionLabel(action, record, text) {
686
+ const label = action.labelFor ? action.labelFor(record) : action.label;
687
+ return label === null ? null : text(label, `actions.${action.name}.label`);
676
688
  }
677
689
  /** The list without `export`, for a viewer who may not export. */
678
690
  function withoutExport(list, keep) {
@@ -3,6 +3,7 @@ import { parseRecordId, recordIdOf } from '../crud/record-id.js';
3
3
  import { runInAdminContext } from '../resource/admin-context.js';
4
4
  import { EffectivePermissions } from './effective.js';
5
5
  import { RESOURCE_OPERATIONS, actionCode, codeMatches, pageCode } from './roles.js';
6
+ import { bootText } from '../i18n/texts.js';
6
7
  const SCOPED = ['view', 'update', 'delete'];
7
8
  /**
8
9
  * Why a user may or may not do things with a resource (spec §6.7). Every answer comes from the code the API
@@ -140,7 +141,7 @@ async function explainRecord(policy, entry, raw, ctx) {
140
141
  const recordActions = [...entry.actions.values()].filter((action) => action.target === 'record');
141
142
  const updatable = update || reasons.update === 'rule';
142
143
  // A per-record label of `null` hides the action on that record, as in `_perm.actions`.
143
- const actions = recordActions.filter((action) => updatable && policy.canRunAction(entry, action, ctx) && policy.recordRule(entry, action.name, found, ctx) && actionLabel(action, found, 'en', 'en') !== null).map((action) => action.name);
144
+ const actions = recordActions.filter((action) => updatable && policy.canRunAction(entry, action, ctx) && policy.recordRule(entry, action.name, found, ctx) && actionLabel(action, found, bootText) !== null).map((action) => action.name);
144
145
  return { id: key, exists, view, update, delete: del, ...(recordActions.length > 0 ? { actions } : {}), reasons };
145
146
  }
146
147
  //# sourceMappingURL=explain.js.map
@@ -25,7 +25,7 @@ import { buildCatalog } from '../policy/catalog.js';
25
25
  import { checkRoles } from '../policy/roles.js';
26
26
  import { PageRegistry } from '../pages/page-registry.js';
27
27
  import { ResourceRegistry } from '../registry/resource-registry.js';
28
- import { AdminContext } from '../resource/admin-context.js';
28
+ import { AdminContext, inAdminTransaction, markTransaction } from '../resource/admin-context.js';
29
29
  import { ADMIN_RBAC_ENTITIES, NmaGroup, NmaGroupMember, NmaGroupRole, NmaRole, NmaUserRole } from './entities.js';
30
30
  import { escalations } from './escalation.js';
31
31
  const NAME = /^[a-z0-9][a-z0-9._-]{0,99}$/i;
@@ -69,13 +69,15 @@ let AdminRbac = class AdminRbac {
69
69
  const run = () => this.db.transaction(async (tx) => {
70
70
  const result = await work(tx, (input) => void (input && entries.push(input)));
71
71
  const inside = { correlationId: ctx.correlationId, user: ctx.user, viewAs: ctx.viewAs, manager: tx };
72
+ // A transaction of its own: its entries are written in it and roll back with the change.
73
+ markTransaction(inside);
72
74
  if (this.audit.joins(inside))
73
75
  for (const input of entries.splice(0))
74
76
  await this.audit.record(input, inside);
75
77
  return result;
76
78
  });
77
79
  // Queued with the admin's other writes on a single-connection driver, unless this runs inside one of them.
78
- const result = await (current?.manager?.connection === this.db ? run() : exclusive(this.db, run));
80
+ const result = await (current && inAdminTransaction(current) && current.manager?.connection === this.db ? run() : exclusive(this.db, run));
79
81
  for (const input of entries)
80
82
  await this.audit.recordAfter(input, ctx);
81
83
  this.invalidate();
@@ -34,6 +34,8 @@ import { hookWarnings } from './hook-warnings.js';
34
34
  import { resolveInlines } from '../inlines/inline-config.js';
35
35
  import { checkTabs } from '../crud/list-tabs.js';
36
36
  import { addComputedSort, checkComputed } from '../crud/computed-columns.js';
37
+ import { bootText } from '../i18n/texts.js';
38
+ import { getCanRules } from '../decorators/admin-scope.js';
37
39
  const DEFAULT_GROUP_ORDER = 100;
38
40
  /** `order` of a resource or a settings page that sets none: the same default as a group's. */
39
41
  export const DEFAULT_MEMBER_ORDER = 100;
@@ -144,10 +146,17 @@ let ResourceRegistry = class ResourceRegistry {
144
146
  });
145
147
  }
146
148
  // Inline children are edited on their parent's page: out of navigation unless they ask to stay.
147
- for (const child of this.list().flatMap((entry) => entry.inlines.map((inline) => inline.child))) {
149
+ const children = new Set(this.list().flatMap((entry) => entry.inlines.map((inline) => inline.child)));
150
+ for (const child of children) {
148
151
  if (child.navOption === undefined)
149
152
  child.nav = false;
150
153
  }
154
+ // `@AdminCan('create')` judges adding a row under a parent: only an inline child has one.
155
+ for (const entry of this.list()) {
156
+ if (!children.has(entry) && getCanRules(entry.resource.constructor, 'create').length > 0) {
157
+ throw new Error(`${entry.className}: @AdminCan('create') needs ${entry.className} to be an inline child (no form.layout names it)`);
158
+ }
159
+ }
151
160
  // A parent and its inlines are saved together or not at all: a promise only a transaction can keep.
152
161
  const parent = this.list().find((entry) => entry.inlines.length > 0);
153
162
  if (parent && !this.options.transactions) {
@@ -274,6 +283,7 @@ let ResourceRegistry = class ResourceRegistry {
274
283
  throw new Error(`${className}: ${message}`);
275
284
  });
276
285
  const schema = buildResourceSchema({ definition, resource, metadata, moduleGroup, className });
286
+ resource.attachUpdateFields(() => schema.form.update);
277
287
  checkTabs(schema, resource.list?.tabs, (message) => {
278
288
  throw new Error(`${className}: ${message}`);
279
289
  });
@@ -303,11 +313,11 @@ let ResourceRegistry = class ResourceRegistry {
303
313
  throw new Error(`${className}: @AdminAction "${atomic.name}" is \`atomic\`, which needs the admin's transactions; they are off (\`transactions: false\`)`);
304
314
  }
305
315
  // Texts in the first language given, like the fields; AdminApiService localizes per request.
306
- schema.actions = [...actions.values()].map((action) => toActionSchema(action, '', ''));
316
+ schema.actions = [...actions.values()].map((action) => toActionSchema(action, bootText));
307
317
  const prints = resolvePrints(resource.constructor, [...BASE_MEMBERS, ...actions.keys()], (message) => {
308
318
  throw new Error(`${className}: ${message}`);
309
319
  });
310
- schema.prints = [...prints.values()].map((print) => toPrintSchema(print, '', ''));
320
+ schema.prints = [...prints.values()].map((print) => toPrintSchema(print, bootText));
311
321
  const exported = checkExport(resource.list?.export, schema, (message) => {
312
322
  throw new Error(`${className}: list.export: ${message}`);
313
323
  });
@@ -9,7 +9,8 @@ export interface AdminContext {
9
9
  /** The underlying Node request (an Express request in v1). */
10
10
  request: IncomingMessage;
11
11
  /**
12
- * The transaction's EntityManager while a create/update/delete runs (undefined for reads).
12
+ * The transaction's EntityManager while a create/update/delete runs (the DataSource's own with `transactions: false`;
13
+ * undefined for reads). Write methods get it typed as set (`AdminWriteContext`).
13
14
  * Use it in your services to write inside the admin's transaction. A service that ignores it and uses its
14
15
  * own repository writes on a separate pooled connection on Postgres/MySQL: outside the transaction, and able
15
16
  * to block on the admin transaction's locks (writing the same row or the same unique key blocks until the admin
@@ -30,6 +31,17 @@ export interface AdminContext {
30
31
  /** Whether the user holds a permission code (`order.view_all`, `reports.run`); superusers hold all. */
31
32
  can(code: string): boolean;
32
33
  }
34
+ /**
35
+ * The context of a create, update, delete, action or settings-page save: `manager` is always set there (the
36
+ * transaction's, or the DataSource's own with `transactions: false`).
37
+ */
38
+ export type AdminWriteContext = AdminContext & {
39
+ manager: EntityManager;
40
+ };
41
+ /** @internal Marks `ctx` as running inside an admin transaction (`WriteRunner.run`). */
42
+ export declare function markTransaction(ctx: object): void;
43
+ /** @internal Whether `ctx` runs inside an admin transaction (row locks, audit entries in the same transaction). */
44
+ export declare function inAdminTransaction(ctx: object): boolean;
33
45
  /** @internal Runs `fn` with `ctx` as the current admin context. Not exported from the package: host code must not fabricate contexts. */
34
46
  export declare function runInAdminContext<T>(ctx: AdminContext, fn: () => T): T;
35
47
  export declare const AdminContext: {
@@ -1,5 +1,15 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
2
  import { randomUUID } from 'node:crypto';
3
+ /** Contexts of an open admin transaction (not merely a write: with `transactions: false` a write has a manager but no transaction). */
4
+ const transactional = new WeakSet();
5
+ /** @internal Marks `ctx` as running inside an admin transaction (`WriteRunner.run`). */
6
+ export function markTransaction(ctx) {
7
+ transactional.add(ctx);
8
+ }
9
+ /** @internal Whether `ctx` runs inside an admin transaction (row locks, audit entries in the same transaction). */
10
+ export function inAdminTransaction(ctx) {
11
+ return transactional.has(ctx);
12
+ }
3
13
  /** The box is deactivated when the request ends, so timers and clients created inside it see no context. */
4
14
  const storage = new AsyncLocalStorage();
5
15
  /** @internal Runs `fn` with `ctx` as the current admin context. Not exported from the package: host code must not fabricate contexts. */
@@ -194,6 +194,8 @@ export interface FormConfig {
194
194
  * (`relation`: the relation field), with a link to it (`link`, «مشاهده پروفایل»).
195
195
  */
196
196
  export interface AsideCardConfig {
197
+ /** Names this card for `translate` (`resource.<r>.form.<key>`). */
198
+ key?: string;
197
199
  title: LocalizedText;
198
200
  icon?: string;
199
201
  fields: string[] | {
@@ -211,7 +213,15 @@ export interface RecordLinkConfig {
211
213
  * Base class for admin resources. Override `create`/`update` (and the finders) to route
212
214
  * admin operations through your own services, so business rules are never bypassed.
213
215
  */
214
- export declare abstract class AdminResourceBase<T extends ObjectLiteral = ObjectLiteral> {
216
+ /**
217
+ * `Id` is the type of a record id in `findOne`, `update`, `delete`, `restore` and `purge`: `number` for an integer
218
+ * primary key, `string` for bigint, uuid and text keys, `{ key: value }` for composite keys. The admin parses ids to
219
+ * that type before they reach you; the parameter only tells TypeScript.
220
+ *
221
+ * Write methods (`create`, `update`, `delete`, `restore`, `purge`, actions) always get a context with `manager` set:
222
+ * type the parameter of your override as `AdminWriteContext` to use it without `!`.
223
+ */
224
+ export declare abstract class AdminResourceBase<T extends ObjectLiteral = ObjectLiteral, Id extends RecordId = RecordId> {
215
225
  #private;
216
226
  list?: ListConfig<T>;
217
227
  form?: FormConfig;
@@ -219,6 +229,16 @@ export declare abstract class AdminResourceBase<T extends ObjectLiteral = Object
219
229
  fields?: FieldsConfig<T>;
220
230
  /** External links of a record, shown in its header. */
221
231
  links(_record: T): RecordLinkConfig[];
232
+ /**
233
+ * Fields locked on this record, on top of each field's `readonlyIf`: the record shows them read-only and a write that
234
+ * changes one is refused (422), inline rows included. Lock everything but some with `this.updateFields`. Must be
235
+ * synchronous and cheap (it runs per record of a page). A throw locks every field of the update form. Default: none.
236
+ */
237
+ readonlyFields(_record: T, _ctx: AdminContext): readonly string[];
238
+ /** @internal Called once by the registry: where `updateFields` reads the update form from. */
239
+ attachUpdateFields(read: () => readonly string[]): void;
240
+ /** The fields of the update form (`schema.form.update`): what `readonlyFields` can lock. */
241
+ protected get updateFields(): readonly string[];
222
242
  /** @internal Called once by the policy during bootstrap: adds the user's view scopes (spec §6.4) to reads. */
223
243
  attachScoper(scoper: (qb: SelectQueryBuilder<any>, ctx: AdminContext | undefined) => SelectQueryBuilder<any>): void;
224
244
  /** `query()` and then the signed-in user's row scopes: what every read of this resource starts from. */
@@ -253,7 +273,7 @@ export declare abstract class AdminResourceBase<T extends ObjectLiteral = Object
253
273
  */
254
274
  findMany(params: ListParams, ctx: AdminContext): Promise<FindManyResult<T>>;
255
275
  /** `options.withDeleted` also finds records in the trash (restore and purge use it). */
256
- findOne(id: RecordId, ctx: AdminContext, options?: {
276
+ findOne(id: Id, ctx: AdminContext, options?: {
257
277
  withDeleted?: boolean;
258
278
  }): Promise<T | null>;
259
279
  /**
@@ -261,9 +281,11 @@ export declare abstract class AdminResourceBase<T extends ObjectLiteral = Object
261
281
  * update (a restricted id is a 422 on the field). `qb` selects the target entity as `option`; the target resource's
262
282
  * `query()` has already been applied. `values` are the record's values as the user sees them: the form's current
263
283
  * values in the picker, the body on create, the stored record with the body on top on update (relations as ids),
264
- * so one field's options can depend on another (`city` on `province`). Default: all records.
284
+ * so one field's options can depend on another (`city` on `province`). Relation ids in `values` (and in
285
+ * `values._parent`) are in the target key's type. May be async: a lookup inside it should use `ctx.manager` when set,
286
+ * so a write's check sees its own transaction. Default: all records.
265
287
  */
266
- relationOptions(_field: string, qb: SelectQueryBuilder<any>, _ctx: AdminContext, _values: Record<string, unknown>): SelectQueryBuilder<any>;
288
+ relationOptions(_field: string, qb: SelectQueryBuilder<any>, _ctx: AdminContext, _values: Record<string, unknown>): SelectQueryBuilder<any> | Promise<SelectQueryBuilder<any>>;
267
289
  /**
268
290
  * Overriding this skips the @BeforeSave/@AfterSave hooks; call `this.runHooks(...)` yourself to keep them.
269
291
  * Relation fields arrive as ids (`customer: 3`, `tags: ['a', 'b']`), already checked to exist; the default
@@ -276,16 +298,16 @@ export declare abstract class AdminResourceBase<T extends ObjectLiteral = Object
276
298
  * Overriding this skips the @BeforeSave/@AfterSave hooks; call `this.runHooks(...)` yourself to keep them.
277
299
  * Relation and file fields arrive as in `create`.
278
300
  */
279
- update(id: RecordId, dto: object, ctx: AdminContext): Promise<T>;
301
+ update(id: Id, dto: object, ctx: AdminContext): Promise<T>;
280
302
  /**
281
303
  * Moves the record to the trash when the entity has a @DeleteDateColumn, else removes it.
282
304
  * Overriding this skips the @BeforeDelete hooks; call `this.runHooks(...)` yourself to keep them.
283
305
  */
284
- delete(id: RecordId, ctx: AdminContext): Promise<void>;
306
+ delete(id: Id, ctx: AdminContext): Promise<void>;
285
307
  /** Takes a record out of the trash (soft-deletable entities only). */
286
- restore(id: RecordId, ctx: AdminContext): Promise<T>;
308
+ restore(id: Id, ctx: AdminContext): Promise<T>;
287
309
  /** Removes a record for good, whether it is in the trash or not. Runs the @BeforeDelete hooks with `'hard'`. */
288
- purge(id: RecordId, ctx: AdminContext): Promise<void>;
310
+ purge(id: Id, ctx: AdminContext): Promise<void>;
289
311
  /** Runs @BeforeSave/@AfterSave/@BeforeDelete methods in declaration order (parent class first). */
290
312
  protected runHooks(kind: HookKind, ...args: unknown[]): Promise<void>;
291
313
  }
@@ -10,6 +10,14 @@ import { AdminContext } from './admin-context.js';
10
10
  * Base class for admin resources. Override `create`/`update` (and the finders) to route
11
11
  * admin operations through your own services, so business rules are never bypassed.
12
12
  */
13
+ /**
14
+ * `Id` is the type of a record id in `findOne`, `update`, `delete`, `restore` and `purge`: `number` for an integer
15
+ * primary key, `string` for bigint, uuid and text keys, `{ key: value }` for composite keys. The admin parses ids to
16
+ * that type before they reach you; the parameter only tells TypeScript.
17
+ *
18
+ * Write methods (`create`, `update`, `delete`, `restore`, `purge`, actions) always get a context with `manager` set:
19
+ * type the parameter of your override as `AdminWriteContext` to use it without `!`.
20
+ */
13
21
  export class AdminResourceBase {
14
22
  list;
15
23
  form;
@@ -19,6 +27,23 @@ export class AdminResourceBase {
19
27
  links(_record) {
20
28
  return [];
21
29
  }
30
+ /**
31
+ * Fields locked on this record, on top of each field's `readonlyIf`: the record shows them read-only and a write that
32
+ * changes one is refused (422), inline rows included. Lock everything but some with `this.updateFields`. Must be
33
+ * synchronous and cheap (it runs per record of a page). A throw locks every field of the update form. Default: none.
34
+ */
35
+ readonlyFields(_record, _ctx) {
36
+ return [];
37
+ }
38
+ #updateFields;
39
+ /** @internal Called once by the registry: where `updateFields` reads the update form from. */
40
+ attachUpdateFields(read) {
41
+ this.#updateFields = read;
42
+ }
43
+ /** The fields of the update form (`schema.form.update`): what `readonlyFields` can lock. */
44
+ get updateFields() {
45
+ return this.#updateFields?.() ?? [];
46
+ }
22
47
  #repository;
23
48
  #scoper;
24
49
  /** @internal Called once by the policy during bootstrap: adds the user's view scopes (spec §6.4) to reads. */
@@ -121,7 +146,9 @@ export class AdminResourceBase {
121
146
  * update (a restricted id is a 422 on the field). `qb` selects the target entity as `option`; the target resource's
122
147
  * `query()` has already been applied. `values` are the record's values as the user sees them: the form's current
123
148
  * values in the picker, the body on create, the stored record with the body on top on update (relations as ids),
124
- * so one field's options can depend on another (`city` on `province`). Default: all records.
149
+ * so one field's options can depend on another (`city` on `province`). Relation ids in `values` (and in
150
+ * `values._parent`) are in the target key's type. May be async: a lookup inside it should use `ctx.manager` when set,
151
+ * so a write's check sees its own transaction. Default: all records.
125
152
  */
126
153
  relationOptions(_field, qb, _ctx, _values) {
127
154
  return qb;
@@ -1,5 +1,5 @@
1
1
  import { columnToField, isSupportedColumn } from './column-field.js';
2
- import { applyFieldConfig, checkFieldConfig, checkLayout, localizeLayout, mainLayout, mergeFieldConfig } from './field-config.js';
2
+ import { applyFieldConfig, bootFieldText, bootLayoutText, checkFieldConfig, checkLayout, localizeLayout, mainLayout, mergeFieldConfig } from './field-config.js';
3
3
  import { dtoObjectField, embeddedField, nestedTypeOf, topEmbedded } from './nested-fields.js';
4
4
  import { isToOne, pathField as toPathField, relationFields, resolvePath } from './relation-fields.js';
5
5
  import { dtoConstraints, hasDtoInitializer, isConditionalProperty } from './dto-constraints.js';
@@ -357,7 +357,7 @@ export function buildResourceSchema(input) {
357
357
  softDelete: metadata.columns.some((column) => column.isDeleteDate),
358
358
  ...(versionField ? { version: versionField } : {}),
359
359
  // Texts in the first language given; AdminApiService localizes per request.
360
- fields: allFields.map((field) => applyFieldConfig(field, fieldConfig.get(field.name), '', '')),
360
+ fields: allFields.map((field) => applyFieldConfig(field, fieldConfig.get(field.name), bootFieldText)),
361
361
  list: {
362
362
  columns,
363
363
  sortable,
@@ -405,7 +405,7 @@ export function buildResourceSchema(input) {
405
405
  requiredOnCreate,
406
406
  readonly: formReadonly,
407
407
  constraints,
408
- ...(layout ? { layout: localizeLayout(layout, '', '') } : {}),
408
+ ...(layout ? { layout: localizeLayout(layout, bootLayoutText) } : {}),
409
409
  ...(aside ? { aside } : {}),
410
410
  ...(mode === 'view' ? { mode: 'view' } : {}),
411
411
  ...(headerConfig
@@ -1,7 +1,7 @@
1
1
  import type { DtoFormSchema, FieldConstraints, FieldSchema } from '../contract.js';
2
2
  import { type AdminFieldOptions } from '../decorators/admin-field.js';
3
3
  import { type DtoClass } from './dto-fields.js';
4
- import { type FieldConfig } from './field-config.js';
4
+ import { type FieldConfig, type FieldText } from './field-config.js';
5
5
  /**
6
6
  * A form described by a DTO alone (an action's input, a settings page): no entity and no resource behind it.
7
7
  * Texts are kept as configured, in every language; `localizeDtoForm` makes the schema one request gets.
@@ -42,7 +42,7 @@ export declare function nestedProtected(dto: DtoClass, property: string, among?:
42
42
  /** The boot error for a protected option inside a group. */
43
43
  export declare function protectedInside(field: string, inside: ProtectedInside): string;
44
44
  /** The form as one request gets it: field options applied, texts in `locale`. */
45
- export declare function localizeDtoForm(form: DtoForm, locale: string, defaultLocale: string, files?: {
45
+ export declare function localizeDtoForm(form: DtoForm, fieldText: FieldText, files?: {
46
46
  maxBytes?: number;
47
47
  enabled?: boolean;
48
48
  }): DtoFormSchema;
@@ -92,9 +92,9 @@ function addNestedConstraints(out, field, path, nestedDto) {
92
92
  }
93
93
  }
94
94
  /** The form as one request gets it: field options applied, texts in `locale`. */
95
- export function localizeDtoForm(form, locale, defaultLocale, files = {}) {
95
+ export function localizeDtoForm(form, fieldText, files = {}) {
96
96
  return {
97
- fields: form.fields.map((field) => applyFieldConfig(field, form.config.get(field.name), locale, defaultLocale, files.maxBytes, files.enabled)),
97
+ fields: form.fields.map((field) => applyFieldConfig(field, form.config.get(field.name), fieldText, files.maxBytes, files.enabled)),
98
98
  constraints: form.constraints,
99
99
  required: form.required,
100
100
  };
@@ -12,6 +12,8 @@ export type FieldsConfig<T> = {
12
12
  } & Record<string, FieldConfig<T> | undefined>;
13
13
  /** `form.layout`: sections (optionally grouped into tabs). */
14
14
  export interface LayoutSectionConfig {
15
+ /** Names this node for `translate` (`resource.<r>.form.<key>`); unique within the layout. */
16
+ key?: string;
15
17
  section?: LocalizedText;
16
18
  fields: string[];
17
19
  /** Columns on wide screens (one on phones). Default 1. */
@@ -25,6 +27,8 @@ export declare const MAX_INLINE_ROWS = 500;
25
27
  * as a table or as cards. The child is an ordinary resource with its own permissions, scopes, fields and services.
26
28
  */
27
29
  export interface LayoutInlineConfig {
30
+ /** Names this node for `translate` (`resource.<r>.form.<key>`); unique within the layout. */
31
+ key?: string;
28
32
  /** The section's title. Default: the child resource's label. */
29
33
  section?: LocalizedText;
30
34
  /**
@@ -55,6 +59,8 @@ export interface LayoutInlineConfig {
55
59
  }
56
60
  /** Label and value rows in a card (an order's totals): fields of the record, or its computed columns (`list.computed`). */
57
61
  export interface LayoutSummaryConfig {
62
+ /** Names this node for `translate` (`resource.<r>.form.<key>`); unique within the layout. */
63
+ key?: string;
58
64
  section?: LocalizedText;
59
65
  summary: Array<{
60
66
  label: LocalizedText;
@@ -64,6 +70,8 @@ export interface LayoutSummaryConfig {
64
70
  }>;
65
71
  }
66
72
  export interface LayoutTabConfig {
73
+ /** Names this node for `translate` (`resource.<r>.form.<key>`); unique within the layout. */
74
+ key?: string;
67
75
  tab: LocalizedText;
68
76
  sections: Array<LayoutSectionConfig | LayoutInlineConfig | LayoutSummaryConfig>;
69
77
  }
@@ -99,8 +107,15 @@ export declare function checkFieldConfig(fields: FieldSchema[], config: Map<stri
99
107
  }): void;
100
108
  /** Fields whose values the audit log never stores: `sensitive`, `secret`, and anything typed into a `password` widget. */
101
109
  export declare function sensitiveFields(config: ReadonlyMap<string, FieldConfig>): Set<string>;
102
- /** The field with its configured options, texts in `locale` (the schema the UI gets). */
103
- export declare function applyFieldConfig(field: FieldSchema, options: FieldConfig | undefined, locale: string, defaultLocale: string, defaultMaxBytes?: number, filesEnabled?: boolean): FieldSchema;
110
+ /**
111
+ * A text of a field in the request's locale. `path` is the text's place under the owner's `fields.` key
112
+ * (`name.label`, `status.enumLabels.open`, `hours.*.day.label`).
113
+ */
114
+ export type FieldText = (value: LocalizedText, path: string) => string;
115
+ /** Texts resolved at boot: the default locale's, or the first one given (the stored schema keeps that one). */
116
+ export declare const bootFieldText: FieldText;
117
+ /** The field with its configured options, texts in the request's locale (the schema the UI gets). */
118
+ export declare function applyFieldConfig(field: FieldSchema, options: FieldConfig | undefined, fieldText: FieldText, defaultMaxBytes?: number, filesEnabled?: boolean, path?: string): FieldSchema;
104
119
  /**
105
120
  * Every layout name is a form field, listed once. Inline nodes (only where `allow.inlines`: a resource's form) are
106
121
  * checked for their shape here; the registry resolves them against the child once every resource is known.
@@ -115,7 +130,10 @@ allow?: {
115
130
  };
116
131
  }): void;
117
132
  /**
118
- * The layout with texts in `locale`. `inline` turns an inline node into what the UI gets (given the section's title in
119
- * `locale`); nodes it answers `undefined` for are left out, and so is a tab left without sections by that.
133
+ * The layout with texts in the request's locale. `text` gets each node's key under the owner's `form.` (`main`,
134
+ * `main.0` for a summary row) when the node has a `key`. `inline` turns an inline node into what the UI gets (given the
135
+ * section's title); nodes it answers `undefined` for are left out, and so is a tab left without sections by that.
120
136
  */
121
- export declare function localizeLayout(layout: LayoutConfig, locale: string, defaultLocale: string, inline?: (node: LayoutInlineConfig, label: string | undefined) => FormLayoutInline | undefined): FormLayoutNode[];
137
+ export declare function localizeLayout(layout: LayoutConfig, text: (value: LocalizedText, key: string | undefined) => string, inline?: (node: LayoutInlineConfig, label: string | undefined) => FormLayoutInline | undefined): FormLayoutNode[];
138
+ /** Layout texts resolved at boot (the stored schema). */
139
+ export declare const bootLayoutText: (value: LocalizedText) => string;
@@ -173,22 +173,24 @@ function checkFileOptions(name, field, options, fail) {
173
173
  export function sensitiveFields(config) {
174
174
  return new Set([...config].filter(([, options]) => options.sensitive === true || options.secret === true || options.widget === 'password').map(([name]) => name));
175
175
  }
176
- /** The field with its configured options, texts in `locale` (the schema the UI gets). */
177
- export function applyFieldConfig(field, options, locale, defaultLocale, defaultMaxBytes = DEFAULT_MAX_FILE_BYTES, filesEnabled = false) {
176
+ /** Texts resolved at boot: the default locale's, or the first one given (the stored schema keeps that one). */
177
+ export const bootFieldText = (value) => resolveText(value, '', '');
178
+ /** The field with its configured options, texts in the request's locale (the schema the UI gets). */
179
+ export function applyFieldConfig(field, options, fieldText, defaultMaxBytes = DEFAULT_MAX_FILE_BYTES, filesEnabled = false, path = field.name) {
180
+ const text = (value, suffix) => fieldText(value, `${path}.${suffix}`);
181
+ const nested = field.fields?.map((child) => applyFieldConfig(child, undefined, fieldText, defaultMaxBytes, filesEnabled, `${path}.${field.many ? '*.' : ''}${child.name}`));
178
182
  if (!options)
179
- return field;
180
- const text = (value) => resolveText(value, locale, defaultLocale);
181
- const out = { ...field };
182
- if (options.label !== undefined)
183
- out.label = text(options.label);
183
+ return { ...field, label: text(field.label, 'label'), ...(nested ? { fields: nested } : {}) };
184
+ const out = { ...field, ...(nested ? { fields: nested } : {}) };
185
+ out.label = text(options.label ?? field.label, 'label');
184
186
  if (options.help !== undefined)
185
- out.help = text(options.help);
187
+ out.help = text(options.help, 'help');
186
188
  if (options.placeholder !== undefined)
187
- out.placeholder = text(options.placeholder);
189
+ out.placeholder = text(options.placeholder, 'placeholder');
188
190
  if (options.widget !== undefined)
189
191
  out.widget = options.widget;
190
192
  if (options.enumLabels)
191
- out.enumLabels = Object.fromEntries(Object.entries(options.enumLabels).map(([value, label]) => [value, text(label)]));
193
+ out.enumLabels = Object.fromEntries(Object.entries(options.enumLabels).map(([value, label]) => [value, text(label, `enumLabels.${value}`)]));
192
194
  if (options.colors)
193
195
  out.colors = { ...options.colors };
194
196
  if (options.showIf)
@@ -196,13 +198,13 @@ export function applyFieldConfig(field, options, locale, defaultLocale, defaultM
196
198
  if (options.slugFrom !== undefined)
197
199
  out.slugFrom = options.slugFrom;
198
200
  if (options.warnIf !== undefined)
199
- out.warnIf = { empty: true, message: text(options.warnIf.message) };
201
+ out.warnIf = { empty: true, message: text(options.warnIf.message, 'warnIf.message') };
200
202
  if (options.widget === 'stepper') {
201
203
  const exclude = options.exclude ?? [];
202
204
  out.steps = { values: (options.steps ?? field.enumValues ?? []).filter((value) => !exclude.includes(value)), exclude: [...exclude], history: options.history !== undefined };
203
205
  }
204
206
  if (options.currency !== undefined) {
205
- out.currency = typeof options.currency === 'string' ? { unit: options.currency, position: 'after' } : { unit: text(options.currency.unit), position: options.currency.position ?? 'after' };
207
+ out.currency = typeof options.currency === 'string' ? { unit: options.currency, position: 'after' } : { unit: text(options.currency.unit, 'currency.unit'), position: options.currency.position ?? 'after' };
206
208
  }
207
209
  if (options.widget === 'file' || options.widget === 'image') {
208
210
  out.file = {
@@ -225,6 +227,16 @@ export function checkLayout(layout, formNames, fail,
225
227
  /** `inlines` and summaries belong in a resource's form; a summary reads these fields and computed columns. */
226
228
  allow = {}) {
227
229
  const seen = new Set();
230
+ const keys = new Set();
231
+ for (const node of layout.flatMap((node) => ('tab' in node ? [node, ...node.sections] : [node]))) {
232
+ if (node.key === undefined)
233
+ continue;
234
+ if (typeof node.key !== 'string' || !/^[\w-]+$/.test(node.key))
235
+ fail('form.layout: a key is a word (letters, digits, _ and -)');
236
+ if (keys.has(node.key))
237
+ fail(`form.layout: key "${node.key}" is used twice`);
238
+ keys.add(node.key);
239
+ }
228
240
  const nodes = layout.flatMap((node) => ('tab' in node ? node.sections : [node]));
229
241
  for (const node of nodes) {
230
242
  if (isSummaryConfig(node)) {
@@ -295,18 +307,19 @@ function checkInlineShape(node, fail) {
295
307
  }
296
308
  }
297
309
  /**
298
- * The layout with texts in `locale`. `inline` turns an inline node into what the UI gets (given the section's title in
299
- * `locale`); nodes it answers `undefined` for are left out, and so is a tab left without sections by that.
310
+ * The layout with texts in the request's locale. `text` gets each node's key under the owner's `form.` (`main`,
311
+ * `main.0` for a summary row) when the node has a `key`. `inline` turns an inline node into what the UI gets (given the
312
+ * section's title); nodes it answers `undefined` for are left out, and so is a tab left without sections by that.
300
313
  */
301
- export function localizeLayout(layout, locale, defaultLocale, inline) {
314
+ export function localizeLayout(layout, text, inline) {
302
315
  const section = (node) => {
303
- const title = node.section !== undefined ? resolveText(node.section, locale, defaultLocale) : undefined;
316
+ const title = node.section !== undefined ? text(node.section, node.key) : undefined;
304
317
  if (isInlineConfig(node))
305
318
  return inline?.(node, title);
306
319
  if (isSummaryConfig(node)) {
307
320
  return {
308
321
  ...(title !== undefined ? { title } : {}),
309
- summary: node.summary.map((row) => ({ label: resolveText(row.label, locale, defaultLocale), value: typeof row.value === 'string' ? { field: row.value } : { computed: row.value.computed } })),
322
+ summary: node.summary.map((row, index) => ({ label: text(row.label, node.key === undefined ? undefined : `${node.key}.${index}`), value: typeof row.value === 'string' ? { field: row.value } : { computed: row.value.computed } })),
310
323
  };
311
324
  }
312
325
  return { ...(title !== undefined ? { title } : {}), fields: [...node.fields], columns: node.columns ?? 1 };
@@ -316,7 +329,7 @@ export function localizeLayout(layout, locale, defaultLocale, inline) {
316
329
  if ('tab' in node) {
317
330
  const sections = node.sections.map(section).filter((item) => item !== undefined);
318
331
  if (sections.length > 0 || node.sections.length === 0)
319
- out.push({ tab: resolveText(node.tab, locale, defaultLocale), sections });
332
+ out.push({ tab: text(node.tab, node.key), sections });
320
333
  }
321
334
  else {
322
335
  const item = section(node);
@@ -326,4 +339,6 @@ export function localizeLayout(layout, locale, defaultLocale, inline) {
326
339
  }
327
340
  return out;
328
341
  }
342
+ /** Layout texts resolved at boot (the stored schema). */
343
+ export const bootLayoutText = (value) => resolveText(value, '', '');
329
344
  //# sourceMappingURL=field-config.js.map