Skip to content

Commit

Permalink
refactor(web, protocol): use optionalWith for schemas
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
suddenlyGiovanni committed Sep 4, 2024
1 parent dc751cc commit 887aeef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions apps/web/app/models/resume/meta/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>('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',
Expand All @@ -14,7 +14,7 @@ export class Meta extends S.Class<Meta>('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',
Expand Down
6 changes: 3 additions & 3 deletions apps/web/app/utils/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const envSchema = Schema.Struct({
// biome-ignore lint/style/useNamingConvention: <explanation>
NODE_ENV: Schema.Literal('production', 'development', 'test'),
// biome-ignore lint/style/useNamingConvention: <explanation>
GITHUB_TOKEN: Schema.optional(
Schema.NonEmpty.annotations({
GITHUB_TOKEN: Schema.optionalWith(
Schema.NonEmptyString.annotations({
description: 'GitHub token',
examples: ['github_pat_xxxxxxx_xxxxxx'],
}),
Expand All @@ -19,7 +19,7 @@ const envSchema = Schema.Struct({
},
),
// biome-ignore lint/style/useNamingConvention: <explanation>
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'),
Expand Down
5 changes: 4 additions & 1 deletion packages/open-graph-protocol/src/open-graph-twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 887aeef

Please sign in to comment.