From 8c357bea1ee6666a3ab066a264ebe51c2ba217d8 Mon Sep 17 00:00:00 2001 From: Pavel Denisjuk Date: Mon, 22 Apr 2024 13:01:51 +0200 Subject: [PATCH] fix(api-headless-cms): expose optional noValidate parameter on all model types --- .../src/plugins/CmsModelPlugin.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/api-headless-cms/src/plugins/CmsModelPlugin.ts b/packages/api-headless-cms/src/plugins/CmsModelPlugin.ts index ec46c94c9fc..63100ac9c60 100644 --- a/packages/api-headless-cms/src/plugins/CmsModelPlugin.ts +++ b/packages/api-headless-cms/src/plugins/CmsModelPlugin.ts @@ -32,7 +32,7 @@ interface CmsModelFieldInput extends Omit { isPrivate?: never; - noValidate?: never; + noValidate?: boolean; singularApiName?: string; pluralApiName?: string; fields: CmsModelFieldInput[]; } -export interface CmsApiModelFull extends Omit { - noValidate: true; +export interface CmsApiModelFull extends Omit { fields: CmsModelFieldBase[]; } @@ -70,7 +69,7 @@ interface CmsPrivateModel | "titleFieldId" | "description" > { - noValidate?: never; + noValidate?: boolean; titleFieldId?: string; singularApiName?: never; pluralApiName?: never; @@ -78,9 +77,9 @@ interface CmsPrivateModel fields: CmsModelFieldInput[]; } -export interface CmsPrivateModelFull extends Omit { +export interface CmsPrivateModelFull + extends Omit { fields: CmsModelFieldBase[]; - noValidate: true; } export type CmsModelInput = CmsApiModel | CmsPrivateModel | CmsApiModelFull | CmsPrivateModelFull; @@ -139,12 +138,13 @@ export class CmsModelPlugin extends Plugin { /** * We can safely ignore this error, because we are sure noValidate is not a model field. */ - // @ts-expect-error delete input["noValidate"]; return { ...modelPlugin, ...input, + // Since `noValidate` is set, we trust the input, and cast to `CmsModelFieldBase`. + fields: input.fields as CmsModelFieldBase[], pluralApiName, singularApiName }; @@ -341,16 +341,16 @@ export const createCmsModel = ( }; export const createPrivateModel = ( - input: Omit + input: Omit ): CmsPrivateModelFull => { return { authorization: false, - ...input, - isPrivate: true, noValidate: true, + isPrivate: true, group: { id: "private", name: "Private Models" - } + }, + ...input }; };