The PR changes the link patterns configuration type from the array to the record whose keys are either LinkType values or arbitrary strings. A link's template can now be an arbitrary function from string to string. LinkConfig is now defined as follows:
A generic type argument is used to allow integrations to extend link options. Allure-cucumber does that to add an extra pattern field to the options.
Defining the config as an intersection allows us to:
keep IDE autocompletion
index the values with arbitrary string keys (TS infers the resulting type to be TOpts instead of TOpts | undefined in such cases, but that's how it works for any record without the noUncheckedIndexedAccess TS option).
Some examples:
import type { Config } from "allure-js-commons/sdk/reporter";
import { LinkType } from "allure-js-commons";
const config: Config = {
issue: { // Hinted by IDE autocompletion
urlTemplate: "https://foo/%s"
},
[LinkType.DEFAULT]: { // Enum as the key
urlTemplate: "https://bar/%s"
},
custom: { // An arbitrary string
urlTemplate: "https://baz/%s",
nameTemplate: "CUSTOM-%s",
},
tms: { // Template functions
urlTemplate: (v) => `https://baz/${v}`,
nameTemplate: (v) => `CUSTOM-${v}`,
}
};
Context
The PR changes the link patterns configuration type from the array to the record whose keys are either
LinkType
values or arbitrary strings. A link's template can now be an arbitrary function fromstring
tostring
.LinkConfig
is now defined as follows:A generic type argument is used to allow integrations to extend link options. Allure-cucumber does that to add an extra
pattern
field to the options.Defining the config as an intersection allows us to:
TOpts
instead ofTOpts | undefined
in such cases, but that's how it works for any record without thenoUncheckedIndexedAccess
TS option).Some examples:
Checklist