@siteimprove/alfa-http 0.89.5
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 +163 -0
- package/dist/body.d.ts +27 -0
- package/dist/body.js +13 -0
- package/dist/cookie.d.ts +31 -0
- package/dist/cookie.js +48 -0
- package/dist/cookies.d.ts +37 -0
- package/dist/cookies.js +64 -0
- package/dist/header.d.ts +40 -0
- package/dist/header.js +58 -0
- package/dist/headers.d.ts +45 -0
- package/dist/headers.js +72 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/request.d.ts +65 -0
- package/dist/request.js +99 -0
- package/dist/response.d.ts +64 -0
- package/dist/response.js +98 -0
- package/package.json +43 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# @siteimprove/alfa-http
|
|
2
|
+
|
|
3
|
+
## 0.89.3
|
|
4
|
+
|
|
5
|
+
## 0.89.2
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- **Changed:** Trying to fix a problem in generating provenance statements ([#1674](https://github.com/Siteimprove/alfa/pull/1674))
|
|
10
|
+
|
|
11
|
+
## 0.89.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- **Added:** Trying to publish Alfa packages on the npm registry ([#1673](https://github.com/Siteimprove/alfa/pull/1673))
|
|
16
|
+
|
|
17
|
+
## 0.89.0
|
|
18
|
+
|
|
19
|
+
## 0.88.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- **Fixed:** The publish flow was updated to a new version. ([`a2f19cf9a6c7c72b8bf085597e4f1a95ac3e4eb2`](https://github.com/Siteimprove/alfa/commit/a2f19cf9a6c7c72b8bf085597e4f1a95ac3e4eb2))
|
|
24
|
+
|
|
25
|
+
Some 0.87.\* versions were generating uninstallable package. This should be fixed now.
|
|
26
|
+
|
|
27
|
+
## 0.87.12
|
|
28
|
+
|
|
29
|
+
## 0.87.11
|
|
30
|
+
|
|
31
|
+
## 0.87.10
|
|
32
|
+
|
|
33
|
+
## 0.87.7
|
|
34
|
+
|
|
35
|
+
## 0.87.6
|
|
36
|
+
|
|
37
|
+
## 0.87.5
|
|
38
|
+
|
|
39
|
+
## 0.87.4
|
|
40
|
+
|
|
41
|
+
## 0.87.3
|
|
42
|
+
|
|
43
|
+
## 0.87.2
|
|
44
|
+
|
|
45
|
+
## 0.87.1
|
|
46
|
+
|
|
47
|
+
## 0.87.0
|
|
48
|
+
|
|
49
|
+
## 0.86.2
|
|
50
|
+
|
|
51
|
+
## 0.86.1
|
|
52
|
+
|
|
53
|
+
## 0.86.0
|
|
54
|
+
|
|
55
|
+
### Minor Changes
|
|
56
|
+
|
|
57
|
+
- **Breaking:** TS resolution has been changed to `Node16`, target to `es2022`. ([#1636](https://github.com/Siteimprove/alfa/pull/1636))
|
|
58
|
+
|
|
59
|
+
- **Breaking:** Alfa is now distributed as ESM rather than CJS modules; projects using it must be ESM or use dynamic `import()`. ([#1636](https://github.com/Siteimprove/alfa/pull/1636))
|
|
60
|
+
|
|
61
|
+
⚠️ This is the last of a series of changes on the internal structure and build process of distributed packages that was started with v0.85.0.
|
|
62
|
+
|
|
63
|
+
## 0.85.1
|
|
64
|
+
|
|
65
|
+
## 0.85.0
|
|
66
|
+
|
|
67
|
+
### Minor Changes
|
|
68
|
+
|
|
69
|
+
- **Breaking:** The .js files are now built in the `dist` folder rather than in `src`. ([#1628](https://github.com/Siteimprove/alfa/pull/1628))
|
|
70
|
+
|
|
71
|
+
⚠️ This is the first of a series of changes on the internal structure and build process of distributed packages. It is probably better to not use this version and wait until more of these internal changes have been done to jump directly to the final result. We are internally releasing these changes for validation purpose only.
|
|
72
|
+
|
|
73
|
+
This should not impact consumers, the `package.json` files should be set correctly to consume these files.
|
|
74
|
+
|
|
75
|
+
## 0.84.0
|
|
76
|
+
|
|
77
|
+
## 0.83.1
|
|
78
|
+
|
|
79
|
+
## 0.83.0
|
|
80
|
+
|
|
81
|
+
## 0.82.0
|
|
82
|
+
|
|
83
|
+
### Minor Changes
|
|
84
|
+
|
|
85
|
+
- **Added:** Serialization options are now accepted, and passed on, by `toJSON()` on these types. ([#1622](https://github.com/Siteimprove/alfa/pull/1622))
|
|
86
|
+
|
|
87
|
+
- **Breaking:** Node 18 is no longer supported. ([#1618](https://github.com/Siteimprove/alfa/pull/1618))
|
|
88
|
+
|
|
89
|
+
## 0.81.0
|
|
90
|
+
|
|
91
|
+
### Patch Changes
|
|
92
|
+
|
|
93
|
+
- **Added:** Each package now contains its internal dependency graph in its `docs` directory. ([#1610](https://github.com/Siteimprove/alfa/pull/1610))
|
|
94
|
+
|
|
95
|
+
## 0.80.0
|
|
96
|
+
|
|
97
|
+
## 0.79.1
|
|
98
|
+
|
|
99
|
+
## 0.79.0
|
|
100
|
+
|
|
101
|
+
## 0.78.2
|
|
102
|
+
|
|
103
|
+
## 0.78.1
|
|
104
|
+
|
|
105
|
+
## 0.78.0
|
|
106
|
+
|
|
107
|
+
## 0.77.0
|
|
108
|
+
|
|
109
|
+
## 0.76.0
|
|
110
|
+
|
|
111
|
+
## 0.75.2
|
|
112
|
+
|
|
113
|
+
## 0.75.1
|
|
114
|
+
|
|
115
|
+
## 0.75.0
|
|
116
|
+
|
|
117
|
+
## 0.74.0
|
|
118
|
+
|
|
119
|
+
## 0.73.0
|
|
120
|
+
|
|
121
|
+
## 0.72.0
|
|
122
|
+
|
|
123
|
+
## 0.71.1
|
|
124
|
+
|
|
125
|
+
## 0.71.0
|
|
126
|
+
|
|
127
|
+
## 0.70.0
|
|
128
|
+
|
|
129
|
+
## 0.69.0
|
|
130
|
+
|
|
131
|
+
## 0.68.0
|
|
132
|
+
|
|
133
|
+
## 0.67.0
|
|
134
|
+
|
|
135
|
+
## 0.66.0
|
|
136
|
+
|
|
137
|
+
## 0.65.1
|
|
138
|
+
|
|
139
|
+
## 0.65.0
|
|
140
|
+
|
|
141
|
+
### Minor Changes
|
|
142
|
+
|
|
143
|
+
- **Removed:** Many pieces of code are no longer exported. These were mostly internal exports that are no longer used in other files and should not impact intended usage of the packages. ([#1437](https://github.com/Siteimprove/alfa/pull/1437))
|
|
144
|
+
|
|
145
|
+
## 0.64.0
|
|
146
|
+
|
|
147
|
+
## 0.63.3
|
|
148
|
+
|
|
149
|
+
## 0.63.2
|
|
150
|
+
|
|
151
|
+
## 0.63.1
|
|
152
|
+
|
|
153
|
+
### Patch Changes
|
|
154
|
+
|
|
155
|
+
- **Fixed:** Added missing dependencies ([#1418](https://github.com/Siteimprove/alfa/pull/1418))
|
|
156
|
+
|
|
157
|
+
Some internal dependencies were missing, causing build failure in projects that use PnP strategies.
|
|
158
|
+
|
|
159
|
+
## 0.63.0
|
|
160
|
+
|
|
161
|
+
## 0.62.2
|
|
162
|
+
|
|
163
|
+
## 0.62.1
|
package/dist/body.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as earl from "@siteimprove/alfa-earl";
|
|
2
|
+
/**
|
|
3
|
+
* {@link https://fetch.spec.whatwg.org/#body-mixin}
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface Body {
|
|
8
|
+
/**
|
|
9
|
+
* {@link https://fetch.spec.whatwg.org/#dom-body-body}
|
|
10
|
+
*/
|
|
11
|
+
readonly body: ArrayBuffer;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare namespace Body {
|
|
17
|
+
interface EARL extends earl.EARL {
|
|
18
|
+
"@context": {
|
|
19
|
+
cnt: "http://www.w3.org/2011/content#";
|
|
20
|
+
};
|
|
21
|
+
"@type": ["cnt:Content", "cnt:ContentAsText"];
|
|
22
|
+
"cnt:characterEncoding": "utf-8";
|
|
23
|
+
"cnt:chars": string;
|
|
24
|
+
}
|
|
25
|
+
function isBody(value: unknown): value is Body;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=body.d.ts.map
|
package/dist/body.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Refinement } from "@siteimprove/alfa-refinement";
|
|
2
|
+
const { isObject } = Refinement;
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export var Body;
|
|
7
|
+
(function (Body) {
|
|
8
|
+
function isBody(value) {
|
|
9
|
+
return isObject(value) && value.body instanceof ArrayBuffer;
|
|
10
|
+
}
|
|
11
|
+
Body.isBody = isBody;
|
|
12
|
+
})(Body || (Body = {}));
|
|
13
|
+
//# sourceMappingURL=body.js.map
|
package/dist/cookie.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Equatable } from "@siteimprove/alfa-equatable";
|
|
2
|
+
import type { Serializable } from "@siteimprove/alfa-json";
|
|
3
|
+
import type * as json from "@siteimprove/alfa-json";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class Cookie implements Equatable, Serializable<Cookie.JSON> {
|
|
8
|
+
static of(name: string, value: string): Cookie;
|
|
9
|
+
private readonly _name;
|
|
10
|
+
private readonly _value;
|
|
11
|
+
private constructor();
|
|
12
|
+
get name(): string;
|
|
13
|
+
get value(): string;
|
|
14
|
+
equals(value: Cookie): boolean;
|
|
15
|
+
equals(value: unknown): value is this;
|
|
16
|
+
toJSON(): Cookie.JSON;
|
|
17
|
+
toString(): string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare namespace Cookie {
|
|
23
|
+
interface JSON {
|
|
24
|
+
[key: string]: json.JSON;
|
|
25
|
+
name: string;
|
|
26
|
+
value: string;
|
|
27
|
+
}
|
|
28
|
+
function from(json: JSON): Cookie;
|
|
29
|
+
function isCookie(value: unknown): value is Cookie;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=cookie.d.ts.map
|
package/dist/cookie.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export class Cookie {
|
|
5
|
+
static of(name, value) {
|
|
6
|
+
return new Cookie(name, value);
|
|
7
|
+
}
|
|
8
|
+
_name;
|
|
9
|
+
_value;
|
|
10
|
+
constructor(name, value) {
|
|
11
|
+
this._name = name;
|
|
12
|
+
this._value = value;
|
|
13
|
+
}
|
|
14
|
+
get name() {
|
|
15
|
+
return this._name;
|
|
16
|
+
}
|
|
17
|
+
get value() {
|
|
18
|
+
return this._value;
|
|
19
|
+
}
|
|
20
|
+
equals(value) {
|
|
21
|
+
return (value instanceof Cookie &&
|
|
22
|
+
value._name === this._name &&
|
|
23
|
+
value._value === this._value);
|
|
24
|
+
}
|
|
25
|
+
toJSON() {
|
|
26
|
+
return {
|
|
27
|
+
name: this._name,
|
|
28
|
+
value: this._value,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
toString() {
|
|
32
|
+
return `${this._name}=${this._value}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
(function (Cookie) {
|
|
39
|
+
function from(json) {
|
|
40
|
+
return Cookie.of(json.name, json.value);
|
|
41
|
+
}
|
|
42
|
+
Cookie.from = from;
|
|
43
|
+
function isCookie(value) {
|
|
44
|
+
return value instanceof Cookie;
|
|
45
|
+
}
|
|
46
|
+
Cookie.isCookie = isCookie;
|
|
47
|
+
})(Cookie || (Cookie = {}));
|
|
48
|
+
//# sourceMappingURL=cookie.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
2
|
+
import type { Serializable } from "@siteimprove/alfa-json";
|
|
3
|
+
import type { Option } from "@siteimprove/alfa-option";
|
|
4
|
+
import { Cookie } from "./cookie.js";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class Cookies implements Iterable<Cookie>, Serializable<Cookies.JSON> {
|
|
9
|
+
/**
|
|
10
|
+
* @remarks
|
|
11
|
+
* If the iterable contains cookies with duplicate names, the last cookie with
|
|
12
|
+
* a given name will take precedence.
|
|
13
|
+
*/
|
|
14
|
+
static of(cookies: Iterable<Cookie>): Cookies;
|
|
15
|
+
private static _empty;
|
|
16
|
+
static empty(): Cookies;
|
|
17
|
+
private readonly _cookies;
|
|
18
|
+
private constructor();
|
|
19
|
+
get(name: string): Option<Cookie>;
|
|
20
|
+
has(name: string): boolean;
|
|
21
|
+
add(cookie: Cookie): Cookies;
|
|
22
|
+
delete(name: string): Cookies;
|
|
23
|
+
[Symbol.iterator](): Iterator<Cookie>;
|
|
24
|
+
toArray(): Array<Cookie>;
|
|
25
|
+
toJSON(): Cookies.JSON;
|
|
26
|
+
toString(): string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare namespace Cookies {
|
|
32
|
+
interface JSON extends Array<Cookie.JSON> {
|
|
33
|
+
}
|
|
34
|
+
function from(json: JSON): Cookies;
|
|
35
|
+
function isCookies(value: unknown): value is Cookies;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=cookies.d.ts.map
|
package/dist/cookies.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
2
|
+
import { Map } from "@siteimprove/alfa-map";
|
|
3
|
+
import { Cookie } from "./cookie.js";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class Cookies {
|
|
8
|
+
/**
|
|
9
|
+
* @remarks
|
|
10
|
+
* If the iterable contains cookies with duplicate names, the last cookie with
|
|
11
|
+
* a given name will take precedence.
|
|
12
|
+
*/
|
|
13
|
+
static of(cookies) {
|
|
14
|
+
return new Cookies(Map.from(Iterable.map(cookies, (cookie) => [cookie.name, cookie])));
|
|
15
|
+
}
|
|
16
|
+
static _empty = new Cookies(Map.empty());
|
|
17
|
+
static empty() {
|
|
18
|
+
return this._empty;
|
|
19
|
+
}
|
|
20
|
+
_cookies;
|
|
21
|
+
constructor(cookies) {
|
|
22
|
+
this._cookies = cookies;
|
|
23
|
+
}
|
|
24
|
+
get(name) {
|
|
25
|
+
return this._cookies.get(name);
|
|
26
|
+
}
|
|
27
|
+
has(name) {
|
|
28
|
+
return this._cookies.has(name);
|
|
29
|
+
}
|
|
30
|
+
add(cookie) {
|
|
31
|
+
return new Cookies(this._cookies.set(cookie.name, cookie));
|
|
32
|
+
}
|
|
33
|
+
delete(name) {
|
|
34
|
+
return new Cookies(this._cookies.delete(name));
|
|
35
|
+
}
|
|
36
|
+
*[Symbol.iterator]() {
|
|
37
|
+
yield* this._cookies.values();
|
|
38
|
+
}
|
|
39
|
+
toArray() {
|
|
40
|
+
return [...this];
|
|
41
|
+
}
|
|
42
|
+
toJSON() {
|
|
43
|
+
return this.toArray().map((cookie) => cookie.toJSON());
|
|
44
|
+
}
|
|
45
|
+
toString() {
|
|
46
|
+
return this.toArray()
|
|
47
|
+
.map((cookie) => cookie.toString())
|
|
48
|
+
.join("; ");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
(function (Cookies) {
|
|
55
|
+
function from(json) {
|
|
56
|
+
return Cookies.of(json.map((cookie) => Cookie.from(cookie)));
|
|
57
|
+
}
|
|
58
|
+
Cookies.from = from;
|
|
59
|
+
function isCookies(value) {
|
|
60
|
+
return value instanceof Cookies;
|
|
61
|
+
}
|
|
62
|
+
Cookies.isCookies = isCookies;
|
|
63
|
+
})(Cookies || (Cookies = {}));
|
|
64
|
+
//# sourceMappingURL=cookies.js.map
|
package/dist/header.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Equatable } from "@siteimprove/alfa-equatable";
|
|
2
|
+
import type * as earl from "@siteimprove/alfa-earl";
|
|
3
|
+
import type * as json from "@siteimprove/alfa-json";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class Header implements Equatable, json.Serializable<Header.JSON>, earl.Serializable<Header.EARL> {
|
|
8
|
+
static of(name: string, value: string): Header;
|
|
9
|
+
private readonly _name;
|
|
10
|
+
private readonly _value;
|
|
11
|
+
private constructor();
|
|
12
|
+
get name(): string;
|
|
13
|
+
get value(): string;
|
|
14
|
+
equals(value: Header): boolean;
|
|
15
|
+
equals(value: unknown): value is this;
|
|
16
|
+
toJSON(options?: json.Serializable.Options): Header.JSON;
|
|
17
|
+
toEARL(): Header.EARL;
|
|
18
|
+
toString(): string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare namespace Header {
|
|
24
|
+
interface JSON {
|
|
25
|
+
[key: string]: json.JSON;
|
|
26
|
+
name: string;
|
|
27
|
+
value: string;
|
|
28
|
+
}
|
|
29
|
+
interface EARL extends earl.EARL {
|
|
30
|
+
"@context": {
|
|
31
|
+
http: "http://www.w3.org/2011/http#";
|
|
32
|
+
};
|
|
33
|
+
"@type": "http:MessageHeader";
|
|
34
|
+
"http:fieldName": string;
|
|
35
|
+
"http:fieldValue": string;
|
|
36
|
+
}
|
|
37
|
+
function from(json: JSON): Header;
|
|
38
|
+
function isHeader(value: unknown): value is Header;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=header.d.ts.map
|
package/dist/header.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export class Header {
|
|
5
|
+
static of(name, value) {
|
|
6
|
+
return new Header(name, value);
|
|
7
|
+
}
|
|
8
|
+
_name;
|
|
9
|
+
_value;
|
|
10
|
+
constructor(name, value) {
|
|
11
|
+
this._name = name;
|
|
12
|
+
this._value = value;
|
|
13
|
+
}
|
|
14
|
+
get name() {
|
|
15
|
+
return this._name;
|
|
16
|
+
}
|
|
17
|
+
get value() {
|
|
18
|
+
return this._value;
|
|
19
|
+
}
|
|
20
|
+
equals(value) {
|
|
21
|
+
return (value instanceof Header &&
|
|
22
|
+
value._name === this._name &&
|
|
23
|
+
value._value === this._value);
|
|
24
|
+
}
|
|
25
|
+
toJSON(options) {
|
|
26
|
+
return {
|
|
27
|
+
name: this._name,
|
|
28
|
+
value: this._value,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
toEARL() {
|
|
32
|
+
return {
|
|
33
|
+
"@context": {
|
|
34
|
+
http: "http://www.w3.org/2011/http#",
|
|
35
|
+
},
|
|
36
|
+
"@type": "http:MessageHeader",
|
|
37
|
+
"http:fieldName": this._name,
|
|
38
|
+
"http:fieldValue": this._value,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
toString() {
|
|
42
|
+
return `${this._name}: ${this._value}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
(function (Header) {
|
|
49
|
+
function from(json) {
|
|
50
|
+
return Header.of(json.name, json.value);
|
|
51
|
+
}
|
|
52
|
+
Header.from = from;
|
|
53
|
+
function isHeader(value) {
|
|
54
|
+
return value instanceof Header;
|
|
55
|
+
}
|
|
56
|
+
Header.isHeader = isHeader;
|
|
57
|
+
})(Header || (Header = {}));
|
|
58
|
+
//# sourceMappingURL=header.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
2
|
+
import type { Option } from "@siteimprove/alfa-option";
|
|
3
|
+
import type * as earl from "@siteimprove/alfa-earl";
|
|
4
|
+
import type * as json from "@siteimprove/alfa-json";
|
|
5
|
+
import { Header } from "./header.js";
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class Headers implements Iterable<Header>, json.Serializable<Headers.JSON>, earl.Serializable<Headers.EARL> {
|
|
10
|
+
/**
|
|
11
|
+
* @remarks
|
|
12
|
+
* If the iterable contains headers with duplicate names, the last header with
|
|
13
|
+
* a given name will take precedence.
|
|
14
|
+
*/
|
|
15
|
+
static of(headers: Iterable<Header>): Headers;
|
|
16
|
+
private static _empty;
|
|
17
|
+
static empty(): Headers;
|
|
18
|
+
private readonly _headers;
|
|
19
|
+
private constructor();
|
|
20
|
+
get(name: string): Option<Header>;
|
|
21
|
+
has(name: string): boolean;
|
|
22
|
+
add(header: Header): Headers;
|
|
23
|
+
delete(name: string): Headers;
|
|
24
|
+
[Symbol.iterator](): Iterator<Header>;
|
|
25
|
+
toArray(): Array<Header>;
|
|
26
|
+
toJSON(options?: json.Serializable.Options): Headers.JSON;
|
|
27
|
+
toEARL(): Headers.EARL;
|
|
28
|
+
toString(): string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare namespace Headers {
|
|
34
|
+
interface JSON extends Array<Header.JSON> {
|
|
35
|
+
}
|
|
36
|
+
interface EARL extends earl.EARL {
|
|
37
|
+
"@context": {
|
|
38
|
+
http: "http://www.w3.org/2011/http#";
|
|
39
|
+
};
|
|
40
|
+
"@list": Array<Header.EARL>;
|
|
41
|
+
}
|
|
42
|
+
function from(json: JSON): Headers;
|
|
43
|
+
function isHeaders(value: unknown): value is Headers;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=headers.d.ts.map
|
package/dist/headers.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
2
|
+
import { Map } from "@siteimprove/alfa-map";
|
|
3
|
+
import { Header } from "./header.js";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class Headers {
|
|
8
|
+
/**
|
|
9
|
+
* @remarks
|
|
10
|
+
* If the iterable contains headers with duplicate names, the last header with
|
|
11
|
+
* a given name will take precedence.
|
|
12
|
+
*/
|
|
13
|
+
static of(headers) {
|
|
14
|
+
return new Headers(Map.from(Iterable.map(headers, (header) => [header.name, header])));
|
|
15
|
+
}
|
|
16
|
+
static _empty = new Headers(Map.empty());
|
|
17
|
+
static empty() {
|
|
18
|
+
return this._empty;
|
|
19
|
+
}
|
|
20
|
+
_headers;
|
|
21
|
+
constructor(headers) {
|
|
22
|
+
this._headers = headers;
|
|
23
|
+
}
|
|
24
|
+
get(name) {
|
|
25
|
+
return this._headers.get(name);
|
|
26
|
+
}
|
|
27
|
+
has(name) {
|
|
28
|
+
return this._headers.has(name);
|
|
29
|
+
}
|
|
30
|
+
add(header) {
|
|
31
|
+
return new Headers(this._headers.set(header.name, header));
|
|
32
|
+
}
|
|
33
|
+
delete(name) {
|
|
34
|
+
return new Headers(this._headers.delete(name));
|
|
35
|
+
}
|
|
36
|
+
*[Symbol.iterator]() {
|
|
37
|
+
yield* this._headers.values();
|
|
38
|
+
}
|
|
39
|
+
toArray() {
|
|
40
|
+
return [...this];
|
|
41
|
+
}
|
|
42
|
+
toJSON(options) {
|
|
43
|
+
return this.toArray().map((header) => header.toJSON(options));
|
|
44
|
+
}
|
|
45
|
+
toEARL() {
|
|
46
|
+
return {
|
|
47
|
+
"@context": {
|
|
48
|
+
http: "http://www.w3.org/2011/http#",
|
|
49
|
+
},
|
|
50
|
+
"@list": this.toArray().map((header) => header.toEARL()),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
toString() {
|
|
54
|
+
return this.toArray()
|
|
55
|
+
.map((header) => header.toString())
|
|
56
|
+
.join("\n");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
(function (Headers) {
|
|
63
|
+
function from(json) {
|
|
64
|
+
return Headers.of(json.map((header) => Header.from(header)));
|
|
65
|
+
}
|
|
66
|
+
Headers.from = from;
|
|
67
|
+
function isHeaders(value) {
|
|
68
|
+
return value instanceof Headers;
|
|
69
|
+
}
|
|
70
|
+
Headers.isHeaders = isHeaders;
|
|
71
|
+
})(Headers || (Headers = {}));
|
|
72
|
+
//# sourceMappingURL=headers.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { URL } from "@siteimprove/alfa-url";
|
|
2
|
+
import type * as earl from "@siteimprove/alfa-earl";
|
|
3
|
+
import type * as json from "@siteimprove/alfa-json";
|
|
4
|
+
import type { Result } from "@siteimprove/alfa-result";
|
|
5
|
+
import type { Body } from "./body.js";
|
|
6
|
+
import { Headers } from "./headers.js";
|
|
7
|
+
/**
|
|
8
|
+
* {@link https://fetch.spec.whatwg.org/#request-class}
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare class Request implements Body, json.Serializable<Request.JSON>, earl.Serializable<Request.EARL> {
|
|
13
|
+
static of(method: string, url: URL, headers?: Headers, body?: ArrayBuffer): Request;
|
|
14
|
+
private static _empty;
|
|
15
|
+
static empty(): Request;
|
|
16
|
+
private readonly _method;
|
|
17
|
+
private readonly _url;
|
|
18
|
+
private readonly _headers;
|
|
19
|
+
private readonly _body;
|
|
20
|
+
private constructor();
|
|
21
|
+
/**
|
|
22
|
+
* {@link https://fetch.spec.whatwg.org/#dom-request-method}
|
|
23
|
+
*/
|
|
24
|
+
get method(): string;
|
|
25
|
+
/**
|
|
26
|
+
* {@link https://fetch.spec.whatwg.org/#dom-request-url}
|
|
27
|
+
*/
|
|
28
|
+
get url(): URL;
|
|
29
|
+
/**
|
|
30
|
+
* {@link https://fetch.spec.whatwg.org/#dom-request-headers}
|
|
31
|
+
*/
|
|
32
|
+
get headers(): Headers;
|
|
33
|
+
/**
|
|
34
|
+
* {@link https://fetch.spec.whatwg.org/#dom-body-body}
|
|
35
|
+
*/
|
|
36
|
+
get body(): ArrayBuffer;
|
|
37
|
+
toJSON(options?: json.Serializable.Options): Request.JSON;
|
|
38
|
+
toEARL(): Request.EARL;
|
|
39
|
+
toString(): string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare namespace Request {
|
|
45
|
+
interface JSON {
|
|
46
|
+
[key: string]: json.JSON;
|
|
47
|
+
method: string;
|
|
48
|
+
url: string;
|
|
49
|
+
headers: Headers.JSON;
|
|
50
|
+
body: string;
|
|
51
|
+
}
|
|
52
|
+
interface EARL extends earl.EARL {
|
|
53
|
+
"@context": {
|
|
54
|
+
http: "http://www.w3.org/2011/http#";
|
|
55
|
+
};
|
|
56
|
+
"@type": ["http:Message", "http:Request"];
|
|
57
|
+
"http:methodName": string;
|
|
58
|
+
"http:requestURI": string;
|
|
59
|
+
"http:headers": Headers.EARL;
|
|
60
|
+
"http:body": Body.EARL;
|
|
61
|
+
}
|
|
62
|
+
function from(json: JSON): Result<Request, string>;
|
|
63
|
+
function isRequest(value: unknown): value is Request;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=request.d.ts.map
|
package/dist/request.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Decoder, Encoder } from "@siteimprove/alfa-encoding";
|
|
2
|
+
import { URL } from "@siteimprove/alfa-url";
|
|
3
|
+
import { Headers } from "./headers.js";
|
|
4
|
+
/**
|
|
5
|
+
* {@link https://fetch.spec.whatwg.org/#request-class}
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export class Request {
|
|
10
|
+
static of(method, url, headers = Headers.empty(), body = new ArrayBuffer(0)) {
|
|
11
|
+
return new Request(method, url, headers, body);
|
|
12
|
+
}
|
|
13
|
+
static _empty = Request.of("GET", URL.blank());
|
|
14
|
+
static empty() {
|
|
15
|
+
return this._empty;
|
|
16
|
+
}
|
|
17
|
+
_method;
|
|
18
|
+
_url;
|
|
19
|
+
_headers;
|
|
20
|
+
_body;
|
|
21
|
+
constructor(method, url, headers, body) {
|
|
22
|
+
this._method = method;
|
|
23
|
+
this._url = url;
|
|
24
|
+
this._headers = headers;
|
|
25
|
+
this._body = body;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* {@link https://fetch.spec.whatwg.org/#dom-request-method}
|
|
29
|
+
*/
|
|
30
|
+
get method() {
|
|
31
|
+
return this._method;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* {@link https://fetch.spec.whatwg.org/#dom-request-url}
|
|
35
|
+
*/
|
|
36
|
+
get url() {
|
|
37
|
+
return this._url;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* {@link https://fetch.spec.whatwg.org/#dom-request-headers}
|
|
41
|
+
*/
|
|
42
|
+
get headers() {
|
|
43
|
+
return this._headers;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* {@link https://fetch.spec.whatwg.org/#dom-body-body}
|
|
47
|
+
*/
|
|
48
|
+
get body() {
|
|
49
|
+
return this._body;
|
|
50
|
+
}
|
|
51
|
+
toJSON(options) {
|
|
52
|
+
return {
|
|
53
|
+
method: this._method,
|
|
54
|
+
url: this._url.toString(),
|
|
55
|
+
headers: this._headers.toJSON(options),
|
|
56
|
+
body: Decoder.decode(new Uint8Array(this._body)),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
toEARL() {
|
|
60
|
+
return {
|
|
61
|
+
"@context": {
|
|
62
|
+
http: "http://www.w3.org/2011/http#",
|
|
63
|
+
},
|
|
64
|
+
"@type": ["http:Message", "http:Request"],
|
|
65
|
+
"http:methodName": this._method,
|
|
66
|
+
"http:requestURI": this._url.toString(),
|
|
67
|
+
"http:headers": this._headers.toEARL(),
|
|
68
|
+
"http:body": {
|
|
69
|
+
"@context": {
|
|
70
|
+
cnt: "http://www.w3.org/2011/content#",
|
|
71
|
+
},
|
|
72
|
+
"@type": ["cnt:Content", "cnt:ContentAsText"],
|
|
73
|
+
"cnt:characterEncoding": "utf-8",
|
|
74
|
+
"cnt:chars": Decoder.decode(new Uint8Array(this._body)),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
toString() {
|
|
79
|
+
let request = `${this._method} ${this._url} HTTP/1.1`;
|
|
80
|
+
request += "\n" + this._headers.toString();
|
|
81
|
+
request += "\n";
|
|
82
|
+
request += Decoder.decode(new Uint8Array(this._body));
|
|
83
|
+
return request;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
(function (Request) {
|
|
90
|
+
function from(json) {
|
|
91
|
+
return URL.parse(json.url).map((url) => Request.of(json.method, url, Headers.from(json.headers), Encoder.encode(json.body)));
|
|
92
|
+
}
|
|
93
|
+
Request.from = from;
|
|
94
|
+
function isRequest(value) {
|
|
95
|
+
return value instanceof Request;
|
|
96
|
+
}
|
|
97
|
+
Request.isRequest = isRequest;
|
|
98
|
+
})(Request || (Request = {}));
|
|
99
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { URL } from "@siteimprove/alfa-url";
|
|
2
|
+
import type * as earl from "@siteimprove/alfa-earl";
|
|
3
|
+
import type * as json from "@siteimprove/alfa-json";
|
|
4
|
+
import type { Result } from "@siteimprove/alfa-result";
|
|
5
|
+
import type { Body } from "./body.js";
|
|
6
|
+
import { Headers } from "./headers.js";
|
|
7
|
+
/**
|
|
8
|
+
* {@link https://fetch.spec.whatwg.org/#response-class}
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare class Response implements Body, json.Serializable<Response.JSON>, earl.Serializable<Response.EARL> {
|
|
13
|
+
static of(url: URL, status: number, headers?: Headers, body?: ArrayBuffer): Response;
|
|
14
|
+
private static _empty;
|
|
15
|
+
static empty(): Response;
|
|
16
|
+
private readonly _url;
|
|
17
|
+
private readonly _status;
|
|
18
|
+
private readonly _headers;
|
|
19
|
+
private readonly _body;
|
|
20
|
+
private constructor();
|
|
21
|
+
/**
|
|
22
|
+
* {@link https://fetch.spec.whatwg.org/#dom-response-url}
|
|
23
|
+
*/
|
|
24
|
+
get url(): URL;
|
|
25
|
+
/**
|
|
26
|
+
* {@link https://fetch.spec.whatwg.org/#dom-response-status}
|
|
27
|
+
*/
|
|
28
|
+
get status(): number;
|
|
29
|
+
/**
|
|
30
|
+
* {@link https://fetch.spec.whatwg.org/#dom-response-headers}
|
|
31
|
+
*/
|
|
32
|
+
get headers(): Headers;
|
|
33
|
+
/**
|
|
34
|
+
* {@link https://fetch.spec.whatwg.org/#dom-body-body}
|
|
35
|
+
*/
|
|
36
|
+
get body(): ArrayBuffer;
|
|
37
|
+
toJSON(options?: json.Serializable.Options): Response.JSON;
|
|
38
|
+
toEARL(): Response.EARL;
|
|
39
|
+
toString(): string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare namespace Response {
|
|
45
|
+
interface JSON {
|
|
46
|
+
[key: string]: json.JSON;
|
|
47
|
+
url: string;
|
|
48
|
+
status: number;
|
|
49
|
+
headers: Headers.JSON;
|
|
50
|
+
body: string;
|
|
51
|
+
}
|
|
52
|
+
interface EARL extends earl.EARL {
|
|
53
|
+
"@context": {
|
|
54
|
+
http: "http://www.w3.org/2011/http#";
|
|
55
|
+
};
|
|
56
|
+
"@type": ["http:Message", "http:Response"];
|
|
57
|
+
"http:statusCodeValue": number;
|
|
58
|
+
"http:headers": Headers.EARL;
|
|
59
|
+
"http:body": Body.EARL;
|
|
60
|
+
}
|
|
61
|
+
function from(json: JSON): Result<Response, string>;
|
|
62
|
+
function isResponse(value: unknown): value is Response;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=response.d.ts.map
|
package/dist/response.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Decoder, Encoder } from "@siteimprove/alfa-encoding";
|
|
2
|
+
import { URL } from "@siteimprove/alfa-url";
|
|
3
|
+
import { Headers } from "./headers.js";
|
|
4
|
+
/**
|
|
5
|
+
* {@link https://fetch.spec.whatwg.org/#response-class}
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export class Response {
|
|
10
|
+
static of(url, status, headers = Headers.empty(), body = new ArrayBuffer(0)) {
|
|
11
|
+
return new Response(url, status, headers, body);
|
|
12
|
+
}
|
|
13
|
+
static _empty = Response.of(URL.blank(), 200);
|
|
14
|
+
static empty() {
|
|
15
|
+
return this._empty;
|
|
16
|
+
}
|
|
17
|
+
_url;
|
|
18
|
+
_status;
|
|
19
|
+
_headers;
|
|
20
|
+
_body;
|
|
21
|
+
constructor(url, status, headers, body) {
|
|
22
|
+
this._url = url;
|
|
23
|
+
this._status = status;
|
|
24
|
+
this._headers = headers;
|
|
25
|
+
this._body = body;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* {@link https://fetch.spec.whatwg.org/#dom-response-url}
|
|
29
|
+
*/
|
|
30
|
+
get url() {
|
|
31
|
+
return this._url;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* {@link https://fetch.spec.whatwg.org/#dom-response-status}
|
|
35
|
+
*/
|
|
36
|
+
get status() {
|
|
37
|
+
return this._status;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* {@link https://fetch.spec.whatwg.org/#dom-response-headers}
|
|
41
|
+
*/
|
|
42
|
+
get headers() {
|
|
43
|
+
return this._headers;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* {@link https://fetch.spec.whatwg.org/#dom-body-body}
|
|
47
|
+
*/
|
|
48
|
+
get body() {
|
|
49
|
+
return this._body;
|
|
50
|
+
}
|
|
51
|
+
toJSON(options) {
|
|
52
|
+
return {
|
|
53
|
+
url: this._url.toString(),
|
|
54
|
+
status: this._status,
|
|
55
|
+
headers: this._headers.toJSON(options),
|
|
56
|
+
body: Decoder.decode(new Uint8Array(this._body)),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
toEARL() {
|
|
60
|
+
return {
|
|
61
|
+
"@context": {
|
|
62
|
+
http: "http://www.w3.org/2011/http#",
|
|
63
|
+
},
|
|
64
|
+
"@type": ["http:Message", "http:Response"],
|
|
65
|
+
"http:statusCodeValue": this._status,
|
|
66
|
+
"http:headers": this._headers.toEARL(),
|
|
67
|
+
"http:body": {
|
|
68
|
+
"@context": {
|
|
69
|
+
cnt: "http://www.w3.org/2011/content#",
|
|
70
|
+
},
|
|
71
|
+
"@type": ["cnt:Content", "cnt:ContentAsText"],
|
|
72
|
+
"cnt:characterEncoding": "utf-8",
|
|
73
|
+
"cnt:chars": Decoder.decode(new Uint8Array(this._body)),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
toString() {
|
|
78
|
+
let response = `HTTP/1.1 ${this._status}`;
|
|
79
|
+
response += "\n" + this._headers.toString();
|
|
80
|
+
response += "\n";
|
|
81
|
+
response += Decoder.decode(new Uint8Array(this._body));
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
(function (Response) {
|
|
89
|
+
function from(json) {
|
|
90
|
+
return URL.parse(json.url).map((url) => Response.of(url, json.status, Headers.from(json.headers), Encoder.encode(json.body)));
|
|
91
|
+
}
|
|
92
|
+
Response.from = from;
|
|
93
|
+
function isResponse(value) {
|
|
94
|
+
return value instanceof Response;
|
|
95
|
+
}
|
|
96
|
+
Response.isResponse = isResponse;
|
|
97
|
+
})(Response || (Response = {}));
|
|
98
|
+
//# sourceMappingURL=response.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json.schemastore.org/package",
|
|
3
|
+
"name": "@siteimprove/alfa-http",
|
|
4
|
+
"homepage": "https://alfa.siteimprove.com",
|
|
5
|
+
"version": "0.89.5",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"description": "Types for modelling HTTP primitives",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "github:Siteimprove/alfa",
|
|
11
|
+
"directory": "packages/alfa-http"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/siteimprove/alfa/issues",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20.0.0"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/**/*.js",
|
|
22
|
+
"dist/**/*.d.ts"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@siteimprove/alfa-earl": "^0.89.5",
|
|
26
|
+
"@siteimprove/alfa-encoding": "^0.89.5",
|
|
27
|
+
"@siteimprove/alfa-equatable": "^0.89.5",
|
|
28
|
+
"@siteimprove/alfa-iterable": "^0.89.5",
|
|
29
|
+
"@siteimprove/alfa-json": "^0.89.5",
|
|
30
|
+
"@siteimprove/alfa-map": "^0.89.5",
|
|
31
|
+
"@siteimprove/alfa-option": "^0.89.5",
|
|
32
|
+
"@siteimprove/alfa-refinement": "^0.89.5",
|
|
33
|
+
"@siteimprove/alfa-result": "^0.89.5",
|
|
34
|
+
"@siteimprove/alfa-url": "^0.89.5"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@siteimprove/alfa-test": "^0.89.5"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"registry": "https://npm.pkg.github.com/"
|
|
42
|
+
}
|
|
43
|
+
}
|