@utiliread/http 1.17.8 → 1.19.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/index.d.ts +231 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +564 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +535 -0
- package/dist/index.mjs.map +1 -0
- package/dist/json.d.ts +15 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +73 -0
- package/dist/json.js.map +1 -0
- package/dist/json.mjs +73 -0
- package/dist/json.mjs.map +1 -0
- package/dist/{esm/jsonpatch/index.d.ts → jsonpatch.d.ts} +10 -9
- package/dist/jsonpatch.d.ts.map +1 -0
- package/dist/jsonpatch.js +18 -0
- package/dist/jsonpatch.js.map +1 -0
- package/dist/jsonpatch.mjs +18 -0
- package/dist/jsonpatch.mjs.map +1 -0
- package/dist/msgpack.d.ts +9 -0
- package/dist/msgpack.d.ts.map +1 -0
- package/dist/msgpack.js +35 -0
- package/dist/msgpack.js.map +1 -0
- package/dist/msgpack.mjs +35 -0
- package/dist/msgpack.mjs.map +1 -0
- package/json.d.ts +1 -1
- package/jsonpatch.d.ts +1 -1
- package/mapper.d.ts +1 -0
- package/msgpack.d.ts +1 -1
- package/package.json +40 -38
- package/plugins/json/node_modules/@utiliread/http/package.json +4 -0
- package/plugins/json/package.json +15 -0
- package/plugins/json/src/index.ts +128 -122
- package/plugins/json/tsconfig.json +1 -2
- package/plugins/jsonpatch/node_modules/@utiliread/http/package.json +4 -0
- package/plugins/jsonpatch/package.json +16 -0
- package/plugins/jsonpatch/src/index.ts +31 -31
- package/plugins/jsonpatch/tsconfig.json +1 -2
- package/plugins/msgpack/node_modules/@utiliread/http/package.json +4 -0
- package/plugins/msgpack/package.json +16 -0
- package/plugins/msgpack/src/index.ts +60 -60
- package/plugins/msgpack/tsconfig.json +1 -2
- 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/mapper.ts +52 -0
- 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 -2
- package/web-test-runner.config.mjs +7 -0
- package/dist/cjs/event-aggregator.js +0 -30
- package/dist/cjs/event-aggregator.js.map +0 -1
- package/dist/cjs/events.js +0 -19
- package/dist/cjs/events.js.map +0 -1
- package/dist/cjs/helpers.js +0 -16
- package/dist/cjs/helpers.js.map +0 -1
- package/dist/cjs/http-builder.js +0 -192
- package/dist/cjs/http-builder.js.map +0 -1
- package/dist/cjs/http-error.js +0 -30
- package/dist/cjs/http-error.js.map +0 -1
- package/dist/cjs/http-response.js +0 -51
- package/dist/cjs/http-response.js.map +0 -1
- package/dist/cjs/http.js +0 -96
- package/dist/cjs/http.js.map +0 -1
- package/dist/cjs/http.spec.js +0 -69
- package/dist/cjs/http.spec.js.map +0 -1
- package/dist/cjs/index.js +0 -38
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json/index.js +0 -74
- package/dist/cjs/json/index.js.map +0 -1
- package/dist/cjs/jsonpatch/index.js +0 -15
- package/dist/cjs/jsonpatch/index.js.map +0 -1
- package/dist/cjs/mapping.js +0 -37
- package/dist/cjs/mapping.js.map +0 -1
- package/dist/cjs/msgpack/index.js +0 -35
- package/dist/cjs/msgpack/index.js.map +0 -1
- package/dist/cjs/pagination.js +0 -3
- package/dist/cjs/pagination.js.map +0 -1
- package/dist/cjs/problem-details.js +0 -3
- package/dist/cjs/problem-details.js.map +0 -1
- package/dist/cjs/query-string.js +0 -66
- package/dist/cjs/query-string.js.map +0 -1
- package/dist/cjs/query-string.spec.js +0 -52
- package/dist/cjs/query-string.spec.js.map +0 -1
- package/dist/cjs/status-codes.js +0 -71
- package/dist/cjs/status-codes.js.map +0 -1
- package/dist/cjs/timeout-error.js +0 -14
- package/dist/cjs/timeout-error.js.map +0 -1
- package/dist/esm/event-aggregator.d.ts +0 -11
- package/dist/esm/event-aggregator.js +0 -26
- package/dist/esm/event-aggregator.js.map +0 -1
- package/dist/esm/events.d.ts +0 -11
- package/dist/esm/events.js +0 -15
- package/dist/esm/events.js.map +0 -1
- package/dist/esm/helpers.d.ts +0 -5
- package/dist/esm/helpers.js +0 -10
- package/dist/esm/helpers.js.map +0 -1
- package/dist/esm/http-builder.d.ts +0 -60
- package/dist/esm/http-builder.js +0 -187
- package/dist/esm/http-builder.js.map +0 -1
- package/dist/esm/http-error.d.ts +0 -10
- package/dist/esm/http-error.js +0 -26
- package/dist/esm/http-error.js.map +0 -1
- package/dist/esm/http-response.d.ts +0 -18
- package/dist/esm/http-response.js +0 -46
- package/dist/esm/http-response.js.map +0 -1
- package/dist/esm/http.d.ts +0 -33
- package/dist/esm/http.js +0 -92
- package/dist/esm/http.js.map +0 -1
- package/dist/esm/http.spec.d.ts +0 -1
- package/dist/esm/http.spec.js +0 -67
- package/dist/esm/http.spec.js.map +0 -1
- package/dist/esm/index.d.ts +0 -15
- package/dist/esm/index.js +0 -11
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json/index.d.ts +0 -15
- package/dist/esm/json/index.js +0 -72
- package/dist/esm/json/index.js.map +0 -1
- package/dist/esm/jsonpatch/index.js +0 -13
- package/dist/esm/jsonpatch/index.js.map +0 -1
- package/dist/esm/mapping.d.ts +0 -9
- package/dist/esm/mapping.js +0 -32
- package/dist/esm/mapping.js.map +0 -1
- package/dist/esm/msgpack/index.d.ts +0 -8
- package/dist/esm/msgpack/index.js +0 -33
- package/dist/esm/msgpack/index.js.map +0 -1
- package/dist/esm/pagination.d.ts +0 -23
- package/dist/esm/pagination.js +0 -2
- package/dist/esm/pagination.js.map +0 -1
- package/dist/esm/problem-details.d.ts +0 -7
- package/dist/esm/problem-details.js +0 -2
- package/dist/esm/problem-details.js.map +0 -1
- package/dist/esm/query-string.d.ts +0 -6
- package/dist/esm/query-string.js +0 -62
- package/dist/esm/query-string.js.map +0 -1
- package/dist/esm/query-string.spec.d.ts +0 -1
- package/dist/esm/query-string.spec.js +0 -50
- package/dist/esm/query-string.spec.js.map +0 -1
- package/dist/esm/status-codes.d.ts +0 -67
- package/dist/esm/status-codes.js +0 -68
- package/dist/esm/status-codes.js.map +0 -1
- package/dist/esm/timeout-error.d.ts +0 -3
- package/dist/esm/timeout-error.js +0 -10
- package/dist/esm/timeout-error.js.map +0 -1
- package/karma.config.js +0 -29
- package/plugins/json/tsconfig.cjs.json +0 -8
- package/plugins/jsonpatch/tsconfig.cjs.json +0 -8
- package/plugins/msgpack/tsconfig.cjs.json +0 -8
- package/src/mapping.ts +0 -44
|
@@ -1,122 +1,128 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
):
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
): HttpBuilderOfT<
|
|
21
|
-
|
|
22
|
-
typeOrMapper:
|
|
23
|
-
): HttpBuilderOfT<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this
|
|
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 {
|
|
2
|
+
HttpBuilder,
|
|
3
|
+
HttpBuilderOfT,
|
|
4
|
+
getMapper,
|
|
5
|
+
getNullableMapper
|
|
6
|
+
} from "@utiliread/http";
|
|
7
|
+
import type {
|
|
8
|
+
InfinitePaginationResult,
|
|
9
|
+
PaginationResult,
|
|
10
|
+
TypeOrMapper
|
|
11
|
+
} from "@utiliread/http";
|
|
12
|
+
import { deserialize, serialize } from "@utiliread/json";
|
|
13
|
+
|
|
14
|
+
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
15
|
+
declare module "@utiliread/http" {
|
|
16
|
+
interface HttpBuilder {
|
|
17
|
+
withJson(content: any): this;
|
|
18
|
+
|
|
19
|
+
expectJson<T>(typeOrMapper?: TypeOrMapper<T>): HttpBuilderOfT<T>;
|
|
20
|
+
expectJsonArray<T>(typeOrMapper: TypeOrMapper<T>): HttpBuilderOfT<T[]>;
|
|
21
|
+
expectJsonNullableArray<T>(
|
|
22
|
+
typeOrMapper: TypeOrMapper<T>,
|
|
23
|
+
): HttpBuilderOfT<(T | null)[]>;
|
|
24
|
+
expectJsonPaginationResult<T>(
|
|
25
|
+
typeOrMapper: TypeOrMapper<T>,
|
|
26
|
+
): HttpBuilderOfT<PaginationResult<T>>;
|
|
27
|
+
expectJsonInfinitePaginationResult<T>(
|
|
28
|
+
typeOrMapper: TypeOrMapper<T>,
|
|
29
|
+
): HttpBuilderOfT<InfinitePaginationResult<T>>;
|
|
30
|
+
}
|
|
31
|
+
interface HttpBuilderOfT<T> {
|
|
32
|
+
withJson(content: any): this;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
HttpBuilder.prototype.withJson = function (this: HttpBuilder, content: any) {
|
|
37
|
+
this.message.content = serialize(content);
|
|
38
|
+
this.message.contentType = "application/json";
|
|
39
|
+
return this;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
HttpBuilderOfT.prototype.withJson = function <T>(
|
|
43
|
+
this: HttpBuilderOfT<T>,
|
|
44
|
+
content: any,
|
|
45
|
+
) {
|
|
46
|
+
this.message.content = serialize(content);
|
|
47
|
+
this.message.contentType = "application/json";
|
|
48
|
+
return this;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
HttpBuilder.prototype.expectJson = function <T>(
|
|
52
|
+
this: HttpBuilder,
|
|
53
|
+
typeOrMapper?: TypeOrMapper<T>,
|
|
54
|
+
) {
|
|
55
|
+
this.message.headers.set("Accept", "application/json");
|
|
56
|
+
return this.useHandler((response) => {
|
|
57
|
+
return response.rawResponse
|
|
58
|
+
.json()
|
|
59
|
+
.then((x) => getMapper(deserialize, typeOrMapper)(x));
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
HttpBuilder.prototype.expectJsonArray = function <T>(
|
|
64
|
+
this: HttpBuilder,
|
|
65
|
+
typeOrMapper: TypeOrMapper<T>,
|
|
66
|
+
) {
|
|
67
|
+
this.message.headers.set("Accept", "application/json");
|
|
68
|
+
return this.useHandler((response) => {
|
|
69
|
+
return response.rawResponse.json().then((x: any[]) => {
|
|
70
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
71
|
+
return x.map(itemFactory);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
HttpBuilder.prototype.expectJsonNullableArray = function <T>(
|
|
77
|
+
this: HttpBuilder,
|
|
78
|
+
typeOrMapper: TypeOrMapper<T>,
|
|
79
|
+
): HttpBuilderOfT<(T | null)[]> {
|
|
80
|
+
this.message.headers.set("Accept", "application/json");
|
|
81
|
+
return this.useHandler((response) => {
|
|
82
|
+
return response.rawResponse.json().then((x: any[]) => {
|
|
83
|
+
const itemFactory = getNullableMapper(deserialize, typeOrMapper);
|
|
84
|
+
return x.map(itemFactory);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
HttpBuilder.prototype.expectJsonPaginationResult = function <T>(
|
|
90
|
+
this: HttpBuilder,
|
|
91
|
+
typeOrMapper: TypeOrMapper<T>,
|
|
92
|
+
) {
|
|
93
|
+
this.message.headers.set("Accept", "application/json");
|
|
94
|
+
return this.useHandler((response) => {
|
|
95
|
+
return response.rawResponse.json().then((x: PaginationResult<any>) => {
|
|
96
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
97
|
+
return {
|
|
98
|
+
meta: {
|
|
99
|
+
pageCount: x.meta.pageCount,
|
|
100
|
+
pageSize: x.meta.pageSize,
|
|
101
|
+
totalItems: x.meta.totalItems,
|
|
102
|
+
},
|
|
103
|
+
data: x.data.map(itemFactory),
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
HttpBuilder.prototype.expectJsonInfinitePaginationResult = function <T>(
|
|
110
|
+
this: HttpBuilder,
|
|
111
|
+
typeOrMapper: TypeOrMapper<T>,
|
|
112
|
+
) {
|
|
113
|
+
this.message.headers.set("Accept", "application/json");
|
|
114
|
+
return this.useHandler((response) => {
|
|
115
|
+
return response.rawResponse
|
|
116
|
+
.json()
|
|
117
|
+
.then((x: InfinitePaginationResult<any>) => {
|
|
118
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
119
|
+
return {
|
|
120
|
+
meta: {
|
|
121
|
+
pageSize: x.meta.pageSize,
|
|
122
|
+
continuationToken: x.meta.continuationToken,
|
|
123
|
+
},
|
|
124
|
+
data: x.data.map(itemFactory),
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"source": "src/index.ts",
|
|
3
|
+
"main": "./../../dist/jsonpatch.js",
|
|
4
|
+
"module": "./../../dist/jsonpatch.mjs",
|
|
5
|
+
"types": "./../../dist/jsonpatch.d.ts",
|
|
6
|
+
"alias": {
|
|
7
|
+
"@utiliread/http": false
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@utiliread/http": "file:../../"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@utiliread/json": "file:../../node_modules/@utiliread/json",
|
|
14
|
+
"@utiliread/jsonpatch": "file:../../node_modules/@utiliread/jsonpatch"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"source": "src/index.ts",
|
|
3
|
+
"main": "./../../dist/msgpack.js",
|
|
4
|
+
"module": "./../../dist/msgpack.mjs",
|
|
5
|
+
"types": "./../../dist/msgpack.d.ts",
|
|
6
|
+
"alias": {
|
|
7
|
+
"@utiliread/http": false
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@utiliread/http": "file:../../"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@msgpack/msgpack": "file:../../node_modules/@msgpack/msgpack",
|
|
14
|
+
"@utiliread/msgpack": "file:../../node_modules/@utiliread/msgpack"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { HttpBuilder, HttpBuilderOfT, HttpResponse,
|
|
2
|
-
import { decodeArrayStream, decodeAsync } from "@msgpack/msgpack";
|
|
3
|
-
|
|
4
|
-
import { deserialize } from "@utiliread/msgpack";
|
|
5
|
-
|
|
6
|
-
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
7
|
-
declare module "@utiliread/http" {
|
|
8
|
-
interface HttpBuilder {
|
|
9
|
-
expectMessagePack<T>(typeOrMapper?:
|
|
10
|
-
expectMessagePackArray<T>(
|
|
11
|
-
typeOrMapper?:
|
|
12
|
-
): HttpBuilderOfT<T[]>;
|
|
13
|
-
streamMessagePackArray<T>(
|
|
14
|
-
typeOrMapper?:
|
|
15
|
-
): HttpBuilderOfT<AsyncGenerator<T, void, unknown>>;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
HttpBuilder.prototype.expectMessagePack = function <T>(
|
|
20
|
-
this: HttpBuilder,
|
|
21
|
-
typeOrMapper?:
|
|
22
|
-
) {
|
|
23
|
-
this.message.headers.set("Accept", "application/x-msgpack");
|
|
24
|
-
return this.useHandler(async (response) => {
|
|
25
|
-
const itemFactory =
|
|
26
|
-
const decoded = await decodeAsync(response.rawResponse.body!);
|
|
27
|
-
return itemFactory(decoded);
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
HttpBuilder.prototype.expectMessagePackArray = function <T>(
|
|
32
|
-
this: HttpBuilder,
|
|
33
|
-
typeOrMapper?:
|
|
34
|
-
) {
|
|
35
|
-
this.message.headers.set("Accept", "application/x-msgpack");
|
|
36
|
-
return this.useHandler(async (response) => {
|
|
37
|
-
const items: T[] = [];
|
|
38
|
-
const itemFactory =
|
|
39
|
-
for await (const item of decodeArrayStream(response.rawResponse.body!)) {
|
|
40
|
-
items.push(itemFactory(item));
|
|
41
|
-
}
|
|
42
|
-
return items;
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
HttpBuilder.prototype.streamMessagePackArray = function <T>(
|
|
47
|
-
this: HttpBuilder,
|
|
48
|
-
typeOrMapper?:
|
|
49
|
-
) {
|
|
50
|
-
this.message.headers.set("Accept", "application/x-msgpack");
|
|
51
|
-
|
|
52
|
-
async function* handler(response: HttpResponse) {
|
|
53
|
-
const itemFactory =
|
|
54
|
-
for await (const item of decodeArrayStream(response.rawResponse.body!)) {
|
|
55
|
-
yield itemFactory(item);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return this.useHandler((response) => Promise.resolve(handler(response)));
|
|
60
|
-
};
|
|
1
|
+
import { HttpBuilder, HttpBuilderOfT, HttpResponse, TypeOrMapper, getMapper } from "@utiliread/http";
|
|
2
|
+
import { decodeArrayStream, decodeAsync } from "@msgpack/msgpack";
|
|
3
|
+
|
|
4
|
+
import { deserialize } from "@utiliread/msgpack";
|
|
5
|
+
|
|
6
|
+
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
7
|
+
declare module "@utiliread/http" {
|
|
8
|
+
interface HttpBuilder {
|
|
9
|
+
expectMessagePack<T>(typeOrMapper?: TypeOrMapper<T>): HttpBuilderOfT<T>;
|
|
10
|
+
expectMessagePackArray<T>(
|
|
11
|
+
typeOrMapper?: TypeOrMapper<T>,
|
|
12
|
+
): HttpBuilderOfT<T[]>;
|
|
13
|
+
streamMessagePackArray<T>(
|
|
14
|
+
typeOrMapper?: TypeOrMapper<T>,
|
|
15
|
+
): HttpBuilderOfT<AsyncGenerator<T, void, unknown>>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
HttpBuilder.prototype.expectMessagePack = function <T>(
|
|
20
|
+
this: HttpBuilder,
|
|
21
|
+
typeOrMapper?: TypeOrMapper<T>,
|
|
22
|
+
) {
|
|
23
|
+
this.message.headers.set("Accept", "application/x-msgpack");
|
|
24
|
+
return this.useHandler(async (response) => {
|
|
25
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
26
|
+
const decoded = await decodeAsync(response.rawResponse.body!);
|
|
27
|
+
return itemFactory(decoded);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
HttpBuilder.prototype.expectMessagePackArray = function <T>(
|
|
32
|
+
this: HttpBuilder,
|
|
33
|
+
typeOrMapper?: TypeOrMapper<T>,
|
|
34
|
+
) {
|
|
35
|
+
this.message.headers.set("Accept", "application/x-msgpack");
|
|
36
|
+
return this.useHandler(async (response) => {
|
|
37
|
+
const items: T[] = [];
|
|
38
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
39
|
+
for await (const item of decodeArrayStream(response.rawResponse.body!)) {
|
|
40
|
+
items.push(itemFactory(item));
|
|
41
|
+
}
|
|
42
|
+
return items;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
HttpBuilder.prototype.streamMessagePackArray = function <T>(
|
|
47
|
+
this: HttpBuilder,
|
|
48
|
+
typeOrMapper?: TypeOrMapper<T>,
|
|
49
|
+
) {
|
|
50
|
+
this.message.headers.set("Accept", "application/x-msgpack");
|
|
51
|
+
|
|
52
|
+
async function* handler(response: HttpResponse) {
|
|
53
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
54
|
+
for await (const item of decodeArrayStream(response.rawResponse.body!)) {
|
|
55
|
+
yield itemFactory(item);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return this.useHandler((response) => Promise.resolve(handler(response)));
|
|
60
|
+
};
|
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
|
+
}
|