Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api-headless-cms): expose optional noValidate parameter #4092

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions packages/api-headless-cms/src/plugins/CmsModelPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface CmsModelFieldInput extends Omit<CmsModelFieldBase, "storageId" | "sett
* This is for backwards compatibility - before fields had storageId.
*
* This should only be populated in old model fields.
* News ones must have this empty.
* New ones must have this empty.
*/
storageId?: string;
/**
Expand All @@ -47,14 +47,13 @@ export interface CmsApiModel
"isPrivate" | "fields" | "singularApiName" | "pluralApiName" | "isPlugin"
> {
isPrivate?: never;
noValidate?: never;
noValidate?: boolean;
singularApiName?: string;
pluralApiName?: string;
fields: CmsModelFieldInput[];
}

export interface CmsApiModelFull extends Omit<CmsApiModel, "fields" | "noValidate"> {
noValidate: true;
export interface CmsApiModelFull extends Omit<CmsApiModel, "fields"> {
fields: CmsModelFieldBase[];
}

Expand All @@ -70,17 +69,17 @@ interface CmsPrivateModel
| "titleFieldId"
| "description"
> {
noValidate?: never;
noValidate?: boolean;
titleFieldId?: string;
singularApiName?: never;
pluralApiName?: never;
isPrivate: true;
fields: CmsModelFieldInput[];
}

export interface CmsPrivateModelFull extends Omit<CmsPrivateModel, "fields" | "noValidate"> {
export interface CmsPrivateModelFull
extends Omit<CmsPrivateModel, "fields" | "createdBy" | "createdOn" | "savedOn"> {
fields: CmsModelFieldBase[];
noValidate: true;
}

export type CmsModelInput = CmsApiModel | CmsPrivateModel | CmsApiModelFull | CmsPrivateModelFull;
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -341,16 +341,16 @@ export const createCmsModel = (
};

export const createPrivateModel = (
input: Omit<CmsPrivateModelFull, "group" | "isPrivate" | "noValidate">
input: Omit<CmsPrivateModelFull, "group" | "isPrivate">
): CmsPrivateModelFull => {
return {
authorization: false,
...input,
isPrivate: true,
noValidate: true,
isPrivate: true,
group: {
id: "private",
name: "Private Models"
}
},
...input
};
};
Loading