@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
@@ -29,7 +29,7 @@ const EXPORT_PAGE = 500;
29
29
  const PRINT_MAX = 100;
30
30
  import { ADMIN_OPTIONS, MAX_BULK } from '../constants.js';
31
31
  import { parseListQuery } from '../crud/list-query.js';
32
- import { buildMenu, checkMenu } from './menu.js';
32
+ import { buildMenu, checkMenu, resolveMenu } from './menu.js';
33
33
  import { DashboardService } from '../dashboard/dashboard.service.js';
34
34
  import { WidgetRegistry } from '../dashboard/widget-registry.js';
35
35
  import { loadComputed } from '../crud/computed-columns.js';
@@ -38,7 +38,7 @@ import { encodeRecordId, parseRecordId, recordIdOf } from '../crud/record-id.js'
38
38
  import { likePattern } from '../crud/list-query-builder.js';
39
39
  import { parseId } from '../crud/list-query.js';
40
40
  import { isLoadedField, loadReferences, relationRef } from '../crud/references.js';
41
- import { relationIdsOf } from '../crud/relation-writes.js';
41
+ import { normalizeRelationValues, relationIdsOf } from '../crud/relation-writes.js';
42
42
  import { serializeRecord } from '../crud/serialize.js';
43
43
  import { validateWrite } from '../crud/validate-write.js';
44
44
  import { auditParticipant } from '../audit/audit-participant.js';
@@ -47,14 +47,16 @@ import { filesParticipant } from '../files/files-participant.js';
47
47
  import { FilesService } from '../files/files.service.js';
48
48
  import { AdminBadRequestError, AdminConflictError, AdminForbiddenError, AdminNotFoundError, AdminValidationError } from '../errors.js';
49
49
  import { AdminPolicy } from '../policy/admin-policy.service.js';
50
- import { resolveText } from '../i18n/localized-text.js';
50
+ import { scopedText } from '../i18n/texts.js';
51
51
  import { ResourceRegistry } from '../registry/resource-registry.js';
52
+ import { inAdminTransaction } from '../resource/admin-context.js';
52
53
  import { AdminResourceBase } from '../resource/admin-resource-base.js';
53
54
  import { PageRegistry } from '../pages/page-registry.js';
54
55
  import { PageService } from '../pages/page.service.js';
55
56
  import { ActionService } from './action.service.js';
56
57
  import { SINGLE_CONNECTION_DRIVERS } from './write-queue.js';
57
58
  import { WriteRunner } from './write-runner.js';
