github Effect-TS/effect effect@3.14.13

latest releases: @effect/platform@0.90.9, @effect/workflow@0.9.5, @effect/workflow@0.9.4...
4 months ago

Patch Changes

  • #4777 ee77788 Thanks @gcanti! - JSONSchema: apply encodeOption to each example and retain successful results.

    Example

    import { JSONSchema, Schema } from "effect"
    
    const schema = Schema.Struct({
      a: Schema.propertySignature(Schema.BigInt).annotations({
        examples: [1n, 2n]
      })
    })
    
    console.log(JSON.stringify(JSONSchema.make(schema), null, 2))
    /*
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "$defs": {
        "BigInt": {
          "type": "string",
          "description": "a string to be decoded into a bigint"
        }
      },
      "type": "object",
      "required": [
        "a"
      ],
      "properties": {
        "a": {
          "$ref": "#/$defs/BigInt",
          "examples": [
            "1",
            "2"
          ]
        }
      },
      "additionalProperties": false
    }
    */
  • #4701 5fce6ba Thanks @gcanti! - Fix JSONSchema.make for Exit schemas.

    Before

    import { JSONSchema, Schema } from "effect"
    
    const schema = Schema.Exit({
      failure: Schema.String,
      success: Schema.Number,
      defect: Schema.Defect
    })
    
    console.log(JSON.stringify(JSONSchema.make(schema), null, 2))
    /*
    throws
    Error: Missing annotation
    at path: ["cause"]["left"]
    details: Generating a JSON Schema for this schema requires an "identifier" annotation
    schema (Suspend): CauseEncoded<string>
    */

    After

    import { JSONSchema, Schema } from "effect"
    
    const schema = Schema.Exit({
      failure: Schema.String,
      success: Schema.Number,
      defect: Schema.Defect
    })
    
    console.log(JSON.stringify(JSONSchema.make(schema), null, 2))
    /*
    Output:
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "$defs": {
        "CauseEncoded0": {
          "anyOf": [
            {
              "type": "object",
              "required": [
                "_tag"
              ],
              "properties": {
                "_tag": {
                  "type": "string",
                  "enum": [
                    "Empty"
                  ]
                }
              },
              "additionalProperties": false
            },
            {
              "type": "object",
              "required": [
                "_tag",
                "error"
              ],
              "properties": {
                "_tag": {
                  "type": "string",
                  "enum": [
                    "Fail"
                  ]
                },
                "error": {
                  "type": "string"
                }
              },
              "additionalProperties": false
            },
            {
              "type": "object",
              "required": [
                "_tag",
                "defect"
              ],
              "properties": {
                "_tag": {
                  "type": "string",
                  "enum": [
                    "Die"
                  ]
                },
                "defect": {
                  "$ref": "#/$defs/Defect"
                }
              },
              "additionalProperties": false
            },
            {
              "type": "object",
              "required": [
                "_tag",
                "fiberId"
              ],
              "properties": {
                "_tag": {
                  "type": "string",
                  "enum": [
                    "Interrupt"
                  ]
                },
                "fiberId": {
                  "$ref": "#/$defs/FiberIdEncoded"
                }
              },
              "additionalProperties": false
            },
            {
              "type": "object",
              "required": [
                "_tag",
                "left",
                "right"
              ],
              "properties": {
                "_tag": {
                  "type": "string",
                  "enum": [
                    "Sequential"
                  ]
                },
                "left": {
                  "$ref": "#/$defs/CauseEncoded0"
                },
                "right": {
                  "$ref": "#/$defs/CauseEncoded0"
                }
              },
              "additionalProperties": false
            },
            {
              "type": "object",
              "required": [
                "_tag",
                "left",
                "right"
              ],
              "properties": {
                "_tag": {
                  "type": "string",
                  "enum": [
                    "Parallel"
                  ]
                },
                "left": {
                  "$ref": "#/$defs/CauseEncoded0"
                },
                "right": {
                  "$ref": "#/$defs/CauseEncoded0"
                }
              },
              "additionalProperties": false
            }
          ],
          "title": "CauseEncoded<string>"
        },
        "Defect": {
          "$id": "/schemas/unknown",
          "title": "unknown"
        },
        "FiberIdEncoded": {
          "anyOf": [
            {
              "$ref": "#/$defs/FiberIdNoneEncoded"
            },
            {
              "$ref": "#/$defs/FiberIdRuntimeEncoded"
            },
            {
              "$ref": "#/$defs/FiberIdCompositeEncoded"
            }
          ]
        },
        "FiberIdNoneEncoded": {
          "type": "object",
          "required": [
            "_tag"
          ],
          "properties": {
            "_tag": {
              "type": "string",
              "enum": [
                "None"
              ]
            }
          },
          "additionalProperties": false
        },
        "FiberIdRuntimeEncoded": {
          "type": "object",
          "required": [
            "_tag",
            "id",
            "startTimeMillis"
          ],
          "properties": {
            "_tag": {
              "type": "string",
              "enum": [
                "Runtime"
              ]
            },
            "id": {
              "$ref": "#/$defs/Int"
            },
            "startTimeMillis": {
              "$ref": "#/$defs/Int"
            }
          },
          "additionalProperties": false
        },
        "Int": {
          "type": "integer",
          "description": "an integer",
          "title": "int"
        },
        "FiberIdCompositeEncoded": {
          "type": "object",
          "required": [
            "_tag",
            "left",
            "right"
          ],
          "properties": {
            "_tag": {
              "type": "string",
              "enum": [
                "Composite"
              ]
            },
            "left": {
              "$ref": "#/$defs/FiberIdEncoded"
            },
            "right": {
              "$ref": "#/$defs/FiberIdEncoded"
            }
          },
          "additionalProperties": false
        }
      },
      "anyOf": [
        {
          "type": "object",
          "required": [
            "_tag",
            "cause"
          ],
          "properties": {
            "_tag": {
              "type": "string",
              "enum": [
                "Failure"
              ]
            },
            "cause": {
              "$ref": "#/$defs/CauseEncoded0"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [
            "_tag",
            "value"
          ],
          "properties": {
            "_tag": {
              "type": "string",
              "enum": [
                "Success"
              ]
            },
            "value": {
              "type": "number"
            }
          },
          "additionalProperties": false
        }
      ],
      "title": "ExitEncoded<number, string, Defect>"
    }
    */
  • #4775 570e45f Thanks @gcanti! - JSONSchema: preserve original key name when using fromKey followed by annotations, closes #4774.

    Before:

    import { JSONSchema, Schema } from "effect"
    
    const schema = Schema.Struct({
      a: Schema.propertySignature(Schema.String)
        .pipe(Schema.fromKey("b"))
        .annotations({})
    })
    
    console.log(JSON.stringify(JSONSchema.make(schema), null, 2))
    /*
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "required": [
        "a"
      ],
      "properties": {
        "a": {
          "type": "string"
        }
      },
      "additionalProperties": false
    }
    */

    After:

    import { JSONSchema, Schema } from "effect"
    
    const schema = Schema.Struct({
      a: Schema.propertySignature(Schema.String)
        .pipe(Schema.fromKey("b"))
        .annotations({})
    })
    
    console.log(JSON.stringify(JSONSchema.make(schema), null, 2))
    /*
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "type": "object",
      "required": [
        "b"
      ],
      "properties": {
        "b": {
          "type": "string"
        }
      },
      "additionalProperties": false
    }
    */

Don't miss a new effect release

NewReleases is sending notifications on new releases.