Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(attributes): derive the attribute name types from the builtin list
Elian Doran87fa569cdfe2
diff --git a/apps/server/src/services/anonymization.spec.ts b/apps/server/src/services/anonymization.spec.tsindex 148232f1bf..6bab6f19f0 100644--- a/apps/server/src/services/anonymization.spec.ts+++ b/apps/server/src/services/anonymization.spec.ts@@ -67,13 +67,16 @@ describe("getFullAnonymizationScript", () => {expect(script).toContain("'inbox'");expect(script).toContain("'archived'");- // share-specific attributes are intentionally excluded from the keep-list.+ // Builtin names whose value is user-authored are intentionally excluded from the keep-list, so+ // that the value gets scrubbed along with the ordinary user attributes.expect(script).not.toContain("'shareCredentials'");expect(script).not.toContain("'shareAlias'");+ expect(script).not.toContain("'geolocation'");+ expect(script).not.toContain("'searchString'");// Sanity: every other builtin attribute name appears in the keep-list.const expectedNames = BUILTIN_ATTRIBUTES- .filter((a) => !["shareCredentials", "shareAlias"].includes(a.name))+ .filter((a) => !("hasUserValue" in a && a.hasUserValue)).map((a) => a.name);for (const name of expectedNames) {expect(script).toContain(`'${name}'`);diff --git a/apps/server/src/services/anonymization.ts b/apps/server/src/services/anonymization.tsindex 0c7d2f21ad..fc206a4d09 100644--- a/apps/server/src/services/anonymization.ts+++ b/apps/server/src/services/anonymization.ts@@ -9,8 +9,10 @@ import sql from "./sql.js";function getFullAnonymizationScript() {// we want to delete all non-builtin attributes because they can contain sensitive names and values- // on the other hand builtin/system attrs should not contain any sensitive info- const builtinAttrNames = BUILTIN_ATTRIBUTES.filter((attr) => !["shareCredentials", "shareAlias"].includes(attr.name))+ // on the other hand builtin/system attrs should not contain any sensitive info -- except for the+ // ones whose name is system-defined but whose value is authored by the user (`#shareCredentials`,+ // `#geolocation`, ...), which `hasUserValue` marks so they get scrubbed like any other attribute+ const builtinAttrNames = BUILTIN_ATTRIBUTES.filter((attr) => !("hasUserValue" in attr && attr.hasUserValue)).map((attr) => `'${attr.name}'`).join(", ");diff --git a/packages/commons/src/index.ts b/packages/commons/src/index.tsindex 908817c037..8a90ee57e5 100644--- a/packages/commons/src/index.ts+++ b/packages/commons/src/index.ts@@ -19,6 +19,7 @@ export * from "./lib/dayjs.js";export * from "./lib/notes.js";export * from "./lib/onenote.js";export * from "./lib/week_utils.js";+export * from "./lib/builtin_attributes.js";export { default as BUILTIN_ATTRIBUTES } from "./lib/builtin_attributes.js";// The spreadsheet modules are deliberately not re-exported here: they pull in numfmt, and the// barrel is imported by virtually every client module. Import them via their subpath instead,diff --git a/packages/commons/src/lib/attribute_names.ts b/packages/commons/src/lib/attribute_names.tsindex 7f72ae7fa2..422a85b346 100644--- a/packages/commons/src/lib/attribute_names.ts+++ b/packages/commons/src/lib/attribute_names.ts@@ -1,111 +1,8 @@/**- * A listing of all the labels used by the system (i.e. not user-defined). Labels defined here have a data type which is not enforced, but offers type safety.+ * Validation of attribute *names* in general, whatever they mean. The vocabulary of names the system+ * itself defines, and the `LabelNames` / `RelationNames` types that go with it, live in+ * `builtin_attributes.ts` — they are derived from the runtime list there so the two cannot drift.*/-type Labels = {- color: string;- iconClass: string;- iconPack: string;- workspace: boolean;- workspaceTabBackgroundColor: string;- workspaceIconClass: string;- executeButton: boolean;- executeDescription: string;- executeTitle: string;- limit: string; // should be probably be number- calendarRoot: boolean;- workspaceCalendarRoot: boolean;- archived: boolean;- sorted: boolean;- template: boolean;- autoReadOnlyDisabled: boolean;- language: string;- originalFileName: string;- pageUrl: string;- docUrl: string;- dateNote: string;-- // Scripting- run: string;- widget: boolean;- "disabled:widget": boolean;- customRequestHandler: string;-- // Tree specific- subtreeHidden: boolean;-- // Search- searchString: string;- ancestorDepth: string;- orderBy: string;- orderDirection: string;-- // Launch bar- bookmarkFolder: boolean;- command: string;- keyboardShortcut: string;-- // Collection-specific- viewType: string;- status: string;- pageSize: number;- geolocation: string;- expanded: string;- "calendar:hideWeekends": boolean;- "calendar:weekNumbers": boolean;- "calendar:view": string;- "calendar:initialDate": string;- "calendar:slotDuration": string;- "calendar:slotLabelInterval": string;- "map:style": string;- "map:scale": boolean;- "map:hideLabels": boolean;- "board:groupBy": string;- maxNestingDepth: number;- includeArchived: boolean;- "presentation:theme": string;- "slide:background": string;-- // Print/export- printLandscape: boolean;- printPageSize: string;- printScale: string;- printMargins: string;-- // Note-type specific- webViewSrc: string;- "disabled:webViewSrc": string;- readOnly: boolean;- fullContentWidth: boolean;- displayMode: string;- tabWidth: number;- indentWithTabs: boolean;- wrapLines: boolean;- mapType: string;- mapRootNoteId: string;-- appTheme: string;- appThemeBase: string;-}--/**- * A listing of all relations used by the system (i.e. not user-defined). Unlike labels, relations- * always point to a note ID, so no specific data type is necessary.- */-type Relations = [- "searchScript",- "ancestor",-- // Active content- "renderNote",- "disabled:renderNote",-- // Launcher-specific- "target",- "widget"-];--export type LabelNames = keyof Labels;-export type RelationNames = Relations[number];/*** The characters an attribute name may consist of: letters, numbers, underscore and colon. Kept as a@@ -129,7 +26,3 @@ export function filterAttributeName(name: string) {export function isValidAttributeName(name: string) {return ATTR_NAME_MATCHER.test(name);}--export type FilterLabelsByType<U> = {- [K in keyof Labels]: Labels[K] extends U ? K : never;-}[keyof Labels];diff --git a/packages/commons/src/lib/builtin_attributes.spec.ts b/packages/commons/src/lib/builtin_attributes.spec.tsnew file mode 100644index 0000000000..003128317c--- /dev/null+++ b/packages/commons/src/lib/builtin_attributes.spec.ts@@ -0,0 +1,57 @@+import { describe, expect, it } from "vitest";++import BUILTIN_ATTRIBUTES, { type FilterLabelsByType, type LabelNames, type RelationNames } from "./builtin_attributes.js";++describe("BUILTIN_ATTRIBUTES", () => {+ it("declares each name once per type, with a value type on every label", () => {+ const seen = new Set<string>();++ for (const attr of BUILTIN_ATTRIBUTES) {+ const key = `${attr.type}:${attr.name}`;+ expect(seen.has(key), `${key} is declared more than once`).toBe(false);+ seen.add(key);++ if (attr.type === "label") {+ expect([ "boolean", "string", "number" ]).toContain(attr.valueType);+ }+ }+ });++ it("marks a value as user-authored only where a value exists to author", () => {+ // Relations always point at a note ID, so `hasUserValue` would be meaningless on one.+ const flaggedRelations = BUILTIN_ATTRIBUTES+ .filter((attr) => attr.type === "relation" && "hasUserValue" in attr)+ .map((attr) => attr.name);++ expect(flaggedRelations).toEqual([]);+ });+});++/**+ * The point of deriving the name types from the list above is that a name cannot be known to one and+ * missing from the other. These assertions fail at build time rather than at run time, so they carry no+ * expectations — merely naming a label that is no longer declared is the failure.+ */+describe("derived name types", () => {+ it("covers plain names, their disabled forms and the per-value-type subsets", () => {+ const label: LabelNames = "calendar:view";+ const relation: RelationNames = "template";++ // Dangerous attributes get their `disabled:` form generated, rather than enumerated by hand.+ const disabledLabel: LabelNames = "disabled:webViewSrc";+ const disabledRelation: RelationNames = "disabled:renderNote";++ const flag: FilterLabelsByType<boolean> = "archived";+ const text: FilterLabelsByType<string> = "searchString";+ const count: FilterLabelsByType<number> = "pageSize";++ // @ts-expect-error a name nothing declares is not a builtin one+ const unknown: LabelNames = "notALabelTriliumKnows";++ // @ts-expect-error `archived` is a flag, so it is absent from the string-valued subset+ const wrongValueType: FilterLabelsByType<string> = "archived";++ expect([ label, relation, disabledLabel, disabledRelation, flag, text, count, unknown, wrongValueType ])+ .toHaveLength(9);+ });+});diff --git a/packages/commons/src/lib/builtin_attributes.ts b/packages/commons/src/lib/builtin_attributes.tsindex 3b89a57901..81427e8e82 100644--- a/packages/commons/src/lib/builtin_attributes.ts+++ b/packages/commons/src/lib/builtin_attributes.ts@@ -1,96 +1,181 @@-export default [- // label names- { type: "label", name: "inbox" },- { type: "label", name: "disableVersioning" },- { type: "label", name: "calendarRoot" },- { type: "label", name: "archived" },- { type: "label", name: "excludeFromExport" },- { type: "label", name: "disableInclusion" },- { type: "label", name: "appCss" },- { type: "label", name: "appTheme" },- { type: "label", name: "appThemeBase" },- { type: "label", name: "hidePromotedAttributes" },- { type: "label", name: "readOnly" },- { type: "label", name: "autoReadOnlyDisabled" },- { type: "label", name: "cssClass" },- { type: "label", name: "iconClass" },- { type: "label", name: "keyboardShortcut" },- { type: "label", name: "run", isDangerous: true },- { type: "label", name: "runOnInstance", isDangerous: false },- { type: "label", name: "runAtHour", isDangerous: false },- { type: "label", name: "customRequestHandler", isDangerous: true },- { type: "label", name: "customResourceProvider", isDangerous: true },- { type: "label", name: "widget", isDangerous: true },- { type: "label", name: "similarNotesWidgetDisabled" },- { type: "label", name: "workspace" },- { type: "label", name: "workspaceIconClass" },- { type: "label", name: "workspaceTabBackgroundColor" },- { type: "label", name: "workspaceCalendarRoot" },- { type: "label", name: "workspaceTemplate" },- { type: "label", name: "searchHome" },- { type: "label", name: "workspaceInbox" },- { type: "label", name: "workspaceSearchHome" },- { type: "label", name: "sqlConsoleHome" },- { type: "label", name: "datePattern" },- { type: "label", name: "weekPattern" },- { type: "label", name: "enableWeekNote" },- { type: "label", name: "monthPattern" },- { type: "label", name: "quarterPattern" },- { type: "label", name: "yearPattern" },- { type: "label", name: "enableQuarterNote" },- { type: "label", name: "pageSize" },- { type: "label", name: "viewType" },- { type: "label", name: "mapRootNoteId" },- { type: "label", name: "mapExcludeRelation" },- { type: "label", name: "mapIncludeRelation" },- { type: "label", name: "bookmarkFolder" },- { type: "label", name: "sorted" },- { type: "label", name: "sortDirection" },- { type: "label", name: "sortFoldersFirst" },- { type: "label", name: "sortNatural" },- { type: "label", name: "sortLocale" },- { type: "label", name: "top" },- { type: "label", name: "bottom" },- { type: "label", name: "fullContentWidth" },- { type: "label", name: "shareHiddenFromTree" },- { type: "label", name: "shareExternalLink" },- { type: "label", name: "shareAlias" },- { type: "label", name: "shareOmitDefaultCss" },- { type: "label", name: "shareRoot" },- { type: "label", name: "shareDescription" },- { type: "label", name: "shareRaw", isDangerous: true },- { type: "label", name: "shareDisallowRobotIndexing" },- { type: "label", name: "shareCredentials" },- { type: "label", name: "shareIndex" },- { type: "label", name: "shareHtmlLocation" },- { type: "label", name: "displayRelations" },- { type: "label", name: "hideRelations" },- { type: "label", name: "titleTemplate", isDangerous: true },- { type: "label", name: "template" },- { type: "label", name: "snippet" },- { type: "label", name: "textSnippet" },- { type: "label", name: "toc" },- { type: "label", name: "color" },- { type: "label", name: "keepCurrentHoisting" },- { type: "label", name: "executeButton" },- { type: "label", name: "executeDescription" },- { type: "label", name: "newNotesOnTop" },- { type: "label", name: "clipperInbox" },- { type: "label", name: "webViewSrc", isDangerous: true },- { type: "label", name: "hideHighlightWidget" },- { type: "label", name: "iconPack", isDangerous: true },- { type: "label", name: "docName", isDangerous: true },- { type: "label", name: "docUrl", isDangerous: true },-- { type: "label", name: "tabWidth" },- { type: "label", name: "indentWithTabs" },- { type: "label", name: "wrapLines" },-- { type: "label", name: "printLandscape" },- { type: "label", name: "printPageSize" },- { type: "label", name: "printScale" },- { type: "label", name: "printMargins" },- { type: "label", name: "internalBookmark" },+/**+ * Every attribute name Trilium itself gives a meaning to, as opposed to the ones a user invents.+ *+ * This is the single source of truth for that vocabulary: the {@link LabelNames} / {@link RelationNames}+ * types are derived from the array below, so a name cannot be known to the type system while being+ * missing from the runtime list (the drift that previously let system attributes go unrecognised).+ * Adding a name here is all that is needed to make it type-checkable and recognised at runtime alike.+ */++/**+ * A label, i.e. an attribute carrying a value.+ */+export interface BuiltinLabel {+ type: "label";+ name: string;+ /**+ * The shape the label's value is read as. Not enforced at runtime — attribute values are always+ * stored as strings — but it types the `useNoteLabel*` hooks via {@link FilterLabelsByType}.+ */+ valueType: "boolean" | "string" | "number";+ /**+ * Whether the attribute executes or embeds content, and so must be neutralised on import.+ * Dangerous attributes can be deactivated by prefixing them with `disabled:`, which is where the+ * `disabled:*` members of {@link LabelNames} / {@link RelationNames} come from.+ */+ isDangerous?: boolean;+ /**+ * Whether the *value* may contain user data, even though the *name* is system-defined. The name of+ * such an attribute is safe to keep in an anonymized database dump, its value is not — see+ * `anonymization.ts`, which preserves builtin attributes wholesale except for these.+ */+ hasUserValue?: boolean;+}++/**+ * A relation, i.e. an attribute pointing at a note. Its value is always a note ID, so it needs neither+ * a value type nor a {@link BuiltinLabel.hasUserValue} marker.+ */+export interface BuiltinRelation {+ type: "relation";+ name: string;+ isDangerous?: boolean;+}++const BUILTIN_ATTRIBUTES = [+ // Note tree & organisation+ { type: "label", name: "inbox", valueType: "boolean" },+ { type: "label", name: "disableVersioning", valueType: "boolean" },+ { type: "label", name: "calendarRoot", valueType: "boolean" },+ { type: "label", name: "archived", valueType: "boolean" },+ { type: "label", name: "excludeFromExport", valueType: "boolean" },+ { type: "label", name: "disableInclusion", valueType: "boolean" },+ { type: "label", name: "appCss", valueType: "boolean" },+ { type: "label", name: "appTheme", valueType: "string" },+ { type: "label", name: "appThemeBase", valueType: "string" },+ { type: "label", name: "hidePromotedAttributes", valueType: "boolean" },+ { type: "label", name: "readOnly", valueType: "boolean" },+ { type: "label", name: "autoReadOnlyDisabled", valueType: "boolean" },+ { type: "label", name: "cssClass", valueType: "string" },+ { type: "label", name: "iconClass", valueType: "string" },+ { type: "label", name: "keyboardShortcut", valueType: "string" },+ { type: "label", name: "run", valueType: "string", isDangerous: true },+ { type: "label", name: "runOnInstance", valueType: "string", isDangerous: false },+ { type: "label", name: "runAtHour", valueType: "number", isDangerous: false },+ { type: "label", name: "customRequestHandler", valueType: "string", isDangerous: true },+ { type: "label", name: "customResourceProvider", valueType: "string", isDangerous: true },+ { type: "label", name: "widget", valueType: "boolean", isDangerous: true },+ { type: "label", name: "similarNotesWidgetDisabled", valueType: "boolean" },+ { type: "label", name: "workspace", valueType: "boolean" },+ { type: "label", name: "workspaceIconClass", valueType: "string" },+ { type: "label", name: "workspaceTabBackgroundColor", valueType: "string" },+ { type: "label", name: "workspaceCalendarRoot", valueType: "boolean" },+ { type: "label", name: "workspaceTemplate", valueType: "boolean" },+ { type: "label", name: "searchHome", valueType: "boolean" },+ { type: "label", name: "workspaceInbox", valueType: "boolean" },+ { type: "label", name: "workspaceSearchHome", valueType: "boolean" },+ { type: "label", name: "sqlConsoleHome", valueType: "boolean" },+ { type: "label", name: "datePattern", valueType: "string" },+ { type: "label", name: "weekPattern", valueType: "string" },+ { type: "label", name: "enableWeekNote", valueType: "boolean" },+ { type: "label", name: "monthPattern", valueType: "string" },+ { type: "label", name: "quarterPattern", valueType: "string" },+ { type: "label", name: "yearPattern", valueType: "string" },+ { type: "label", name: "enableQuarterNote", valueType: "boolean" },+ { type: "label", name: "dateNote", valueType: "string", hasUserValue: true },+ { type: "label", name: "pageSize", valueType: "number" },+ { type: "label", name: "viewType", valueType: "string" },+ { type: "label", name: "mapRootNoteId", valueType: "string" },+ { type: "label", name: "mapExcludeRelation", valueType: "string" },+ { type: "label", name: "mapIncludeRelation", valueType: "string" },+ { type: "label", name: "bookmarkFolder", valueType: "boolean" },+ { type: "label", name: "sorted", valueType: "boolean" },+ { type: "label", name: "sortDirection", valueType: "string" },+ { type: "label", name: "sortFoldersFirst", valueType: "boolean" },+ { type: "label", name: "sortNatural", valueType: "boolean" },+ { type: "label", name: "sortLocale", valueType: "string" },+ { type: "label", name: "top", valueType: "boolean" },+ { type: "label", name: "bottom", valueType: "boolean" },+ { type: "label", name: "fullContentWidth", valueType: "boolean" },+ { type: "label", name: "subtreeHidden", valueType: "boolean", hasUserValue: true },+ { type: "label", name: "expanded", valueType: "string", hasUserValue: true },++ // Sharing+ { type: "label", name: "shareHiddenFromTree", valueType: "boolean" },+ { type: "label", name: "shareExternalLink", valueType: "boolean" },+ { type: "label", name: "shareAlias", valueType: "string", hasUserValue: true },+ { type: "label", name: "shareOmitDefaultCss", valueType: "boolean" },+ { type: "label", name: "shareRoot", valueType: "boolean" },+ { type: "label", name: "shareDescription", valueType: "string" },+ { type: "label", name: "shareRaw", valueType: "boolean", isDangerous: true },+ { type: "label", name: "shareDisallowRobotIndexing", valueType: "boolean" },+ { type: "label", name: "shareCredentials", valueType: "string", hasUserValue: true },+ { type: "label", name: "shareIndex", valueType: "boolean" },+ { type: "label", name: "shareHtmlLocation", valueType: "string" },++ // Attributes & scripting+ { type: "label", name: "displayRelations", valueType: "string" },+ { type: "label", name: "hideRelations", valueType: "string" },+ { type: "label", name: "titleTemplate", valueType: "string", isDangerous: true },+ { type: "label", name: "template", valueType: "boolean" },+ { type: "label", name: "snippet", valueType: "boolean" },+ { type: "label", name: "textSnippet", valueType: "boolean" },+ { type: "label", name: "toc", valueType: "string" },+ { type: "label", name: "color", valueType: "string" },+ { type: "label", name: "keepCurrentHoisting", valueType: "boolean" },+ { type: "label", name: "executeButton", valueType: "boolean" },+ { type: "label", name: "executeDescription", valueType: "string" },+ { type: "label", name: "executeTitle", valueType: "string", hasUserValue: true },+ { type: "label", name: "newNotesOnTop", valueType: "boolean" },+ { type: "label", name: "clipperInbox", valueType: "boolean" },+ { type: "label", name: "webViewSrc", valueType: "string", isDangerous: true },+ { type: "label", name: "hideHighlightWidget", valueType: "boolean" },+ { type: "label", name: "iconPack", valueType: "string", isDangerous: true },+ { type: "label", name: "docName", valueType: "string", isDangerous: true },+ { type: "label", name: "docUrl", valueType: "string", isDangerous: true },+ { type: "label", name: "language", valueType: "string", hasUserValue: true },+ { type: "label", name: "originalFileName", valueType: "string", hasUserValue: true },+ { type: "label", name: "pageUrl", valueType: "string", hasUserValue: true },+ { type: "label", name: "command", valueType: "string", hasUserValue: true },+ { type: "label", name: "displayMode", valueType: "string", hasUserValue: true },++ // Search+ { type: "label", name: "searchString", valueType: "string", hasUserValue: true },+ { type: "label", name: "ancestorDepth", valueType: "string", hasUserValue: true },+ { type: "label", name: "orderBy", valueType: "string", hasUserValue: true },+ { type: "label", name: "orderDirection", valueType: "string", hasUserValue: true },+ { type: "label", name: "limit", valueType: "string", hasUserValue: true },++ // Collections+ { type: "label", name: "status", valueType: "string", hasUserValue: true },+ { type: "label", name: "board:groupBy", valueType: "string", hasUserValue: true },+ { type: "label", name: "maxNestingDepth", valueType: "number", hasUserValue: true },+ { type: "label", name: "includeArchived", valueType: "boolean", hasUserValue: true },+ { type: "label", name: "calendar:view", valueType: "string", hasUserValue: true },+ { type: "label", name: "calendar:initialDate", valueType: "string", hasUserValue: true },+ { type: "label", name: "calendar:hideWeekends", valueType: "boolean", hasUserValue: true },+ { type: "label", name: "calendar:weekNumbers", valueType: "boolean", hasUserValue: true },+ { type: "label", name: "calendar:slotDuration", valueType: "string", hasUserValue: true },+ { type: "label", name: "calendar:slotLabelInterval", valueType: "string", hasUserValue: true },+ { type: "label", name: "geolocation", valueType: "string", hasUserValue: true },+ { type: "label", name: "mapType", valueType: "string", hasUserValue: true },+ { type: "label", name: "map:style", valueType: "string", hasUserValue: true },+ { type: "label", name: "map:scale", valueType: "boolean", hasUserValue: true },+ { type: "label", name: "map:hideLabels", valueType: "boolean", hasUserValue: true },+ { type: "label", name: "presentation:theme", valueType: "string", hasUserValue: true },+ { type: "label", name: "slide:background", valueType: "string", hasUserValue: true },++ // Code notes+ { type: "label", name: "tabWidth", valueType: "number" },+ { type: "label", name: "indentWithTabs", valueType: "boolean" },+ { type: "label", name: "wrapLines", valueType: "boolean" },++ // Printing+ { type: "label", name: "printLandscape", valueType: "boolean" },+ { type: "label", name: "printPageSize", valueType: "string" },+ { type: "label", name: "printScale", valueType: "string" },+ { type: "label", name: "printMargins", valueType: "string" },+ { type: "label", name: "internalBookmark", valueType: "boolean" },// relation names{ type: "relation", name: "internalLink" },@@ -111,9 +196,41 @@ export default [{ type: "relation", name: "inherit" },{ type: "relation", name: "widget", isDangerous: true },{ type: "relation", name: "renderNote", isDangerous: true },+ { type: "relation", name: "searchScript" },+ { type: "relation", name: "ancestor" },+ { type: "relation", name: "target" },{ type: "relation", name: "shareCss" },{ type: "relation", name: "shareJs", isDangerous: true },{ type: "relation", name: "shareHtml", isDangerous: true },{ type: "relation", name: "shareTemplate", isDangerous: true },{ type: "relation", name: "shareFavicon" }-];+] as const satisfies readonly (BuiltinLabel | BuiltinRelation)[];++/**+ * Exported under the interface rather than the literal-preserving `as const` type: an entry that omits+ * an optional field would otherwise not have it at all, making `attr.isDangerous` a type error across+ * the union. The literal types remain available internally, for the name unions below.+ */+export default BUILTIN_ATTRIBUTES as readonly (BuiltinLabel | BuiltinRelation)[];++type BuiltinAttributeEntry = (typeof BUILTIN_ATTRIBUTES)[number];+type LabelEntry = Extract<BuiltinAttributeEntry, { type: "label" }>;+type RelationEntry = Extract<BuiltinAttributeEntry, { type: "relation" }>;++/**+ * The `disabled:`-prefixed forms of the dangerous entries in `T`, which is how a dangerous attribute is+ * neutralised without losing its value. Derived rather than enumerated, so marking an attribute+ * dangerous is enough to make its disabled form known to the type system.+ */+type DisabledForms<T extends { name: string }> = `disabled:${Extract<T, { isDangerous: true }>["name"]}`;++/** Maps a value type back onto the {@link BuiltinLabel.valueType} discriminant that stands for it. */+type ValueTypeName<U> = U extends boolean ? "boolean" : U extends number ? "number" : U extends string ? "string" : never;++type LabelsWithValueType<U> = Extract<LabelEntry, { valueType: ValueTypeName<U> }>;++export type LabelNames = LabelEntry["name"] | DisabledForms<LabelEntry>;+export type RelationNames = RelationEntry["name"] | DisabledForms<RelationEntry>;++/** The names of the labels whose value is read as `U`, e.g. `FilterLabelsByType<boolean>` for flags. */+export type FilterLabelsByType<U> = LabelsWithValueType<U>["name"] | DisabledForms<LabelsWithValueType<U>>;