@shivaedev/http 0.3.0 → 0.4.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 +64 -0
- package/README.md +5 -3
- package/dist/body.d.ts +4 -4
- package/dist/body.d.ts.map +1 -1
- package/dist/body.js +12 -2
- package/dist/body.js.map +1 -1
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +8 -0
- package/dist/errors.js.map +1 -1
- package/dist/filterStatus.d.ts.map +1 -1
- package/dist/filterStatus.js +4 -2
- package/dist/filterStatus.js.map +1 -1
- package/dist/paginate.d.ts.map +1 -1
- package/dist/paginate.js +7 -4
- package/dist/paginate.js.map +1 -1
- package/package.json +4 -3
- package/src/body.ts +12 -2
- package/src/errors.ts +10 -1
- package/src/filterStatus.ts +4 -2
- package/src/paginate.ts +7 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.0 - 2026-11-02
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Read HEAD responses and statuses 204, 205 and 304 as empty bytes or text; JSON decoding still rejects empty input.
|
|
8
|
+
- Limit encoded responses by bytes exposed by the native client stream, without comparing compressed Content-Length to decoded bytes. Fetch exposes decompressed bytes; Node's native HTTP transport exposes encoded bytes.
|
|
9
|
+
- Remove userinfo, query strings and fragments from status-error URLs.
|
|
10
|
+
- Keep pagination links on the request's origin.
|
|
11
|
+
- Release response bodies before returning status or body-size failures, and keep schema failures from holding HTTP connections.
|
|
12
|
+
- Release GitHub response bodies on rejection and before refreshing a rejected installation token, so repeated failures do not exhaust the connection pool.
|
|
13
|
+
|
|
14
|
+
### Breaking
|
|
15
|
+
|
|
16
|
+
- Bounded response readers reject NaN, infinite and negative limits with the typed `InvalidBodyLimit` error from `errors.ts`. Pass a finite nonnegative byte limit and handle the new failure in the error channel.
|
|
17
|
+
- GitHub methods using the bounded response reader also expose `InvalidBodyLimit` from `@shivaedev/http/errors.ts` for invalid byte limits. Supply finite nonnegative limits and handle that failure alongside existing response failures.
|
|
18
|
+
- Pagination rejects automatic fetch redirects so custom headers cannot reach another origin. Pass a direct same-origin page URL instead of a redirecting URL; links to later pages must also use direct URLs. Other fetch options in the current Effect context are preserved. Use a client without redirect-following middleware.
|
|
19
|
+
- GitHub listing methods inherit the redirect restriction. List the repository's current API path instead of an endpoint that redirects after a rename or transfer.
|
|
20
|
+
|
|
21
|
+
## 0.3.1 - 2026-10-31
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- Include `CHANGELOG.md` in published package contents so release notes are available in `node_modules`.
|
|
26
|
+
- Release checks reject published package `files` lists that omit `CHANGELOG.md`, naming the package and how to include it.
|
|
27
|
+
- `RemoteHttpError` carries a readable message naming the status, method, host and path without query strings, headers or bodies.
|
|
28
|
+
- Failed jobs record the error message or a summary of its fields with sensitive values redacted, beside the error tag.
|
|
29
|
+
|
|
30
|
+
## 0.3.0 - 2026-10-30
|
|
31
|
+
|
|
32
|
+
### Breaking
|
|
33
|
+
|
|
34
|
+
- Request body reads fail with HTTP 413 before reading when Effect's `HttpIncomingMessage.MaxBodySize` is undefined. Provide a finite byte limit through `Effect.provideService(HttpIncomingMessage.MaxBodySize, ByteSize.bytes(limit))` when mounting native routes or webhook routes outside `appHost`.
|
|
35
|
+
- `RequestBodyTooLarge` is a Schema tagged error carrying a numeric `limit` in bytes, with `0` for an unconfigured limit. Replace bigint comparisons with number comparisons and obtain request context separately; the error no longer carries `request` or its headers.
|
|
36
|
+
|
|
37
|
+
## 0.2.0 - 2026-10-30
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- Require the Effect 4.0.6 stack.
|
|
42
|
+
|
|
43
|
+
### Fixed
|
|
44
|
+
|
|
45
|
+
- Publish committed SQL invalidations immediately for their owning database, including when another database has an open transaction.
|
|
46
|
+
|
|
47
|
+
### Breaking
|
|
48
|
+
|
|
49
|
+
- `@shivaedev/sql`: migration-body SQL failures now propagate as native typed `MigrationError` failures. Handle them with `Effect.catchTag("MigrationError", ...)` instead of defect recovery; migration-body defects remain defects.
|
|
50
|
+
- `@shivaedev/http`: bounded request-body reads use the native reader and its connection cleanup. Do not assume a rejected upload can drain an arbitrarily large unread body and reuse its connection; allow the HTTP client to open a new connection. The optional Node platform peer is no longer required by this package.
|
|
51
|
+
|
|
52
|
+
## 0.1.1 - 2026-10-29
|
|
53
|
+
|
|
54
|
+
### Fixed
|
|
55
|
+
|
|
56
|
+
- The application host constructs services, handlers and routes before listening, so startup connections are refused until requests can be answered.
|
|
57
|
+
- Server and HTTP modules import Node platform modules directly to avoid loading Redis during startup.
|
|
58
|
+
- Generated apps import Node platform modules directly, and deployment stories allow enough time for their sequential cold processes without a fixed timeout on each startup health probe.
|
|
59
|
+
|
|
60
|
+
## 0.1.0 - 2026-10-27
|
|
61
|
+
|
|
62
|
+
### Added
|
|
63
|
+
|
|
64
|
+
- First release of `@shivaedev/http`: typed status failures (`filterStatus.ts`, `errors.ts`), link pagination (`paginate.ts`) and bounded response bodies (`body.ts`) for Effect's HTTP client, and bounded request bodies for native Node routes (`server/boundedBody.ts`).
|
package/README.md
CHANGED
|
@@ -33,11 +33,13 @@ Everything here wraps a native `HttpClient`, `HttpClientResponse` or `HttpServer
|
|
|
33
33
|
|
|
34
34
|
### Calling outside APIs
|
|
35
35
|
|
|
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
|
|
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
|
-
`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. `nextLink(header)` exposes the link parsing.
|
|
38
|
+
`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
39
|
|
|
40
|
-
`readBoundedBody(response, limit)` returns bytes; `readBoundedText` decodes UTF-8, and `readBoundedJson(response, limit, schema)` decodes JSON through the supplied Schema.
|
|
40
|
+
`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`.
|
|
41
|
+
|
|
42
|
+
HEAD responses and statuses 204, 205 and 304 read as empty bytes or text, regardless of metadata lengths. JSON decoding still rejects empty input. Limits must be finite and nonnegative; NaN, either infinity and negative limits fail with `InvalidBodyLimit` from `errors.ts`, carrying `limit`. Zero accepts only an empty body.
|
|
41
43
|
|
|
42
44
|
### Reading request bodies on a native route
|
|
43
45
|
|
package/dist/body.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import type { HttpClientResponse } from "effect/http";
|
|
3
|
-
import { ResponseBodyTooLarge } from "./errors.ts";
|
|
4
|
-
export declare const readBoundedBody: (response: HttpClientResponse.HttpClientResponse, limit: number) => Effect.Effect<Uint8Array<ArrayBuffer>, import("effect/http/HttpClientError").HttpClientError | ResponseBodyTooLarge, never>;
|
|
5
|
-
export declare function readBoundedText(response: HttpClientResponse.HttpClientResponse, limit: number): Effect.Effect<string, import("effect/http/HttpClientError").HttpClientError | ResponseBodyTooLarge, never>;
|
|
6
|
-
export declare function readBoundedJson<TSchema extends Schema.Constraint>(response: HttpClientResponse.HttpClientResponse, limit: number, schema: TSchema): Effect.Effect<TSchema["Type"], import("effect/http/HttpClientError").HttpClientError | ResponseBodyTooLarge | Schema.SchemaError, TSchema["DecodingServices"]>;
|
|
3
|
+
import { InvalidBodyLimit, ResponseBodyTooLarge } from "./errors.ts";
|
|
4
|
+
export declare const readBoundedBody: (response: HttpClientResponse.HttpClientResponse, limit: number) => Effect.Effect<Uint8Array<ArrayBuffer>, import("effect/http/HttpClientError").HttpClientError | InvalidBodyLimit | ResponseBodyTooLarge, never>;
|
|
5
|
+
export declare function readBoundedText(response: HttpClientResponse.HttpClientResponse, limit: number): Effect.Effect<string, import("effect/http/HttpClientError").HttpClientError | InvalidBodyLimit | ResponseBodyTooLarge, never>;
|
|
6
|
+
export declare function readBoundedJson<TSchema extends Schema.Constraint>(response: HttpClientResponse.HttpClientResponse, limit: number, schema: TSchema): Effect.Effect<TSchema["Type"], import("effect/http/HttpClientError").HttpClientError | InvalidBodyLimit | ResponseBodyTooLarge | Schema.SchemaError, TSchema["DecodingServices"]>;
|
|
7
7
|
//# sourceMappingURL=body.d.ts.map
|
package/dist/body.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../src/body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../src/body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAErE,eAAO,MAAM,eAAe,oNAkC1B,CAAC;AAEH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,kBAAkB,CAAC,kBAAkB,EAAE,KAAK,EAAE,MAAM,iIAE7F;AAED,wBAAgB,eAAe,CAAC,OAAO,SAAS,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,kBAAkB,CAAC,kBAAkB,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,qLAEjJ"}
|
package/dist/body.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
|
-
import { ResponseBodyTooLarge } from "./errors.js";
|
|
2
|
+
import { InvalidBodyLimit, ResponseBodyTooLarge } from "./errors.js";
|
|
3
3
|
export const readBoundedBody = Effect.fnUntraced(function* (response, limit) {
|
|
4
|
+
const empty = response.request.method === "HEAD" || response.status === 204 || response.status === 205 || response.status === 304;
|
|
5
|
+
const invalid = !Number.isFinite(limit) || limit < 0;
|
|
4
6
|
const length = response.headers["content-length"];
|
|
5
|
-
|
|
7
|
+
const oversized = response.headers["content-encoding"] === undefined && length !== undefined && Number(length) > limit;
|
|
8
|
+
if (invalid || empty || oversized) {
|
|
9
|
+
yield* Effect.scoped(Stream.toPull(response.stream));
|
|
10
|
+
if (invalid) {
|
|
11
|
+
return yield* new InvalidBodyLimit({ limit });
|
|
12
|
+
}
|
|
13
|
+
if (empty) {
|
|
14
|
+
return new Uint8Array();
|
|
15
|
+
}
|
|
6
16
|
return yield* new ResponseBodyTooLarge({ limit });
|
|
7
17
|
}
|
|
8
18
|
const chunks = [];
|
package/dist/body.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body.js","sourceRoot":"","sources":["../src/body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../src/body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAErE,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAA+C,EAAE,KAAa;IACzH,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC;IAClI,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,SAAS,IAAI,MA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C,UAAU,CAAC;IAC5B,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,eAAe,CAAC,QAA+C,EAAE,KAAa;IAC7F,OAAO,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACjG,CAAC;AAED,MAAM,UAAU,eAAe,CAAoC,QAA+C,EAAE,KAAa,EAAE,MAAe;IACjJ,OAAO,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACpH,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ declare const RemoteHttpError_base: Schema.Class<RemoteHttpError, Schema.TaggedS
|
|
|
34
34
|
url: Schema.String;
|
|
35
35
|
}>, import("effect/Cause").YieldableError>;
|
|
36
36
|
export declare class RemoteHttpError extends RemoteHttpError_base {
|
|
37
|
+
get message(): string;
|
|
37
38
|
}
|
|
38
39
|
export type RemoteStatusError = RemoteUnauthorized | RemoteNotFound | RemoteGone | RemoteRateLimited | RemoteHttpError;
|
|
39
40
|
declare const PaginationLinkError_base: Schema.Class<PaginationLinkError, Schema.TaggedStruct<"PaginationLinkError", {
|
|
@@ -47,5 +48,10 @@ declare const ResponseBodyTooLarge_base: Schema.Class<ResponseBodyTooLarge, Sche
|
|
|
47
48
|
}>, import("effect/Cause").YieldableError>;
|
|
48
49
|
export declare class ResponseBodyTooLarge extends ResponseBodyTooLarge_base {
|
|
49
50
|
}
|
|
51
|
+
declare const InvalidBodyLimit_base: Schema.Class<InvalidBodyLimit, Schema.TaggedStruct<"InvalidBodyLimit", {
|
|
52
|
+
readonly limit: Schema.Number;
|
|
53
|
+
}>, import("effect/Cause").YieldableError>;
|
|
54
|
+
export declare class InvalidBodyLimit extends InvalidBodyLimit_base {
|
|
55
|
+
}
|
|
50
56
|
export {};
|
|
51
57
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/errors.js
CHANGED
|
@@ -12,6 +12,10 @@ export class RemoteRateLimited extends Schema.TaggedError()("RemoteRateLimited",
|
|
|
12
12
|
}) {
|
|
13
13
|
}
|
|
14
14
|
export class RemoteHttpError extends Schema.TaggedError()("RemoteHttpError", answer) {
|
|
15
|
+
get message() {
|
|
16
|
+
const url = new URL(this.url);
|
|
17
|
+
return `HTTP ${this.status}: ${this.method} ${url.host}${url.pathname}`;
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
export class PaginationLinkError extends Schema.TaggedError()("PaginationLinkError", {
|
|
17
21
|
reason: Schema.Literals(["cross-origin", "invalid"]),
|
|
@@ -22,4 +26,8 @@ export class ResponseBodyTooLarge extends Schema.TaggedError()("ResponseBodyTooL
|
|
|
22
26
|
limit: Schema.Number,
|
|
23
27
|
}) {
|
|
24
28
|
}
|
|
29
|
+
export class InvalidBodyLimit extends Schema.TaggedError()("InvalidBodyLimit", {
|
|
30
|
+
limit: Schema.Number,
|
|
31
|
+
}) {
|
|
32
|
+
}
|
|
25
33
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;AAEpF,MAAM,OAAO,kBAAmB,SAAQ,MAAM,CAAC,WAAW,EAAsB,CAAC,oBAAoB,EAAE,MAAM,CAAC;CAAG;AACjH,MAAM,OAAO,cAAe,SAAQ,MAAM,CAAC,WAAW,EAAkB,CAAC,gBAAgB,EAAE,MAAM,CAAC;CAAG;AACrG,MAAM,OAAO,UAAW,SAAQ,MAAM,CAAC,WAAW,EAAc,CAAC,YAAY,EAAE,MAAM,CAAC;C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AAI,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IACzE,CAAC;CACD;AAID,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 +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;
|
|
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"}
|
package/dist/filterStatus.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateTime, Effect } from "effect";
|
|
1
|
+
import { DateTime, Effect, Stream } from "effect";
|
|
2
2
|
import { HttpClient } from "effect/http";
|
|
3
3
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
4
4
|
import { RemoteGone, RemoteHttpError, RemoteNotFound, RemoteRateLimited, RemoteUnauthorized } from "./errors.js";
|
|
@@ -8,7 +8,8 @@ const checkStatus = Effect.fnUntraced(function* (response) {
|
|
|
8
8
|
if (status >= HttpStatus.fromLiteral("OK") && status < HttpStatus.fromLiteral("MultipleChoices")) {
|
|
9
9
|
return response;
|
|
10
10
|
}
|
|
11
|
-
const
|
|
11
|
+
const url = new URL(request.url);
|
|
12
|
+
const fields = { method: request.method, status, url: `${url.origin}${url.pathname}` };
|
|
12
13
|
let error;
|
|
13
14
|
switch (status) {
|
|
14
15
|
case HttpStatus.fromLiteral("Unauthorized"):
|
|
@@ -31,6 +32,7 @@ const checkStatus = Effect.fnUntraced(function* (response) {
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
35
|
+
yield* Effect.scoped(Stream.toPull(response.stream));
|
|
34
36
|
return yield* Effect.fail(error);
|
|
35
37
|
});
|
|
36
38
|
export function filterStatus(client) {
|
package/dist/filterStatus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterStatus.js","sourceRoot":"","sources":["../src/filterStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
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,UAA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KAAK,UAAU,CAAC,WAAW,CAAC,oBAAoB,CAAC,IAAI,MAAM,KAAK,SAAS,CAAC,EAAE,CAAC;gBAC/I,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAChE,KAAK,GAAG,IAAI,iBAAiB,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;YACnG,CAAC;iBAAM,CAAC;gBACP,KAAK,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;YACrC,CAAC;QACF,CAAC;IACF,CAAC;IACD,KAAK,CAAC,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"}
|
package/dist/paginate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.d.ts","sourceRoot":"","sources":["../src/paginate.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"paginate.d.ts","sourceRoot":"","sources":["../src/paginate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAmB,KAAK,UAAU,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC3G,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAoBlD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,CAAC,iBAAiB,oFAmBlH"}
|
package/dist/paginate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Effect, Stream } from "effect";
|
|
2
|
-
import { HttpClientRequest } from "effect/http";
|
|
1
|
+
import { Effect, Option, Stream } from "effect";
|
|
2
|
+
import { FetchHttpClient, HttpClientRequest } from "effect/http";
|
|
3
3
|
import { PaginationLinkError } from "./errors.js";
|
|
4
4
|
import { nextLink } from "./nextLink.js";
|
|
5
5
|
const nextRequest = Effect.fnUntraced(function* (response) {
|
|
@@ -13,7 +13,7 @@ const nextRequest = Effect.fnUntraced(function* (response) {
|
|
|
13
13
|
catch: () => new PaginationLinkError({ reason: "invalid", url }),
|
|
14
14
|
try: () => new URL(link, current),
|
|
15
15
|
});
|
|
16
|
-
if (next.origin !== new URL(
|
|
16
|
+
if (next.origin !== new URL(response.request.url).origin) {
|
|
17
17
|
return yield* new PaginationLinkError({ reason: "cross-origin", url });
|
|
18
18
|
}
|
|
19
19
|
return HttpClientRequest.setUrl(response.request, next);
|
|
@@ -24,7 +24,10 @@ export function paginate(client, first) {
|
|
|
24
24
|
if (request === undefined) {
|
|
25
25
|
return undefined;
|
|
26
26
|
}
|
|
27
|
-
const
|
|
27
|
+
const options = yield* Effect.serviceOption(FetchHttpClient.RequestInit);
|
|
28
|
+
const response = yield* client
|
|
29
|
+
.execute(request)
|
|
30
|
+
.pipe(Effect.provideService(FetchHttpClient.RequestInit, { ...Option.getOrUndefined(options), redirect: "error" }));
|
|
28
31
|
return [response, response];
|
|
29
32
|
}));
|
|
30
33
|
}
|
package/dist/paginate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.js","sourceRoot":"","sources":["../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,IAAI,mBAAmB,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,QAAQ,CAAO,MAAwC,EAAE,KAA0C;IAClH,OAAO,MAAM,CAAC,MAAM,CAKlB,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAClB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnB,MAAM,OAAO,GAAG,iBAAiB,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACjG,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM;aAC5B,OAAO,CAAC,OAAO,CAAC;aAChB,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,eAAe,CAAC,WAAW,EAAE,EAAE,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QACrH,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAU,CAAC;IACtC,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Bounded HTTP bodies, status failures and paginated clients over Effect HTTP",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -41,12 +41,13 @@
|
|
|
41
41
|
"!src/**/*.spec.ts",
|
|
42
42
|
"!src/**/*.spec.tsx",
|
|
43
43
|
"!src/**/test-support",
|
|
44
|
+
"CHANGELOG.md",
|
|
44
45
|
"README.md"
|
|
45
46
|
],
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@effect/platform-node": "4.0.6",
|
|
48
|
-
"@shivaedev/quality": "0.
|
|
49
|
-
"@shivaedev/test-story": "0.
|
|
49
|
+
"@shivaedev/quality": "0.55.0",
|
|
50
|
+
"@shivaedev/test-story": "0.33.0",
|
|
50
51
|
"@types/node": "24.19.2",
|
|
51
52
|
"effect": "4.0.6",
|
|
52
53
|
"typescript": "7.0.2",
|
package/src/body.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
2
|
import type { HttpClientResponse } from "effect/http";
|
|
3
|
-
import { ResponseBodyTooLarge } from "./errors.ts";
|
|
3
|
+
import { InvalidBodyLimit, ResponseBodyTooLarge } from "./errors.ts";
|
|
4
4
|
|
|
5
5
|
export const readBoundedBody = Effect.fnUntraced(function* (response: HttpClientResponse.HttpClientResponse, limit: number) {
|
|
6
|
+
const empty = response.request.method === "HEAD" || response.status === 204 || response.status === 205 || response.status === 304;
|
|
7
|
+
const invalid = !Number.isFinite(limit) || limit < 0;
|
|
6
8
|
const length = response.headers["content-length"];
|
|
7
|
-
|
|
9
|
+
const oversized = response.headers["content-encoding"] === undefined && length !== undefined && Number(length) > limit;
|
|
10
|
+
if (invalid || empty || oversized) {
|
|
11
|
+
yield* Effect.scoped(Stream.toPull(response.stream));
|
|
12
|
+
if (invalid) {
|
|
13
|
+
return yield* new InvalidBodyLimit({ limit });
|
|
14
|
+
}
|
|
15
|
+
if (empty) {
|
|
16
|
+
return new Uint8Array();
|
|
17
|
+
}
|
|
8
18
|
return yield* new ResponseBodyTooLarge({ limit });
|
|
9
19
|
}
|
|
10
20
|
const chunks: Uint8Array[] = [];
|
package/src/errors.ts
CHANGED
|
@@ -9,7 +9,12 @@ export class RemoteRateLimited extends Schema.TaggedError<RemoteRateLimited>()("
|
|
|
9
9
|
...answer,
|
|
10
10
|
retryAfter: Schema.optionalKey(Schema.DateTimeUtc),
|
|
11
11
|
}) {}
|
|
12
|
-
export class RemoteHttpError extends Schema.TaggedError<RemoteHttpError>()("RemoteHttpError", answer) {
|
|
12
|
+
export class RemoteHttpError extends Schema.TaggedError<RemoteHttpError>()("RemoteHttpError", answer) {
|
|
13
|
+
override get message(): string {
|
|
14
|
+
const url = new URL(this.url);
|
|
15
|
+
return `HTTP ${this.status}: ${this.method} ${url.host}${url.pathname}`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
13
18
|
|
|
14
19
|
export type RemoteStatusError = RemoteUnauthorized | RemoteNotFound | RemoteGone | RemoteRateLimited | RemoteHttpError;
|
|
15
20
|
|
|
@@ -21,3 +26,7 @@ export class PaginationLinkError extends Schema.TaggedError<PaginationLinkError>
|
|
|
21
26
|
export class ResponseBodyTooLarge extends Schema.TaggedError<ResponseBodyTooLarge>()("ResponseBodyTooLarge", {
|
|
22
27
|
limit: Schema.Number,
|
|
23
28
|
}) {}
|
|
29
|
+
|
|
30
|
+
export class InvalidBodyLimit extends Schema.TaggedError<InvalidBodyLimit>()("InvalidBodyLimit", {
|
|
31
|
+
limit: Schema.Number,
|
|
32
|
+
}) {}
|
package/src/filterStatus.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DateTime, Effect } from "effect";
|
|
1
|
+
import { DateTime, Effect, Stream } from "effect";
|
|
2
2
|
import { HttpClient, type HttpClientResponse } from "effect/http";
|
|
3
3
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
4
4
|
import { RemoteGone, RemoteHttpError, RemoteNotFound, RemoteRateLimited, type RemoteStatusError, RemoteUnauthorized } from "./errors.ts";
|
|
@@ -9,7 +9,8 @@ const checkStatus = Effect.fnUntraced(function* (response: HttpClientResponse.Ht
|
|
|
9
9
|
if (status >= HttpStatus.fromLiteral("OK") && status < HttpStatus.fromLiteral("MultipleChoices")) {
|
|
10
10
|
return response;
|
|
11
11
|
}
|
|
12
|
-
const
|
|
12
|
+
const url = new URL(request.url);
|
|
13
|
+
const fields = { method: request.method, status, url: `${url.origin}${url.pathname}` };
|
|
13
14
|
let error: RemoteStatusError;
|
|
14
15
|
switch (status) {
|
|
15
16
|
case HttpStatus.fromLiteral("Unauthorized"):
|
|
@@ -31,6 +32,7 @@ const checkStatus = Effect.fnUntraced(function* (response: HttpClientResponse.Ht
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
35
|
+
yield* Effect.scoped(Stream.toPull(response.stream));
|
|
34
36
|
return yield* Effect.fail(error);
|
|
35
37
|
});
|
|
36
38
|
|
package/src/paginate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Effect, Stream } from "effect";
|
|
2
|
-
import { type HttpClient, HttpClientRequest, type HttpClientResponse } from "effect/http";
|
|
1
|
+
import { Effect, Option, Stream } from "effect";
|
|
2
|
+
import { FetchHttpClient, type HttpClient, HttpClientRequest, type HttpClientResponse } from "effect/http";
|
|
3
3
|
import { PaginationLinkError } from "./errors.ts";
|
|
4
4
|
import { nextLink } from "./nextLink.ts";
|
|
5
5
|
|
|
@@ -14,7 +14,7 @@ const nextRequest = Effect.fnUntraced(function* (response: HttpClientResponse.Ht
|
|
|
14
14
|
catch: () => new PaginationLinkError({ reason: "invalid", url }),
|
|
15
15
|
try: () => new URL(link, current),
|
|
16
16
|
});
|
|
17
|
-
if (next.origin !== new URL(
|
|
17
|
+
if (next.origin !== new URL(response.request.url).origin) {
|
|
18
18
|
return yield* new PaginationLinkError({ reason: "cross-origin", url });
|
|
19
19
|
}
|
|
20
20
|
return HttpClientRequest.setUrl(response.request, next);
|
|
@@ -32,7 +32,10 @@ export function paginate<E, R>(client: HttpClient.HttpClient.With<E, R>, first:
|
|
|
32
32
|
if (request === undefined) {
|
|
33
33
|
return undefined;
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const options = yield* Effect.serviceOption(FetchHttpClient.RequestInit);
|
|
36
|
+
const response = yield* client
|
|
37
|
+
.execute(request)
|
|
38
|
+
.pipe(Effect.provideService(FetchHttpClient.RequestInit, { ...Option.getOrUndefined(options), redirect: "error" }));
|
|
36
39
|
return [response, response] as const;
|
|
37
40
|
}),
|
|
38
41
|
);
|