@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.
Files changed (143) hide show
  1. package/dist/index.d.ts +231 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +564 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +535 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/json.d.ts +15 -0
  8. package/dist/json.d.ts.map +1 -0
  9. package/dist/json.js +78 -0
  10. package/dist/json.js.map +1 -0
  11. package/dist/json.mjs +78 -0
  12. package/dist/json.mjs.map +1 -0
  13. package/dist/jsonpatch.d.ts +10 -0
  14. package/dist/jsonpatch.d.ts.map +1 -0
  15. package/dist/jsonpatch.js +18 -0
  16. package/dist/jsonpatch.js.map +1 -0
  17. package/dist/jsonpatch.mjs +18 -0
  18. package/dist/jsonpatch.mjs.map +1 -0
  19. package/dist/msgpack.d.ts +9 -0
  20. package/dist/msgpack.d.ts.map +1 -0
  21. package/dist/msgpack.js +35 -0
  22. package/dist/msgpack.js.map +1 -0
  23. package/dist/msgpack.mjs +35 -0
  24. package/dist/msgpack.mjs.map +1 -0
  25. package/json.d.ts +1 -1
  26. package/jsonpatch.d.ts +1 -1
  27. package/msgpack.d.ts +1 -1
  28. package/package.json +34 -30
  29. package/plugins/json/node_modules/@utiliread/http/package.json +1 -1
  30. package/plugins/json/package.json +15 -0
  31. package/plugins/json/src/index.ts +143 -124
  32. package/plugins/json/tsconfig.json +1 -2
  33. package/plugins/jsonpatch/node_modules/@utiliread/http/package.json +1 -1
  34. package/plugins/jsonpatch/package.json +16 -0
  35. package/plugins/jsonpatch/src/index.ts +32 -31
  36. package/plugins/jsonpatch/tsconfig.json +1 -2
  37. package/plugins/msgpack/node_modules/@utiliread/http/package.json +1 -1
  38. package/plugins/msgpack/package.json +16 -0
  39. package/plugins/msgpack/src/index.ts +60 -67
  40. package/plugins/msgpack/tsconfig.json +1 -2
  41. package/src/index.ts +1 -1
  42. package/tsconfig.json +0 -1
  43. package/web-test-runner.config.mjs +7 -7
  44. package/dist/cjs/event-aggregator.js +0 -30
  45. package/dist/cjs/event-aggregator.js.map +0 -1
  46. package/dist/cjs/events.js +0 -19
  47. package/dist/cjs/events.js.map +0 -1
  48. package/dist/cjs/helpers.js +0 -16
  49. package/dist/cjs/helpers.js.map +0 -1
  50. package/dist/cjs/http-builder.js +0 -192
  51. package/dist/cjs/http-builder.js.map +0 -1
  52. package/dist/cjs/http-error.js +0 -30
  53. package/dist/cjs/http-error.js.map +0 -1
  54. package/dist/cjs/http-response.js +0 -51
  55. package/dist/cjs/http-response.js.map +0 -1
  56. package/dist/cjs/http.js +0 -96
  57. package/dist/cjs/http.js.map +0 -1
  58. package/dist/cjs/http.spec.js +0 -69
  59. package/dist/cjs/http.spec.js.map +0 -1
  60. package/dist/cjs/index.js +0 -38
  61. package/dist/cjs/index.js.map +0 -1
  62. package/dist/cjs/json/index.js +0 -74
  63. package/dist/cjs/json/index.js.map +0 -1
  64. package/dist/cjs/jsonpatch/index.js +0 -15
  65. package/dist/cjs/jsonpatch/index.js.map +0 -1
  66. package/dist/cjs/mapping.js +0 -37
  67. package/dist/cjs/mapping.js.map +0 -1
  68. package/dist/cjs/msgpack/index.js +0 -35
  69. package/dist/cjs/msgpack/index.js.map +0 -1
  70. package/dist/cjs/pagination.js +0 -3
  71. package/dist/cjs/pagination.js.map +0 -1
  72. package/dist/cjs/problem-details.js +0 -3
  73. package/dist/cjs/problem-details.js.map +0 -1
  74. package/dist/cjs/query-string.js +0 -68
  75. package/dist/cjs/query-string.js.map +0 -1
  76. package/dist/cjs/query-string.spec.js +0 -52
  77. package/dist/cjs/query-string.spec.js.map +0 -1
  78. package/dist/cjs/status-codes.js +0 -71
  79. package/dist/cjs/status-codes.js.map +0 -1
  80. package/dist/cjs/timeout-error.js +0 -14
  81. package/dist/cjs/timeout-error.js.map +0 -1
  82. package/dist/esm/event-aggregator.d.ts +0 -11
  83. package/dist/esm/event-aggregator.js +0 -26
  84. package/dist/esm/event-aggregator.js.map +0 -1
  85. package/dist/esm/events.d.ts +0 -11
  86. package/dist/esm/events.js +0 -15
  87. package/dist/esm/events.js.map +0 -1
  88. package/dist/esm/helpers.d.ts +0 -5
  89. package/dist/esm/helpers.js +0 -10
  90. package/dist/esm/helpers.js.map +0 -1
  91. package/dist/esm/http-builder.d.ts +0 -60
  92. package/dist/esm/http-builder.js +0 -187
  93. package/dist/esm/http-builder.js.map +0 -1
  94. package/dist/esm/http-error.d.ts +0 -10
  95. package/dist/esm/http-error.js +0 -26
  96. package/dist/esm/http-error.js.map +0 -1
  97. package/dist/esm/http-response.d.ts +0 -18
  98. package/dist/esm/http-response.js +0 -46
  99. package/dist/esm/http-response.js.map +0 -1
  100. package/dist/esm/http.d.ts +0 -33
  101. package/dist/esm/http.js +0 -92
  102. package/dist/esm/http.js.map +0 -1
  103. package/dist/esm/http.spec.d.ts +0 -1
  104. package/dist/esm/http.spec.js +0 -67
  105. package/dist/esm/http.spec.js.map +0 -1
  106. package/dist/esm/index.d.ts +0 -15
  107. package/dist/esm/index.js +0 -11
  108. package/dist/esm/index.js.map +0 -1
  109. package/dist/esm/json/index.d.ts +0 -15
  110. package/dist/esm/json/index.js +0 -72
  111. package/dist/esm/json/index.js.map +0 -1
  112. package/dist/esm/jsonpatch/index.d.ts +0 -9
  113. package/dist/esm/jsonpatch/index.js +0 -13
  114. package/dist/esm/jsonpatch/index.js.map +0 -1
  115. package/dist/esm/mapping.d.ts +0 -9
  116. package/dist/esm/mapping.js +0 -32
  117. package/dist/esm/mapping.js.map +0 -1
  118. package/dist/esm/msgpack/index.d.ts +0 -8
  119. package/dist/esm/msgpack/index.js +0 -33
  120. package/dist/esm/msgpack/index.js.map +0 -1
  121. package/dist/esm/pagination.d.ts +0 -23
  122. package/dist/esm/pagination.js +0 -2
  123. package/dist/esm/pagination.js.map +0 -1
  124. package/dist/esm/problem-details.d.ts +0 -7
  125. package/dist/esm/problem-details.js +0 -2
  126. package/dist/esm/problem-details.js.map +0 -1
  127. package/dist/esm/query-string.d.ts +0 -6
  128. package/dist/esm/query-string.js +0 -64
  129. package/dist/esm/query-string.js.map +0 -1
  130. package/dist/esm/query-string.spec.d.ts +0 -1
  131. package/dist/esm/query-string.spec.js +0 -50
  132. package/dist/esm/query-string.spec.js.map +0 -1
  133. package/dist/esm/status-codes.d.ts +0 -67
  134. package/dist/esm/status-codes.js +0 -68
  135. package/dist/esm/status-codes.js.map +0 -1
  136. package/dist/esm/timeout-error.d.ts +0 -3
  137. package/dist/esm/timeout-error.js +0 -10
  138. package/dist/esm/timeout-error.js.map +0 -1
  139. package/plugins/json/tsconfig.cjs.json +0 -8
  140. package/plugins/jsonpatch/tsconfig.cjs.json +0 -8
  141. package/plugins/msgpack/tsconfig.cjs.json +0 -8
  142. package/tsconfig.cjs.json +0 -9
  143. /package/src/{mapping.ts → mapper.ts} +0 -0
