Skip to content

A platform for community discussion. Free, open, simple.

DEV: Convert admin palette, text, email and content models to TypeScript (#45207)

Sérgio Saquetimda295a991726
diff --git a/frontend/discourse/admin/models/color-scheme-color.js b/frontend/discourse/admin/models/color-scheme-color.ts
similarity index 62%
rename from frontend/discourse/admin/models/color-scheme-color.js
rename to frontend/discourse/admin/models/color-scheme-color.ts
index 72dfc14ac77..8fffba259d8 100644
--- a/frontend/discourse/admin/models/color-scheme-color.js
+++ b/frontend/discourse/admin/models/color-scheme-color.ts
@@ -7,27 +7,40 @@ import { isValidHex, normalizeHex } from "discourse/lib/color-transformations";
import { deepEqual } from "discourse/lib/object";
import { i18n } from "discourse-i18n";
+/** A palette color; custom colors without a base default send a null `default_hex`. */
+export interface ColorSchemeColorFields {
+ name: string;
+ is_advanced?: boolean;
+ originals: { hex: string };
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface ColorSchemeColor extends ColorSchemeColorFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export default class ColorSchemeColor extends EmberObject {
- @tracked hex;
+ /** Revert copies `default_hex`, so this can be null or absent too. */
+ @tracked hex: string | null | undefined;
- @tracked originalHex;
- @tracked default_hex;
+ @tracked originalHex: string | null | undefined;
+ @tracked default_hex: string | null | undefined;
// Whether the current value is different than Discourse's default color scheme.
- init(object) {
- super.init(...arguments);
+ init(object: { hex?: string | null }) {
+ // eslint-disable-next-line prefer-rest-params
+ super.init(...(arguments as unknown as [object]));
this.originalHex = object.hex;
}
@dependentKeyCompat
- get overridden() {
+ get overridden(): boolean {
return !deepEqual(this.hex, this.default_hex);
}
// Whether value has changed since it was last saved.
@computed("hex")
- get changed() {
+ get changed(): boolean {
if (!this.originals) {
return false;
}
@@ -39,7 +52,7 @@ export default class ColorSchemeColor extends EmberObject {
// Whether the saved value is different than Discourse's default color scheme.
@computed("default_hex", "hex")
- get savedIsOverriden() {
+ get savedIsOverriden(): boolean {
if (!this.default_hex) {
return false;
}
@@ -47,28 +60,24 @@ export default class ColorSchemeColor extends EmberObject {
}
@computed("name")
- get translatedName() {
+ get translatedName(): string {
return i18n(`admin.customize.colors.${this.name}.name`, {
defaultValue: this.name,
});
}
@computed("name")
- get description() {
+ get description(): string {
return i18n(`admin.customize.colors.${this.name}.description`, {
defaultValue: "",
});
}
- /**
- brightness returns a number between 0 (darkest) to 255 (brightest).
- Undefined if hex is not a valid color.
-
- @property brightness
- **/
+ /** Brightness from 0 (darkest) to 255 (brightest), or undefined when hex is not a valid color. */
@computed("hex")
- get brightness() {
- let hex = this.hex;
+ get brightness(): number | undefined {
+ // A missing hex throws here.
+ let hex = this.hex!;
if (hex.length === 6 || hex.length === 3) {
hex = normalizeHex(hex);
return Math.round(
@@ -81,16 +90,16 @@ export default class ColorSchemeColor extends EmberObject {
}
@computed("hex")
- get valid() {
+ get valid(): boolean {
return isValidHex(this.hex);
}
- discardColorChange() {
+ discardColorChange(): void {
this.hex = this.originalHex;
}
@on("init")
- startTrackingChanges() {
+ startTrackingChanges(): void {
this.set("originals", {
hex: this.hex || "FFFFFF",
});
@@ -99,18 +108,18 @@ export default class ColorSchemeColor extends EmberObject {
this.notifyPropertyChange("hex");
}
- revert() {
+ revert(): void {
this.set("hex", this.default_hex);
}
- undo() {
+ undo(): void {
if (this.originals) {
this.set("hex", this.originals.hex);
}
}
@observes("hex")
- hexValueChanged() {
+ hexValueChanged(): void {
if (this.hex) {
this.set("hex", this.hex.toString().replace(/[^0-9a-fA-F]/g, ""));
}
diff --git a/frontend/discourse/admin/models/color-scheme.js b/frontend/discourse/admin/models/color-scheme.ts
similarity index 55%
rename from frontend/discourse/admin/models/color-scheme.js
rename to frontend/discourse/admin/models/color-scheme.ts
index f756899fdb9..ebca29428f0 100644
--- a/frontend/discourse/admin/models/color-scheme.js
+++ b/frontend/discourse/admin/models/color-scheme.ts
@@ -7,17 +7,82 @@ import LegacyArrayLikeObject from "discourse/lib/legacy-array-like-object";
import { autoTrackedArray } from "discourse/lib/tracked-tools";
import { i18n } from "discourse-i18n";
-class ColorSchemes extends LegacyArrayLikeObject {
+/** A palette color as the server sends it. */
+export interface ColorSchemeColorPayload {
+ name: string;
+ hex: string;
+ default_hex: string | null;
+ is_advanced: boolean;
+}
+
+/** `/admin/color_schemes` and `/admin/config/colors/:id` record. */
+export interface ColorSchemePayload {
+ id: number;
+ name: string;
+ is_base: boolean | null;
+ base_scheme_id: number | null;
+ theme_id: number | null;
+ theme_name: string | null;
+ user_selectable: boolean;
+ is_builtin_default: boolean | null;
+ /** Null for a palette with no colors. */
+ is_dark: boolean | null;
+ colors: ColorSchemeColorPayload[];
+}
+
+/** Server metadata is optional: the manager builds id-only instances and copies omit it. */
+export interface ColorSchemeFields {
+ is_base?: boolean | null;
+ is_builtin_default?: boolean | null;
+ is_dark?: boolean | null;
+ theme_id?: number | null;
+ theme_name?: string | null;
+ base_scheme_id?: number | null;
+ can_edit?: boolean;
+ default_light_on_theme?: boolean;
+ default_dark_on_theme?: boolean;
+ saving?: boolean;
+ savingStatus?: string | null;
+ originals: { name: string | undefined; user_selectable: boolean | undefined };
+}
+
+/** `init` turns raw color records into ColorSchemeColor instances. */
+export type ColorSchemeCreateAttrs<M = ColorScheme> = Partial<
+ Omit<M, "colors">
+> & {
+ colors?: (Partial<ColorSchemeColorPayload> | ColorSchemeColor)[];
+};
+
+export interface ColorSchemeSaveOptions {
+ forceSave?: boolean;
+ saveNameOnly?: boolean;
+ enabledOnly?: boolean;
+}
+
+class ColorSchemes extends LegacyArrayLikeObject<ColorScheme> {
@tracked loading = false;
}
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface ColorScheme extends ColorSchemeFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
export default class ColorScheme extends EmberObject {
- static async findAll() {
+ declare static create: <
+ C extends abstract new (...args: never[]) => EmberObject,
+ >(
+ this: C,
+ attrs?: ColorSchemeCreateAttrs<InstanceType<C>>
+ ) => InstanceType<C>;
+
+ static async findAll(): Promise<ColorSchemes> {
const colorSchemes = ColorSchemes.create({ content: [], loading: true });
- const all = await ajax("/admin/color_schemes");
+ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.
+ const all = (await ajax("/admin/color_schemes")) as ColorSchemePayload[];
all.forEach((colorScheme) => {
- colorSchemes.push(
+ // The proxy forwards array methods to `content`.
+ (colorSchemes as unknown as ColorScheme[]).push(
ColorScheme.create({
id: colorScheme.id,
name: colorScheme.name,
@@ -34,8 +99,11 @@ export default class ColorScheme extends EmberObject {
return colorSchemes;
}
- static async find(id) {
- const json = await ajax(`/admin/config/colors/${id}`);
+ static async find(id: number | string): Promise<ColorScheme> {
+ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.
+ const json = (await ajax(
+ `/admin/config/colors/${id}`
+ )) as ColorSchemePayload;
return ColorScheme.create({
id: json.id,
name: json.name,
@@ -48,15 +116,14 @@ export default class ColorScheme extends EmberObject {
});
}
- @tracked name;
- @tracked user_selectable;
- @tracked id;
- @autoTrackedArray colors;
+ @tracked name: string | undefined;
+ @tracked user_selectable: boolean | undefined;
+ @tracked id: number | undefined;
+ @autoTrackedArray colors!: ColorSchemeColor[];
- init() {
- super.init(...arguments);
+ init(...args: Parameters<EmberObject["init"]>) {
+ super.init(...args);
- /** @type Array */
const colors = this.colors ?? [];
this.colors = colors.map((c) => {
return ColorSchemeColor.create(c);
@@ -65,17 +132,17 @@ export default class ColorScheme extends EmberObject {
}
@dependentKeyCompat
- get newRecord() {
+ get newRecord(): boolean {
return !this.id;
}
@computed
- get description() {
+ get description(): string {
return "" + this.name;
}
@computed("name", "user_selectable", "[email protected]", "saving")
- get changed() {
+ get changed(): boolean {
if (!this.originals) {
return false;
}
@@ -93,7 +160,7 @@ export default class ColorScheme extends EmberObject {
}
@computed("changed")
- get disableSave() {
+ get disableSave(): boolean {
if (this.theme_id) {
return false;
}
@@ -103,15 +170,15 @@ export default class ColorScheme extends EmberObject {
);
}
- startTrackingChanges() {
+ startTrackingChanges(): void {
this.set("originals", {
name: this.name,
user_selectable: this.user_selectable,
});
}
- schemeJson() {
- const buffer = [];
+ schemeJson(): string {
+ const buffer: string[] = [];
this.colors.forEach((c) => {
buffer.push(` "${c.get("name")}": "${c.get("hex")}"`);
});
@@ -119,7 +186,10 @@ export default class ColorScheme extends EmberObject {
return [`"${this.name}": {`, buffer.join(",\n"), "}"].join("\n");
}
- schemeObject() {
+ schemeObject(): {
+ name: string | undefined;
+ light: Record<string, string | null | undefined>;
+ } {
return {
name: this.name,
light: Object.fromEntries(
@@ -131,15 +201,14 @@ export default class ColorScheme extends EmberObject {
/**
* @returns a JSON representation of the color scheme.
*/
- dump() {
+ dump(): string {
return JSON.stringify(this.schemeObject(), null, 2);
}
- copy() {
+ copy(): ColorScheme {
const newScheme = ColorScheme.create({
name: this.name,
can_edit: true,
- /** @type Array */
colors: [],
});
this.colors.forEach((c) => {
@@ -150,14 +219,21 @@ export default class ColorScheme extends EmberObject {
return newScheme;
}
- save(opts) {
+ save(opts?: ColorSchemeSaveOptions): Promise<void> | undefined {
if (!opts?.forceSave && (this.is_base || this.disableSave)) {
return;
}
this.setProperties({ savingStatus: i18n("saving"), saving: true });
- const data = {};
+ const data: {
+ name?: string;
+ user_selectable?: boolean;
+ default_light_on_theme?: boolean;
+ default_dark_on_theme?: boolean;
+ base_scheme_id?: number | null;
+ colors?: Pick<ColorSchemeColor, "name" | "hex">[];
+ } = {};
if (!opts || !opts.enabledOnly) {
data.name = this.name;
@@ -169,7 +245,7 @@ export default class ColorScheme extends EmberObject {
data.colors = [];
this.colors.forEach((c) => {
if (!this.id || c.get("changed")) {
- data.colors.push(c.getProperties("name", "hex"));
+ data.colors!.push(c.getProperties("name", "hex"));
}
});
}
@@ -180,7 +256,7 @@ export default class ColorScheme extends EmberObject {
type: this.id ? "PUT" : "POST",
dataType: "json",
contentType: "application/json",
- }).then((result) => {
+ }).then((result: ColorSchemePayload) => {
if (result.id) {
this.set("id", result.id);
}
@@ -198,7 +274,9 @@ export default class ColorScheme extends EmberObject {
});
}
- updateUserSelectable(value) {
+ updateUserSelectable(
+ value: boolean
+ ): Promise<ColorSchemePayload> | undefined {
if (!this.id) {
return;
}
@@ -211,7 +289,10 @@ export default class ColorScheme extends EmberObject {
});
}
- updateDefaultOnTheme(field, value) {
+ updateDefaultOnTheme(
+ field: "default_light_on_theme" | "default_dark_on_theme",
+ value: boolean
+ ): Promise<ColorSchemePayload> | undefined {
if (!this.id) {
return;
}
@@ -224,8 +305,10 @@ export default class ColorScheme extends EmberObject {
});
}
- /** @returns {any} */
- destroy() {
+ /** Deletes the palette on the server, unlike EmberObject's `destroy`. */
+ destroy(this: never): never;
+ destroy(): Promise<{ success: string }> | undefined;
+ destroy(): Promise<{ success: string }> | undefined {
if (this.id) {
return ajax(`/admin/color_schemes/${this.id}`, { type: "DELETE" });
}
diff --git a/frontend/discourse/admin/models/email-preview.js b/frontend/discourse/admin/models/email-preview.js
deleted file mode 100644
index 3de69dcb077..00000000000
--- a/frontend/discourse/admin/models/email-preview.js
+++ /dev/null
@@ -1,21 +0,0 @@
-import EmberObject from "@ember/object";
-import { ajax } from "discourse/lib/ajax";
-
-export default class EmailPreview extends EmberObject {
- static findDigest(username, lastSeenAt) {
- return ajax("/admin/email/preview-digest.json", {
- data: { last_seen_at: lastSeenAt || oneWeekAgo(), username },
- }).then((result) => EmailPreview.create(result));
- }
-
- static sendDigest(username, lastSeenAt, email) {
- return ajax("/admin/email/send-digest.json", {
- type: "POST",
- data: { last_seen_at: lastSeenAt || oneWeekAgo(), username, email },
- });
- }
-}
-
-export function oneWeekAgo() {
- return moment().locale("en").subtract(7, "days").format("YYYY-MM-DD");
-}
diff --git a/frontend/discourse/admin/models/email-preview.ts b/frontend/discourse/admin/models/email-preview.ts
new file mode 100644
index 00000000000..f22064f2dd3
--- /dev/null
+++ b/frontend/discourse/admin/models/email-preview.ts
@@ -0,0 +1,41 @@
+import EmberObject from "@ember/object";
+import { ajax } from "discourse/lib/ajax";
+
+/** `/admin/email/preview-digest` response. */
+export interface EmailPreviewFields {
+ html_content: string;
+ text_content: string;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface EmailPreview extends EmailPreviewFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class EmailPreview extends EmberObject {
+ static findDigest(
+ username: string | null | undefined,
+ lastSeenAt?: string | null
+ ): Promise<EmailPreview> {
+ return ajax("/admin/email/preview-digest.json", {
+ data: { last_seen_at: lastSeenAt || oneWeekAgo(), username },
+ }).then((result: EmailPreviewFields) => EmailPreview.create(result));
+ }
+
+ static sendDigest(
+ username: string | null | undefined,
+ lastSeenAt: string | null | undefined,
+ email: string | null | undefined
+ ): Promise<{ success?: string; errors?: string | string[] | null }> {
+ return ajax("/admin/email/send-digest.json", {
+ type: "POST",
+ data: { last_seen_at: lastSeenAt || oneWeekAgo(), username, email },
+ });
+ }
+}
+
+export function oneWeekAgo(): string {
+ return moment().locale("en").subtract(7, "days").format("YYYY-MM-DD");
+}
+
+/** The application provides moment globally. */
+declare const moment: typeof import("moment");
diff --git a/frontend/discourse/admin/models/email-settings.js b/frontend/discourse/admin/models/email-settings.js
deleted file mode 100644
index 2981b0d4041..00000000000
--- a/frontend/discourse/admin/models/email-settings.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import EmberObject from "@ember/object";
-import { ajax } from "discourse/lib/ajax";
-
-export default class EmailSettings extends EmberObject {
- static find() {
- return ajax("/admin/email/server-settings.json").then(function (settings) {
- return EmailSettings.create(settings);
- });
- }
-}
diff --git a/frontend/discourse/admin/models/email-settings.ts b/frontend/discourse/admin/models/email-settings.ts
new file mode 100644
index 00000000000..5a8b67fb676
--- /dev/null
+++ b/frontend/discourse/admin/models/email-settings.ts
@@ -0,0 +1,22 @@
+import EmberObject from "@ember/object";
+import { ajax } from "discourse/lib/ajax";
+
+/** `/admin/email/server-settings`; each mail transport supplies its own setting values. */
+export interface EmailSettingsFields {
+ delivery_method: string;
+ settings: { name: string; value: unknown }[];
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface EmailSettings extends EmailSettingsFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class EmailSettings extends EmberObject {
+ static find(): Promise<EmailSettings> {
+ return ajax("/admin/email/server-settings.json").then(function (
+ settings: EmailSettingsFields
+ ) {
+ return EmailSettings.create(settings);
+ });
+ }
+}
diff --git a/frontend/discourse/admin/models/email-style.js b/frontend/discourse/admin/models/email-style.js
deleted file mode 100644
index 2824539a7a6..00000000000
--- a/frontend/discourse/admin/models/email-style.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import RestModel from "discourse/models/rest";
-
-export default class EmailStyle extends RestModel {
- changed = false;
-
- setField(fieldName, value) {
- this.set(`${fieldName}`, value);
- this.set("changed", true);
- }
-}
diff --git a/frontend/discourse/admin/models/email-style.ts b/frontend/discourse/admin/models/email-style.ts
new file mode 100644
index 00000000000..51402a8a88c
--- /dev/null
+++ b/frontend/discourse/admin/models/email-style.ts
@@ -0,0 +1,29 @@
+import RestModel from "discourse/models/rest";
+
+/** `/admin/customize/email_style` record. */
+export interface EmailStyleFields {
+ id?: string;
+ html?: string;
+ css: string;
+ default_html?: string;
+ default_css: string;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface EmailStyle extends EmailStyleFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class EmailStyle extends RestModel {
+ changed = false;
+
+ setField(fieldName: "html" | "css", value: string): void {
+ this.set(`${fieldName}`, value);
+ this.set("changed", true);
+ }
+}
+
+declare module "discourse/services/store" {
+ interface ModelRegistry {
+ "email-style": EmailStyle;
+ }
+}
diff --git a/frontend/discourse/admin/models/email-template.js b/frontend/discourse/admin/models/email-template.js
deleted file mode 100644
index 55c3ae1f06d..00000000000
--- a/frontend/discourse/admin/models/email-template.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import { getProperties } from "@ember/object";
-import { ajax } from "discourse/lib/ajax";
-import RestModel from "discourse/models/rest";
-
-export default class EmailTemplate extends RestModel {
- revert() {
- return ajax(`/admin/email/templates/${this.id}`, {
- type: "DELETE",
- }).then((result) =>
- getProperties(result.email_template, "subject", "body", "can_revert")
- );
- }
-}
diff --git a/frontend/discourse/admin/models/email-template.ts b/frontend/discourse/admin/models/email-template.ts
new file mode 100644
index 00000000000..147917178f4
--- /dev/null
+++ b/frontend/discourse/admin/models/email-template.ts
@@ -0,0 +1,33 @@
+import { getProperties } from "@ember/object";
+import { ajax } from "discourse/lib/ajax";
+import RestModel from "discourse/models/rest";
+
+/** `/admin/email/templates` record; pluralized templates send a body per plural form. */
+export interface EmailTemplateFields {
+ id: string;
+ title: string;
+ subject: string | null;
+ body: string | Record<string, string>;
+ can_revert: boolean;
+ interpolation_keys: string[];
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface EmailTemplate extends EmailTemplateFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class EmailTemplate extends RestModel {
+ revert(): Promise<Pick<EmailTemplate, "subject" | "body" | "can_revert">> {
+ return ajax(`/admin/email/templates/${this.id}`, {
+ type: "DELETE",
+ }).then((result: { email_template: EmailTemplateFields }) =>
+ getProperties(result.email_template, "subject", "body", "can_revert")
+ );
+ }
+}
+
+declare module "discourse/services/store" {
+ interface ModelRegistry {
+ "email-template": EmailTemplate;
+ }
+}
diff --git a/frontend/discourse/admin/models/embedding.js b/frontend/discourse/admin/models/embedding.js
deleted file mode 100644
index 05793a3cb5d..00000000000
--- a/frontend/discourse/admin/models/embedding.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import { autoTrackedArray } from "discourse/lib/tracked-tools";
-import RestModel from "discourse/models/rest";
-
-export default class Embedding extends RestModel {
- @autoTrackedArray embeddable_hosts;
-}
diff --git a/frontend/discourse/admin/models/embedding.ts b/frontend/discourse/admin/models/embedding.ts
new file mode 100644
index 00000000000..c69c4c85675
--- /dev/null
+++ b/frontend/discourse/admin/models/embedding.ts
@@ -0,0 +1,43 @@
+import { autoTrackedArray } from "discourse/lib/tracked-tools";
+import RestModel from "discourse/models/rest";
+
+/** An embeddable host; the store hydrates these from the embedding's `embeddable_host_ids`. */
+export interface EmbeddableHost extends RestModel {
+ id: number;
+ host: string;
+ allowed_paths: string | null;
+ class_name: string | null;
+ category_id: number;
+ user: string | null;
+ tags: { id: number; name: string; slug: string }[];
+}
+
+/** `/admin/customize/embedding` settings. */
+export interface EmbeddingFields {
+ id: string;
+ fields: string[];
+ base_url: string;
+ embed_by_username: string;
+ embed_post_limit: number;
+ embed_title_scrubber: string;
+ embed_truncate: boolean;
+ embed_unlisted: boolean;
+ allowed_embed_selectors: string;
+ blocked_embed_selectors: string;
+ allowed_embed_classnames: string;
+ embeddable_host_ids?: number[];
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface Embedding extends EmbeddingFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class Embedding extends RestModel {
+ @autoTrackedArray embeddable_hosts!: EmbeddableHost[];
+}
+
+declare module "discourse/services/store" {
+ interface ModelRegistry {
+ embedding: Embedding;
+ }
+}
diff --git a/frontend/discourse/admin/models/flag-type.js b/frontend/discourse/admin/models/flag-type.js
deleted file mode 100644
index bb2c018d521..00000000000
--- a/frontend/discourse/admin/models/flag-type.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import { computed } from "@ember/object";
-import RestModel from "discourse/models/rest";
-import { i18n } from "discourse-i18n";
-
-export default class FlagType extends RestModel {
- @computed("id")
- get name() {
- return i18n(`admin.flags.summary.action_type_${this.id}`, { count: 1 });
- }
-}
diff --git a/frontend/discourse/admin/models/flag-type.ts b/frontend/discourse/admin/models/flag-type.ts
new file mode 100644
index 00000000000..1ee3de22d2f
--- /dev/null
+++ b/frontend/discourse/admin/models/flag-type.ts
@@ -0,0 +1,18 @@
+import { computed } from "@ember/object";
+import RestModel from "discourse/models/rest";
+import { i18n } from "discourse-i18n";
+
+export interface FlagTypeFields {
+ id?: number | string;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface FlagType extends FlagTypeFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class FlagType extends RestModel {
+ @computed("id")
+ get name(): string {
+ return i18n(`admin.flags.summary.action_type_${this.id}`, { count: 1 });
+ }
+}
diff --git a/frontend/discourse/admin/models/form-template.js b/frontend/discourse/admin/models/form-template.js
deleted file mode 100644
index 6eb18a98f12..00000000000
--- a/frontend/discourse/admin/models/form-template.js
+++ /dev/null
@@ -1,49 +0,0 @@
-import { ajax } from "discourse/lib/ajax";
-import RestModel from "discourse/models/rest";
-
-export default class FormTemplate extends RestModel {
- static createTemplate(data) {
- return ajax("/admin/customize/form-templates.json", {
- type: "POST",
- data,
- });
- }
-
- static updateTemplate(id, data) {
- return ajax(`/admin/customize/form-templates/${id}.json`, {
- type: "PUT",
- data,
- });
- }
-
- static createOrUpdateTemplate(data) {
- if (data.id) {
- return this.updateTemplate(data.id, data);
- } else {
- return this.createTemplate(data);
- }
- }
-
- static deleteTemplate(id) {
- return ajax(`/admin/customize/form-templates/${id}.json`, {
- type: "DELETE",
- });
- }
-
- static async findAll() {
- const result = await ajax("/admin/customize/form-templates.json");
- return result.form_templates;
- }
-
- static async findById(id) {
- const result = await ajax(`/admin/customize/form-templates/${id}.json`);
- return result.form_template;
- }
-
- static validateTemplate(data) {
- return ajax(`/admin/customize/form-templates/preview.json`, {
- type: "GET",
- data,
- });
- }
-}
diff --git a/frontend/discourse/admin/models/form-template.ts b/frontend/discourse/admin/models/form-template.ts
new file mode 100644
index 00000000000..78b43be38ca
--- /dev/null
+++ b/frontend/discourse/admin/models/form-template.ts
@@ -0,0 +1,85 @@
+import { ajax } from "discourse/lib/ajax";
+import RestModel from "discourse/models/rest";
+
+/** `/admin/customize/form-templates` record; `template` is YAML text. */
+export interface FormTemplateFields {
+ id: number;
+ name: string;
+ template: string;
+}
+
+/** Form input; new templates have no id. */
+export interface FormTemplateInput {
+ id?: number;
+ name: string;
+ template: string;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface FormTemplate extends FormTemplateFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class FormTemplate extends RestModel {
+ static createTemplate(
+ data: FormTemplateInput
+ ): Promise<{ form_template: FormTemplateFields }> {
+ return ajax("/admin/customize/form-templates.json", {
+ type: "POST",
+ data,
+ });
+ }
+
+ static updateTemplate(
+ id: number | string,
+ data: FormTemplateInput
+ ): Promise<{ form_template: FormTemplateFields }> {
+ return ajax(`/admin/customize/form-templates/${id}.json`, {
+ type: "PUT",
+ data,
+ });
+ }
+
+ static createOrUpdateTemplate(
+ data: FormTemplateInput
+ ): Promise<{ form_template: FormTemplateFields }> {
+ if (data.id) {
+ return this.updateTemplate(data.id, data);
+ } else {
+ return this.createTemplate(data);
+ }
+ }
+
+ static deleteTemplate(id: number | string): Promise<{ success: string }> {
+ return ajax(`/admin/customize/form-templates/${id}.json`, {
+ type: "DELETE",
+ });
+ }
+
+ /** Resolves the plain records, not model instances. */
+ static async findAll(): Promise<FormTemplateFields[]> {
+ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.
+ const result = (await ajax("/admin/customize/form-templates.json")) as {
+ form_templates: FormTemplateFields[];
+ };
+ return result.form_templates;
+ }
+
+ /** Resolves the plain record, not a model instance. */
+ static async findById(id: number | string): Promise<FormTemplateFields> {
+ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.
+ const result = (await ajax(
+ `/admin/customize/form-templates/${id}.json`
+ )) as { form_template: FormTemplateFields };
+ return result.form_template;
+ }
+
+ /** Previews an unsaved template, so the echoed id can be null. */
+ static validateTemplate(data: FormTemplateInput): Promise<{
+ form_template: { id: number | null; name: string; template: string };
+ }> {
+ return ajax(`/admin/customize/form-templates/preview.json`, {
+ type: "GET",
+ data,
+ });
+ }
+}
diff --git a/frontend/discourse/admin/models/permalink.js b/frontend/discourse/admin/models/permalink.js
deleted file mode 100644
index e8b6cb751a1..00000000000
--- a/frontend/discourse/admin/models/permalink.js
+++ /dev/null
@@ -1,27 +0,0 @@
-import { computed } from "@ember/object";
-import { ajax } from "discourse/lib/ajax";
-import DiscourseURL from "discourse/lib/url";
-import Category from "discourse/models/category";
-import RestModel from "discourse/models/rest";
-
-export default class Permalink extends RestModel {
- static async findAll(filter) {
- const data = await ajax("/admin/permalinks.json", { data: { filter } });
- return data.map((p) => Permalink.create(p));
- }
-
- @computed("category_id")
- get category() {
- return Category.findById(this.category_id);
- }
-
- @computed("external_url")
- get linkIsExternal() {
- return !DiscourseURL.isInternal(this.external_url);
- }
-
- @computed("url")
- get key() {
- return this.url.replace("/", "_");
- }
-}
diff --git a/frontend/discourse/admin/models/permalink.ts b/frontend/discourse/admin/models/permalink.ts
new file mode 100644
index 00000000000..bc7401909da
--- /dev/null
+++ b/frontend/discourse/admin/models/permalink.ts
@@ -0,0 +1,63 @@
+import { computed } from "@ember/object";
+import { ajax } from "discourse/lib/ajax";
+import DiscourseURL from "discourse/lib/url";
+import Category from "discourse/models/category";
+import RestModel, { type RestPayload } from "discourse/models/rest";
+
+/** `/admin/permalinks` record; each target and its display fields are null unless it is the permalink's type. */
+export interface PermalinkFields {
+ id?: number;
+ url: string;
+ topic_id: number | null;
+ topic_title: string | null;
+ topic_url: string | null;
+ post_id: number | null;
+ post_url: string | null;
+ post_number: number | null;
+ post_topic_title: string | null;
+ category_id: number | null;
+ category_name: string | null;
+ category_url: string | null;
+ external_url: string | null;
+ tag_id: number | null;
+ tag_name: string | null;
+ tag_url: string | null;
+ user_id: number | null;
+ user_url: string | null;
+ username: string | null;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface Permalink extends PermalinkFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class Permalink extends RestModel {
+ static async findAll(filter?: string | null): Promise<Permalink[]> {
+ // TODO(typescript-pending): ajax has no response generic; remove this assertion when it does.
+ const data = (await ajax("/admin/permalinks.json", {
+ data: { filter },
+ })) as (PermalinkFields & RestPayload)[];
+ return data.map((p) => Permalink.create(p));
+ }
+
+ @computed("category_id")
+ get category(): Category | undefined {
+ return Category.findById(this.category_id);
+ }
+
+ @computed("external_url")
+ get linkIsExternal(): boolean {
+ return !DiscourseURL.isInternal(this.external_url);
+ }
+
+ @computed("url")
+ get key(): string {
+ return this.url.replace("/", "_");
+ }
+}
+
+declare module "discourse/services/store" {
+ interface ModelRegistry {
+ permalink: Permalink;
+ }
+}
diff --git a/frontend/discourse/admin/models/site-text.js b/frontend/discourse/admin/models/site-text.js
deleted file mode 100644
index b93792677f3..00000000000
--- a/frontend/discourse/admin/models/site-text.js
+++ /dev/null
@@ -1,31 +0,0 @@
-import { getProperties } from "@ember/object";
-import { ajax } from "discourse/lib/ajax";
-import RestModel from "discourse/models/rest";
-
-export default class SiteText extends RestModel {
- revert(locale) {
- return ajax(`/admin/customize/site_texts/${this.id}?locale=${locale}`, {
- type: "DELETE",
- }).then((result) =>
- getProperties(
- result.site_text,
- "value",
- "can_revert",
- "overridden",
- "status",
- "old_default",
- "new_default",
- "interpolation_keys"
- )
- );
- }
-
- dismissOutdated(locale) {
- return ajax(
- `/admin/customize/site_texts/${this.id}/dismiss_outdated?locale=${locale}`,
- {
- type: "PUT",
- }
- );
- }
-}
diff --git a/frontend/discourse/admin/models/site-text.ts b/frontend/discourse/admin/models/site-text.ts
new file mode 100644
index 00000000000..422fe792e04
--- /dev/null
+++ b/frontend/discourse/admin/models/site-text.ts
@@ -0,0 +1,70 @@
+import { getProperties } from "@ember/object";
+import { ajax } from "discourse/lib/ajax";
+import RestModel from "discourse/models/rest";
+
+/** `/admin/customize/site_texts` record, keyed by its translation key. */
+export interface SiteTextFields {
+ id: string;
+ value: string;
+ status:
+ | "up_to_date"
+ | "outdated"
+ | "invalid_interpolation_keys"
+ | "deprecated";
+ old_default: string | null;
+ new_default: string | null;
+ interpolation_keys: string[];
+ overridden: boolean;
+ can_revert: boolean;
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface SiteText extends SiteTextFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class SiteText extends RestModel {
+ revert(
+ locale: string
+ ): Promise<
+ Pick<
+ SiteText,
+ | "value"
+ | "can_revert"
+ | "overridden"
+ | "status"
+ | "old_default"
+ | "new_default"
+ | "interpolation_keys"
+ >
+ > {
+ return ajax(`/admin/customize/site_texts/${this.id}?locale=${locale}`, {
+ type: "DELETE",
+ }).then((result: { site_text: SiteTextFields }) =>
+ getProperties(
+ result.site_text,
+ "value",
+ "can_revert",
+ "overridden",
+ "status",
+ "old_default",
+ "new_default",
+ "interpolation_keys"
+ )
+ );
+ }
+
+ dismissOutdated(locale: string): Promise<{ success: string }> {
+ return ajax(
+ `/admin/customize/site_texts/${this.id}/dismiss_outdated?locale=${locale}`,
+ {
+ type: "PUT",
+ }
+ );
+ }
+}
+
+declare module "discourse/services/store" {
+ interface ModelRegistry {
+ "site-text": SiteText;
+ }
+}
diff --git a/frontend/discourse/admin/models/user-field.js b/frontend/discourse/admin/models/user-field.js
deleted file mode 100644
index 0704bd73be1..00000000000
--- a/frontend/discourse/admin/models/user-field.js
+++ /dev/null
@@ -1,46 +0,0 @@
-import { tracked } from "@glimmer/tracking";
-import EmberObject from "@ember/object";
-import { dependentKeyCompat } from "@ember/object/compat";
-import RestModel from "discourse/models/rest";
-import { i18n } from "discourse-i18n";
-
-export default class UserField extends RestModel {
- static fieldTypes() {
- if (!this._fieldTypes) {
- this._fieldTypes = [
- UserFieldType.create({ id: "text" }),
- UserFieldType.create({ id: "textarea" }),
- UserFieldType.create({ id: "date" }),
- UserFieldType.create({ id: "confirm" }),
- UserFieldType.create({ id: "dropdown", hasOptions: true }),
- UserFieldType.create({ id: "multiselect", hasOptions: true }),
- ];
- }
-
- return this._fieldTypes;
- }
-
- static fieldTypeById(id) {
- return this.fieldTypes().find((value) => value.id === id);
- }
-
- @tracked field_type;
- @tracked editable;
- @tracked show_on_profile;
- @tracked show_on_user_card;
- @tracked searchable;
- @tracked requirement;
-
- get fieldTypeName() {
- return UserField.fieldTypes().find((ft) => ft.id === this.field_type).name;
- }
-}
-
-class UserFieldType extends EmberObject {
- @tracked id;
-
- @dependentKeyCompat
- get name() {
- return i18n(`admin.user_fields.field_types.${this.id}`);
- }
-}
diff --git a/frontend/discourse/admin/models/user-field.ts b/frontend/discourse/admin/models/user-field.ts
new file mode 100644
index 00000000000..c6362d2a58a
--- /dev/null
+++ b/frontend/discourse/admin/models/user-field.ts
@@ -0,0 +1,80 @@
+import { tracked } from "@glimmer/tracking";
+import EmberObject from "@ember/object";
+import { dependentKeyCompat } from "@ember/object/compat";
+import RestModel from "discourse/models/rest";
+import { i18n } from "discourse-i18n";
+
+export type UserFieldKind =
+ | "text"
+ | "textarea"
+ | "date"
+ | "confirm"
+ | "dropdown"
+ | "multiselect";
+
+/** `/admin/config/user_fields` record; new records start with only the route defaults. */
+export interface UserFieldFields {
+ id?: number;
+ name?: string;
+ description?: string;
+ required?: boolean;
+ show_on_signup: boolean;
+ position?: number | null;
+ /** Only option-bearing field types send options. */
+ options?: string[];
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging
+export default interface UserField extends UserFieldFields {}
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
+export default class UserField extends RestModel {
+ static fieldTypes(): UserFieldType[] {
+ if (!this._fieldTypes) {
+ this._fieldTypes = [
+ UserFieldType.create({ id: "text" }),
+ UserFieldType.create({ id: "textarea" }),
+ UserFieldType.create({ id: "date" }),
+ UserFieldType.create({ id: "confirm" }),
+ UserFieldType.create({ id: "dropdown", hasOptions: true }),
+ UserFieldType.create({ id: "multiselect", hasOptions: true }),
+ ];
+ }
+
+ return this._fieldTypes;
+ }
+
+ static fieldTypeById(id: string | undefined): UserFieldType | undefined {
+ return this.fieldTypes().find((value) => value.id === id);
+ }
+
+ @tracked field_type!: UserFieldKind;
+
+ @tracked editable: boolean | undefined;
+ @tracked show_on_profile: boolean | undefined;
+ @tracked show_on_user_card: boolean | undefined;
+ @tracked searchable: boolean | undefined;
+ @tracked requirement!: "optional" | "for_all_users" | "on_signup";
+ declare static _fieldTypes?: UserFieldType[];
+
+ get fieldTypeName(): string {
+ return UserField.fieldTypes().find((ft) => ft.id === this.field_type)!.name;
+ }
+}
+
+class UserFieldType extends EmberObject {
+ @tracked id!: UserFieldKind;
+
+ declare hasOptions?: boolean;
+
+ @dependentKeyCompat
+ get name(): string {
+ return i18n(`admin.user_fields.field_types.${this.id}`);
+ }
+}
+
+declare module "discourse/services/store" {
+ interface ModelRegistry {
+ "user-field": UserField;
+ }
+}
diff --git a/frontend/discourse/type-tests/models/admin-content-test.ts b/frontend/discourse/type-tests/models/admin-content-test.ts
new file mode 100644
index 00000000000..bba59b12596
--- /dev/null
+++ b/frontend/discourse/type-tests/models/admin-content-test.ts
@@ -0,0 +1,563 @@
+import type EmberObject from "@ember/object";
+import { expectTypeOf } from "expect-type";
+import ColorScheme from "discourse/admin/models/color-scheme";
+import ColorSchemeColor from "discourse/admin/models/color-scheme-color";
+import EmailPreview, { oneWeekAgo } from "discourse/admin/models/email-preview";
+import EmailSettings from "discourse/admin/models/email-settings";
+import EmailStyle from "discourse/admin/models/email-style";
+import EmailTemplate from "discourse/admin/models/email-template";
+import Embedding from "discourse/admin/models/embedding";
+import FlagType from "discourse/admin/models/flag-type";
+import FormTemplate from "discourse/admin/models/form-template";
+import Permalink from "discourse/admin/models/permalink";
+import SiteText from "discourse/admin/models/site-text";
+import UserField from "discourse/admin/models/user-field";
+import type LegacyArrayLikeObject from "discourse/lib/legacy-array-like-object";
+import type Category from "discourse/models/category";
+import type RestModel from "discourse/models/rest";
+import type {
+ default as StoreService,
+ ModelFor,
+ ResultSetOf,
+} from "discourse/services/store";
+
+type FieldKind =
+ | "text"
+ | "textarea"
+ | "date"
+ | "confirm"
+ | "dropdown"
+ | "multiselect";
+type TextStatus =
+ | "up_to_date"
+ | "outdated"
+ | "invalid_interpolation_keys"
+ | "deprecated";
+type TemplateData = { id: number; name: string; template: string };
+type PaletteData = {
+ id: number;
+ name: string;
+ is_base: boolean | null;
+ base_scheme_id: number | null;
+ theme_id: number | null;
+ theme_name: string | null;
+ user_selectable: boolean;
+ is_builtin_default: boolean | null;
+ is_dark: boolean | null;
+ colors: {
+ name: string;
+ hex: string;
+ default_hex: string | null;
+ is_advanced: boolean;
+ }[];
+};
+
+declare const store: StoreService;
+
+expectTypeOf<ModelFor<"site-text">>().toEqualTypeOf<SiteText>();
+expectTypeOf<ModelFor<"email-style">>().toEqualTypeOf<EmailStyle>();
+expectTypeOf<ModelFor<"email-template">>().toEqualTypeOf<EmailTemplate>();
+expectTypeOf<ModelFor<"embedding">>().toEqualTypeOf<Embedding>();
+expectTypeOf<ModelFor<"permalink">>().toEqualTypeOf<Permalink>();
+expectTypeOf<ModelFor<"user-field">>().toEqualTypeOf<UserField>();
+expectTypeOf(store.find("email-style")).resolves.toEqualTypeOf<EmailStyle>();
+expectTypeOf(store.find("embedding")).resolves.toEqualTypeOf<Embedding>();
+expectTypeOf(
+ store.find("permalink", "112")
+).resolves.toEqualTypeOf<Permalink>();
+expectTypeOf(
+ store.find("user-field", "252")
+).resolves.toEqualTypeOf<UserField>();
+expectTypeOf(store.findAll("email-template")).resolves.toEqualTypeOf<
+ ResultSetOf<EmailTemplate> | undefined
+>();
+expectTypeOf(store.findAll("user-field")).resolves.toEqualTypeOf<
+ ResultSetOf<UserField> | undefined
+>();
+store.find("site-text", {
+ q: "title",
+ locale: "en",
+ overridden: true,
+ page: 0,
+});
+
+declare const scheme: ColorScheme;
+declare const schemes: Awaited<ReturnType<typeof ColorScheme.findAll>>;
+declare const color: ColorSchemeColor;
+
+expectTypeOf<Omit<ColorScheme, "destroy">>().toExtend<
+ Omit<EmberObject, "destroy">
+>();
+expectTypeOf(scheme).not.toExtend<RestModel>();
+expectTypeOf(schemes).toExtend<LegacyArrayLikeObject<ColorScheme>>();
+expectTypeOf(schemes.content).toEqualTypeOf<ColorScheme[]>();
+expectTypeOf(schemes.loading).toEqualTypeOf<boolean>();
+ColorScheme.findAll();
+schemes.loading = false;
+schemes.content.push(scheme);
+expectTypeOf(ColorScheme.find(860)).resolves.toEqualTypeOf<ColorScheme>();
+ColorScheme.find("860");
+
+ColorScheme.create({
+ id: 860,
+ name: "Captured palette",
+ is_base: null,
+ base_scheme_id: null,
+ theme_id: null,
+ theme_name: null,
+ user_selectable: true,
+ is_builtin_default: null,
+ is_dark: false,
+ colors: [
+ { name: "primary", hex: "222", default_hex: "222", is_advanced: false },
+ ],
+});
+// The manager constructs an id-only instance; copies omit server metadata.
+ColorScheme.create({ id: 860 });
+ColorScheme.create({ name: "Copy", can_edit: true, colors: [] });
+expectTypeOf(scheme.id).toEqualTypeOf<number | undefined>();
+expectTypeOf(scheme.name).toEqualTypeOf<string | undefined>();
+expectTypeOf(scheme.user_selectable).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(scheme.is_base).toEqualTypeOf<boolean | null | undefined>();
+expectTypeOf(scheme.is_builtin_default).toEqualTypeOf<
+ boolean | null | undefined
+>();
+expectTypeOf(scheme.is_dark).toEqualTypeOf<boolean | null | undefined>();
+expectTypeOf(scheme.theme_id).toEqualTypeOf<number | null | undefined>();
+expectTypeOf(scheme.theme_name).toEqualTypeOf<string | null | undefined>();
+expectTypeOf(scheme.base_scheme_id).toEqualTypeOf<number | null | undefined>();
+expectTypeOf(scheme.can_edit).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(scheme.default_light_on_theme).toEqualTypeOf<
+ boolean | undefined
+>();
+expectTypeOf(scheme.default_dark_on_theme).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(scheme.saving).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(scheme.savingStatus).toEqualTypeOf<string | null | undefined>();
+expectTypeOf(scheme.originals).toEqualTypeOf<{
+ name: string | undefined;
+ user_selectable: boolean | undefined;
+}>();
+expectTypeOf(scheme.colors).toEqualTypeOf<ColorSchemeColor[]>();
+scheme.colors = [color];
+scheme.name = "Renamed";
+scheme.base_scheme_id = null;
+scheme.default_light_on_theme = true;
+scheme.default_dark_on_theme = false;
+scheme.savingStatus = null;
+expectTypeOf(scheme.newRecord).toEqualTypeOf<boolean>();
+expectTypeOf(scheme.description).toEqualTypeOf<string>();
+expectTypeOf(scheme.changed).toEqualTypeOf<boolean>();
+expectTypeOf(scheme.disableSave).toEqualTypeOf<boolean>();
+expectTypeOf(scheme.startTrackingChanges()).toEqualTypeOf<void>();
+expectTypeOf(scheme.schemeJson()).toEqualTypeOf<string>();
+expectTypeOf(scheme.schemeObject()).toEqualTypeOf<{
+ name: string | undefined;
+ light: Record<string, string | null | undefined>;
+}>();
+expectTypeOf(scheme.dump()).toEqualTypeOf<string>();
+expectTypeOf(scheme.copy()).toEqualTypeOf<ColorScheme>();
+expectTypeOf(scheme.save()).toEqualTypeOf<Promise<void> | undefined>();
+scheme.save({ forceSave: true });
+scheme.save({ saveNameOnly: true, forceSave: true });
+scheme.save({ enabledOnly: true });
+expectTypeOf(scheme.updateUserSelectable(true)).toEqualTypeOf<
+ Promise<PaletteData> | undefined
+>();
+expectTypeOf(
+ scheme.updateDefaultOnTheme("default_light_on_theme", true)
+).toEqualTypeOf<Promise<PaletteData> | undefined>();
+scheme.updateDefaultOnTheme("default_dark_on_theme", false);
+expectTypeOf(scheme.destroy()).toEqualTypeOf<
+ Promise<{ success: string }> | undefined
+>();
+
+expectTypeOf(color).toExtend<EmberObject>();
+expectTypeOf(color).not.toExtend<RestModel>();
+ColorSchemeColor.create({ name: "primary", hex: "222" });
+ColorSchemeColor.create({
+ name: "custom",
+ hex: "abcdef",
+ default_hex: null,
+ is_advanced: true,
+});
+expectTypeOf(color.name).toEqualTypeOf<string>();
+// Revert copies default_hex, which can be absent or null, into hex.
+expectTypeOf(color.hex).toEqualTypeOf<string | null | undefined>();
+expectTypeOf(color.originalHex).toEqualTypeOf<string | null | undefined>();
+expectTypeOf(color.default_hex).toEqualTypeOf<string | null | undefined>();
+expectTypeOf(color.is_advanced).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(color.originals).toEqualTypeOf<{ hex: string }>();
+expectTypeOf(color.overridden).toEqualTypeOf<boolean>();
+expectTypeOf(color.changed).toEqualTypeOf<boolean>();
+expectTypeOf(color.savedIsOverriden).toEqualTypeOf<boolean>();
+expectTypeOf(color.translatedName).toEqualTypeOf<string>();
+expectTypeOf(color.description).toEqualTypeOf<string>();
+expectTypeOf(color.brightness).toEqualTypeOf<number | undefined>();
+expectTypeOf(color.valid).toEqualTypeOf<boolean>();
+expectTypeOf(color.startTrackingChanges()).toEqualTypeOf<void>();
+expectTypeOf(color.discardColorChange()).toEqualTypeOf<void>();
+expectTypeOf(color.revert()).toEqualTypeOf<void>();
+expectTypeOf(color.undo()).toEqualTypeOf<void>();
+expectTypeOf(color.hexValueChanged()).toEqualTypeOf<void>();
+color.hex = "abcdef";
+color.default_hex = "222";
+
+declare const siteText: SiteText;
+expectTypeOf(siteText).toExtend<RestModel>();
+store.createRecord("site-text", {
+ id: "js.composer.reply",
+ value: "Reply",
+ status: "up_to_date",
+ old_default: null,
+ new_default: null,
+ interpolation_keys: [],
+ overridden: false,
+ can_revert: false,
+});
+expectTypeOf(siteText.id).toEqualTypeOf<string>();
+expectTypeOf(siteText.value).toEqualTypeOf<string>();
+expectTypeOf(siteText.status).toEqualTypeOf<TextStatus>();
+expectTypeOf(siteText.old_default).toEqualTypeOf<string | null>();
+expectTypeOf(siteText.new_default).toEqualTypeOf<string | null>();
+expectTypeOf(siteText.interpolation_keys).toEqualTypeOf<string[]>();
+expectTypeOf(siteText.overridden).toEqualTypeOf<boolean>();
+expectTypeOf(siteText.can_revert).toEqualTypeOf<boolean>();
+expectTypeOf(siteText.revert("en")).resolves.toEqualTypeOf<
+ Pick<
+ SiteText,
+ | "value"
+ | "can_revert"
+ | "overridden"
+ | "status"
+ | "old_default"
+ | "new_default"
+ | "interpolation_keys"
+ >
+>();
+expectTypeOf(siteText.dismissOutdated("en")).resolves.toEqualTypeOf<{
+ success: string;
+}>();
+siteText.save({ value: "Answer", locale: "en" });
+siteText.status = "outdated";
+
+declare const style: EmailStyle;
+expectTypeOf(style).toExtend<RestModel>();
+EmailStyle.create({ css: "body {}", default_css: "" });
+EmailStyle.create({
+ id: "email-style",
+ html: "%{email_content}",
+ css: "",
+ default_html: "%{email_content}",
+ default_css: "",
+});
+expectTypeOf(style.id).toEqualTypeOf<string | undefined>();
+expectTypeOf(style.html).toEqualTypeOf<string | undefined>();
+expectTypeOf(style.default_html).toEqualTypeOf<string | undefined>();
+expectTypeOf(style.css).toEqualTypeOf<string>();
+expectTypeOf(style.default_css).toEqualTypeOf<string>();
+expectTypeOf(style.changed).toEqualTypeOf<boolean>();
+expectTypeOf(style.setField("css", "body {}")).toEqualTypeOf<void>();
+style.setField("html", "%{email_content}");
+style.save({ html: "%{email_content}", css: "" });
+
+declare const emailTemplate: EmailTemplate;
+expectTypeOf(emailTemplate).toExtend<RestModel>();
+EmailTemplate.create({
+ id: "system_messages.user_posts_deleted",
+ title: "User Posts Deleted",
+ subject: "All posts deleted",
+ body: { one: "%{count} post", other: "%{count} posts" },
+ can_revert: false,
+ interpolation_keys: ["user"],
+});
+EmailTemplate.create({ id: "invite_mailer", subject: null, body: "Hello" });
+expectTypeOf(emailTemplate.id).toEqualTypeOf<string>();
+expectTypeOf(emailTemplate.title).toEqualTypeOf<string>();
+expectTypeOf(emailTemplate.subject).toEqualTypeOf<string | null>();
+expectTypeOf(emailTemplate.body).toEqualTypeOf<
+ string | Record<string, string>
+>();
+expectTypeOf(emailTemplate.can_revert).toEqualTypeOf<boolean>();
+expectTypeOf(emailTemplate.interpolation_keys).toEqualTypeOf<string[]>();
+expectTypeOf(emailTemplate.revert()).resolves.toEqualTypeOf<
+ Pick<EmailTemplate, "subject" | "body" | "can_revert">
+>();
+emailTemplate.save({ subject: null, body: "Updated" });
+
+declare const preview: EmailPreview;
+expectTypeOf(preview).toExtend<EmberObject>();
+expectTypeOf(preview).not.toExtend<RestModel>();
+EmailPreview.create({ html_content: "<p>Hello</p>", text_content: "Hello" });
+expectTypeOf(preview.html_content).toEqualTypeOf<string>();
+expectTypeOf(preview.text_content).toEqualTypeOf<string>();
+expectTypeOf(oneWeekAgo()).toEqualTypeOf<string>();
+expectTypeOf(
+ EmailPreview.findDigest("anne")
+).resolves.toEqualTypeOf<EmailPreview>();
+EmailPreview.findDigest("anne", null);
+EmailPreview.findDigest("anne", "2026-10-20");
+expectTypeOf(
+ EmailPreview.sendDigest("anne", "2026-10-20", "[email protected]")
+).resolves.toExtend<{ success?: string; errors?: string | string[] | null }>();
+expectTypeOf(
+ EmailPreview.sendDigest("anne", null, "[email protected]")
+).resolves.not.toBeAny();
+EmailPreview.sendDigest(null, null, null);
+EmailPreview.sendDigest(undefined, null, "[email protected]");
+
+declare const emailSettings: EmailSettings;
+expectTypeOf(emailSettings).toExtend<EmberObject>();
+expectTypeOf(emailSettings).not.toExtend<RestModel>();
+expectTypeOf(EmailSettings.find()).resolves.toEqualTypeOf<EmailSettings>();
+EmailSettings.create({ delivery_method: "test", settings: [] });
+expectTypeOf(emailSettings.delivery_method).toEqualTypeOf<string>();
+// Mail transports supply their own settings values; the capture has no rows.
+expectTypeOf(emailSettings.settings).toEqualTypeOf<
+ { name: string; value: unknown }[]
+>();
+
+declare const embedding: Embedding;
+expectTypeOf(embedding).toExtend<RestModel>();
+Embedding.create({
+ id: "default",
+ fields: ["embed_by_username", "embed_post_limit"],
+ base_url: "http://test.localhost",
+ embed_by_username: "",
+ embed_post_limit: 100,
+ embed_title_scrubber: "",
+ embed_truncate: true,
+ embed_unlisted: false,
+ allowed_embed_selectors: "",
+ blocked_embed_selectors: "",
+ allowed_embed_classnames: "emoji",
+ embeddable_host_ids: [51],
+});
+expectTypeOf(embedding.id).toEqualTypeOf<string>();
+expectTypeOf(embedding.fields).toEqualTypeOf<string[]>();
+expectTypeOf(embedding.base_url).toEqualTypeOf<string>();
+expectTypeOf(embedding.embed_by_username).toEqualTypeOf<string>();
+expectTypeOf(embedding.embed_post_limit).toEqualTypeOf<number>();
+expectTypeOf(embedding.embed_title_scrubber).toEqualTypeOf<string>();
+expectTypeOf(embedding.embed_truncate).toEqualTypeOf<boolean>();
+expectTypeOf(embedding.embed_unlisted).toEqualTypeOf<boolean>();
+expectTypeOf(embedding.allowed_embed_selectors).toEqualTypeOf<string>();
+expectTypeOf(embedding.blocked_embed_selectors).toEqualTypeOf<string>();
+expectTypeOf(embedding.allowed_embed_classnames).toEqualTypeOf<string>();
+expectTypeOf(embedding.embeddable_host_ids).toEqualTypeOf<
+ number[] | undefined
+>();
+expectTypeOf(embedding.embeddable_hosts).not.toBeAny();
+expectTypeOf(embedding.embeddable_hosts[0]).toExtend<RestModel>();
+expectTypeOf(embedding.embeddable_hosts[0].id).toEqualTypeOf<number>();
+expectTypeOf(embedding.embeddable_hosts[0].host).toEqualTypeOf<string>();
+expectTypeOf(embedding.embeddable_hosts[0].allowed_paths).toEqualTypeOf<
+ string | null
+>();
+expectTypeOf(embedding.embeddable_hosts[0].class_name).toEqualTypeOf<
+ string | null
+>();
+expectTypeOf(embedding.embeddable_hosts[0].category_id).toEqualTypeOf<number>();
+expectTypeOf(embedding.embeddable_hosts[0].user).toEqualTypeOf<string | null>();
+expectTypeOf(embedding.embeddable_hosts[0].tags).toEqualTypeOf<
+ { id: number; name: string; slug: string }[]
+>();
+embedding.embeddable_hosts = [];
+embedding.embeddable_hosts.push(embedding.embeddable_hosts[0]);
+embedding.embeddable_hosts[0].save({
+ host: "example.com",
+ tags: [1],
+ user: "anne",
+});
+embedding.update({
+ type: "posts_and_topics",
+ embed_by_username: "anne",
+ embed_post_limit: 100,
+ embed_title_scrubber: "",
+ embed_truncate: true,
+ embed_unlisted: false,
+});
+embedding.update({
+ type: "crawlers",
+ allowed_embed_selectors: "article",
+ blocked_embed_selectors: "nav",
+ allowed_embed_classnames: "emoji",
+});
+
+declare const permalink: Permalink;
+expectTypeOf(permalink).toExtend<RestModel>();
+Permalink.create({
+ id: 113,
+ url: "ext",
+ topic_id: null,
+ topic_title: null,
+ topic_url: null,
+ post_id: null,
+ post_url: null,
+ post_number: null,
+ post_topic_title: null,
+ category_id: null,
+ category_name: null,
+ category_url: null,
+ external_url: "https://example.com",
+ tag_id: null,
+ tag_name: null,
+ tag_url: null,
+ user_id: null,
+ user_url: null,
+ username: null,
+});
+expectTypeOf(permalink.id).toEqualTypeOf<number | undefined>();
+expectTypeOf(permalink.url).toEqualTypeOf<string>();
+expectTypeOf(permalink.topic_id).toEqualTypeOf<number | null>();
+expectTypeOf(permalink.post_id).toEqualTypeOf<number | null>();
+expectTypeOf(permalink.category_id).toEqualTypeOf<number | null>();
+expectTypeOf(permalink.tag_id).toEqualTypeOf<number | null>();
+expectTypeOf(permalink.user_id).toEqualTypeOf<number | null>();
+expectTypeOf(permalink.post_number).toEqualTypeOf<number | null>();
+expectTypeOf(permalink.topic_title).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.topic_url).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.post_url).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.post_topic_title).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.category_name).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.category_url).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.external_url).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.tag_name).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.tag_url).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.user_url).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.username).toEqualTypeOf<string | null>();
+expectTypeOf(permalink.category).toEqualTypeOf<Category | undefined>();
+expectTypeOf(permalink.linkIsExternal).toEqualTypeOf<boolean>();
+expectTypeOf(permalink.key).toEqualTypeOf<string>();
+expectTypeOf(Permalink.findAll()).resolves.toEqualTypeOf<Permalink[]>();
+Permalink.findAll(null);
+Permalink.findAll("old/path");
+store.createRecord("permalink").save({
+ url: "old/path",
+ permalink_type: "topic",
+ permalink_type_value: "22928",
+});
+store.createRecord("permalink").save({
+ url: "ext",
+ permalink_type: "external_url",
+ permalink_type_value: "https://example.com",
+});
+
+declare const template: FormTemplate;
+expectTypeOf(template).toExtend<RestModel>();
+FormTemplate.create({ id: 84, name: "Bug report", template: "- type: input" });
+expectTypeOf(template.id).toEqualTypeOf<number>();
+expectTypeOf(template.name).toEqualTypeOf<string>();
+expectTypeOf(template.template).toEqualTypeOf<string>();
+expectTypeOf(FormTemplate.findAll()).resolves.toEqualTypeOf<TemplateData[]>();
+expectTypeOf(
+ FormTemplate.findById("84")
+).resolves.toEqualTypeOf<TemplateData>();
+FormTemplate.findById(84);
+expectTypeOf(FormTemplate.findById(84)).resolves.not.toExtend<RestModel>();
+expectTypeOf(
+ FormTemplate.createTemplate({ name: "Bug report", template: "- type: input" })
+).resolves.toEqualTypeOf<{ form_template: TemplateData }>();
+expectTypeOf(
+ FormTemplate.updateTemplate(84, {
+ name: "Bug report",
+ template: "- type: input",
+ })
+).resolves.toEqualTypeOf<{ form_template: TemplateData }>();
+FormTemplate.updateTemplate("84", {
+ name: "Bug report",
+ template: "- type: input",
+});
+expectTypeOf(
+ FormTemplate.createOrUpdateTemplate({
+ name: "Bug report",
+ template: "- type: input",
+ })
+).resolves.toEqualTypeOf<{ form_template: TemplateData }>();
+FormTemplate.createOrUpdateTemplate({
+ id: 84,
+ name: "Bug report",
+ template: "- type: input",
+});
+expectTypeOf(
+ FormTemplate.validateTemplate({
+ id: 84,
+ name: "Bug report",
+ template: "- type: input",
+ })
+).resolves.toEqualTypeOf<{
+ form_template: { id: number | null; name: string; template: string };
+}>();
+FormTemplate.validateTemplate({
+ name: "Bug report",
+ template: "- type: input",
+});
+expectTypeOf(FormTemplate.deleteTemplate(84)).resolves.toEqualTypeOf<{
+ success: string;
+}>();
+FormTemplate.deleteTemplate("84");
+// @ts-expect-error Preview requires YAML text, not a parsed array.
+FormTemplate.validateTemplate({ name: "Bug report", template: [] });
+
+declare const flagType: FlagType;
+expectTypeOf(flagType).toExtend<RestModel>();
+// No active loader supplies a narrower id contract for this legacy model.
+expectTypeOf(flagType.id).toEqualTypeOf<number | string | undefined>();
+expectTypeOf(flagType.name).toEqualTypeOf<string>();
+FlagType.create({ id: 3 });
+
+declare const userField: UserField;
+declare const fieldType: ReturnType<typeof UserField.fieldTypes>[number];
+expectTypeOf(userField).toExtend<RestModel>();
+store.createRecord("user-field", {
+ field_type: "text",
+ requirement: "optional",
+ show_on_signup: true,
+});
+UserField.create({
+ id: 252,
+ name: "Favourite colour",
+ description: "user field description",
+ field_type: "dropdown",
+ editable: true,
+ required: true,
+ requirement: "on_signup",
+ show_on_profile: false,
+ show_on_user_card: false,
+ show_on_signup: true,
+ searchable: false,
+ position: 0,
+ options: ["Red"],
+});
+expectTypeOf(userField.id).toEqualTypeOf<number | undefined>();
+expectTypeOf(userField.name).toEqualTypeOf<string | undefined>();
+expectTypeOf(userField.description).toEqualTypeOf<string | undefined>();
+expectTypeOf(userField.field_type).toEqualTypeOf<FieldKind>();
+expectTypeOf(userField.requirement).toEqualTypeOf<
+ "optional" | "for_all_users" | "on_signup"
+>();
+expectTypeOf(userField.editable).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(userField.required).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(userField.show_on_profile).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(userField.show_on_user_card).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(userField.show_on_signup).toEqualTypeOf<boolean>();
+expectTypeOf(userField.searchable).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(userField.position).toEqualTypeOf<number | null | undefined>();
+expectTypeOf(userField.options).toEqualTypeOf<string[] | undefined>();
+expectTypeOf(userField.fieldTypeName).toEqualTypeOf<string>();
+expectTypeOf(fieldType).toExtend<EmberObject>();
+expectTypeOf(fieldType).not.toExtend<RestModel>();
+expectTypeOf(fieldType.id).toEqualTypeOf<FieldKind>();
+expectTypeOf(fieldType.name).toEqualTypeOf<string>();
+expectTypeOf(fieldType.hasOptions).toEqualTypeOf<boolean | undefined>();
+expectTypeOf(UserField.fieldTypes()).toEqualTypeOf<(typeof fieldType)[]>();
+expectTypeOf(UserField.fieldTypeById("dropdown")).toEqualTypeOf<
+ typeof fieldType | undefined
+>();
+UserField.fieldTypeById("unknown");
+UserField.fieldTypeById(undefined);
+userField.field_type = "multiselect";
+userField.requirement = "for_all_users";
+userField.options = ["Red", "Blue"];
+userField.save({ field_type: "dropdown", options: ["Red"], editable: true });
+// @ts-expect-error The serializer sends option labels, not numeric ids.
+userField.options = [1];