Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
chore: upgrade to Effect v3
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrisnl committed Apr 16, 2024
1 parent 972fac7 commit 8248866
Show file tree
Hide file tree
Showing 44 changed files with 1,462 additions and 1,085 deletions.
10 changes: 5 additions & 5 deletions app/core/db/config.server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as Schema from '@effect/schema/Schema';

const envValidationSchema = Schema.struct({
DB_USER: Schema.string.pipe(Schema.minLength(2)),
DB_HOST: Schema.string.pipe(Schema.minLength(2)),
DB_NAME: Schema.string.pipe(Schema.minLength(2)),
DB_PASSWORD: Schema.string.pipe(Schema.minLength(2)),
const envValidationSchema = Schema.Struct({
DB_USER: Schema.String.pipe(Schema.minLength(2)),
DB_HOST: Schema.String.pipe(Schema.minLength(2)),
DB_NAME: Schema.String.pipe(Schema.minLength(2)),
DB_PASSWORD: Schema.String.pipe(Schema.minLength(2)),
DB_PORT: Schema.NumberFromString,
});

Expand Down
12 changes: 6 additions & 6 deletions app/core/db/generate-schema.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as Schema from '@effect/schema/Schema';
import * as zg from 'zapatos/generate';

const envValidationSchema = Schema.struct({
DB_USER: Schema.string.pipe(Schema.minLength(2)),
DB_HOST: Schema.string.pipe(Schema.minLength(2)),
DB_NAME: Schema.string.pipe(Schema.minLength(2)),
DB_PASSWORD: Schema.string.pipe(Schema.minLength(2)),
DB_SSL: Schema.string.pipe(Schema.nonEmpty()),
const envValidationSchema = Schema.Struct({
DB_USER: Schema.String.pipe(Schema.minLength(2)),
DB_HOST: Schema.String.pipe(Schema.minLength(2)),
DB_NAME: Schema.String.pipe(Schema.minLength(2)),
DB_PASSWORD: Schema.String.pipe(Schema.minLength(2)),
DB_SSL: Schema.String.pipe(Schema.nonEmpty()),
});

// Throw on-load if missing
Expand Down
4 changes: 2 additions & 2 deletions app/core/domain/announcement-status.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {compose} from 'effect/Function';
export const DRAFT = 'DRAFT' as const;
export const PUBLISHED = 'PUBLISHED' as const;

export const announcementStatusSchema = Schema.literal(DRAFT, PUBLISHED).pipe(
export const announcementStatusSchema = Schema.Literal(DRAFT, PUBLISHED).pipe(
Schema.message(
() => "Announcement status must be one of 'DRAFT' or 'PUBLISHED'"
)
);

export type AnnouncementStatus = Schema.Schema.To<
export type AnnouncementStatus = Schema.Schema.Type<
typeof announcementStatusSchema
>;

Expand Down
12 changes: 6 additions & 6 deletions app/core/domain/announcement.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ export const announcementIdSchema = uuidSchema.pipe(
Schema.brand(AnnouncementIdBrand)
);

export class Announcement extends Schema.Class<Announcement>()({
export class Announcement extends Schema.Class<Announcement>('Announcement')({
id: uuidSchema,
orgId: orgIdSchema,
title: announcementTitleSchema,
content: announcementContentSchema,
status: announcementStatusSchema,
createdByUser: Schema.nullable(
Schema.struct({name: userNameSchema, id: userIdSchema})
createdByUser: Schema.NullOr(
Schema.Struct({name: userNameSchema, id: userIdSchema})
),
publishedByUser: Schema.nullable(
Schema.struct({name: userNameSchema, id: userIdSchema})
publishedByUser: Schema.NullOr(
Schema.Struct({name: userNameSchema, id: userIdSchema})
),
updatedAt: Schema.Date,
createdAt: Schema.Date,
publishedAt: Schema.nullable(Schema.Date),
publishedAt: Schema.NullOr(Schema.Date),
}) {
static fromUnknown = compose(
Schema.decodeUnknown(this),
Expand Down
2 changes: 1 addition & 1 deletion app/core/domain/email.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const emailSchema = Schema.compose(Schema.Trim, Schema.Lowercase).pipe(
Schema.brand(EmailBrand)
);

export type Email = Schema.Schema.To<typeof emailSchema>;
export type Email = Schema.Schema.Type<typeof emailSchema>;

class EmailParseError extends Data.TaggedError('EmailParseError')<{
cause: ParseError;
Expand Down
4 changes: 2 additions & 2 deletions app/core/domain/invite-status.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const PENDING = 'PENDING' as const;
export const DECLINED = 'DECLINED' as const;
export const EXPIRED = 'EXPIRED' as const;

export const inviteStatusSchema = Schema.literal(
export const inviteStatusSchema = Schema.Literal(
PENDING,
DECLINED,
EXPIRED
Expand All @@ -17,7 +17,7 @@ export const inviteStatusSchema = Schema.literal(
)
);

export type InviteStatus = Schema.Schema.To<typeof inviteStatusSchema>;
export type InviteStatus = Schema.Schema.Type<typeof inviteStatusSchema>;

class InviteStatusParseError extends Data.TaggedError(
'InviteStatusParseError'
Expand Down
6 changes: 4 additions & 2 deletions app/core/domain/membership-invitation.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ class MembershipInvitationParse extends Data.TaggedError(
cause: ParseError;
}> {}

export class MembershipInvitation extends Schema.Class<MembershipInvitation>()({
export class MembershipInvitation extends Schema.Class<MembershipInvitation>(
'MembershipInvitation'
)({
id: uuidSchema,
email: emailSchema,
status: inviteStatusSchema,
role: membershipRoleSchema,
createdAt: Schema.Date,
updatedAt: Schema.Date,
org: Schema.struct({
org: Schema.Struct({
name: orgNameSchema,
id: orgIdSchema,
slug: orgSlugSchema,
Expand Down
4 changes: 2 additions & 2 deletions app/core/domain/membership-role.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export const MEMBER = 'MEMBER' as const;

const MembershipRoleBrand = Symbol.for('MembershipRoleBrand');

export const membershipRoleSchema = Schema.literal(OWNER, ADMIN, MEMBER).pipe(
export const membershipRoleSchema = Schema.Literal(OWNER, ADMIN, MEMBER).pipe(
Schema.message(() => "The role must be one of 'OWNER', 'ADMIN' or 'MEMBER'"),
Schema.brand(MembershipRoleBrand)
);

export type MembershipRole = Schema.Schema.To<typeof membershipRoleSchema>;
export type MembershipRole = Schema.Schema.Type<typeof membershipRoleSchema>;

class MembershipRoleParseError extends Data.TaggedError(
'MembershipRoleParseError'
Expand Down
6 changes: 3 additions & 3 deletions app/core/domain/membership.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class MembershipParseError extends Data.TaggedError('MembershipParseError')<{
cause: ParseError;
}> {}

export class Membership extends Schema.Class<Membership>()({
org: Schema.struct({
export class Membership extends Schema.Class<Membership>('Membership')({
org: Schema.Struct({
name: orgNameSchema,
id: orgIdSchema,
slug: orgSlugSchema,
}),
user: Schema.struct({
user: Schema.Struct({
name: userNameSchema,
id: userIdSchema,
email: emailSchema,
Expand Down
4 changes: 2 additions & 2 deletions app/core/domain/org.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export const orgNameSchema = Schema.Trim.pipe(
);

export const orgIdSchema = uuidSchema.pipe(Schema.brand(OrgIdBrand));
export const orgSlugSchema = Schema.string.pipe(Schema.minLength(2));
export const orgSlugSchema = Schema.String.pipe(Schema.minLength(2));

export class Org extends Schema.Class<Org>()({
export class Org extends Schema.Class<Org>('Org')({
id: orgIdSchema,
name: orgNameSchema,
slug: orgSlugSchema,
Expand Down
4 changes: 2 additions & 2 deletions app/core/domain/password-reset-token.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {uuidSchema} from './uuid.server';

const PasswordResetTokenBrand = Symbol.for('PasswordResetTokenBrand');

export const passwordResetTokenSchema = Schema.struct({
export const passwordResetTokenSchema = Schema.Struct({
id: uuidSchema.pipe(Schema.message(() => 'Token is in invalid format')),
userId: uuidSchema,
expiresAt: Schema.Date,
createdAt: Schema.Date,
updatedAt: Schema.Date,
}).pipe(Schema.brand(PasswordResetTokenBrand));

export type PasswordResetToken = Schema.Schema.To<
export type PasswordResetToken = Schema.Schema.Type<
typeof passwordResetTokenSchema
>;

Expand Down
4 changes: 2 additions & 2 deletions app/core/domain/password.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {compose, pipe} from 'effect/Function';
const SALT_ROUNDS = 10;
const PasswordBrand = Symbol.for('PasswordBrand');

export const passwordSchema = Schema.string.pipe(
export const passwordSchema = Schema.String.pipe(
Schema.minLength(8, {
message: () => 'Password should be at least 8 characters long',
}),
Expand All @@ -17,7 +17,7 @@ export const passwordSchema = Schema.string.pipe(
Schema.brand(PasswordBrand)
);

export type Password = Schema.Schema.To<typeof passwordSchema>;
export type Password = Schema.Schema.Type<typeof passwordSchema>;

export class PasswordHashError {
readonly _tag = 'PasswordHashError';
Expand Down
4 changes: 2 additions & 2 deletions app/core/domain/user.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export const userNameSchema = Schema.Trim.pipe(
const UserIdBrand = Symbol.for('UserIdBrand');
export const userIdSchema = uuidSchema.pipe(Schema.brand(UserIdBrand));

export class User extends Schema.Class<User>()({
export class User extends Schema.Class<User>('User')({
id: userIdSchema,
name: userNameSchema,
email: emailSchema,
emailVerified: Schema.boolean,
emailVerified: Schema.Boolean,
createdAt: Schema.Date,
updatedAt: Schema.Date,
}) {
Expand Down
2 changes: 1 addition & 1 deletion app/core/domain/uuid.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const uuidSchema = Schema.UUID.pipe(
Schema.brand(UuidBrand)
);

export type Uuid = Schema.Schema.To<typeof uuidSchema>;
export type Uuid = Schema.Schema.Type<typeof uuidSchema>;

export const parseUUID = compose(
Schema.decodeUnknown(uuidSchema),
Expand Down
6 changes: 4 additions & 2 deletions app/core/domain/verify-email-token.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import {uuidSchema} from './uuid.server';

const VerifyEmailTokenBrand = Symbol.for('VerifyEmailTokenBrand');

export const verifyEmailTokenSchema = Schema.struct({
export const verifyEmailTokenSchema = Schema.Struct({
id: uuidSchema.pipe(Schema.message(() => 'Token is in invalid format')),
userId: uuidSchema,
expiresAt: Schema.Date,
createdAt: Schema.Date,
updatedAt: Schema.Date,
}).pipe(Schema.brand(VerifyEmailTokenBrand));

export type VerifyEmailToken = Schema.Schema.To<typeof verifyEmailTokenSchema>;
export type VerifyEmailToken = Schema.Schema.Type<
typeof verifyEmailTokenSchema
>;

class VerifyEmailTokenParseError extends Data.TaggedError(
'VerifyEmailTokenParseError'
Expand Down
4 changes: 2 additions & 2 deletions app/core/lib/session.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as Effect from 'effect/Effect';

import {Redirect} from '~/core/lib/responses.server';

const envValidationSchema = Schema.struct({
SESSION_SECRET: Schema.string.pipe(Schema.nonEmpty()),
const envValidationSchema = Schema.Struct({
SESSION_SECRET: Schema.String.pipe(Schema.nonEmpty()),
});

// Throw on-load if missing
Expand Down
4 changes: 2 additions & 2 deletions app/core/lib/theme.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as Schema from '@effect/schema/Schema';
import {createCookieSessionStorage} from '@remix-run/node';
import {createThemeSessionResolver} from 'remix-themes';

const envValidationSchema = Schema.struct({
SESSION_SECRET: Schema.string.pipe(Schema.nonEmpty()),
const envValidationSchema = Schema.Struct({
SESSION_SECRET: Schema.String.pipe(Schema.nonEmpty()),
});
const config = Schema.decodeUnknownSync(envValidationSchema)(process.env);

Expand Down
4 changes: 2 additions & 2 deletions app/core/lib/validation-helper.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {formatError} from '@effect/schema/ArrayFormatter';
import {formatErrorSync} from '@effect/schema/ArrayFormatter';
import * as Schema from '@effect/schema/Schema';
import {pipe} from 'effect';
import * as Effect from 'effect/Effect';
Expand All @@ -13,7 +13,7 @@ export const schemaResolver =
errors: 'all',
}),
Effect.mapError((error) => {
const issue = formatError(error);
const issue = formatErrorSync(error);
const message = issue[0]!.message;
return new ValidationError({errors: [message]});
})
Expand Down
14 changes: 7 additions & 7 deletions app/core/mailer/config.server.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as Schema from '@effect/schema/Schema';

const envValidationSchema = Schema.struct({
SMTP_HOST: Schema.string.pipe(Schema.minLength(2)),
SMTP_USER: Schema.string.pipe(Schema.minLength(2)),
SMTP_PASSWORD: Schema.string.pipe(Schema.minLength(2)),
const envValidationSchema = Schema.Struct({
SMTP_HOST: Schema.String.pipe(Schema.minLength(2)),
SMTP_USER: Schema.String.pipe(Schema.minLength(2)),
SMTP_PASSWORD: Schema.String.pipe(Schema.minLength(2)),
SMTP_PORT: Schema.NumberFromString,
SMTP_SECURE: Schema.string.pipe(Schema.nonEmpty()),
SMTP_SECURE: Schema.String.pipe(Schema.nonEmpty()),

EMAIL_FROM: Schema.string.pipe(Schema.minLength(5), Schema.endsWith('.com')),
DASHBOARD_URL: Schema.string.pipe(
EMAIL_FROM: Schema.String.pipe(Schema.minLength(5), Schema.endsWith('.com')),
DASHBOARD_URL: Schema.String.pipe(
Schema.minLength(5),
Schema.startsWith('http')
),
Expand Down
2 changes: 1 addition & 1 deletion app/core/mailer/emails/send-invitation-email.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function sendInvitationEmail({
),
Effect.flatMap(() => Effect.log(error)),
// suppress error
Effect.flatMap(() => Effect.unit)
Effect.flatMap(() => Effect.void)
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function sendPasswordResetEmail({
),
Effect.flatMap(() => Effect.log(error)),
// suppress error
Effect.flatMap(() => Effect.unit)
Effect.flatMap(() => Effect.void)
)
)
);
Expand Down
2 changes: 1 addition & 1 deletion app/core/mailer/emails/send-verification-email.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function sendVerificationEmail({
),
Effect.flatMap(() => Effect.log(error)),
// suppress error
Effect.flatMap(() => Effect.unit)
Effect.flatMap(() => Effect.void)
)
)
);
Expand Down
10 changes: 5 additions & 5 deletions app/core/redis/config.server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as Schema from '@effect/schema/Schema';

const envValidationSchema = Schema.struct({
REDIS_HOST: Schema.string.pipe(Schema.minLength(2)),
REDIS_PASSWORD: Schema.string,
REDIS_USER: Schema.string,
const envValidationSchema = Schema.Struct({
REDIS_HOST: Schema.String.pipe(Schema.minLength(2)),
REDIS_PASSWORD: Schema.String,
REDIS_USER: Schema.String,
REDIS_PORT: Schema.NumberFromString,
REDIS_TLS: Schema.string,
REDIS_TLS: Schema.String,
});

// Throw on-load if missing
Expand Down
4 changes: 2 additions & 2 deletions app/core/use-cases/accept-invitation.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {PENDING} from '../domain/invite-status.server';
import {Org} from '../domain/org.server';
import type {User} from '../domain/user.server';

const validationSchema = Schema.struct({
const validationSchema = Schema.Struct({
invitationId: uuidSchema,
});

export type AcceptInvitationProps = Schema.Schema.To<typeof validationSchema>;
export type AcceptInvitationProps = Schema.Schema.Type<typeof validationSchema>;

export function acceptInvitation({pool, db}: {pool: PgPool; db: DB}) {
function execute({
Expand Down
4 changes: 2 additions & 2 deletions app/core/use-cases/change-password.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
} from '../domain/password.server';
import type {User} from '../domain/user.server';

const validationSchema = Schema.struct({
const validationSchema = Schema.Struct({
oldPassword: passwordSchema,
newPassword: passwordSchema,
});

export type ChangePasswordProps = Schema.Schema.To<typeof validationSchema>;
export type ChangePasswordProps = Schema.Schema.Type<typeof validationSchema>;

export function changePassword({pool, db}: {pool: PgPool; db: DB}) {
function execute({
Expand Down
6 changes: 4 additions & 2 deletions app/core/use-cases/create-announcement.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import {DatabaseError, InternalServerError} from '~/core/lib/errors.server.ts';
import {schemaResolver} from '~/core/lib/validation-helper.server';
import {announcementAuthorizationService} from '~/core/services/announcement-authorization-service.server';

const validationSchema = Schema.struct({
const validationSchema = Schema.Struct({
title: announcementTitleSchema,
content: announcementContentSchema,
status: announcementStatusSchema,
});

export type CreateAnnouncementProps = Schema.Schema.To<typeof validationSchema>;
export type CreateAnnouncementProps = Schema.Schema.Type<
typeof validationSchema
>;

export function createAnnouncement({pool, db}: {pool: PgPool; db: DB}) {
function execute({
Expand Down
Loading

0 comments on commit 8248866

Please sign in to comment.