@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.
Files changed (160) hide show
  1. package/.vscode/settings.json +2 -2
  2. package/dist/index.d.ts +231 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +564 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +535 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/json.d.ts +15 -0
  9. package/dist/json.d.ts.map +1 -0
  10. package/dist/json.js +73 -0
  11. package/dist/json.js.map +1 -0
  12. package/dist/json.mjs +73 -0
  13. package/dist/json.mjs.map +1 -0
  14. package/dist/{esm/jsonpatch/index.d.ts → jsonpatch.d.ts} +10 -9
  15. package/dist/jsonpatch.d.ts.map +1 -0
  16. package/dist/jsonpatch.js +18 -0
  17. package/dist/jsonpatch.js.map +1 -0
  18. package/dist/jsonpatch.mjs +18 -0
  19. package/dist/jsonpatch.mjs.map +1 -0
  20. package/dist/msgpack.d.ts +9 -0
  21. package/dist/msgpack.d.ts.map +1 -0
  22. package/dist/msgpack.js +35 -0
  23. package/dist/msgpack.js.map +1 -0
  24. package/dist/msgpack.mjs +35 -0
  25. package/dist/msgpack.mjs.map +1 -0
  26. package/json.d.ts +1 -1
  27. package/jsonpatch.d.ts +1 -1
  28. package/mapper.d.ts +1 -0
  29. package/msgpack.d.ts +1 -1
  30. package/package.json +40 -38
  31. package/plugins/json/node_modules/@utiliread/http/package.json +4 -0
  32. package/plugins/json/package.json +15 -0
  33. package/plugins/json/src/index.ts +128 -122
  34. package/plugins/json/tsconfig.json +1 -2
  35. package/plugins/jsonpatch/node_modules/@utiliread/http/package.json +4 -0
  36. package/plugins/jsonpatch/package.json +16 -0
  37. package/plugins/jsonpatch/src/index.ts +31 -31
  38. package/plugins/jsonpatch/tsconfig.json +1 -2
  39. package/plugins/msgpack/node_modules/@utiliread/http/package.json +4 -0
  40. package/plugins/msgpack/package.json +16 -0
  41. package/plugins/msgpack/src/index.ts +60 -60
  42. package/plugins/msgpack/tsconfig.json +1 -2
  43. package/src/event-aggregator.ts +21 -21
  44. package/src/events.ts +39 -39
  45. package/src/helpers.ts +6 -6
  46. package/src/http-builder.ts +252 -218
  47. package/src/http-error.ts +30 -23
  48. package/src/http-response.ts +1 -1
  49. package/src/http.spec.ts +1 -1
  50. package/src/http.ts +8 -5
  51. package/src/index.ts +1 -1
  52. package/src/mapper.ts +52 -0
  53. package/src/pagination.ts +16 -16
  54. package/src/problem-details.ts +6 -6
  55. package/src/query-string.spec.ts +59 -43
  56. package/src/query-string.ts +56 -58
  57. package/src/status-codes.ts +67 -67
  58. package/src/timeout-error.ts +7 -7
  59. package/tsconfig.cjs.json +1 -0
  60. package/tsconfig.json +1 -2
  61. package/web-test-runner.config.mjs +7 -0
  62. package/dist/cjs/event-aggregator.js +0 -30
  63. package/dist/cjs/event-aggregator.js.map +0 -1
  64. package/dist/cjs/events.js +0 -19
  65. package/dist/cjs/events.js.map +0 -1
  66. package/dist/cjs/helpers.js +0 -16
  67. package/dist/cjs/helpers.js.map +0 -1
  68. package/dist/cjs/http-builder.js +0 -192
  69. package/dist/cjs/http-builder.js.map +0 -1
  70. package/dist/cjs/http-error.js +0 -30
  71. package/dist/cjs/http-error.js.map +0 -1
  72. package/dist/cjs/http-response.js +0 -51
  73. package/dist/cjs/http-response.js.map +0 -1
  74. package/dist/cjs/http.js +0 -96
  75. package/dist/cjs/http.js.map +0 -1
  76. package/dist/cjs/http.spec.js +0 -69
  77. package/dist/cjs/http.spec.js.map +0 -1
  78. package/dist/cjs/index.js +0 -38
  79. package/dist/cjs/index.js.map +0 -1
  80. package/dist/cjs/json/index.js +0 -74
  81. package/dist/cjs/json/index.js.map +0 -1
  82. package/dist/cjs/jsonpatch/index.js +0 -15
  83. package/dist/cjs/jsonpatch/index.js.map +0 -1
  84. package/dist/cjs/mapping.js +0 -37
  85. package/dist/cjs/mapping.js.map +0 -1
  86. package/dist/cjs/msgpack/index.js +0 -35
  87. package/dist/cjs/msgpack/index.js.map +0 -1
  88. package/dist/cjs/pagination.js +0 -3
  89. package/dist/cjs/pagination.js.map +0 -1
  90. package/dist/cjs/problem-details.js +0 -3
  91. package/dist/cjs/problem-details.js.map +0 -1
  92. package/dist/cjs/query-string.js +0 -66
  93. package/dist/cjs/query-string.js.map +0 -1
  94. package/dist/cjs/query-string.spec.js +0 -52
  95. package/dist/cjs/query-string.spec.js.map +0 -1
  96. package/dist/cjs/status-codes.js +0 -71
  97. package/dist/cjs/status-codes.js.map +0 -1
  98. package/dist/cjs/timeout-error.js +0 -14
  99. package/dist/cjs/timeout-error.js.map +0 -1
  100. package/dist/esm/event-aggregator.d.ts +0 -11
  101. package/dist/esm/event-aggregator.js +0 -26
  102. package/dist/esm/event-aggregator.js.map +0 -1
  103. package/dist/esm/events.d.ts +0 -11
  104. package/dist/esm/events.js +0 -15
  105. package/dist/esm/events.js.map +0 -1
  106. package/dist/esm/helpers.d.ts +0 -5
  107. package/dist/esm/helpers.js +0 -10
  108. package/dist/esm/helpers.js.map +0 -1
  109. package/dist/esm/http-builder.d.ts +0 -60
  110. package/dist/esm/http-builder.js +0 -187
  111. package/dist/esm/http-builder.js.map +0 -1
  112. package/dist/esm/http-error.d.ts +0 -10
  113. package/dist/esm/http-error.js +0 -26
  114. package/dist/esm/http-error.js.map +0 -1
  115. package/dist/esm/http-response.d.ts +0 -18
  116. package/dist/esm/http-response.js +0 -46
  117. package/dist/esm/http-response.js.map +0 -1
  118. package/dist/esm/http.d.ts +0 -33
  119. package/dist/esm/http.js +0 -92
  120. package/dist/esm/http.js.map +0 -1
  121. package/dist/esm/http.spec.d.ts +0 -1
  122. package/dist/esm/http.spec.js +0 -67
  123. package/dist/esm/http.spec.js.map +0 -1
  124. package/dist/esm/index.d.ts +0 -15
  125. package/dist/esm/index.js +0 -11
  126. package/dist/esm/index.js.map +0 -1
  127. package/dist/esm/json/index.d.ts +0 -15
  128. package/dist/esm/json/index.js +0 -72
  129. package/dist/esm/json/index.js.map +0 -1
  130. package/dist/esm/jsonpatch/index.js +0 -13
  131. package/dist/esm/jsonpatch/index.js.map +0 -1
  132. package/dist/esm/mapping.d.ts +0 -9
  133. package/dist/esm/mapping.js +0 -32
  134. package/dist/esm/mapping.js.map +0 -1
  135. package/dist/esm/msgpack/index.d.ts +0 -8
  136. package/dist/esm/msgpack/index.js +0 -33
  137. package/dist/esm/msgpack/index.js.map +0 -1
  138. package/dist/esm/pagination.d.ts +0 -23
  139. package/dist/esm/pagination.js +0 -2
  140. package/dist/esm/pagination.js.map +0 -1
  141. package/dist/esm/problem-details.d.ts +0 -7
  142. package/dist/esm/problem-details.js +0 -2
  143. package/dist/esm/problem-details.js.map +0 -1
  144. package/dist/esm/query-string.d.ts +0 -6
  145. package/dist/esm/query-string.js +0 -62
  146. package/dist/esm/query-string.js.map +0 -1
  147. package/dist/esm/query-string.spec.d.ts +0 -1
  148. package/dist/esm/query-string.spec.js +0 -50
  149. package/dist/esm/query-string.spec.js.map +0 -1
  150. package/dist/esm/status-codes.d.ts +0 -67
  151. package/dist/esm/status-codes.js +0 -68
  152. package/dist/esm/status-codes.js.map +0 -1
  153. package/dist/esm/timeout-error.d.ts +0 -3
  154. package/dist/esm/timeout-error.js +0 -10
  155. package/dist/esm/timeout-error.js.map +0 -1
  156. package/karma.config.js +0 -29
  157. package/plugins/json/tsconfig.cjs.json +0 -8
  158. package/plugins/jsonpatch/tsconfig.cjs.json +0 -8
  159. package/plugins/msgpack/tsconfig.cjs.json +0 -8
  160. package/src/mapping.ts +0 -44
