@shivaedev/http 0.4.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0 - 2026-11-04
4
+
5
+ ### Breaking
6
+
7
+ - TypeScript source exports now use `@shivaedev/source` instead of `source`. Replace `source` with `@shivaedev/source` in Node `--conditions`, TypeScript `customConditions`, and Vite/Vitest `resolve.conditions`. Bare `source` selects built JavaScript; no compatibility alias is provided.
8
+
9
+ ## 0.5.0 - 2026-11-03
10
+
11
+ ### Added
12
+
13
+ - Export `checkStatus` from `checkStatus.ts` to check an existing response with the same typed failures as `filterStatus`.
14
+ - Export `isRemoteStatusError` from `errors.ts` to recognize the shared HTTP status failures.
15
+
16
+ ### Breaking
17
+
18
+ - in `server/boundedBody.ts`, call `readBoundedBody()` instead of `readBoundedBody(request)`. The reader requires the native `HttpServerRequest.HttpServerRequest` in the Effect environment. Native router handlers already provide it; other callers must use `Effect.provideService(HttpServerRequest.HttpServerRequest, request)`.
19
+
3
20
  ## 0.4.0 - 2026-11-02
4
21
 
5
22
  ### Fixed
package/README.md CHANGED
@@ -35,6 +35,8 @@ Everything here wraps a native `HttpClient`, `HttpClientResponse` or `HttpServer
35
35
 
36
36
  `filterStatus(client)` passes 2xx responses through and fails other statuses with Schema tagged errors from `errors.ts`: `RemoteUnauthorized` (401), `RemoteNotFound` (404), `RemoteGone` (410), `RemoteRateLimited` (429, or 503 carrying `Retry-After`) and `RemoteHttpError` for other statuses. Errors carry the method, the URL without userinfo, query string or fragment and the status, without headers or body. `RemoteRateLimited.retryAfter` is an optional UTC `DateTime`: delay-seconds use Effect's clock, and HTTP dates name the instant directly. Missing or invalid values leave it undefined; `parseRetryAfter(header, now)` exposes the same parsing.
37
37
 
38
+ `checkStatus(response)` from `checkStatus.ts` applies the same status mapping to an existing native response. `filterStatus` delegates to it. Use `isRemoteStatusError(error)` from `errors.ts` to recognize any of these typed status failures.
39
+
38
40
  `paginate(client, request)` follows quoted or unquoted `rel=next`, including headers with multiple links and relations, resolves relative links and stops at the last page. Taking one page sends one request. A next link on another origin fails with `PaginationLinkError` before that request is sent. Pagination disables automatic fetch redirects with `redirect: "error"`, preserving other fetch options from the current Effect context: a redirect fails through the native client's error channel before sending custom headers to its destination. Use direct page URLs and a client without redirect-following middleware. `nextLink(header)` exposes the link parsing.
39
41
 
40
42
  `readBoundedBody(response, limit)` returns bytes; `readBoundedText` decodes UTF-8, and `readBoundedJson(response, limit, schema)` decodes JSON through the supplied Schema. The limit counts bytes exposed by the native client's `response.stream`, including decompressed bytes with `FetchHttpClient`. The reader does no decompression of its own; Node's native HTTP transport exposes encoded bytes. Responses with `Content-Encoding` are limited during streaming, without comparing their wire `Content-Length` to the limit. For unencoded responses, an oversized `Content-Length` fails before reading the body. Crossing the stream-byte limit fails with `ResponseBodyTooLarge`, carrying `limit`.
@@ -43,15 +45,15 @@ HEAD responses and statuses 204, 205 and 304 read as empty bytes or text, regard
43
45
 
44
46
  ### Reading request bodies on a native route
45
47
 
46
- For a native Node HTTP route, use `readBoundedBody` from `server/boundedBody.ts` with Effect's `HttpIncomingMessage.MaxBodySize`. It returns an `ArrayBuffer` without decoding the bytes:
48
+ For a native Node HTTP route, use `readBoundedBody()` from `server/boundedBody.ts` with Effect's `HttpIncomingMessage.MaxBodySize`. It reads the native `HttpServerRequest.HttpServerRequest` from the Effect environment and returns an `ArrayBuffer` without decoding the bytes:
47
49
 
48
50
  ```ts
