@shivaedev/effect-contract 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/rejection.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { type Cause, Effect, Schema } from "effect";
2
2
 
3
- export type RejectionValue<Tag extends string, Fields extends Schema.Struct.Fields> = Schema.TaggedStruct<Tag, Fields>["Type"] & Cause.YieldableError;
3
+ export type RejectionValue<TTag extends string, TFields extends Schema.Struct.Fields> = Schema.TaggedStruct<TTag, TFields>["Type"] &
4
+ Cause.YieldableError;
4
5
 
5
- export type RejectionClass<Tag extends string, Fields extends Schema.Struct.Fields> = Schema.Class<
6
- RejectionValue<Tag, Fields>,
7
- Schema.TaggedStruct<Tag, Fields>,
6
+ export type RejectionClass<TTag extends string, TFields extends Schema.Struct.Fields> = Schema.Class<
7
+ RejectionValue<TTag, TFields>,
8
+ Schema.TaggedStruct<TTag, TFields>,
8
9
  Cause.YieldableError
9
10
  >;
10
11
 
@@ -14,42 +15,42 @@ export interface RejectionSpecs {
14
15
  readonly [tag: string]: Schema.Struct.Fields | TaggedRejection;
15
16
  }
16
17
 
17
- export type Rejections<Specs extends RejectionSpecs> = {
18
- readonly [Tag in keyof Specs & string]: Specs[Tag] extends TaggedRejection
19
- ? Specs[Tag]
20
- : Specs[Tag] extends Schema.Struct.Fields
21
- ? RejectionClass<Tag, Specs[Tag]>
18
+ export type Rejections<TSpecs extends RejectionSpecs> = {
19
+ readonly [TTag in keyof TSpecs & string]: TSpecs[TTag] extends TaggedRejection
20
+ ? TSpecs[TTag]
21
+ : TSpecs[TTag] extends Schema.Struct.Fields
22
+ ? RejectionClass<TTag, TSpecs[TTag]>
22
23
  : never;
23
24
  };
24
25
 
25
- export type RejectedBy<Specs extends RejectionSpecs> = {
26
- [Tag in keyof Specs & string]: Rejections<Specs>[Tag]["Type"];
27
- }[keyof Specs & string];
26
+ export type RejectedBy<TSpecs extends RejectionSpecs> = {
27
+ [TTag in keyof TSpecs & string]: Rejections<TSpecs>[TTag]["Type"];
28
+ }[keyof TSpecs & string];
28
29
 
29
- export type Reject<Specs extends RejectionSpecs> = {
30
- readonly [Tag in keyof Specs & string]: Rejections<Specs>[Tag] extends new (
31
- ...args: infer Arguments
32
- ) => infer Value
33
- ? (...args: Arguments) => Effect.Effect<never, Value>
30
+ export type Reject<TSpecs extends RejectionSpecs> = {
31
+ readonly [TTag in keyof TSpecs & string]: Rejections<TSpecs>[TTag] extends new (
32
+ ...args: infer TArguments
33
+ ) => infer TValue
34
+ ? (...args: TArguments) => Effect.Effect<never, TValue>
34
35
  : never;
35
36
  };
36
37
 
37
- export type RejectionUnion<Specs extends RejectionSpecs> = [keyof Specs & string] extends [never]
38
+ export type RejectionUnion<TSpecs extends RejectionSpecs> = [keyof TSpecs & string] extends [never]
38
39
  ? Schema.Never
39
- : Schema.Union<readonly Rejections<Specs>[keyof Specs & string][]>;
40
+ : Schema.Union<readonly Rejections<TSpecs>[keyof TSpecs & string][]>;
40
41
 
41
- export type MatchingTags<Specs extends RejectionSpecs> = {
42
- readonly [Tag in keyof Specs]: Specs[Tag] extends TaggedRejection
43
- ? Specs[Tag]["Type"] extends { readonly _tag: Tag }
44
- ? Specs[Tag]
45
- : `The rejection class under "${Tag & string}" must have that _tag`
46
- : Specs[Tag];
42
+ export type MatchingTags<TSpecs extends RejectionSpecs> = {
43
+ readonly [TTag in keyof TSpecs]: TSpecs[TTag] extends TaggedRejection
44
+ ? TSpecs[TTag]["Type"] extends { readonly _tag: TTag }
45
+ ? TSpecs[TTag]
46
+ : `The rejection class under "${TTag & string}" must have that _tag`
47
+ : TSpecs[TTag];
47
48
  };
48
49
 
49
- export interface RejectionSet<Specs extends RejectionSpecs> {
50
- readonly error: RejectionUnion<Specs>;
51
- readonly Rejection: Rejections<Specs>;
52
- readonly reject: Reject<Specs>;
50
+ export interface RejectionSet<TSpecs extends RejectionSpecs> {
51
+ readonly error: RejectionUnion<TSpecs>;
52
+ readonly Rejection: Rejections<TSpecs>;
53
+ readonly reject: Reject<TSpecs>;
53
54
  }
54
55
 
55
56
  interface LooseRejectionSet {
@@ -58,7 +59,7 @@ interface LooseRejectionSet {
58
59
  readonly reject: { readonly [tag: string]: (...args: readonly unknown[]) => Effect.Effect<never, unknown> };
59
60
  }
60
61
 
61
- export function rejectionSet<const Specs extends RejectionSpecs>(specs: Specs): RejectionSet<Specs>;
62
+ export function rejectionSet<const TSpecs extends RejectionSpecs>(specs: TSpecs): RejectionSet<TSpecs>;
62
63
  export function rejectionSet(specs: RejectionSpecs): LooseRejectionSet {
63
64
  const classes = Object.entries(specs).map(([tag, spec]): readonly [string, TaggedRejection] => [
64
65
  tag,
@@ -73,16 +74,18 @@ export function rejectionSet(specs: RejectionSpecs): LooseRejectionSet {
73
74
  };
74
75
  }
75
76
 
76
- export type FieldRejection<Field extends string> = Readonly<{
77
- field: Schema.Literals<readonly Field[]>;
77
+ export type FieldRejection<TField extends string> = Readonly<{
78
+ field: Schema.Literals<readonly TField[]>;
78
79
  message: Schema.String;
79
80
  }>;
80
81
 
81
- export function fieldRejection<const Fields extends Schema.Struct.Fields>(struct: { readonly fields: Fields }): FieldRejection<keyof Fields & string>;
82
- export function fieldRejection<const Fields extends Schema.Struct.Fields, const Field extends keyof Fields & string>(
83
- struct: { readonly fields: Fields },
84
- fields: readonly Field[],
85
- ): FieldRejection<Field>;
82
+ export function fieldRejection<const TFields extends Schema.Struct.Fields>(struct: {
83
+ readonly fields: TFields;
84
+ }): FieldRejection<keyof TFields & string>;
85
+ export function fieldRejection<const TFields extends Schema.Struct.Fields, const TField extends keyof TFields & string>(
86
+ struct: { readonly fields: TFields },
87
+ fields: readonly TField[],
88
+ ): FieldRejection<TField>;
86
89
  export function fieldRejection(struct: { readonly fields: Schema.Struct.Fields }, fields?: readonly string[]): FieldRejection<string> {
87
90
  return { field: Schema.Literals(fields ?? Object.keys(struct.fields)), message: Schema.String };
88
91
  }