package/src/mapper.ts ADDED
@@ -0,0 +1,52 @@
1
+ type DeserializeFn<T> = (source: any, type: Type<T>) => T | null | undefined;
2
+ export type Type<T> = { new (): T };
3
+ export type Mapper<T> = (source: any) => T;
4
+ export type TypeOrMapper<T> = Type<T> | Mapper<T>;
5
+
6
+ export function getNullableMapper<T>(
7
+ deserialize: DeserializeFn<T>,
8
+ typeOrMap: Type<T> | Mapper<T> | undefined,
9
+ ): Mapper<T | null> {
10
+ if (!typeOrMap) {
11
+ return (x: any) => <T>x;
12
+ }
13
+
14
+ if (isZeroArgumentFunction(typeOrMap)) {
15
+ // It cannot be a factory function if it takes no arguments,
16
+ // so it must be a (zero argument) type (constructor)
17
+ return (x: any) => {
18
+ const bound = deserialize(x, typeOrMap);
19
+
20
+ // The server cannot produce the undefined result
21
+ if (bound === undefined) {
22
+ throw Error("The model factory created a undefined result");
23
+ }
24
+
25
+ return bound;
26
+ };
27
+ }
28
+
29
+ return typeOrMap;
30
+ }
31
+
32
+ export function getMapper<T>(
33
+ deserialize: DeserializeFn<T>,
34
+ typeOrMap: Type<T> | Mapper<T> | undefined,
35
+ ): Mapper<T> {
36
+ const nullableFactory = getNullableMapper(deserialize, typeOrMap);
37
+ return (x: any) => {
38
+ const result = nullableFactory(x);
39
+
40
+ if (result === null) {
41
+ throw Error("The model factory created a null result");
42
+ }
43
+
44
+ return result;
45
+ };
46
+ }
47
+
48
+ function isZeroArgumentFunction<T>(
49
+ typeCtor: Function,
50
+ ): typeCtor is { new (): T } {
51
+ return typeCtor.length === 0;
52
+ }
package/src/pagination.ts CHANGED
@@ -1,26 +1,26 @@
1
1
  export interface Page {
2
- number?: number;
3
- size: number;
2
+ number?: number;
3
+ size: number;
4
4
  }
