Skip to content

Commit

Permalink
chore: update realworld to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
TylorS committed Jun 19, 2024
1 parent 308d020 commit 7a04ca9
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 66 deletions.
8 changes: 4 additions & 4 deletions examples/realworld/src/api/common/infrastructure/Passwords.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Context } from "@typed/core"
import type { Password } from "@typed/realworld/model"
import { PasswordHash } from "@typed/realworld/model"
import { Effect, Secret } from "effect"
import { Effect, Redacted } from "effect"

export const HashPassword = Context.Fn<(password: Password) => Effect.Effect<PasswordHash>>()("PasswordHash")

export const HashPasswordLive = HashPassword.implement((password) =>
Effect.gen(function*(_) {
const bcrypt = yield* _(Effect.promise(() => import("bcrypt")))
const hash = yield* _(Effect.promise(() => bcrypt.hash(Secret.value(password), 10)))
return PasswordHash.make(Secret.fromString(hash))
const hash = yield* _(Effect.promise(() => bcrypt.hash(Redacted.value(password), 10)))
return PasswordHash.make(Redacted.make(hash))
})
)

Expand All @@ -20,6 +20,6 @@ export const ComparePassword = Context.Fn<(password: Password, hash: PasswordHas
export const ComparePasswordLive = ComparePassword.implement((password, hash) =>
Effect.gen(function*(_) {
const bcrypt = yield* _(Effect.promise(() => import("bcrypt")))
return yield* _(Effect.promise(() => bcrypt.compare(Secret.value(password), Secret.value(hash))))
return yield* _(Effect.promise(() => bcrypt.compare(Redacted.value(password), Redacted.value(hash))))
})
)
2 changes: 1 addition & 1 deletion examples/realworld/src/api/common/infrastructure/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function handleExpectedErrors<
return new Unprocessable({ errors: [(error as Sql.error.SqlError).message] })
case "ParseError":
case "SchemaError":
return new Unprocessable({ errors: [TreeFormatter.formatIssueSync((error as ParseError).error)] })
return new Unprocessable({ errors: [TreeFormatter.formatIssueSync((error as ParseError).issue)] })
case "And":
case "InvalidData":
case "MissingData":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Pg from "@effect/sql-pg"
import * as Sql from "@effect/sql"
import * as Effect from "effect/Effect"

export default Effect.flatMap(
Pg.client.PgClient,
Sql.client.Client,
(sql) =>
sql`
-- Users
Expand Down
23 changes: 16 additions & 7 deletions examples/realworld/src/model/Article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,37 @@ import { Profile } from "@typed/realworld/model/Profile"

export const ArticleId = Schema.nanoId.pipe(
Schema.brand("ArticleId"),
Schema.description("Unique identifier for the Article")
Schema.annotations({ description: "Unique identifier for the Article" })
)

export const ArticleSlug = Schema.String.pipe(
Schema.brand("ArticleSlug"),
Schema.description("Slug for Article generated from Article.title")
Schema.annotations({ description: "Slug for Article generated from Article.title" })
)
export type ArticleSlug = Schema.Schema.Type<typeof ArticleSlug>

export const ArticleTitle = Schema.String.pipe(Schema.brand("ArticleTitle"), Schema.description("Title of the Article"))
export const ArticleTitle = Schema.String.pipe(
Schema.brand("ArticleTitle"),
Schema.annotations({ description: "Title of the Article" })
)
export type ArticleTitle = Schema.Schema.Type<typeof ArticleTitle>

export const ArticleDescription = Schema.String.pipe(
Schema.brand("ArticleDescription"),
Schema.description("Description of the Article")
Schema.annotations({ description: "Description of the Article" })
)
export type ArticleDescription = Schema.Schema.Type<typeof ArticleDescription>

export const ArticleBody = Schema.String.pipe(Schema.brand("ArticleBody"), Schema.description("Content of the Article"))
export const ArticleBody = Schema.String.pipe(
Schema.brand("ArticleBody"),
Schema.annotations({ description: "Content of the Article" })
)
export type ArticleBody = Schema.Schema.Type<typeof ArticleBody>

export const ArticleTag = Schema.String.pipe(Schema.brand("ArticleTag"), Schema.description("Tag for the Article"))
export const ArticleTag = Schema.String.pipe(
Schema.brand("ArticleTag"),
Schema.annotations({ description: "Tag for the Article" })
)
export type ArticleTag = Schema.Schema.Type<typeof ArticleTag>

export const ArticleTagList = Schema.Array(ArticleTag)
Expand All @@ -43,7 +52,7 @@ export const Article = Schema.Struct({
createdAt: Schema.Date,
updatedAt: Schema.Date
}).pipe(
Schema.identifier("Article")
Schema.annotations({ identifier: "Article" })
)

export interface Article extends Schema.Schema.Type<typeof Article> {}
12 changes: 9 additions & 3 deletions examples/realworld/src/model/Comment.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import * as Schema from "@typed/realworld/lib/Schema"
import { Profile } from "./Profile"

export const CommentId = Schema.nanoId.pipe(Schema.brand("CommentId"), Schema.description("Nano ID for Comment"))
export const CommentId = Schema.nanoId.pipe(
Schema.brand("CommentId"),
Schema.annotations({ description: "Nano ID for Comment" })
)
export type CommentId = Schema.Schema.Type<typeof CommentId>

export const CommentBody = Schema.String.pipe(Schema.brand("CommentBody"), Schema.description("Comment Body"))
export const CommentBody = Schema.String.pipe(
Schema.brand("CommentBody"),
Schema.annotations({ description: "Comment Body" })
)
export type CommentBody = Schema.Schema.Type<typeof CommentBody>

export const Comment = Schema.Struct({
Expand All @@ -13,6 +19,6 @@ export const Comment = Schema.Struct({
author: Profile,
createdAt: Schema.Date,
updatedAt: Schema.Date
}).pipe(Schema.identifier("Comment"))
}).pipe(Schema.annotations({ identifier: "Comment" }))

export interface Comment extends Schema.Schema.Type<typeof Comment> {}
10 changes: 4 additions & 6 deletions examples/realworld/src/model/Password.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import * as Schema from "@typed/realworld/lib/Schema"

export const Password = Schema.Secret.pipe(
export const Password = Schema.Redacted(Schema.String).pipe(
Schema.brand("Password"),
Schema.identifier("Password"),
Schema.description("Password")
Schema.annotations({ identifier: "Password", description: "Password" })
)
export type Password = Schema.Schema.Type<typeof Password>

export const PasswordHash = Schema.Secret.pipe(
export const PasswordHash = Schema.Redacted(Schema.String).pipe(
Schema.brand("PasswordHash"),
Schema.identifier("PasswordHash"),
Schema.description("PasswordHash")
Schema.annotations({ identifier: "PasswordHash", description: "PasswordHash" })
)
export type PasswordHash = Schema.Schema.Type<typeof PasswordHash>
2 changes: 1 addition & 1 deletion examples/realworld/src/model/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { User } from "./User"
export const Profile = User.pipe(
Schema.omit("id", "token"),
Schema.extend(Schema.Struct({ following: Schema.Boolean })),
Schema.identifier("Profile")
Schema.annotations({ identifier: "Profile" })
)

export interface Profile extends Schema.Schema.Type<typeof Profile> {}
17 changes: 10 additions & 7 deletions examples/realworld/src/model/User.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import * as Schema from "@typed/realworld/lib/Schema"

export const UserId = Schema.nanoId.pipe(Schema.brand("UserId"), Schema.description("Nano ID for User"))
export const UserId = Schema.nanoId.pipe(
Schema.brand("UserId"),
Schema.annotations({ description: "Nano ID for User" })
)
export type UserId = Schema.Schema.Type<typeof UserId>

export const Email = Schema.String.pipe(Schema.brand("Email"), Schema.description("Email Address"))
export const Email = Schema.String.pipe(Schema.brand("Email"), Schema.annotations({ description: "Email Address" }))
export type Email = Schema.Schema.Type<typeof Email>

export const Username = Schema.String.pipe(Schema.brand("Username"), Schema.description("Username"))
export const Username = Schema.String.pipe(Schema.brand("Username"), Schema.annotations({ description: "Username" }))
export type Username = Schema.Schema.Type<typeof Username>

export const Bio = Schema.String.pipe(Schema.brand("Bio"), Schema.description("Biography"))
export const Bio = Schema.String.pipe(Schema.brand("Bio"), Schema.annotations({ description: "Biography" }))
export type Bio = Schema.Schema.Type<typeof Bio>

export const Image = Schema.String.pipe(Schema.brand("Image"), Schema.description("Image URL"))
export const Image = Schema.String.pipe(Schema.brand("Image"), Schema.annotations({ description: "Image URL" }))
export type Image = Schema.Schema.Type<typeof Image>

export const JwtToken = Schema.String.pipe(Schema.brand("JwtToken"), Schema.description("JWT Token"))
export const JwtToken = Schema.String.pipe(Schema.brand("JwtToken"), Schema.annotations({ description: "JWT Token" }))
export type JwtToken = Schema.Schema.Type<typeof JwtToken>

export const User = Schema.Struct({
Expand All @@ -25,6 +28,6 @@ export const User = Schema.Struct({
token: JwtToken,
bio: Schema.OptionFromNullishOr(Bio, null),
image: Schema.OptionFromNullishOr(Image, null)
}).pipe(Schema.identifier("User"))
}).pipe(Schema.annotations({ identifier: "User" }))

export interface User extends Schema.Schema.Type<typeof User> {}
2 changes: 1 addition & 1 deletion examples/realworld/src/services/CreateArticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Effect } from "effect"

export const CreateArticleInput = Article.pipe(
Schema.pick("title", "description", "body", "tagList"),
Schema.identifier("CreateArticleInput")
Schema.annotations({ identifier: "CreateArticleInput" })
)
export type CreateArticleInput = Schema.Schema.Type<typeof CreateArticleInput>

Expand Down
2 changes: 1 addition & 1 deletion examples/realworld/src/services/CreateComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Effect } from "effect"

export const CreateCommentInput = Comment.pipe(
Schema.omit("id", "author", "createdAt", "updatedAt"),
Schema.identifier("CreateCommentInput")
Schema.annotations({ identifier: "CreateCommentInput" })
)
export type CreateCommentInput = Schema.Schema.Type<typeof CreateCommentInput>

Expand Down
4 changes: 3 additions & 1 deletion examples/realworld/src/services/DeleteArticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { ArticleSlug } from "@typed/realworld/model"
import type { Unauthorized, Unprocessable } from "@typed/realworld/services/errors"
import type { Effect } from "effect"

export const DeleteArticleInput = Schema.Struct({ slug: ArticleSlug }).pipe(Schema.identifier("DeleteArticleInput"))
export const DeleteArticleInput = Schema.Struct({ slug: ArticleSlug }).pipe(
Schema.annotations({ identifier: "DeleteArticleInput" })
)
export type DeleteArticleInput = Schema.Schema.Type<typeof DeleteArticleInput>

export type DeleteArticleError = Unauthorized | Unprocessable
Expand Down
4 changes: 3 additions & 1 deletion examples/realworld/src/services/DeleteComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { CommentId } from "@typed/realworld/model"
import type { Unauthorized, Unprocessable } from "@typed/realworld/services/errors"
import type { Effect } from "effect"

export const DeleteCommentInput = Schema.Struct({ id: CommentId }).pipe(Schema.identifier("DeleteCommentInput"))
export const DeleteCommentInput = Schema.Struct({ id: CommentId }).pipe(
Schema.annotations({ identifier: "DeleteCommentInput" })
)
export type DeleteCommentInput = Schema.Schema.Type<typeof DeleteCommentInput>

export type DeleteCommentError = Unauthorized | Unprocessable
Expand Down
4 changes: 3 additions & 1 deletion examples/realworld/src/services/GetArticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { ArticleSlug } from "@typed/realworld/model"
import type { Unprocessable } from "@typed/realworld/services/errors"
import type { Effect } from "effect"

export const GetArticleInput = Schema.Struct({ slug: ArticleSlug }).pipe(Schema.identifier("GetArticleInput"))
export const GetArticleInput = Schema.Struct({ slug: ArticleSlug }).pipe(
Schema.annotations({ identifier: "GetArticleInput" })
)
export type GetArticleInput = Schema.Schema.Type<typeof GetArticleInput>

export const GetArticle = Fn<(input: GetArticleInput) => Effect.Effect<Article, Unprocessable>>()("GetArticle")
Expand Down
4 changes: 1 addition & 3 deletions examples/realworld/src/services/GetArticles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export const GetArticlesInput = Schema.Struct({
favorited: Schema.optionalOrNull(Username),
limit: Schema.optionalOrNull(Schema.NumberFromString),
offset: Schema.optionalOrNull(Schema.NumberFromString)
}).pipe(
Schema.identifier("GetArticlesInput")
)
}).annotations({ identifier: "GetArticlesInput" })

export type GetArticlesInput = Schema.Schema.Type<typeof GetArticlesInput>

Expand Down
4 changes: 1 addition & 3 deletions examples/realworld/src/services/GetFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import type { Effect } from "effect"
export const GetFeedInput = Schema.Struct({
limit: Schema.optional(Schema.NumberFromString, { exact: true, as: "Option" }),
offset: Schema.optional(Schema.NumberFromString, { exact: true, as: "Option" })
}).pipe(
Schema.identifier("GetFeedInput")
)
}).annotations({ identifier: "GetFeedInput" })
export type GetFeedInput = Schema.Schema.Type<typeof GetFeedInput>

export type GetFeedError = Unprocessable | Unauthorized
Expand Down
5 changes: 2 additions & 3 deletions examples/realworld/src/services/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import type { Effect } from "effect/Effect"
export const LoginInput = Schema.Struct({
email: Email,
password: Password
}).pipe(
Schema.identifier("LoginInput")
)
}).annotations({ identifier: "LoginInput" })

export type LoginInput = Schema.Schema.Type<typeof LoginInput>

export type LoginError = Unauthorized | Unprocessable
Expand Down
2 changes: 1 addition & 1 deletion examples/realworld/src/services/Register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const RegisterInput = Schema.Struct({
email: Email,
username: Username,
password: Password
}).pipe(Schema.identifier("RegisterInput"))
}).annotations({ identifier: "RegisterInput" })
export type RegisterInput = Schema.Schema.Type<typeof RegisterInput>

export type RegisterError = Unprocessable
Expand Down
4 changes: 1 addition & 3 deletions examples/realworld/src/services/UpdateArticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { CreateArticleInput } from "@typed/realworld/services/CreateArticle"
import type { Unauthorized, Unprocessable } from "@typed/realworld/services/errors"
import type { Effect } from "effect"

export const UpdateArticleInput = Schema.partial(CreateArticleInput).pipe(
Schema.identifier("UpdateArticleInput")
)
export const UpdateArticleInput = Schema.partial(CreateArticleInput).annotations({ identifier: "UpdateArticleInput" })
export type UpdateArticleInput = Schema.Schema.Type<typeof UpdateArticleInput>

export type UpdateArticleError = Unauthorized | Unprocessable
Expand Down
2 changes: 1 addition & 1 deletion examples/realworld/src/services/UpdateUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const UpdateUserInput = Schema.Struct({
password: Schema.OptionFromNullishOr(Password, null),
image: User.fields.image,
bio: User.fields.bio
}).pipe(Schema.identifier("UpdateUserInput"))
}).annotations({ identifier: "UpdateUserInput" })
export type UpdateUserInput = Schema.Schema.Type<typeof UpdateUserInput>

export type UpdateUserError = Unauthorized | Unprocessable
Expand Down
Loading

0 comments on commit 7a04ca9

Please sign in to comment.