From 887aeef51c53d0b2907d29bdcf5065ff99736b1a Mon Sep 17 00:00:00 2001
From: Giovanni Ravalico <15946771+suddenlyGiovanni@users.noreply.github.com>
Date: Wed, 4 Sep 2024 12:18:52 +0200
Subject: [PATCH] refactor(web, protocol): use optionalWith for schemas
Replaced optional with optionalWith for schema definitions in multiple files. This change ensures more precise control over optional fields and improves code consistency.
Signed-off-by: Giovanni Ravalico <15946771+suddenlyGiovanni@users.noreply.github.com>
---
apps/web/app/models/resume/meta/meta.ts | 6 +++---
apps/web/app/utils/env.server.ts | 6 +++---
packages/open-graph-protocol/src/open-graph-twitter.ts | 5 ++++-
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/apps/web/app/models/resume/meta/meta.ts b/apps/web/app/models/resume/meta/meta.ts
index 9a73ebe34..d11ce3c8a 100644
--- a/apps/web/app/models/resume/meta/meta.ts
+++ b/apps/web/app/models/resume/meta/meta.ts
@@ -2,9 +2,9 @@ import * as S from '@effect/schema/Schema'
import { TrimmedNonEmpty, UrlString } from '@suddenlygiovanni/resume/schema-primitive'
export class Meta extends S.Class('Meta')({
- canonical: S.optional(UrlString, { exact: true }),
+ canonical: S.optionalWith(UrlString, { exact: true }),
- lastModified: S.optional(
+ lastModified: S.optionalWith(
S.Date.annotations({
jsonSchema: {
format: 'date-time',
@@ -14,7 +14,7 @@ export class Meta extends S.Class('Meta')({
{ exact: true },
),
- version: S.optional(
+ version: S.optionalWith(
TrimmedNonEmpty.annotations({
title: 'version',
description: 'A version field which follows semver - e.g. v1.0.0',
diff --git a/apps/web/app/utils/env.server.ts b/apps/web/app/utils/env.server.ts
index 2d70cb7a4..095ef9d8a 100644
--- a/apps/web/app/utils/env.server.ts
+++ b/apps/web/app/utils/env.server.ts
@@ -8,8 +8,8 @@ const envSchema = Schema.Struct({
// biome-ignore lint/style/useNamingConvention:
NODE_ENV: Schema.Literal('production', 'development', 'test'),
// biome-ignore lint/style/useNamingConvention:
- GITHUB_TOKEN: Schema.optional(
- Schema.NonEmpty.annotations({
+ GITHUB_TOKEN: Schema.optionalWith(
+ Schema.NonEmptyString.annotations({
description: 'GitHub token',
examples: ['github_pat_xxxxxxx_xxxxxx'],
}),
@@ -19,7 +19,7 @@ const envSchema = Schema.Struct({
},
),
// biome-ignore lint/style/useNamingConvention:
- ALLOW_INDEXING: Schema.optional(
+ ALLOW_INDEXING: Schema.optionalWith(
Schema.transform(Schema.Literal('true', 'false'), Schema.Boolean, {
decode: string => string === 'true',
encode: boolean => (boolean ? 'true' : 'false'),
diff --git a/packages/open-graph-protocol/src/open-graph-twitter.ts b/packages/open-graph-protocol/src/open-graph-twitter.ts
index 8031a812c..710d50e93 100644
--- a/packages/open-graph-protocol/src/open-graph-twitter.ts
+++ b/packages/open-graph-protocol/src/open-graph-twitter.ts
@@ -262,7 +262,10 @@ export function makeTwitterCardMeta<
}
const [property] = args
return (content: Content): TwitterCardMeta =>
- ({ name: property, content: String(content) }) as const
+ ({
+ name: property,
+ content: String(content),
+ }) as const
}
interface TwitterCardBase {