import * as Schema from "@effect/schema/Schema";
import { parseEither } from "@effect/schema/Parser";
import { isLeft } from "@effect/data/Either";
enum Foo {
Test1 = "test1",
Test2 = "test2",
}
export const StateSchema = Schema.struct({
foo: Schema.enums(Foo),
somestring: Schema.string.pipe(Schema.optional),
}).pipe(
Schema.extend(
Schema.record(
Schema.templateLiteral(
Schema.string,
Schema.literal("-photo-"),
Schema.number,
),
Schema.string,
),
),
);
const state = {
foo: Foo.Test1,
somestring: "djhafk",
"foo-photo-0": "",
"foo-photo-1": "",
"bar-photo-0": "",
}
const parsedState = parseEither(StateSchema)(state);
if (isLeft(parsedState)) {
console.error("ERROR: ", JSON.stringify(parsedState.left, null, 2))
} else {
console.log("OK: ", parsedState.right)
}
import * as Schema from "@effect/schema/Schema";
import { parseEither } from "@effect/schema/Parser";
import { isLeft } from "@effect/data/Either";
enum Foo {
Test1 = "test1",
Test2 = "test2",
}
export const StateSchema = Schema.struct({
foo: Schema.enums(Foo),
somestring: Schema.string.pipe(Schema.optional),
}).pipe(
Schema.extend(
Schema.record(
Schema.templateLiteral(
Schema.string,
Schema.literal("-photo-"),
Schema.number,
),
Schema.string,
),
),
);
const state = {
foo: Foo.Test1,
somestring: "djhafk",
"foo-photo-0": "",
"foo-photo-1": "",
"bar-photo-0": "",
}
const parsedState = parseEither(StateSchema)(state);
if (isLeft(parsedState)) {
console.error("ERROR: ", JSON.stringify(parsedState.left, null, 2))
} else {
console.log("OK: ", parsedState.right)
}