Skip to content

Releases: Effect-TS/effect

[email protected]

17 Mar 17:38
596e051
Compare
Choose a tag to compare

Patch Changes

  • #4610 0c4803f Thanks @gcanti! - Preserve specific annotations (e.g., arbitrary) when using Schema.typeSchema, closes #4609.

    Previously, annotations such as arbitrary were lost when calling Schema.typeSchema on a transformation. This update ensures that certain annotations, which depend only on the "to" side of the transformation, are preserved.

    Annotations that are now retained:

    • examples
    • default
    • jsonSchema
    • arbitrary
    • pretty
    • equivalence

    Example

    Before

    import { Arbitrary, FastCheck, Schema } from "effect"
    
    const schema = Schema.NumberFromString.annotations({
      arbitrary: () => (fc) => fc.constant(1)
    })
    
    const to = Schema.typeSchema(schema) // ❌ Annotation is lost
    
    console.log(FastCheck.sample(Arbitrary.make(to), 5))
    /*
    [
      2.5223372357846707e-44,
      -2.145443957806771e+25,
      -3.4028179901346956e+38,
      5.278086259208735e+29,
      1.8216880036222622e-44
    ]
    */

    After

    import { Arbitrary, FastCheck, Schema } from "effect"
    
    const schema = Schema.NumberFromString.annotations({
      arbitrary: () => (fc) => fc.constant(1)
    })
    
    const to = Schema.typeSchema(schema) // ✅ Annotation is now preserved
    
    console.log(FastCheck.sample(Arbitrary.make(to), 5))
    /*
    [ 1, 1, 1, 1, 1 ]
    */
  • #4607 6f65ac4 Thanks @gcanti! - Add support for jsonSchema annotations on SymbolFromSelf index signatures.

    Before

    import { JSONSchema, Schema } from "effect"
    
    const schema = Schema.Record({
      key: Schema.SymbolFromSelf.annotations({ jsonSchema: { type: "string" } }),
      value: Schema.Number
    })
    
    JSONSchema.make(schema)
    /*
    throws:
    Error: Unsupported index signature parameter
    schema (SymbolKeyword): symbol
    */

    After

    import { JSONSchema, Schema } from "effect"
    
    const schema = Schema.Record({
      key: Schema.SymbolFromSelf.annotations({ jsonSchema: { type: "string" } }),
      value: Schema.Number
    })
    
    console.log(JSON.stringify(JSONSchema.make(schema), null, 2))
    /*
    Output:
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "required": [],
      "properties": {},
      "additionalProperties": {
        "type": "number"
      },
      "propertyNames": {
        "type": "string"
      }
    }
    */

@effect/[email protected]

17 Mar 17:40
596e051
Compare
Choose a tag to compare

Patch Changes

@effect/[email protected]

17 Mar 17:39
596e051
Compare
Choose a tag to compare

Patch Changes

@effect/[email protected]

17 Mar 17:39
596e051
Compare
Choose a tag to compare

@effect/[email protected]

17 Mar 17:39
596e051
Compare
Choose a tag to compare

@effect/[email protected]

17 Mar 17:40
596e051
Compare
Choose a tag to compare

@effect/[email protected]

17 Mar 17:39
596e051
Compare
Choose a tag to compare

@effect/[email protected]

17 Mar 17:39
596e051
Compare
Choose a tag to compare

@effect/[email protected]

17 Mar 17:39
596e051
Compare
Choose a tag to compare

@effect/[email protected]

17 Mar 17:39
596e051
Compare
Choose a tag to compare