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(deps): update effect packages #963

Merged
merged 12 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 3 additions & 6 deletions apps/web/app/models/resume/meta/meta.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import * as jsonSchema from '@effect/schema/JSONSchema'
import type * as S from '@effect/schema/Schema'
import { JSONSchema } from 'effect'
import { describe, expect, test } from 'vitest'

import { expectEffectFailure, expectEffectSuccess } from '~/schemas/test-utils.ts'

import { Meta } from './meta.ts'

describe('Meta', () => {
const metaInput = {
canonical: 'https://example.com',
lastModified: 'Thu, 02 May 2024 18:33:23 GMT',
version: 'v6.9',
} satisfies S.Schema.Encoded<typeof Meta>
}

describe('decode', () => {
test('handle all missing property', async () => {
Expand Down Expand Up @@ -95,7 +92,7 @@ describe('Meta', () => {
})

test('JSONSchema', () => {
expect(JSON.stringify(jsonSchema.make(Meta), null, '\t')).toMatchFileSnapshot(
expect(JSON.stringify(JSONSchema.make(Meta), null, '\t')).toMatchFileSnapshot(
'meta-schema.snapshot.json',
)
})
Expand Down
16 changes: 8 additions & 8 deletions apps/web/app/models/resume/meta/meta.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as S from '@effect/schema/Schema'
import { TrimmedNonEmpty, UrlString } from '@suddenlygiovanni/resume/schema-primitive'
import { Schema } from 'effect'

export class Meta extends S.Class<Meta>('Meta')({
canonical: S.optionalWith(UrlString, { exact: true }),
export class Meta extends Schema.Class<Meta>('Meta')({
canonical: Schema.optionalWith(UrlString, { exact: true }),

lastModified: S.optionalWith(
S.Date.annotations({
lastModified: Schema.optionalWith(
Schema.Date.annotations({
jsonSchema: {
format: 'date-time',
type: 'string',
Expand All @@ -14,7 +14,7 @@ export class Meta extends S.Class<Meta>('Meta')({
{ exact: true },
),

version: S.optionalWith(
version: Schema.optionalWith(
TrimmedNonEmpty.annotations({
title: 'version',
description: 'A version field which follows semver - e.g. v1.0.0',
Expand All @@ -23,7 +23,7 @@ export class Meta extends S.Class<Meta>('Meta')({
{ exact: true },
),
}) {
static decode = S.decode(this)
static decode = Schema.decode(this)

static encode = S.encode(this)
static encode = Schema.encode(this)
}
4 changes: 2 additions & 2 deletions apps/web/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Schema from '@effect/schema/Schema'
import { invariantResponse } from '@epic-web/invariant'
import type {
ActionFunctionArgs,
Expand All @@ -8,7 +7,8 @@ import type {
} from '@remix-run/node'
import { Links, Meta, Scripts, ScrollRestoration, json, useLoaderData } from '@remix-run/react'
import { Types, makeOpenGraphWebsite } from '@suddenlygiovanni/open-graph-protocol'
import * as Either from 'effect/Either'
import { Either, Schema } from 'effect'

import type { JSX, ReactElement, ReactNode } from 'react'

import { Layout } from '@suddenlygiovanni/ui/components/layout/layout.tsx'
Expand Down
17 changes: 9 additions & 8 deletions apps/web/app/routes/resume/format-date-locale-short.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ParseError } from '@effect/schema/ParseResult'
import { getOrThrow, isLeft } from 'effect/Either'
import { Either } from 'effect'

import { ParseError } from 'effect/ParseResult'
import { describe, expect, test } from 'vitest'
import { formatDateLocaleShort } from './format-date-locale-short.ts'

describe('formatDateLocaleShort', () => {
test('should return an error for an empty string', () => {
const result = formatDateLocaleShort('')
expect(isLeft(result)).toBe(true)
if (isLeft(result)) {
expect(Either.isLeft(result)).toBe(true)
if (Either.isLeft(result)) {
expect(result.left).toBeInstanceOf(ParseError)
}
})
Expand All @@ -16,8 +17,8 @@ describe('formatDateLocaleShort', () => {
const invalidDateString = '19/04/2022'
const result = formatDateLocaleShort(invalidDateString)

expect(isLeft(result)).toBe(true)
if (isLeft(result)) {
expect(Either.isLeft(result)).toBe(true)
if (Either.isLeft(result)) {
expect(result.left).toBeInstanceOf(ParseError)
}
})
Expand All @@ -27,7 +28,7 @@ describe('formatDateLocaleShort', () => {
const isoDateString2 = '2022-04-30'
const result1 = formatDateLocaleShort(isoDateString1)
const result2 = formatDateLocaleShort(isoDateString2)
expect(getOrThrow(result1)).toBe('Apr 2022')
expect(getOrThrow(result2)).toBe('Apr 2022')
expect(Either.getOrThrow(result1)).toBe('Apr 2022')
expect(Either.getOrThrow(result2)).toBe('Apr 2022')
})
})
4 changes: 2 additions & 2 deletions apps/web/app/routes/resume/format-date-locale-short.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ParseError } from '@effect/schema/ParseResult'
import * as Schema from '@effect/schema/Schema'
import { Schema } from 'effect'
import type { Either } from 'effect/Either'
import type { ParseError } from 'effect/ParseResult'

/**
* Given a string date, this function validates and transforms it to a US locale short date format.
Expand Down
8 changes: 4 additions & 4 deletions apps/web/app/schemas/parse-yml.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AST, ParseResult, Schema } from '@effect/schema'
// biome-ignore lint/style/useNamingConvention: I want to have the same style of using JSON.<method>
import * as YAML from '@std/yaml'
import { ParseResult, Schema, SchemaAST } from 'effect'

export const YmlString = Schema.String.annotations({
[AST.IdentifierAnnotationId]: 'YmlString',
[AST.TitleAnnotationId]: 'YmlString',
[AST.DescriptionAnnotationId]: 'a YML string',
[SchemaAST.IdentifierAnnotationId]: 'YmlString',
[SchemaAST.TitleAnnotationId]: 'YmlString',
[SchemaAST.DescriptionAnnotationId]: 'a YML string',
})

/**
Expand Down
59 changes: 28 additions & 31 deletions apps/web/app/schemas/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { ParseOptions } from '@effect/schema/AST'
import type * as ParseResult from '@effect/schema/ParseResult'
import * as S from '@effect/schema/Schema'
import { formatErrorSync } from '@effect/schema/TreeFormatter'
import * as Effect from 'effect/Effect'
import * as Either from 'effect/Either'
import * as Option from 'effect/Option'
import { Effect, Either, Option, Schema } from 'effect'
import { type ParseError, TreeFormatter } from 'effect/ParseResult'
import type { ParseOptions } from 'effect/SchemaAST'

import { expect } from 'vitest'

export const onExcessPropertyError: ParseOptions = {
Expand All @@ -20,44 +17,44 @@ export const allErrors: ParseOptions = {
}

export const expectDecodeUnknownSuccess = async <A, I>(
schema: S.Schema<A, I, never>,
schema: Schema.Schema<A, I, never>,
input: unknown,
// biome-ignore lint/suspicious/noExplicitAny: ok here
expected: A = input as any,
options?: ParseOptions,
) => expectSuccess(S.decodeUnknown(schema)(input, options), expected)
): Promise<void> => expectSuccess(Schema.decodeUnknown(schema)(input, options), expected)

export const expectDecodeUnknownFailure = async <A, I>(
schema: S.Schema<A, I, never>,
schema: Schema.Schema<A, I, never>,
input: unknown,
message: string,
options?: ParseOptions,
) => expectFailure(S.decodeUnknown(schema)(input, options), message)
): Promise<void> => expectFailure(Schema.decodeUnknown(schema)(input, options), message)

export const expectEncodeSuccess = async <A, I>(
schema: S.Schema<A, I, never>,
schema: Schema.Schema<A, I, never>,
a: A,
expected: unknown,
options?: ParseOptions,
) => expectSuccess(S.encode(schema)(a, options), expected)
): Promise<void> => expectSuccess(Schema.encode(schema)(a, options), expected)

export const expectEncodeFailure = async <A, I>(
schema: S.Schema<A, I, never>,
schema: Schema.Schema<A, I, never>,
a: A,
message: string,
options?: ParseOptions,
) => expectFailure(S.encode(schema)(a, options), message)
): Promise<void> => expectFailure(Schema.encode(schema)(a, options), message)

// biome-ignore lint/style/useNamingConvention: <explanation>
export const printAST = <A, I, R>(schema: S.Schema<A, I, R>) => {
export const printAST = <A, I, R>(schema: Schema.Schema<A, I, R>): void => {
console.log('%o', schema.ast)
}

// biome-ignore lint/suspicious/useAwait: <explanation>
export const expectFailure = async <A>(
effect: Either.Either<A, ParseResult.ParseError> | Effect.Effect<A, ParseResult.ParseError>,
effect: Either.Either<A, ParseError> | Effect.Effect<A, ParseError>,
message: string,
) => {
): Promise<void> => {
if (Either.isEither(effect)) {
expectEitherLeft(effect, message)
} else {
Expand All @@ -69,7 +66,7 @@ export const expectFailure = async <A>(
export const expectSuccess = async <E, A>(
effect: Either.Either<A, E> | Effect.Effect<A, E>,
a: A,
) => {
): Promise<void> => {
if (Either.isEither(effect)) {
expectEitherRight(effect, a)
} else {
Expand All @@ -78,33 +75,33 @@ export const expectSuccess = async <E, A>(
}

export const expectEffectFailure = async <A>(
effect: Effect.Effect<A, ParseResult.ParseError>,
effect: Effect.Effect<A, ParseError>,
message: string,
) => {
): Promise<void> => {
expect(
await Effect.runPromise(Effect.either(Effect.mapError(effect, formatErrorSync))),
await Effect.runPromise(Effect.either(Effect.mapError(effect, TreeFormatter.formatErrorSync))),
).toStrictEqual(Either.left(message))
}

export const expectEffectSuccess = async <E, A>(effect: Effect.Effect<A, E>, a: A) => {
export const expectEffectSuccess = async <E, A>(
effect: Effect.Effect<A, E>,
a: A,
): Promise<void> => {
expect(await Effect.runPromise(Effect.either(effect))).toStrictEqual(Either.right(a))
}

export const expectEitherLeft = <A>(
e: Either.Either<A, ParseResult.ParseError>,
message: string,
) => {
expect(Either.mapLeft(e, formatErrorSync)).toStrictEqual(Either.left(message))
export const expectEitherLeft = <A>(e: Either.Either<A, ParseError>, message: string): void => {
expect(Either.mapLeft(e, TreeFormatter.formatErrorSync)).toStrictEqual(Either.left(message))
}

export const expectEitherRight = <E, A>(e: Either.Either<A, E>, a: A) => {
export const expectEitherRight = <E, A>(e: Either.Either<A, E>, a: A): void => {
expect(e).toStrictEqual(Either.right(a))
}

export const expectNone = <A>(o: Option.Option<A>) => {
export const expectNone = <A>(o: Option.Option<A>): void => {
expect(o).toStrictEqual(Option.none())
}

export const expectSome = <A>(o: Option.Option<A>, a: A) => {
export const expectSome = <A>(o: Option.Option<A>, a: A): void => {
expect(o).toStrictEqual(Option.some(a))
}
2 changes: 1 addition & 1 deletion apps/web/app/services/resume-repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Schema } from '@effect/schema'
import { Resume } from '@suddenlygiovanni/resume/schema-resume'
import { Schema } from 'effect'
import { Console, Data, Effect, Layer, Option } from 'effect'

import { Meta } from '~/models/resume/meta/meta.ts'
Expand Down
7 changes: 3 additions & 4 deletions apps/web/app/utils/env.server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// biome-ignore lint/correctness/noNodejsModules: <explanation>
import * as process from 'node:process'
import * as Schema from '@effect/schema/Schema'
import { formatError } from '@effect/schema/TreeFormatter'
import * as Either from 'effect/Either'
import { Either, Schema } from 'effect'
import { TreeFormatter } from 'effect/ParseResult'

const envSchema = Schema.Struct({
// biome-ignore lint/style/useNamingConvention: <explanation>
Expand Down Expand Up @@ -51,7 +50,7 @@ declare global {
export function init(): void {
const maybeEnv = Schema.decodeUnknownEither(envSchema)(process.env, { errors: 'all' })
if (Either.isLeft(maybeEnv)) {
console.error('❌ Invalid environment variables:', formatError(maybeEnv.left))
console.error('❌ Invalid environment variables:', TreeFormatter.formatError(maybeEnv.left))
throw new Error('Invalid environment variables')
}
}
Expand Down
3 changes: 1 addition & 2 deletions apps/web/app/utils/theme.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Schema from '@effect/schema/Schema'
import { useFetchers } from '@remix-run/react'
import * as Either from 'effect/Either'
import { Either, Schema } from 'effect'

import { useHints } from './client-hints.tsx'
import { useRequestInfo } from './request-info.ts'
Expand Down
5 changes: 2 additions & 3 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
}
},
"dependencies": {
"@effect/schema": "0.72.2",
"@epic-web/client-hints": "1.3.5",
"@epic-web/invariant": "1.0.0",
"@octokit/core": "6.1.2",
Expand All @@ -16,10 +15,10 @@
"@remix-run/serve": "2.13.1",
"@std/yaml": "npm:@jsr/[email protected]",
"@suddenlygiovanni/open-graph-protocol": "workspace:*",
"@suddenlygiovanni/resume": "12.1.12",
"@suddenlygiovanni/resume": "13.0.0",
"@suddenlygiovanni/ui": "workspace:*",
"cookie": "1.0.1",
"effect": "3.7.2",
"effect": "3.10.4",
"isbot": "5.1.17",
"react": "18.3.1",
"react-dom": "18.3.1"
Expand Down
Loading
Loading