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

Commit

Permalink
Fix compilation errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed May 16, 2021
1 parent 77116fd commit 0078454
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
23 changes: 17 additions & 6 deletions apps/frontend/Todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as A from "@effect-ts-demo/core/ext/Array"
import {
array,
constructor,
identity,
Model,
literal,
NonEmptyString,
Expand All @@ -15,10 +16,12 @@ import {
These,
union,
reasonableString,
parseStringE,
leafE,
} from "@effect-ts-demo/core/ext/Schema"
import * as Todo from "@effect-ts-demo/todo-client/Tasks"
import { TaskId, TaskListId } from "@effect-ts-demo/todo-client/Tasks"
import { constant, flow, identity, pipe } from "@effect-ts/core/Function"
import { constant, flow, pipe, identity as ident } from "@effect-ts/core/Function"
import * as O from "@effect-ts/core/Option"
import * as ORD from "@effect-ts/core/Ord"
import { Lens } from "@effect-ts/monocle"
Expand Down Expand Up @@ -151,8 +154,12 @@ const isOrder = (u: any): u is Order & NonEmptyString => u in orders
export const Order = nonEmptyString[">>>"](
pipe(
identity(isOrder),
parser((x) => (isOrder(x) ? These.succeed(x) : These.fail("not order"))),
constructor((x) => (isOrder(x) ? These.succeed(x) : These.fail("not order")))
parser((x) =>
isOrder(x) ? These.succeed(x) : These.fail(leafE(parseStringE("not order")))
),
constructor((x) =>
isOrder(x) ? These.succeed(x) : These.fail(leafE(parseStringE("not order")))
)
)
) // TODO

Expand All @@ -162,8 +169,12 @@ const isOrderDir = (u: any): u is OrderDir & NonEmptyString => u in orders
export const OrderDir = nonEmptyString[">>>"](
pipe(
identity(isOrderDir),
parser((x) => (isOrderDir(x) ? These.succeed(x) : These.fail("not order"))),
constructor((x) => (isOrderDir(x) ? These.succeed(x) : These.fail("not order")))
parser((x) =>
isOrderDir(x) ? These.succeed(x) : These.fail(leafE(parseStringE("not order")))
),
constructor((x) =>
isOrderDir(x) ? These.succeed(x) : These.fail(leafE(parseStringE("not order")))
)
)
) // TODO

Expand All @@ -188,7 +199,7 @@ export function filterByCategory(category: TaskView | string) {
return A.filter((t: Todo.Task) => t.listId === "inbox")
}
case "all": {
return identity
return ident
}
default:
return A.filter((t: Todo.Task) => t.listId === category)
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/features/Tasks/FolderList/FolderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function TLG(g: Todo.TaskListGroup) {
>
<TaskListEntry
{...l}
title={("| -- " + l.title) as S.NonEmptyString}
title={("| -- " + l.title) as S.ReasonableString}
/>
</Box>
)}
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/features/Tasks/FolderList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ const FolderListView = ({ category }: { category: O.Option<Todo.Category> }) =>
A.map(
({ slug, tasks }) =>
new TaskListView({
title: toUpperCaseFirst(slug) as S.NonEmptyString,
title: toUpperCaseFirst(slug) as S.ReasonableString,
slug,
count: tasks.length,
})
)
),
new TaskListView({
title: "Tasks" as S.NonEmptyString,
title: "Tasks" as S.ReasonableString,
slug: "tasks",
count: unfilteredTasks["|>"](filterByCategory("inbox")).length,
}),
Expand Down
16 changes: 8 additions & 8 deletions apps/frontend/features/Tasks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ export function useTasks() {
}

const newTask =
(v: Todo.TaskView | S.NonEmptyString, listId: Todo.TaskListIdU = "inbox") =>
(newTitle: S.NonEmptyString) =>
(v: Todo.TaskView | S.ReasonableString, listId: Todo.TaskListIdU = "inbox") =>
(newTitle: S.ReasonableString) =>
TodoClient.TasksClient.CreateTask({
title: newTitle,
isFavorite: v === "important",
myDay: v === "my-day" ? O.some(new Date()) : O.none,
listId,
})
export function useNewTask(
v: Todo.TaskView | S.NonEmptyString,
v: Todo.TaskView | S.ReasonableString,
listId?: Todo.TaskListId
) {
return useFetch(newTask(v, listId))
Expand Down Expand Up @@ -224,7 +224,7 @@ export function useTaskCommandsResolved(t: Todo.Task) {
}
}

const parseNES = Parser.for(S.nonEmptyString)["|>"](S.condemnFail)
const parseRS = Parser.for(S.reasonableString)["|>"](S.condemnFail)

export function useTaskCommands(id: Todo.TaskId) {
const modifyTasks = useModifyTasks()
Expand Down Expand Up @@ -263,7 +263,7 @@ export function useTaskCommands(id: Todo.TaskId) {
function updateStepTitle(t: Todo.Task) {
return (s: Todo.Step) =>
flow(
parseNES,
parseRS,
T.map((stepTitle) => t["|>"](Todo.Task.updateStep(s, stepTitle))),
T.chain(updateAndRefreshTask)
)
Expand All @@ -287,7 +287,7 @@ export function useTaskCommands(id: Todo.TaskId) {

function addNewTaskStep(t: Todo.Task) {
return flow(
parseNES,
parseRS,
T.map((title) => t["|>"](Todo.Task.addStep(title))),
T.chain(updateAndRefreshTask)
)
Expand All @@ -303,7 +303,7 @@ export function useTaskCommands(id: Todo.TaskId) {

function setTitle(t: Todo.Task) {
return flow(
parseNES,
parseRS,
T.map((v) => t["|>"](Todo.Task.lens["|>"](Lens.prop("title")).set(v))),
T.chain(updateAndRefreshTask)
)
Expand All @@ -321,7 +321,7 @@ export function useTaskCommands(id: Todo.TaskId) {
return (note: string | null) =>
pipe(
EO.fromNullable(note),
EO.chainEffect(parseNES),
EO.chainEffect(parseRS),
T.chain((note) => updateAndRefreshTask({ id: t.id, note }))
)
}
Expand Down
6 changes: 4 additions & 2 deletions packages/core/ext/Schema/_api/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export interface ReasonableStringBrand {
readonly ReasonableString: unique symbol
}

export type ReasonableString = S.NonEmptyString & ReasonableStringBrand
// TODO: Evaluate if it makes sense to inherit the others too.
export type ReasonableString = TextString & LongString & ReasonableStringBrand

export const reasonableStringFromString = pipe(
makeConstrainedFromString<ReasonableString>(1, 256 - 1),
Expand All @@ -45,7 +46,8 @@ export interface LongStringBrand {
readonly LongString: unique symbol
}

export type LongString = S.NonEmptyString & LongStringBrand
// TODO: Evaluate if it makes sense to inherit the others too.
export type LongString = TextString & LongStringBrand

export const longStringFromString = pipe(
makeConstrainedFromString<LongString>(1, 2048 - 1),
Expand Down

0 comments on commit 0078454

Please sign in to comment.