5
5
 
6
6
  export interface PaginationResult<T> {
7
- meta: {
8
- pageCount: number;
9
- pageSize: number;
10
- totalItems: number;
11
- },
12
- data: T[];
7
+ meta: {
8
+ pageCount: number;
9
+ pageSize: number;
10
+ totalItems: number;
11
+ };
12
+ data: T[];
13
13
  }
14
14
 
15
15
  export interface InfinitePage {
16
- continuationToken?: string;
17
- size: number;
16
+ continuationToken?: string;
17
+ size: number;
18
18
  }
19
19
 
20
20
  export interface InfinitePaginationResult<T> {
21
- meta: {
22
- pageSize: number;
23
- continuationToken: string | null;
24
- },
25
- data: T[];
26
- }
21
+ meta: {
22
+ pageSize: number;
23
+ continuationToken: string | null;
24
+ };
25
+ data: T[];
26
+ }
@@ -1,7 +1,7 @@
1
1
  export type ProblemDetails = {
2
- detail?: string;
3
- instance?: string;
4
- status?: number;
5
- title?: string;
6
- type: string;
7
- } & Record<string, any>;
2
+ detail?: string;
3
+ instance?: string;
4
+ status?: number;
5
+ title?: string;
6
+ type: string;
7
+ } & Record<string, any>;
@@ -1,63 +1,79 @@
1
- import { DateTime } from 'luxon';
2
- import { QueryString } from './query-string';
3
- import { expect } from 'chai';
1
+ import { DateTime } from "luxon";
2
+ import { QueryString } from "./query-string";
3
+ import { expect } from "chai";
4
4
 
