@utiliread/http 1.18.0 → 1.19.1
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/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 +78 -0
- package/dist/json.js.map +1 -0
- package/dist/json.mjs +78 -0
- package/dist/json.mjs.map +1 -0
- package/dist/jsonpatch.d.ts +10 -0
- 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/msgpack.d.ts +1 -1
- package/package.json +34 -30
- package/plugins/json/node_modules/@utiliread/http/package.json +1 -1
- package/plugins/json/package.json +15 -0
- package/plugins/json/src/index.ts +143 -124
- package/plugins/json/tsconfig.json +1 -2
- package/plugins/jsonpatch/node_modules/@utiliread/http/package.json +1 -1
- package/plugins/jsonpatch/package.json +16 -0
- package/plugins/jsonpatch/src/index.ts +32 -31
- package/plugins/jsonpatch/tsconfig.json +1 -2
- package/plugins/msgpack/node_modules/@utiliread/http/package.json +1 -1
- package/plugins/msgpack/package.json +16 -0
- package/plugins/msgpack/src/index.ts +60 -67
- package/plugins/msgpack/tsconfig.json +1 -2
- package/src/index.ts +1 -1
- package/tsconfig.json +0 -1
- package/web-test-runner.config.mjs +7 -7
- 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 -68
- 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.d.ts +0 -9
- 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 -64
- 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/plugins/json/tsconfig.cjs.json +0 -8
- package/plugins/jsonpatch/tsconfig.cjs.json +0 -8
- package/plugins/msgpack/tsconfig.cjs.json +0 -8
- package/tsconfig.cjs.json +0 -9
- /package/src/{mapping.ts → mapper.ts} +0 -0
|
@@ -1,124 +1,143 @@
|
|
|
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
|
-
this
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
HttpBuilder.prototype.
|
|
60
|
-
this: HttpBuilder,
|
|
61
|
-
typeOrMapper
|
|
62
|
-
) {
|
|
63
|
-
this.message.headers.set("Accept", "application/json");
|
|
64
|
-
return this.useHandler((response) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
HttpBuilder.prototype.
|
|
73
|
-
this: HttpBuilder,
|
|
74
|
-
typeOrMapper:
|
|
75
|
-
)
|
|
76
|
-
this.message.headers.set("Accept", "application/json");
|
|
77
|
-
return this.useHandler((response) => {
|
|
78
|
-
|
|
79
|
-
const itemFactory =
|
|
80
|
-
return x.map(itemFactory);
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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>(
|
|
20
|
+
typeOrMapper?: import("@utiliread/http").TypeOrMapper<T>
|
|
21
|
+
): import("@utiliread/http").HttpBuilderOfT<T>;
|
|
22
|
+
expectJsonArray<T>(
|
|
23
|
+
typeOrMapper: import("@utiliread/http").TypeOrMapper<T>
|
|
24
|
+
): import("@utiliread/http").HttpBuilderOfT<T[]>;
|
|
25
|
+
expectJsonNullableArray<T>(
|
|
26
|
+
typeOrMapper: import("@utiliread/http").TypeOrMapper<T>
|
|
27
|
+
): import("@utiliread/http").HttpBuilderOfT<(T | null)[]>;
|
|
28
|
+
expectJsonPaginationResult<T>(
|
|
29
|
+
typeOrMapper: import("@utiliread/http").TypeOrMapper<T>
|
|
30
|
+
): import("@utiliread/http").HttpBuilderOfT<
|
|
31
|
+
import("@utiliread/http").PaginationResult<T>
|
|
32
|
+
>;
|
|
33
|
+
expectJsonInfinitePaginationResult<T>(
|
|
34
|
+
typeOrMapper: import("@utiliread/http").TypeOrMapper<T>
|
|
35
|
+
): import("@utiliread/http").HttpBuilderOfT<
|
|
36
|
+
import("@utiliread/http").InfinitePaginationResult<T>
|
|
37
|
+
>;
|
|
38
|
+
}
|
|
39
|
+
interface HttpBuilderOfT<T> {
|
|
40
|
+
withJson(content: any): this;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
HttpBuilder.prototype.withJson = function (this: HttpBuilder, content: any) {
|
|
45
|
+
this.message.content = serialize(content);
|
|
46
|
+
this.message.contentType = "application/json";
|
|
47
|
+
return this;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
HttpBuilderOfT.prototype.withJson = function <T>(
|
|
51
|
+
this: HttpBuilderOfT<T>,
|
|
52
|
+
content: any
|
|
53
|
+
) {
|
|
54
|
+
this.message.content = serialize(content);
|
|
55
|
+
this.message.contentType = "application/json";
|
|
56
|
+
return this;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
HttpBuilder.prototype.expectJson = function <T>(
|
|
60
|
+
this: HttpBuilder,
|
|
61
|
+
typeOrMapper?: TypeOrMapper<T>
|
|
62
|
+
) {
|
|
63
|
+
this.message.headers.set("Accept", "application/json");
|
|
64
|
+
return this.useHandler((response) => {
|
|
65
|
+
const promise = response.rawResponse
|
|
66
|
+
.json()
|
|
67
|
+
.then((x) => getMapper(deserialize, typeOrMapper)(x));
|
|
68
|
+
return promise;
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
HttpBuilder.prototype.expectJsonArray = function <T>(
|
|
73
|
+
this: HttpBuilder,
|
|
74
|
+
typeOrMapper: TypeOrMapper<T>
|
|
75
|
+
) {
|
|
76
|
+
this.message.headers.set("Accept", "application/json");
|
|
77
|
+
return this.useHandler((response) => {
|
|
78
|
+
const promise = response.rawResponse.json().then((x: any[]) => {
|
|
79
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
80
|
+
return x.map(itemFactory);
|
|
81
|
+
});
|
|
82
|
+
return promise;
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
HttpBuilder.prototype.expectJsonNullableArray = function <T>(
|
|
87
|
+
this: HttpBuilder,
|
|
88
|
+
typeOrMapper: TypeOrMapper<T>
|
|
89
|
+
): HttpBuilderOfT<(T | null)[]> {
|
|
90
|
+
this.message.headers.set("Accept", "application/json");
|
|
91
|
+
return this.useHandler((response) => {
|
|
92
|
+
const promise = response.rawResponse.json().then((x: any[]) => {
|
|
93
|
+
const itemFactory = getNullableMapper(deserialize, typeOrMapper);
|
|
94
|
+
return x.map(itemFactory);
|
|
95
|
+
});
|
|
96
|
+
return promise;
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
HttpBuilder.prototype.expectJsonPaginationResult = function <T>(
|
|
101
|
+
this: HttpBuilder,
|
|
102
|
+
typeOrMapper: TypeOrMapper<T>
|
|
103
|
+
) {
|
|
104
|
+
this.message.headers.set("Accept", "application/json");
|
|
105
|
+
return this.useHandler((response) => {
|
|
106
|
+
const promise = response.rawResponse
|
|
107
|
+
.json()
|
|
108
|
+
.then((x: PaginationResult<any>) => {
|
|
109
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
110
|
+
return {
|
|
111
|
+
meta: {
|
|
112
|
+
pageCount: x.meta.pageCount,
|
|
113
|
+
pageSize: x.meta.pageSize,
|
|
114
|
+
totalItems: x.meta.totalItems,
|
|
115
|
+
},
|
|
116
|
+
data: x.data.map(itemFactory),
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
return promise;
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
HttpBuilder.prototype.expectJsonInfinitePaginationResult = function <T>(
|
|
124
|
+
this: HttpBuilder,
|
|
125
|
+
typeOrMapper: TypeOrMapper<T>
|
|
126
|
+
) {
|
|
127
|
+
this.message.headers.set("Accept", "application/json");
|
|
128
|
+
return this.useHandler((response) => {
|
|
129
|
+
const promise = response.rawResponse
|
|
130
|
+
.json()
|
|
131
|
+
.then((x: InfinitePaginationResult<any>) => {
|
|
132
|
+
const itemFactory = getMapper(deserialize, typeOrMapper);
|
|
133
|
+
return {
|
|
134
|
+
meta: {
|
|
135
|
+
pageSize: x.meta.pageSize,
|
|
136
|
+
continuationToken: x.meta.continuationToken,
|
|
137
|
+
},
|
|
138
|
+
data: x.data.map(itemFactory),
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
return promise;
|
|
142
|
+
});
|
|
143
|
+
};
|
|
@@ -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,32 @@
|
|
|
1
|
-
import { HttpBuilder, HttpBuilderOfT } from "@utiliread/http";
|
|
2
|
-
|
|
3
|
-
import type { Operation } from "@utiliread/jsonpatch";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.message.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.message.
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import { HttpBuilder, HttpBuilderOfT } from "@utiliread/http";
|
|
2
|
+
|
|
3
|
+
import type { Operation } from "@utiliread/jsonpatch";
|
|
4
|
+
import { serialize } from "@utiliread/json";
|
|
5
|
+
|
|
6
|
+
// https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
|
7
|
+
declare module "@utiliread/http" {
|
|
8
|
+
interface HttpBuilder {
|
|
9
|
+
withJsonPatch(operations: import("@utiliread/jsonpatch").Operation[]): this;
|
|
10
|
+
}
|
|
11
|
+
interface HttpBuilderOfT<T> {
|
|
12
|
+
withJsonPatch(operations: import("@utiliread/jsonpatch").Operation[]): this;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
HttpBuilder.prototype.withJsonPatch = function (
|
|
17
|
+
this: HttpBuilder,
|
|
18
|
+
operations: Operation[],
|
|
19
|
+
) {
|
|
20
|
+
this.message.content = serialize(operations);
|
|
21
|
+
this.message.contentType = "application/json-patch+json";
|
|
22
|
+
return this;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
HttpBuilderOfT.prototype.withJsonPatch = function <T>(
|
|
26
|
+
this: HttpBuilderOfT<T>,
|
|
27
|
+
operations: Operation[],
|
|
28
|
+
) {
|
|
29
|
+
this.message.content = serialize(operations);
|
|
30
|
+
this.message.contentType = "application/json-patch+json";
|
|
31
|
+
return this;
|
|
32
|
+
};
|
|
@@ -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,67 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
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
|
-
|
|
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
|
-
};
|
|
1
|
+
import { HttpBuilder, 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?: import("@utiliread/http").TypeOrMapper<T>): import("@utiliread/http").HttpBuilderOfT<T>;
|
|
10
|
+
expectMessagePackArray<T>(
|
|
11
|
+
typeOrMapper?: import("@utiliread/http").TypeOrMapper<T>,
|
|
12
|
+
): import("@utiliread/http").HttpBuilderOfT<T[]>;
|
|
13
|
+
streamMessagePackArray<T>(
|
|
14
|
+
typeOrMapper?: import("@utiliread/http").TypeOrMapper<T>,
|
|
15
|
+
): import("@utiliread/http").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/index.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { esbuildPlugin } from "@web/dev-server-esbuild";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
1
|
+
import { esbuildPlugin } from "@web/dev-server-esbuild";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
nodeResolve: true,
|
|
5
|
+
files: ["src/**/*.spec.ts"],
|
|
6
|
+
plugins: [esbuildPlugin({ ts: true })],
|
|
7
|
+
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventAggregator = void 0;
|
|
4
|
-
class EventAggregator {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.callbacks = [];
|
|
7
|
-
}
|
|
8
|
-
get any() {
|
|
9
|
-
return this.callbacks.length > 0;
|
|
10
|
-
}
|
|
11
|
-
subscribe(callback) {
|
|
12
|
-
this.callbacks.push(callback);
|
|
13
|
-
return {
|
|
14
|
-
dispose: () => {
|
|
15
|
-
const index = this.callbacks.indexOf(callback);
|
|
16
|
-
if (index >= 0) {
|
|
17
|
-
this.callbacks.splice(index, 1);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
async publish(...params) {
|
|
23
|
-
const callbacks = this.callbacks.slice();
|
|
24
|
-
for (const callback of callbacks) {
|
|
25
|
-
await Promise.resolve(callback.apply(this, params));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.EventAggregator = EventAggregator;
|
|
30
|
-
//# sourceMappingURL=event-aggregator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-aggregator.js","sourceRoot":"","sources":["../../src/event-aggregator.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAe;IAA5B;QACY,cAAS,GAAe,EAAE,CAAC;IAwBvC,CAAC;IAtBG,IAAI,GAAG;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,SAAS,CAAC,QAAqB;QAC3B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO;YACH,OAAO,EAAE,GAAG,EAAE;gBACV,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC/C,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;oBACb,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBACpC,CAAC;YACL,CAAC;SACJ,CAAA;IACL,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAG,MAAS;QACtB,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACzC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YAC/B,MAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QACxD,CAAC;IACL,CAAC;CACJ;AAzBD,0CAyBC"}
|
package/dist/cjs/events.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.events = void 0;
|
|
4
|
-
const http_builder_1 = require("./http-builder");
|
|
5
|
-
function events(action, configure) {
|
|
6
|
-
return function (...params) {
|
|
7
|
-
const builder = action(...params);
|
|
8
|
-
const events = configure(...params);
|
|
9
|
-
if (events.sent) {
|
|
10
|
-
builder.onSent(events.sent);
|
|
11
|
-
}
|
|
12
|
-
if (builder instanceof http_builder_1.HttpBuilderOfT && events.received) {
|
|
13
|
-
builder.onReceived(events.received);
|
|
14
|
-
}
|
|
15
|
-
return builder;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
exports.events = events;
|
|
19
|
-
//# sourceMappingURL=events.js.map
|
package/dist/cjs/events.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":";;;AAAA,iDAAsE;AAuBtE,SAAgB,MAAM,CACpB,MAA2B,EAC3B,SAAkD;IAElD,OAAO,UAAU,GAAG,MAAS;QAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC;QACpC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YAChB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,OAAO,YAAY,6BAAc,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACzD,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC;AAfD,wBAeC"}
|