49
51
  import { ByteSize, Effect } from "effect";
50
52
  import { HttpIncomingMessage, HttpRouter, HttpServerResponse } from "effect/http";
51
53
  import { readBoundedBody } from "@shivaedev/http/server/boundedBody.ts";
52
54
 
53
- const routes = HttpRouter.add("POST", "/webhook", (request) =>
54
- readBoundedBody(request).pipe(
55
+ const routes = HttpRouter.add("POST", "/webhook", () =>
56
+ readBoundedBody().pipe(
55
57
  Effect.map((body) => HttpServerResponse.uint8Array(new Uint8Array(body))),
56
58
  Effect.provideService(HttpIncomingMessage.MaxBodySize, ByteSize.bytes(64 * 1024)),
57
59
  ),
@@ -0,0 +1,5 @@
1
+ import { Effect } from "effect";
2
+ import type { HttpClientResponse } from "effect/http";
3
+ import { RemoteGone, RemoteHttpError, RemoteNotFound, RemoteRateLimited, RemoteUnauthorized } from "./errors.ts";
4
+ export declare const checkStatus: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<HttpClientResponse.HttpClientResponse, RemoteGone | RemoteHttpError | RemoteNotFound | RemoteRateLimited | RemoteUnauthorized, never>;
5
+ //# sourceMappingURL=checkStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkStatus.d.ts","sourceRoot":"","sources":["../src/checkStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAU,MAAM,QAAQ,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAA0B,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGzI,eAAO,MAAM,WAAW,0MA8BtB,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { DateTime, Effect, Stream } from "effect";
2
+ import * as HttpStatus from "effect/http/HttpStatus";
3
+ import { RemoteGone, RemoteHttpError, RemoteNotFound, RemoteRateLimited, RemoteUnauthorized } from "./errors.js";
4
+ import { parseRetryAfter } from "./parseRetryAfter.js";
5
+ export const checkStatus = Effect.fnUntraced(function* (response) {
6
+ const { status, request } = response;
7
+ if (status >= HttpStatus.fromLiteral("OK") && status < HttpStatus.fromLiteral("MultipleChoices")) {
8
+ return response;
9
+ }
10
+ const url = new URL(request.url);
11
+ const fields = { method: request.method, status, url: `${url.origin}${url.pathname}` };
12
+ let error;
13
+ switch (status) {
14
+ case HttpStatus.fromLiteral("Unauthorized"):
15
+ error = new RemoteUnauthorized(fields);
16
+ break;
17
+ case HttpStatus.fromLiteral("NotFound"):
18
+ error = new RemoteNotFound(fields);
19
+ break;
20
+ case HttpStatus.fromLiteral("Gone"):
21
+ error = new RemoteGone(fields);
22
+ break;
23
+ default: {
24
+ const header = response.headers["retry-after"];
25
+ if (status === HttpStatus.fromLiteral("TooManyRequests") || (status === HttpStatus.fromLiteral("ServiceUnavailable") && header !== undefined)) {
26
+ const retryAfter = parseRetryAfter(header, yield* DateTime.now);
27
+ error = new RemoteRateLimited({ ...fields, ...(retryAfter === undefined ? {} : { retryAfter }) });
28
+ }
29
+ else {
30
+ error = new RemoteHttpError(fields);
31
+ }
32
+ }
33
+ }
34
+ yield* Effect.scoped(Stream.toPull(response.stream));
35
+ return yield* Effect.fail(error);
36
+ });
37
+ //# sourceMappingURL=checkStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkStatus.js","sourceRoot":"","sources":["../src/checkStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAA0B,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACzI,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAA+C;IACtG,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IACrC,IAAI,MAAM,IAAI,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAClG,OAAO,QAAQ,CAAC;IACjB,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,G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AAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACrD,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC"}
package/dist/errors.d.ts CHANGED
@@ -36,7 +36,9 @@ declare const RemoteHttpError_base: Schema.Class<RemoteHttpError, Schema.TaggedS
36
36
  export declare class RemoteHttpError extends RemoteHttpError_base {
37
37
  get message(): string;
38
38
  }
39
- export type RemoteStatusError = RemoteUnauthorized | RemoteNotFound | RemoteGone | RemoteRateLimited | RemoteHttpError;
39
+ declare const RemoteStatusError: Schema.Union<readonly [typeof RemoteUnauthorized, typeof RemoteNotFound, typeof RemoteGone, typeof RemoteRateLimited, typeof RemoteHttpError]>;
40
+ export type RemoteStatusError = typeof RemoteStatusError.Type;
41
+ export declare const isRemoteStatusError: <I>(input: I) => input is I & (RemoteGone | RemoteHttpError | RemoteNotFound | RemoteRateLimited | RemoteUnauthorized);
40
42
  declare const PaginationLinkError_base: Schema.Class<PaginationLinkError, Schema.TaggedStruct<"PaginationLinkError", {
41
43
  readonly reason: Schema.Literals<readonly ["cross-origin", "invalid"]>;
42
44
  readonly url: Schema.String;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;;AAIhC,qBAAa,kBAAmB,SAAQ,uBAAsE;CAAG;;;;;;AACjH,qBAAa,cAAe,SAAQ,mBAA8D;CAAG;;;;;;AACrG,qBAAa,UAAW,SAAQ,eAAsD;CAAG;;;;;;;AACzF,qBAAa,iBAAkB,SAAQ,sBAGrC;CAAG;;;;;;AACL,qBAAa,eAAgB,SAAQ,oBAAgE;IACpG,IAAa,OAAO,IAAI,MAAM,CAG7B;CACD;AAED,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG,cAAc,GAAG,UAAU,GAAG,iBAAiB,GAAG,eAAe,CAAC;;;;;AAEvH,qBAAa,mBAAoB,SAAQ,wBAGvC;CAAG;;;;AAEL,qBAAa,oBAAqB,SAAQ,yBAExC;CAAG;;;;AAEL,qBAAa,gBAAiB,SAAQ,qBAEpC;CAAG"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;;AAIhC,qBAAa,kBAAmB,SAAQ,uBAAsE;CAAG;;;;;;AACjH,qBAAa,cAAe,SAAQ,mBAA8D;CAAG;;;;;;AACrG,qBAAa,UAAW,SAAQ,eAAsD;CAAG;;;;;;;AACzF,qBAAa,iBAAkB,SAAQ,sBAGrC;CAAG;;;;;;AACL,qBAAa,eAAgB,SAAQ,oBAAgE;IACpG,IAAa,OAAO,IAAI,MAAM,CAG7B;CACD;AAED,QAAA,MAAM,iBAAiB,gJAAqG,CAAC;AAC7H,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;AAC9D,eAAO,MAAM,mBAAmB,wHAA+B,CAAC;;;;;AAEhE,qBAAa,mBAAoB,SAAQ,wBAGvC;CAAG;;;;AAEL,qBAAa,oBAAqB,SAAQ,yBAExC;CAAG;;;;AAEL,qBAAa,gBAAiB,SAAQ,qBAEpC;CAAG"}
package/dist/errors.js CHANGED
@@ -17,6 +17,8 @@ export class RemoteHttpError extends Schema.TaggedError()("RemoteHttpError", ans
17
17
  return `HTTP ${this.status}: ${this.method} ${url.host}${url.pathname}`;
18
18
  }
19
19
  }
20
+ const RemoteStatusError = Schema.Union([RemoteUnauthorized, RemoteNotFound, RemoteGone, RemoteRateLimited, RemoteHttpError]);
21
+ export const isRemoteStatusError = Schema.is(RemoteStatusError);
20
22
  export class PaginationLinkError extends Schema.TaggedError()("PaginationLinkError", {
21
23
  reason: Schema.Literals(["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,CAAC,CAAC;QAC9B,OAAO,QAAQ,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IACzE,CAAC;CACD;AAED,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,kBAAkB,EAAE,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAAE,eAAe,CAAC,CAAC,CAAC;AAE7H,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;AAEhE,MAAM,OAAO,mBAAoB,SAAQ,MAAM,CAAC,WAAW,EAAuB,CAAC,qBAAqB,EAAE;IACzG,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACpD,GAAG,EAAE,MAAM,CAAC,MAAM;CAClB,CAAC;CAAG;AAEL,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,WAAW,EAAwB,CAAC,sBAAsB,EAAE;IAC5G,KAAK,EAAE,MAAM,CAAC,MAAM;CACpB,CAAC;CAAG;AAEL,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,EAAoB,CAAC,kBAAkB,EAAE;IAChG,KAAK,EAAE,MAAM,CAAC,MAAM;CACpB,CAAC;CAAG"}
@@ -1,4 +1,4 @@
1
1
  import { HttpClient } from "effect/http";
2
- import { type RemoteStatusError } from "./errors.ts";
2
+ import type { RemoteStatusError } from "./errors.ts";
3
3
  export declare function filterStatus<E, R>(client: HttpClient.HttpClient.With<E, R>): HttpClient.HttpClient.With<E | RemoteStatusError, R>;
4
4
  //# sourceMappingURL=filterStatus.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filterStatus.d.ts","sourceRoot":"","sources":["../src/filterStatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAA2B,MAAM,aAAa,CAAC;AAElE,OAAO,EAAkE,KAAK,iBAAiB,EAAsB,MAAM,aAAa,CAAC;AAmCzI,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAEjI"}
1
+ {"version":3,"file":"filterStatus.d.ts","sourceRoot":"","sources":["../src/filterStatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAEjI"}
@@ -1,40 +1,6 @@
1
- import { DateTime, Effect, Stream } from "effect";
1
+ import { Effect } from "effect";
2
2
  import { HttpClient } from "effect/http";
3
- import * as HttpStatus from "effect/http/HttpStatus";
4
- import { RemoteGone, RemoteHttpError, RemoteNotFound, RemoteRateLimited, RemoteUnauthorized } from "./errors.js";
5
- import { parseRetryAfter } from "./parseRetryAfter.js";
6
- const checkStatus = Effect.fnUntraced(function* (response) {
7
- const { status, request } = response;
8
- if (status >= HttpStatus.fromLiteral("OK") && status < HttpStatus.fromLiteral("MultipleChoices")) {
9
- return response;
10
- }
11
- const url = new URL(request.url);
12
- const fields = { method: request.method, status, url: `${url.origin}${url.pathname}` };
13
- let error;
14
- switch (status) {
15
- case HttpStatus.fromLiteral("Unauthorized"):
16
- error = new RemoteUnauthorized(fields);
17
- break;
18
- case HttpStatus.fromLiteral("NotFound"):
19
- error = new RemoteNotFound(fields);
20
- break;
21
- case HttpStatus.fromLiteral("Gone"):
22
- error = new RemoteGone(fields);
23
- break;
24
- default: {
25
- const header = response.headers["retry-after"];
26
- if (status === HttpStatus.fromLiteral("TooManyRequests") || (status === HttpStatus.fromLiteral("ServiceUnavailable") && header !== undefined)) {
27
- const retryAfter = parseRetryAfter(header, yield* DateTime.now);
28
- error = new RemoteRateLimited({ ...fields, ...(retryAfter === undefined ? {} : { retryAfter }) });
29
- }
30
- else {
31
- error = new RemoteHttpError(fields);
32
- }
33
- }
34
- }
35
- yield* Effect.scoped(Stream.toPull(response.stream));
36
- return yield* Effect.fail(error);
37
- });
3
+ import { checkStatus } from "./checkStatus.js";
38
4
  export function filterStatus(client) {
39
5
  return HttpClient.transformResponse(client, Effect.flatMap(checkStatus));
40
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"filterStatus.js","sourceRoot":"","sources":["../src/filterStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,UAAU,EAA2B,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAA0B,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACzI,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAA+C;IAC/F,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IACrC,IAAI,MAAM,IAAI,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAClG,OAAO,QAAQ,CAAC;IACjB,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAA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C,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACrD,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,YAAY,CAAO,MAAwC;IAC1E,OAAO,UAAU,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AAC1E,CAAC"}
1
+ {"version":3,"file":"filterStatus.js","sourceRoot":"","sources":["../src/filterStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,MAAM,UAAU,YAAY,CAAO,MAAwC;IAC1E,OAAO,UAAU,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AAC1E,CAAC"}
@@ -1,11 +1,11 @@
1
1
  import { Effect, Schema } from "effect";
2
- import { type HttpServerRequest, HttpServerRespondable, HttpServerResponse } from "effect/http";
2
+ import { HttpServerRequest, HttpServerRespondable, HttpServerResponse } from "effect/http";
3
3
  declare const RequestBodyTooLarge_base: Schema.Class<RequestBodyTooLarge, Schema.TaggedStruct<"RequestBodyTooLarge", {
4
4
  readonly limit: Schema.Number;
5
5
  }>, import("effect/Cause").YieldableError>;
6
6
  export declare class RequestBodyTooLarge extends RequestBodyTooLarge_base implements HttpServerRespondable.Respondable {
7
7
  [HttpServerRespondable.symbol](): Effect.Effect<HttpServerResponse.HttpServerResponse, never, never>;
8
8
  }
9
- export declare const readBoundedBody: (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<ArrayBuffer, import("effect/http/HttpServerError").HttpServerError | RequestBodyTooLarge, never>;
9
+ export declare const readBoundedBody: () => Effect.Effect<ArrayBuffer, import("effect/http/HttpServerError").HttpServerError | RequestBodyTooLarge, HttpServerRequest.HttpServerRequest>;
10
10
  export {};
11
11
  //# sourceMappingURL=boundedBody.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boundedBody.d.ts","sourceRoot":"","sources":["../../src/server/boundedBody.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAuB,KAAK,iBAAiB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;;;;AAGrH,qBAAa,mBACZ,SAAQ,wBACR,YAAW,qBAAqB,CAAC,WAAW;IAE5C,CAAC,qBAAqB,CAAC,MAAM,CAAC,uEAE7B;CACD;AAED,eAAO,MAAM,eAAe,kKAgB1B,CAAC"}
1
+ {"version":3,"file":"boundedBody.d.ts","sourceRoot":"","sources":["../../src/server/boundedBody.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAuB,iBAAiB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;;;;AAGhH,qBAAa,mBACZ,SAAQ,wBACR,YAAW,qBAAqB,CAAC,WAAW;IAE5C,CAAC,qBAAqB,CAAC,MAAM,CAAC,uEAE7B;CACD;AAED,eAAO,MAAM,eAAe,oJAiB1B,CAAC"}
@@ -1,12 +1,13 @@
1
1
  import { Effect, Schema } from "effect";
2
- import { HttpIncomingMessage, HttpServerRespondable, HttpServerResponse } from "effect/http";
2
+ import { HttpIncomingMessage, HttpServerRequest, HttpServerRespondable, HttpServerResponse } from "effect/http";
3
3
  import * as HttpStatus from "effect/http/HttpStatus";
4
4
  export class RequestBodyTooLarge extends Schema.TaggedError()("RequestBodyTooLarge", { limit: Schema.Number }) {
5
5
  [HttpServerRespondable.symbol]() {
6
6
  return Effect.succeed(HttpServerResponse.empty({ status: HttpStatus.fromLiteral("PayloadTooLarge") }));
7
7
  }
8
8
  }
9
- export const readBoundedBody = Effect.fnUntraced(function* (request) {
9
+ export const readBoundedBody = Effect.fnUntraced(function* () {
10
+ const request = yield* HttpServerRequest.HttpServerRequest;
10
11
  const maxBodySize = yield* HttpIncomingMessage.MaxBodySize;
11
12
  if (maxBodySize === undefined) {
12
13
  return yield* new RequestBodyTooLarge({ limit: 0 });
@@ -1 +1 @@
1
- {"version":3,"file":"boundedBody.js","sourceRoot":"","sources":["../../src/server/boundedBody.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAA0B,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACrH,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,MAAM,OAAO,mBACZ,SAAQ,MAAM,CAAC,WAAW,EAAuB,CAAC,qBAAqB,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;IAGlG,CAAC,qBAAqB,CAAC,MAAM,CAAC;QAC7B,OAAO,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC;IACxG,CAAC;CACD;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,OAA4C;IACvG,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC;IAC3D,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,CAAC,IAAI,mBAAmB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAA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CAAC,UAAU,CAAC,QAAQ,CAAC;IACzD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC,iBAAiB,CAAC;IAC3D,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC;IAC3D,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,CAAC,IAAI,mBAAmB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACjD,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,WAAW,EAAE,CAAC;QAC1D,OAAO,KAAK,CAAC,CAAC,IAAI,mBAAmB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CACrC,MAAM,CAAC,OAAO,CACb,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,mBAAmB,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,cAAc,EAC9F,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,EAAE,KAAK,EAAE,CAAC,CACxC,CACD,CAAC;AACH,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/http",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Bounded HTTP bodies, status failures and paginated clients over Effect HTTP",
5
5
  "keywords": [
6
6
  "effect"
@@ -20,14 +20,14 @@
20
20
  "imports": {
21
21
  "#test/*": "./src/test-support/*",
22
22
  "#*.ts": {
23
- "source": "./src/*.ts",
23
+ "@shivaedev/source": "./src/*.ts",
24
24
  "types": "./dist/*.d.ts",
25
25
  "default": "./dist/*.js"
26
26
  }
27
27
  },
28
28
  "exports": {
29
29
  "./*.ts": {
30
- "source": "./src/*.ts",
30
+ "@shivaedev/source": "./src/*.ts",
31
31
  "types": "./dist/*.d.ts",
32
32
  "default": "./dist/*.js"
33
33
  },
@@ -46,8 +46,8 @@
46
46
  ],
47
47
  "devDependencies": {
48
48
  "@effect/platform-node": "4.0.6",
49
- "@shivaedev/quality": "0.55.0",
50
- "@shivaedev/test-story": "0.33.0",
49
+ "@shivaedev/quality": "0.60.0",
50
+ "@shivaedev/test-story": "0.38.0",
51
51
  "@types/node": "24.19.2",
52
52
  "effect": "4.0.6",
53
53
  "typescript": "7.0.2",
@@ -0,0 +1,37 @@
1
+ import { DateTime, Effect, Stream } from "effect";
2
+ import type { HttpClientResponse } from "effect/http";
3
+ import * as HttpStatus from "effect/http/HttpStatus";
4
+ import { RemoteGone, RemoteHttpError, RemoteNotFound, RemoteRateLimited, type RemoteStatusError, RemoteUnauthorized } from "./errors.ts";
5
+ import { parseRetryAfter } from "./parseRetryAfter.ts";
6
+
7
+ export const checkStatus = Effect.fnUntraced(function* (response: HttpClientResponse.HttpClientResponse) {
8
+ const { status, request } = response;
9
+ if (status >= HttpStatus.fromLiteral("OK") && status < HttpStatus.fromLiteral("MultipleChoices")) {
10
+ return response;
11
+ }
12
+ const url = new URL(request.url);
13
+ const fields = { method: request.method, status, url: `${url.origin}${url.pathname}` };
14
+ let error: RemoteStatusError;
15
+ switch (status) {
16
+ case HttpStatus.fromLiteral("Unauthorized"):
17
+ error = new RemoteUnauthorized(fields);
18
+ break;
19
+ case HttpStatus.fromLiteral("NotFound"):
20
+ error = new RemoteNotFound(fields);
21
+ break;
22
+ case HttpStatus.fromLiteral("Gone"):
23
+ error = new RemoteGone(fields);
24
+ break;
25
+ default: {
26
+ const header = response.headers["retry-after"];
27
+ if (status === HttpStatus.fromLiteral("TooManyRequests") || (status === HttpStatus.fromLiteral("ServiceUnavailable") && header !== undefined)) {
28
+ const retryAfter = parseRetryAfter(header, yield* DateTime.now);
29
+ error = new RemoteRateLimited({ ...fields, ...(retryAfter === undefined ? {} : { retryAfter }) });
30
+ } else {
31
+ error = new RemoteHttpError(fields);
32
+ }
33
+ }
34
+ }
35
+ yield* Effect.scoped(Stream.toPull(response.stream));
36
+ return yield* Effect.fail(error);
37
+ });
package/src/errors.ts CHANGED
@@ -16,7 +16,9 @@ export class RemoteHttpError extends Schema.TaggedError<RemoteHttpError>()("Remo
16
16
  }
17
17
  }
18
18
 
19
- export type RemoteStatusError = RemoteUnauthorized | RemoteNotFound | RemoteGone | RemoteRateLimited | RemoteHttpError;
19
+ const RemoteStatusError = Schema.Union([RemoteUnauthorized, RemoteNotFound, RemoteGone, RemoteRateLimited, RemoteHttpError]);
20
+ export type RemoteStatusError = typeof RemoteStatusError.Type;
21
+ export const isRemoteStatusError = Schema.is(RemoteStatusError);
20
22
 
21
23
  export class PaginationLinkError extends Schema.TaggedError<PaginationLinkError>()("PaginationLinkError", {
22
24
  reason: Schema.Literals(["cross-origin", "invalid"]),
@@ -1,40 +1,7 @@
1
- import { DateTime, Effect, Stream } from "effect";
2
- import { HttpClient, type HttpClientResponse } from "effect/http";
3
- import * as HttpStatus from "effect/http/HttpStatus";
4
- import { RemoteGone, RemoteHttpError, RemoteNotFound, RemoteRateLimited, type RemoteStatusError, RemoteUnauthorized } from "./errors.ts";
5
- import { parseRetryAfter } from "./parseRetryAfter.ts";
6
-
7
- const checkStatus = Effect.fnUntraced(function* (response: HttpClientResponse.HttpClientResponse) {
8
- const { status, request } = response;
9
- if (status >= HttpStatus.fromLiteral("OK") && status < HttpStatus.fromLiteral("MultipleChoices")) {
10
- return response;
11
- }
12
- const url = new URL(request.url);
13
- const fields = { method: request.method, status, url: `${url.origin}${url.pathname}` };
14
- let error: RemoteStatusError;
15
- switch (status) {
16
- case HttpStatus.fromLiteral("Unauthorized"):
17
- error = new RemoteUnauthorized(fields);
18
- break;
19
- case HttpStatus.fromLiteral("NotFound"):
20
- error = new RemoteNotFound(fields);
21
- break;
22
- case HttpStatus.fromLiteral("Gone"):
23
- error = new RemoteGone(fields);
24
- break;
25
- default: {
26
- const header = response.headers["retry-after"];
27
- if (status === HttpStatus.fromLiteral("TooManyRequests") || (status === HttpStatus.fromLiteral("ServiceUnavailable") && header !== undefined)) {
28
- const retryAfter = parseRetryAfter(header, yield* DateTime.now);
29
- error = new RemoteRateLimited({ ...fields, ...(retryAfter === undefined ? {} : { retryAfter }) });
30
- } else {
31
- error = new RemoteHttpError(fields);
32
- }
33
- }
34
- }
35
- yield* Effect.scoped(Stream.toPull(response.stream));
36
- return yield* Effect.fail(error);
37
- });
1
+ import { Effect } from "effect";
2
+ import { HttpClient } from "effect/http";
3
+ import { checkStatus } from "./checkStatus.ts";
4
+ import type { RemoteStatusError } from "./errors.ts";
38
5
 
39
6
  export function filterStatus<E, R>(client: HttpClient.HttpClient.With<E, R>): HttpClient.HttpClient.With<E | RemoteStatusError, R> {
40
7
  return HttpClient.transformResponse(client, Effect.flatMap(checkStatus));
@@ -1,5 +1,5 @@
1
1
  import { Effect, Schema } from "effect";
2
- import { HttpIncomingMessage, type HttpServerRequest, HttpServerRespondable, HttpServerResponse } from "effect/http";
2
+ import { HttpIncomingMessage, HttpServerRequest, HttpServerRespondable, HttpServerResponse } from "effect/http";
3
3
  import * as HttpStatus from "effect/http/HttpStatus";
4
4
 
5
5
  export class RequestBodyTooLarge
@@ -11,7 +11,8 @@ export class RequestBodyTooLarge
11
11
  }
12
12
  }
13
13
 
14
- export const readBoundedBody = Effect.fnUntraced(function* (request: HttpServerRequest.HttpServerRequest) {
14
+ export const readBoundedBody = Effect.fnUntraced(function* () {
15
+ const request = yield* HttpServerRequest.HttpServerRequest;
15
16
  const maxBodySize = yield* HttpIncomingMessage.MaxBodySize;
16
17
  if (maxBodySize === undefined) {
17
18
  return yield* new RequestBodyTooLarge({ limit: 0 });