@utiliread/http 1.16.1 → 1.17.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 (142) hide show
  1. package/dist/index.d.ts +227 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +534 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +507 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/{esm/json.d.ts → json.d.ts} +15 -17
  8. package/dist/json.d.ts.map +1 -0
  9. package/dist/json.js +100 -0
  10. package/dist/json.js.map +1 -0
  11. package/dist/json.mjs +100 -0
  12. package/dist/json.mjs.map +1 -0
  13. package/dist/{esm/jsonpatch.d.ts → jsonpatch.d.ts} +10 -9
  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/{esm/msgpack.d.ts → msgpack.d.ts} +9 -10
  20. package/dist/msgpack.d.ts.map +1 -0
  21. package/dist/msgpack.js +62 -0
  22. package/dist/msgpack.js.map +1 -0
  23. package/dist/msgpack.mjs +62 -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/karma.config.js +27 -29
  28. package/msgpack.d.ts +1 -1
  29. package/package.json +28 -20
  30. package/plugins/json/package-lock.json +145 -0
  31. package/plugins/json/package.json +11 -0
  32. package/{src/json.ts → plugins/json/src/index.ts} +124 -117
  33. package/plugins/json/tsconfig.json +3 -0
  34. package/plugins/jsonpatch/package-lock.json +124 -0
  35. package/plugins/jsonpatch/package.json +13 -0
  36. package/{src/jsonpatch.ts → plugins/jsonpatch/src/index.ts} +31 -30
  37. package/plugins/jsonpatch/tsconfig.json +3 -0
  38. package/plugins/msgpack/package-lock.json +134 -0
  39. package/plugins/msgpack/package.json +12 -0
  40. package/{src/msgpack.ts → plugins/msgpack/src/index.ts} +61 -64
  41. package/plugins/msgpack/tsconfig.json +3 -0
  42. package/src/http-builder.ts +1 -1
  43. package/src/http.spec.ts +0 -27
  44. package/src/http.ts +132 -116
  45. package/src/index.ts +8 -6
  46. package/src/mapping.ts +1 -0
  47. package/tsconfig.json +8 -17
  48. package/tsconfig.test.json +10 -0
  49. package/dist/cjs/event-aggregator.js +0 -94
  50. package/dist/cjs/event-aggregator.js.map +0 -1
  51. package/dist/cjs/events.js +0 -23
  52. package/dist/cjs/events.js.map +0 -1
  53. package/dist/cjs/helpers.js +0 -16
  54. package/dist/cjs/helpers.js.map +0 -1
  55. package/dist/cjs/http-builder.js +0 -284
  56. package/dist/cjs/http-builder.js.map +0 -1
  57. package/dist/cjs/http-error.js +0 -53
  58. package/dist/cjs/http-error.js.map +0 -1
  59. package/dist/cjs/http-response.js +0 -102
  60. package/dist/cjs/http-response.js.map +0 -1
  61. package/dist/cjs/http.js +0 -97
  62. package/dist/cjs/http.js.map +0 -1
  63. package/dist/cjs/http.spec.js +0 -144
  64. package/dist/cjs/http.spec.js.map +0 -1
  65. package/dist/cjs/index.js +0 -37
  66. package/dist/cjs/index.js.map +0 -1
  67. package/dist/cjs/json.js +0 -71
  68. package/dist/cjs/json.js.map +0 -1
  69. package/dist/cjs/jsonpatch.js +0 -15
  70. package/dist/cjs/jsonpatch.js.map +0 -1
  71. package/dist/cjs/mapping.js +0 -37
  72. package/dist/cjs/mapping.js.map +0 -1
  73. package/dist/cjs/msgpack.js +0 -173
  74. package/dist/cjs/msgpack.js.map +0 -1
  75. package/dist/cjs/pagination.js +0 -3
  76. package/dist/cjs/pagination.js.map +0 -1
  77. package/dist/cjs/problem-details.js +0 -3
  78. package/dist/cjs/problem-details.js.map +0 -1
  79. package/dist/cjs/query-string.js +0 -69
  80. package/dist/cjs/query-string.js.map +0 -1
  81. package/dist/cjs/query-string.spec.js +0 -52
  82. package/dist/cjs/query-string.spec.js.map +0 -1
  83. package/dist/cjs/status-codes.js +0 -71
  84. package/dist/cjs/status-codes.js.map +0 -1
  85. package/dist/cjs/timeout-error.js +0 -32
  86. package/dist/cjs/timeout-error.js.map +0 -1
  87. package/dist/esm/event-aggregator.d.ts +0 -11
  88. package/dist/esm/event-aggregator.js +0 -91
  89. package/dist/esm/event-aggregator.js.map +0 -1
  90. package/dist/esm/events.d.ts +0 -11
  91. package/dist/esm/events.js +0 -19
  92. package/dist/esm/events.js.map +0 -1
  93. package/dist/esm/helpers.d.ts +0 -5
  94. package/dist/esm/helpers.js +0 -10
  95. package/dist/esm/helpers.js.map +0 -1
  96. package/dist/esm/http-builder.d.ts +0 -60
  97. package/dist/esm/http-builder.js +0 -281
  98. package/dist/esm/http-builder.js.map +0 -1
  99. package/dist/esm/http-error.d.ts +0 -10
  100. package/dist/esm/http-error.js +0 -50
  101. package/dist/esm/http-error.js.map +0 -1
  102. package/dist/esm/http-response.d.ts +0 -18
  103. package/dist/esm/http-response.js +0 -99
  104. package/dist/esm/http-response.js.map +0 -1
  105. package/dist/esm/http.d.ts +0 -32
  106. package/dist/esm/http.js +0 -94
  107. package/dist/esm/http.js.map +0 -1
  108. package/dist/esm/http.spec.d.ts +0 -1
  109. package/dist/esm/http.spec.js +0 -142
  110. package/dist/esm/http.spec.js.map +0 -1
  111. package/dist/esm/index.d.ts +0 -13
  112. package/dist/esm/index.js +0 -10
  113. package/dist/esm/index.js.map +0 -1
  114. package/dist/esm/json.js +0 -69
  115. package/dist/esm/json.js.map +0 -1
  116. package/dist/esm/jsonpatch.js +0 -13
  117. package/dist/esm/jsonpatch.js.map +0 -1
  118. package/dist/esm/mapping.d.ts +0 -8
  119. package/dist/esm/mapping.js +0 -32
  120. package/dist/esm/mapping.js.map +0 -1
  121. package/dist/esm/msgpack.js +0 -171
  122. package/dist/esm/msgpack.js.map +0 -1
  123. package/dist/esm/pagination.d.ts +0 -23
  124. package/dist/esm/pagination.js +0 -2
  125. package/dist/esm/pagination.js.map +0 -1
  126. package/dist/esm/problem-details.d.ts +0 -7
  127. package/dist/esm/problem-details.js +0 -2
  128. package/dist/esm/problem-details.js.map +0 -1
  129. package/dist/esm/query-string.d.ts +0 -6
  130. package/dist/esm/query-string.js +0 -66
  131. package/dist/esm/query-string.js.map +0 -1
  132. package/dist/esm/query-string.spec.d.ts +0 -1
  133. package/dist/esm/query-string.spec.js +0 -50
  134. package/dist/esm/query-string.spec.js.map +0 -1
  135. package/dist/esm/status-codes.d.ts +0 -67
  136. package/dist/esm/status-codes.js +0 -68
  137. package/dist/esm/status-codes.js.map +0 -1
  138. package/dist/esm/timeout-error.d.ts +0 -3
  139. package/dist/esm/timeout-error.js +0 -29
  140. package/dist/esm/timeout-error.js.map +0 -1
  141. package/index.d.ts +0 -1
  142. package/tsconfig.cjs.json +0 -9
