Patch Changes
-
#2892
d9d22e7
Thanks @gcanti! - Schema- add
propertySignature
API interface (with afrom
property) - extend
optional
API interface with afrom
property - extend
optionalWithOptions
API interface with afrom
property
- add
-
#2901
3c080f7
Thanks @gcanti! - make theAST.TemplateLiteral
constructor public -
#2901
3c080f7
Thanks @gcanti! - add support for string literals toSchema.TemplateLiteral
andTemplateLiteral
API interface.Before
import { Schema } from "@effect/schema"; // `https://${string}.com` | `https://${string}.net` const MyUrl = Schema.TemplateLiteral( Schema.Literal("https://"), Schema.String, Schema.Literal("."), Schema.Literal("com", "net"), );
Now
import { Schema } from "@effect/schema"; // `https://${string}.com` | `https://${string}.net` const MyUrl = Schema.TemplateLiteral( "https://", Schema.String, ".", Schema.Literal("com", "net"), );
-
#2905
7d6d875
Thanks @gcanti! - add support for unions torename
, closes #2904 -
#2897
70cda70
Thanks @gcanti! - AddencodedBoundSchema
API.The
encodedBoundSchema
function is similar toencodedSchema
but preserves the refinements up to the first transformation point in the
original schema.Function Signature:
export const encodedBoundSchema = <A, I, R>(schema: Schema<A, I, R>): Schema<I>
The term "bound" in this context refers to the boundary up to which refinements are preserved when extracting the encoded form of a schema. It essentially marks the limit to which initial validations and structure are maintained before any transformations are applied.
Example Usage:
import { Schema } from "@effect/schema"; const schema = Schema.Struct({ foo: Schema.String.pipe(Schema.minLength(3), Schema.compose(Schema.Trim)), }); // The resultingEncodedBoundSchema preserves the minLength(3) refinement, // ensuring the string length condition is enforced but omits the Trim transformation. const resultingEncodedBoundSchema = Schema.encodedBoundSchema(schema); // resultingEncodedBoundSchema is the same as: Schema.Struct({ foo: Schema.String.pipe(Schema.minLength(3)), });
In the provided example:
- Initial Schema: The schema for
foo
includes a refinement to ensure strings have a minimum length of three characters and a transformation to trim the string. - Resulting Schema:
resultingEncodedBoundSchema
maintains theminLength(3)
condition, ensuring that this validation persists. However, it excludes the trimming transformation, focusing solely on the length requirement without altering the string's formatting.
- Initial Schema: The schema for
-
Updated dependencies [
fb91f17
]:- effect@3.2.8