59
+ import { getCanRules } from '../decorators/admin-scope.js';
58
60
  let AdminApiService = class AdminApiService {
59
61
  registry;
60
62
  options;
@@ -102,7 +104,7 @@ let AdminApiService = class AdminApiService {
102
104
  change: (change, tx, method) => this.change(change, tx, method),
103
105
  checkRelationsExist: (entry, ids, ctx, values) => this.checkRelationsExist(entry, ids, ctx, values),
104
106
  checkVersion: (entry, id, expected, ctx) => this.checkVersion(entry, id, expected, ctx),
105
- lockedFields: (entry, entity) => this.lockedFields(entry, entity),
107
+ lockedFields: (entry, entity, ctx) => this.lockedFields(entry, entity, ctx),
106
108
  values: async (entry, entity, ctx) => toValues(await this.record(entry, entity, ctx)),
107
109
  reloadIfEmpty: (entry, result, id, ctx) => this.reloadIfEmpty(entry, result, id, ctx),
108
110
  errorMapper: options.errorMapper,
@@ -129,7 +131,7 @@ let AdminApiService = class AdminApiService {
129
131
  }
130
132
  /** Sidebar data with labels in `locale` (the default locale when omitted). */
131
133
  meta(locale = this.options.locale, ctx) {
132
- const text = (label) => resolveText(label, locale, this.options.locale);
134
+ const text = (label, key) => this.options.texts(label, locale, key);
133
135
  // Only resources the user may view (spec §6.5: meta is filtered per user).
134
136
  // `nav: false` resources have no entry of their own (spec §5): reachable by URL, not listed.
135
137
  const resources = this.registry.list().filter((entry) => entry.nav && (!ctx || this.policy.permissionsOf(ctx).canOn(entry.schema.name, 'view')));
@@ -140,13 +142,13 @@ let AdminApiService = class AdminApiService {
140
142
  .groupList()
141
143
  .map((group) => ({
142
144
  group,
143
- label: text(group.label),
145
+ label: text(group.label, `group.${group.key}`),
144
146
  resources: resources
145
147
  .filter((entry) => entry.schema.group === group.key)
146
148
  .map((entry) => {
147
149
  const { schema, label } = entry;
148
150
  const seen = ctx ? this.view(entry, ctx).schema : schema;
149
- const summary = { name: schema.name, label: text(label), ...(schema.icon ? { icon: schema.icon } : {}), creatable: seen.creatable, searchable: seen.list.search.length > 0 };
151
+ const summary = { name: schema.name, label: text(label, `resource.${schema.name}`), ...(schema.icon ? { icon: schema.icon } : {}), creatable: seen.creatable, searchable: seen.list.search.length > 0 };
150
152
  return { order: entry.order, summary };
151
153
  })
152
154
  .sort(byOrder)
@@ -167,10 +169,10 @@ let AdminApiService = class AdminApiService {
167
169
  resources: items,
168
170
  pages: groupPages,
169
171
  }));
170
- const menu = this.options.menu && buildMenu(this.options.menu, text, groups.flatMap((group) => group.resources), groups.flatMap((group) => group.pages));
172
+ const menu = this.menu && buildMenu(this.menu, text, groups);
171
173
  // With widgets in the app, whether this user has a dashboard (it replaces the home page).
172
174
  const dashboard = this.widgets.list().length > 0 ? { dashboard: ctx ? this.dashboard.has(ctx) : true } : {};
173
- return { schemaVersion: 1, title: text(this.options.title), locale, locales: this.options.locales, groups, ...dashboard, ...(menu ? { menu } : {}) };
175
+ return { schemaVersion: 1, title: text(this.options.title, 'title'), locale, locales: this.options.locales, groups, ...dashboard, ...(menu ? { menu } : {}) };
174
176
  }
175
177
  /**
176
178
  * Image cells hold a file key; the page gets its URL (the storage's public one, or the admin's download route, which
@@ -222,14 +224,22 @@ let AdminApiService = class AdminApiService {
222
224
  /** Computed columns of some rows of a resource, image cells as URLs. */
223
225
  async computedValues(entry, columns, entities, ctx) {
224
226
  const locale = ctx.locale ?? this.options.locale;
225
- const values = await loadComputed(columns, entities, entry.metadata, ctx, this.registry.childQuery, (alias) => entry.resource.readQuery(alias, ctx), (label) => resolveText(label, locale, this.options.locale), (target, field) => this.registry.forEntity(target, entry.dataSource)?.schema.fields.find((candidate) => candidate.name === field));
227
+ const values = await loadComputed(columns, entities, entry.metadata, ctx, this.registry.childQuery, (alias) => entry.resource.readQuery(alias, ctx), (label) => this.options.texts(label, locale), (target, field) => this.registry.forEntity(target, entry.dataSource)?.schema.fields.find((candidate) => candidate.name === field));
226
228
  await this.imageUrls(entry, columns, values, ctx);
227
229
  return values;
228
230
  }
229
231
  /** The menu's references are checked once every resource and settings page is registered. */
230
232
  onApplicationBootstrap() {
231
- if (this.options.menu)
232
- checkMenu(this.options.menu, this.registry, this.pageRegistry);
233
+ if (!this.options.menu)
234
+ return;
235
+ this.menu = resolveMenu(this.options.menu, this.registry, this.pageRegistry);
236
+ checkMenu(this.menu, this.registry, this.pageRegistry);
237
+ }
238
+ /** `options.menu` with its classes and groups resolved (at bootstrap, once everything is registered). */
239
+ menu;
240
+ /** @internal The resolved menu (`@nest-my-admin/testing` crawls its badges). */
241
+ resolvedMenu() {
242
+ return this.menu;
233
243
  }
234
244
  /**
235
245
  * `GET /api/menu/badges`: each menu badge counted for this user through the list's own path (scopes and `query()`
@@ -238,8 +248,8 @@ let AdminApiService = class AdminApiService {
238
248
  async badges(ctx) {
239
249
  const out = {};
240
250
  const perms = this.policy.permissionsOf(ctx);
241
- for (const section of this.options.menu?.sections ?? []) {
242
- for (const item of section.items) {
251
+ for (const section of this.menu?.sections ?? []) {
252
+ for (const item of section.items ?? []) {
243
253
  if (!('resource' in item) || !item.badge)
244
254
  continue;
245
255
  const entry = this.registry.get(item.resource);
@@ -266,24 +276,25 @@ let AdminApiService = class AdminApiService {
266
276
  const entry = this.registry.get(name);
267
277
  if (ctx)
268
278
  this.policy.requireReach(entry, ctx);
269
- const text = (label) => resolveText(label, locale, this.options.locale);
279
+ const text = scopedText(this.options.texts, locale, `resource.${name}`);
270
280
  const related = entry.schema.related.map((item, index) => {
271
- const base = text(this.registry.get(item.resource).label);
281
+ const target = this.registry.get(item.resource);
282
+ const base = this.options.texts(target.label, locale, `resource.${target.schema.name}`);
272
283
  const fieldLabel = entry.relatedFieldLabels[index];
273
284
  return { ...item, label: fieldLabel ? `${base} (${fieldLabel})` : base };
274
285
  });
275
- const fields = entry.schema.fields.map((field) => applyFieldConfig(field, entry.fieldConfig.get(field.name), locale, this.options.locale, this.options.files?.maxBytes, this.files.enabled));
286
+ const fields = entry.schema.fields.map((field) => applyFieldConfig(field, entry.fieldConfig.get(field.name), (value, path) => text(value, `fields.${path}`), this.options.files?.maxBytes, this.files.enabled));
276
287
  const layout = mainLayout(entry.resource.form?.layout);
277
- const inline = (node, label) => toLayoutInline(inlineOf(entry, node), label, locale, this.options.locale);
278
- const form = layout ? { ...entry.schema.form, layout: localizeLayout(layout, locale, this.options.locale, inline) } : entry.schema.form;
279
- const actions = [...entry.actions.values()].map((action) => toActionSchema(action, locale, this.options.locale));
280
- const prints = [...entry.prints.values()].map((print) => toPrintSchema(print, locale, this.options.locale));
281
- const computed = entry.schema.list.computed && Object.fromEntries(Object.entries(entry.schema.list.computed).map(([key, column]) => [key, { ...column, label: text(entry.computed.get(key).column.label) }]));
282
- const tabs = entry.schema.list.tabs?.map((tab, index) => ({ ...tab, label: text(entry.resource.list.tabs[index].label) }));
288
+ const inline = (node, label) => toLayoutInline(inlineOf(entry, node), label, text, this.options.texts(inlineOf(entry, node).child.label, locale, `resource.${inlineOf(entry, node).name}`));
289
+ const form = layout ? { ...entry.schema.form, layout: localizeLayout(layout, (value, key) => text(value, key === undefined ? undefined : `form.${key}`), inline) } : entry.schema.form;
290
+ const actions = [...entry.actions.values()].map((action) => toActionSchema(action, text));
291
+ const prints = [...entry.prints.values()].map((print) => toPrintSchema(print, text));
292
+ const computed = entry.schema.list.computed && Object.fromEntries(Object.entries(entry.schema.list.computed).map(([key, column]) => [key, { ...column, label: text(entry.computed.get(key).column.label, `list.computed.${key}.label`) }]));
293
+ const tabs = entry.schema.list.tabs?.map((tab, index) => ({ ...tab, label: text(entry.resource.list.tabs[index].label, `list.tabs.${tab.key}.label`) }));
283
294
  const list = { ...entry.schema.list, ...(computed ? { computed } : {}), ...(tabs ? { tabs } : {}) };
284
295
  const asideConfig = entry.resource.form?.layout && !Array.isArray(entry.resource.form.layout) ? entry.resource.form.layout.aside : undefined;
285
- const localizedForm = form.aside && asideConfig ? { ...form, aside: form.aside.map((card, index) => ({ ...card, title: text(asideConfig[index].title) })) } : form;
286
- const localized = { ...entry.schema, label: text(entry.label), related, fields, form: localizedForm, actions, prints, list };
296
+ const localizedForm = form.aside && asideConfig ? { ...form, aside: form.aside.map((card, index) => ({ ...card, title: text(asideConfig[index].title, asideConfig[index].key === undefined ? undefined : `form.${asideConfig[index].key}`) })) } : form;
297
+ const localized = { ...entry.schema, label: text(entry.label, ''), related, fields, form: localizedForm, actions, prints, list };
287
298
  const schema = ctx ? this.policy.view(entry, localized, ctx).schema : localized;
288
299
  // The child schema of every inline left in the layout (the policy removed those the user may not view).
289
300
  const children = (schema.form.layout ?? []).flatMap((node) => ('tab' in node ? node.sections : [node])).flatMap((node) => ('inline' in node ? [node.inline] : []));
@@ -316,7 +327,7 @@ let AdminApiService = class AdminApiService {
316
327
  const computed = [...entry.computed.values()].filter((column) => schema.list.computed?.[column.key] && shown.has(column.key));
317
328
  if (computed.length > 0) {
318
329
  const locale = ctx.locale ?? this.options.locale;
319
- const values = await loadComputed(computed, items, entry.metadata, ctx, this.registry.childQuery, (alias) => entry.resource.readQuery(alias, ctx), (label) => resolveText(label, locale, this.options.locale), (entity, field) => this.registry.forEntity(entity, entry.dataSource)?.schema.fields.find((candidate) => candidate.name === field));
330
+ const values = await loadComputed(computed, items, entry.metadata, ctx, this.registry.childQuery, (alias) => entry.resource.readQuery(alias, ctx), (label) => this.options.texts(label, locale), (entity, field) => this.registry.forEntity(entity, entry.dataSource)?.schema.fields.find((candidate) => candidate.name === field));
320
331
  await this.imageUrls(entry, computed, values, ctx);
321
332
  for (const record of records)
322
333
  record._computed = values.get(String(record._id)) ?? {};
@@ -364,7 +375,7 @@ let AdminApiService = class AdminApiService {
364
375
  return undefined;
365
376
  return {
366
377
  resource: schema.name,
367
- label: resolveText(entry.label, locale, this.options.locale),
378
+ label: this.options.texts(entry.label, locale, `resource.${schema.name}`),
368
379
  items: items.map((entity) => {
369
380
  const id = recordIdOf(entity, schema.primaryKeys);
370
381
  return { _id: id, _title: this.policy.titleVisible(entry, ctx) ? entry.title(entity) : `#${id}` };
@@ -459,7 +470,7 @@ let AdminApiService = class AdminApiService {
459
470
  const files = fileFields.length > 0 ? await this.files.refs(this.files.ownerOf(entry), entities, fileFields, ctx) : undefined;
460
471
  const out = entities.map((entity, index) => {
461
472
  const id = recordIdOf(entity, schema.primaryKeys);
462
- const locked = this.lockedFields(entry, entity);
473
+ const locked = this.lockedFields(entry, entity, ctx);
463
474
  const links = this.recordLinks(entry, entity, locale);
464
475
  // TypeORM does not load the discriminator into entities; each row's class says which kind it is.
465
476
  const values = discriminator && schema.fields.some((field) => field.name === discriminator) ? { ...loaded?.get(id), [discriminator]: kindOf(entity) } : loaded?.get(id);
@@ -519,6 +530,7 @@ let AdminApiService = class AdminApiService {
519
530
  return this.write(entry, ctx, async (tx) => {
520
531
  // Every refusal the children can cause is decided before the parent is written.
521
532
  const checked = plan ? await this.inlineWriter.check(plan, undefined, tx) : undefined;
533
+ await this.checkParentRules(entry, dto, tx);
522
534
  const created = await this.change({ kind: 'create', target: entry, dto }, tx, async () => {
523
535
  await this.checkRelationsExist(entry, relationIds, tx, dto);
524
536
  const result = await resource.create(dto, tx);
@@ -532,6 +544,35 @@ let AdminApiService = class AdminApiService {
532
544
  return this.withInlineRows(entry, created, tx);
533
545
  });
534
546
  }
547
+ /**
548
+ * `@AdminCan('create')` of an inline child written through its own endpoint: each parent its link field names, as
549
+ * the user may view it, must allow the row (403) — on create, and on an update that moves the row to another parent
550
+ * (`existing`: the stored row; staying under its parent is not adding). Without a link value the rule has nothing to
551
+ * judge; a parent the parent resource does not show the user is a 422 like a missing one.
552
+ */
553
+ async checkParentRules(entry, dto, ctx, existing) {
554
+ if (getCanRules(entry.resource.constructor, 'create').length === 0)
555
+ return;
556
+ for (const parent of this.registry.list()) {
557
+ for (const inline of parent.inlines) {
558
+ const value = inline.child === entry ? dto[inline.link] : undefined;
559
+ if (value === undefined || value === null)
560
+ continue;
561
+ if (existing) {
562
+ const stored = existing[inline.link];
563
+ const storedId = typeof stored === 'object' && stored !== null ? stored[inline.referenced] : stored;
564
+ if (storedId !== undefined && storedId !== null && String(storedId) === String(value))
565
+ continue;
566
+ }
567
+ const found = await parent.resource.readQuery('nma_parent', ctx).andWhere(`nma_parent.${inline.referenced} = :nmaParent`, { nmaParent: value }).getOne();
568
+ // A parent this resource does not show (another resource on the entity might): as missing, so the rule is never skipped.
569
+ if (!found)
570
+ throw new AdminValidationError({ [inline.link]: ['does not exist'] }, 'A related record does not exist');
571
+ if (!this.policy.createRule(entry, found, ctx))
572
+ throw new AdminForbiddenError(`You may not add ${entry.schema.label} rows here`);
573
+ }
574
+ }
575
+ }
535
576
  async update(name, rawId, body, ctx, version) {
536
577
  const entry = this.registry.get(name);
537
578
  this.policy.require(entry, 'update', ctx);
@@ -560,7 +601,8 @@ let AdminApiService = class AdminApiService {
560
601
  if (!existing)
561
602
  throw new AdminNotFoundError(`${schema.label} "${rawId}" not found`);
562
603
  this.policy.requireRecordRule(entry, 'update', existing, tx);
563
- const locked = this.lockedFields(entry, existing).filter((name) => Object.hasOwn(dto, name));
604
+ await this.checkParentRules(entry, dto, tx, existing);
605
+ const locked = this.lockedFields(entry, existing, tx).filter((name) => Object.hasOwn(dto, name));
564
606
  if (locked.length > 0)
565
607
  throw new AdminValidationError(Object.fromEntries(locked.map((name) => [name, ['is read-only']])), 'Some fields are read-only');
566
608
  const checked = plan ? await this.inlineWriter.check(plan, existing, tx) : undefined;
@@ -642,7 +684,7 @@ let AdminApiService = class AdminApiService {
642
684
  if (expected === undefined || !version)
643
685
  return;
644
686
  const manager = ctx.manager ?? entry.dataSource.manager;
645
- const lock = ctx.manager && !SINGLE_CONNECTION_DRIVERS.has(entry.dataSource.options.type) ? { mode: 'pessimistic_write' } : undefined;
687
+ const lock = inAdminTransaction(ctx) && !SINGLE_CONNECTION_DRIVERS.has(entry.dataSource.options.type) ? { mode: 'pessimistic_write' } : undefined;
646
688
  const where = typeof id === 'object' ? id : { [entry.schema.primaryKeys[0]]: id };
647
689
  const current = await manager.getRepository(entry.metadata.target).findOne({ where, withDeleted, ...(lock ? { lock } : {}) });
648
690
  if (!current)
@@ -655,7 +697,7 @@ let AdminApiService = class AdminApiService {
655
697
  * A query for the records a relation field may point to (`option`), restricted by the target resource's query() and
656
698
  * this resource's relationOptions().
657
699
  */
658
- optionsQuery(entry, field, ctx, values) {
700
+ async optionsQuery(entry, field, ctx, values) {
659
701
  const target = entry.relations.get(field).inverseEntityMetadata;
660
702
  const manager = ctx.manager ?? entry.dataSource.manager;
661
703
  const qb = manager.getRepository(target.target).createQueryBuilder('option');
@@ -676,7 +718,7 @@ let AdminApiService = class AdminApiService {
676
718
  continue;
677
719
  const target = entry.relations.get(field).inverseEntityMetadata;
678
720
  const key = target.primaryColumns[0].propertyName;
679
- const rows = await this.optionsQuery(entry, field, ctx, values)
721
+ const rows = await (await this.optionsQuery(entry, field, ctx, values))
680
722
  .andWhere(`option.${key} IN (:...nmaIds)`, { nmaIds: ids })
681
723
  .select(`option.${key}`, 'id')
682
724
  .getRawMany();
@@ -708,7 +750,7 @@ let AdminApiService = class AdminApiService {
708
750
  throw new AdminValidationError({ [key]: [known.has(key) ? 'must be given once' : 'is not a supported parameter'] });
709
751
  }
710
752
  }
711
- const values = this.parentValues(entry, parseValues(query.get('values')), query.get('parent'), ctx);
753
+ const values = this.parentValues(entry, normalizeRelationValues(parseValues(query.get('values')), entry.schema), query.get('parent'), ctx);
712
754
  const relation = entry.relations.get(fieldName);
713
755
  const target = relation.inverseEntityMetadata;
714
756
  const key = target.primaryColumns[0].propertyName;
@@ -718,7 +760,7 @@ let AdminApiService = class AdminApiService {
718
760
  if (targetEntry && !this.policy.permissionsOf(ctx).canOn(targetEntry.schema.name, 'view')) {
719
761
  throw new AdminForbiddenError(`You may not view ${targetEntry.schema.label} records`);
720
762
  }
721
- const qb = this.optionsQuery(entry, fieldName, ctx, values);
763
+ const qb = await this.optionsQuery(entry, fieldName, ctx, values);
722
764
  const rawIds = query.get('ids');
723
765
  const search = query.get('search')?.trim() ?? '';
724
766
  if (rawIds !== null) {
@@ -767,7 +809,7 @@ let AdminApiService = class AdminApiService {
767
809
  if (typeof sent !== 'object' || sent === null || Array.isArray(sent))
768
810
  throw new AdminValidationError({ values: ['_parent must be an object of the parent form\'s values'] });
769
811
  const own = Object.fromEntries(Object.entries(sent).filter(([key]) => !key.startsWith('_')));
770
- return { ...values, _parent: { ...own, _resource: parent.schema.name } };
812
+ return { ...values, _parent: { ...normalizeRelationValues(own, parent.schema), _resource: parent.schema.name } };
771
813
  }
772
814
  /**
773
815
  * Deletes each record on its own (its own transaction, hooks, `query()` and trash), so one failure never undoes the
@@ -815,7 +857,7 @@ let AdminApiService = class AdminApiService {
815
857
  if (!print)
816
858
  throw new AdminNotFoundError(`${entry.schema.label} has no print template "${printName}"`);
817
859
  if (!this.policy.canPrint(entry, printName, ctx))
818
- throw new AdminForbiddenError(`You may not print "${resolveText(print.label, ctx.locale ?? this.options.locale, this.options.locale)}"`);
860
+ throw new AdminForbiddenError(`You may not print "${this.options.texts(print.label, ctx.locale ?? this.options.locale, `resource.${entry.schema.name}.prints.${print.name}.label`)}"`);
819
861
  const ids = [...new Set(rawIds)];
820
862
  if (ids.length === 0)
821
863
  throw new AdminBadRequestError('id is required');
@@ -839,7 +881,7 @@ let AdminApiService = class AdminApiService {
839
881
  throw hostError(error);
840
882
  }
841
883
  const locale = ctx.locale ?? this.options.locale;
842
- const label = resolveText(print.label, locale, this.options.locale);
884
+ const label = this.options.texts(print.label, locale, `resource.${entry.schema.name}.prints.${print.name}.label`);
843
885
  for (const entity of entities) {
844
886
  await this.audit.recordAfter({ event: printCode(entry.schema.name, printName), entry, recordId: recordIdOf(entity, entry.schema.primaryKeys), title: entry.title(entity) }, ctx);
845
887
  }
@@ -941,22 +983,40 @@ let AdminApiService = class AdminApiService {
941
983
  await this.change({ kind: 'purge', target: entry, id }, tx, () => entry.resource.purge(id, tx));
942
984
  });
943
985
  }
944
- /** Fields `readonlyIf` locks on this record. A function that throws locks its field (and is logged once). */
945
- lockedFields(entry, entity) {
946
- const locked = [];
986
+ /**
987
+ * Fields `readonlyIf` and the resource's `readonlyFields` lock on this record, each once. A `readonlyIf` that throws
988
+ * locks its field, a `readonlyFields` that throws locks the update form (each logged once); unknown names are dropped.
989
+ */
990
+ lockedFields(entry, entity, ctx) {
991
+ const locked = new Set();
947
992
  for (const [name, options] of entry.fieldConfig) {
948
993
  if (!options.readonlyIf)
949
994
  continue;
950
995
  try {
951
996
  if (options.readonlyIf(entity))
952
- locked.push(name);
997
+ locked.add(name);
953
998
  }
954
999
  catch (error) {
955
- locked.push(name);
1000
+ locked.add(name);
956
1001
  this.warnOnce(`${entry.className}.fields.${name}.readonlyIf threw (${error instanceof Error ? error.message : String(error)}); the field stays read-only`);
957
1002
  }
958
1003
  }
959
- return locked;
1004
+ let more;
1005
+ try {
1006
+ more = entry.resource.readonlyFields(entity, ctx);
1007
+ }
1008
+ catch (error) {
1009
+ more = entry.schema.form.update;
1010
+ this.warnOnce(`${entry.className}.readonlyFields threw (${error instanceof Error ? error.message : String(error)}); the record stays read-only`);
1011
+ }
1012
+ const fields = new Set(entry.schema.fields.map((field) => field.name));
1013
+ for (const name of more) {
1014
+ if (fields.has(name) && !entry.schema.primaryKeys.includes(name))
1015
+ locked.add(name);
1016
+ else if (!fields.has(name))
1017
+ this.warnOnce(`${entry.className}.readonlyFields names "${name}", which is not a field; it is ignored`);
1018
+ }
1019
+ return [...locked];
960
1020
  }
961
1021
  /** `links()` of the resource with labels in the locale; only http(s) and relative URLs get through. */
962
1022
  recordLinks(entry, entity, locale) {
@@ -970,7 +1030,7 @@ let AdminApiService = class AdminApiService {
970
1030
  }
971
1031
  return (Array.isArray(links) ? links : [])
972
1032
  .filter((link) => typeof link?.href === 'string' && (/^https?:\/\//i.test(link.href) || !/^[a-z][a-z0-9+.-]*:/i.test(link.href.trim())))
973
- .map((link) => ({ label: resolveText(link.label, locale, this.options.locale), href: link.href }));
1033
+ .map((link) => ({ label: this.options.texts(link.label, locale), href: link.href }));
974
1034
  }
975
1035
  warned = new Set();
976
1036
  warnOnce(message) {
@@ -3,13 +3,46 @@ import type { LocalizedText } from '../i18n/localized-text.js';
3
3
  import type { AdminMenuOptions } from '../options.js';
4
4
  import type { PageRegistry } from '../pages/page-registry.js';
5
5
  import type { ResourceRegistry } from '../registry/resource-registry.js';
6
+ /** A menu item by name (classes resolved at boot). */
7
+ export type ResolvedMenuItem = {
8
+ resource: string;
9
+ badge?: Record<string, string>;
10
+ } | {
11
+ page: string;
12
+ } | {
13
+ href: string;
14
+ label: LocalizedText;
15
+ };
16
+ /** A menu section with every reference resolved: names for classes, a group's label and icon filled in. */
17
+ export interface ResolvedMenuSection {
18
+ key: string;
19
+ label: LocalizedText;
20
+ /** The `translate` key of the label: the section's own (`menu.<key>`), or the group's (`group.<key>`). */
21
+ labelKey: string;
22
+ icon: string;
23
+ /** Without items: the members of this group, as the user sees them (meta's group). */
24
+ group?: string;
25
+ items?: ResolvedMenuItem[];
26
+ }
27
+ export interface ResolvedMenu {
28
+ sections: ResolvedMenuSection[];
29
+ advanced?: {
30
+ label?: LocalizedText;
31
+ };
32
+ }
33
+ /** The menu with classes turned into names and `{ group }` sections filled from their `@AdminGroup`; fails boot on an unknown one. */
34
+ export declare function resolveMenu(menu: AdminMenuOptions, registry: ResourceRegistry, pages: PageRegistry): ResolvedMenu;
6
35
  /**
7
36
  * The menu's references, once every resource and page is registered: they exist, resources have a navigation entry,
8
37
  * and each badge is a list query the resource accepts (its `filter[...]` fields are in `list.filters`).
9
38
  */
10
- export declare function checkMenu(menu: AdminMenuOptions, registry: ResourceRegistry, pages: PageRegistry): void;
39
+ export declare function checkMenu(menu: ResolvedMenu, registry: ResourceRegistry, pages: PageRegistry): void;
11
40
  /**
12
41
  * The menu as one user gets it: items cut to the resources and pages they see (`resources`, `pages`: what meta
13
42
  * lists for them), empty sections dropped, and what no section places in `advanced`, in meta's order.
14
43
  */
15
- export declare function buildMenu(menu: AdminMenuOptions, text: (label: LocalizedText) => string, resources: MetaResourceSummary[], pages: MetaPageSummary[]): MetaMenu;
44
+ export declare function buildMenu(menu: ResolvedMenu, text: (label: LocalizedText, key?: string) => string, groups: Array<{
45
+ key: string;
46
+ resources: MetaResourceSummary[];
47
+ pages: MetaPageSummary[];
48
+ }>): MetaMenu;
package/dist/api/menu.js CHANGED
@@ -1,4 +1,44 @@
1
1
  import { parseListQuery } from '../crud/list-query.js';
2
+ import { didYouMean } from '../schema/suggest.js';
3
+ /** The menu with classes turned into names and `{ group }` sections filled from their `@AdminGroup`; fails boot on an unknown one. */
4
+ export function resolveMenu(menu, registry, pages) {
5
+ const groups = new Map(registry.groupList().map((group) => [group.key, group]));
6
+ const sections = menu.sections.map((section) => {
7
+ const fail = (message) => {
8
+ throw new Error(`nest-my-admin: menu: ${message}`);
9
+ };
10
+ const items = section.items?.map((item) => {
11
+ if ('resource' in item && typeof item.resource === 'function') {
12
+ const entry = registry.list().find((candidate) => candidate.resource.constructor === item.resource);
13
+ if (!entry)
14
+ fail(`${item.resource.name} is not a registered resource`);
15
+ return { ...item, resource: entry.schema.name };
16
+ }
17
+ if ('page' in item && typeof item.page === 'function') {
18
+ const page = pages.list().find((candidate) => candidate.source.constructor === item.page);
19
+ if (!page)
20
+ fail(`${item.page.name} is not a registered settings page`);
21
+ return { page: page.name };
22
+ }
23
+ return item;
24
+ });
25
+ const key = section.key;
26
+ if (section.group === undefined)
27
+ return { key, label: section.label, labelKey: `menu.${key}`, icon: section.icon, items: items };
28
+ const group = groups.get(section.group);
29
+ if (!group)
30
+ fail(`unknown group "${section.group}"${didYouMean(section.group, [...groups.keys()])}`);
31
+ return {
32
+ key,
33
+ label: section.label ?? group.label,
34
+ labelKey: section.label !== undefined ? `menu.${key}` : `group.${group.key}`,
35
+ icon: section.icon ?? group.icon ?? 'folder',
36
+ group: group.key,
37
+ ...(items ? { items } : {}),
38
+ };
39
+ });
40
+ return { sections, ...(menu.advanced ? { advanced: menu.advanced } : {}) };
41
+ }
2
42
  /**
3
43
  * The menu's references, once every resource and page is registered: they exist, resources have a navigation entry,
4
44
  * and each badge is a list query the resource accepts (its `filter[...]` fields are in `list.filters`).
@@ -8,7 +48,7 @@ export function checkMenu(menu, registry, pages) {
8
48
  const fail = (message) => {
9
49
  throw new Error(`nest-my-admin: menu.sections.${section.key}: ${message}`);
10
50
  };
11
- for (const item of section.items) {
51
+ for (const item of section.items ?? []) {
12
52
  if ('resource' in item) {
13
53
  const entry = registry.find(item.resource);
14
54
  if (!entry)
@@ -36,14 +76,19 @@ export function checkMenu(menu, registry, pages) {
36
76
  * The menu as one user gets it: items cut to the resources and pages they see (`resources`, `pages`: what meta
37
77
  * lists for them), empty sections dropped, and what no section places in `advanced`, in meta's order.
38
78
  */
39
- export function buildMenu(menu, text, resources, pages) {
79
+ export function buildMenu(menu, text, groups) {
80
+ const resources = groups.flatMap((group) => group.resources);
81
+ const pages = groups.flatMap((group) => group.pages);
40
82
  const resourceByName = new Map(resources.map((resource) => [resource.name, resource]));
41
83
  const pageByName = new Map(pages.map((page) => [page.name, page]));
42
84
  const placed = new Set();
43
85
  const sections = [];
44
86
  for (const section of menu.sections) {
45
87
  const items = [];
46
- for (const item of section.items) {
88
+ // A group section without items lists the group's members as the user sees them.
89
+ const members = groups.find((group) => group.key === section.group);
90
+ const listed = section.items ?? [...(members?.resources ?? []).map((resource) => ({ resource: resource.name })), ...(members?.pages ?? []).map((page) => ({ page: page.name }))];
91
+ for (const item of listed) {
47
92
  if ('resource' in item) {
48
93
  placed.add(`r:${item.resource}`);
49
94
  const seen = resourceByName.get(item.resource);
@@ -61,15 +106,15 @@ export function buildMenu(menu, text, resources, pages) {
61
106
  }
62
107
  }
63
108
  // A section of links only is the host's choice; one whose resources and pages were all cut is dropped.
64
- const linksOnly = section.items.every((item) => 'href' in item);
109
+ const linksOnly = section.items !== undefined && section.items.every((item) => 'href' in item);
65
110
  if (linksOnly || items.some((item) => item.kind !== 'link'))
66
- sections.push({ key: section.key, label: text(section.label), icon: section.icon, items });
111
+ sections.push({ key: section.key, label: text(section.label, section.labelKey), icon: section.icon, items });
67
112
  }
68
113
  const rest = [
69
114
  ...resources.filter((resource) => !placed.has(`r:${resource.name}`)).map((resource) => resourceItem(resource, false)),
70
115
  ...pages.filter((page) => !placed.has(`p:${page.name}`)).map((page) => ({ kind: 'page', page: page.name, label: page.label, ...(page.icon ? { icon: page.icon } : {}) })),
71
116
  ];
72
- return { sections, advanced: { key: 'advanced', label: text(menu.advanced?.label ?? { en: 'Advanced', fa: 'پیشرفته' }), icon: 'database', items: rest } };
117
+ return { sections, advanced: { key: 'advanced', label: text(menu.advanced?.label ?? { en: 'Advanced', fa: 'پیشرفته' }, 'menu.advanced'), icon: 'database', items: rest } };
73
118
  }
74
119
  function resourceItem(summary, badge) {
75
120
  return {
@@ -1,7 +1,7 @@
1
1
  import type { Logger } from '@nestjs/common';
2
2
  import type { DataSource } from 'typeorm';
3
3
  import type { ResolvedAdminOptions } from '../options.js';
4
- import { AdminContext } from '../resource/admin-context.js';
4
+ import { AdminContext, type AdminWriteContext } from '../resource/admin-context.js';
5
5
  import type { WriteChange, WriteParticipant } from './write-participant.js';
6
6
  /**
7
7
  * The admin's write transaction (`AdminApiService.write`) and the participants of every change made inside it.
@@ -21,7 +21,7 @@ export declare class WriteRunner {
21
21
  */
22
22
  run<T>(target: {
23
23
  dataSource: DataSource;
24
- }, ctx: AdminContext, work: (ctx: AdminContext) => Promise<T>): Promise<T>;
24
+ }, ctx: AdminContext, work: (ctx: AdminWriteContext) => Promise<T>): Promise<T>;
25
25
  /**
26
26
  * One change inside the write `tx`: every participant's `before`, then the host `method`, then every `after` with
27
27
  * what the method saved (`savedOf`; by default the method's answer when it is an object) and with what is stored
@@ -1,5 +1,5 @@
1
1
  import { hostError } from '../http/error-response.js';
2
- import { AdminContext, runInAdminContext } from '../resource/admin-context.js';
2
+ import { AdminContext, markTransaction, runInAdminContext } from '../resource/admin-context.js';
3
3
  import { keyOf, loadStored } from '../crud/stored-row.js';
4
4
  import { exclusive } from './write-queue.js';
5
5
  /**
@@ -43,7 +43,12 @@ export class WriteRunner {
43
43
  };
44
44
  if (!this.options.transactions) {
45
45
  // Nothing to commit: the participants settle when the outermost write on this context is done.
46
- return this.open.has(ctx) ? work(ctx) : committed(ctx, () => work(ctx));
46
+ // The write still gets a manager, the DataSource's own; it is not a transaction (`inAdminTransaction` says no).
47
+ // A nested write on this context: it got its manager from the outer one.
48
+ if (this.open.has(ctx))
49
+ return work(ctx);
50
+ const plain = { ...ctx, manager: target.dataSource.manager };
51
+ return committed(plain, () => runInAdminContext(plain, () => work(plain)));
47
52
  }
48
53
  const { dataSource } = target;
49
54
  // Re-entrant write (host code inside a write calls the API again on the same DataSource): join the outer
@@ -59,6 +64,7 @@ export class WriteRunner {
59
64
  const transactional = { ...ctx };
60
65
  return committed(transactional, () => dataSource.transaction(async (manager) => {
61
66
  transactional.manager = manager;
67
+ markTransaction(transactional);
62
68
  return runInAdminContext(transactional, () => work(transactional));
63
69
  }));
64
70
  });
@@ -5,6 +5,7 @@ import { keyOf, loadStored, whereOf } from '../crud/stored-row.js';
5
5
  import { pick } from '../pages/page.service.js';
6
6
  import { sensitiveFields } from '../schema/field-config.js';
7
7
  import { diffRecords } from './diff.js';
8
+ import { inAdminTransaction } from '../resource/admin-context.js';
8
9
  const EVENTS = { create: 'created', update: 'updated', delete: 'deleted', restore: 'restored', purge: 'purged' };
9
10
  /**
10
11
  * The audit log as a participant of every write (after files). "Before" is read and serialized ahead of the host
@@ -61,7 +62,7 @@ export function auditParticipant(audit) {
61
62
  const input = change.parent ? { ...entry, meta: { ...entry.meta, parent: change.parent } } : entry;
62
63
  if (audit.joins(tx))
63
64
  state.entryId = await audit.record(input, tx);
64
- else if (tx.manager)
65
+ else if (inAdminTransaction(tx))
65
66
  state.pending = input;
66
67
  else
67
68
  await audit.recordAfter(input, tx);
@@ -15,7 +15,7 @@ import { ModuleRef } from '@nestjs/core';
15
15
  import { getDataSourceToken } from '@nestjs/typeorm';
16
16
  import { SINGLE_CONNECTION_DRIVERS, exclusive } from '../api/write-queue.js';
17
17
  import { ADMIN_OPTIONS } from '../constants.js';
18
- import { AdminContext } from '../resource/admin-context.js';
18
+ import { AdminContext, inAdminTransaction } from '../resource/admin-context.js';
19
19
  import { fitChanges } from './diff.js';
20
20
  import { NmaAuditEntry } from './entities.js';
21
21
  import { LoginFailures, WINDOW_MS } from './login-failures.js';
@@ -126,7 +126,7 @@ let AdminAudit = class AdminAudit {
126
126
  }
127
127
  /** Whether an entry recorded with `ctx` is written in its transaction (the transaction is on the audit log's DataSource). */
128
128
  joins(ctx) {
129
- return this.enabled && ctx.manager !== undefined && ctx.manager.connection === this.db;
129
+ return this.enabled && inAdminTransaction(ctx) && ctx.manager !== undefined && ctx.manager.connection === this.db;
130
130
  }
131
131
  /**
132
132
  * Writes an entry now, inside `ctx.manager`'s transaction when it `joins`, and answers its id. Throws when it
@@ -286,7 +286,9 @@ let AdminAudit = class AdminAudit {
286
286
  // On a single-connection driver, an entry written from inside an admin write on the audit log's own DataSource
287
287
  // (host code of that write changed something on another DataSource) cannot wait for the queue that write
288
288
  // holds: it goes through the write's manager.
289
- const holder = SINGLE_CONNECTION_DRIVERS.has(this.db.options.type) ? AdminContext.current()?.manager : undefined;
289
+ const current = AdminContext.current();
290
+ // Only a transaction holds the queue; a write with `transactions: false` has a manager but holds nothing.
291
+ const holder = SINGLE_CONNECTION_DRIVERS.has(this.db.options.type) && current && inAdminTransaction(current) ? current.manager : undefined;
290
292
  const inside = manager ?? (holder?.connection === this.db ? holder : undefined);
291
293
  const result = inside ? await inside.getRepository(NmaAuditEntry).insert(values) : await exclusive(this.db, () => this.db.getRepository(NmaAuditEntry).insert(values));
292
294
  const id = Number(result.identifiers[0]?.id);
@@ -556,6 +556,10 @@ export interface RecordPermissions {
556
556
  delete: boolean;
557
557
  /** Record actions by name: the label to show on this record (`label.for`, else the action's label), or `false` when it may not run here. */
558
558
  actions?: Record<string, string | false>;
559
+ /** Inline children with an `@AdminCan('create')` rule: whether a row may be added under this record. */
560
+ inlines?: Record<string, {
561
+ create: boolean;
562
+ }>;
559
563
  }
560
564
  /** `POST /resources/:resource/bulk-delete` with `{ ids }` (encoded record ids): each id succeeds or fails on its own. */
561
565
  export interface BulkResult {
@@ -1096,4 +1100,6 @@ export interface AdminRuntimeConfig {
1096
1100
  unit: LocalizedLabel;
1097
1101
  position: 'after' | 'before';
1098
1102
  };
1103
+ /** UI texts the host rewords through `translate` (`ui.<key>`), per locale; only the overridden keys. */
1104
+ messages?: Record<string, Record<string, string>>;
1099
1105
  }
@@ -15,3 +15,9 @@ export declare function relationIdsOf(body: object, schema: ResourceSchema): Map
15
15
  * Used by the default create/update; host services get the ids as validated.
16
16
  */
17
17
  export declare function toRelationReferences(dto: object, metadata: RelatedMetadataLike): object;
18
+ /**
19
+ * Relation values of a picker's `values` (form state the browser sent) in the target key's type, as write bodies
20
+ * already are: a to-one id parsed with `parseId`, a many-to-many list element-wise. A value that does not parse is
21
+ * left out; `null` stays; other keys are untouched.
22
+ */
23
+ export declare function normalizeRelationValues(values: Record<string, unknown>, schema: ResourceSchema): Record<string, unknown>;