package/src/index.ts CHANGED
@@ -1,18 +1,20 @@
1
1
  export { Http } from "./http";
2
- export {
2
+ export type {
3
3
  Page,
4
4
  PaginationResult,
5
5
  InfinitePage,
6
6
  InfinitePaginationResult,
7
7
  } from "./pagination";
8
- export { ProblemDetails } from "./problem-details";
8
+ export type { ProblemDetails } from "./problem-details";
9
9
  export { QueryString } from "./query-string";
10
10
  export { HttpResponse, HttpResponseOfT } from "./http-response";
11
- export { HttpBuilder, HttpBuilderOfT, Message } from "./http-builder";
11
+ export { HttpBuilder, HttpBuilderOfT } from "./http-builder";
12
+ export type { Message } from "./http-builder";
12
13
  export { HttpError } from "./http-error";
13
14
  export { TimeoutError } from "./timeout-error";
14
15
  export { events } from "./events";
15
16
  export * from "./helpers";
16
- export { Fetch } from "./http";
17
- export { Subscription } from "./event-aggregator";
18
- export { statusCodes } from "./status-codes";
17
+ export type { Fetch } from "./http";
18
+ export type { Subscription } from "./event-aggregator";
19
+ export { statusCodes } from "./status-codes";
20
+ export type { TypeOrMapper } from "./mapping";
package/src/mapping.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  type DeserializeFn<T> = (source: any, type: Type<T>) => T | null | undefined;
2
2
  export type Type<T> = { new(): T };
3
3
  export type Mapper<T> = ((source: any) => T);
4
+ export type TypeOrMapper<T> = Type<T> | Mapper<T>;
4
5
 
5
6
  export function getNullableMapper<T>(deserialize: DeserializeFn<T>, typeOrMap: Type<T> | Mapper<T> | undefined): Mapper<T | null> {
6
7
  if (!typeOrMap) {
package/tsconfig.json CHANGED
@@ -1,18 +1,9 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "es5",
4
- "module": "esnext",
5
- "moduleResolution": "node",
6
- "declaration": true,
7
- "sourceMap": true,
8
- "strict": true,
9
- "rootDir": "src",
10
- "outDir": "dist/esm",
11
- "lib": [ "es2017", "dom" ],
12
- "stripInternal": true,
13
- },
14
- "exclude": [
15
- "./*.d.ts",
16
- "dist"
17
- ]
18
- }
2
+ "compilerOptions": {
3
+ "target": "ES2018",
4
+ "strict": true,
5
+ "stripInternal": true,
6
+ "lib": ["ES2018", "DOM"]
7
+ },
8
+ "exclude": ["./dist/*", "./*.d.ts"]
9
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "ES2020",
5
+ "module": "commonjs",
6
+ "outDir": "dist/test"
7
+ },
8
+ "exclude": ["./dist/*.d.ts", "./dist/*", "./*.d.ts"],
9
+ "include": ["./src"]
10
+ }
@@ -1,94 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.EventAggregator = void 0;
40
- var EventAggregator = /** @class */ (function () {
41
- function EventAggregator() {
42
- this.callbacks = [];
43
- }
44
- Object.defineProperty(EventAggregator.prototype, "any", {
45
- get: function () {
46
- return this.callbacks.length > 0;
47
- },
48
- enumerable: false,
49
- configurable: true
50
- });
51
- EventAggregator.prototype.subscribe = function (callback) {
52
- var _this = this;
53
- this.callbacks.push(callback);
54
- return {
55
- dispose: function () {
56
- var index = _this.callbacks.indexOf(callback);
57
- if (index >= 0) {
58
- _this.callbacks.splice(index, 1);
59
- }
60
- }
61
- };
62
- };
63
- EventAggregator.prototype.publish = function () {
64
- var params = [];
65
- for (var _i = 0; _i < arguments.length; _i++) {
66
- params[_i] = arguments[_i];
67
- }
68
- return __awaiter(this, void 0, void 0, function () {
69
- var callbacks, _a, callbacks_1, callback;
70
- return __generator(this, function (_b) {
71
- switch (_b.label) {
72
- case 0:
73
- callbacks = this.callbacks.slice();
74
- _a = 0, callbacks_1 = callbacks;
75
- _b.label = 1;
76
- case 1:
77
- if (!(_a < callbacks_1.length)) return [3 /*break*/, 4];
78
- callback = callbacks_1[_a];
79
- return [4 /*yield*/, Promise.resolve(callback.apply(this, params))];
80
- case 2:
81
- _b.sent();
82
- _b.label = 3;
83
- case 3:
84
- _a++;
85
- return [3 /*break*/, 1];
86
- case 4: return [2 /*return*/];
87
- }
88
- });
89
- });
90
- };
91
- return EventAggregator;
92
- }());
93
- exports.EventAggregator = EventAggregator;
94
- //# sourceMappingURL=event-aggregator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-aggregator.js","sourceRoot":"","sources":["../../src/event-aggregator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;IAAA;QACY,cAAS,GAAe,EAAE,CAAC;IAwBvC,CAAC;IAtBG,sBAAI,gCAAG;aAAP;YACI,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,CAAC;;;OAAA;IAED,mCAAS,GAAT,UAAU,QAAqB;QAA/B,iBAUC;QATG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO;YACH,OAAO,EAAE;gBACL,IAAM,KAAK,GAAG,KAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC/C,IAAI,KAAK,IAAI,CAAC,EAAE;oBACZ,KAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBACnC;YACL,CAAC;SACJ,CAAA;IACL,CAAC;IAEK,iCAAO,GAAb;QAAc,gBAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,2BAAY;;;;;;;wBAChB,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;8BACT,EAAT,uBAAS;;;6BAAT,CAAA,uBAAS,CAAA;wBAArB,QAAQ;wBACf,qBAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,EAAA;;wBAAnD,SAAmD,CAAC;;;wBADjC,IAAS,CAAA;;;;;;KAGnC;IACL,sBAAC;AAAD,CAAC,AAzBD,IAyBC;AAzBY,0CAAe"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.events = void 0;
4
- var http_builder_1 = require("./http-builder");
5
- function events(action, configure) {
6
- return function () {
7
- var params = [];
8
- for (var _i = 0; _i < arguments.length; _i++) {
9
- params[_i] = arguments[_i];
10
- }
11
- var builder = action.apply(void 0, params);
12
- var events = configure.apply(void 0, params);
13
- if (events.sent) {
14
- builder.onSent(events.sent);
15
- }
16
- if (builder instanceof http_builder_1.HttpBuilderOfT && events.received) {
17
- builder.onReceived(events.received);
18
- }
19
- return builder;
20
- };
21
- }
22
- exports.events = events;
23
- //# sourceMappingURL=events.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":";;;AAAA,+CAAsE;AAuBtE,SAAgB,MAAM,CACpB,MAA2B,EAC3B,SAAkD;IAElD,OAAO;QAAU,gBAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,2BAAY;;QAC3B,IAAM,OAAO,GAAG,MAAM,eAAI,MAAM,CAAC,CAAC;QAClC,IAAM,MAAM,GAAG,SAAS,eAAI,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"}
@@ -1,284 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.HttpBuilderOfT = exports.HttpBuilder = void 0;
55
- var http_response_1 = require("./http-response");
56
- var timeout_error_1 = require("./timeout-error");
57
- var event_aggregator_1 = require("./event-aggregator");
58
- var HttpBuilder = /** @class */ (function () {
59
- function HttpBuilder(message, options, /** @internal */ http) {
60
- this.message = message;
61
- this.options = options;
62
- this.http = http;
63
- this._ensureSuccessStatusCode = true;
64
- this._onSend = new event_aggregator_1.EventAggregator();
65
- this._onSent = new event_aggregator_1.EventAggregator();
66
- }
67
- HttpBuilder.prototype.onSend = function (callback) {
68
- this._onSend.subscribe(callback);
69
- return this;
70
- };
71
- HttpBuilder.prototype.onSent = function (callback) {
72
- this._onSent.subscribe(callback);
73
- return this;
74
- };
75
- HttpBuilder.prototype.useHandler = function (handler) {
76
- return new HttpBuilderOfT(this, handler);
77
- };
78
- HttpBuilder.prototype.send = function (abortSignal) {
79
- return __awaiter(this, void 0, void 0, function () {
80
- var init, outerController, fetchResponsePromise, fetchResponse, httpResponse;
81
- var _this = this;
82
- return __generator(this, function (_a) {
83
- switch (_a.label) {
84
- case 0:
85
- if (this.message.contentType) {
86
- this.message.headers.set('Content-Type', this.message.contentType);
87
- }
88
- // Resolve the final url and assign it to the message
89
- // This makes the final url apper in onSend, onSent, and on Received handlers
90
- this.message.url = this.getUrl();
91
- return [4 /*yield*/, this._onSend.publish(this.message)];
92
- case 1:
93
- _a.sent();
94
- return [4 /*yield*/, this.http._onSend.publish(this.message)];
95
- case 2:
96
- _a.sent();
97
- init = {
98
- method: this.message.method,
99
- body: this.message.content,
100
- headers: this.message.headers,
101
- mode: this.message.mode
102
- };
103
- if (abortSignal || this.options.timeout) {
104
- outerController = new AbortController();
105
- if (abortSignal) {
106
- abortSignal.addEventListener("abort", function () {
107
- outerController.abort();
108
- });
109
- }
110
- init.signal = outerController.signal;
111
- }
112
- fetchResponsePromise = this.options.fetch(this.message.url, init);
113
- if (!this.options.timeout) return [3 /*break*/, 4];
114
- return [4 /*yield*/, Promise.race([
115
- fetchResponsePromise,
116
- new Promise(function (_, reject) { return setTimeout(function () {
117
- outerController.abort();
118
- reject(new timeout_error_1.TimeoutError());
119
- }, _this.options.timeout); })
120
- ])];
121
- case 3:
122
- fetchResponse = _a.sent();
123
- return [3 /*break*/, 6];
124
- case 4: return [4 /*yield*/, fetchResponsePromise];
125
- case 5:
126
- fetchResponse = _a.sent();
127
- _a.label = 6;
128
- case 6:
129
- httpResponse = new http_response_1.HttpResponse(fetchResponse);
130
- if (this._ensureSuccessStatusCode) {
131
- httpResponse.ensureSuccessfulStatusCode();
132
- }
133
- return [4 /*yield*/, this._onSent.publish(httpResponse, this.message)];
134
- case 7:
135
- _a.sent();
136
- return [4 /*yield*/, this.http._onSent.publish(httpResponse, this.message)];
137
- case 8:
138
- _a.sent();
139
- return [2 /*return*/, httpResponse];
140
- }
141
- });
142
- });
143
- };
144
- HttpBuilder.prototype.getUrl = function () {
145
- var baseUrl = this.options.baseUrl;
146
- if (!baseUrl) {
147
- return this.message.url;
148
- }
149
- if (baseUrl.endsWith('/')) {
150
- baseUrl = baseUrl.substr(0, baseUrl.length - 1);
151
- }
152
- if (this.message.url.startsWith('/')) {
153
- return baseUrl + this.message.url;
154
- }
155
- else {
156
- return baseUrl + '/' + this.message.url;
157
- }
158
- };
159
- HttpBuilder.prototype.ensureSuccessStatusCode = function (ensureSuccessStatusCode) {
160
- this._ensureSuccessStatusCode = ensureSuccessStatusCode === false ? false : true;
161
- return this;
162
- };
163
- HttpBuilder.prototype.useCors = function (mode) {
164
- this.message.mode = mode;
165
- return this;
166
- };
167
- HttpBuilder.prototype.useTimeout = function (timeout) {
168
- this.options.timeout = timeout || undefined;
169
- return this;
170
- };
171
- // Content Extensions
172
- HttpBuilder.prototype.with = function (content, contentType) {
173
- this.message.content = content;
174
- this.message.contentType = contentType;
175
- return this;
176
- };
177
- HttpBuilder.prototype.withForm = function (content) {
178
- this.message.content = content;
179
- this.message.contentType = undefined;
180
- return this;
181
- };
182
- // Modifier Extensions
183
- HttpBuilder.prototype.addHeader = function (name, value) {
184
- this.message.headers.append(name, value);
185
- return this;
186
- };
187
- // Expect Extensions
188
- HttpBuilder.prototype.expectString = function () {
189
- return this.useHandler(function (response) {
190
- return response.rawResponse.text();
191
- });
192
- };
193
- HttpBuilder.prototype.expectBinary = function () {
194
- return this.useHandler(function (response) {
195
- return response.rawResponse.arrayBuffer();
196
- });
197
- };
198
- return HttpBuilder;
199
- }());
200
- exports.HttpBuilder = HttpBuilder;
201
- var HttpBuilderOfT = /** @class */ (function (_super) {
202
- __extends(HttpBuilderOfT, _super);
203
- function HttpBuilderOfT(inner, handler) {
204
- var _this = _super.call(this, inner.message, inner.options, inner.http) || this;
205
- _this.inner = inner;
206
- _this.handler = handler;
207
- _this._onReceived = new event_aggregator_1.EventAggregator();
208
- return _this;
209
- }
210
- HttpBuilderOfT.prototype.onSend = function (callback) {
211
- this.inner.onSend(callback);
212
- return this;
213
- };
214
- HttpBuilderOfT.prototype.onSent = function (callback) {
215
- this.inner.onSent(callback);
216
- return this;
217
- };
218
- HttpBuilderOfT.prototype.ensureSuccessStatusCode = function (ensureSuccessStatusCode) {
219
- this.inner.ensureSuccessStatusCode(ensureSuccessStatusCode);
220
- return this;
221
- };
222
- HttpBuilderOfT.prototype.useCors = function (mode) {
223
- this.inner.useCors(mode);
224
- return this;
225
- };
226
- HttpBuilderOfT.prototype.useTimeout = function (timeout) {
227
- this.inner.useTimeout(timeout);
228
- return this;
229
- };
230
- HttpBuilderOfT.prototype.allowEmptyResponse = function () {
231
- var _this = this;
232
- if (this._onReceived.any) {
233
- throw new Error("onReceived() must be called after allowEmptyResponse() because the callback type changes");
234
- }
235
- return new HttpBuilderOfT(this.inner, function (response) {
236
- if (response.statusCode === 204) {
237
- return Promise.resolve(null);
238
- }
239
- return _this.handler(response);
240
- });
241
- };
242
- HttpBuilderOfT.prototype.onReceived = function (callback) {
243
- this._onReceived.subscribe(callback);
244
- return this;
245
- };
246
- HttpBuilderOfT.prototype.send = function (abortSignal) {
247
- var _this = this;
248
- var responsePromise = this.inner.send(abortSignal).then(function (x) { return new http_response_1.HttpResponseOfT(x.rawResponse, _this.handler); });
249
- return asSendPromise(responsePromise, function () { return responsePromise.then(function (response) { return _this.handleReceive(response); }); });
250
- };
251
- HttpBuilderOfT.prototype.transfer = function (abortSignal) {
252
- var _this = this;
253
- return this.send(abortSignal).then(function (response) { return _this.handleReceive(response); });
254
- };
255
- HttpBuilderOfT.prototype.handleReceive = function (response) {
256
- return __awaiter(this, void 0, void 0, function () {
257
- var request, value;
258
- return __generator(this, function (_a) {
259
- switch (_a.label) {
260
- case 0:
261
- request = this.message;
262
- return [4 /*yield*/, response.receive()];
263
- case 1:
264
- value = _a.sent();
265
- return [4 /*yield*/, this._onReceived.publish(response, request, value)];
266
- case 2:
267
- _a.sent();
268
- return [4 /*yield*/, this.http._onReceived.publish(response, request, value)];
269
- case 3:
270
- _a.sent();
271
- return [2 /*return*/, value];
272
- }
273
- });
274
- });
275
- };
276
- return HttpBuilderOfT;
277
- }(HttpBuilder));
278
- exports.HttpBuilderOfT = HttpBuilderOfT;
279
- function asSendPromise(responsePromise, thenReceive) {
280
- var sendPromise = responsePromise;
281
- sendPromise.thenReceive = thenReceive;
282
- return sendPromise;
283
- }
284
- //# sourceMappingURL=http-builder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"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O,KAAK,EAAC;;;;KAChB;IACL,qBAAC;AAAD,CAAC,AAtED,CAAuC,WAAW,GAsEjD;AAtEY,wCAAc;AA8F3B,SAAS,aAAa,CAAI,eAAsC,EAAE,WAA6B;IAC3F,IAAM,WAAW,GAAG,eAAiC,CAAC;IACtD,WAAW,CAAC,WAAW,GAAG,WAAW,CAAC;IACtC,OAAO,WAAW,CAAC;AACvB,CAAC"}
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.HttpError = void 0;
19
- var HttpError = /** @class */ (function (_super) {
20
- __extends(HttpError, _super);
21
- function HttpError(statusCode, response) {
22
- if (response === void 0) { response = undefined; }
23
- var _this = _super.call(this, "The response was not successful: ".concat(statusCode)) || this;
24
- _this.statusCode = statusCode;
25
- _this.response = response;
26
- _this.name = 'HttpError';
27
- // Set the prototype explicitly to allow for "... instanceof HttpError",
28
- // see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
29
- Object.setPrototypeOf(_this, HttpError.prototype);
30
- return _this;
31
- }
32
- Object.defineProperty(HttpError.prototype, "hasDetails", {
33
- get: function () {
34
- var _a, _b;
35
- var contentType = (_b = (_a = this.response) === null || _a === void 0 ? void 0 : _a.rawResponse) === null || _b === void 0 ? void 0 : _b.headers.get("Content-Type");
36
- return contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/problem+json");
37
- },
38
- enumerable: false,
39
- configurable: true
40
- });
41
- HttpError.prototype.details = function () {
42
- var _a, _b;
43
- var rawResponse = (_a = this.response) === null || _a === void 0 ? void 0 : _a.rawResponse;
44
- if (rawResponse && this.hasDetails) {
45
- (_b = this.detailsPromise) !== null && _b !== void 0 ? _b : (this.detailsPromise = rawResponse.json().then(function (details) { return details; }));
46
- return this.detailsPromise.then(function (details) { return details; });
47
- }
48
- return Promise.reject(new Error("There are no problem details in the response"));
49
- };
50
- return HttpError;
51
- }(Error));
52
- exports.HttpError = HttpError;
53
- //# sourceMappingURL=http-error.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-error.js","sourceRoot":"","sources":["../../src/http-error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAGA;IAA+B,6BAAK;IAQhC,mBAAmB,UAAkB,EAAU,QAA8C;QAA9C,yBAAA,EAAA,oBAA8C;QAA7F,YACI,kBAAM,2CAAoC,UAAU,CAAE,CAAC,SAM1D;QAPkB,gBAAU,GAAV,UAAU,CAAQ;QAAU,cAAQ,GAAR,QAAQ,CAAsC;QAEzF,KAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QAExB,wEAAwE;QACxE,mJAAmJ;QACnJ,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;;IACrD,CAAC;IAZD,sBAAI,iCAAU;aAAd;;YACI,IAAM,WAAW,GAAG,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,WAAW,0CAAE,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAC5E,OAAO,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,CAAC,0BAA0B,CAAC,CAAC;QAC7D,CAAC;;;OAAA;IAWD,2BAAO,GAAP;;QACI,IAAM,WAAW,GAAG,MAAA,IAAI,CAAC,QAAQ,0CAAE,W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