Skip to content

Commit

Permalink
Remove default schemas (#1541)
Browse files Browse the repository at this point in the history
* refactor(HasStrapiTimestampsSchema): delete schema

* refactor(HasOptionalStrapiIdSchema): delete schema
  • Loading branch information
aaschlote authored Dec 10, 2024
1 parent ccff44f commit 31a3f25
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 107 deletions.
7 changes: 0 additions & 7 deletions app/services/cms/__test__/getStrapiEntryFromFile.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from "node:fs";
import { faker } from "@faker-js/faker";
import { getStrapiFooter } from "tests/factories/cmsModels/strapiFooter";
import { getStrapiEntryFromFile } from "~/services/cms/getStrapiEntryFromFile";
import { StrapiLocaleSchema } from "~/services/cms/models/StrapiLocale";
Expand All @@ -14,9 +13,6 @@ describe("services/cms", () => {
const impressumPath = "/impressum";
const impressum = {
slug: impressumPath,
createdAt: faker.date.past().toISOString(),
updatedAt: faker.date.past().toISOString(),
publishedAt: faker.date.past().toISOString(),
locale: StrapiLocaleSchema.Values.de,
meta: {
title: "Impressum",
Expand All @@ -37,9 +33,6 @@ describe("services/cms", () => {
"form-flow-pages": [
{
attributes: {
createdAt: faker.date.past().toISOString(),
updatedAt: faker.date.past().toISOString(),
publishedAt: faker.date.past().toISOString(),
heading: "",
locale: StrapiLocaleSchema.Values.de,
preHeading: null,
Expand Down
7 changes: 0 additions & 7 deletions app/services/cms/models/HasStrapiTimestamps.ts

This file was deleted.

4 changes: 1 addition & 3 deletions app/services/cms/models/StrapiBackground.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";
import { StrapiWrapperSchema } from "./StrapiWrapper";

export const StrapiBackgroundSchema = z
.object({
__component: z.literal("meta.background").optional(),
})
.merge(StrapiWrapperSchema)
.merge(HasOptionalStrapiIdSchema);
.merge(StrapiWrapperSchema);

export type StrapiBackground = z.infer<typeof StrapiBackgroundSchema>;
19 changes: 8 additions & 11 deletions app/services/cms/models/StrapiButton.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";

export const StrapiButtonSchema = z
.object({
__component: z.literal("form-elements.button").optional(),
look: z.enum(["primary", "secondary", "tertiary", "ghost"]),
size: z.enum(["large", "medium", "small"]),
fullWidth: z.boolean(),
href: z.string().nullable(),
text: z.string().nullable(),
})
.merge(HasOptionalStrapiIdSchema);
export const StrapiButtonSchema = z.object({
__component: z.literal("form-elements.button").optional(),
look: z.enum(["primary", "secondary", "tertiary", "ghost"]),
size: z.enum(["large", "medium", "small"]),
fullWidth: z.boolean(),
href: z.string().nullable(),
text: z.string().nullable(),
});
4 changes: 1 addition & 3 deletions app/services/cms/models/StrapiContainer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";
import { StrapiWrapperSchema } from "./StrapiWrapper";

export const StrapiContainerSchema = z
.object({
__component: z.literal("meta.container").optional(),
})
.merge(StrapiWrapperSchema)
.merge(HasOptionalStrapiIdSchema);
.merge(StrapiWrapperSchema);

export type StrapiContainer = z.infer<typeof StrapiContainerSchema>;
6 changes: 1 addition & 5 deletions app/services/cms/models/StrapiCookieBannerSchema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { z } from "zod";
import { type CookieBannerContentProps } from "~/components/cookieBanner/CookieBanner";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";
import { HasStrapiLocaleSchema } from "./HasStrapiLocale";
import { HasStrapiTimestampsSchema } from "./HasStrapiTimestamps";
import { getHeadingProps, StrapiHeadingSchema } from "./StrapiHeading";
import { getRichTextProps, StrapiParagraphSchema } from "./StrapiParagraph";

Expand All @@ -15,9 +13,7 @@ export const StrapiCookieBannerSchema = z
cookieSettingLinkText: z.string(),
cookieSettingLinkUrl: z.string(),
})
.merge(HasOptionalStrapiIdSchema)
.merge(HasStrapiLocaleSchema)
.merge(HasStrapiTimestampsSchema);
.merge(HasStrapiLocaleSchema);

type StrapiCookieBanner = z.infer<typeof StrapiCookieBannerSchema>;

Expand Down
4 changes: 1 addition & 3 deletions app/services/cms/models/StrapiElementWithId.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { z } from "zod";
import { HasStrapiLocaleSchema } from "./HasStrapiLocale";
import { HasStrapiTimestampsSchema } from "./HasStrapiTimestamps";
import { StrapiContentComponentSchema } from "./StrapiContentComponent";

export const StrapiElementWithIdSchema = z
.object({
elementId: z.string(),
element: z.array(StrapiContentComponentSchema),
})
.merge(HasStrapiLocaleSchema)
.merge(HasStrapiTimestampsSchema);
.merge(HasStrapiLocaleSchema);

export type StrapiElementWithId = z.infer<typeof StrapiElementWithIdSchema>;
11 changes: 4 additions & 7 deletions app/services/cms/models/StrapiErrorCategory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { z } from "zod";
import { HasStrapiTimestampsSchema } from "./HasStrapiTimestamps";
import { StrapiFieldErrorSchema } from "./StrapiFieldError";

export const StrapiErrorCategorySchema = z
.object({
name: z.string(),
errorCodes: z.array(StrapiFieldErrorSchema),
})
.merge(HasStrapiTimestampsSchema);
export const StrapiErrorCategorySchema = z.object({
name: z.string(),
errorCodes: z.array(StrapiFieldErrorSchema),
});
11 changes: 4 additions & 7 deletions app/services/cms/models/StrapiFieldError.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";

export const StrapiFieldErrorSchema = z
.object({
code: z.string(),
text: z.string(),
})
.merge(HasOptionalStrapiIdSchema);
export const StrapiFieldErrorSchema = z.object({
code: z.string(),
text: z.string(),
});
6 changes: 1 addition & 5 deletions app/services/cms/models/StrapiFooter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { z } from "zod";
import { type FooterProps } from "~/components/Footer";
import { omitNull } from "~/util/omitNull";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";
import { HasStrapiLocaleSchema } from "./HasStrapiLocale";
import { HasStrapiTimestampsSchema } from "./HasStrapiTimestamps";
import { StrapiImageSchema, getImageProps } from "./StrapiImage";
import { StrapiLinkSchema } from "./StrapiLink";
import { StrapiParagraphSchema, getRichTextProps } from "./StrapiParagraph";
Expand All @@ -14,9 +12,7 @@ export const StrapiFooterSchema = z
paragraphs: z.array(StrapiParagraphSchema),
links: z.array(StrapiLinkSchema),
})
.merge(HasOptionalStrapiIdSchema)
.merge(HasStrapiLocaleSchema)
.merge(HasStrapiTimestampsSchema);
.merge(HasStrapiLocaleSchema);

export type StrapiFooter = z.infer<typeof StrapiFooterSchema>;

Expand Down
6 changes: 1 addition & 5 deletions app/services/cms/models/StrapiFormFlowPage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";
import { HasStrapiLocaleSchema } from "./HasStrapiLocale";
import { HasStrapiMetaSchema } from "./HasStrapiMeta";
import { HasStrapiTimestampsSchema } from "./HasStrapiTimestamps";
import { StrapiContentComponentSchema } from "./StrapiContentComponent";
import { StrapiFlowIdSchema } from "./StrapiFlowId";
import { StrapiFormComponentSchema } from "./StrapiFormComponent";
Expand All @@ -23,9 +21,7 @@ export const StrapiFormFlowPageSchema = z

post_form: z.array(StrapiContentComponentSchema),
})
.merge(HasOptionalStrapiIdSchema)
.merge(HasStrapiLocaleSchema)
.merge(HasStrapiMetaSchema)
.merge(HasStrapiTimestampsSchema);
.merge(HasStrapiMetaSchema);

export type StrapiFormFlowPage = z.infer<typeof StrapiFormFlowPageSchema>;
2 changes: 0 additions & 2 deletions app/services/cms/models/StrapiImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export const StrapiImageSchema = z.object({
provider: z.string(),

provider_metadata: z.string().nullable(),
createdAt: z.string().datetime({ precision: 3 }),
updatedAt: z.string().datetime({ precision: 3 }),
}),
})
.merge(HasOptionalStrapiIdSchema)
Expand Down
11 changes: 4 additions & 7 deletions app/services/cms/models/StrapiLink.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";

export const StrapiLinkSchema = z
.object({
url: z.string(),
text: z.string().nullable(),
})
.merge(HasOptionalStrapiIdSchema);
export const StrapiLinkSchema = z.object({
url: z.string(),
text: z.string().nullable(),
});

export type StrapiLink = z.infer<typeof StrapiLinkSchema>;
2 changes: 0 additions & 2 deletions app/services/cms/models/StrapiMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ export const StrapiMetaSchema = z.object({
ogTitle: z.string().nullable(),
breadcrumb: z.string(),
});
// technically the object contains an id, but we don't need it
// .merge(HasOptionalStrapiIdSchema);

export type StrapiMeta = z.infer<typeof StrapiMetaSchema>;
6 changes: 1 addition & 5 deletions app/services/cms/models/StrapiPage.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";
import { HasStrapiLocaleSchema } from "./HasStrapiLocale";
import { HasStrapiMetaSchema } from "./HasStrapiMeta";
import { HasStrapiTimestampsSchema } from "./HasStrapiTimestamps";
import { StrapiContentComponentSchema } from "./StrapiContentComponent";

export const StrapiPageSchema = z
.object({
content: z.array(StrapiContentComponentSchema),
slug: z.string(),
})
.merge(HasOptionalStrapiIdSchema)
.merge(HasStrapiLocaleSchema)
.merge(HasStrapiMetaSchema)
.merge(HasStrapiTimestampsSchema);
.merge(HasStrapiMetaSchema);

export type StrapiPage = z.infer<typeof StrapiPageSchema>;
4 changes: 1 addition & 3 deletions app/services/cms/models/StrapiPageHeader.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";
import { HasStrapiLocaleSchema } from "./HasStrapiLocale";
import { HasStrapiTimestampsSchema } from "./HasStrapiTimestamps";

export const StrapiPageHeaderSchema = z
.object({
title: z.string(),
linkLabel: z.string(),
})
.merge(HasOptionalStrapiIdSchema)
.merge(HasStrapiLocaleSchema)
.merge(HasStrapiTimestampsSchema);
.merge(HasStrapiLocaleSchema);

type StrapiPageHeader = z.infer<typeof StrapiPageHeaderSchema>;

Expand Down
7 changes: 2 additions & 5 deletions app/services/cms/models/StrapiResultPage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema, HasStrapiIdSchema } from "./HasStrapiId";
import { HasStrapiIdSchema } from "./HasStrapiId";
import { HasStrapiLocaleSchema } from "./HasStrapiLocale";
import { HasStrapiMetaSchema } from "./HasStrapiMeta";
import { HasStrapiTimestampsSchema } from "./HasStrapiTimestamps";
import { StrapiContentComponentSchema } from "./StrapiContentComponent";
import { StrapiElementWithIdSchema } from "./StrapiElementWithId";
import { StrapiFlowIdSchema } from "./StrapiFlowId";
Expand Down Expand Up @@ -33,9 +32,7 @@ export const StrapiResultPageSchema = z
freeZone: z.array(StrapiContentComponentSchema),
nextLink: StrapiLinkSchema.nullable(),
})
.merge(HasOptionalStrapiIdSchema)
.merge(HasStrapiLocaleSchema)
.merge(HasStrapiMetaSchema)
.merge(HasStrapiTimestampsSchema);
.merge(HasStrapiMetaSchema);

