@utiliread/http 1.16.2 → 1.17.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/index.d.ts +227 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +534 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +507 -0
- package/dist/index.mjs.map +1 -0
- package/dist/{esm/json.d.ts → json.d.ts} +15 -17
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +100 -0
- package/dist/json.js.map +1 -0
- package/dist/json.mjs +100 -0
- package/dist/json.mjs.map +1 -0
- package/dist/{esm/jsonpatch.d.ts → jsonpatch.d.ts} +10 -9
- package/dist/jsonpatch.d.ts.map +1 -0
- package/dist/jsonpatch.js +18 -0
- package/dist/jsonpatch.js.map +1 -0
- package/dist/jsonpatch.mjs +18 -0
- package/dist/jsonpatch.mjs.map +1 -0
- package/dist/{esm/msgpack.d.ts → msgpack.d.ts} +9 -10
- package/dist/msgpack.d.ts.map +1 -0
- package/dist/msgpack.js +62 -0
- package/dist/msgpack.js.map +1 -0
- package/dist/msgpack.mjs +62 -0
- package/dist/msgpack.mjs.map +1 -0
- package/json.d.ts +1 -1
- package/jsonpatch.d.ts +1 -1
- package/karma.config.js +27 -29
- package/msgpack.d.ts +1 -1
- package/package.json +28 -20
- package/plugins/json/package-lock.json +145 -0
- package/plugins/json/package.json +11 -0
- package/{src/json.ts → plugins/json/src/index.ts} +124 -117
- package/plugins/json/tsconfig.json +3 -0
- package/plugins/jsonpatch/package-lock.json +124 -0
- package/plugins/jsonpatch/package.json +13 -0
- package/{src/jsonpatch.ts → plugins/jsonpatch/src/index.ts} +31 -30
- package/plugins/jsonpatch/tsconfig.json +3 -0
- package/plugins/msgpack/package-lock.json +134 -0
- package/plugins/msgpack/package.json +12 -0
- package/{src/msgpack.ts → plugins/msgpack/src/index.ts} +61 -64
- package/plugins/msgpack/tsconfig.json +3 -0
- package/src/http-builder.ts +1 -1
- package/src/http.spec.ts +0 -27
- package/src/http.ts +132 -116
- package/src/index.ts +8 -6
- package/src/mapping.ts +1 -0
- package/tsconfig.json +8 -17
- package/tsconfig.test.json +9 -0
- package/dist/cjs/event-aggregator.js +0 -94
- package/dist/cjs/event-aggregator.js.map +0 -1
- package/dist/cjs/events.js +0 -23
- package/dist/cjs/events.js.map +0 -1
- package/dist/cjs/helpers.js +0 -16
- package/dist/cjs/helpers.js.map +0 -1
- package/dist/cjs/http-builder.js +0 -284
- package/dist/cjs/http-builder.js.map +0 -1
- package/dist/cjs/http-error.js +0 -53
- package/dist/cjs/http-error.js.map +0 -1
- package/dist/cjs/http-response.js +0 -102
- package/dist/cjs/http-response.js.map +0 -1
- package/dist/cjs/http.js +0 -97
- package/dist/cjs/http.js.map +0 -1
- package/dist/cjs/http.spec.js +0 -144
- package/dist/cjs/http.spec.js.map +0 -1
- package/dist/cjs/index.js +0 -37
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json.js +0 -71
- package/dist/cjs/json.js.map +0 -1
- package/dist/cjs/jsonpatch.js +0 -15
- package/dist/cjs/jsonpatch.js.map +0 -1
- package/dist/cjs/mapping.js +0 -37
- package/dist/cjs/mapping.js.map +0 -1
- package/dist/cjs/msgpack.js +0 -173
- package/dist/cjs/msgpack.js.map +0 -1
- package/dist/cjs/pagination.js +0 -3
- package/dist/cjs/pagination.js.map +0 -1
- package/dist/cjs/problem-details.js +0 -3
- package/dist/cjs/problem-details.js.map +0 -1
- package/dist/cjs/query-string.js +0 -69
- package/dist/cjs/query-string.js.map +0 -1
- package/dist/cjs/query-string.spec.js +0 -52
- package/dist/cjs/query-string.spec.js.map +0 -1
- package/dist/cjs/status-codes.js +0 -71
- package/dist/cjs/status-codes.js.map +0 -1
- package/dist/cjs/timeout-error.js +0 -32
- package/dist/cjs/timeout-error.js.map +0 -1
- package/dist/esm/event-aggregator.d.ts +0 -11
- package/dist/esm/event-aggregator.js +0 -91
- package/dist/esm/event-aggregator.js.map +0 -1
- package/dist/esm/events.d.ts +0 -11
- package/dist/esm/events.js +0 -19
- package/dist/esm/events.js.map +0 -1
- package/dist/esm/helpers.d.ts +0 -5
- package/dist/esm/helpers.js +0 -10
- package/dist/esm/helpers.js.map +0 -1
- package/dist/esm/http-builder.d.ts +0 -60
- package/dist/esm/http-builder.js +0 -281
- package/dist/esm/http-builder.js.map +0 -1
- package/dist/esm/http-error.d.ts +0 -10
- package/dist/esm/http-error.js +0 -50
- package/dist/esm/http-error.js.map +0 -1
- package/dist/esm/http-response.d.ts +0 -18
- package/dist/esm/http-response.js +0 -99
- package/dist/esm/http-response.js.map +0 -1
- package/dist/esm/http.d.ts +0 -32
- package/dist/esm/http.js +0 -94
- package/dist/esm/http.js.map +0 -1
- package/dist/esm/http.spec.d.ts +0 -1
- package/dist/esm/http.spec.js +0 -142
- package/dist/esm/http.spec.js.map +0 -1
- package/dist/esm/index.d.ts +0 -13
- package/dist/esm/index.js +0 -10
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json.js +0 -69
- package/dist/esm/json.js.map +0 -1
- package/dist/esm/jsonpatch.js +0 -13
- package/dist/esm/jsonpatch.js.map +0 -1
- package/dist/esm/mapping.d.ts +0 -8
- package/dist/esm/mapping.js +0 -32
- package/dist/esm/mapping.js.map +0 -1
- package/dist/esm/msgpack.js +0 -171
- package/dist/esm/msgpack.js.map +0 -1
- package/dist/esm/pagination.d.ts +0 -23
- package/dist/esm/pagination.js +0 -2
- package/dist/esm/pagination.js.map +0 -1
- package/dist/esm/problem-details.d.ts +0 -7
- package/dist/esm/problem-details.js +0 -2
- package/dist/esm/problem-details.js.map +0 -1
- package/dist/esm/query-string.d.ts +0 -6
- package/dist/esm/query-string.js +0 -66
- package/dist/esm/query-string.js.map +0 -1
- package/dist/esm/query-string.spec.d.ts +0 -1
- package/dist/esm/query-string.spec.js +0 -50
- package/dist/esm/query-string.spec.js.map +0 -1
- package/dist/esm/status-codes.d.ts +0 -67
- package/dist/esm/status-codes.js +0 -68
- package/dist/esm/status-codes.js.map +0 -1
- package/dist/esm/timeout-error.d.ts +0 -3
- package/dist/esm/timeout-error.js +0 -29
- package/dist/esm/timeout-error.js.map +0 -1
- package/index.d.ts +0 -1
- package/tsconfig.cjs.json +0 -9
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Fetch } from './http';
|
|
2
|
-
import { HttpResponse, HttpResponseOfT } from './http-response';
|
|
3
|
-
import { Http } from '.';
|
|
4
|
-
export declare class HttpBuilder {
|
|
5
|
-
message: Message;
|
|
6
|
-
options: RequestOptions;
|
|
7
|
-
private _ensureSuccessStatusCode;
|
|
8
|
-
private _onSend;
|
|
9
|
-
private _onSent;
|
|
10
|
-
constructor(message: Message, options: RequestOptions, /** @internal */ http: Http);
|
|
11
|
-
onSend(callback: (request: Message) => void | Promise<void>): this;
|
|
12
|
-
onSent(callback: (response: HttpResponse, request: Message) => void | Promise<void>): this;
|
|
13
|
-
useHandler<T>(handler: (response: HttpResponse) => Promise<T>): HttpBuilderOfT<T>;
|
|
14
|
-
send(abortSignal?: AbortSignal): Promise<HttpResponse>;
|
|
15
|
-
getUrl(): string;
|
|
16
|
-
ensureSuccessStatusCode(ensureSuccessStatusCode?: boolean): this;
|
|
17
|
-
useCors(mode: RequestMode): this;
|
|
18
|
-
useTimeout(timeout: number | null): this;
|
|
19
|
-
with(content: any, contentType?: string): this;
|
|
20
|
-
withForm(content: FormData): this;
|
|
21
|
-
addHeader(name: string, value: string): this;
|
|
22
|
-
expectString(): HttpBuilderOfT<string>;
|
|
23
|
-
expectBinary(): HttpBuilderOfT<ArrayBuffer>;
|
|
24
|
-
}
|
|
25
|
-
export declare class HttpBuilderOfT<T> extends HttpBuilder {
|
|
26
|
-
private inner;
|
|
27
|
-
private handler;
|
|
28
|
-
private _onReceived;
|
|
29
|
-
constructor(inner: HttpBuilder, handler: (response: HttpResponse) => Promise<T>);
|
|
30
|
-
onSend(callback: (request: Message) => void | Promise<void>): this;
|
|
31
|
-
onSent(callback: (response: HttpResponse, request: Message) => void | Promise<void>): this;
|
|
32
|
-
ensureSuccessStatusCode(ensureSuccessStatusCode?: boolean): this;
|
|
33
|
-
useCors(mode: RequestMode): this;
|
|
34
|
-
useTimeout(timeout: number): this;
|
|
35
|
-
allowEmptyResponse(): HttpBuilderOfT<T | null>;
|
|
36
|
-
onReceived(callback: (response: HttpResponseOfT<T>, request: Message, value: T) => void | Promise<void>): this;
|
|
37
|
-
send(abortSignal?: AbortSignal): SendPromise<T>;
|
|
38
|
-
transfer(abortSignal?: AbortSignal): Promise<T>;
|
|
39
|
-
private handleReceive;
|
|
40
|
-
}
|
|
41
|
-
export declare type HttpMethod = "HEAD" | "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
|
|
42
|
-
export interface Message {
|
|
43
|
-
method: HttpMethod;
|
|
44
|
-
url: string;
|
|
45
|
-
headers: Headers;
|
|
46
|
-
content?: any;
|
|
47
|
-
contentType?: string;
|
|
48
|
-
mode?: RequestMode;
|
|
49
|
-
properties: {
|
|
50
|
-
[key: string]: any;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export interface RequestOptions {
|
|
54
|
-
fetch: Fetch;
|
|
55
|
-
timeout?: number;
|
|
56
|
-
baseUrl?: string;
|
|
57
|
-
}
|
|
58
|
-
export interface SendPromise<T> extends Promise<HttpResponseOfT<T>> {
|
|
59
|
-
thenReceive(): Promise<T>;
|
|
60
|
-
}
|
package/dist/esm/http-builder.js
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
26
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
27
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
28
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
|
-
function step(op) {
|
|
30
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
-
while (_) try {
|
|
32
|
-
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;
|
|
33
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
|
-
switch (op[0]) {
|
|
35
|
-
case 0: case 1: t = op; break;
|
|
36
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
37
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
38
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
39
|
-
default:
|
|
40
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
41
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
42
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
43
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
44
|
-
if (t[2]) _.ops.pop();
|
|
45
|
-
_.trys.pop(); continue;
|
|
46
|
-
}
|
|
47
|
-
op = body.call(thisArg, _);
|
|
48
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
49
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
import { HttpResponse, HttpResponseOfT } from './http-response';
|
|
53
|
-
import { TimeoutError } from './timeout-error';
|
|
54
|
-
import { EventAggregator } from './event-aggregator';
|
|
55
|
-
var HttpBuilder = /** @class */ (function () {
|
|
56
|
-
function HttpBuilder(message, options, /** @internal */ http) {
|
|
57
|
-
this.message = message;
|
|
58
|
-
this.options = options;
|
|
59
|
-
this.http = http;
|
|
60
|
-
this._ensureSuccessStatusCode = true;
|
|
61
|
-
this._onSend = new EventAggregator();
|
|
62
|
-
this._onSent = new EventAggregator();
|
|
63
|
-
}
|
|
64
|
-
HttpBuilder.prototype.onSend = function (callback) {
|
|
65
|
-
this._onSend.subscribe(callback);
|
|
66
|
-
return this;
|
|
67
|
-
};
|
|
68
|
-
HttpBuilder.prototype.onSent = function (callback) {
|
|
69
|
-
this._onSent.subscribe(callback);
|
|
70
|
-
return this;
|
|
71
|
-
};
|
|
72
|
-
HttpBuilder.prototype.useHandler = function (handler) {
|
|
73
|
-
return new HttpBuilderOfT(this, handler);
|
|
74
|
-
};
|
|
75
|
-
HttpBuilder.prototype.send = function (abortSignal) {
|
|
76
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
-
var init, outerController, fetchResponsePromise, fetchResponse, httpResponse;
|
|
78
|
-
var _this = this;
|
|
79
|
-
return __generator(this, function (_a) {
|
|
80
|
-
switch (_a.label) {
|
|
81
|
-
case 0:
|
|
82
|
-
if (this.message.contentType) {
|
|
83
|
-
this.message.headers.set('Content-Type', this.message.contentType);
|
|
84
|
-
}
|
|
85
|
-
// Resolve the final url and assign it to the message
|
|
86
|
-
// This makes the final url apper in onSend, onSent, and on Received handlers
|
|
87
|
-
this.message.url = this.getUrl();
|
|
88
|
-
return [4 /*yield*/, this._onSend.publish(this.message)];
|
|
89
|
-
case 1:
|
|
90
|
-
_a.sent();
|
|
91
|
-
return [4 /*yield*/, this.http._onSend.publish(this.message)];
|
|
92
|
-
case 2:
|
|
93
|
-
_a.sent();
|
|
94
|
-
init = {
|
|
95
|
-
method: this.message.method,
|
|
96
|
-
body: this.message.content,
|
|
97
|
-
headers: this.message.headers,
|
|
98
|
-
mode: this.message.mode
|
|
99
|
-
};
|
|
100
|
-
if (abortSignal || this.options.timeout) {
|
|
101
|
-
outerController = new AbortController();
|
|
102
|
-
if (abortSignal) {
|
|
103
|
-
abortSignal.addEventListener("abort", function () {
|
|
104
|
-
outerController.abort();
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
init.signal = outerController.signal;
|
|
108
|
-
}
|
|
109
|
-
fetchResponsePromise = this.options.fetch(this.message.url, init);
|
|
110
|
-
if (!this.options.timeout) return [3 /*break*/, 4];
|
|
111
|
-
return [4 /*yield*/, Promise.race([
|
|
112
|
-
fetchResponsePromise,
|
|
113
|
-
new Promise(function (_, reject) { return setTimeout(function () {
|
|
114
|
-
outerController.abort();
|
|
115
|
-
reject(new TimeoutError());
|
|
116
|
-
}, _this.options.timeout); })
|
|
117
|
-
])];
|
|
118
|
-
case 3:
|
|
119
|
-
fetchResponse = _a.sent();
|
|
120
|
-
return [3 /*break*/, 6];
|
|
121
|
-
case 4: return [4 /*yield*/, fetchResponsePromise];
|
|
122
|
-
case 5:
|
|
123
|
-
fetchResponse = _a.sent();
|
|
124
|
-
_a.label = 6;
|
|
125
|
-
case 6:
|
|
126
|
-
httpResponse = new HttpResponse(fetchResponse);
|
|
127
|
-
if (this._ensureSuccessStatusCode) {
|
|
128
|
-
httpResponse.ensureSuccessfulStatusCode();
|
|
129
|
-
}
|
|
130
|
-
return [4 /*yield*/, this._onSent.publish(httpResponse, this.message)];
|
|
131
|
-
case 7:
|
|
132
|
-
_a.sent();
|
|
133
|
-
return [4 /*yield*/, this.http._onSent.publish(httpResponse, this.message)];
|
|
134
|
-
case 8:
|
|
135
|
-
_a.sent();
|
|
136
|
-
return [2 /*return*/, httpResponse];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
HttpBuilder.prototype.getUrl = function () {
|
|
142
|
-
var baseUrl = this.options.baseUrl;
|
|
143
|
-
if (!baseUrl) {
|
|
144
|
-
return this.message.url;
|
|
145
|
-
}
|
|
146
|
-
if (baseUrl.endsWith('/')) {
|
|
147
|
-
baseUrl = baseUrl.substr(0, baseUrl.length - 1);
|
|
148
|
-
}
|
|
149
|
-
if (this.message.url.startsWith('/')) {
|
|
150
|
-
return baseUrl + this.message.url;
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
return baseUrl + '/' + this.message.url;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
HttpBuilder.prototype.ensureSuccessStatusCode = function (ensureSuccessStatusCode) {
|
|
157
|
-
this._ensureSuccessStatusCode = ensureSuccessStatusCode === false ? false : true;
|
|
158
|
-
return this;
|
|
159
|
-
};
|
|
160
|
-
HttpBuilder.prototype.useCors = function (mode) {
|
|
161
|
-
this.message.mode = mode;
|
|
162
|
-
return this;
|
|
163
|
-
};
|
|
164
|
-
HttpBuilder.prototype.useTimeout = function (timeout) {
|
|
165
|
-
this.options.timeout = timeout || undefined;
|
|
166
|
-
return this;
|
|
167
|
-
};
|
|
168
|
-
// Content Extensions
|
|
169
|
-
HttpBuilder.prototype.with = function (content, contentType) {
|
|
170
|
-
this.message.content = content;
|
|
171
|
-
this.message.contentType = contentType;
|
|
172
|
-
return this;
|
|
173
|
-
};
|
|
174
|
-
HttpBuilder.prototype.withForm = function (content) {
|
|
175
|
-
this.message.content = content;
|
|
176
|
-
this.message.contentType = undefined;
|
|
177
|
-
return this;
|
|
178
|
-
};
|
|
179
|
-
// Modifier Extensions
|
|
180
|
-
HttpBuilder.prototype.addHeader = function (name, value) {
|
|
181
|
-
this.message.headers.append(name, value);
|
|
182
|
-
return this;
|
|
183
|
-
};
|
|
184
|
-
// Expect Extensions
|
|
185
|
-
HttpBuilder.prototype.expectString = function () {
|
|
186
|
-
return this.useHandler(function (response) {
|
|
187
|
-
return response.rawResponse.text();
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
HttpBuilder.prototype.expectBinary = function () {
|
|
191
|
-
return this.useHandler(function (response) {
|
|
192
|
-
return response.rawResponse.arrayBuffer();
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
return HttpBuilder;
|
|
196
|
-
}());
|
|
197
|
-
export { HttpBuilder };
|
|
198
|
-
var HttpBuilderOfT = /** @class */ (function (_super) {
|
|
199
|
-
__extends(HttpBuilderOfT, _super);
|
|
200
|
-
function HttpBuilderOfT(inner, handler) {
|
|
201
|
-
var _this = _super.call(this, inner.message, inner.options, inner.http) || this;
|
|
202
|
-
_this.inner = inner;
|
|
203
|
-
_this.handler = handler;
|
|
204
|
-
_this._onReceived = new EventAggregator();
|
|
205
|
-
return _this;
|
|
206
|
-
}
|
|
207
|
-
HttpBuilderOfT.prototype.onSend = function (callback) {
|
|
208
|
-
this.inner.onSend(callback);
|
|
209
|
-
return this;
|
|
210
|
-
};
|
|
211
|
-
HttpBuilderOfT.prototype.onSent = function (callback) {
|
|
212
|
-
this.inner.onSent(callback);
|
|
213
|
-
return this;
|
|
214
|
-
};
|
|
215
|
-
HttpBuilderOfT.prototype.ensureSuccessStatusCode = function (ensureSuccessStatusCode) {
|
|
216
|
-
this.inner.ensureSuccessStatusCode(ensureSuccessStatusCode);
|
|
217
|
-
return this;
|
|
218
|
-
};
|
|
219
|
-
HttpBuilderOfT.prototype.useCors = function (mode) {
|
|
220
|
-
this.inner.useCors(mode);
|
|
221
|
-
return this;
|
|
222
|
-
};
|
|
223
|
-
HttpBuilderOfT.prototype.useTimeout = function (timeout) {
|
|
224
|
-
this.inner.useTimeout(timeout);
|
|
225
|
-
return this;
|
|
226
|
-
};
|
|
227
|
-
HttpBuilderOfT.prototype.allowEmptyResponse = function () {
|
|
228
|
-
var _this = this;
|
|
229
|
-
if (this._onReceived.any) {
|
|
230
|
-
throw new Error("onReceived() must be called after allowEmptyResponse() because the callback type changes");
|
|
231
|
-
}
|
|
232
|
-
return new HttpBuilderOfT(this.inner, function (response) {
|
|
233
|
-
if (response.statusCode === 204) {
|
|
234
|
-
return Promise.resolve(null);
|
|
235
|
-
}
|
|
236
|
-
return _this.handler(response);
|
|
237
|
-
});
|
|
238
|
-
};
|
|
239
|
-
HttpBuilderOfT.prototype.onReceived = function (callback) {
|
|
240
|
-
this._onReceived.subscribe(callback);
|
|
241
|
-
return this;
|
|
242
|
-
};
|
|
243
|
-
HttpBuilderOfT.prototype.send = function (abortSignal) {
|
|
244
|
-
var _this = this;
|
|
245
|
-
var responsePromise = this.inner.send(abortSignal).then(function (x) { return new HttpResponseOfT(x.rawResponse, _this.handler); });
|
|
246
|
-
return asSendPromise(responsePromise, function () { return responsePromise.then(function (response) { return _this.handleReceive(response); }); });
|
|
247
|
-
};
|
|
248
|
-
HttpBuilderOfT.prototype.transfer = function (abortSignal) {
|
|
249
|
-
var _this = this;
|
|
250
|
-
return this.send(abortSignal).then(function (response) { return _this.handleReceive(response); });
|
|
251
|
-
};
|
|
252
|
-
HttpBuilderOfT.prototype.handleReceive = function (response) {
|
|
253
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
254
|
-
var request, value;
|
|
255
|
-
return __generator(this, function (_a) {
|
|
256
|
-
switch (_a.label) {
|
|
257
|
-
case 0:
|
|
258
|
-
request = this.message;
|
|
259
|
-
return [4 /*yield*/, response.receive()];
|
|
260
|
-
case 1:
|
|
261
|
-
value = _a.sent();
|
|
262
|
-
return [4 /*yield*/, this._onReceived.publish(response, request, value)];
|
|
263
|
-
case 2:
|
|
264
|
-
_a.sent();
|
|
265
|
-
return [4 /*yield*/, this.http._onReceived.publish(response, request, value)];
|
|
266
|
-
case 3:
|
|
267
|
-
_a.sent();
|
|
268
|
-
return [2 /*return*/, value];
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
};
|
|
273
|
-
return HttpBuilderOfT;
|
|
274
|
-
}(HttpBuilder));
|
|
275
|
-
export { HttpBuilderOfT };
|
|
276
|
-
function asSendPromise(responsePromise, thenReceive) {
|
|
277
|
-
var sendPromise = responsePromise;
|
|
278
|
-
sendPromise.thenReceive = thenReceive;
|
|
279
|
-
return sendPromise;
|
|
280
|
-
}
|
|
281
|
-
//# sourceMappingURL=http-builder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-builder.js","sourceRoot":"","sources":["../../src/http-builder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD;IAKI,qBAAmB,OAAgB,EAAS,OAAuB,EAAE,gBAAgB,CAAQ,IAAU;QAApF,YAAO,GAAP,OAAO,CAAS;QAAS,YAAO,GAAP,OAAO,CAAgB;QAA0B,SAAI,GAAJ,IAA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import { ProblemDetails } from './problem-details';
|
|
3
|
-
export declare class HttpError extends Error {
|
|
4
|
-
statusCode: number;
|
|
5
|
-
private response;
|
|
6
|
-
private detailsPromise?;
|
|
7
|
-
get hasDetails(): boolean | undefined;
|
|
8
|
-
constructor(statusCode: number, response?: HttpResponse | undefined);
|
|
9
|
-
details<TDetails = ProblemDetails>(): Promise<TDetails>;
|
|
10
|
-
}
|
package/dist/esm/http-error.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var HttpError = /** @class */ (function (_super) {
|
|
17
|
-
__extends(HttpError, _super);
|
|
18
|
-
function HttpError(statusCode, response) {
|
|
19
|
-
if (response === void 0) { response = undefined; }
|
|
20
|
-
var _this = _super.call(this, "The response was not successful: ".concat(statusCode)) || this;
|
|
21
|
-
_this.statusCode = statusCode;
|
|
22
|
-
_this.response = response;
|
|
23
|
-
_this.name = 'HttpError';
|
|
24
|
-
// Set the prototype explicitly to allow for "... instanceof HttpError",
|
|
25
|
-
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
26
|
-
Object.setPrototypeOf(_this, HttpError.prototype);
|
|
27
|
-
return _this;
|
|
28
|
-
}
|
|
29
|
-
Object.defineProperty(HttpError.prototype, "hasDetails", {
|
|
30
|
-
get: function () {
|
|
31
|
-
var _a, _b;
|
|
32
|
-
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");
|
|
33
|
-
return contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/problem+json");
|
|
34
|
-
},
|
|
35
|
-
enumerable: false,
|
|
36
|
-
configurable: true
|
|
37
|
-
});
|
|
38
|
-
HttpError.prototype.details = function () {
|
|
39
|
-
var _a, _b;
|
|
40
|
-
var rawResponse = (_a = this.response) === null || _a === void 0 ? void 0 : _a.rawResponse;
|
|
41
|
-
if (rawResponse && this.hasDetails) {
|
|
42
|
-
(_b = this.detailsPromise) !== null && _b !== void 0 ? _b : (this.detailsPromise = rawResponse.json().then(function (details) { return details; }));
|
|
43
|
-
return this.detailsPromise.then(function (details) { return details; });
|
|
44
|
-
}
|
|
45
|
-
return Promise.reject(new Error("There are no problem details in the response"));
|
|
46
|
-
};
|
|
47
|
-
return HttpError;
|
|
48
|
-
}(Error));
|
|
49
|
-
export { HttpError };
|
|
50
|
-
//# 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,WAAW,CAAC;QAE/C,IAAI,WAAW,IAAI,IAAI,CAAC,UAAU,EAAE;YAChC,MAAA,IAAI,CAAC,cAAc,oCAAnB,IAAI,CAAC,cAAc,GAAK,WAAW,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,UAAA,OAAO,IAAI,OAAgB,OAAO,EAAvB,CAAuB,CAAC,EAAC;YACpF,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,UAAA,OAAO,IAAI,OAAU,OAAO,EAAjB,CAAiB,CAAC,CAAC;SACjE;QAED,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC,CAAC;IACrF,CAAC;IACL,gBAAC;AAAD,CAAC,AA3BD,CAA+B,KAAK,GA2BnC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare class HttpResponse {
|
|
2
|
-
rawResponse: Response;
|
|
3
|
-
get url(): string;
|
|
4
|
-
get statusCode(): number;
|
|
5
|
-
get headers(): Headers;
|
|
6
|
-
get isInformational(): boolean;
|
|
7
|
-
get isSuccessful(): boolean;
|
|
8
|
-
get isRedirection(): boolean;
|
|
9
|
-
get isClientError(): boolean;
|
|
10
|
-
get isServerError(): boolean;
|
|
11
|
-
constructor(rawResponse: Response);
|
|
12
|
-
ensureSuccessfulStatusCode(): this;
|
|
13
|
-
}
|
|
14
|
-
export declare class HttpResponseOfT<T> extends HttpResponse {
|
|
15
|
-
private handler;
|
|
16
|
-
constructor(rawResponse: Response, handler: (response: HttpResponse) => Promise<T>);
|
|
17
|
-
receive(): Promise<T>;
|
|
18
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
import { HttpError } from "./http-error";
|
|
17
|
-
var HttpResponse = /** @class */ (function () {
|
|
18
|
-
function HttpResponse(rawResponse) {
|
|
19
|
-
this.rawResponse = rawResponse;
|
|
20
|
-
}
|
|
21
|
-
Object.defineProperty(HttpResponse.prototype, "url", {
|
|
22
|
-
get: function () {
|
|
23
|
-
return this.rawResponse.url;
|
|
24
|
-
},
|
|
25
|
-
enumerable: false,
|
|
26
|
-
configurable: true
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(HttpResponse.prototype, "statusCode", {
|
|
29
|
-
get: function () {
|
|
30
|
-
return this.rawResponse.status;
|
|
31
|
-
},
|
|
32
|
-
enumerable: false,
|
|
33
|
-
configurable: true
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(HttpResponse.prototype, "headers", {
|
|
36
|
-
get: function () {
|
|
37
|
-
return this.rawResponse.headers;
|
|
38
|
-
},
|
|
39
|
-
enumerable: false,
|
|
40
|
-
configurable: true
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(HttpResponse.prototype, "isInformational", {
|
|
43
|
-
get: function () {
|
|
44
|
-
return this.statusCode >= 100 && this.statusCode < 200;
|
|
45
|
-
},
|
|
46
|
-
enumerable: false,
|
|
47
|
-
configurable: true
|
|
48
|
-
});
|
|
49
|
-
Object.defineProperty(HttpResponse.prototype, "isSuccessful", {
|
|
50
|
-
get: function () {
|
|
51
|
-
return this.statusCode >= 200 && this.statusCode < 300;
|
|
52
|
-
},
|
|
53
|
-
enumerable: false,
|
|
54
|
-
configurable: true
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(HttpResponse.prototype, "isRedirection", {
|
|
57
|
-
get: function () {
|
|
58
|
-
return this.statusCode >= 300 && this.statusCode < 400;
|
|
59
|
-
},
|
|
60
|
-
enumerable: false,
|
|
61
|
-
configurable: true
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(HttpResponse.prototype, "isClientError", {
|
|
64
|
-
get: function () {
|
|
65
|
-
return this.statusCode >= 400 && this.statusCode < 500;
|
|
66
|
-
},
|
|
67
|
-
enumerable: false,
|
|
68
|
-
configurable: true
|
|
69
|
-
});
|
|
70
|
-
Object.defineProperty(HttpResponse.prototype, "isServerError", {
|
|
71
|
-
get: function () {
|
|
72
|
-
return this.statusCode >= 500 && this.statusCode < 600;
|
|
73
|
-
},
|
|
74
|
-
enumerable: false,
|
|
75
|
-
configurable: true
|
|
76
|
-
});
|
|
77
|
-
HttpResponse.prototype.ensureSuccessfulStatusCode = function () {
|
|
78
|
-
if (!this.isSuccessful) {
|
|
79
|
-
throw new HttpError(this.statusCode, this);
|
|
80
|
-
}
|
|
81
|
-
return this;
|
|
82
|
-
};
|
|
83
|
-
return HttpResponse;
|
|
84
|
-
}());
|
|
85
|
-
export { HttpResponse };
|
|
86
|
-
var HttpResponseOfT = /** @class */ (function (_super) {
|
|
87
|
-
__extends(HttpResponseOfT, _super);
|
|
88
|
-
function HttpResponseOfT(rawResponse, handler) {
|
|
89
|
-
var _this = _super.call(this, rawResponse) || this;
|
|
90
|
-
_this.handler = handler;
|
|
91
|
-
return _this;
|
|
92
|
-
}
|
|
93
|
-
HttpResponseOfT.prototype.receive = function () {
|
|
94
|
-
return this.handler(this);
|
|
95
|
-
};
|
|
96
|
-
return HttpResponseOfT;
|
|
97
|
-
}(HttpResponse));
|
|
98
|
-
export { HttpResponseOfT };
|
|
99
|
-
//# sourceMappingURL=http-response.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-response.js","sourceRoot":"","sources":["../../src/http-response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;IAiCE,sBAAmB,WAAqB;QAArB,gBAAW,GAAX,WAAW,CAAU;IAAG,CAAC;IAhC5C,sBAAI,6BAAG;aAAP;YACE,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;QAC9B,CAAC;;;OAAA;IAED,sBAAI,oCAAU;aAAd;YACE,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QACjC,CAAC;;;OAAA;IAED,sBAAI,iCAAO;aAAX;YACE,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QAClC,CAAC;;;OAAA;IAED,sBAAI,yCAAe;aAAnB;YACE,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACzD,CAAC;;;OAAA;IAED,sBAAI,sCAAY;aAAhB;YACE,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACzD,CAAC;;;OAAA;IAED,sBAAI,uCAAa;aAAjB;YACE,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACzD,CAAC;;;OAAA;IAED,sBAAI,uCAAa;aAAjB;YACE,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACzD,CAAC;;;OAAA;IAED,sBAAI,uCAAa;aAAjB;YACE,OAAO,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QACzD,CAAC;;;OAAA;IAIM,iDAA0B,GAAjC;QACE,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;SAC5C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IACH,mBAAC;AAAD,CAAC,AA1CD,IA0CC;;AAED;IAAwC,mCAAY;IAClD,yBACE,WAAqB,EACb,OAA+C;QAFzD,YAIE,kBAAM,WAAW,CAAC,SACnB;QAHS,aAAO,GAAP,OAAO,CAAwC;;IAGzD,CAAC;IAED,iCAAO,GAAP;QACE,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IACH,sBAAC;AAAD,CAAC,AAXD,CAAwC,YAAY,GAWnD"}
|
package/dist/esm/http.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { HttpBuilder, HttpMethod, Message } from './http-builder';
|
|
2
|
-
import { HttpResponse, HttpResponseOfT } from './http-response';
|
|
3
|
-
export declare type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
4
|
-
export declare class Http {
|
|
5
|
-
static defaults: HttpOptions;
|
|
6
|
-
private static instance?;
|
|
7
|
-
options: HttpOptions;
|
|
8
|
-
constructor(options?: Partial<HttpOptions>);
|
|
9
|
-
static request(method: HttpMethod, url: string, params?: any): HttpBuilder;
|
|
10
|
-
static head(url: string, params?: any): HttpBuilder;
|
|
11
|
-
static post(url: string, params?: any): HttpBuilder;
|
|
12
|
-
static get(url: string, params?: any): HttpBuilder;
|
|
13
|
-
static put(url: string, params?: any): HttpBuilder;
|
|
14
|
-
static patch(url: string, params?: any): HttpBuilder;
|
|
15
|
-
static delete(url: string, params?: any): HttpBuilder;
|
|
16
|
-
private static getInstance;
|
|
17
|
-
request(method: HttpMethod, url: string, params?: any): HttpBuilder;
|
|
18
|
-
head(url: string, params?: any): HttpBuilder;
|
|
19
|
-
post(url: string, params?: any): HttpBuilder;
|
|
20
|
-
get(url: string, params?: any): HttpBuilder;
|
|
21
|
-
put(url: string, params?: any): HttpBuilder;
|
|
22
|
-
patch(url: string, params?: any): HttpBuilder;
|
|
23
|
-
delete(url: string, params?: any): HttpBuilder;
|
|
24
|
-
onSend(callback: (request: Message) => void | Promise<void>): import("./event-aggregator").Subscription;
|
|
25
|
-
onSent(callback: (response: HttpResponse, request: Message) => void | Promise<void>): import("./event-aggregator").Subscription;
|
|
26
|
-
onReceived(callback: (response: HttpResponseOfT<any>, request: Message, value: any) => void | Promise<void>): import("./event-aggregator").Subscription;
|
|
27
|
-
}
|
|
28
|
-
export interface HttpOptions {
|
|
29
|
-
fetch?: Fetch;
|
|
30
|
-
timeout?: number;
|
|
31
|
-
baseUrl?: string;
|
|
32
|
-
}
|