Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-tables-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Add typeConstructor annotation for Schema
1 change: 1 addition & 0 deletions packages/ai/ai/src/Prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,7 @@ export interface PromptEncoded {
export class PromptFromSelf extends Schema.declare(
(u) => isPrompt(u),
{
typeConstructor: { _tag: "effect/ai/Prompt" },
identifier: "PromptFromSelf",
description: "a Prompt instance",
arbitrary: (): Arbitrary.LazyArbitrary<Prompt> => (fc) =>
Expand Down
2 changes: 2 additions & 0 deletions packages/cluster/src/Envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const EnvelopeFromSelf: Schema.Schema<
Envelope.Any,
Envelope.Any
> = Schema.declare(isEnvelope, {
typeConstructor: { _tag: "effect/cluster/Envelope" },
identifier: "Envelope"
})

Expand All @@ -215,6 +216,7 @@ export const RequestFromSelf: Schema.Schema<
Request.Any,
Request.Any
> = Schema.declare((u): u is Request.Any => isEnvelope(u) && u._tag === "Request", {
typeConstructor: { _tag: "effect/cluster/Envelope.Request" },
identifier: "Envelope"
})

Expand Down
7 changes: 5 additions & 2 deletions packages/cluster/src/Reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ export class Chunk<R extends Rpc.Any> extends Data.TaggedClass("Chunk")<{
/**
* @since 1.0.0
*/
static readonly schemaFromSelf: Schema.Schema<Chunk<never>> = Schema.declare((u): u is Chunk<never> =>
isReply(u) && u._tag === "Chunk"
static readonly schemaFromSelf: Schema.Schema<Chunk<never>> = Schema.declare(
(u): u is Chunk<never> => isReply(u) && u._tag === "Chunk",
{
typeConstructor: { _tag: "effect/cluster/Reply.Chunk" }
}
)

/**
Expand Down
24 changes: 24 additions & 0 deletions packages/effect/src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4148,6 +4148,7 @@ export declare namespace Annotations {
* @since 3.10.0
*/
export interface Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []> extends Doc<A> {
readonly typeConstructor?: AST.TypeConstructorAnnotation
readonly identifier?: AST.IdentifierAnnotation
readonly message?: AST.MessageAnnotation
readonly schemaId?: AST.SchemaIdAnnotation
Expand Down Expand Up @@ -4918,6 +4919,7 @@ export class ULID extends String$.pipe(
* @since 3.11.0
*/
export class URLFromSelf extends instanceOf(URL, {
typeConstructor: { _tag: "URL" },
identifier: "URLFromSelf",
arbitrary: (): LazyArbitrary<URL> => (fc) => fc.webUrl().map((s) => new URL(s)),
pretty: () => (url) => url.toString()
Expand Down Expand Up @@ -5850,6 +5852,7 @@ export const RedactedFromSelf = <Value extends Schema.Any>(value: Value): Redact
encode: (value) => redactedParse(ParseResult.encodeUnknown(value))
},
{
typeConstructor: { _tag: "effect/Redacted" },
description: "Redacted(<redacted>)",
pretty: () => () => "Redacted(<redacted>)",
arbitrary: redactedArbitrary,
Expand Down Expand Up @@ -5891,6 +5894,7 @@ export function Redacted<Value extends Schema.Any>(value: Value): Redacted<Value
export class DurationFromSelf extends declare(
duration_.isDuration,
{
typeConstructor: { _tag: "effect/Duration" },
identifier: "DurationFromSelf",
pretty: (): pretty_.Pretty<duration_.Duration> => String,
arbitrary: (): LazyArbitrary<duration_.Duration> => (fc) =>
Expand Down Expand Up @@ -6194,6 +6198,7 @@ export const betweenDuration = <S extends Schema.Any>(
export class Uint8ArrayFromSelf extends declare(
Predicate.isUint8Array,
{
typeConstructor: { _tag: "Uint8Array" },
identifier: "Uint8ArrayFromSelf",
pretty: (): pretty_.Pretty<Uint8Array> => (u8arr) => `new Uint8Array(${JSON.stringify(Array.from(u8arr))})`,
arbitrary: (): LazyArbitrary<Uint8Array> => (fc) => fc.uint8Array(),
Expand Down Expand Up @@ -6781,6 +6786,7 @@ export type DateFromSelfSchemaId = typeof DateFromSelfSchemaId
export class DateFromSelf extends declare(
Predicate.isDate,
{
typeConstructor: { _tag: "Date" },
identifier: "DateFromSelf",
schemaId: DateFromSelfSchemaId,
[DateFromSelfSchemaId]: { noInvalidDate: false },
Expand Down Expand Up @@ -6874,6 +6880,7 @@ export class DateFromNumber extends transform(
export class DateTimeUtcFromSelf extends declare(
(u) => dateTime.isDateTime(u) && dateTime.isUtc(u),
{
typeConstructor: { _tag: "effect/DateTime.Utc" },
identifier: "DateTimeUtcFromSelf",
description: "a DateTime.Utc instance",
pretty: (): pretty_.Pretty<dateTime.Utc> => (dateTime) => dateTime.toString(),
Expand Down Expand Up @@ -6950,6 +6957,7 @@ const timeZoneOffsetArbitrary = (): LazyArbitrary<dateTime.TimeZone.Offset> => (
export class TimeZoneOffsetFromSelf extends declare(
dateTime.isTimeZoneOffset,
{
typeConstructor: { _tag: "effect/DateTime.TimeZone.Offset" },
identifier: "TimeZoneOffsetFromSelf",
description: "a TimeZone.Offset instance",
pretty: (): pretty_.Pretty<dateTime.TimeZone.Offset> => (zone) => zone.toString(),
Expand Down Expand Up @@ -6985,6 +6993,7 @@ const timeZoneNamedArbitrary = (): LazyArbitrary<dateTime.TimeZone.Named> => (fc
export class TimeZoneNamedFromSelf extends declare(
dateTime.isTimeZoneNamed,
{
typeConstructor: { _tag: "effect/DateTime.TimeZone.Named" },
identifier: "TimeZoneNamedFromSelf",
description: "a TimeZone.Named instance",
pretty: (): pretty_.Pretty<dateTime.TimeZone.Named> => (zone) => zone.toString(),
Expand Down Expand Up @@ -7054,6 +7063,7 @@ const timeZoneArbitrary: LazyArbitrary<dateTime.TimeZone> = (fc) =>
export class DateTimeZonedFromSelf extends declare(
(u) => dateTime.isDateTime(u) && dateTime.isZoned(u),
{
typeConstructor: { _tag: "effect/DateTime.Zoned" },
identifier: "DateTimeZonedFromSelf",
description: "a DateTime.Zoned instance",
pretty: (): pretty_.Pretty<dateTime.Zoned> => (dateTime) => dateTime.toString(),
Expand Down Expand Up @@ -7169,6 +7179,7 @@ const OptionFromSelf_ = <Value extends Schema.Any>(value: Value): OptionFromSelf
encode: (value) => optionParse(ParseResult.encodeUnknown(value))
},
{
typeConstructor: { _tag: "effect/Option" },
pretty: optionPretty,
arbitrary: optionArbitrary,
equivalence: option_.getEquivalence
Expand Down Expand Up @@ -7427,6 +7438,7 @@ export const EitherFromSelf = <R extends Schema.All, L extends Schema.All>({ lef
encode: (right, left) => eitherParse(ParseResult.encodeUnknown(right), ParseResult.encodeUnknown(left))
},
{
typeConstructor: { _tag: "effect/Either" },
description: `Either<${format(right)}, ${format(left)}>`,
pretty: eitherPretty,
arbitrary: eitherArbitrary,
Expand Down Expand Up @@ -7615,6 +7627,7 @@ const mapFromSelf_ = <K extends Schema.Any, V extends Schema.Any>(
encode: (Key, Value) => readonlyMapParse(ParseResult.encodeUnknown(Array$(Tuple(Key, Value))))
},
{
typeConstructor: { _tag: "ReadonlyMap" },
description,
pretty: readonlyMapPretty,
arbitrary: mapArbitrary,
Expand Down Expand Up @@ -7797,6 +7810,7 @@ const setFromSelf_ = <Value extends Schema.Any>(value: Value, description: strin
encode: (item) => readonlySetParse(ParseResult.encodeUnknown(Array$(item)))
},
{
typeConstructor: { _tag: "ReadonlySet" },
description,
pretty: readonlySetPretty,
arbitrary: setArbitrary,
Expand Down Expand Up @@ -7898,6 +7912,7 @@ const bigDecimalArbitrary = (): LazyArbitrary<bigDecimal_.BigDecimal> => (fc) =>
export class BigDecimalFromSelf extends declare(
bigDecimal_.isBigDecimal,
{
typeConstructor: { _tag: "effect/BigDecimal" },
identifier: "BigDecimalFromSelf",
pretty: bigDecimalPretty,
arbitrary: bigDecimalArbitrary,
Expand Down Expand Up @@ -8267,6 +8282,7 @@ export const ChunkFromSelf = <Value extends Schema.Any>(value: Value): ChunkFrom
encode: (item) => chunkParse(ParseResult.encodeUnknown(Array$(item)))
},
{
typeConstructor: { _tag: "effect/Chunk" },
description: `Chunk<${format(value)}>`,
pretty: chunkPretty,
arbitrary: chunkArbitrary,
Expand Down Expand Up @@ -8338,6 +8354,7 @@ export const NonEmptyChunkFromSelf = <Value extends Schema.Any>(value: Value): N
encode: (item) => nonEmptyChunkParse(ParseResult.encodeUnknown(NonEmptyArray(item)))
},
{
typeConstructor: { _tag: "effect/Chunk.NonEmptyChunk" },
description: `NonEmptyChunk<${format(value)}>`,
pretty: nonEmptyChunkPretty,
arbitrary: nonEmptyChunkArbitrary,
Expand Down Expand Up @@ -9194,6 +9211,7 @@ const fiberIdPretty: pretty_.Pretty<fiberId_.FiberId> = (fiberId) => {
export class FiberIdFromSelf extends declare(
fiberId_.isFiberId,
{
typeConstructor: { _tag: "effect/FiberId" },
identifier: "FiberIdFromSelf",
pretty: () => fiberIdPretty,
arbitrary: () => fiberIdArbitrary
Expand Down Expand Up @@ -9409,6 +9427,7 @@ export const CauseFromSelf = <E extends Schema.All, D extends Schema.All>({ defe
encode: (error, defect) => causeParse(ParseResult.encodeUnknown(causeEncoded(error, defect)))
},
{
typeConstructor: { _tag: "effect/Cause" },
title: `Cause<${error.ast}>`,
pretty: causePretty,
arbitrary: causeArbitrary
Expand Down Expand Up @@ -9659,6 +9678,7 @@ export const ExitFromSelf = <A extends Schema.All, E extends Schema.All, D exten
)
},
{
typeConstructor: { _tag: "effect/Exit" },
title: `Exit<${success.ast}, ${failure.ast}>`,
pretty: exitPretty,
arbitrary: exitArbitrary
Expand Down Expand Up @@ -9771,6 +9791,7 @@ export const HashSetFromSelf = <Value extends Schema.Any>(
encode: (item) => hashSetParse(ParseResult.encodeUnknown(Array$(item)))
},
{
typeConstructor: { _tag: "effect/HashSet" },
description: `HashSet<${format(value)}>`,
pretty: hashSetPretty,
arbitrary: hashSetArbitrary,
Expand Down Expand Up @@ -9870,6 +9891,7 @@ export const HashMapFromSelf = <K extends Schema.Any, V extends Schema.Any>({ ke
encode: (key, value) => hashMapParse(ParseResult.encodeUnknown(Array$(Tuple(key, value))))
},
{
typeConstructor: { _tag: "effect/HashMap" },
description: `HashMap<${format(key)}, ${format(value)}>`,
pretty: hashMapPretty,
arbitrary: hashMapArbitrary,
Expand Down Expand Up @@ -9956,6 +9978,7 @@ export const ListFromSelf = <Value extends Schema.Any>(
encode: (item) => listParse(ParseResult.encodeUnknown(Array$(item)))
},
{
typeConstructor: { _tag: "effect/List" },
description: `List<${format(value)}>`,
pretty: listPretty,
arbitrary: listArbitrary,
Expand Down Expand Up @@ -10046,6 +10069,7 @@ export const SortedSetFromSelf = <Value extends Schema.Any>(
encode: (item) => sortedSetParse(ParseResult.encodeUnknown(Array$(item)), ordI)
},
{
typeConstructor: { _tag: "effect/SortedSet" },
description: `SortedSet<${format(value)}>`,
pretty: sortedSetPretty,
arbitrary: (arb, ctx) => sortedSetArbitrary(arb, ordA, ctx),
Expand Down
24 changes: 24 additions & 0 deletions packages/effect/src/SchemaAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ export type AST =
// annotations
// -------------------------------------------------------------------------------------

/**
* @category annotations
* @since 3.19.0
* @experimental
*/
export type TypeConstructorAnnotation = {
readonly _tag: string
[key: PropertyKey]: unknown
}

/**
* @category annotations
* @since 3.19.0
* @experimental
*/
export const TypeConstructorAnnotationId: unique symbol = Symbol.for("effect/annotation/TypeConstructor")

/**
* @category annotations
* @since 3.10.0
Expand Down Expand Up @@ -326,6 +343,13 @@ export const getAnnotation: {
Option.none()
)

/**
* @category annotations
* @since 3.19.0
* @experimental
*/
export const getTypeConstructorAnnotation = getAnnotation<TypeConstructorAnnotation>(TypeConstructorAnnotationId)

/**
* @category annotations
* @since 3.10.0
Expand Down
1 change: 1 addition & 0 deletions packages/platform/src/Headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const make = (input: Record.ReadonlyRecord<string, string>): Mutable<Headers> =>
* @category schemas
*/
export const schemaFromSelf: Schema.Schema<Headers> = Schema.declare(isHeaders, {
typeConstructor: { _tag: "effect/platform/Headers" },
identifier: "Headers",
equivalence: () => Record.getEquivalence(String.Equivalence)
})
Expand Down
1 change: 1 addition & 0 deletions packages/platform/src/Multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export class MultipartError extends Schema.TaggedError<MultipartError>()("Multip
* @category Schemas
*/
export const FileSchema: Schema.Schema<PersistedFile> = Schema.declare(isPersistedFile, {
typeConstructor: { _tag: "effect/platform/Multipart.PersistedFile" },
identifier: "PersistedFile",
jsonSchema: {
type: "string",
Expand Down
4 changes: 3 additions & 1 deletion packages/workflow/src/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ export class Complete<A, E> extends Data.TaggedClass("Complete")<{
readonly success: Success
readonly error: Error
}): Schema.Schema<Complete<Success["Type"], Error["Type"]>> {
return Schema.declare((u): u is Complete<Success["Type"], Error["Type"]> => isResult(u) && u._tag === "Complete")
return Schema.declare((u): u is Complete<Success["Type"], Error["Type"]> => isResult(u) && u._tag === "Complete", {
typeConstructor: { _tag: "effect/workflow/Workflow.Complete" }
})
}

/**
Expand Down