|
27 | 27 | * - `params` fills the entries' `{{name}}` holes. A value is used as given, |
28 | 28 | * or, spelled `{ key, fallback }`, is itself the recipient-language text of |
29 | 29 | * the catalog entry `key`, else `fallback`; or, spelled |
30 | | - * `{ objectLabel, fallback }`, is the label of the object named |
31 | | - * `objectLabel` in the recipient's language, else `fallback`. |
| 30 | + * `{ object, fallback }`, is the label of the object whose API name is |
| 31 | + * `object`, in the recipient's language, else `fallback`. |
32 | 32 | * - [#35384] An object's label is METADATA, not a catalog sentence, so the |
33 | | - * `{ objectLabel }` param is resolved as `GET /meta/object/:name` serves it: |
| 33 | + * `{ object }` param is resolved as `GET /meta/object/:name` serves it: |
34 | 34 | * by `translateObject` (`@objectstack/spec/system`) over the object's |
35 | 35 | * served definition and its packaged base, with the metadata route's |
36 | 36 | * `ResolveOptions` (the recipient's negotiated locale, the DECLARED |
@@ -98,15 +98,16 @@ export type NotificationTextParam = |
98 | 98 | | NotificationObjectLabelParam; |
99 | 99 |
|
100 | 100 | /** |
101 | | - * [#35384] A `{{name}}` value that is the label of the object `objectLabel` |
102 | | - * names (its API name, `crm_deal`), in the recipient's language, as |
| 101 | + * [#35384] A `{{name}}` value that is the label of the object whose API name |
| 102 | + * `object` holds (`crm_deal`), in the recipient's language, as |
103 | 103 | * `GET /meta/object/:name` serves it: `translateObject` over the object's |
104 | 104 | * served definition and packaged base, with the metadata route's resolve |
105 | 105 | * options. `fallback` is the text when nothing resolves (no `i18n` service |
106 | 106 | * that can hand its translations over, no data engine that knows the object). |
107 | 107 | */ |
108 | 108 | export interface NotificationObjectLabelParam { |
109 | | - readonly objectLabel: string; |
| 109 | + /** The object's API name (`ObjectSchema.name`), never its label: the param names the object, the render picks its label. */ |
| 110 | + readonly object: string; |
110 | 111 | readonly fallback: string; |
111 | 112 | } |
112 | 113 |
|
@@ -158,7 +159,7 @@ const PARAM_NAME_SHAPE = /^\w+$/; |
158 | 159 |
|
159 | 160 | const TEXT_MEMBERS: ReadonlySet<string> = new Set(['titleKey', 'bodyKey', 'params']); |
160 | 161 | const KEYED_PARAM_MEMBERS: ReadonlySet<string> = new Set(['key', 'fallback']); |
161 | | -const OBJECT_LABEL_PARAM_MEMBERS: ReadonlySet<string> = new Set(['objectLabel', 'fallback']); |
| 162 | +const OBJECT_LABEL_PARAM_MEMBERS: ReadonlySet<string> = new Set(['object', 'fallback']); |
162 | 163 |
|
163 | 164 | /** |
164 | 165 | * An object's API name: one segment of {@link CATALOG_KEY_SHAPE}, so every |
@@ -194,15 +195,15 @@ function problemOf(value: unknown): string | undefined { |
194 | 195 | for (const [name, param] of Object.entries(params)) { |
195 | 196 | if (!PARAM_NAME_SHAPE.test(name)) return `.params has a name '${name}' no {{hole}} can spell`; |
196 | 197 | if (typeof param === 'string') continue; |
197 | | - if (!isPlainObject(param)) return `.params.${name} must be a string, { key, fallback } or { objectLabel, fallback }`; |
198 | | - if ('objectLabel' in param) { |
| 198 | + if (!isPlainObject(param)) return `.params.${name} must be a string, { key, fallback } or { object, fallback }`; |
| 199 | + if ('object' in param) { |
199 | 200 | for (const member of Object.keys(param)) { |
200 | 201 | if (!OBJECT_LABEL_PARAM_MEMBERS.has(member)) { |
201 | | - return `.params.${name} has an undeclared member '${member}' (declared: objectLabel, fallback)`; |
| 202 | + return `.params.${name} has an undeclared member '${member}' (declared: object, fallback)`; |
202 | 203 | } |
203 | 204 | } |
204 | | - if (typeof param.objectLabel !== 'string' || !OBJECT_NAME_SHAPE.test(param.objectLabel)) { |
205 | | - return `.params.${name}.objectLabel must be an object's API name such as 'crm_deal' (got ${JSON.stringify(param.objectLabel)})`; |
| 205 | + if (typeof param.object !== 'string' || !OBJECT_NAME_SHAPE.test(param.object)) { |
| 206 | + return `.params.${name}.object must be an object's API name such as 'crm_deal' (got ${JSON.stringify(param.object)})`; |
206 | 207 | } |
207 | 208 | if (typeof param.fallback !== 'string') return `.params.${name}.fallback must be a string`; |
208 | 209 | continue; |
@@ -375,9 +376,9 @@ export class NotificationTextRenderer { |
375 | 376 | for (const [name, param] of Object.entries(keys.params ?? {})) { |
376 | 377 | if (typeof param === 'string') { |
377 | 378 | params[name] = param; |
378 | | - } else if ('objectLabel' in param) { |
| 379 | + } else if ('object' in param) { |
379 | 380 | translation ??= { value: metaLabelTranslation(i18n, locale) }; |
380 | | - params[name] = this.objectLabel(translation.value, param.objectLabel) ?? param.fallback; |
| 381 | + params[name] = this.objectLabel(translation.value, param.object) ?? param.fallback; |
381 | 382 | } else { |
382 | 383 | params[name] = lookup(i18n, param.key, locale) ?? param.fallback; |
383 | 384 | } |
|
0 commit comments