Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.
Releases
@effect/schema@0.68.0
Minor Changes
#2906
f6c7977
Thanks @gcanti! - ## Refactoring of theParseIssue
ModelThe
ParseIssue
model in the@effect/schema/ParseResult
module has undergone a comprehensive redesign and simplification that enhances its expressiveness without compromising functionality. This section explores the motivation and details of this refactoring.Enhanced
Schema.filter
APIThe
Schema.filter
API has been improved to support more complex filtering that can involve multiple properties of a struct. This is especially useful for validations that compare two fields, such as ensuring that apassword
field matches aconfirm_password
field, a common requirement in form validations.Previous Limitations:
Previously, while it was possible to implement a filter that compared two fields, there was no straightforward way to attach validation messages to a specific field. This posed challenges, especially in form validations where precise error reporting is crucial.
Example of Previous Implementation:
In this scenario, while the filter functionally works, the lack of a specific error path (
path: []
) means errors are not as descriptive or helpful as they could be.Specifying Error Paths
With the new improvements, it's now possible to specify an error path along with the message, which enhances error specificity and is particularly beneficial for integration with tools like
react-hook-form
.Updated Implementation Example:
This modification allows the error to be directly associated with the
confirm_password
field, improving clarity for the end-user.Multiple Error Reporting
The refactored API also supports reporting multiple issues at once, which is useful in forms where several validation checks might fail simultaneously.
Example of Multiple Issues Reporting:
The new
ParseIssue
ModelThe
ParseIssue
type has undergone a significant restructuring to improve its expressiveness and simplicity. This new model categorizes issues into leaf and composite types, enhancing clarity and making error handling more systematic.Structure of
ParseIsssue
Type:Key Changes in the Model:
New Members:
Composite
: A new class that aggregates multipleParseIssue
instances.Missing
: Identifies when a required element or value is absent.Unexpected
: Flags unexpected elements or values in the input.Pointer
: Points to the part of the data structure where an issue occurs.Removed Members:
Declaration
,TupleType
,TypeLiteral
,Union
,Member
,Key
, andIndex
have been consolidated under theComposite
type for a more streamlined approach.Definition of
Composite
:Refined Error Messaging System
We've updated our internal function
getErrorMessage
to enhance how error messages are formatted throughout our application. This function constructs an error message that includes the reason for the error, additional details, the path to where the error occurred, and the schema's AST representation if available.Example
Enhancing Tuples with Element Annotations
Annotations are used to add metadata to tuple elements, which can describe the purpose or requirements of each element more clearly. This can be particularly useful when generating documentation or JSON schemas from your schemas.
Missing messages
You can provide custom messages for missing fields or elements using the new
missingMessage
annotation.Example (missing field)
Example (missing element)
Streamlining Annotations
The individual APIs that were previously used to add annotations to schemas have been removed. This change was made because these individual annotation APIs did not provide significant value and were burdensome to maintain. Instead, you can now use the
annotations
method directly or theSchema.annotations
API for apipe
-able approach.Before
Now
Standardize Error Handling for
*Either
,*Sync
andasserts
APIsNow the
*Sync
andasserts
APIs throw aParseError
while before they was throwing a simpleError
with acause
containing aParseIssue
List of Changes
AST
MissingMessageAnnotation
annotationsType
verbose
option fromtoString()
methodsBreaking
Element
toOptionalType
and add anannotations
fieldTupleType
definition: fromrest: ReadonlyArray<AST>
torest: ReadonlyArray<Type>
TemplateLiteral.make
Schema
missingMessage
annotation toPropertySignature
FilterIssue
helper interfaceBreaking
TupleType.Element
typeOptionalElement
API interface withElement
API interfacePropertySignature.GetToken
message
identifier
title
description
examples
default
documentation
jsonSchema
equivalence
concurrency
concurrency
parseIssueTitle
Secret
andSecretFromSelf
ParseResult
isParseError
type guardBreaking
ParseIssue
refactoringMissing
andUnexpected
parse issuesDeclaration
withComposite
Union
in favour ofComposite
TypeLiteral
in favour ofComposite
TupleType
in favour ofComposite
Member
classKey
andIndex
intoPointer
Type
message
field fromOption<string>
tostring | undefined
Refinement
error
field toissue
Transformation
error
field toissue
Missing
ast: AST.Type
fieldmessage
fieldactual
fieldUnexpected
ast
field with amessage
fieldactual
fieldParseError
error
property toissue
missing
export*Either
,*Sync
andasserts
APIs, closes From Discord: Detecting ParseError indecode*Sync
for Error Retry Handling in@tanstack/react-query
#2968Patch Changes
a67b8fe
]:@effect/cli@0.36.47
Patch Changes
f6c7977
,a67b8fe
]:effect@3.3.4
Patch Changes
a67b8fe
Thanks @tim-smart! - use Math.random for Hash.random@effect/experimental@0.16.28
Patch Changes
f6c7977
,a67b8fe
]:@effect/opentelemetry@0.34.21
Patch Changes
a67b8fe
]:@effect/platform@0.57.3
Patch Changes
f6c7977
,a67b8fe
]:@effect/platform-browser@0.36.3
Patch Changes
a67b8fe
]:@effect/platform-bun@0.36.12
Patch Changes
a67b8fe
]:@effect/platform-node@0.51.12
Patch Changes
a67b8fe
]:@effect/platform-node-shared@0.6.12
Patch Changes
a67b8fe
]:@effect/printer@0.33.30
Patch Changes
a67b8fe
]:@effect/printer-ansi@0.33.30
Patch Changes
a67b8fe
]:@effect/rpc@0.30.47
Patch Changes
f6c7977
,a67b8fe
]:@effect/rpc-http@0.28.47
Patch Changes
f6c7977
,a67b8fe
]:@effect/sql@0.3.13
Patch Changes
f6c7977
,a67b8fe
]:@effect/sql-drizzle@0.1.5
Patch Changes
a67b8fe
]:@effect/sql-mssql@0.3.14
Patch Changes
a67b8fe
]:@effect/sql-mysql2@0.3.14
Patch Changes
a67b8fe
]:@effect/sql-pg@0.3.14
Patch Changes
a67b8fe
]:@effect/sql-sqlite-bun@0.3.14
Patch Changes
a67b8fe
]:@effect/sql-sqlite-node@0.3.14
Patch Changes
a67b8fe
]:@effect/sql-sqlite-react-native@0.5.5
Patch Changes
a67b8fe
]:@effect/sql-sqlite-wasm@0.2.32
Patch Changes
a67b8fe
]:@effect/typeclass@0.24.30
Patch Changes
a67b8fe
]:@effect/vitest@0.5.14
Patch Changes
a67b8fe
]: