@utiliread/http 1.1.8 → 1.10.2
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/cjs/event-aggregator.js +89 -5
- package/dist/cjs/event-aggregator.js.map +1 -1
- package/dist/cjs/http-builder.js +43 -101
- package/dist/cjs/http-builder.js.map +1 -1
- package/dist/cjs/http-response.js +7 -0
- package/dist/cjs/http-response.js.map +1 -1
- package/dist/cjs/http.js +26 -2
- package/dist/cjs/http.js.map +1 -1
- package/dist/esm/event-aggregator.d.ts +7 -12
- package/dist/esm/event-aggregator.js +88 -4
- package/dist/esm/event-aggregator.js.map +1 -1
- package/dist/esm/http-builder.d.ts +14 -15
- package/dist/esm/http-builder.js +43 -101
- package/dist/esm/http-builder.js.map +1 -1
- package/dist/esm/http-response.d.ts +1 -0
- package/dist/esm/http-response.js +7 -0
- package/dist/esm/http-response.js.map +1 -1
- package/dist/esm/http.d.ts +7 -6
- package/dist/esm/http.js +26 -2
- package/dist/esm/http.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/event-aggregator.ts +32 -0
- package/src/http-builder.ts +30 -76
- package/src/http-response.ts +4 -0
- package/src/http.ts +34 -9
- package/src/index.ts +1 -1
- package/tsconfig.json +2 -1
- package/src/settings.ts +0 -7
|
@@ -1,10 +1,94 @@
|
|
|
1
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
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
function
|
|
39
|
+
exports.EventAggregator = void 0;
|
|
40
|
+
var EventAggregator = /** @class */ (function () {
|
|
41
|
+
function EventAggregator() {
|
|
42
|
+
this.callbacks = [];
|
|
6
43
|
}
|
|
7
|
-
|
|
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;
|
|
8
92
|
}());
|
|
9
|
-
exports.
|
|
93
|
+
exports.EventAggregator = EventAggregator;
|
|
10
94
|
//# sourceMappingURL=event-aggregator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-aggregator.js","sourceRoot":"","sources":["../../src/event-aggregator.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/cjs/http-builder.js
CHANGED
|
@@ -54,23 +54,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
54
54
|
exports.HttpBuilderOfT = exports.HttpBuilder = void 0;
|
|
55
55
|
var http_response_1 = require("./http-response");
|
|
56
56
|
var timeout_error_1 = require("./timeout-error");
|
|
57
|
+
var event_aggregator_1 = require("./event-aggregator");
|
|
57
58
|
var HttpBuilder = /** @class */ (function () {
|
|
58
|
-
function HttpBuilder(message, options) {
|
|
59
|
+
function HttpBuilder(message, options, /** @internal */ http) {
|
|
59
60
|
this.message = message;
|
|
60
61
|
this.options = options;
|
|
62
|
+
this.http = http;
|
|
61
63
|
this._ensureSuccessStatusCode = true;
|
|
62
|
-
this._onSend =
|
|
63
|
-
this._onSent =
|
|
64
|
-
if (options.onSent) {
|
|
65
|
-
this._onSent.push(options.onSent);
|
|
66
|
-
}
|
|
64
|
+
this._onSend = new event_aggregator_1.EventAggregator();
|
|
65
|
+
this._onSent = new event_aggregator_1.EventAggregator();
|
|
67
66
|
}
|
|
68
67
|
HttpBuilder.prototype.onSend = function (callback) {
|
|
69
|
-
this._onSend.
|
|
68
|
+
this._onSend.subscribe(callback);
|
|
70
69
|
return this;
|
|
71
70
|
};
|
|
72
71
|
HttpBuilder.prototype.onSent = function (callback) {
|
|
73
|
-
this._onSent.
|
|
72
|
+
this._onSent.subscribe(callback);
|
|
74
73
|
return this;
|
|
75
74
|
};
|
|
76
75
|
HttpBuilder.prototype.useHandler = function (handler) {
|
|
@@ -78,33 +77,23 @@ var HttpBuilder = /** @class */ (function () {
|
|
|
78
77
|
};
|
|
79
78
|
HttpBuilder.prototype.send = function (abortSignal) {
|
|
80
79
|
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
-
var
|
|
80
|
+
var init, outerController, fetchResponsePromise, fetchResponse, httpResponse;
|
|
82
81
|
var _this = this;
|
|
83
|
-
return __generator(this, function (
|
|
84
|
-
switch (
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
85
84
|
case 0:
|
|
86
|
-
if (!this.options.fetch) {
|
|
87
|
-
throw Error('fetch() is not properly configured');
|
|
88
|
-
}
|
|
89
85
|
if (this.message.contentType) {
|
|
90
86
|
this.message.headers.set('Content-Type', this.message.contentType);
|
|
91
87
|
}
|
|
92
88
|
// Resolve the final url and assign it to the message
|
|
93
89
|
// This makes the final url apper in onSend, onSent, and on Received handlers
|
|
94
90
|
this.message.url = this.getUrl();
|
|
95
|
-
|
|
96
|
-
_d.label = 1;
|
|
91
|
+
return [4 /*yield*/, this._onSend.publish(this.message)];
|
|
97
92
|
case 1:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return [4 /*yield*/, Promise.resolve(callback(this.message))];
|
|
93
|
+
_a.sent();
|
|
94
|
+
return [4 /*yield*/, this.http._onSend.publish(this.message)];
|
|
101
95
|
case 2:
|
|
102
|
-
|
|
103
|
-
_d.label = 3;
|
|
104
|
-
case 3:
|
|
105
|
-
_i++;
|
|
106
|
-
return [3 /*break*/, 1];
|
|
107
|
-
case 4:
|
|
96
|
+
_a.sent();
|
|
108
97
|
init = {
|
|
109
98
|
method: this.message.method,
|
|
110
99
|
body: this.message.content,
|
|
@@ -121,7 +110,7 @@ var HttpBuilder = /** @class */ (function () {
|
|
|
121
110
|
init.signal = outerController.signal;
|
|
122
111
|
}
|
|
123
112
|
fetchResponsePromise = this.options.fetch(this.message.url, init);
|
|
124
|
-
if (!this.options.timeout) return [3 /*break*/,
|
|
113
|
+
if (!this.options.timeout) return [3 /*break*/, 4];
|
|
125
114
|
return [4 /*yield*/, Promise.race([
|
|
126
115
|
fetchResponsePromise,
|
|
127
116
|
new Promise(function (_, reject) { return setTimeout(function () {
|
|
@@ -129,31 +118,25 @@ var HttpBuilder = /** @class */ (function () {
|
|
|
129
118
|
reject(new timeout_error_1.TimeoutError());
|
|
130
119
|
}, _this.options.timeout); })
|
|
131
120
|
])];
|
|
121
|
+
case 3:
|
|
122
|
+
fetchResponse = _a.sent();
|
|
123
|
+
return [3 /*break*/, 6];
|
|
124
|
+
case 4: return [4 /*yield*/, fetchResponsePromise];
|
|
132
125
|
case 5:
|
|
133
|
-
fetchResponse =
|
|
134
|
-
|
|
135
|
-
case 6:
|
|
136
|
-
case 7:
|
|
137
|
-
fetchResponse = _d.sent();
|
|
138
|
-
_d.label = 8;
|
|
139
|
-
case 8:
|
|
126
|
+
fetchResponse = _a.sent();
|
|
127
|
+
_a.label = 6;
|
|
128
|
+
case 6:
|
|
140
129
|
httpResponse = new http_response_1.HttpResponse(fetchResponse);
|
|
141
130
|
if (this._ensureSuccessStatusCode) {
|
|
142
131
|
httpResponse.ensureSuccessfulStatusCode();
|
|
143
132
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
_d.sent();
|
|
152
|
-
_d.label = 11;
|
|
153
|
-
case 11:
|
|
154
|
-
_b++;
|
|
155
|
-
return [3 /*break*/, 9];
|
|
156
|
-
case 12: return [2 /*return*/, httpResponse];
|
|
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];
|
|
157
140
|
}
|
|
158
141
|
});
|
|
159
142
|
});
|
|
@@ -177,30 +160,10 @@ var HttpBuilder = /** @class */ (function () {
|
|
|
177
160
|
this._ensureSuccessStatusCode = ensureSuccessStatusCode === false ? false : true;
|
|
178
161
|
return this;
|
|
179
162
|
};
|
|
180
|
-
HttpBuilder.prototype.use = function (settings) {
|
|
181
|
-
if (settings.fetch) {
|
|
182
|
-
this.useFetch(settings.fetch);
|
|
183
|
-
}
|
|
184
|
-
if (settings.corsMode) {
|
|
185
|
-
this.useCors(settings.corsMode);
|
|
186
|
-
}
|
|
187
|
-
if (settings.baseUrl) {
|
|
188
|
-
this.useBaseUrl(settings.baseUrl);
|
|
189
|
-
}
|
|
190
|
-
return this;
|
|
191
|
-
};
|
|
192
|
-
HttpBuilder.prototype.useFetch = function (fetch) {
|
|
193
|
-
this.options.fetch = fetch;
|
|
194
|
-
return this;
|
|
195
|
-
};
|
|
196
163
|
HttpBuilder.prototype.useCors = function (mode) {
|
|
197
164
|
this.message.mode = mode;
|
|
198
165
|
return this;
|
|
199
166
|
};
|
|
200
|
-
HttpBuilder.prototype.useBaseUrl = function (baseUrl) {
|
|
201
|
-
this.options.baseUrl = baseUrl;
|
|
202
|
-
return this;
|
|
203
|
-
};
|
|
204
167
|
HttpBuilder.prototype.useTimeout = function (timeout) {
|
|
205
168
|
this.options.timeout = timeout || undefined;
|
|
206
169
|
return this;
|
|
@@ -238,13 +201,10 @@ exports.HttpBuilder = HttpBuilder;
|
|
|
238
201
|
var HttpBuilderOfT = /** @class */ (function (_super) {
|
|
239
202
|
__extends(HttpBuilderOfT, _super);
|
|
240
203
|
function HttpBuilderOfT(inner, handler) {
|
|
241
|
-
var _this = _super.call(this, inner.message, inner.options) || this;
|
|
204
|
+
var _this = _super.call(this, inner.message, inner.options, inner.http) || this;
|
|
242
205
|
_this.inner = inner;
|
|
243
206
|
_this.handler = handler;
|
|
244
|
-
_this._onReceived =
|
|
245
|
-
if (inner.options.onReceived) {
|
|
246
|
-
_this._onReceived.push(inner.options.onReceived);
|
|
247
|
-
}
|
|
207
|
+
_this._onReceived = new event_aggregator_1.EventAggregator();
|
|
248
208
|
return _this;
|
|
249
209
|
}
|
|
250
210
|
HttpBuilderOfT.prototype.onSend = function (callback) {
|
|
@@ -259,30 +219,18 @@ var HttpBuilderOfT = /** @class */ (function (_super) {
|
|
|
259
219
|
this.inner.ensureSuccessStatusCode(ensureSuccessStatusCode);
|
|
260
220
|
return this;
|
|
261
221
|
};
|
|
262
|
-
HttpBuilderOfT.prototype.use = function (settings) {
|
|
263
|
-
this.inner.use(settings);
|
|
264
|
-
return this;
|
|
265
|
-
};
|
|
266
|
-
HttpBuilderOfT.prototype.useFetch = function (fetch) {
|
|
267
|
-
this.inner.useFetch(fetch);
|
|
268
|
-
return this;
|
|
269
|
-
};
|
|
270
222
|
HttpBuilderOfT.prototype.useCors = function (mode) {
|
|
271
223
|
this.inner.useCors(mode);
|
|
272
224
|
return this;
|
|
273
225
|
};
|
|
274
|
-
HttpBuilderOfT.prototype.useBaseUrl = function (baseUrl) {
|
|
275
|
-
this.inner.useBaseUrl(baseUrl);
|
|
276
|
-
return this;
|
|
277
|
-
};
|
|
278
226
|
HttpBuilderOfT.prototype.useTimeout = function (timeout) {
|
|
279
227
|
this.inner.useTimeout(timeout);
|
|
280
228
|
return this;
|
|
281
229
|
};
|
|
282
230
|
HttpBuilderOfT.prototype.allowEmptyResponse = function () {
|
|
283
231
|
var _this = this;
|
|
284
|
-
if (this._onReceived.
|
|
285
|
-
throw new Error("onReceived()
|
|
232
|
+
if (this._onReceived.any) {
|
|
233
|
+
throw new Error("onReceived() must be called after allowEmptyResponse() because the callback type changes");
|
|
286
234
|
}
|
|
287
235
|
return new HttpBuilderOfT(this.inner, function (response) {
|
|
288
236
|
if (response.status === 204) {
|
|
@@ -292,7 +240,7 @@ var HttpBuilderOfT = /** @class */ (function (_super) {
|
|
|
292
240
|
});
|
|
293
241
|
};
|
|
294
242
|
HttpBuilderOfT.prototype.onReceived = function (callback) {
|
|
295
|
-
this._onReceived.
|
|
243
|
+
this._onReceived.subscribe(callback);
|
|
296
244
|
return this;
|
|
297
245
|
};
|
|
298
246
|
HttpBuilderOfT.prototype.send = function (abortSignal) {
|
|
@@ -306,27 +254,21 @@ var HttpBuilderOfT = /** @class */ (function (_super) {
|
|
|
306
254
|
};
|
|
307
255
|
HttpBuilderOfT.prototype.handleReceive = function (response) {
|
|
308
256
|
return __awaiter(this, void 0, void 0, function () {
|
|
309
|
-
var request, value
|
|
310
|
-
return __generator(this, function (
|
|
311
|
-
switch (
|
|
257
|
+
var request, value;
|
|
258
|
+
return __generator(this, function (_a) {
|
|
259
|
+
switch (_a.label) {
|
|
312
260
|
case 0:
|
|
313
261
|
request = this.message;
|
|
314
262
|
return [4 /*yield*/, response.receive()];
|
|
315
263
|
case 1:
|
|
316
|
-
value =
|
|
317
|
-
|
|
318
|
-
_b.label = 2;
|
|
264
|
+
value = _a.sent();
|
|
265
|
+
return [4 /*yield*/, this._onReceived.publish(response, request, value)];
|
|
319
266
|
case 2:
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return [4 /*yield*/, Promise.resolve(callback(request, response, value))];
|
|
267
|
+
_a.sent();
|
|
268
|
+
return [4 /*yield*/, this.http._onReceived.publish(response, request, value)];
|
|
323
269
|
case 3:
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
case 4:
|
|
327
|
-
_i++;
|
|
328
|
-
return [3 /*break*/, 2];
|
|
329
|
-
case 5: return [2 /*return*/, value];
|
|
270
|
+
_a.sent();
|
|
271
|
+
return [2 /*return*/, value];
|
|
330
272
|
}
|
|
331
273
|
});
|
|
332
274
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-builder.js","sourceRoot":"","sources":["../../src/http-builder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAAgE;AAChE,iDAA+C;
|
|
1
|
+
{"version":3,"file":"http-builder.js","sourceRoot":"","sources":["../../src/http-builder.ts"],"names":[],"mappings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D;AAtEY,wCAAc;AA6F3B,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"}
|
|
@@ -35,6 +35,13 @@ var HttpResponse = /** @class */ (function () {
|
|
|
35
35
|
enumerable: false,
|
|
36
36
|
configurable: true
|
|
37
37
|
});
|
|
38
|
+
Object.defineProperty(HttpResponse.prototype, "headers", {
|
|
39
|
+
get: function () {
|
|
40
|
+
return this.rawResponse.headers;
|
|
41
|
+
},
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: true
|
|
44
|
+
});
|
|
38
45
|
Object.defineProperty(HttpResponse.prototype, "isInformational", {
|
|
39
46
|
get: function () {
|
|
40
47
|
return this.statusCode >= 100 && this.statusCode < 200;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-response.js","sourceRoot":"","sources":["../../src/http-response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AAEzC;
|
|
1
|
+
{"version":3,"file":"http-response.js","sourceRoot":"","sources":["../../src/http-response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AAEzC;IAiCI,sBAAmB,WAAqB;QAArB,gBAAW,GAAX,WAAW,CAAU;IACxC,CAAC;IAjCD,sBAAI,6BAAG;aAAP;YACI,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;QAChC,CAAC;;;OAAA;IAED,sBAAI,oCAAU;aAAd;YACI,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QACnC,CAAC;;;OAAA;IAED,sBAAI,iCAAO;aAAX;YACI,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QACpC,CAAC;;;OAAA;IAED,sBAAI,yCAAe;aAAnB;YACI,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IA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
exports.Http = void 0;
|
|
4
|
+
var event_aggregator_1 = require("./event-aggregator");
|
|
4
5
|
var http_builder_1 = require("./http-builder");
|
|
5
6
|
var query_string_1 = require("./query-string");
|
|
6
7
|
var Http = /** @class */ (function () {
|
|
7
8
|
function Http(options) {
|
|
9
|
+
/** @internal */
|
|
10
|
+
this._onSend = new event_aggregator_1.EventAggregator();
|
|
11
|
+
/** @internal */
|
|
12
|
+
this._onSent = new event_aggregator_1.EventAggregator();
|
|
13
|
+
/** @internal */
|
|
14
|
+
this._onReceived = new event_aggregator_1.EventAggregator();
|
|
8
15
|
this.options = Object.assign({}, Http.defaults, options); // Later sources' properties overwrite earlier ones.
|
|
9
16
|
}
|
|
10
17
|
Http.request = function (method, url, params) {
|
|
@@ -42,8 +49,16 @@ var Http = /** @class */ (function () {
|
|
|
42
49
|
url: url + query_string_1.QueryString.serialize(params),
|
|
43
50
|
headers: new Headers()
|
|
44
51
|
};
|
|
45
|
-
var
|
|
46
|
-
|
|
52
|
+
var fetch = this.options.fetch;
|
|
53
|
+
if (!fetch) {
|
|
54
|
+
throw Error('fetch() is not properly configured');
|
|
55
|
+
}
|
|
56
|
+
var builder = new http_builder_1.HttpBuilder(message, {
|
|
57
|
+
fetch: fetch,
|
|
58
|
+
timeout: this.options.timeout,
|
|
59
|
+
baseUrl: this.options.baseUrl,
|
|
60
|
+
}, this);
|
|
61
|
+
return builder;
|
|
47
62
|
};
|
|
48
63
|
Http.prototype.head = function (url, params) {
|
|
49
64
|
return this.request('HEAD', url, params);
|
|
@@ -63,6 +78,15 @@ var Http = /** @class */ (function () {
|
|
|
63
78
|
Http.prototype.delete = function (url, params) {
|
|
64
79
|
return this.request('DELETE', url, params);
|
|
65
80
|
};
|
|
81
|
+
Http.prototype.onSend = function (callback) {
|
|
82
|
+
return this._onSend.subscribe(callback);
|
|
83
|
+
};
|
|
84
|
+
Http.prototype.onSent = function (callback) {
|
|
85
|
+
return this._onSent.subscribe(callback);
|
|
86
|
+
};
|
|
87
|
+
Http.prototype.onReceived = function (callback) {
|
|
88
|
+
return this._onReceived.subscribe(callback);
|
|
89
|
+
};
|
|
66
90
|
Http.defaults = {
|
|
67
91
|
fetch: window.fetch ? window.fetch.bind(window) : undefined,
|
|
68
92
|
};
|
package/dist/cjs/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":";;;AAAA,+CAAkE;AAElE,+CAA6C;AAI7C;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/http.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AACrD,+CAAkE;AAElE,+CAA6C;AAI7C;IAaI,cAAY,OAA8B;QAP1C,gBAAgB;QAChB,YAAO,GAAG,IAAI,kCAAe,EAAa,CAAC;QAC3C,gBAAgB;QAChB,YAAO,GAAG,IAAI,kCAAe,EAA2B,CAAC;QACzD,gBAAgB;QAChB,gBAAW,GAAG,IAAI,kCAAe,EAAwC,CAAC;QAGtE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,oDAAoD;IAClH,CAAC;IAEM,YAAO,GAAd,UAAe,MAAkB,EAAE,GAAW,EAAE,MAAY;QACxD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;IAEM,SAAI,GAAX,UAAY,GAAW,EAAE,MAAY;QACjC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAEM,SAAI,GAAX,UAAY,GAAW,EAAE,MAAY;QACjC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAEM,QAAG,GAAV,U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CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC;IAzGM,aAAQ,GAAgB;QAC3B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;KAC9D,CAAA;IAwGL,WAAC;CAAA,AA3GD,IA2GC;AA3GY,oBAAI"}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
hook: "sent" | "received";
|
|
8
|
-
url: string;
|
|
9
|
-
reducer: Function;
|
|
10
|
-
params: any;
|
|
11
|
-
response: HttpResponse;
|
|
12
|
-
value?: any;
|
|
1
|
+
declare type Callback<P extends any[] = any[]> = (...params: P) => void | Promise<void>;
|
|
2
|
+
export declare class EventAggregator<P extends any[]> {
|
|
3
|
+
private callbacks;
|
|
4
|
+
get any(): boolean;
|
|
5
|
+
subscribe(callback: Callback<P>): Subscription;
|
|
6
|
+
publish(...params: P): Promise<void>;
|
|
13
7
|
}
|
|
14
8
|
export interface Subscription {
|
|
15
9
|
dispose(): void;
|
|
16
10
|
}
|
|
11
|
+
export {};
|
|
@@ -1,7 +1,91 @@
|
|
|
1
|
-
var
|
|
2
|
-
function
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
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;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
3
35
|
}
|
|
4
|
-
|
|
36
|
+
};
|
|
37
|
+
var EventAggregator = /** @class */ (function () {
|
|
38
|
+
function EventAggregator() {
|
|
39
|
+
this.callbacks = [];
|
|
40
|
+
}
|
|
41
|
+
Object.defineProperty(EventAggregator.prototype, "any", {
|
|
42
|
+
get: function () {
|
|
43
|
+
return this.callbacks.length > 0;
|
|
44
|
+
},
|
|
45
|
+
enumerable: false,
|
|
46
|
+
configurable: true
|
|
47
|
+
});
|
|
48
|
+
EventAggregator.prototype.subscribe = function (callback) {
|
|
49
|
+
var _this = this;
|
|
50
|
+
this.callbacks.push(callback);
|
|
51
|
+
return {
|
|
52
|
+
dispose: function () {
|
|
53
|
+
var index = _this.callbacks.indexOf(callback);
|
|
54
|
+
if (index >= 0) {
|
|
55
|
+
_this.callbacks.splice(index, 1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
EventAggregator.prototype.publish = function () {
|
|
61
|
+
var params = [];
|
|
62
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
63
|
+
params[_i] = arguments[_i];
|
|
64
|
+
}
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var callbacks, _a, callbacks_1, callback;
|
|
67
|
+
return __generator(this, function (_b) {
|
|
68
|
+
switch (_b.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
callbacks = this.callbacks.slice();
|
|
71
|
+
_a = 0, callbacks_1 = callbacks;
|
|
72
|
+
_b.label = 1;
|
|
73
|
+
case 1:
|
|
74
|
+
if (!(_a < callbacks_1.length)) return [3 /*break*/, 4];
|
|
75
|
+
callback = callbacks_1[_a];
|
|
76
|
+
return [4 /*yield*/, Promise.resolve(callback.apply(this, params))];
|
|
77
|
+
case 2:
|
|
78
|
+
_b.sent();
|
|
79
|
+
_b.label = 3;
|
|
80
|
+
case 3:
|
|
81
|
+
_a++;
|
|
82
|
+
return [3 /*break*/, 1];
|
|
83
|
+
case 4: return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return EventAggregator;
|
|
5
89
|
}());
|
|
6
|
-
export {
|
|
90
|
+
export { EventAggregator };
|
|
7
91
|
//# sourceMappingURL=event-aggregator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-aggregator.js","sourceRoot":"","sources":["../../src/event-aggregator.ts"],"names":[],"mappings":"
|
|
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"}
|