@entifix/core 0.8.0 → 0.10.0
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/README.md +3 -3
- package/dist/deadline/deadline.d.ts +33 -0
- package/dist/deadline/deadline.d.ts.map +1 -0
- package/dist/deadline/deadline.js +33 -0
- package/dist/deadline/deadline.js.map +1 -0
- package/dist/entity-definition/links/entity-collection-link/entity-collection-link.d.ts +3 -3
- package/dist/entity-definition/links/entity-collection-link/entity-collection-link.d.ts.map +1 -1
- package/dist/entity-definition/links/entity-collection-link/entity-collection-link.js.map +1 -1
- package/dist/entity-definition/links/entity-link/entity-link.d.ts +4 -4
- package/dist/entity-definition/links/entity-link/entity-link.d.ts.map +1 -1
- package/dist/entity-definition/links/entity-link/entity-link.js.map +1 -1
- package/dist/entity-definition/links/entity-link-source/entity-link-source.d.ts +3 -3
- package/dist/entity-definition/links/entity-link-source/entity-link-source.d.ts.map +1 -1
- package/dist/entity-definition/links/entity-link-source/entity-link-source.js.map +1 -1
- package/dist/entity-definition/validate/validate-records.d.ts +23 -6
- package/dist/entity-definition/validate/validate-records.d.ts.map +1 -1
- package/dist/entity-definition/validate/validate-records.js +25 -10
- package/dist/entity-definition/validate/validate-records.js.map +1 -1
- package/dist/envelope/make-envelope.d.ts +7 -1
- package/dist/envelope/make-envelope.d.ts.map +1 -1
- package/dist/envelope/make-envelope.js +12 -0
- package/dist/envelope/make-envelope.js.map +1 -1
- package/dist/envelope/read-envelope.d.ts +14 -7
- package/dist/envelope/read-envelope.d.ts.map +1 -1
- package/dist/envelope/read-envelope.js +36 -25
- package/dist/envelope/read-envelope.js.map +1 -1
- package/dist/envelope/types.d.ts +3 -1
- package/dist/envelope/types.d.ts.map +1 -1
- package/dist/envelope/types.js.map +1 -1
- package/dist/failure/define.d.ts +39 -0
- package/dist/failure/define.d.ts.map +1 -0
- package/dist/failure/define.js +70 -0
- package/dist/failure/define.js.map +1 -0
- package/dist/failure/failure.d.ts +79 -0
- package/dist/failure/failure.d.ts.map +1 -0
- package/dist/failure/failure.js +39 -0
- package/dist/failure/failure.js.map +1 -0
- package/dist/failure/generic.d.ts +141 -0
- package/dist/failure/generic.d.ts.map +1 -0
- package/dist/failure/generic.js +101 -0
- package/dist/failure/generic.js.map +1 -0
- package/dist/failure/index.d.ts +50 -0
- package/dist/failure/index.d.ts.map +1 -0
- package/dist/failure/index.js +47 -0
- package/dist/failure/index.js.map +1 -0
- package/dist/failure/predicates.d.ts +56 -0
- package/dist/failure/predicates.d.ts.map +1 -0
- package/dist/failure/predicates.js +22 -0
- package/dist/failure/predicates.js.map +1 -0
- package/dist/failure/problem.d.ts +49 -0
- package/dist/failure/problem.d.ts.map +1 -0
- package/dist/failure/problem.js +87 -0
- package/dist/failure/problem.js.map +1 -0
- package/dist/failure/registry.d.ts +28 -0
- package/dist/failure/registry.d.ts.map +1 -0
- package/dist/failure/registry.js +36 -0
- package/dist/failure/registry.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/query/fold.d.ts +40 -0
- package/dist/query/fold.d.ts.map +1 -0
- package/dist/query/fold.js +49 -0
- package/dist/query/fold.js.map +1 -0
- package/dist/query/in-memory-query.d.ts +12 -1
- package/dist/query/in-memory-query.d.ts.map +1 -1
- package/dist/query/in-memory-query.js +33 -3
- package/dist/query/in-memory-query.js.map +1 -1
- package/dist/rsql/facet-query-url.d.ts +25 -0
- package/dist/rsql/facet-query-url.d.ts.map +1 -0
- package/dist/rsql/facet-query-url.js +63 -0
- package/dist/rsql/facet-query-url.js.map +1 -0
- package/dist/rsql/index.d.ts +1 -0
- package/dist/rsql/index.d.ts.map +1 -1
- package/dist/rsql/index.js +1 -0
- package/dist/rsql/index.js.map +1 -1
- package/dist/types/EntityFacets.d.ts +30 -0
- package/dist/types/EntityFacets.d.ts.map +1 -0
- package/dist/types/EntityFacets.js +10 -0
- package/dist/types/EntityFacets.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* The failures every host shares — the ones a framework route, an adapter or a
|
|
4
|
+
* transport raises without knowing the domain it serves. A domain names its
|
|
5
|
+
* own refusals beside these, through the same definers.
|
|
6
|
+
*
|
|
7
|
+
* Each code is permanent: a host's message catalog keys on it.
|
|
8
|
+
*/
|
|
9
|
+
/** One field a request got wrong. `pointer` locates it, `code` names the rule. */
|
|
10
|
+
export declare const FieldProblem: Schema.Struct<{
|
|
11
|
+
readonly pointer: Schema.String;
|
|
12
|
+
readonly detail: Schema.String;
|
|
13
|
+
readonly code: Schema.String;
|
|
14
|
+
}>;
|
|
15
|
+
export type FieldProblem = typeof FieldProblem.Type;
|
|
16
|
+
declare const Invalid_base: Schema.Class<Invalid, Schema.TaggedStruct<"Invalid", {
|
|
17
|
+
readonly errors: Schema.$Array<Schema.Struct<{
|
|
18
|
+
readonly pointer: Schema.String;
|
|
19
|
+
readonly detail: Schema.String;
|
|
20
|
+
readonly code: Schema.String;
|
|
21
|
+
}>>;
|
|
22
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"invalid", "invalid">>;
|
|
23
|
+
/** The request breaks rules on its own; every broken one is listed. */
|
|
24
|
+
export declare class Invalid extends Invalid_base {
|
|
25
|
+
}
|
|
26
|
+
declare const InvalidQuery_base: Schema.Class<InvalidQuery, Schema.TaggedStruct<"InvalidQuery", {
|
|
27
|
+
readonly reason: Schema.String;
|
|
28
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"invalidQuery", "invalid">>;
|
|
29
|
+
/** A list, filter or sort the query language cannot accept. */
|
|
30
|
+
export declare class InvalidQuery extends InvalidQuery_base {
|
|
31
|
+
}
|
|
32
|
+
declare const InvalidEnvelope_base: Schema.Class<InvalidEnvelope, Schema.TaggedStruct<"InvalidEnvelope", {
|
|
33
|
+
readonly reason: Schema.String;
|
|
34
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"invalidEnvelope", "invalid">>;
|
|
35
|
+
/**
|
|
36
|
+
* A payload that is not the envelope its reader expected. The sender's fault —
|
|
37
|
+
* a `400` at an HTTP edge and poison on a bus, where redelivering the same
|
|
38
|
+
* bytes produces the same refusal.
|
|
39
|
+
*/
|
|
40
|
+
export declare class InvalidEnvelope extends InvalidEnvelope_base {
|
|
41
|
+
}
|
|
42
|
+
declare const Unauthenticated_base: Schema.Class<Unauthenticated, Schema.TaggedStruct<"Unauthenticated", Record<never, never>>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"unauthenticated", "unauthenticated">>;
|
|
43
|
+
/** No credential, or one that does not verify. */
|
|
44
|
+
export declare class Unauthenticated extends Unauthenticated_base {
|
|
45
|
+
}
|
|
46
|
+
declare const Forbidden_base: Schema.Class<Forbidden, Schema.TaggedStruct<"Forbidden", {
|
|
47
|
+
readonly permission: Schema.optionalKey<Schema.String>;
|
|
48
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"forbidden", "forbidden">>;
|
|
49
|
+
/** A verified caller without the grant. */
|
|
50
|
+
export declare class Forbidden extends Forbidden_base {
|
|
51
|
+
}
|
|
52
|
+
declare const NotFound_base: Schema.Class<NotFound, Schema.TaggedStruct<"NotFound", {
|
|
53
|
+
readonly entity: Schema.optionalKey<Schema.String>;
|
|
54
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"notFound", "notFound">>;
|
|
55
|
+
/** The addressed record does not exist. */
|
|
56
|
+
export declare class NotFound extends NotFound_base {
|
|
57
|
+
}
|
|
58
|
+
declare const DuplicateKey_base: Schema.Class<DuplicateKey, Schema.TaggedStruct<"DuplicateKey", {
|
|
59
|
+
readonly key: Schema.optionalKey<Schema.String>;
|
|
60
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"duplicateKey", "conflict">>;
|
|
61
|
+
/** A write that would duplicate a value the store declares unique. */
|
|
62
|
+
export declare class DuplicateKey extends DuplicateKey_base {
|
|
63
|
+
}
|
|
64
|
+
declare const Declined_base: Schema.Class<Declined, Schema.TaggedStruct<"Declined", {
|
|
65
|
+
readonly reason: Schema.optionalKey<Schema.String>;
|
|
66
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"declined", "declined">>;
|
|
67
|
+
/** A third party, or a rule over other records, said no. */
|
|
68
|
+
export declare class Declined extends Declined_base {
|
|
69
|
+
}
|
|
70
|
+
declare const Contention_base: Schema.Class<Contention, Schema.TaggedStruct<"Contention", Record<never, never>>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"contention", "contention">>;
|
|
71
|
+
/** Lost a race that a retry can win — a claim taken, a transaction aborted. */
|
|
72
|
+
export declare class Contention extends Contention_base {
|
|
73
|
+
}
|
|
74
|
+
declare const Overloaded_base: Schema.Class<Overloaded, Schema.TaggedStruct<"Overloaded", {
|
|
75
|
+
readonly retryAfterSeconds: Schema.optionalKey<Schema.Number>;
|
|
76
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"overloaded", "exhausted">>;
|
|
77
|
+
/** The dependency asked for less load. Stops retries wherever it appears. */
|
|
78
|
+
export declare class Overloaded extends Overloaded_base {
|
|
79
|
+
}
|
|
80
|
+
declare const Unavailable_base: Schema.Class<Unavailable, Schema.TaggedStruct<"Unavailable", {
|
|
81
|
+
readonly dependency: Schema.optionalKey<Schema.String>;
|
|
82
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"unavailable", "unavailable">>;
|
|
83
|
+
/** A dependency could not be reached. */
|
|
84
|
+
export declare class Unavailable extends Unavailable_base {
|
|
85
|
+
}
|
|
86
|
+
declare const UpstreamUnavailable_base: Schema.Class<UpstreamUnavailable, Schema.TaggedStruct<"UpstreamUnavailable", {
|
|
87
|
+
readonly upstream: Schema.optionalKey<Schema.String>;
|
|
88
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"upstreamUnavailable", "unavailable">>;
|
|
89
|
+
/** The service a proxy forwards to could not be reached. */
|
|
90
|
+
export declare class UpstreamUnavailable extends UpstreamUnavailable_base {
|
|
91
|
+
}
|
|
92
|
+
declare const Timeout_base: Schema.Class<Timeout, Schema.TaggedStruct<"Timeout", {
|
|
93
|
+
readonly dependency: Schema.optionalKey<Schema.String>;
|
|
94
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"timeout", "timeout">>;
|
|
95
|
+
/** A dependency did not answer in time. */
|
|
96
|
+
export declare class Timeout extends Timeout_base {
|
|
97
|
+
}
|
|
98
|
+
declare const ProtocolFailure_base: Schema.Class<ProtocolFailure, Schema.TaggedStruct<"ProtocolFailure", {
|
|
99
|
+
readonly reason: Schema.String;
|
|
100
|
+
readonly upstreamStatus: Schema.optionalKey<Schema.Number>;
|
|
101
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"protocol", "protocol">>;
|
|
102
|
+
/**
|
|
103
|
+
* A peer answered something that does not decode — a body that is not a
|
|
104
|
+
* problem, a code nothing registered, a document that does not match its
|
|
105
|
+
* schema.
|
|
106
|
+
*/
|
|
107
|
+
export declare class ProtocolFailure extends ProtocolFailure_base {
|
|
108
|
+
}
|
|
109
|
+
declare const Internal_base: Schema.Class<Internal, Schema.TaggedStruct<"Internal", Record<never, never>>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"internal", "internal">>;
|
|
110
|
+
/** A bug, surfaced as a value. Never carries the bug's text onto a wire. */
|
|
111
|
+
export declare class Internal extends Internal_base {
|
|
112
|
+
}
|
|
113
|
+
declare const IdempotencyKeyMissing_base: Schema.Class<IdempotencyKeyMissing, Schema.TaggedStruct<"IdempotencyKeyMissing", Record<never, never>>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"idempotencyKeyMissing", "invalid">>;
|
|
114
|
+
/** An idempotent route was called without its `Idempotency-Key`. */
|
|
115
|
+
export declare class IdempotencyKeyMissing extends IdempotencyKeyMissing_base {
|
|
116
|
+
}
|
|
117
|
+
declare const IdempotencyKeyReused_base: Schema.Class<IdempotencyKeyReused, Schema.TaggedStruct<"IdempotencyKeyReused", Record<never, never>>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"idempotencyKeyReused", "declined">>;
|
|
118
|
+
/** One `Idempotency-Key` arrived with two different payloads. */
|
|
119
|
+
export declare class IdempotencyKeyReused extends IdempotencyKeyReused_base {
|
|
120
|
+
}
|
|
121
|
+
declare const IdempotencyKeyInFlight_base: Schema.Class<IdempotencyKeyInFlight, Schema.TaggedStruct<"IdempotencyKeyInFlight", Record<never, never>>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"idempotencyKeyInFlight", "contention">>;
|
|
122
|
+
/** The first request under this `Idempotency-Key` has not finished. */
|
|
123
|
+
export declare class IdempotencyKeyInFlight extends IdempotencyKeyInFlight_base {
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* What a store adapter fails with — a datastore, a cache, a bus: the value it
|
|
127
|
+
* guarded already exists, someone else got there first, it could not be
|
|
128
|
+
* reached, it did not answer in time, or it answered something unreadable.
|
|
129
|
+
* A port that talks to storage names this as its failure.
|
|
130
|
+
*/
|
|
131
|
+
export type StoreFailure = DuplicateKey | Contention | Unavailable | Timeout | ProtocolFailure;
|
|
132
|
+
/**
|
|
133
|
+
* The technical part of {@link StoreFailure}: the store failing to answer, as
|
|
134
|
+
* opposed to answering no. A unit of work rolls back and surfaces these; a
|
|
135
|
+
* business failure — a `DuplicateKey` included — is its abort.
|
|
136
|
+
*/
|
|
137
|
+
export type StoreFault = Exclude<StoreFailure, DuplicateKey>;
|
|
138
|
+
/** Whether `value` is a {@link StoreFault}, read by tag. */
|
|
139
|
+
export declare const isStoreFault: (value: unknown) => value is StoreFault;
|
|
140
|
+
export {};
|
|
141
|
+
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/failure/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC;;;;;;GAMG;AAEH,kFAAkF;AAClF,eAAO,MAAM,YAAY;;;;EAIvB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;;;;;;;;AAEpD,uEAAuE;AACvE,qBAAa,OAAQ,SAAQ,YAI5B;CAAG;;;;AAEJ,+DAA+D;AAC/D,qBAAa,YAAa,SAAQ,iBAKjC;CAAG;;;;AAEJ;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,oBAOpC;CAAG;;AAEJ,kDAAkD;AAClD,qBAAa,eAAgB,SAAQ,oBAEqB;CAAG;;;;AAE7D,2CAA2C;AAC3C,qBAAa,SAAU,SAAQ,cAM9B;CAAG;;;;AAEJ,2CAA2C;AAC3C,qBAAa,QAAS,SAAQ,aAI7B;CAAG;;;;AAEJ,sEAAsE;AACtE,qBAAa,YAAa,SAAQ,iBAIjC;CAAG;;;;AAEJ,4DAA4D;AAC5D,qBAAa,QAAS,SAAQ,aAK7B;CAAG;;AAEJ,+EAA+E;AAC/E,qBAAa,UAAW,SAAQ,eAG/B;CAAG;;;;AAEJ,6EAA6E;AAC7E,qBAAa,UAAW,SAAQ,eAI/B;CAAG;;;;AAEJ,yCAAyC;AACzC,qBAAa,WAAY,SAAQ,gBAIhC;CAAG;;;;AAEJ,4DAA4D;AAC5D,qBAAa,mBAAoB,SAAQ,wBAIvC;CAAG;;;;AAEL,2CAA2C;AAC3C,qBAAa,OAAQ,SAAQ,YAI5B;CAAG;;;;;AAEJ;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,oBAUpC;CAAG;;AAEJ,4EAA4E;AAC5E,qBAAa,QAAS,SAAQ,aAG7B;CAAG;;AAEJ,oEAAoE;AACpE,qBAAa,qBAAsB,SAAQ,0BAEiC;CAAG;;AAE/E,iEAAiE;AACjE,qBAAa,oBAAqB,SAAQ,yBAE+B;CAAG;;AAE5E,uEAAuE;AACvE,qBAAa,sBAAuB,SAAQ,2BAK3C;CAAG;AAEJ;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACtB,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,OAAO,GAAG,eAAe,CAAC;AAEtE;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AAS7D,4DAA4D;AAC5D,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UAGsB,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { defineFailure } from './define.js';
|
|
3
|
+
/**
|
|
4
|
+
* The failures every host shares — the ones a framework route, an adapter or a
|
|
5
|
+
* transport raises without knowing the domain it serves. A domain names its
|
|
6
|
+
* own refusals beside these, through the same definers.
|
|
7
|
+
*
|
|
8
|
+
* Each code is permanent: a host's message catalog keys on it.
|
|
9
|
+
*/ /** One field a request got wrong. `pointer` locates it, `code` names the rule. */ export const FieldProblem = Schema.Struct({
|
|
10
|
+
pointer: Schema.String,
|
|
11
|
+
detail: Schema.String,
|
|
12
|
+
code: Schema.String
|
|
13
|
+
});
|
|
14
|
+
/** The request breaks rules on its own; every broken one is listed. */ export class Invalid extends defineFailure('invalid')()('Invalid', 'invalid', {
|
|
15
|
+
errors: Schema.Array(FieldProblem)
|
|
16
|
+
}) {
|
|
17
|
+
}
|
|
18
|
+
/** A list, filter or sort the query language cannot accept. */ export class InvalidQuery extends defineFailure('invalid')()('InvalidQuery', 'invalidQuery', {
|
|
19
|
+
reason: Schema.String
|
|
20
|
+
}, {
|
|
21
|
+
message: ({ reason })=>reason
|
|
22
|
+
}) {
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A payload that is not the envelope its reader expected. The sender's fault —
|
|
26
|
+
* a `400` at an HTTP edge and poison on a bus, where redelivering the same
|
|
27
|
+
* bytes produces the same refusal.
|
|
28
|
+
*/ export class InvalidEnvelope extends defineFailure('invalid')()('InvalidEnvelope', 'invalidEnvelope', {
|
|
29
|
+
reason: Schema.String
|
|
30
|
+
}, {
|
|
31
|
+
message: ({ reason })=>reason
|
|
32
|
+
}) {
|
|
33
|
+
}
|
|
34
|
+
/** No credential, or one that does not verify. */ export class Unauthenticated extends defineFailure('unauthenticated')()('Unauthenticated', 'unauthenticated') {
|
|
35
|
+
}
|
|
36
|
+
/** A verified caller without the grant. */ export class Forbidden extends defineFailure('forbidden')()('Forbidden', 'forbidden', // Which grant was missing: diagnostic, not a leak — the caller already
|
|
37
|
+
// knows what it asked to do.
|
|
38
|
+
{
|
|
39
|
+
permission: Schema.optionalKey(Schema.String)
|
|
40
|
+
}) {
|
|
41
|
+
}
|
|
42
|
+
/** The addressed record does not exist. */ export class NotFound extends defineFailure('notFound')()('NotFound', 'notFound', {
|
|
43
|
+
entity: Schema.optionalKey(Schema.String)
|
|
44
|
+
}) {
|
|
45
|
+
}
|
|
46
|
+
/** A write that would duplicate a value the store declares unique. */ export class DuplicateKey extends defineFailure('conflict')()('DuplicateKey', 'duplicateKey', {
|
|
47
|
+
key: Schema.optionalKey(Schema.String)
|
|
48
|
+
}) {
|
|
49
|
+
}
|
|
50
|
+
/** A third party, or a rule over other records, said no. */ export class Declined extends defineFailure('declined')()('Declined', 'declined', {
|
|
51
|
+
reason: Schema.optionalKey(Schema.String)
|
|
52
|
+
}, {
|
|
53
|
+
message: ({ reason })=>reason != null ? reason : ''
|
|
54
|
+
}) {
|
|
55
|
+
}
|
|
56
|
+
/** Lost a race that a retry can win — a claim taken, a transaction aborted. */ export class Contention extends defineFailure('contention')()('Contention', 'contention') {
|
|
57
|
+
}
|
|
58
|
+
/** The dependency asked for less load. Stops retries wherever it appears. */ export class Overloaded extends defineFailure('exhausted')()('Overloaded', 'overloaded', {
|
|
59
|
+
retryAfterSeconds: Schema.optionalKey(Schema.Number)
|
|
60
|
+
}) {
|
|
61
|
+
}
|
|
62
|
+
/** A dependency could not be reached. */ export class Unavailable extends defineFailure('unavailable')()('Unavailable', 'unavailable', {
|
|
63
|
+
dependency: Schema.optionalKey(Schema.String)
|
|
64
|
+
}) {
|
|
65
|
+
}
|
|
66
|
+
/** The service a proxy forwards to could not be reached. */ export class UpstreamUnavailable extends defineFailure('unavailable')()('UpstreamUnavailable', 'upstreamUnavailable', {
|
|
67
|
+
upstream: Schema.optionalKey(Schema.String)
|
|
68
|
+
}) {
|
|
69
|
+
}
|
|
70
|
+
/** A dependency did not answer in time. */ export class Timeout extends defineFailure('timeout')()('Timeout', 'timeout', {
|
|
71
|
+
dependency: Schema.optionalKey(Schema.String)
|
|
72
|
+
}) {
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A peer answered something that does not decode — a body that is not a
|
|
76
|
+
* problem, a code nothing registered, a document that does not match its
|
|
77
|
+
* schema.
|
|
78
|
+
*/ export class ProtocolFailure extends defineFailure('protocol')()('ProtocolFailure', 'protocol', {
|
|
79
|
+
reason: Schema.String,
|
|
80
|
+
upstreamStatus: Schema.optionalKey(Schema.Number)
|
|
81
|
+
}, {
|
|
82
|
+
message: ({ reason })=>reason
|
|
83
|
+
}) {
|
|
84
|
+
}
|
|
85
|
+
/** A bug, surfaced as a value. Never carries the bug's text onto a wire. */ export class Internal extends defineFailure('internal')()('Internal', 'internal') {
|
|
86
|
+
}
|
|
87
|
+
/** An idempotent route was called without its `Idempotency-Key`. */ export class IdempotencyKeyMissing extends defineFailure('invalid')()('IdempotencyKeyMissing', 'idempotencyKeyMissing') {
|
|
88
|
+
}
|
|
89
|
+
/** One `Idempotency-Key` arrived with two different payloads. */ export class IdempotencyKeyReused extends defineFailure('declined')()('IdempotencyKeyReused', 'idempotencyKeyReused') {
|
|
90
|
+
}
|
|
91
|
+
/** The first request under this `Idempotency-Key` has not finished. */ export class IdempotencyKeyInFlight extends defineFailure('contention')()('IdempotencyKeyInFlight', 'idempotencyKeyInFlight') {
|
|
92
|
+
}
|
|
93
|
+
const STORE_FAULT_TAGS = new Set([
|
|
94
|
+
'Contention',
|
|
95
|
+
'Unavailable',
|
|
96
|
+
'Timeout',
|
|
97
|
+
'ProtocolFailure'
|
|
98
|
+
]);
|
|
99
|
+
/** Whether `value` is a {@link StoreFault}, read by tag. */ export const isStoreFault = (value)=>typeof value === 'object' && value !== null && STORE_FAULT_TAGS.has(value._tag);
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=generic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/failure/generic.ts"],"sourcesContent":["import { Schema } from 'effect';\n\nimport { defineFailure } from './define.js';\n\n/**\n * The failures every host shares — the ones a framework route, an adapter or a\n * transport raises without knowing the domain it serves. A domain names its\n * own refusals beside these, through the same definers.\n *\n * Each code is permanent: a host's message catalog keys on it.\n */\n\n/** One field a request got wrong. `pointer` locates it, `code` names the rule. */\nexport const FieldProblem = Schema.Struct({\n pointer: Schema.String,\n detail: Schema.String,\n code: Schema.String,\n});\nexport type FieldProblem = typeof FieldProblem.Type;\n\n/** The request breaks rules on its own; every broken one is listed. */\nexport class Invalid extends defineFailure('invalid')<Invalid>()(\n 'Invalid',\n 'invalid',\n { errors: Schema.Array(FieldProblem) },\n) {}\n\n/** A list, filter or sort the query language cannot accept. */\nexport class InvalidQuery extends defineFailure('invalid')<InvalidQuery>()(\n 'InvalidQuery',\n 'invalidQuery',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/**\n * A payload that is not the envelope its reader expected. The sender's fault —\n * a `400` at an HTTP edge and poison on a bus, where redelivering the same\n * bytes produces the same refusal.\n */\nexport class InvalidEnvelope extends defineFailure(\n 'invalid',\n)<InvalidEnvelope>()(\n 'InvalidEnvelope',\n 'invalidEnvelope',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/** No credential, or one that does not verify. */\nexport class Unauthenticated extends defineFailure(\n 'unauthenticated',\n)<Unauthenticated>()('Unauthenticated', 'unauthenticated') {}\n\n/** A verified caller without the grant. */\nexport class Forbidden extends defineFailure('forbidden')<Forbidden>()(\n 'Forbidden',\n 'forbidden',\n // Which grant was missing: diagnostic, not a leak — the caller already\n // knows what it asked to do.\n { permission: Schema.optionalKey(Schema.String) },\n) {}\n\n/** The addressed record does not exist. */\nexport class NotFound extends defineFailure('notFound')<NotFound>()(\n 'NotFound',\n 'notFound',\n { entity: Schema.optionalKey(Schema.String) },\n) {}\n\n/** A write that would duplicate a value the store declares unique. */\nexport class DuplicateKey extends defineFailure('conflict')<DuplicateKey>()(\n 'DuplicateKey',\n 'duplicateKey',\n { key: Schema.optionalKey(Schema.String) },\n) {}\n\n/** A third party, or a rule over other records, said no. */\nexport class Declined extends defineFailure('declined')<Declined>()(\n 'Declined',\n 'declined',\n { reason: Schema.optionalKey(Schema.String) },\n { message: ({ reason }) => reason ?? '' },\n) {}\n\n/** Lost a race that a retry can win — a claim taken, a transaction aborted. */\nexport class Contention extends defineFailure('contention')<Contention>()(\n 'Contention',\n 'contention',\n) {}\n\n/** The dependency asked for less load. Stops retries wherever it appears. */\nexport class Overloaded extends defineFailure('exhausted')<Overloaded>()(\n 'Overloaded',\n 'overloaded',\n { retryAfterSeconds: Schema.optionalKey(Schema.Number) },\n) {}\n\n/** A dependency could not be reached. */\nexport class Unavailable extends defineFailure('unavailable')<Unavailable>()(\n 'Unavailable',\n 'unavailable',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/** The service a proxy forwards to could not be reached. */\nexport class UpstreamUnavailable extends defineFailure(\n 'unavailable',\n)<UpstreamUnavailable>()('UpstreamUnavailable', 'upstreamUnavailable', {\n upstream: Schema.optionalKey(Schema.String),\n}) {}\n\n/** A dependency did not answer in time. */\nexport class Timeout extends defineFailure('timeout')<Timeout>()(\n 'Timeout',\n 'timeout',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A peer answered something that does not decode — a body that is not a\n * problem, a code nothing registered, a document that does not match its\n * schema.\n */\nexport class ProtocolFailure extends defineFailure(\n 'protocol',\n)<ProtocolFailure>()(\n 'ProtocolFailure',\n 'protocol',\n {\n reason: Schema.String,\n upstreamStatus: Schema.optionalKey(Schema.Number),\n },\n { message: ({ reason }) => reason },\n) {}\n\n/** A bug, surfaced as a value. Never carries the bug's text onto a wire. */\nexport class Internal extends defineFailure('internal')<Internal>()(\n 'Internal',\n 'internal',\n) {}\n\n/** An idempotent route was called without its `Idempotency-Key`. */\nexport class IdempotencyKeyMissing extends defineFailure(\n 'invalid',\n)<IdempotencyKeyMissing>()('IdempotencyKeyMissing', 'idempotencyKeyMissing') {}\n\n/** One `Idempotency-Key` arrived with two different payloads. */\nexport class IdempotencyKeyReused extends defineFailure(\n 'declined',\n)<IdempotencyKeyReused>()('IdempotencyKeyReused', 'idempotencyKeyReused') {}\n\n/** The first request under this `Idempotency-Key` has not finished. */\nexport class IdempotencyKeyInFlight extends defineFailure(\n 'contention',\n)<IdempotencyKeyInFlight>()(\n 'IdempotencyKeyInFlight',\n 'idempotencyKeyInFlight',\n) {}\n\n/**\n * What a store adapter fails with — a datastore, a cache, a bus: the value it\n * guarded already exists, someone else got there first, it could not be\n * reached, it did not answer in time, or it answered something unreadable.\n * A port that talks to storage names this as its failure.\n */\nexport type StoreFailure =\n DuplicateKey | Contention | Unavailable | Timeout | ProtocolFailure;\n\n/**\n * The technical part of {@link StoreFailure}: the store failing to answer, as\n * opposed to answering no. A unit of work rolls back and surfaces these; a\n * business failure — a `DuplicateKey` included — is its abort.\n */\nexport type StoreFault = Exclude<StoreFailure, DuplicateKey>;\n\nconst STORE_FAULT_TAGS: ReadonlySet<string> = new Set([\n 'Contention',\n 'Unavailable',\n 'Timeout',\n 'ProtocolFailure',\n]);\n\n/** Whether `value` is a {@link StoreFault}, read by tag. */\nexport const isStoreFault = (value: unknown): value is StoreFault =>\n typeof value === 'object' &&\n value !== null &&\n STORE_FAULT_TAGS.has((value as { readonly _tag?: unknown })._tag as string);\n"],"names":["Schema","defineFailure","FieldProblem","Struct","pointer","String","detail","code","Invalid","errors","Array","InvalidQuery","reason","message","InvalidEnvelope","Unauthenticated","Forbidden","permission","optionalKey","NotFound","entity","DuplicateKey","key","Declined","Contention","Overloaded","retryAfterSeconds","Number","Unavailable","dependency","UpstreamUnavailable","upstream","Timeout","ProtocolFailure","upstreamStatus","Internal","IdempotencyKeyMissing","IdempotencyKeyReused","IdempotencyKeyInFlight","STORE_FAULT_TAGS","Set","isStoreFault","value","has","_tag"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,QAAQ,cAAc;AAE5C;;;;;;CAMC,GAED,gFAAgF,GAChF,OAAO,MAAMC,eAAeF,OAAOG,MAAM,CAAC;IACxCC,SAASJ,OAAOK,MAAM;IACtBC,QAAQN,OAAOK,MAAM;IACrBE,MAAMP,OAAOK,MAAM;AACrB,GAAG;AAGH,qEAAqE,GACrE,OAAO,MAAMG,gBAAgBP,cAAc,aACzC,WACA,WACA;IAAEQ,QAAQT,OAAOU,KAAK,CAACR;AAAc;AACpC;AAEH,6DAA6D,GAC7D,OAAO,MAAMS,qBAAqBV,cAAc,aAC9C,gBACA,gBACA;IAAEW,QAAQZ,OAAOK,MAAM;AAAC,GACxB;IAAEQ,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH;;;;CAIC,GACD,OAAO,MAAME,wBAAwBb,cACnC,aAEA,mBACA,mBACA;IAAEW,QAAQZ,OAAOK,MAAM;AAAC,GACxB;IAAEQ,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH,gDAAgD,GAChD,OAAO,MAAMG,wBAAwBd,cACnC,qBACmB,mBAAmB;AAAoB;AAE5D,yCAAyC,GACzC,OAAO,MAAMe,kBAAkBf,cAAc,eAC3C,aACA,aACA,uEAAuE;AACvE,6BAA6B;AAC7B;IAAEgB,YAAYjB,OAAOkB,WAAW,CAAClB,OAAOK,MAAM;AAAE;AAC/C;AAEH,yCAAyC,GACzC,OAAO,MAAMc,iBAAiBlB,cAAc,cAC1C,YACA,YACA;IAAEmB,QAAQpB,OAAOkB,WAAW,CAAClB,OAAOK,MAAM;AAAE;AAC3C;AAEH,oEAAoE,GACpE,OAAO,MAAMgB,qBAAqBpB,cAAc,cAC9C,gBACA,gBACA;IAAEqB,KAAKtB,OAAOkB,WAAW,CAAClB,OAAOK,MAAM;AAAE;AACxC;AAEH,0DAA0D,GAC1D,OAAO,MAAMkB,iBAAiBtB,cAAc,cAC1C,YACA,YACA;IAAEW,QAAQZ,OAAOkB,WAAW,CAAClB,OAAOK,MAAM;AAAE,GAC5C;IAAEQ,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA,iBAAAA,SAAU;AAAG;AACvC;AAEH,6EAA6E,GAC7E,OAAO,MAAMY,mBAAmBvB,cAAc,gBAC5C,cACA;AACC;AAEH,2EAA2E,GAC3E,OAAO,MAAMwB,mBAAmBxB,cAAc,eAC5C,cACA,cACA;IAAEyB,mBAAmB1B,OAAOkB,WAAW,CAAClB,OAAO2B,MAAM;AAAE;AACtD;AAEH,uCAAuC,GACvC,OAAO,MAAMC,oBAAoB3B,cAAc,iBAC7C,eACA,eACA;IAAE4B,YAAY7B,OAAOkB,WAAW,CAAClB,OAAOK,MAAM;AAAE;AAC/C;AAEH,0DAA0D,GAC1D,OAAO,MAAMyB,4BAA4B7B,cACvC,iBACuB,uBAAuB,uBAAuB;IACrE8B,UAAU/B,OAAOkB,WAAW,CAAClB,OAAOK,MAAM;AAC5C;AAAI;AAEJ,yCAAyC,GACzC,OAAO,MAAM2B,gBAAgB/B,cAAc,aACzC,WACA,WACA;IAAE4B,YAAY7B,OAAOkB,WAAW,CAAClB,OAAOK,MAAM;AAAE;AAC/C;AAEH;;;;CAIC,GACD,OAAO,MAAM4B,wBAAwBhC,cACnC,cAEA,mBACA,YACA;IACEW,QAAQZ,OAAOK,MAAM;IACrB6B,gBAAgBlC,OAAOkB,WAAW,CAAClB,OAAO2B,MAAM;AAClD,GACA;IAAEd,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH,0EAA0E,GAC1E,OAAO,MAAMuB,iBAAiBlC,cAAc,cAC1C,YACA;AACC;AAEH,kEAAkE,GAClE,OAAO,MAAMmC,8BAA8BnC,cACzC,aACyB,yBAAyB;AAA0B;AAE9E,+DAA+D,GAC/D,OAAO,MAAMoC,6BAA6BpC,cACxC,cACwB,wBAAwB;AAAyB;AAE3E,qEAAqE,GACrE,OAAO,MAAMqC,+BAA+BrC,cAC1C,gBAEA,0BACA;AACC;AAkBH,MAAMsC,mBAAwC,IAAIC,IAAI;IACpD;IACA;IACA;IACA;CACD;AAED,0DAA0D,GAC1D,OAAO,MAAMC,eAAe,CAACC,QAC3B,OAAOA,UAAU,YACjBA,UAAU,QACVH,iBAAiBI,GAAG,CAAC,AAACD,MAAsCE,IAAI,EAAY"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export * from './failure.js';
|
|
2
|
+
export * from './generic.js';
|
|
3
|
+
export * from './predicates.js';
|
|
4
|
+
export * from './problem.js';
|
|
5
|
+
export * from './registry.js';
|
|
6
|
+
/**
|
|
7
|
+
* Everything a host needs to define and match failures, under one name
|
|
8
|
+
* ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* class DuplicateSlug extends Failure.conflict<DuplicateSlug>()(
|
|
12
|
+
* 'DuplicateSlug',
|
|
13
|
+
* 'duplicateSlug',
|
|
14
|
+
* { slug: Schema.String },
|
|
15
|
+
* ) {}
|
|
16
|
+
*
|
|
17
|
+
* effect.pipe(Effect.catchIf(Failure.isCategory('conflict'), …))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const Failure: {
|
|
21
|
+
readonly invalid: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "invalid">>;
|
|
22
|
+
readonly unauthenticated: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "unauthenticated">>;
|
|
23
|
+
readonly forbidden: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "forbidden">>;
|
|
24
|
+
readonly notFound: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "notFound">>;
|
|
25
|
+
readonly conflict: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "conflict">>;
|
|
26
|
+
readonly declined: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "declined">>;
|
|
27
|
+
readonly contention: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "contention">>;
|
|
28
|
+
readonly exhausted: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "exhausted">>;
|
|
29
|
+
readonly unavailable: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "unavailable">>;
|
|
30
|
+
readonly timeout: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "timeout">>;
|
|
31
|
+
readonly protocol: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "protocol">>;
|
|
32
|
+
readonly internal: <Self = never>() => <const Tag extends string, const Code extends string, const Fields extends import("effect/Schema").Struct.Fields = Record<never, never>>(tag: Tag, code: Code, fields?: Fields, options?: import("./define.js").FailureOptions<import("effect/Schema").Struct.Type<Fields>>) => [Self] extends [never] ? "Missing `Self` generic - use `class Self extends Schema.TaggedError<Self>(...)`" : import("effect/Schema").Class<Self, import("effect/Schema").TaggedStruct<Tag, Fields>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<Code, "internal">>;
|
|
33
|
+
readonly is: import("./predicates.js").FailureGuard<import("./failure.js").EntifixFailure<string, string, import("./failure.js").FailureCategory>>;
|
|
34
|
+
readonly isTag: <const Tag extends string>(tag: Tag) => import("./predicates.js").FailureGuard<{
|
|
35
|
+
readonly _tag: Tag;
|
|
36
|
+
}>;
|
|
37
|
+
readonly isCategory: <const C extends import("./failure.js").FailureCategory>(category: C) => import("./predicates.js").FailureGuard<{
|
|
38
|
+
readonly category: C;
|
|
39
|
+
}>;
|
|
40
|
+
readonly isFamily: <const F extends import("./failure.js").FailureFamily>(family: F) => import("./predicates.js").FailureGuard<{
|
|
41
|
+
readonly family: F;
|
|
42
|
+
}>;
|
|
43
|
+
readonly and: <A, B>(left: import("./predicates.js").FailureGuard<A>, right: import("./predicates.js").FailureGuard<B>) => import("./predicates.js").FailureGuard<A & B>;
|
|
44
|
+
readonly or: <A, B>(left: import("./predicates.js").FailureGuard<A>, right: import("./predicates.js").FailureGuard<B>) => import("./predicates.js").FailureGuard<A | B>;
|
|
45
|
+
readonly not: <S>(guard: import("./predicates.js").FailureGuard<S>) => <E>(value: E) => value is Exclude<E, S>;
|
|
46
|
+
readonly when: <Shape, R = never>(guard: import("./predicates.js").FailureGuard<Shape>, condition: (failure: Shape) => import("effect/Effect").Effect<boolean, never, R>) => import("./predicates.js").EffectfulFailurePredicate<Shape, R>;
|
|
47
|
+
readonly lookup: (code: string) => import("./registry.js").RegisteredFailure | undefined;
|
|
48
|
+
readonly registered: () => readonly import("./registry.js").RegisteredFailure[];
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/failure/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAE9B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,OAAO;2CAwBqR,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;mDAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;6CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;4CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;4CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;4CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;8CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;6CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;+CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;2CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;4CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;4CAAxP,wBAA6B,EAAC,yBAA8B,EAAC,iFAAqE,EAAM,QAAa,EAAC,UAAe,EAAC,eAAoB,EAAC,2FAA6D;;;;;;;;;;;;;4EAA89B,CAAC,EAAE,QAAQ;;;;CADhgD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { defineFailure } from './define.js';
|
|
2
|
+
import { and, isCategory, isFailure, isFamily, isTag, not, or, when } from './predicates.js';
|
|
3
|
+
import { lookupFailure, registeredFailures } from './registry.js';
|
|
4
|
+
export * from './failure.js';
|
|
5
|
+
export * from './generic.js';
|
|
6
|
+
export * from './predicates.js';
|
|
7
|
+
export * from './problem.js';
|
|
8
|
+
export * from './registry.js';
|
|
9
|
+
/**
|
|
10
|
+
* Everything a host needs to define and match failures, under one name
|
|
11
|
+
* ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* class DuplicateSlug extends Failure.conflict<DuplicateSlug>()(
|
|
15
|
+
* 'DuplicateSlug',
|
|
16
|
+
* 'duplicateSlug',
|
|
17
|
+
* { slug: Schema.String },
|
|
18
|
+
* ) {}
|
|
19
|
+
*
|
|
20
|
+
* effect.pipe(Effect.catchIf(Failure.isCategory('conflict'), …))
|
|
21
|
+
* ```
|
|
22
|
+
*/ export const Failure = {
|
|
23
|
+
invalid: defineFailure('invalid'),
|
|
24
|
+
unauthenticated: defineFailure('unauthenticated'),
|
|
25
|
+
forbidden: defineFailure('forbidden'),
|
|
26
|
+
notFound: defineFailure('notFound'),
|
|
27
|
+
conflict: defineFailure('conflict'),
|
|
28
|
+
declined: defineFailure('declined'),
|
|
29
|
+
contention: defineFailure('contention'),
|
|
30
|
+
exhausted: defineFailure('exhausted'),
|
|
31
|
+
unavailable: defineFailure('unavailable'),
|
|
32
|
+
timeout: defineFailure('timeout'),
|
|
33
|
+
protocol: defineFailure('protocol'),
|
|
34
|
+
internal: defineFailure('internal'),
|
|
35
|
+
is: isFailure,
|
|
36
|
+
isTag,
|
|
37
|
+
isCategory,
|
|
38
|
+
isFamily,
|
|
39
|
+
and,
|
|
40
|
+
or,
|
|
41
|
+
not,
|
|
42
|
+
when,
|
|
43
|
+
lookup: lookupFailure,
|
|
44
|
+
registered: registeredFailures
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/failure/index.ts"],"sourcesContent":["import { defineFailure } from './define.js';\nimport {\n and,\n isCategory,\n isFailure,\n isFamily,\n isTag,\n not,\n or,\n when,\n} from './predicates.js';\nimport { lookupFailure, registeredFailures } from './registry.js';\n\nexport * from './failure.js';\nexport * from './generic.js';\nexport * from './predicates.js';\nexport * from './problem.js';\nexport * from './registry.js';\n\n/**\n * Everything a host needs to define and match failures, under one name\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n *\n * ```ts\n * class DuplicateSlug extends Failure.conflict<DuplicateSlug>()(\n * 'DuplicateSlug',\n * 'duplicateSlug',\n * { slug: Schema.String },\n * ) {}\n *\n * effect.pipe(Effect.catchIf(Failure.isCategory('conflict'), …))\n * ```\n */\nexport const Failure = {\n invalid: defineFailure('invalid'),\n unauthenticated: defineFailure('unauthenticated'),\n forbidden: defineFailure('forbidden'),\n notFound: defineFailure('notFound'),\n conflict: defineFailure('conflict'),\n declined: defineFailure('declined'),\n contention: defineFailure('contention'),\n exhausted: defineFailure('exhausted'),\n unavailable: defineFailure('unavailable'),\n timeout: defineFailure('timeout'),\n protocol: defineFailure('protocol'),\n internal: defineFailure('internal'),\n is: isFailure,\n isTag,\n isCategory,\n isFamily,\n and,\n or,\n not,\n when,\n lookup: lookupFailure,\n registered: registeredFailures,\n} as const;\n"],"names":["defineFailure","and","isCategory","isFailure","isFamily","isTag","not","or","when","lookupFailure","registeredFailures","Failure","invalid","unauthenticated","forbidden","notFound","conflict","declined","contention","exhausted","unavailable","timeout","protocol","internal","is","lookup","registered"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAC5C,SACEC,GAAG,EACHC,UAAU,EACVC,SAAS,EACTC,QAAQ,EACRC,KAAK,EACLC,GAAG,EACHC,EAAE,EACFC,IAAI,QACC,kBAAkB;AACzB,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,gBAAgB;AAElE,cAAc,eAAe;AAC7B,cAAc,eAAe;AAC7B,cAAc,kBAAkB;AAChC,cAAc,eAAe;AAC7B,cAAc,gBAAgB;AAE9B;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,UAAU;IACrBC,SAASZ,cAAc;IACvBa,iBAAiBb,cAAc;IAC/Bc,WAAWd,cAAc;IACzBe,UAAUf,cAAc;IACxBgB,UAAUhB,cAAc;IACxBiB,UAAUjB,cAAc;IACxBkB,YAAYlB,cAAc;IAC1BmB,WAAWnB,cAAc;IACzBoB,aAAapB,cAAc;IAC3BqB,SAASrB,cAAc;IACvBsB,UAAUtB,cAAc;IACxBuB,UAAUvB,cAAc;IACxBwB,IAAIrB;IACJE;IACAH;IACAE;IACAH;IACAM;IACAD;IACAE;IACAiB,QAAQhB;IACRiB,YAAYhB;AACd,EAAW"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Effect } from 'effect';
|
|
2
|
+
import type { EntifixFailure, FailureCategory, FailureFamily } from './failure.js';
|
|
3
|
+
/**
|
|
4
|
+
* A guard over anything, naming the shape it admits.
|
|
5
|
+
*
|
|
6
|
+
* It is written over `unknown` rather than over a failure union on purpose:
|
|
7
|
+
* TypeScript narrows a union by a guard on a supertype by **filtering** its
|
|
8
|
+
* members, so `if (isCategory('conflict')(e))` leaves exactly the members of
|
|
9
|
+
* `E` whose `category` is `'conflict'` — the same as `Extract<E, Shape>` — and
|
|
10
|
+
* one predicate serves every union it is applied to.
|
|
11
|
+
*
|
|
12
|
+
* The check reads `_tag`, `category` and `family` and never the prototype, so a
|
|
13
|
+
* failure decoded off a wire or defined in a second copy of this module
|
|
14
|
+
* matches exactly as one constructed in place.
|
|
15
|
+
*/
|
|
16
|
+
export type FailureGuard<Shape> = (value: unknown) => value is Shape;
|
|
17
|
+
/** Admits the failure whose `_tag` is `tag`. */
|
|
18
|
+
export declare const isTag: <const Tag extends string>(tag: Tag) => FailureGuard<{
|
|
19
|
+
readonly _tag: Tag;
|
|
20
|
+
}>;
|
|
21
|
+
/** Admits every failure in `category`. */
|
|
22
|
+
export declare const isCategory: <const C extends FailureCategory>(category: C) => FailureGuard<{
|
|
23
|
+
readonly category: C;
|
|
24
|
+
}>;
|
|
25
|
+
/** Admits every failure in `family`. */
|
|
26
|
+
export declare const isFamily: <const F extends FailureFamily>(family: F) => FailureGuard<{
|
|
27
|
+
readonly family: F;
|
|
28
|
+
}>;
|
|
29
|
+
/** Admits any `EntifixFailure`, of any category. */
|
|
30
|
+
export declare const isFailure: FailureGuard<EntifixFailure>;
|
|
31
|
+
/** Both guards admit it. */
|
|
32
|
+
export declare const and: <A, B>(left: FailureGuard<A>, right: FailureGuard<B>) => FailureGuard<A & B>;
|
|
33
|
+
/** Either guard admits it. */
|
|
34
|
+
export declare const or: <A, B>(left: FailureGuard<A>, right: FailureGuard<B>) => FailureGuard<A | B>;
|
|
35
|
+
/**
|
|
36
|
+
* The guard does not admit it.
|
|
37
|
+
*
|
|
38
|
+
* ⚠️ Generic over the union it is applied to, because "not this shape" has no
|
|
39
|
+
* shape of its own: `not(isFamily('business'))(e)` narrows `E` to
|
|
40
|
+
* `Exclude<E, { family: 'business' }>`. Applied with no union in view — as an
|
|
41
|
+
* argument to {@link and} or {@link or} — it admits correctly and narrows
|
|
42
|
+
* nothing, so keep it the outermost combinator.
|
|
43
|
+
*/
|
|
44
|
+
export declare const not: <S>(guard: FailureGuard<S>) => <E>(value: E) => value is Exclude<E, S>;
|
|
45
|
+
/**
|
|
46
|
+
* A guard plus a condition that needs the request — a dial read from
|
|
47
|
+
* configuration, the caller's organization. The guard narrows; the condition
|
|
48
|
+
* decides, and it is an Effect because the context it reads is.
|
|
49
|
+
*/
|
|
50
|
+
export interface EffectfulFailurePredicate<Shape, R = never> {
|
|
51
|
+
readonly guard: FailureGuard<Shape>;
|
|
52
|
+
readonly condition: (failure: Shape) => Effect.Effect<boolean, never, R>;
|
|
53
|
+
}
|
|
54
|
+
/** Pairs a guard with a condition read from the request's context. */
|
|
55
|
+
export declare const when: <Shape, R = never>(guard: FailureGuard<Shape>, condition: (failure: Shape) => Effect.Effect<boolean, never, R>) => EffectfulFailurePredicate<Shape, R>;
|
|
56
|
+
//# sourceMappingURL=predicates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../../src/failure/predicates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,KAAK,CAAC;AAOrE,gDAAgD;AAChD,eAAO,MAAM,KAAK,GACf,KAAK,CAAC,GAAG,SAAS,MAAM,EAAE,KAAK,GAAG,KAAG,YAAY,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAE5C,CAAC;AAEhC,0CAA0C;AAC1C,eAAO,MAAM,UAAU,GACpB,KAAK,CAAC,CAAC,SAAS,eAAe,EAC9B,UAAU,CAAC,KACV,YAAY,CAAC;IAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;CAAE,CAEF,CAAC;AAEzC,wCAAwC;AACxC,eAAO,MAAM,QAAQ,GAClB,KAAK,CAAC,CAAC,SAAS,aAAa,EAC5B,QAAQ,CAAC,KACR,YAAY,CAAC;IAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAEJ,CAAC;AAErC,oDAAoD;AACpD,eAAO,MAAM,SAAS,EAAE,YAAY,CAAC,cAAc,CAOiB,CAAC;AAErE,4BAA4B;AAC5B,eAAO,MAAM,GAAG,GACb,CAAC,EAAE,CAAC,EAAE,MAAM,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,YAAY,CAAC,CAAC,CAAC,KAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAE5C,CAAC;AAEhC,8BAA8B;AAC9B,eAAO,MAAM,EAAE,GACZ,CAAC,EAAE,CAAC,EAAE,MAAM,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,YAAY,CAAC,CAAC,CAAC,KAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAE5C,CAAC;AAEhC;;;;;;;;GAQG;AACH,eAAO,MAAM,GAAG,GACb,CAAC,EAAE,OAAO,YAAY,CAAC,CAAC,CAAC,MACzB,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CACrB,CAAC;AAElB;;;;GAIG;AACH,MAAM,WAAW,yBAAyB,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK;IACzD,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;CAC1E;AAED,sEAAsE;AACtE,eAAO,MAAM,IAAI,GAAI,KAAK,EAAE,CAAC,GAAG,KAAK,EACnC,OAAO,YAAY,CAAC,KAAK,CAAC,EAC1B,WAAW,CAAC,OAAO,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAC9D,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAA2B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const readsAs = (value, key, expected)=>typeof value === 'object' && value !== null && value[key] === expected;
|
|
2
|
+
/** Admits the failure whose `_tag` is `tag`. */ export const isTag = (tag)=>(value)=>readsAs(value, '_tag', tag);
|
|
3
|
+
/** Admits every failure in `category`. */ export const isCategory = (category)=>(value)=>readsAs(value, 'category', category);
|
|
4
|
+
/** Admits every failure in `family`. */ export const isFamily = (family)=>(value)=>readsAs(value, 'family', family);
|
|
5
|
+
/** Admits any `EntifixFailure`, of any category. */ export const isFailure = (value)=>typeof value === 'object' && value !== null && typeof value['_tag'] === 'string' && typeof value['code'] === 'string' && typeof value['category'] === 'string';
|
|
6
|
+
/** Both guards admit it. */ export const and = (left, right)=>(value)=>left(value) && right(value);
|
|
7
|
+
/** Either guard admits it. */ export const or = (left, right)=>(value)=>left(value) || right(value);
|
|
8
|
+
/**
|
|
9
|
+
* The guard does not admit it.
|
|
10
|
+
*
|
|
11
|
+
* ⚠️ Generic over the union it is applied to, because "not this shape" has no
|
|
12
|
+
* shape of its own: `not(isFamily('business'))(e)` narrows `E` to
|
|
13
|
+
* `Exclude<E, { family: 'business' }>`. Applied with no union in view — as an
|
|
14
|
+
* argument to {@link and} or {@link or} — it admits correctly and narrows
|
|
15
|
+
* nothing, so keep it the outermost combinator.
|
|
16
|
+
*/ export const not = (guard)=>(value)=>!guard(value);
|
|
17
|
+
/** Pairs a guard with a condition read from the request's context. */ export const when = (guard, condition)=>({
|
|
18
|
+
guard,
|
|
19
|
+
condition
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=predicates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/failure/predicates.ts"],"sourcesContent":["import type { Effect } from 'effect';\n\nimport type {\n EntifixFailure,\n FailureCategory,\n FailureFamily,\n} from './failure.js';\n\n/**\n * A guard over anything, naming the shape it admits.\n *\n * It is written over `unknown` rather than over a failure union on purpose:\n * TypeScript narrows a union by a guard on a supertype by **filtering** its\n * members, so `if (isCategory('conflict')(e))` leaves exactly the members of\n * `E` whose `category` is `'conflict'` — the same as `Extract<E, Shape>` — and\n * one predicate serves every union it is applied to.\n *\n * The check reads `_tag`, `category` and `family` and never the prototype, so a\n * failure decoded off a wire or defined in a second copy of this module\n * matches exactly as one constructed in place.\n */\nexport type FailureGuard<Shape> = (value: unknown) => value is Shape;\n\nconst readsAs = (value: unknown, key: string, expected: string): boolean =>\n typeof value === 'object' &&\n value !== null &&\n (value as Record<string, unknown>)[key] === expected;\n\n/** Admits the failure whose `_tag` is `tag`. */\nexport const isTag =\n <const Tag extends string>(tag: Tag): FailureGuard<{ readonly _tag: Tag }> =>\n (value): value is { readonly _tag: Tag } =>\n readsAs(value, '_tag', tag);\n\n/** Admits every failure in `category`. */\nexport const isCategory =\n <const C extends FailureCategory>(\n category: C,\n ): FailureGuard<{ readonly category: C }> =>\n (value): value is { readonly category: C } =>\n readsAs(value, 'category', category);\n\n/** Admits every failure in `family`. */\nexport const isFamily =\n <const F extends FailureFamily>(\n family: F,\n ): FailureGuard<{ readonly family: F }> =>\n (value): value is { readonly family: F } =>\n readsAs(value, 'family', family);\n\n/** Admits any `EntifixFailure`, of any category. */\nexport const isFailure: FailureGuard<EntifixFailure> = (\n value,\n): value is EntifixFailure =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as Record<string, unknown>)['_tag'] === 'string' &&\n typeof (value as Record<string, unknown>)['code'] === 'string' &&\n typeof (value as Record<string, unknown>)['category'] === 'string';\n\n/** Both guards admit it. */\nexport const and =\n <A, B>(left: FailureGuard<A>, right: FailureGuard<B>): FailureGuard<A & B> =>\n (value): value is A & B =>\n left(value) && right(value);\n\n/** Either guard admits it. */\nexport const or =\n <A, B>(left: FailureGuard<A>, right: FailureGuard<B>): FailureGuard<A | B> =>\n (value): value is A | B =>\n left(value) || right(value);\n\n/**\n * The guard does not admit it.\n *\n * ⚠️ Generic over the union it is applied to, because \"not this shape\" has no\n * shape of its own: `not(isFamily('business'))(e)` narrows `E` to\n * `Exclude<E, { family: 'business' }>`. Applied with no union in view — as an\n * argument to {@link and} or {@link or} — it admits correctly and narrows\n * nothing, so keep it the outermost combinator.\n */\nexport const not =\n <S>(guard: FailureGuard<S>) =>\n <E>(value: E): value is Exclude<E, S> =>\n !guard(value);\n\n/**\n * A guard plus a condition that needs the request — a dial read from\n * configuration, the caller's organization. The guard narrows; the condition\n * decides, and it is an Effect because the context it reads is.\n */\nexport interface EffectfulFailurePredicate<Shape, R = never> {\n readonly guard: FailureGuard<Shape>;\n readonly condition: (failure: Shape) => Effect.Effect<boolean, never, R>;\n}\n\n/** Pairs a guard with a condition read from the request's context. */\nexport const when = <Shape, R = never>(\n guard: FailureGuard<Shape>,\n condition: (failure: Shape) => Effect.Effect<boolean, never, R>,\n): EffectfulFailurePredicate<Shape, R> => ({ guard, condition });\n"],"names":["readsAs","value","key","expected","isTag","tag","isCategory","category","isFamily","family","isFailure","and","left","right","or","not","guard","when","condition"],"mappings":"AAuBA,MAAMA,UAAU,CAACC,OAAgBC,KAAaC,WAC5C,OAAOF,UAAU,YACjBA,UAAU,QACV,AAACA,KAAiC,CAACC,IAAI,KAAKC;AAE9C,8CAA8C,GAC9C,OAAO,MAAMC,QACX,CAA2BC,MAC3B,CAACJ,QACCD,QAAQC,OAAO,QAAQI,KAAK;AAEhC,wCAAwC,GACxC,OAAO,MAAMC,aACX,CACEC,WAEF,CAACN,QACCD,QAAQC,OAAO,YAAYM,UAAU;AAEzC,sCAAsC,GACtC,OAAO,MAAMC,WACX,CACEC,SAEF,CAACR,QACCD,QAAQC,OAAO,UAAUQ,QAAQ;AAErC,kDAAkD,GAClD,OAAO,MAAMC,YAA0C,CACrDT,QAEA,OAAOA,UAAU,YACjBA,UAAU,QACV,OAAO,AAACA,KAAiC,CAAC,OAAO,KAAK,YACtD,OAAO,AAACA,KAAiC,CAAC,OAAO,KAAK,YACtD,OAAO,AAACA,KAAiC,CAAC,WAAW,KAAK,SAAS;AAErE,0BAA0B,GAC1B,OAAO,MAAMU,MACX,CAAOC,MAAuBC,QAC9B,CAACZ,QACCW,KAAKX,UAAUY,MAAMZ,OAAO;AAEhC,4BAA4B,GAC5B,OAAO,MAAMa,KACX,CAAOF,MAAuBC,QAC9B,CAACZ,QACCW,KAAKX,UAAUY,MAAMZ,OAAO;AAEhC;;;;;;;;CAQC,GACD,OAAO,MAAMc,MACX,CAAIC,QACJ,CAAIf,QACF,CAACe,MAAMf,OAAO;AAYlB,oEAAoE,GACpE,OAAO,MAAMgB,OAAO,CAClBD,OACAE,YACyC,CAAA;QAAEF;QAAOE;IAAU,CAAA,EAAG"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { type EntifixFailure } from './failure.js';
|
|
3
|
+
/** The content type every error answer carries (RFC 9457). */
|
|
4
|
+
export declare const PROBLEM_CONTENT_TYPE = "application/problem+json";
|
|
5
|
+
/**
|
|
6
|
+
* The envelope of an RFC 9457 problem, with entifix's members beside the
|
|
7
|
+
* standard ones. `code` is top-level because it is what a client translates;
|
|
8
|
+
* the failure's own fields ride as extension members.
|
|
9
|
+
*/
|
|
10
|
+
export declare const Problem: Schema.Struct<{
|
|
11
|
+
readonly type: Schema.String;
|
|
12
|
+
readonly title: Schema.String;
|
|
13
|
+
readonly status: Schema.Number;
|
|
14
|
+
readonly code: Schema.String;
|
|
15
|
+
readonly category: Schema.Literals<readonly import("./failure.js").FailureCategory[]>;
|
|
16
|
+
readonly detail: Schema.optionalKey<Schema.String>;
|
|
17
|
+
readonly instance: Schema.optionalKey<Schema.String>;
|
|
18
|
+
readonly traceId: Schema.optionalKey<Schema.String>;
|
|
19
|
+
}>;
|
|
20
|
+
/** A problem body: the envelope plus the failure's own fields. */
|
|
21
|
+
export type Problem = typeof Problem.Type & Readonly<Record<string, unknown>>;
|
|
22
|
+
export interface ProblemOptions {
|
|
23
|
+
/** The status to answer with; the category's default when absent. */
|
|
24
|
+
readonly status?: number;
|
|
25
|
+
readonly traceId?: string;
|
|
26
|
+
/** The request path the failure answers. */
|
|
27
|
+
readonly instance?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The problem body a failure answers with.
|
|
31
|
+
*
|
|
32
|
+
* `detail` is the failure's `message` when it has one, and is never
|
|
33
|
+
* `String(error)`: a failure's message is written by its author for a reader,
|
|
34
|
+
* a defect's text is not, and a defect never reaches this function.
|
|
35
|
+
*/
|
|
36
|
+
export declare const problemOf: (failure: EntifixFailure, options?: ProblemOptions) => Problem;
|
|
37
|
+
/**
|
|
38
|
+
* The failure a problem body names, with its typed fields — or a
|
|
39
|
+
* {@link ProtocolFailure} when the body is not a problem, names a code nothing
|
|
40
|
+
* registered, or carries fields that do not decode.
|
|
41
|
+
*
|
|
42
|
+
* Never throws and never fails: whatever a peer sends, the caller gets a
|
|
43
|
+
* failure it can branch on.
|
|
44
|
+
*
|
|
45
|
+
* @param status the HTTP status the body arrived with, kept on a
|
|
46
|
+
* `ProtocolFailure` so the caller still knows what the peer meant.
|
|
47
|
+
*/
|
|
48
|
+
export declare const decodeProblem: (body: unknown, status?: number) => EntifixFailure;
|
|
49
|
+
//# sourceMappingURL=problem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem.d.ts","sourceRoot":"","sources":["../../src/failure/problem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,cAAc,CAAC;AAItB,8DAA8D;AAC9D,eAAO,MAAM,oBAAoB,6BAA6B,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,OAAO;;;;;;;;;EASlB,CAAC;AAEH,kEAAkE;AAClE,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE9E,MAAM,WAAW,cAAc;IAC7B,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AA0BD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GACpB,SAAS,cAAc,EACvB,UAAS,cAAmB,KAC3B,OAUD,CAAC;AAKH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,OAAO,EACb,SAAS,MAAM,KACd,cAqBF,CAAC"}
|