@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/CHANGELOG.md +13 -0
- package/README.md +331 -62
- package/dist/bind.d.ts +10 -5
- package/dist/bind.d.ts.map +1 -1
- package/dist/bind.js +8 -2
- package/dist/bind.js.map +1 -1
- package/dist/contract.d.ts +23 -20
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +13 -8
- package/dist/contract.js.map +1 -1
- package/dist/keys.d.ts +10 -10
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +3 -1
- package/dist/keys.js.map +1 -1
- package/dist/makeLiveServer.d.ts +20 -0
- package/dist/makeLiveServer.d.ts.map +1 -0
- package/dist/makeLiveServer.js +26 -0
- package/dist/makeLiveServer.js.map +1 -0
- package/dist/operation.d.ts +37 -25
- package/dist/operation.d.ts.map +1 -1
- package/dist/operation.js +7 -4
- package/dist/operation.js.map +1 -1
- package/dist/rejection.d.ts +27 -27
- package/dist/rejection.d.ts.map +1 -1
- package/dist/rejection.js.map +1 -1
- package/docs/north-star.md +45 -0
- package/docs/roadmap.md +26 -0
- package/package.json +56 -13
- package/src/bind.ts +31 -10
- package/src/contract.ts +59 -39
- package/src/keys.ts +15 -13
- package/src/makeLiveServer.ts +32 -0
- package/src/operation.ts +69 -42
- package/src/rejection.ts +40 -37
package/src/rejection.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type Cause, Effect, Schema } from "effect";
|
|
2
2
|
|
|
3
|
-
export type RejectionValue<
|
|
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<
|
|
6
|
-
RejectionValue<
|
|
7
|
-
Schema.TaggedStruct<
|
|
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<
|
|
18
|
-
readonly [
|
|
19
|
-
?
|
|
20
|
-
:
|
|
21
|
-
? RejectionClass<
|
|
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<
|
|
26
|
-
[
|
|
27
|
-
}[keyof
|
|
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<
|
|
30
|
-
readonly [
|
|
31
|
-
...args: infer
|
|
32
|
-
) => infer
|
|
33
|
-
? (...args:
|
|
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<
|
|
38
|
+
export type RejectionUnion<TSpecs extends RejectionSpecs> = [keyof TSpecs & string] extends [never]
|
|
38
39
|
? Schema.Never
|
|
39
|
-
: Schema.Union<readonly Rejections<
|
|
40
|
+
: Schema.Union<readonly Rejections<TSpecs>[keyof TSpecs & string][]>;
|
|
40
41
|
|
|
41
|
-
export type MatchingTags<
|
|
42
|
-
readonly [
|
|
43
|
-
?
|
|
44
|
-
?
|
|
45
|
-
: `The rejection class under "${
|
|
46
|
-
:
|
|
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<
|
|
50
|
-
readonly error: RejectionUnion<
|
|
51
|
-
readonly Rejection: Rejections<
|
|
52
|
-
readonly reject: Reject<
|
|
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
|
|
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<
|
|
77
|
-
field: Schema.Literals<readonly
|
|
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
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
}
|