export type StrapiResultPage = z.infer<typeof StrapiResultPageSchema>;
8 changes: 4 additions & 4 deletions app/services/cms/models/StrapiSelectOption.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";

export const StrapiSelectOptionSchema = z
.object({ text: z.string(), value: z.string() })
.merge(HasOptionalStrapiIdSchema);
export const StrapiSelectOptionSchema = z.object({
text: z.string(),
value: z.string(),
});
6 changes: 1 addition & 5 deletions app/services/cms/models/StrapiVorabCheckPage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { z } from "zod";
import { HasOptionalStrapiIdSchema } from "./HasStrapiId";
import { HasStrapiLocaleSchema } from "./HasStrapiLocale";
import { HasStrapiMetaSchema } from "./HasStrapiMeta";
import { HasStrapiTimestampsSchema } from "./HasStrapiTimestamps";
import { StrapiContentComponentSchema } from "./StrapiContentComponent";
import { StrapiFlowIdSchema } from "./StrapiFlowId";
import { StrapiFormComponentSchema } from "./StrapiFormComponent";
Expand All @@ -18,7 +16,5 @@ export const StrapiVorabCheckPageSchema = z
form: z.array(StrapiFormComponentSchema),
nextButtonLabel: z.string().nullable(),
})
.merge(HasOptionalStrapiIdSchema)
.merge(HasStrapiLocaleSchema)
.merge(HasStrapiMetaSchema)
.merge(HasStrapiTimestampsSchema);
.merge(HasStrapiMetaSchema);
3 changes: 0 additions & 3 deletions app/services/cms/models/__test__/StrapiImage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ describe("getImageProps", () => {
formats: { key: "value" },
hash: "hash",
provider: "provider",

provider_metadata: "provider_metadata",
createdAt: "2023-04-06T13:58:37.139Z",
updatedAt: "2023-04-06T13:58:37.139Z",
},
},
});
Expand Down
3 changes: 0 additions & 3 deletions tests/factories/cmsModels/strapiFlowPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export function getStrapiFlowPage(
pre_form: [],
post_form: [],
locale: params.locale ?? "de",
createdAt: faker.date.anytime().toISOString(),
updatedAt: faker.date.anytime().toISOString(),
publishedAt: faker.date.anytime().toISOString(),
meta: {
title: faker.lorem.word(),
breadcrumb: faker.lorem.word(),
Expand Down
3 changes: 0 additions & 3 deletions tests/factories/cmsModels/strapiFooter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ export function getStrapiFooter() {
image: getStrapiImage(),
paragraphs: faker.helpers.multiple(getStrapiParagraph, { count: 2 }),
links: faker.helpers.multiple(getStrapiLink, { count: 7 }),
createdAt: faker.date.past().toISOString(),
updatedAt: faker.date.recent().toISOString(),
publishedAt: faker.date.recent().toISOString(),
};
}
2 changes: 0 additions & 2 deletions tests/factories/cmsModels/strapiImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export function getStrapiImage(): StrapiImage {
hash: `${name}_${hash}`,
provider: "aws-s3",
provider_metadata: null,
createdAt: faker.date.past().toISOString(),
updatedAt: faker.date.recent().toISOString(),
},
},
};
Expand Down

0 comments on commit 31a3f25

Please sign in to comment.