5
5
  describe("query-string", () => {
6
- it("should handle string", () => {
7
- const qs = QueryString.serialize({
8
- aString: "hello"
9
- });
10
-
11
- expect(qs).to.equal("?aString=hello");
6
+ it("should handle string", () => {
7
+ const qs = QueryString.serialize({
8
+ aString: "hello",
12
9
  });
13
10
 
14
- it("should handle string array", () => {
15
- const qs = QueryString.serialize({
16
- aString: ["hello","world"]
17
- });
11
+ expect(qs).to.equal("?aString=hello");
12
+ });
18
13
 
19
- expect(qs).to.equal("?aString[0]=hello&aString[1]=world");
14
+ it("should handle string array", () => {
15
+ const qs = QueryString.serialize({
16
+ aString: ["hello", "world"],
20
17
  });
21
18
 
22
- it("should handle object array", () => {
23
- const qs = QueryString.serialize({
24
- array: [{a: "hello"}, {b: "world"}]
25
- });
19
+ expect(qs).to.equal("?aString[0]=hello&aString[1]=world");
20
+ });
26
21
 
27
- expect(qs).to.equal("?array[0].a=hello&array[1].b=world");
22
+ it("should handle object array", () => {
23
+ const qs = QueryString.serialize({
24
+ array: [{ a: "hello" }, { b: "world" }],
28
25
  });
29
26
 
30
- it("should handle luxon DateTime in local timezone", () => {
31
- const datetime = DateTime.fromObject({year: 2014, month: 11, day: 12, hour: 21, minute: 6});
32
- const qs = QueryString.serialize({
33
- aDateTime: datetime
34
- });
27
+ expect(qs).to.equal("?array[0].a=hello&array[1].b=world");
28
+ });
35
29
 
36
- expect(qs).to.equal("?aDateTime=" + encodeURIComponent("2014-11-12T21:06:00.000+01:00"));
30
+ it("should handle luxon DateTime in local timezone", () => {
31
+ const datetime = DateTime.fromObject({
32
+ year: 2014,
33
+ month: 11,
34
+ day: 12,
35
+ hour: 21,
36
+ minute: 6,
37
+ });
38
+ const qs = QueryString.serialize({
39
+ aDateTime: datetime,
37
40
  });
38
41
 
39
- it("should handle luxon DateTime in utc", () => {
40
- const datetime = DateTime.fromObject({year: 2014, month: 11, day: 12, hour: 21, minute: 6}).toUTC();
41
- const qs = QueryString.serialize({
42
- aDateTime: datetime
43
- });
42
+ expect(qs).to.equal(
43
+ "?aDateTime=" + encodeURIComponent("2014-11-12T21:06:00.000+01:00"),
44
+ );
45
+ });
44
46
 
45
- expect(qs).to.equal("?aDateTime=" + encodeURIComponent("2014-11-12T20:06:00.000Z"));
47
+ it("should handle luxon DateTime in utc", () => {
48
+ const datetime = DateTime.fromObject({
49
+ year: 2014,
50
+ month: 11,
51
+ day: 12,
52
+ hour: 21,
53
+ minute: 6,
54
+ }).toUTC();
55
+ const qs = QueryString.serialize({
56
+ aDateTime: datetime,
46
57
  });
47
58
 
48
- it("should handle null", () => {
49
- const qs = QueryString.serialize({
50
- null: null
51
- });
59
+ expect(qs).to.equal(
60
+ "?aDateTime=" + encodeURIComponent("2014-11-12T20:06:00.000Z"),
61
+ );
62
+ });
52
63
 
53
- expect(qs).to.equal("?null");
64
+ it("should handle null", () => {
65
+ const qs = QueryString.serialize({
66
+ null: null,
54
67
  });
55
68
 
56
- it("should not include undefined", () => {
57
- const qs = QueryString.serialize({
58
- null: undefined
59
- });
69
+ expect(qs).to.equal("?null");
70
+ });
71
+
72
+ it("should not include undefined", () => {
73
+ const qs = QueryString.serialize({
74
+ null: undefined,
75
+ });
60
76
 
61
- expect(qs).to.equal("");
62
- })
63
- });
77
+ expect(qs).to.equal("");
78
+ });
79
+ });
@@ -1,70 +1,68 @@
1
1
  import { DateTime } from "luxon";
2
2
 
3
3
  export class QueryString {
4
- static serialize(params: any) {
5
- if (!params) {
6
- return "";
7
- }
8
- const serialized = this._serializeQueryString(params);
9
- if (!serialized.length) {
10
- return "";
11
- }
12
- return "?" + serialized;
4
+ static serialize(params: any) {
5
+ if (!params) {
6
+ return "";
13
7
  }
8
+ const serialized = this._serializeQueryString(params);
9
+ if (!serialized.length) {
10
+ return "";
11
+ }
12
+ return "?" + serialized;
13
+ }
14
14
 
15
- static append(url: string, params: any) {
16
- if (!params) {
17
- return url;
18
- }
19
- const any = url.indexOf("?") >= 0;
20
- const separator = any ? "&" : "?";
21
-
22
- return url + separator + this._serializeQueryString(params);
15
+ static append(url: string, params: any) {
16
+ if (!params) {
17
+ return url;
23
18
  }
19
+ const any = url.indexOf("?") >= 0;
20
+ const separator = any ? "&" : "?";
24
21
 
25
- static getParameter(name: string) {
26
- const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
27
- const match = regex.exec(window.location.href);
28
- if (match) {
29
- if (match[1].length > 0) {
30
- return decodeURIComponent(match[2]);
31
- }
32
- else {
33
- return null;
34
- }
35
- }
22
+ return url + separator + this._serializeQueryString(params);
23
+ }
24
+
25
+ static getParameter(name: string) {
26
+ const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
27
+ const match = regex.exec(window.location.href);
28
+ if (match) {
29
+ if (match[1].length > 0) {
30
+ return decodeURIComponent(match[2]);
31
+ } else {
32
+ return null;
33
+ }
36
34
  }
35
+ }
37
36
 
38
- private static _serializeQueryString(source: any, prefix?: string) {
39
- const parts: string[] = [];
40
- for (const propertyName in source) {
41
- if (source.hasOwnProperty(propertyName)) {
42
- const key = prefix != null
43
- ? prefix + (
44
- Array.isArray(source)
45
- ? "[" + encodeURIComponent(propertyName) + "]"
46
- : "." + encodeURIComponent(propertyName)
47
- )
48
- : encodeURIComponent(propertyName);
49
- const value = source[propertyName];
37
+ private static _serializeQueryString(source: any, prefix?: string) {
38
+ const parts: string[] = [];
39
+ for (const propertyName in source) {
40
+ if (source.hasOwnProperty(propertyName)) {
41
+ const key =
42
+ prefix != null
43
+ ? prefix +
44
+ (Array.isArray(source)
45
+ ? "[" + encodeURIComponent(propertyName) + "]"
46
+ : "." + encodeURIComponent(propertyName))
47
+ : encodeURIComponent(propertyName);
48
+ const value = source[propertyName];
50
49
 
51
- if (value instanceof DateTime) {
52
- parts.push(key + "=" + encodeURIComponent(value.toISO()));
53
- }
54
- else if (value === null) {
55
- parts.push(key);
56
- }
57
- else if (value !== undefined) {
58
- if (typeof value === "object") {
59
- parts.push(this._serializeQueryString(value, key));
60
- }
61
- else {
62
- parts.push(key + "=" + encodeURIComponent(value));
63
- }
64
- }
65
- }
50
+ if (value instanceof DateTime) {
51
+ if (value.isValid) {
52
+ parts.push(key + "=" + encodeURIComponent(value.toISO()!));
53
+ }
54
+ } else if (value === null) {
55
+ parts.push(key);
56
+ } else if (value !== undefined) {
57
+ if (typeof value === "object") {
58
+ parts.push(this._serializeQueryString(value, key));
59
+ } else {
60
+ parts.push(key + "=" + encodeURIComponent(value));
61
+ }
66
62
  }
67
-
68
- return parts.join("&");
63
+ }
69
64
  }
70
- }
65
+
66
+ return parts.join("&");
67
+ }
68
+ }
@@ -1,67 +1,67 @@
1
- export const statusCodes = Object.freeze({
2
- status100Continue: 100,
3
- status101SwitchingProtocols: 101,
4
- status102Processing: 102,
5
- status200OK: 200,
6
- status201Created: 201,
7
- status202Accepted: 202,
8
- status203NonAuthoritative: 203,
9
- status204NoContent: 204,
10
- status205ResetContent: 205,
11
- status206PartialContent: 206,
12
- status207MultiStatus: 207,
13
- status208AlreadyReported: 208,
14
- status226IMUsed: 226,
15
- status300MultipleChoices: 300,
16
- status301MovedPermanently: 301,
17
- status302Found: 302,
18
- status303SeeOther: 303,
19
- status304NotModified: 304,
20
- status305UseProxy: 305,
21
- status306SwitchProxy: 306,
22
- status307TemporaryRedirect: 307,
23
- status308PermanentRedirect: 308,
24
- status400BadRequest: 400,
25
- status401Unauthorized: 401,
26
- status402PaymentRequired: 402,
27
- status403Forbidden: 403,
28
- status404NotFound: 404,
29
- status405MethodNotAllowed: 405,
30
- status406NotAcceptable: 406,
31
- status407ProxyAuthenticationRequired: 407,
32
- status408RequestTimeout: 408,
33
- status409Conflict: 409,
34
- status410Gone: 410,
35
- status411LengthRequired: 411,
36
- status412PreconditionFailed: 412,
37
- status413RequestEntityTooLarge: 413,
38
- status413PayloadTooLarge: 413,
39
- status414RequestUriTooLong: 414,
40
- status414UriTooLong: 414,
41
- status415UnsupportedMediaType: 415,
42
- status416RequestedRangeNotSatisfiable: 416,
43
- status416RangeNotSatisfiable: 416,
44
- status417ExpectationFailed: 417,
45
- status418ImATeapot: 418,
46
- status419AuthenticationTimeout: 419,
47
- status421MisdirectedRequest: 421,
48
- status422UnprocessableEntity: 422,
49
- status423Locked: 423,
50
- status424FailedDependency: 424,
51
- status426UpgradeRequired: 426,
52
- status428PreconditionRequired: 428,
53
- status429TooManyRequests: 429,
54
- status431RequestHeaderFieldsTooLarge: 431,
55
- status451UnavailableForLegalReasons: 451,
56
- status500InternalServerError: 500,
57
- status501NotImplemented: 501,
58
- status502BadGateway: 502,
59
- status503ServiceUnavailable: 503,
60
- status504GatewayTimeout: 504,
61
- status505HttpVersionNotsupported: 505,
62
- status506VariantAlsoNegotiates: 506,
63
- status507InsufficientStorage: 507,
64
- status508LoopDetected: 508,
65
- status510NotExtended: 510,
66
- status511NetworkAuthenticationRequired: 511,
67
- });
1
+ export const statusCodes = Object.freeze({
2
+ status100Continue: 100,
3
+ status101SwitchingProtocols: 101,
4
+ status102Processing: 102,
5
+ status200OK: 200,
6
+ status201Created: 201,
7
+ status202Accepted: 202,
8
+ status203NonAuthoritative: 203,
9
+ status204NoContent: 204,
10
+ status205ResetContent: 205,
11
+ status206PartialContent: 206,
12
+ status207MultiStatus: 207,
13
+ status208AlreadyReported: 208,
14
+ status226IMUsed: 226,
15
+ status300MultipleChoices: 300,
16
+ status301MovedPermanently: 301,
17
+ status302Found: 302,
18
+ status303SeeOther: 303,
19
+ status304NotModified: 304,
20
+ status305UseProxy: 305,
21
+ status306SwitchProxy: 306,
22
+ status307TemporaryRedirect: 307,
23
+ status308PermanentRedirect: 308,
24
+ status400BadRequest: 400,
25
+ status401Unauthorized: 401,
26
+ status402PaymentRequired: 402,
27
+ status403Forbidden: 403,
28
+ status404NotFound: 404,
29
+ status405MethodNotAllowed: 405,
30
+ status406NotAcceptable: 406,
31
+ status407ProxyAuthenticationRequired: 407,
32
+ status408RequestTimeout: 408,
33
+ status409Conflict: 409,
34
+ status410Gone: 410,
35
+ status411LengthRequired: 411,
36
+ status412PreconditionFailed: 412,
37
+ status413RequestEntityTooLarge: 413,
38
+ status413PayloadTooLarge: 413,
39
+ status414RequestUriTooLong: 414,
40
+ status414UriTooLong: 414,
41
+ status415UnsupportedMediaType: 415,
42
+ status416RequestedRangeNotSatisfiable: 416,
43
+ status416RangeNotSatisfiable: 416,
44
+ status417ExpectationFailed: 417,
45
+ status418ImATeapot: 418,
46
+ status419AuthenticationTimeout: 419,
47
+ status421MisdirectedRequest: 421,
48
+ status422UnprocessableEntity: 422,
49
+ status423Locked: 423,
50
+ status424FailedDependency: 424,
51
+ status426UpgradeRequired: 426,
52
+ status428PreconditionRequired: 428,
53
+ status429TooManyRequests: 429,
54
+ status431RequestHeaderFieldsTooLarge: 431,
55
+ status451UnavailableForLegalReasons: 451,
56
+ status500InternalServerError: 500,
57
+ status501NotImplemented: 501,
58
+ status502BadGateway: 502,
59
+ status503ServiceUnavailable: 503,
60
+ status504GatewayTimeout: 504,
61
+ status505HttpVersionNotsupported: 505,
62
+ status506VariantAlsoNegotiates: 506,
63
+ status507InsufficientStorage: 507,
64
+ status508LoopDetected: 508,
65
+ status510NotExtended: 510,
66
+ status511NetworkAuthenticationRequired: 511,
67
+ });
@@ -1,10 +1,10 @@
1
1
  export class TimeoutError extends Error {
2
- constructor() {
3
- super("Timeout: The request was not successful");
4
- this.name = 'TimeoutError';
2
+ constructor() {
3
+ super("Timeout: The request was not successful");
4
+ this.name = "TimeoutError";
5
5
 
6
- // Set the prototype explicitly to allow for "... instanceof TimeoutError",
7
- // see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
8
- Object.setPrototypeOf(this, TimeoutError.prototype);
9
- }
6
+ // Set the prototype explicitly to allow for "... instanceof TimeoutError",
7
+ // see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
8
+ Object.setPrototypeOf(this, TimeoutError.prototype);
9
+ }
10
10
  }
package/tsconfig.cjs.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "extends": "./tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "module": "CommonJS",
5
+ "moduleResolution": "Node10",
5
6
  "outDir": "dist/cjs",
6
7
  "declaration": false
7
8
  }
package/tsconfig.json CHANGED
@@ -2,13 +2,12 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2018",
4
4
  "module": "ESNext",
5
- "moduleResolution": "Node",
5
+ "moduleResolution": "Bundler",
6
6
  "declaration": true,
7
7
  "sourceMap": true,
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
  },
@@ -0,0 +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,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;oBACZ,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBACnC;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;YAC9B,MAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;SACvD;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;YACf,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;SAC7B;QACD,IAAI,OAAO,YAAY,6BAAc,IAAI,MAAM,CAAC,QAAQ,EAAE;YACxD,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;SACrC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC;AAfD,wBAeC"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isTimeoutError = exports.isAbortError = exports.isHttpError = void 0;
4
- function isHttpError(error) {
5
- return error.name === "HttpError";
6
- }
7
- exports.isHttpError = isHttpError;
8
- function isAbortError(error) {
9
- return error.name === "AbortError";
10
- }
11
- exports.isAbortError = isAbortError;
12
- function isTimeoutError(error) {
13
- return error.name === "TimeoutError";
14
- }
15
- exports.isTimeoutError = isTimeoutError;
16
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;;AAGA,SAAgB,WAAW,CAAC,KAAY;IACpC,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC;AACtC,CAAC;AAFD,kCAEC;AAED,SAAgB,YAAY,CAAC,KAAY;IACrC,OAAO,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC;AACvC,CAAC;AAFD,oCAEC;AAED,SAAgB,cAAc,CAAC,KAAY;IACvC,OAAO,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC;AACzC,CAAC;AAFD,wCAEC"}