viell-effect-schema-http 0.0.0-stage → 0.1.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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -2
  3. package/dist/concurrency/Interaction.d.ts +65 -0
  4. package/dist/concurrency/Interaction.d.ts.map +1 -0
  5. package/dist/concurrency/Interaction.js +99 -0
  6. package/dist/concurrency/Interaction.js.map +1 -0
  7. package/dist/http/Body.d.ts +162 -0
  8. package/dist/http/Body.d.ts.map +1 -0
  9. package/dist/http/Body.js +184 -0
  10. package/dist/http/Body.js.map +1 -0
  11. package/dist/http/Operation.d.ts +97 -0
  12. package/dist/http/Operation.d.ts.map +1 -0
  13. package/dist/http/Operation.js +146 -0
  14. package/dist/http/Operation.js.map +1 -0
  15. package/dist/http/Policy.d.ts +82 -0
  16. package/dist/http/Policy.d.ts.map +1 -0
  17. package/dist/http/Policy.js +76 -0
  18. package/dist/http/Policy.js.map +1 -0
  19. package/dist/http/Request.d.ts +324 -0
  20. package/dist/http/Request.d.ts.map +1 -0
  21. package/dist/http/Request.js +391 -0
  22. package/dist/http/Request.js.map +1 -0
  23. package/dist/http/Response.d.ts +126 -0
  24. package/dist/http/Response.d.ts.map +1 -0
  25. package/dist/http/Response.js +100 -0
  26. package/dist/http/Response.js.map +1 -0
  27. package/dist/http/Transport.d.ts +75 -0
  28. package/dist/http/Transport.d.ts.map +1 -0
  29. package/dist/http/Transport.js +91 -0
  30. package/dist/http/Transport.js.map +1 -0
  31. package/dist/http/UrlEncoding.d.ts +78 -0
  32. package/dist/http/UrlEncoding.d.ts.map +1 -0
  33. package/dist/http/UrlEncoding.js +64 -0
  34. package/dist/http/UrlEncoding.js.map +1 -0
  35. package/dist/http/internal/fields.d.ts +12 -0
  36. package/dist/http/internal/fields.d.ts.map +1 -0
  37. package/dist/http/internal/fields.js +21 -0
  38. package/dist/http/internal/fields.js.map +1 -0
  39. package/dist/main.d.ts +33 -0
  40. package/dist/main.d.ts.map +1 -0
  41. package/dist/main.js +33 -0
  42. package/dist/main.js.map +1 -0
  43. package/package.json +125 -4
  44. package/src/concurrency/Interaction.ts +192 -0
  45. package/src/http/Body.ts +318 -0
  46. package/src/http/Operation.ts +300 -0
  47. package/src/http/Policy.ts +130 -0
  48. package/src/http/Request.ts +700 -0
  49. package/src/http/Response.ts +201 -0
  50. package/src/http/Transport.ts +143 -0
  51. package/src/http/UrlEncoding.ts +119 -0
  52. package/src/http/internal/fields.ts +46 -0
  53. package/src/main.ts +32 -0
