github Effect-TS/effect effect@3.14.2

latest releases: @effect/vitest@0.20.7, @effect/typeclass@0.33.7, @effect/sql-sqlite-wasm@0.34.7...
15 days ago

Patch Changes

  • #4646 f87991b Thanks @gcanti! - SchemaAST: add missing getSchemaIdAnnotation API

  • #4646 f87991b Thanks @gcanti! - Arbitrary: fix bug where annotations were ignored.

    Before

    import { Arbitrary, Schema } from "effect"
    
    const schema = Schema.Int.annotations({
      arbitrary: (_, ctx) => (fc) => {
        console.log("context: ", ctx)
        return fc.integer()
      }
    }).pipe(Schema.greaterThan(0), Schema.lessThan(10))
    
    Arbitrary.make(schema)
    // No output ❌

    After

    import { Arbitrary, Schema } from "effect"
    
    const schema = Schema.Int.annotations({
      arbitrary: (_, ctx) => (fc) => {
        console.log("context: ", ctx)
        return fc.integer()
      }
    }).pipe(Schema.greaterThan(0), Schema.lessThan(10))
    
    Arbitrary.make(schema)
    /*
    context:  {
      maxDepth: 2,
      constraints: {
        _tag: 'NumberConstraints',
        constraints: { min: 0, minExcluded: true, max: 10, maxExcluded: true },
        isInteger: true
      }
    }
    */
  • #4648 0a3e3e1 Thanks @gcanti! - Schema: standardSchemaV1 now includes the schema, closes #4494.

    This update fixes an issue where passing Schema.standardSchemaV1(...) directly to JSONSchema.make would throw a TypeError. The schema was missing from the returned object, causing the JSON schema generation to fail.

    Now standardSchemaV1 includes the schema itself, so it can be used with JSONSchema.make without issues.

    Example

    import { JSONSchema, Schema } from "effect"
    
    const Person = Schema.Struct({
      name: Schema.optionalWith(Schema.NonEmptyString, { exact: true })
    })
    
    const standardSchema = Schema.standardSchemaV1(Person)
    
    console.log(JSONSchema.make(standardSchema))
    /*
    {
      '$schema': 'http://json-schema.org/draft-07/schema#',
      '$defs': {
        NonEmptyString: {
          type: 'string',
          description: 'a non empty string',
          title: 'nonEmptyString',
          minLength: 1
        }
      },
      type: 'object',
      required: [],
      properties: { name: { '$ref': '#/$defs/NonEmptyString' } },
      additionalProperties: false
    }
    */

Don't miss a new effect release

NewReleases is sending notifications on new releases.