Skip to content

Commit

Permalink
Effect 2.2.2 and Schema 0.61.2
Browse files Browse the repository at this point in the history
Schema parse renamed to decodeUnknown.
  • Loading branch information
steida committed Jan 26, 2024
1 parent f6e0339 commit f1d76d3
Show file tree
Hide file tree
Showing 23 changed files with 766 additions and 772 deletions.
8 changes: 8 additions & 0 deletions .changeset/modern-beds-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@evolu/common": patch
"@evolu/server": patch
---

Effect 2.2.2 and Schema 0.61.2

Schema parse renamed to decodeUnknown.
6 changes: 3 additions & 3 deletions apps/native/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const OwnerActions: FC = () => {
const [isMnemonicShown, setIsMnemonicShown] = useState(false);
const [isRestoreShown, setIsRestoreShown] = useState(false);
const [mnemonic, setMnemonic] = useState("");
const parsedMnemonic = S.parseEither(NonEmptyString1000)(mnemonic);
const parsedMnemonic = S.decodeUnknownEither(NonEmptyString1000)(mnemonic);

const handleMnemonicInputEndEditing = (): void => {
Either.match(parsedMnemonic, {
Expand Down Expand Up @@ -210,7 +210,7 @@ const Todos: FC = () => {
const { create } = useEvolu<Database>();

const [text, setText] = useState("");
const newTodoTitle = S.parseEither(NonEmptyString1000)(text);
const newTodoTitle = S.decodeUnknownEither(NonEmptyString1000)(text);
const handleTextInputEndEditing = (): void => {
Either.match(newTodoTitle, {
onLeft: Function.constVoid,
Expand Down Expand Up @@ -334,7 +334,7 @@ const TodoCategories: FC = () => {
const { rows } = useQuery(todoCategories);

const [text, setText] = useState("");
const newTodoTitle = S.parseEither(NonEmptyString50)(text);
const newTodoTitle = S.decodeUnknownEither(NonEmptyString50)(text);
const handleTextInputEndEditing = (): void => {
Either.match(newTodoTitle, {
onLeft: Function.constVoid,
Expand Down
4 changes: 2 additions & 2 deletions apps/native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"clean": "rm -rf .turbo .expo node_modules dist"
},
"dependencies": {
"@effect/schema": "^0.60.7",
"@effect/schema": "^0.61.2",
"@evolu/react-native": "workspace:*",
"@react-native-community/netinfo": "9.3.10",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"effect": "2.2.0",
"effect": "2.2.2",
"events": "^3.3.0",
"expo": "^49.0.21",
"expo-sqlite": "~11.3.3",
Expand Down
8 changes: 4 additions & 4 deletions apps/web/components/NextJsExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ const createFixtures = (): Promise<void> =>
if (todos.row || categories.row) return;

const { id: notUrgentCategoryId } = evolu.create("todoCategory", {
name: S.parseSync(NonEmptyString50)("Not Urgent"),
name: S.decodeSync(NonEmptyString50)("Not Urgent"),
});

evolu.create("todo", {
title: S.parseSync(NonEmptyString1000)("Try React Suspense"),
title: S.decodeSync(NonEmptyString1000)("Try React Suspense"),
categoryId: notUrgentCategoryId,
});
});
Expand Down Expand Up @@ -417,13 +417,13 @@ const Button: FC<{
};

const prompt = <From extends string, To>(
schema: S.Schema<From, To>,
schema: S.Schema<never, From, To>,
message: string,
onSuccess: (value: To) => void,
): void => {
const value = window.prompt(message);
if (value == null) return; // on cancel
const a = S.parseEither(schema)(value);
const a = S.decodeUnknownEither(schema)(value);
if (a._tag === "Left") {
alert(formatError(a.left));
return;
Expand Down
4 changes: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"clean": "rm -rf .turbo .next node_modules"
},
"dependencies": {
"@effect/schema": "^0.60.7",
"@effect/schema": "^0.61.2",
"@evolu/common": "workspace:*",
"@evolu/react": "workspace:*",
"clsx": "^2.1.0",
"effect": "2.2.0",
"effect": "2.2.2",
"next": "14.1.0",
"nextra": "^2.13.2",
"nextra-theme-docs": "^2.13.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/docs/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ It has to be parsed with the `NonEmptyString1000` schema. Isn't that beautiful?
import * as S from "@effect/schema/Schema";
import { NonEmptyString1000 } from "@evolu/react";

S.parse(NonEmptyString1000)(title);
S.decode(NonEmptyString1000)(title);
```

Learn more about [Schema](https://github.com/effect-ts/schema).
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const { rows } = useQuery(allTodos);
// Create a todo.
const { create } = useEvolu<Database>();
create("todo", {
title: S.parseSync(NonEmptyString1000)("Learn Effect"),
title: S.decodeSync(NonEmptyString1000)("Learn Effect"),
});

// Update a todo.
Expand Down
8 changes: 4 additions & 4 deletions examples/electron-app/src/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ const createFixtures = (): Promise<void> =>
if (todos.row || categories.row) return;

const { id: notUrgentCategoryId } = evolu.create("todoCategory", {
name: S.parseSync(NonEmptyString50)("Not Urgent"),
name: S.decodeSync(NonEmptyString50)("Not Urgent"),
});

evolu.create("todo", {
title: S.parseSync(NonEmptyString1000)("Try React Suspense"),
title: S.decodeSync(NonEmptyString1000)("Try React Suspense"),
categoryId: notUrgentCategoryId,
});
});
Expand Down Expand Up @@ -412,13 +412,13 @@ const Button: FC<{
};

const prompt = <From extends string, To>(
schema: S.Schema<From, To>,
schema: S.Schema<never, From, To>,
message: string,
onSuccess: (value: To) => void,
): void => {
const value = window.prompt(message);
if (value == null) return; // on cancel
const a = S.parseEither(schema)(value);
const a = S.decodeUnknownEither(schema)(value);
if (a._tag === "Left") {
alert(formatError(a.left));
return;
Expand Down
8 changes: 4 additions & 4 deletions examples/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ const createFixtures = (): Promise<void> =>
if (todos.row || categories.row) return;

const { id: notUrgentCategoryId } = evolu.create("todoCategory", {
name: S.parseSync(NonEmptyString50)("Not Urgent"),
name: S.decodeSync(NonEmptyString50)("Not Urgent"),
});

evolu.create("todo", {
title: S.parseSync(NonEmptyString1000)("Try React Suspense"),
title: S.decodeSync(NonEmptyString1000)("Try React Suspense"),
categoryId: notUrgentCategoryId,
});
});
Expand Down Expand Up @@ -414,13 +414,13 @@ const Button: FC<{
};

const prompt = <From extends string, To>(
schema: S.Schema<From, To>,
schema: S.Schema<never, From, To>,
message: string,
onSuccess: (value: To) => void,
): void => {
const value = window.prompt(message);
if (value == null) return; // on cancel
const a = S.parseEither(schema)(value);
const a = S.decodeUnknownEither(schema)(value);
if (a._tag === "Left") {
alert(formatError(a.left));
return;
Expand Down
8 changes: 4 additions & 4 deletions examples/remix/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ const createFixtures = (): Promise<void> =>
if (todos.row || categories.row) return;

const { id: notUrgentCategoryId } = evolu.create("todoCategory", {
name: S.parseSync(NonEmptyString50)("Not Urgent"),
name: S.decodeSync(NonEmptyString50)("Not Urgent"),
});

evolu.create("todo", {
title: S.parseSync(NonEmptyString1000)("Try React Suspense"),
title: S.decodeSync(NonEmptyString1000)("Try React Suspense"),
categoryId: notUrgentCategoryId,
});
});
Expand Down Expand Up @@ -416,13 +416,13 @@ const Button: FC<{
};

const prompt = <From extends string, To>(
schema: S.Schema<From, To>,
schema: S.Schema<never, From, To>,
message: string,
onSuccess: (value: To) => void,
): void => {
const value = window.prompt(message);
if (value == null) return; // on cancel
const a = S.parseEither(schema)(value);
const a = S.decodeUnknownEither(schema)(value);
if (a._tag === "Left") {
alert(formatError(a.left));
return;
Expand Down
8 changes: 4 additions & 4 deletions examples/vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ const createFixtures = (): Promise<void> =>
if (todos.row || categories.row) return;

const { id: notUrgentCategoryId } = evolu.create("todoCategory", {
name: S.parseSync(NonEmptyString50)("Not Urgent"),
name: S.decodeSync(NonEmptyString50)("Not Urgent"),
});

evolu.create("todo", {
title: S.parseSync(NonEmptyString1000)("Try React Suspense"),
title: S.decodeSync(NonEmptyString1000)("Try React Suspense"),
categoryId: notUrgentCategoryId,
});
});
Expand Down Expand Up @@ -412,13 +412,13 @@ const Button: FC<{
};

const prompt = <From extends string, To>(
schema: S.Schema<From, To>,
schema: S.Schema<never, From, To>,
message: string,
onSuccess: (value: To) => void,
): void => {
const value = window.prompt(message);
if (value == null) return; // on cancel
const a = S.parseEither(schema)(value);
const a = S.decodeUnknownEither(schema)(value);
if (a._tag === "Left") {
alert(formatError(a.left));
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-evolu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"eslint-config-next": "14.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "^1.11.1",
"eslint-plugin-jsdoc": "^48.0.2",
"eslint-plugin-jsdoc": "^48.0.4",
"eslint-plugin-node": "^11.1.0",
"next": "14.1.0",
"react": "^18.2.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/evolu-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@
"nanoid": "^5.0.4"
},
"devDependencies": {
"@effect/schema": "^0.60.7",
"@effect/schema": "^0.61.2",
"@evolu/tsconfig": "workspace:*",
"@protobuf-ts/plugin": "^2.9.3",
"@protobuf-ts/protoc": "^2.9.3",
"array-shuffle": "^3.0.0",
"effect": "2.2.0",
"effect": "2.2.2",
"eslint": "^8.56.0",
"eslint-config-evolu": "workspace:*",
"typescript": "^5.3.3",
"vitest": "^1.2.1"
},
"peerDependencies": {
"@effect/schema": "^0.60.7",
"effect": "2.2.0"
"@effect/schema": "^0.61.2",
"effect": "2.2.2"
},
"publishConfig": {
"access": "public"
Expand Down
12 changes: 6 additions & 6 deletions packages/evolu-common/src/Crdt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export const Millis = S.number.pipe(

export type Millis = S.Schema.To<typeof Millis>;

export const initialMillis = S.parseSync(Millis)(
export const initialMillis = S.decodeSync(Millis)(
AllowedTimeRange.greaterThan + 1,
);

export const Counter = S.number.pipe(S.between(0, 65535), S.brand("Counter"));
export type Counter = S.Schema.To<typeof Counter>;

const initialCounter = S.parseSync(Counter)(0);
const initialCounter = S.decodeSync(Counter)(0);

export type TimestampHash = number & Brand.Brand<"TimestampHash">;

Expand All @@ -76,7 +76,7 @@ export const unsafeTimestampFromString = (s: TimestampString): Timestamp => {
export const timestampToHash = (t: Timestamp): TimestampHash =>
murmurhash(timestampToString(t)) as TimestampHash;

const syncNodeId = S.parseSync(NodeId)("0000000000000000");
const syncNodeId = S.decodeSync(NodeId)("0000000000000000");

export const makeSyncTimestamp = (
millis: Millis = initialMillis,
Expand Down Expand Up @@ -106,7 +106,7 @@ export const Time = Context.Tag<Time>();
export const TimeLive = Layer.succeed(
Time,
Time.of({
now: Effect.suspend(() => S.parse(Millis)(Date.now())).pipe(
now: Effect.suspend(() => S.decode(Millis)(Date.now())).pipe(
Effect.catchTag("ParseError", () =>
Effect.fail<TimestampTimeOutOfRangeError>({
_tag: "TimestampTimeOutOfRangeError",
Expand Down Expand Up @@ -177,11 +177,11 @@ const incrementCounter = (
): Either.Either<TimestampCounterOverflowError, Counter> =>
pipe(
Number.increment(counter),
S.parseEither(Counter),
S.decodeEither(Counter),
Either.mapLeft(() => ({ _tag: "TimestampCounterOverflowError" })),
);

const counterMin = S.parseSync(Counter)(0);
const counterMin = S.decodeSync(Counter)(0);

export const sendTimestamp = (
timestamp: Timestamp,
Expand Down
6 changes: 4 additions & 2 deletions packages/evolu-common/src/Crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ export interface NanoId {

export const NanoId = Context.Tag<NanoId>();

export const NodeId: S.BrandSchema<string, string & Brand.Brand<"NodeId">> =
S.string.pipe(S.pattern(/^[\w-]{16}$/), S.brand("NodeId"));
export const NodeId = S.string.pipe(
S.pattern(/^[\w-]{16}$/),
S.brand("NodeId"),
);
export type NodeId = S.Schema.To<typeof NodeId>;

const nanoidForNodeId = customAlphabet("0123456789abcdef", 16);
Expand Down
13 changes: 7 additions & 6 deletions packages/evolu-common/src/Db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const table = <Fields extends TableFields>(
? ValidateFieldsNames<Fields> extends true
? ValidateFieldsHasId<Fields> extends true
? S.Schema<
never,
Types.Simplify<
S.FromStruct<Fields> & S.Schema.From<typeof ReservedColumns>
>,
Expand All @@ -91,15 +92,15 @@ const ReservedColumns = S.struct({
isDeleted: SqliteBoolean,
});

type TableFields = Record<string, S.Schema<any, any>>;
type TableFields = Record<string, S.Schema<never, any, any>>;

type ValidateFieldsTypes<Fields extends TableFields> =
keyof Fields extends infer K
? K extends keyof Fields
? Fields[K] extends TableFields
? ValidateFieldsTypes<Fields[K]>
: // eslint-disable-next-line @typescript-eslint/no-unused-vars
Fields[K] extends S.Schema<infer _I, infer A>
Fields[K] extends S.Schema<never, infer _I, infer A>
? A extends Value
? true
: false
Expand Down Expand Up @@ -258,9 +259,9 @@ export interface Table {

// https://github.com/Effect-TS/schema/releases/tag/v0.18.0
const getPropertySignatures = <I extends { [K in keyof A]: any }, A>(
schema: S.Schema<I, A>,
): { [K in keyof A]: S.Schema<I[K], A[K]> } => {
const out: Record<PropertyKey, S.Schema<any>> = {};
schema: S.Schema<never, I, A>,
): { [K in keyof A]: S.Schema<never, I[K], A[K]> } => {
const out: Record<PropertyKey, S.Schema<never, any, any>> = {};
const propertySignatures = AST.getPropertySignatures(schema.ast);
for (let i = 0; i < propertySignatures.length; i++) {
const propertySignature = propertySignatures[i];
Expand All @@ -270,7 +271,7 @@ const getPropertySignatures = <I extends { [K in keyof A]: any }, A>(
return out as any;
};

export const schemaToTables = (schema: S.Schema<any, any>): Tables =>
export const schemaToTables = (schema: S.Schema<never, any, any>): Tables =>
pipe(
getPropertySignatures(schema),
ReadonlyRecord.toEntries,
Expand Down
Loading

1 comment on commit f1d76d3

@vercel
Copy link

@vercel vercel bot commented on f1d76d3 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

evolu – ./

evolu.vercel.app
evolu-git-main-evolu.vercel.app
www.evolu.dev
evolu-evolu.vercel.app
evolu.dev

Please sign in to comment.