@@ -1,124 +1,143 @@
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
+ 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
+ };
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "../../dist/esm/json"
4
+ "rootDir": "src"
6
5
  },
7
6
  "include": ["./src/*.ts"]
8
7
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@utiliread/http",
3
- "types": "../../../../../dist/esm/index.d.ts"
3
+ "types": "../../../../../dist/index.d.ts"
4
4
  }
@@ -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
- 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
+
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
+ };
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "../../dist/esm/jsonpatch"
4
+ "rootDir": "src"
6
5
  },
7
6
  "include": ["./src/*.ts"]
8
7
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@utiliread/http",
3
- "types": "../../../../../dist/esm/index.d.ts"
3
+ "types": "../../../../../dist/index.d.ts"
4
4
  }
@@ -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
- 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
- };
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
+ };
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "../../dist/esm/msgpack"
4
+ "rootDir": "src"
6
5
  },
7
6
  "include": ["./src/*.ts"]
8
7
  }
package/src/index.ts CHANGED
@@ -17,4 +17,4 @@ export * from "./helpers";
17
17
  export type { Fetch } from "./http";
18
18
  export type { Subscription } from "./event-aggregator";
19
19
  export { statusCodes } from "./status-codes";
20
- export * as Mapping from "./mapping";
20
+ export * from "./mapper";
package/tsconfig.json CHANGED
@@ -8,7 +8,6 @@
8
8
  "strict": true,
9
9
  "stripInternal": true,
10
10
  "rootDir": "src",
11
- "outDir": "dist/esm",
12
11
  "lib": ["ES2018", "DOM"],
13
12
  "types": ["mocha"]
14
13
  },
@@ -1,7 +1,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
+ 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"}
@@ -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
@@ -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"}