@utiliread/http 1.17.7 → 1.18.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/.vscode/settings.json +2 -2
- package/dist/cjs/event-aggregator.js +29 -29
- package/dist/cjs/event-aggregator.js.map +1 -1
- package/dist/cjs/events.js +18 -18
- package/dist/cjs/events.js.map +1 -1
- package/dist/cjs/helpers.js +15 -15
- package/dist/cjs/http-builder.js +191 -191
- package/dist/cjs/http-builder.js.map +1 -1
- package/dist/cjs/http-error.js +29 -29
- package/dist/cjs/http-error.js.map +1 -1
- package/dist/cjs/http-response.js +50 -50
- package/dist/cjs/http-response.js.map +1 -1
- package/dist/cjs/http.js +95 -95
- package/dist/cjs/http.js.map +1 -1
- package/dist/cjs/http.spec.js +68 -68
- package/dist/cjs/http.spec.js.map +1 -1
- package/dist/cjs/index.js +37 -37
- package/dist/cjs/json/index.js +73 -73
- package/dist/cjs/jsonpatch/index.js +14 -14
- package/dist/cjs/mapping.js +36 -36
- package/dist/cjs/mapping.js.map +1 -1
- package/dist/cjs/msgpack/index.js +34 -34
- package/dist/cjs/msgpack/index.js.map +1 -1
- package/dist/cjs/pagination.js +2 -2
- package/dist/cjs/problem-details.js +2 -2
- package/dist/cjs/query-string.js +67 -65
- package/dist/cjs/query-string.js.map +1 -1
- package/dist/cjs/query-string.spec.js +51 -51
- package/dist/cjs/status-codes.js +70 -70
- package/dist/cjs/timeout-error.js +13 -13
- package/dist/esm/event-aggregator.d.ts +11 -11
- package/dist/esm/event-aggregator.js +25 -25
- package/dist/esm/event-aggregator.js.map +1 -1
- package/dist/esm/events.d.ts +11 -11
- package/dist/esm/events.js +14 -14
- package/dist/esm/events.js.map +1 -1
- package/dist/esm/helpers.d.ts +5 -5
- package/dist/esm/helpers.js +9 -9
- package/dist/esm/http-builder.d.ts +60 -60
- package/dist/esm/http-builder.js +186 -186
- package/dist/esm/http-builder.js.map +1 -1
- package/dist/esm/http-error.d.ts +10 -10
- package/dist/esm/http-error.js +25 -25
- package/dist/esm/http-error.js.map +1 -1
- package/dist/esm/http-response.d.ts +18 -18
- package/dist/esm/http-response.js +45 -45
- package/dist/esm/http-response.js.map +1 -1
- package/dist/esm/http.d.ts +33 -33
- package/dist/esm/http.js +91 -91
- package/dist/esm/http.js.map +1 -1
- package/dist/esm/http.spec.d.ts +1 -1
- package/dist/esm/http.spec.js +66 -66
- package/dist/esm/http.spec.js.map +1 -1
- package/dist/esm/index.d.ts +15 -15
- package/dist/esm/index.js +10 -10
- package/dist/esm/json/index.d.ts +15 -15
- package/dist/esm/json/index.js +71 -71
- package/dist/esm/jsonpatch/index.d.ts +9 -9
- package/dist/esm/jsonpatch/index.js +12 -12
- package/dist/esm/mapping.d.ts +9 -9
- package/dist/esm/mapping.js +31 -31
- package/dist/esm/mapping.js.map +1 -1
- package/dist/esm/msgpack/index.d.ts +8 -8
- package/dist/esm/msgpack/index.js +32 -32
- package/dist/esm/msgpack/index.js.map +1 -1
- package/dist/esm/pagination.d.ts +23 -23
- package/dist/esm/pagination.js +1 -1
- package/dist/esm/problem-details.d.ts +7 -7
- package/dist/esm/problem-details.js +1 -1
- package/dist/esm/query-string.d.ts +6 -6
- package/dist/esm/query-string.js +63 -61
- package/dist/esm/query-string.js.map +1 -1
- package/dist/esm/query-string.spec.d.ts +1 -1
- package/dist/esm/query-string.spec.js +49 -49
- package/dist/esm/status-codes.d.ts +67 -67
- package/dist/esm/status-codes.js +67 -67
- package/dist/esm/timeout-error.d.ts +3 -3
- package/dist/esm/timeout-error.js +9 -9
- package/package.json +15 -17
- package/plugins/json/node_modules/@utiliread/http/package.json +4 -0
- package/plugins/json/src/index.ts +124 -122
- package/plugins/jsonpatch/node_modules/@utiliread/http/package.json +4 -0
- package/plugins/jsonpatch/src/index.ts +31 -31
- package/plugins/msgpack/node_modules/@utiliread/http/package.json +4 -0
- package/plugins/msgpack/src/index.ts +67 -60
- package/src/event-aggregator.ts +21 -21
- package/src/events.ts +39 -39
- package/src/helpers.ts +6 -6
- package/src/http-builder.ts +252 -218
- package/src/http-error.ts +30 -23
- package/src/http-response.ts +1 -1
- package/src/http.spec.ts +1 -1
- package/src/http.ts +8 -5
- package/src/index.ts +1 -1
- package/src/mapping.ts +40 -32
- package/src/pagination.ts +16 -16
- package/src/problem-details.ts +6 -6
- package/src/query-string.spec.ts +59 -43
- package/src/query-string.ts +56 -58
- package/src/status-codes.ts +67 -67
- package/src/timeout-error.ts +7 -7
- package/tsconfig.cjs.json +1 -0
- package/tsconfig.json +1 -1
- package/web-test-runner.config.mjs +7 -0
- package/karma.config.js +0 -29
- package/src/mapping.d.ts +0 -9
- package/src/mapping.js +0 -32
- package/src/mapping.js.map +0 -1
|
@@ -1,122 +1,124 @@
|
|
|
1
|
-
import { HttpBuilder, HttpBuilderOfT, Mapping } from "@utiliread/http";
|
|
2
|
-
import type {
|
|
3
|
-
InfinitePaginationResult,
|
|
4
|
-
PaginationResult,
|
|
5
|
-
} from "@utiliread/http";
|
|
6
|
-
import { deserialize, serialize } from "@utiliread/json";
|
|
7
|
-
|
|
8
|
-
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
9
|
-
declare module "@utiliread/http" {
|
|
10
|
-
interface HttpBuilder {
|
|
11
|
-
withJson(content: any): this;
|
|
12
|
-
|
|
13
|
-
expectJson<T>(typeOrMapper?: Mapping.TypeOrMapper<T>): HttpBuilderOfT<T>;
|
|
14
|
-
expectJsonArray<T>(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
};
|
|
1
|
+
import { HttpBuilder, HttpBuilderOfT, Mapping } from "@utiliread/http";
|
|
2
|
+
import type {
|
|
3
|
+
InfinitePaginationResult,
|
|
4
|
+
PaginationResult,
|
|
5
|
+
} from "@utiliread/http";
|
|
6
|
+
import { deserialize, serialize } from "@utiliread/json";
|
|
7
|
+
|
|
8
|
+
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
9
|
+
declare module "@utiliread/http" {
|
|
10
|
+
interface HttpBuilder {
|
|
11
|
+
withJson(content: any): this;
|
|
12
|
+
|
|
13
|
+
expectJson<T>(typeOrMapper?: Mapping.TypeOrMapper<T>): HttpBuilderOfT<T>;
|
|
14
|
+
expectJsonArray<T>(
|
|
15
|
+
typeOrMapper: Mapping.TypeOrMapper<T>,
|
|
16
|
+
): HttpBuilderOfT<T[]>;
|
|
17
|
+
expectJsonNullableArray<T>(
|
|
18
|
+
typeOrMapper: Mapping.TypeOrMapper<T>,
|
|
19
|
+
): HttpBuilderOfT<(T | null)[]>;
|
|
20
|
+
expectJsonPaginationResult<T>(
|
|
21
|
+
typeOrMapper: Mapping.TypeOrMapper<T>,
|
|
22
|
+
): HttpBuilderOfT<PaginationResult<T>>;
|
|
23
|
+
expectJsonInfinitePaginationResult<T>(
|
|
24
|
+
typeOrMapper: Mapping.TypeOrMapper<T>,
|
|
25
|
+
): HttpBuilderOfT<InfinitePaginationResult<T>>;
|
|
26
|
+
}
|
|
27
|
+
interface HttpBuilderOfT<T> {
|
|
28
|
+
withJson(content: any): this;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
HttpBuilder.prototype.withJson = function (this: HttpBuilder, content: any) {
|
|
33
|
+
this.message.content = serialize(content);
|
|
34
|
+
this.message.contentType = "application/json";
|
|
35
|
+
return this;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
HttpBuilderOfT.prototype.withJson = function <T>(
|
|
39
|
+
this: HttpBuilderOfT<T>,
|
|
40
|
+
content: any,
|
|
41
|
+
) {
|
|
42
|
+
this.message.content = serialize(content);
|
|
43
|
+
this.message.contentType = "application/json";
|
|
44
|
+
return this;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
HttpBuilder.prototype.expectJson = function <T>(
|
|
48
|
+
this: HttpBuilder,
|
|
49
|
+
typeOrMapper?: Mapping.TypeOrMapper<T>,
|
|
50
|
+
) {
|
|
51
|
+
this.message.headers.set("Accept", "application/json");
|
|
52
|
+
return this.useHandler((response) => {
|
|
53
|
+
return response.rawResponse
|
|
54
|
+
.json()
|
|
55
|
+
.then((x) => Mapping.getMapper(deserialize, typeOrMapper)(x));
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
HttpBuilder.prototype.expectJsonArray = function <T>(
|
|
60
|
+
this: HttpBuilder,
|
|
61
|
+
typeOrMapper: Mapping.TypeOrMapper<T>,
|
|
62
|
+
) {
|
|
63
|
+
this.message.headers.set("Accept", "application/json");
|
|
64
|
+
return this.useHandler((response) => {
|
|
65
|
+
return response.rawResponse.json().then((x: any[]) => {
|
|
66
|
+
const itemFactory = Mapping.getMapper(deserialize, typeOrMapper);
|
|
67
|
+
return x.map(itemFactory);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
HttpBuilder.prototype.expectJsonNullableArray = function <T>(
|
|
73
|
+
this: HttpBuilder,
|
|
74
|
+
typeOrMapper: Mapping.TypeOrMapper<T>,
|
|
75
|
+
): HttpBuilderOfT<(T | null)[]> {
|
|
76
|
+
this.message.headers.set("Accept", "application/json");
|
|
77
|
+
return this.useHandler((response) => {
|
|
78
|
+
return response.rawResponse.json().then((x: any[]) => {
|
|
79
|
+
const itemFactory = Mapping.getNullableMapper(deserialize, typeOrMapper);
|
|
80
|
+
return x.map(itemFactory);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
HttpBuilder.prototype.expectJsonPaginationResult = function <T>(
|
|
86
|
+
this: HttpBuilder,
|
|
87
|
+
typeOrMapper: Mapping.TypeOrMapper<T>,
|
|
88
|
+
) {
|
|
89
|
+
this.message.headers.set("Accept", "application/json");
|
|
90
|
+
return this.useHandler((response) => {
|
|
91
|
+
return response.rawResponse.json().then((x: PaginationResult<any>) => {
|
|
92
|
+
const itemFactory = Mapping.getMapper(deserialize, typeOrMapper);
|
|
93
|
+
return {
|
|
94
|
+
meta: {
|
|
95
|
+
pageCount: x.meta.pageCount,
|
|
96
|
+
pageSize: x.meta.pageSize,
|
|
97
|
+
totalItems: x.meta.totalItems,
|
|
98
|
+
},
|
|
99
|
+
data: x.data.map(itemFactory),
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
HttpBuilder.prototype.expectJsonInfinitePaginationResult = function <T>(
|
|
106
|
+
this: HttpBuilder,
|
|
107
|
+
typeOrMapper: Mapping.TypeOrMapper<T>,
|
|
108
|
+
) {
|
|
109
|
+
this.message.headers.set("Accept", "application/json");
|
|
110
|
+
return this.useHandler((response) => {
|
|
111
|
+
return response.rawResponse
|
|
112
|
+
.json()
|
|
113
|
+
.then((x: InfinitePaginationResult<any>) => {
|
|
114
|
+
const itemFactory = Mapping.getMapper(deserialize, typeOrMapper);
|
|
115
|
+
return {
|
|
116
|
+
meta: {
|
|
117
|
+
pageSize: x.meta.pageSize,
|
|
118
|
+
continuationToken: x.meta.continuationToken,
|
|
119
|
+
},
|
|
120
|
+
data: x.data.map(itemFactory),
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { HttpBuilder, HttpBuilderOfT } from "@utiliread/http";
|
|
2
|
-
import { serialize } from "@utiliread/json";
|
|
3
|
-
import type { Operation } from "@utiliread/jsonpatch";
|
|
4
|
-
|
|
5
|
-
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
6
|
-
declare module "@utiliread/http" {
|
|
7
|
-
interface HttpBuilder {
|
|
8
|
-
withJsonPatch(operations: Operation[]): this;
|
|
9
|
-
}
|
|
10
|
-
interface HttpBuilderOfT<T> {
|
|
11
|
-
withJsonPatch(operations: Operation[]): this;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
HttpBuilder.prototype.withJsonPatch = function (
|
|
16
|
-
this: HttpBuilder,
|
|
17
|
-
operations: Operation[]
|
|
18
|
-
) {
|
|
19
|
-
this.message.content = serialize(operations);
|
|
20
|
-
this.message.contentType = "application/json-patch+json";
|
|
21
|
-
return this;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
HttpBuilderOfT.prototype.withJsonPatch = function <T>(
|
|
25
|
-
this: HttpBuilderOfT<T>,
|
|
26
|
-
operations: Operation[]
|
|
27
|
-
) {
|
|
28
|
-
this.message.content = serialize(operations);
|
|
29
|
-
this.message.contentType = "application/json-patch+json";
|
|
30
|
-
return this;
|
|
31
|
-
};
|
|
1
|
+
import { HttpBuilder, HttpBuilderOfT } from "@utiliread/http";
|
|
2
|
+
import { serialize } from "@utiliread/json";
|
|
3
|
+
import type { Operation } from "@utiliread/jsonpatch";
|
|
4
|
+
|
|
5
|
+
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
6
|
+
declare module "@utiliread/http" {
|
|
7
|
+
interface HttpBuilder {
|
|
8
|
+
withJsonPatch(operations: Operation[]): this;
|
|
9
|
+
}
|
|
10
|
+
interface HttpBuilderOfT<T> {
|
|
11
|
+
withJsonPatch(operations: Operation[]): this;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
HttpBuilder.prototype.withJsonPatch = function (
|
|
16
|
+
this: HttpBuilder,
|
|
17
|
+
operations: Operation[],
|
|
18
|
+
) {
|
|
19
|
+
this.message.content = serialize(operations);
|
|
20
|
+
this.message.contentType = "application/json-patch+json";
|
|
21
|
+
return this;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
HttpBuilderOfT.prototype.withJsonPatch = function <T>(
|
|
25
|
+
this: HttpBuilderOfT<T>,
|
|
26
|
+
operations: Operation[],
|
|
27
|
+
) {
|
|
28
|
+
this.message.content = serialize(operations);
|
|
29
|
+
this.message.contentType = "application/json-patch+json";
|
|
30
|
+
return this;
|
|
31
|
+
};
|
|
@@ -1,60 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
import {
|
|
2
|
+
HttpBuilder,
|
|
3
|
+
HttpBuilderOfT,
|
|
4
|
+
HttpResponse,
|
|
5
|
+
Mapping,
|
|
6
|
+
} from "@utiliread/http";
|
|
7
|
+
import { decodeArrayStream, decodeAsync } from "@msgpack/msgpack";
|
|
8
|
+
|
|
9
|
+
import { deserialize } from "@utiliread/msgpack";
|
|
10
|
+
|
|
11
|
+
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
12
|
+
declare module "@utiliread/http" {
|
|
13
|
+
interface HttpBuilder {
|
|
14
|
+
expectMessagePack<T>(
|
|
15
|
+
typeOrMapper?: Mapping.TypeOrMapper<T>,
|
|
16
|
+
): HttpBuilderOfT<T>;
|
|
17
|
+
expectMessagePackArray<T>(
|
|
18
|
+
typeOrMapper?: Mapping.TypeOrMapper<T>,
|
|
19
|
+
): HttpBuilderOfT<T[]>;
|
|
20
|
+
streamMessagePackArray<T>(
|
|
21
|
+
typeOrMapper?: Mapping.TypeOrMapper<T>,
|
|
22
|
+
): HttpBuilderOfT<AsyncGenerator<T, void, unknown>>;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
HttpBuilder.prototype.expectMessagePack = function <T>(
|
|
27
|
+
this: HttpBuilder,
|
|
28
|
+
typeOrMapper?: Mapping.TypeOrMapper<T>,
|
|
29
|
+
) {
|
|
30
|
+
this.message.headers.set("Accept", "application/x-msgpack");
|
|
31
|
+
return this.useHandler(async (response) => {
|
|
32
|
+
const itemFactory = Mapping.getMapper(deserialize, typeOrMapper);
|
|
33
|
+
const decoded = await decodeAsync(response.rawResponse.body!);
|
|
34
|
+
return itemFactory(decoded);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
HttpBuilder.prototype.expectMessagePackArray = function <T>(
|
|
39
|
+
this: HttpBuilder,
|
|
40
|
+
typeOrMapper?: Mapping.TypeOrMapper<T>,
|
|
41
|
+
) {
|
|
42
|
+
this.message.headers.set("Accept", "application/x-msgpack");
|
|
43
|
+
return this.useHandler(async (response) => {
|
|
44
|
+
const items: T[] = [];
|
|
45
|
+
const itemFactory = Mapping.getMapper(deserialize, typeOrMapper);
|
|
46
|
+
for await (const item of decodeArrayStream(response.rawResponse.body!)) {
|
|
47
|
+
items.push(itemFactory(item));
|
|
48
|
+
}
|
|
49
|
+
return items;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
HttpBuilder.prototype.streamMessagePackArray = function <T>(
|
|
54
|
+
this: HttpBuilder,
|
|
55
|
+
typeOrMapper?: Mapping.TypeOrMapper<T>,
|
|
56
|
+
) {
|
|
57
|
+
this.message.headers.set("Accept", "application/x-msgpack");
|
|
58
|
+
|
|
59
|
+
async function* handler(response: HttpResponse) {
|
|
60
|
+
const itemFactory = Mapping.getMapper(deserialize, typeOrMapper);
|
|
61
|
+
for await (const item of decodeArrayStream(response.rawResponse.body!)) {
|
|
62
|
+
yield itemFactory(item);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return this.useHandler((response) => Promise.resolve(handler(response)));
|
|
67
|
+
};
|
package/src/event-aggregator.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
type Callback<P extends any[] = any[]> = (...params: P) => void | Promise<void>;
|
|
2
2
|
|
|
3
3
|
export class EventAggregator<P extends any[]> {
|
|
4
|
-
|
|
4
|
+
private callbacks: Function[] = [];
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
get any() {
|
|
7
|
+
return this.callbacks.length > 0;
|
|
8
|
+
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}
|
|
10
|
+
subscribe(callback: Callback<P>): Subscription {
|
|
11
|
+
this.callbacks.push(callback);
|
|
12
|
+
return {
|
|
13
|
+
dispose: () => {
|
|
14
|
+
const index = this.callbacks.indexOf(callback);
|
|
15
|
+
if (index >= 0) {
|
|
16
|
+
this.callbacks.splice(index, 1);
|
|
19
17
|
}
|
|
20
|
-
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
22
|
+
async publish(...params: P) {
|
|
23
|
+
const callbacks = this.callbacks.slice();
|
|
24
|
+
for (const callback of callbacks) {
|
|
25
|
+
await Promise.resolve(callback.apply(this, params));
|
|
27
26
|
}
|
|
27
|
+
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export interface Subscription {
|
|
31
|
-
|
|
32
|
-
}
|
|
31
|
+
dispose(): void;
|
|
32
|
+
}
|
package/src/events.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { HttpBuilder, HttpBuilderOfT, Message } from "./http-builder";
|
|
2
|
-
import { HttpResponse } from "./http-response";
|
|
3
|
-
|
|
4
|
-
interface Events {
|
|
5
|
-
sent: (response: HttpResponse, request: Message) => void | Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface EventsOfT<T> extends Events {
|
|
9
|
-
received: (
|
|
10
|
-
response: HttpResponse,
|
|
11
|
-
request: Message,
|
|
12
|
-
value: T
|
|
13
|
-
) => void | Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function events<P extends any[]>(
|
|
17
|
-
action: (...params: P) => HttpBuilder,
|
|
18
|
-
configure: (...params: P) => Partial<Events
|
|
19
|
-
): (...params: P) => HttpBuilder;
|
|
20
|
-
export function events<B extends HttpBuilderOfT<T>, P extends any[], T>(
|
|
21
|
-
action: (...params: P) => B,
|
|
22
|
-
configure: (...params: P) => Partial<EventsOfT<T
|
|
23
|
-
): (...params: P) => B;
|
|
24
|
-
export function events<B extends HttpBuilderOfT<T>, P extends any[], T>(
|
|
25
|
-
action: (...params: P) => B,
|
|
26
|
-
configure: (...params: P) => Partial<EventsOfT<T
|
|
27
|
-
): (...params: P) => B {
|
|
28
|
-
return function (...params: P) {
|
|
29
|
-
const builder = action(...params);
|
|
30
|
-
const events = configure(...params);
|
|
31
|
-
if (events.sent) {
|
|
32
|
-
builder.onSent(events.sent);
|
|
33
|
-
}
|
|
34
|
-
if (builder instanceof HttpBuilderOfT && events.received) {
|
|
35
|
-
builder.onReceived(events.received);
|
|
36
|
-
}
|
|
37
|
-
return builder;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
1
|
+
import { HttpBuilder, HttpBuilderOfT, Message } from "./http-builder";
|
|
2
|
+
import { HttpResponse } from "./http-response";
|
|
3
|
+
|
|
4
|
+
interface Events {
|
|
5
|
+
sent: (response: HttpResponse, request: Message) => void | Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface EventsOfT<T> extends Events {
|
|
9
|
+
received: (
|
|
10
|
+
response: HttpResponse,
|
|
11
|
+
request: Message,
|
|
12
|
+
value: T,
|
|
13
|
+
) => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function events<P extends any[]>(
|
|
17
|
+
action: (...params: P) => HttpBuilder,
|
|
18
|
+
configure: (...params: P) => Partial<Events>,
|
|
19
|
+
): (...params: P) => HttpBuilder;
|
|
20
|
+
export function events<B extends HttpBuilderOfT<T>, P extends any[], T>(
|
|
21
|
+
action: (...params: P) => B,
|
|
22
|
+
configure: (...params: P) => Partial<EventsOfT<T>>,
|
|
23
|
+
): (...params: P) => B;
|
|
24
|
+
export function events<B extends HttpBuilderOfT<T>, P extends any[], T>(
|
|
25
|
+
action: (...params: P) => B,
|
|
26
|
+
configure: (...params: P) => Partial<EventsOfT<T>>,
|
|
27
|
+
): (...params: P) => B {
|
|
28
|
+
return function (...params: P) {
|
|
29
|
+
const builder = action(...params);
|
|
30
|
+
const events = configure(...params);
|
|
31
|
+
if (events.sent) {
|
|
32
|
+
builder.onSent(events.sent);
|
|
33
|
+
}
|
|
34
|
+
if (builder instanceof HttpBuilderOfT && events.received) {
|
|
35
|
+
builder.onReceived(events.received);
|
|
36
|
+
}
|
|
37
|
+
return builder;
|
|
38
|
+
};
|
|
39
|
+
}
|
package/src/helpers.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { HttpError } from
|
|
2
|
-
import { TimeoutError } from
|
|
1
|
+
import { HttpError } from "./http-error";
|
|
2
|
+
import { TimeoutError } from "./timeout-error";
|
|
3
3
|
|
|
4
4
|
export function isHttpError(error: Error): error is HttpError {
|
|
5
|
-
|
|
5
|
+
return error.name === "HttpError";
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export function isAbortError(error: Error): boolean {
|
|
9
|
-
|
|
9
|
+
return error.name === "AbortError";
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function isTimeoutError(error: Error): error is TimeoutError {
|
|
13
|
-
|
|
14
|
-
}
|
|
13
|
+
return error.name === "TimeoutError";
|
|
14
|
+
}
|