resources: add response compose helpers#1070
Conversation
There was a problem hiding this comment.
Pull request overview
Adds small composition helpers to the resources/responses.ts module to build static built-in responses by concatenating multiple LocaleText values with separators (with language fallback to en), plus unit tests validating composition behavior and severity handling.
Changes:
- Add
combineLocaleTexthelper to concatenate localized strings with per-language fallback. - Export new
composeandcompose3helpers to generate static built-in responses from 2 or 3LocaleTextparts. - Add unit tests covering composed output strings, severity selection, and locale fallbacks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| resources/responses.ts | Introduces combineLocaleText plus exported compose / compose3 static response helpers. |
| test/unittests/responses_test.ts | Adds unit tests validating composed output strings and severity / locale fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
re: It's possible to make a function in Typescript require pairs of arguments, such that: const compose = (a: LocaleText, ...rest: SpecialType)...;
const lt = { en: 'Test' };
const sep1 = { en: '=>' };
const sep2 = { en: '+' };
// Returns `Test`
compose(lt);
// Returns `Test => Test`
compose(lt, sep1, lt);
// Results in compile error
compose(lt, sep1);
// Returns `Test => Test + Test`
compose(lt, sep1, lt, sep2, lt);(setting up the Typescript types to get this functioning is a bit complicated, but it's possible). I think the better question here is, "is there any case where more than 3 combines should be required, or would any case that potentially fits that criteria be better off broken up into separate triggers". If it should always be broken up, then some function parameter type checking with optional parameters can allow for a single If we might want to allow additional combines, it would be better to use a generic function setup that allows 1 + any number of pairs of arguments as described above. |
|
There are quite a few cases where combining 3 LocaleTexts:
There are also a few cases that combine four pieces:
So I don’t think After trying a few things, I found that the type definitions for a fully generic version were actually longer and more complex than the implementation itself. I opted for the current structure because it's easier to read and maintain, even if it's less flexible. |
|
The hardest part of implementing generics is the existence of |
9113271 to
355cbdf
Compare
fixes #1058
Add
composeandcompose3helper functions for combining LocaleText output strings into static built-in responses.Based on my experience so far, I am confident that as long as it is used only for simple and clear content, there will be no translation issues.
2026-06-05
combineLocaleTextfunction public2026-06-23
composeto a variadic function that takesseverityas an argument later, and removecompose3.