@@ -0,0 +1,391 @@
1
+ import { Data, Effect, Pipeable, Redacted, Schema } from "effect";
2
+ import { Headers, HttpClientRequest, UrlParams, } from "effect/http";
3
+ import * as Fields from "./internal/fields.js";
4
+ import * as Transport from "./Transport.js";
5
+ import * as UrlEncoding from "./UrlEncoding.js";
6
+ /**
7
+ * Request preparation failed before dispatch.
8
+ *
9
+ * @remarks
10
+ * Covers computed-field failures, URL-rendering exceptions, and a GET/HEAD body other than
11
+ * `HttpBody.empty`. Schema encoding failures remain separate `SchemaError` values.
12
+ */
13
+ export class InvalidRequest extends Data.TaggedError("InvalidRequest") {
14
+ }
15
+ const construct = (declaration, prepare) => ({ ...Pipeable.Prototype, declaration, prepare });
16
+ /**
17
+ * Describe a request with a method and URL, without sending it.
18
+ *
19
+ * @remarks
20
+ * Use `undefined` as input until a binding adds required fields. A relative path can be combined
21
+ * with {@link baseUrl}; {@link path} can supply the complete path from typed input.
22
+ * Custom method strings pass through unchanged.
23
+ *
24
+ * A constructor query is parsed as form data: `+` becomes a space, percent escapes are decoded,
25
+ * and empty `&` segments are dropped. Bare keys remain distinct from empty values. Compilation
26
+ * renders these entries through `UrlEncoding.query`; a constructor fragment is discarded.
27
+ */
28
+ export const make = (method, url) => {
29
+ const hash = url.indexOf("#");
30
+ const withoutHash = hash < 0 ? url : url.slice(0, hash);
31
+ const start = withoutHash.indexOf("?");
32
+ const query = [];
33
+ if (start >= 0) {
34
+ for (const segment of withoutHash.slice(start + 1).split("&")) {
35
+ // URLSearchParams strips one leading query marker; a marker in the key is data.
36
+ for (const [key, value] of new URLSearchParams(`?${segment}`))
37
+ query.push([key, segment.includes("=") ? value : null]);
38
+ }
39
+ }
40
+ return construct({
41
+ method,
42
+ url: start < 0 ? withoutHash : withoutHash.slice(0, start),
43
+ baseUrl: "",
44
+ headers: [],
45
+ query,
46
+ headersBound: false,
47
+ queryBound: false,
48
+ }, (_, draft) => Effect.succeed(draft));
49
+ };
50
+ /**
51
+ * Describe a GET request. Use {@link baseUrl} for a shared origin or path prefix.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { Request } from "viell-effect-schema-http";
56
+ * const users = Request.get("/users").pipe(
57
+ * Request.baseUrl("https://api.example.test/api/v1"),
58
+ * );
59
+ * ```
60
+ */
61
+ export const get = (url) => make("GET", url);
62
+ /**
63
+ * Describe a POST request. Add typed input with {@link body}, {@link path} or other bindings.
64
+ */
65
+ export const post = (url) => make("POST", url);
66
+ /**
67
+ * Describe a PUT request. Add an outgoing representation with {@link body}.
68
+ */
69
+ export const put = (url) => make("PUT", url);
70
+ /**
71
+ * Describe a PATCH request. Add an outgoing representation with {@link body}.
72
+ */
73
+ export const patch = (url) => make("PATCH", url);
74
+ /**
75
+ * Describe a DELETE request. A response contract decides which deletion outcomes to accept.
76
+ */
77
+ export const del = (url) => make("DELETE", url);
78
+ /**
79
+ * Describe a HEAD request. Its outgoing body must remain `HttpBody.empty`.
80
+ */
81
+ export const head = (url) => make("HEAD", url);
82
+ /**
83
+ * Describe an OPTIONS request. The HTTP provider still controls browser preflight behavior.
84
+ */
85
+ export const options = (url) => make("OPTIONS", url);
86
+ /**
87
+ * Set the shared origin and fixed path prefix for a request.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { Request } from "viell-effect-schema-http";
92
+ * const api = Request.baseUrl("https://api.example.test/api/v1");
93
+ * const users = Request.get("/users").pipe(api);
94
+ * const teams = Request.get("/teams").pipe(api);
95
+ * ```
96
+ *
97
+ * @remarks
98
+ * The base is joined after path preparation. With the default URL policy, an absolute request
99
+ * URL bypasses it; a leading `/` on a relative path keeps the base's prefix. Calling this again
100
+ * replaces the base, rather than appending to it. Keep query fields in request combinators.
101
+ */
102
+ export const baseUrl = (url) => (self) => construct({ ...self.declaration, baseUrl: url }, self.prepare);
103
+ const editHeaders = (edit) => (self) => construct({ ...self.declaration, headers: edit(self.declaration.headers) }, self.prepare);
104
+ const editQuery = (edit) => (self) => construct({ ...self.declaration, query: edit(self.declaration.query) }, self.prepare);
105
+ /**
106
+ * Set a raw header, replacing every existing line with that name.
107
+ *
108
+ * @remarks
109
+ * Names compare without case and are stored lowercase. Unavailable after a header schema is
110
+ * bound. The body encoder owns `Content-Type` and `Content-Length`.
111
+ */
112
+ export const setHeader = (name, value) => editHeaders((fields) => Fields.set(fields, name.toLowerCase(), value));
113
+ /**
114
+ * Add a raw header line after the existing lines, preserving repetition.
115
+ *
116
+ * @remarks
117
+ * Names are stored lowercase. Unavailable after a header schema is bound. Sending separate
118
+ * lines requires a provider that supports them; Fetch may combine or restrict headers.
119
+ */
120
+ export const appendHeader = (name, value) => editHeaders((fields) => Fields.append(fields, name.toLowerCase(), value));
121
+ /**
122
+ * Remove a raw header, or only its declarations with the supplied fixed value.
123
+ *
124
+ * @remarks
125
+ * Names compare without case. Value functions are never evaluated to compare with `value`.
126
+ * Unavailable after a header schema is bound.
127
+ */
128
+ export const removeHeader = (name, value) => editHeaders((fields) => Fields.remove(fields, name.toLowerCase(), value));
129
+ /**
130
+ * Set a raw query field, replacing entries with the same case-sensitive name.
131
+ *
132
+ * @remarks
133
+ * `null` produces a bare key, `""` an empty value, and `undefined` omits the entry.
134
+ * Unavailable after a query schema is bound.
135
+ */
136
+ export const setQuery = (name, value) => editQuery((fields) => Fields.set(fields, name, value));
137
+ /**
138
+ * Append a raw query entry, preserving order and repeated names.
139
+ *
140
+ * @remarks
141
+ * Uses the same value rules as {@link setQuery}. Unavailable after a query schema is bound.
142
+ */
143
+ export const appendQuery = (name, value) => editQuery((fields) => Fields.append(fields, name, value));
144
+ /**
145
+ * Remove a raw query field, or only declarations with the supplied fixed value.
146
+ *
147
+ * @remarks
148
+ * Names compare with case. Value functions are not evaluated for comparison.
149
+ * Unavailable after a query schema is bound.
150
+ */
151
+ export const removeQuery = (name, value) => editQuery((fields) => Fields.remove(fields, name, value));
152
+ const replaceQuery = (draft, entries) => {
153
+ const added = entries.map(([key, value]) => [key, value ?? ""]);
154
+ const keys = new Set(added.map(([key]) => key));
155
+ const bareKeys = new Set(Array.from(draft.bareKeys).filter(([key]) => !keys.has(key)));
156
+ entries.forEach(([, value], index) => {
157
+ if (value === null)
158
+ bareKeys.add(added[index]);
159
+ });
160
+ const { request } = draft;
161
+ const params = [
162
+ ...request.urlParams.params.filter(([key]) => !keys.has(key)),
163
+ ...added,
164
+ ];
165
+ return {
166
+ ...draft,
167
+ request: HttpClientRequest.makeWith(request.method, request.url, UrlParams.make(params), request.hash, request.headers, request.body),
168
+ bareKeys,
169
+ };
170
+ };
171
+ /** Fields that describe the body itself rather than the request. */
172
+ const bodyFields = ["content-type", "content-length"];
173
+ /** Give the body fields their values from `before`, removing those it lacks. */
174
+ const keepBodyFields = (headers, before) => bodyFields.reduce((result, name) => {
175
+ const value = before[name];
176
+ return value === undefined
177
+ ? Headers.remove(result, name)
178
+ : Headers.set(result, name, value);
179
+ }, headers);
180
+ /**
181
+ * Bind a schema to the call's `{ headers }` input.
182
+ *
183
+ * @remarks
184
+ * Encoding produces ordered header lines. The schema replaces raw header declarations and owns
185
+ * the group: later raw setters or another header schema are unavailable.
186
+ * When a body is present, its `Content-Type` and `Content-Length` take precedence, regardless of
187
+ * binding order. Without a body, the schema values apply; a later body binding, including
188
+ * `Body.empty`, replaces those fields according to its encoder.
189
+ */
190
+ export const headers = (contract) => {
191
+ const encode = Schema.encodeEffect(contract);
192
+ return (self) => construct({ ...self.declaration, headers: [], headersBound: true }, Effect.fnUntraced(function* (input, draft) {
193
+ const encoded = yield* encode(input.headers);
194
+ const prepared = yield* self.prepare(input, draft);
195
+ const headerLines = Transport.entries(encoded);
196
+ const merged = HttpClientRequest.setHeaders(prepared.request, Transport.toHeaders(headerLines));
197
+ // Compilation then drops the schema's lines for any body field whose value was kept.
198
+ return {
199
+ ...prepared,
200
+ request: prepared.request.body._tag === "Empty"
201
+ ? merged
202
+ : HttpClientRequest.updateHeaders(merged, (fields) => keepBodyFields(fields, prepared.request.headers)),
203
+ headerLines,
204
+ };
205
+ }));
206
+ };
207
+ /**
208
+ * Bind a schema to the call's `{ query }` input.
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * import { Schema } from "effect";
213
+ * import { Request } from "viell-effect-schema-http";
214
+ * const search = Request.get("https://api.example.test/users").pipe(
215
+ * Request.query(Schema.Struct({ page: Schema.NumberFromString })),
216
+ * );
217
+ * // Input: { query: { page: 2 } }; URL query: ?page=2
218
+ * ```
219
+ *
220
+ * @remarks
221
+ * The schema encodes to `UrlEncoding.QueryInput`. It replaces raw query declarations, including
222
+ * the constructor's query string, and owns the group. Later raw setters or another query schema
223
+ * are unavailable. Use {@link mapInput} to supply application defaults.
224
+ */
225
+ export const query = (contract) => {
226
+ const encode = Schema.encodeEffect(contract);
227
+ return (self) => construct({ ...self.declaration, query: [], queryBound: true }, Effect.fnUntraced(function* (input, draft) {
228
+ const encoded = yield* encode(input.query);
229
+ const prepared = yield* self.prepare(input, draft);
230
+ return replaceQuery(prepared, UrlEncoding.queryEntries(encoded));
231
+ }));
232
+ };
233
+ /**
234
+ * Bind a schema to `{ path }` input and render the complete request path.
235
+ *
236
+ * @example
237
+ * ```ts
238
+ * import { Schema } from "effect";
239
+ * import { Request } from "viell-effect-schema-http";
240
+ * const user = Request.get("").pipe(
241
+ * Request.baseUrl("https://api.example.test"),
242
+ * Request.path(Schema.NumberFromString, (id, encode) => `/users/${encode(id)}`),
243
+ * );
244
+ * // Input: { path: 42 }; URL: https://api.example.test/users/42
245
+ * ```
246
+ *
247
+ * @remarks
248
+ * The value under `path` has the schema's application type. A scalar schema takes a scalar;
249
+ * `Schema.Struct({ userId: Schema.NumberFromString })` takes `{ userId: number }`. Use a struct
250
+ * to name one path value or group several. Renderer parameter names do not affect the input type.
251
+ *
252
+ * The renderer receives the schema-encoded value and the active path-value encoder. Escape each
253
+ * dynamic value with that encoder. The returned path replaces the constructor's path; it does
254
+ * not append to it. The shared base URL is joined afterwards. Reuse renderer functions for
255
+ * nested resources rather than stacking path bindings.
256
+ * Renderer or path-encoding exceptions become {@link InvalidRequest}; schema failures remain
257
+ * `SchemaError` values.
258
+ */
259
+ export const path = (contract, render) => {
260
+ const encode = Schema.encodeEffect(contract);
261
+ return (self) => construct(self.declaration, Effect.fnUntraced(function* (input, draft) {
262
+ const encoded = yield* encode(input.path);
263
+ const encoding = yield* UrlEncoding.UrlEncoding;
264
+ const prepared = yield* self.prepare(input, draft);
265
+ const url = yield* Effect.try({
266
+ try: () => render(encoded, encoding.path),
267
+ catch: (cause) => new InvalidRequest({
268
+ message: "Failed to render the request path",
269
+ cause,
270
+ }),
271
+ });
272
+ return {
273
+ ...prepared,
274
+ request: HttpClientRequest.setUrl(prepared.request, url),
275
+ };
276
+ }));
277
+ };
278
+ /**
279
+ * Bind an encoder to the call's `{ body }` input.
280
+ *
281
+ * @remarks
282
+ * The body is encoded once per operation evaluation. Its encoder determines `Content-Type` and
283
+ * `Content-Length`; multipart metadata is supplied by the transport.
284
+ */
285
+ export const body = (codec) => (self) => construct(self.declaration, Effect.fnUntraced(function* (input, draft) {
286
+ const encoded = yield* codec.encode(input.body);
287
+ const prepared = yield* self.prepare(input, draft);
288
+ return {
289
+ ...prepared,
290
+ request: HttpClientRequest.setBody(prepared.request, encoded),
291
+ };
292
+ }));
293
+ /**
294
+ * Adapt your application's argument to this request's required input.
295
+ *
296
+ * @remarks
297
+ * Use it to rename fields or supply defaults while preserving schema validation. The mapping
298
+ * runs during preparation; a thrown exception is a defect.
299
+ */
300
+ export const mapInput = (f) => (self) => construct(self.declaration, (input, draft) => Effect.suspend(() => self.prepare(f(input), draft)));
301
+ /**
302
+ * Edit the native request with an Effect during preparation.
303
+ *
304
+ * @remarks
305
+ * Runs once per evaluation, before attempts, after preceding preparation steps. The base URL
306
+ * and separate query parameters are not yet rendered. Use `Operation.make`'s `transformClient`
307
+ * for per-attempt credentials or signing the materialized URL. Provider normalization still
308
+ * applies afterwards.
309
+ *
310
+ * A transform can be reused on requests whose input contains what its function reads. Inline
311
+ * callbacks in `pipe` infer their input from the request.
312
+ */
313
+ export const mapEffect = (f) => (self) => construct(self.declaration, (input, draft) => Effect.flatMap(self.prepare(input, draft), (prepared) => Effect.map(f(prepared.request, input), (request) => ({
314
+ ...prepared,
315
+ request,
316
+ }))));
317
+ const initialDraft = (declaration) => {
318
+ // Custom method strings pass through at runtime; the method union is narrower than the transport.
319
+ const native = HttpClientRequest.make(declaration.method)(declaration.url);
320
+ const headerLines = Fields.resolve(declaration.headers);
321
+ return replaceQuery({
322
+ request: HttpClientRequest.setHeaders(native, Transport.toHeaders(headerLines)),
323
+ headerLines,
324
+ bareKeys: new Set(),
325
+ }, Fields.resolve(declaration.query));
326
+ };
327
+ const finalize = (draft, base, encoding) => {
328
+ const { request } = draft;
329
+ const url = encoding.join(base, request.url);
330
+ const search = encoding.query(request.urlParams.params.map((param) => [
331
+ param[0],
332
+ draft.bareKeys.has(param)
333
+ ? null
334
+ : Redacted.isRedacted(param[1])
335
+ ? Redacted.value(param[1])
336
+ : param[1],
337
+ ]));
338
+ const compiled = HttpClientRequest.makeWith(request.method, search === "" ? url : `${url}${url.includes("?") ? "&" : "?"}${search}`, UrlParams.empty, request.hash, request.headers, request.body);
339
+ return {
340
+ request: compiled,
341
+ headerLines: Transport.reconcile(draft.headerLines, compiled.headers),
342
+ };
343
+ };
344
+ /**
345
+ * Prepare a request and its header lines without sending it.
346
+ *
347
+ * @example
348
+ * ```ts
349
+ * import { Effect } from "effect";
350
+ * import { Request } from "viell-effect-schema-http";
351
+ * const result = await Effect.runPromise(
352
+ * Request.compile(Request.get("https://api.example.test/health"), undefined),
353
+ * );
354
+ * // result.request.url === "https://api.example.test/health"
355
+ * ```
356
+ *
357
+ * @remarks
358
+ * Each evaluation resolves computed fields and encodes input once. The returned Effect requires
359
+ * any services used by the input schemas or preparation. Use {@link materialize} when only the
360
+ * native request is needed.
361
+ */
362
+ export const compile = Effect.fnUntraced(function* (self, input) {
363
+ const encoding = yield* UrlEncoding.UrlEncoding;
364
+ const initial = yield* Effect.try({
365
+ try: () => initialDraft(self.declaration),
366
+ catch: (cause) => new InvalidRequest({
367
+ message: "Failed to materialize request fields",
368
+ cause,
369
+ }),
370
+ });
371
+ const draft = yield* self.prepare(input, initial);
372
+ const { method } = draft.request;
373
+ if ((method === "GET" || method === "HEAD") &&
374
+ draft.request.body._tag !== "Empty") {
375
+ return yield* new InvalidRequest({
376
+ message: `${method} cannot carry a request body`,
377
+ });
378
+ }
379
+ return yield* Effect.try({
380
+ try: () => finalize(draft, self.declaration.baseUrl, encoding),
381
+ catch: (cause) => new InvalidRequest({ message: "Failed to encode request URL", cause }),
382
+ });
383
+ });
384
+ /**
385
+ * Prepare only the native request, without sending it.
386
+ *
387
+ * @remarks
388
+ * Use {@link compile} to retain the original header-line representation as well.
389
+ */
390
+ export const materialize = (self, input) => Effect.map(compile(self, input), (compiled) => compiled.request);
391
+ //# sourceMappingURL=Request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Request.js","sourceRoot":"","sources":["../../src/http/Request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EACL,OAAO,EACP,iBAAiB,EAEjB,SAAS,GACV,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK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cookies, Headers, HttpClientError, HttpClientResponse } from "effect/http";
3
+ import * as Body from "./Body.js";
4
+ import * as Transport from "./Transport.js";
5
+ /**
6
+ * The status, headers and cookies available for selecting a response decoder.
7
+ *
8
+ * @remarks
9
+ * Contains no body. Header and cookie visibility depends on the HTTP provider and browser.
10
+ * `headerLines` is present only when a provider attached its observed lines.
11
+ */
12
+ export interface Metadata {
13
+ readonly status: number;
14
+ readonly headers: Headers.Headers;
15
+ readonly cookies: Cookies.Cookies;
16
+ /** Provider-observed lines, when the provider supplied them. Normalized headers are always available. */
17
+ readonly headerLines: Option.Option<Transport.Lines>;
18
+ }
19
+ declare const UnexpectedResponse_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
20
+ readonly _tag: "UnexpectedResponse";
21
+ } & Readonly<A>;
22
+ /**
23
+ * No response case matched, and the unmatched body was successfully drained.
24
+ *
25
+ * @remarks
26
+ * Contains metadata only. A failed drain produces {@link DecodeError} instead.
27
+ */
28
+ export declare class UnexpectedResponse extends UnexpectedResponse_base<{
29
+ readonly metadata: Metadata;
30
+ }> {
31
+ }
32
+ declare const DecodeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
33
+ readonly _tag: "DecodeError";
34
+ } & Readonly<A>;
35
+ /**
36
+ * A selected body decoder failed, or draining an unmatched body failed.
37
+ *
38
+ * @remarks
39
+ * `cause` retains the underlying typed error; it may contain schema input or response content.
40
+ * Selection does not fall through to a different case after this failure.
41
+ */
42
+ export declare class DecodeError<out E> extends DecodeError_base<{
43
+ readonly metadata: Metadata;
44
+ readonly cause: E;
45
+ }> {
46
+ }
47
+ /**
48
+ * An ordered contract that chooses a body decoder from response metadata.
49
+ *
50
+ * @remarks
51
+ * Build cases with {@link status} or {@link when}, then combine them with {@link orElse}.
52
+ * A declared status, including 4xx or 5xx, returns the decoder's value if decoding succeeds.
53
+ */
54
+ export interface Response<out A, out E = never, out R = never> extends Pipeable.Pipeable {
55
+ readonly select: (metadata: Metadata) => Option.Option<Body.Decoder<A, E, R>>;
56
+ /** Media types contributed to the automatic `Accept` header, in declaration order. */
57
+ readonly accepts: ReadonlyArray<string>;
58
+ }
59
+ /**
60
+ * Read metadata from an Effect HTTP response without consuming its body.
61
+ */
62
+ export declare const metadata: (response: HttpClientResponse.HttpClientResponse) => Metadata;
63
+ /**
64
+ * Select a body decoder when a predicate accepts the response metadata.
65
+ *
66
+ * @remarks
67
+ * The predicate runs before body decoding. It cannot select by payload contents; use one schema
68
+ * with alternatives for payloads sharing the same metadata.
69
+ */
70
+ export declare const when: <A, E, R>(predicate: (metadata: Metadata) => boolean, body: Body.Decoder<A, E, R>) => Response<A, E, R>;
71
+ /**
72
+ * Select a body decoder for one exact HTTP status.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { Body, Response } from "viell-effect-schema-http";
77
+ * const health = Response.status(200, Body.text);
78
+ * ```
79
+ */
80
+ export declare const status: <A, E, R>(code: number, body: Body.Decoder<A, E, R>) => Response<A, E, R>;
81
+ /**
82
+ * Use another response contract when this one has no matching case.
83
+ *
84
+ * @remarks
85
+ * Declaration order is priority. This is selection fallback, not decoding-error recovery.
86
+ * A selected decoder's failure never tries the fallback.
87
+ */
88
+ export declare const orElse: <B, E2, R2>(that: Response<B, E2, R2>) => <A, E, R>(self: Response<A, E, R>) => Response<A | B, E | E2, R | R2>;
89
+ /**
90
+ * A decoded value labelled with its case name and response metadata.
91
+ *
92
+ * @remarks
93
+ * Checking `_tag` narrows the value type when several tagged outcomes form a union.
94
+ */
95
+ export interface Tagged<Tag extends string, A> {
96
+ readonly _tag: Tag;
97
+ readonly value: A;
98
+ readonly metadata: Metadata;
99
+ }
100
+ /**
101
+ * Wrap a body decoder's result with a case name, value and response metadata.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { Body, Response } from "viell-effect-schema-http";
106
+ * const response = Response.status(200, Response.tag("Found", Body.text)).pipe(
107
+ * Response.orElse(Response.status(404, Response.tag("Missing", Body.empty))),
108
+ * );
109
+ * ```
110
+ *
111
+ * @remarks
112
+ * This returns a body decoder, ready to use inside {@link status} or {@link when}.
113
+ * Tagging a response does not turn it into an Effect failure.
114
+ */
115
+ export declare const tag: <const Tag extends string, A, E, R>(name: Tag, body: Body.Decoder<A, E, R>) => Body.Decoder<Tagged<Tag, A>, E, R>;
116
+ /**
117
+ * Choose a response case and decode the native response's body.
118
+ *
119
+ * @remarks
120
+ * An unmatched body is drained before `UnexpectedResponse`; a failed drain or decoder becomes
121
+ * `DecodeError`. Direct callers own the response's resource lifetime. `Operation.make` manages
122
+ * that lifetime and any configured attempt timeout for ordinary execution.
123
+ */
124
+ export declare const decode: <A, E, R>(self: Response<A, E, R>, response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, UnexpectedResponse | DecodeError<E | HttpClientError.HttpClientError>, R>;
125
+ export {};
126
+ //# sourceMappingURL=Response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Response.d.ts","sourceRoot":"","sources":["../../src/http/Response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,eAAe,EACf,kBAAkB,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAClC,yGAAyG;IACz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AM,CAAC,MAAM,CACd,CAAC,EACD,kBAAkB,GAAG,WAAW,CAAC,CAAC,GAAG,eAAe,CAAC,eAAe,CAAC,EACrE,CAAC,CAkBC,CAAC"}
@@ -0,0 +1,100 @@
1
+ import { Data, Effect, Option, Pipeable } from "effect";
2
+ import * as Body from "./Body.js";
3
+ import * as Transport from "./Transport.js";
4
+ /**
5
+ * No response case matched, and the unmatched body was successfully drained.
6
+ *
7
+ * @remarks
8
+ * Contains metadata only. A failed drain produces {@link DecodeError} instead.
9
+ */
10
+ export class UnexpectedResponse extends Data.TaggedError("UnexpectedResponse") {
11
+ }
12
+ /**
13
+ * A selected body decoder failed, or draining an unmatched body failed.
14
+ *
15
+ * @remarks
16
+ * `cause` retains the underlying typed error; it may contain schema input or response content.
17
+ * Selection does not fall through to a different case after this failure.
18
+ */
19
+ export class DecodeError extends Data.TaggedError("DecodeError") {
20
+ }
21
+ /**
22
+ * Read metadata from an Effect HTTP response without consuming its body.
23
+ */
24
+ export const metadata = (response) => ({
25
+ status: response.status,
26
+ headers: response.headers,
27
+ cookies: response.cookies,
28
+ headerLines: Transport.responseHeaderLines(response),
29
+ });
30
+ const make = (select, accepts) => ({
31
+ ...Pipeable.Prototype,
32
+ select,
33
+ accepts,
34
+ });
35
+ /**
36
+ * Select a body decoder when a predicate accepts the response metadata.
37
+ *
38
+ * @remarks
39
+ * The predicate runs before body decoding. It cannot select by payload contents; use one schema
40
+ * with alternatives for payloads sharing the same metadata.
41
+ */
42
+ export const when = (predicate, body) => make((info) => (predicate(info) ? Option.some(body) : Option.none()), body.mediaType === undefined ? [] : [body.mediaType]);
43
+ /**
44
+ * Select a body decoder for one exact HTTP status.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { Body, Response } from "viell-effect-schema-http";
49
+ * const health = Response.status(200, Body.text);
50
+ * ```
51
+ */
52
+ export const status = (code, body) => when((info) => info.status === code, body);
53
+ /**
54
+ * Use another response contract when this one has no matching case.
55
+ *
56
+ * @remarks
57
+ * Declaration order is priority. This is selection fallback, not decoding-error recovery.
58
+ * A selected decoder's failure never tries the fallback.
59
+ */
60
+ export const orElse = (that) => (self) => make((info) => Option.orElse(self.select(info), () => that.select(info)), Array.from(new Set([...self.accepts, ...that.accepts])));
61
+ /**
62
+ * Wrap a body decoder's result with a case name, value and response metadata.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { Body, Response } from "viell-effect-schema-http";
67
+ * const response = Response.status(200, Response.tag("Found", Body.text)).pipe(
68
+ * Response.orElse(Response.status(404, Response.tag("Missing", Body.empty))),
69
+ * );
70
+ * ```
71
+ *
72
+ * @remarks
73
+ * This returns a body decoder, ready to use inside {@link status} or {@link when}.
74
+ * Tagging a response does not turn it into an Effect failure.
75
+ */
76
+ export const tag = (name, body) => Body.decoder((response) => Effect.map(body.decode(response), (value) => ({
77
+ _tag: name,
78
+ value,
79
+ metadata: metadata(response),
80
+ })), body.mediaType);
81
+ /**
82
+ * Choose a response case and decode the native response's body.
83
+ *
84
+ * @remarks
85
+ * An unmatched body is drained before `UnexpectedResponse`; a failed drain or decoder becomes
86
+ * `DecodeError`. Direct callers own the response's resource lifetime. `Operation.make` manages
87
+ * that lifetime and any configured attempt timeout for ordinary execution.
88
+ */
89
+ export const decode = (self, response) => Effect.suspend(() => {
90
+ const info = metadata(response);
91
+ const selected = self.select(info);
92
+ const decodeError = (cause) => new DecodeError({ metadata: info, cause });
93
+ if (Option.isNone(selected)) {
94
+ return Body.empty
95
+ .decode(response)
96
+ .pipe(Effect.mapError(decodeError), Effect.andThen(Effect.fail(new UnexpectedResponse({ metadata: info }))));
97
+ }
98
+ return Effect.mapError(selected.value.decode(response), decodeError);
99
+ });
100
+ //# sourceMappingURL=Response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Response.js","sourceRoot":"","sources":["../../src/http/Response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;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