github Effect-TS/effect @effect/experimental@0.23.1

latest releases: @effect/sql-sqlite-wasm@0.20.4, @effect/typeclass@0.29.13, @effect/vitest@0.13.13...
2 months ago

Patch Changes

  • #3455 e9da539 Thanks @tim-smart! - add VariantSchema module to experimental

    The VariantSchema module can be used to schemas with multiple variants.

    import { VariantSchema } from "@effect/experimental";
    import { Schema } from "@effect/schema";
    import { DateTime } from "effect";
    
    export const { Class, Field, Struct } = VariantSchema.factory({
      variants: ["database", "api"],
      defaultVariant: "database",
    });
    
    class User extends Class<User>("User")({
      id: Schema.Number,
      createdAt: Field({
        database: Schema.DateTimeUtc.pipe(
          Schema.optionalWith({ default: DateTime.unsafeNow }),
        ),
        api: Schema.DateTimeUtc,
      }),
      updateAt: Field({
        database: Schema.DateTimeUtc.pipe(
          Schema.optionalWith({ default: DateTime.unsafeNow }),
        ),
        api: Schema.DateTimeUtc,
      }),
    }) {}
    
    // the class will use the `defaultVariant` fields
    const user = new User({ id: 1 });
    user.createdAt;
    user.updateAt;
    
    // access the `Schema.Struct` variants as static props
    User.database;
    User.api;

Don't miss a new effect release

NewReleases is sending notifications on new releases.