@utiliread/http 1.17.7 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +2 -2
- package/dist/cjs/event-aggregator.js +29 -29
- package/dist/cjs/event-aggregator.js.map +1 -1
- package/dist/cjs/events.js +18 -18
- package/dist/cjs/events.js.map +1 -1
- package/dist/cjs/helpers.js +15 -15
- package/dist/cjs/http-builder.js +191 -191
- package/dist/cjs/http-builder.js.map +1 -1
- package/dist/cjs/http-error.js +29 -29
- package/dist/cjs/http-error.js.map +1 -1
- package/dist/cjs/http-response.js +50 -50
- package/dist/cjs/http-response.js.map +1 -1
- package/dist/cjs/http.js +95 -95
- package/dist/cjs/http.js.map +1 -1
- package/dist/cjs/http.spec.js +68 -68
- package/dist/cjs/http.spec.js.map +1 -1
- package/dist/cjs/index.js +37 -37
- package/dist/cjs/json/index.js +73 -73
- package/dist/cjs/jsonpatch/index.js +14 -14
- package/dist/cjs/mapping.js +36 -36
- package/dist/cjs/mapping.js.map +1 -1
- package/dist/cjs/msgpack/index.js +34 -34
- package/dist/cjs/msgpack/index.js.map +1 -1
- package/dist/cjs/pagination.js +2 -2
- package/dist/cjs/problem-details.js +2 -2
- package/dist/cjs/query-string.js +67 -65
- package/dist/cjs/query-string.js.map +1 -1
- package/dist/cjs/query-string.spec.js +51 -51
- package/dist/cjs/status-codes.js +70 -70
- package/dist/cjs/timeout-error.js +13 -13
- package/dist/esm/event-aggregator.d.ts +11 -11
- package/dist/esm/event-aggregator.js +25 -25
- package/dist/esm/event-aggregator.js.map +1 -1
- package/dist/esm/events.d.ts +11 -11
- package/dist/esm/events.js +14 -14
- package/dist/esm/events.js.map +1 -1
- package/dist/esm/helpers.d.ts +5 -5
- package/dist/esm/helpers.js +9 -9
- package/dist/esm/http-builder.d.ts +60 -60
- package/dist/esm/http-builder.js +186 -186
- package/dist/esm/http-builder.js.map +1 -1
- package/dist/esm/http-error.d.ts +10 -10
- package/dist/esm/http-error.js +25 -25
- package/dist/esm/http-error.js.map +1 -1
- package/dist/esm/http-response.d.ts +18 -18
- package/dist/esm/http-response.js +45 -45
- package/dist/esm/http-response.js.map +1 -1
- package/dist/esm/http.d.ts +33 -33
- package/dist/esm/http.js +91 -91
- package/dist/esm/http.js.map +1 -1
- package/dist/esm/http.spec.d.ts +1 -1
- package/dist/esm/http.spec.js +66 -66
- package/dist/esm/http.spec.js.map +1 -1
- package/dist/esm/index.d.ts +15 -15
- package/dist/esm/index.js +10 -10
- package/dist/esm/json/index.d.ts +15 -15
- package/dist/esm/json/index.js +71 -71
- package/dist/esm/jsonpatch/index.d.ts +9 -9
- package/dist/esm/jsonpatch/index.js +12 -12
- package/dist/esm/mapping.d.ts +9 -9
- package/dist/esm/mapping.js +31 -31
- package/dist/esm/mapping.js.map +1 -1
- package/dist/esm/msgpack/index.d.ts +8 -8
- package/dist/esm/msgpack/index.js +32 -32
- package/dist/esm/msgpack/index.js.map +1 -1
- package/dist/esm/pagination.d.ts +23 -23
- package/dist/esm/pagination.js +1 -1
- package/dist/esm/problem-details.d.ts +7 -7
- package/dist/esm/problem-details.js +1 -1
- package/dist/esm/query-string.d.ts +6 -6
- package/dist/esm/query-string.js +63 -61
- package/dist/esm/query-string.js.map +1 -1
- package/dist/esm/query-string.spec.d.ts +1 -1
- package/dist/esm/query-string.spec.js +49 -49
- package/dist/esm/status-codes.d.ts +67 -67
- package/dist/esm/status-codes.js +67 -67
- package/dist/esm/timeout-error.d.ts +3 -3
- package/dist/esm/timeout-error.js +9 -9
- package/package.json +15 -17
- package/plugins/json/node_modules/@utiliread/http/package.json +4 -0
- package/plugins/json/src/index.ts +124 -122
- package/plugins/jsonpatch/node_modules/@utiliread/http/package.json +4 -0
- package/plugins/jsonpatch/src/index.ts +31 -31
- package/plugins/msgpack/node_modules/@utiliread/http/package.json +4 -0
- package/plugins/msgpack/src/index.ts +67 -60
- package/src/event-aggregator.ts +21 -21
- package/src/events.ts +39 -39
- package/src/helpers.ts +6 -6
- package/src/http-builder.ts +252 -218
- package/src/http-error.ts +30 -23
- package/src/http-response.ts +1 -1
- package/src/http.spec.ts +1 -1
- package/src/http.ts +8 -5
- package/src/index.ts +1 -1
- package/src/mapping.ts +40 -32
- package/src/pagination.ts +16 -16
- package/src/problem-details.ts +6 -6
- package/src/query-string.spec.ts +59 -43
- package/src/query-string.ts +56 -58
- package/src/status-codes.ts +67 -67
- package/src/timeout-error.ts +7 -7
- package/tsconfig.cjs.json +1 -0
- package/tsconfig.json +1 -1
- package/web-test-runner.config.mjs +7 -0
- package/karma.config.js +0 -29
- package/src/mapping.d.ts +0 -9
- package/src/mapping.js +0 -32
- package/src/mapping.js.map +0 -1
package/src/mapping.ts
CHANGED
|
@@ -1,44 +1,52 @@
|
|
|
1
1
|
type DeserializeFn<T> = (source: any, type: Type<T>) => T | null | undefined;
|
|
2
|
-
export type Type<T> = { new(): T };
|
|
3
|
-
export type Mapper<T> = (
|
|
2
|
+
export type Type<T> = { new (): T };
|
|
3
|
+
export type Mapper<T> = (source: any) => T;
|
|
4
4
|
export type TypeOrMapper<T> = Type<T> | Mapper<T>;
|
|
5
5
|
|
|
6
|
-
export function getNullableMapper<T>(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
export function getNullableMapper<T>(
|
|
7
|
+
deserialize: DeserializeFn<T>,
|
|
8
|
+
typeOrMap: Type<T> | Mapper<T> | undefined,
|
|
9
|
+
): Mapper<T | null> {
|
|
10
|
+
if (!typeOrMap) {
|
|
11
|
+
return (x: any) => <T>x;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (isZeroArgumentFunction(typeOrMap)) {
|
|
15
|
+
// It cannot be a factory function if it takes no arguments,
|
|
16
|
+
// so it must be a (zero argument) type (constructor)
|
|
17
|
+
return (x: any) => {
|
|
18
|
+
const bound = deserialize(x, typeOrMap);
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
// The server cannot produce the undefined result
|
|
21
|
+
if (bound === undefined) {
|
|
22
|
+
throw Error("The model factory created a undefined result");
|
|
23
|
+
}
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
return bound;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
return typeOrMap;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
export function getMapper<T>(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
export function getMapper<T>(
|
|
33
|
+
deserialize: DeserializeFn<T>,
|
|
34
|
+
typeOrMap: Type<T> | Mapper<T> | undefined,
|
|
35
|
+
): Mapper<T> {
|
|
36
|
+
const nullableFactory = getNullableMapper(deserialize, typeOrMap);
|
|
37
|
+
return (x: any) => {
|
|
38
|
+
const result = nullableFactory(x);
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
if (result === null) {
|
|
41
|
+
throw Error("The model factory created a null result");
|
|
42
|
+
}
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
function isZeroArgumentFunction<T>(
|
|
43
|
-
|
|
44
|
-
}
|
|
48
|
+
function isZeroArgumentFunction<T>(
|
|
49
|
+
typeCtor: Function,
|
|
50
|
+
): typeCtor is { new (): T } {
|
|
51
|
+
return typeCtor.length === 0;
|
|
52
|
+
}
|
package/src/pagination.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
export interface Page {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
number?: number;
|
|
3
|
+
size: number;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export interface PaginationResult<T> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
meta: {
|
|
8
|
+
pageCount: number;
|
|
9
|
+
pageSize: number;
|
|
10
|
+
totalItems: number;
|
|
11
|
+
};
|
|
12
|
+
data: T[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface InfinitePage {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
continuationToken?: string;
|
|
17
|
+
size: number;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export interface InfinitePaginationResult<T> {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
21
|
+
meta: {
|
|
22
|
+
pageSize: number;
|
|
23
|
+
continuationToken: string | null;
|
|
24
|
+
};
|
|
25
|
+
data: T[];
|
|
26
|
+
}
|
package/src/problem-details.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type ProblemDetails = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} & Record<string, any>;
|
|
2
|
+
detail?: string;
|
|
3
|
+
instance?: string;
|
|
4
|
+
status?: number;
|
|
5
|
+
title?: string;
|
|
6
|
+
type: string;
|
|
7
|
+
} & Record<string, any>;
|
package/src/query-string.spec.ts
CHANGED
|
@@ -1,63 +1,79 @@
|
|
|
1
|
-
import { DateTime } from
|
|
2
|
-
import { QueryString } from
|
|
3
|
-
import { expect } from
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
import { QueryString } from "./query-string";
|
|
3
|
+
import { expect } from "chai";
|
|
4
4
|
|
|
5
5
|
describe("query-string", () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
expect(qs).to.equal("?aString=hello");
|
|
6
|
+
it("should handle string", () => {
|
|
7
|
+
const qs = QueryString.serialize({
|
|
8
|
+
aString: "hello",
|
|
12
9
|
});
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
aString: ["hello","world"]
|
|
17
|
-
});
|
|
11
|
+
expect(qs).to.equal("?aString=hello");
|
|
12
|
+
});
|
|
18
13
|
|
|
19
|
-
|
|
14
|
+
it("should handle string array", () => {
|
|
15
|
+
const qs = QueryString.serialize({
|
|
16
|
+
aString: ["hello", "world"],
|
|
20
17
|
});
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
array: [{a: "hello"}, {b: "world"}]
|
|
25
|
-
});
|
|
19
|
+
expect(qs).to.equal("?aString[0]=hello&aString[1]=world");
|
|
20
|
+
});
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
it("should handle object array", () => {
|
|
23
|
+
const qs = QueryString.serialize({
|
|
24
|
+
array: [{ a: "hello" }, { b: "world" }],
|
|
28
25
|
});
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const qs = QueryString.serialize({
|
|
33
|
-
aDateTime: datetime
|
|
34
|
-
});
|
|
27
|
+
expect(qs).to.equal("?array[0].a=hello&array[1].b=world");
|
|
28
|
+
});
|
|
35
29
|
|
|
36
|
-
|
|
30
|
+
it("should handle luxon DateTime in local timezone", () => {
|
|
31
|
+
const datetime = DateTime.fromObject({
|
|
32
|
+
year: 2014,
|
|
33
|
+
month: 11,
|
|
34
|
+
day: 12,
|
|
35
|
+
hour: 21,
|
|
36
|
+
minute: 6,
|
|
37
|
+
});
|
|
38
|
+
const qs = QueryString.serialize({
|
|
39
|
+
aDateTime: datetime,
|
|
37
40
|
});
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
42
|
+
expect(qs).to.equal(
|
|
43
|
+
"?aDateTime=" + encodeURIComponent("2014-11-12T21:06:00.000+01:00"),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
it("should handle luxon DateTime in utc", () => {
|
|
48
|
+
const datetime = DateTime.fromObject({
|
|
49
|
+
year: 2014,
|
|
50
|
+
month: 11,
|
|
51
|
+
day: 12,
|
|
52
|
+
hour: 21,
|
|
53
|
+
minute: 6,
|
|
54
|
+
}).toUTC();
|
|
55
|
+
const qs = QueryString.serialize({
|
|
56
|
+
aDateTime: datetime,
|
|
46
57
|
});
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
expect(qs).to.equal(
|
|
60
|
+
"?aDateTime=" + encodeURIComponent("2014-11-12T20:06:00.000Z"),
|
|
61
|
+
);
|
|
62
|
+
});
|
|
52
63
|
|
|
53
|
-
|
|
64
|
+
it("should handle null", () => {
|
|
65
|
+
const qs = QueryString.serialize({
|
|
66
|
+
null: null,
|
|
54
67
|
});
|
|
55
68
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
expect(qs).to.equal("?null");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should not include undefined", () => {
|
|
73
|
+
const qs = QueryString.serialize({
|
|
74
|
+
null: undefined,
|
|
75
|
+
});
|
|
60
76
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
77
|
+
expect(qs).to.equal("");
|
|
78
|
+
});
|
|
79
|
+
});
|
package/src/query-string.ts
CHANGED
|
@@ -1,70 +1,68 @@
|
|
|
1
1
|
import { DateTime } from "luxon";
|
|
2
2
|
|
|
3
3
|
export class QueryString {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
const serialized = this._serializeQueryString(params);
|
|
9
|
-
if (!serialized.length) {
|
|
10
|
-
return "";
|
|
11
|
-
}
|
|
12
|
-
return "?" + serialized;
|
|
4
|
+
static serialize(params: any) {
|
|
5
|
+
if (!params) {
|
|
6
|
+
return "";
|
|
13
7
|
}
|
|
8
|
+
const serialized = this._serializeQueryString(params);
|
|
9
|
+
if (!serialized.length) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
return "?" + serialized;
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
const any = url.indexOf("?") >= 0;
|
|
20
|
-
const separator = any ? "&" : "?";
|
|
21
|
-
|
|
22
|
-
return url + separator + this._serializeQueryString(params);
|
|
15
|
+
static append(url: string, params: any) {
|
|
16
|
+
if (!params) {
|
|
17
|
+
return url;
|
|
23
18
|
}
|
|
19
|
+
const any = url.indexOf("?") >= 0;
|
|
20
|
+
const separator = any ? "&" : "?";
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
return url + separator + this._serializeQueryString(params);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static getParameter(name: string) {
|
|
26
|
+
const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
|
|
27
|
+
const match = regex.exec(window.location.href);
|
|
28
|
+
if (match) {
|
|
29
|
+
if (match[1].length > 0) {
|
|
30
|
+
return decodeURIComponent(match[2]);
|
|
31
|
+
} else {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
36
34
|
}
|
|
35
|
+
}
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
private static _serializeQueryString(source: any, prefix?: string) {
|
|
38
|
+
const parts: string[] = [];
|
|
39
|
+
for (const propertyName in source) {
|
|
40
|
+
if (source.hasOwnProperty(propertyName)) {
|
|
41
|
+
const key =
|
|
42
|
+
prefix != null
|
|
43
|
+
? prefix +
|
|
44
|
+
(Array.isArray(source)
|
|
45
|
+
? "[" + encodeURIComponent(propertyName) + "]"
|
|
46
|
+
: "." + encodeURIComponent(propertyName))
|
|
47
|
+
: encodeURIComponent(propertyName);
|
|
48
|
+
const value = source[propertyName];
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
50
|
+
if (value instanceof DateTime) {
|
|
51
|
+
if (value.isValid) {
|
|
52
|
+
parts.push(key + "=" + encodeURIComponent(value.toISO()!));
|
|
53
|
+
}
|
|
54
|
+
} else if (value === null) {
|
|
55
|
+
parts.push(key);
|
|
56
|
+
} else if (value !== undefined) {
|
|
57
|
+
if (typeof value === "object") {
|
|
58
|
+
parts.push(this._serializeQueryString(value, key));
|
|
59
|
+
} else {
|
|
60
|
+
parts.push(key + "=" + encodeURIComponent(value));
|
|
61
|
+
}
|
|
66
62
|
}
|
|
67
|
-
|
|
68
|
-
return parts.join("&");
|
|
63
|
+
}
|
|
69
64
|
}
|
|
70
|
-
|
|
65
|
+
|
|
66
|
+
return parts.join("&");
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/status-codes.ts
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
export const statusCodes = Object.freeze({
|
|
2
|
-
status100Continue: 100,
|
|
3
|
-
status101SwitchingProtocols: 101,
|
|
4
|
-
status102Processing: 102,
|
|
5
|
-
status200OK: 200,
|
|
6
|
-
status201Created: 201,
|
|
7
|
-
status202Accepted: 202,
|
|
8
|
-
status203NonAuthoritative: 203,
|
|
9
|
-
status204NoContent: 204,
|
|
10
|
-
status205ResetContent: 205,
|
|
11
|
-
status206PartialContent: 206,
|
|
12
|
-
status207MultiStatus: 207,
|
|
13
|
-
status208AlreadyReported: 208,
|
|
14
|
-
status226IMUsed: 226,
|
|
15
|
-
status300MultipleChoices: 300,
|
|
16
|
-
status301MovedPermanently: 301,
|
|
17
|
-
status302Found: 302,
|
|
18
|
-
status303SeeOther: 303,
|
|
19
|
-
status304NotModified: 304,
|
|
20
|
-
status305UseProxy: 305,
|
|
21
|
-
status306SwitchProxy: 306,
|
|
22
|
-
status307TemporaryRedirect: 307,
|
|
23
|
-
status308PermanentRedirect: 308,
|
|
24
|
-
status400BadRequest: 400,
|
|
25
|
-
status401Unauthorized: 401,
|
|
26
|
-
status402PaymentRequired: 402,
|
|
27
|
-
status403Forbidden: 403,
|
|
28
|
-
status404NotFound: 404,
|
|
29
|
-
status405MethodNotAllowed: 405,
|
|
30
|
-
status406NotAcceptable: 406,
|
|
31
|
-
status407ProxyAuthenticationRequired: 407,
|
|
32
|
-
status408RequestTimeout: 408,
|
|
33
|
-
status409Conflict: 409,
|
|
34
|
-
status410Gone: 410,
|
|
35
|
-
status411LengthRequired: 411,
|
|
36
|
-
status412PreconditionFailed: 412,
|
|
37
|
-
status413RequestEntityTooLarge: 413,
|
|
38
|
-
status413PayloadTooLarge: 413,
|
|
39
|
-
status414RequestUriTooLong: 414,
|
|
40
|
-
status414UriTooLong: 414,
|
|
41
|
-
status415UnsupportedMediaType: 415,
|
|
42
|
-
status416RequestedRangeNotSatisfiable: 416,
|
|
43
|
-
status416RangeNotSatisfiable: 416,
|
|
44
|
-
status417ExpectationFailed: 417,
|
|
45
|
-
status418ImATeapot: 418,
|
|
46
|
-
status419AuthenticationTimeout: 419,
|
|
47
|
-
status421MisdirectedRequest: 421,
|
|
48
|
-
status422UnprocessableEntity: 422,
|
|
49
|
-
status423Locked: 423,
|
|
50
|
-
status424FailedDependency: 424,
|
|
51
|
-
status426UpgradeRequired: 426,
|
|
52
|
-
status428PreconditionRequired: 428,
|
|
53
|
-
status429TooManyRequests: 429,
|
|
54
|
-
status431RequestHeaderFieldsTooLarge: 431,
|
|
55
|
-
status451UnavailableForLegalReasons: 451,
|
|
56
|
-
status500InternalServerError: 500,
|
|
57
|
-
status501NotImplemented: 501,
|
|
58
|
-
status502BadGateway: 502,
|
|
59
|
-
status503ServiceUnavailable: 503,
|
|
60
|
-
status504GatewayTimeout: 504,
|
|
61
|
-
status505HttpVersionNotsupported: 505,
|
|
62
|
-
status506VariantAlsoNegotiates: 506,
|
|
63
|
-
status507InsufficientStorage: 507,
|
|
64
|
-
status508LoopDetected: 508,
|
|
65
|
-
status510NotExtended: 510,
|
|
66
|
-
status511NetworkAuthenticationRequired: 511,
|
|
67
|
-
});
|
|
1
|
+
export const statusCodes = Object.freeze({
|
|
2
|
+
status100Continue: 100,
|
|
3
|
+
status101SwitchingProtocols: 101,
|
|
4
|
+
status102Processing: 102,
|
|
5
|
+
status200OK: 200,
|
|
6
|
+
status201Created: 201,
|
|
7
|
+
status202Accepted: 202,
|
|
8
|
+
status203NonAuthoritative: 203,
|
|
9
|
+
status204NoContent: 204,
|
|
10
|
+
status205ResetContent: 205,
|
|
11
|
+
status206PartialContent: 206,
|
|
12
|
+
status207MultiStatus: 207,
|
|
13
|
+
status208AlreadyReported: 208,
|
|
14
|
+
status226IMUsed: 226,
|
|
15
|
+
status300MultipleChoices: 300,
|
|
16
|
+
status301MovedPermanently: 301,
|
|
17
|
+
status302Found: 302,
|
|
18
|
+
status303SeeOther: 303,
|
|
19
|
+
status304NotModified: 304,
|
|
20
|
+
status305UseProxy: 305,
|
|
21
|
+
status306SwitchProxy: 306,
|
|
22
|
+
status307TemporaryRedirect: 307,
|
|
23
|
+
status308PermanentRedirect: 308,
|
|
24
|
+
status400BadRequest: 400,
|
|
25
|
+
status401Unauthorized: 401,
|
|
26
|
+
status402PaymentRequired: 402,
|
|
27
|
+
status403Forbidden: 403,
|
|
28
|
+
status404NotFound: 404,
|
|
29
|
+
status405MethodNotAllowed: 405,
|
|
30
|
+
status406NotAcceptable: 406,
|
|
31
|
+
status407ProxyAuthenticationRequired: 407,
|
|
32
|
+
status408RequestTimeout: 408,
|
|
33
|
+
status409Conflict: 409,
|
|
34
|
+
status410Gone: 410,
|
|
35
|
+
status411LengthRequired: 411,
|
|
36
|
+
status412PreconditionFailed: 412,
|
|
37
|
+
status413RequestEntityTooLarge: 413,
|
|
38
|
+
status413PayloadTooLarge: 413,
|
|
39
|
+
status414RequestUriTooLong: 414,
|
|
40
|
+
status414UriTooLong: 414,
|
|
41
|
+
status415UnsupportedMediaType: 415,
|
|
42
|
+
status416RequestedRangeNotSatisfiable: 416,
|
|
43
|
+
status416RangeNotSatisfiable: 416,
|
|
44
|
+
status417ExpectationFailed: 417,
|
|
45
|
+
status418ImATeapot: 418,
|
|
46
|
+
status419AuthenticationTimeout: 419,
|
|
47
|
+
status421MisdirectedRequest: 421,
|
|
48
|
+
status422UnprocessableEntity: 422,
|
|
49
|
+
status423Locked: 423,
|
|
50
|
+
status424FailedDependency: 424,
|
|
51
|
+
status426UpgradeRequired: 426,
|
|
52
|
+
status428PreconditionRequired: 428,
|
|
53
|
+
status429TooManyRequests: 429,
|
|
54
|
+
status431RequestHeaderFieldsTooLarge: 431,
|
|
55
|
+
status451UnavailableForLegalReasons: 451,
|
|
56
|
+
status500InternalServerError: 500,
|
|
57
|
+
status501NotImplemented: 501,
|
|
58
|
+
status502BadGateway: 502,
|
|
59
|
+
status503ServiceUnavailable: 503,
|
|
60
|
+
status504GatewayTimeout: 504,
|
|
61
|
+
status505HttpVersionNotsupported: 505,
|
|
62
|
+
status506VariantAlsoNegotiates: 506,
|
|
63
|
+
status507InsufficientStorage: 507,
|
|
64
|
+
status508LoopDetected: 508,
|
|
65
|
+
status510NotExtended: 510,
|
|
66
|
+
status511NetworkAuthenticationRequired: 511,
|
|
67
|
+
});
|
package/src/timeout-error.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export class TimeoutError extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
constructor() {
|
|
3
|
+
super("Timeout: The request was not successful");
|
|
4
|
+
this.name = "TimeoutError";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
// Set the prototype explicitly to allow for "... instanceof TimeoutError",
|
|
7
|
+
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
8
|
+
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
9
|
+
}
|
|
10
10
|
}
|
package/tsconfig.cjs.json
CHANGED
package/tsconfig.json
CHANGED
package/karma.config.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const tsconfig = require("./tsconfig.json");
|
|
2
|
-
|
|
3
|
-
module.exports = function (config) {
|
|
4
|
-
config.set({
|
|
5
|
-
frameworks: ["mocha", "chai", "karma-typescript"],
|
|
6
|
-
files: ["src/**/*.ts"],
|
|
7
|
-
preprocessors: {
|
|
8
|
-
"src/**/*.ts": ["karma-typescript"],
|
|
9
|
-
},
|
|
10
|
-
reporters: ["progress", "karma-typescript"],
|
|
11
|
-
browsers: ["ChromeHeadless", "ChromeDebugging"],
|
|
12
|
-
customLaunchers: {
|
|
13
|
-
ChromeDebugging: {
|
|
14
|
-
base: "Chrome",
|
|
15
|
-
flags: ["--remote-debugging-port=9222"],
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
karmaTypescriptConfig: {
|
|
19
|
-
bundlerOptions: {
|
|
20
|
-
entrypoints: /\.spec\.ts$/,
|
|
21
|
-
sourceMap: tsconfig.compilerOptions.sourceMap,
|
|
22
|
-
},
|
|
23
|
-
coverageOptions: {
|
|
24
|
-
instrumentation: false,
|
|
25
|
-
},
|
|
26
|
-
tsconfig: "./tsconfig.test.json",
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
};
|
package/src/mapping.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare type DeserializeFn<T> = (source: any, type: Type<T>) => T | null | undefined;
|
|
2
|
-
export declare type Type<T> = {
|
|
3
|
-
new (): T;
|
|
4
|
-
};
|
|
5
|
-
export declare type Mapper<T> = ((source: any) => T);
|
|
6
|
-
export declare type TypeOrMapper<T> = Type<T> | Mapper<T>;
|
|
7
|
-
export declare function getNullableMapper<T>(deserialize: DeserializeFn<T>, typeOrMap: Type<T> | Mapper<T> | undefined): Mapper<T | null>;
|
|
8
|
-
export declare function getMapper<T>(deserialize: DeserializeFn<T>, typeOrMap: Type<T> | Mapper<T> | undefined): Mapper<T>;
|
|
9
|
-
export {};
|
package/src/mapping.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export function getNullableMapper(deserialize, typeOrMap) {
|
|
2
|
-
if (!typeOrMap) {
|
|
3
|
-
return (x) => x;
|
|
4
|
-
}
|
|
5
|
-
if (isZeroArgumentFunction(typeOrMap)) {
|
|
6
|
-
// It cannot be a factory function if it takes no arguments,
|
|
7
|
-
// so it must be a (zero argument) type (constructor)
|
|
8
|
-
return (x) => {
|
|
9
|
-
const bound = deserialize(x, typeOrMap);
|
|
10
|
-
// The server cannot produce the undefined result
|
|
11
|
-
if (bound === undefined) {
|
|
12
|
-
throw Error("The model factory created a undefined result");
|
|
13
|
-
}
|
|
14
|
-
return bound;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return typeOrMap;
|
|
18
|
-
}
|
|
19
|
-
export function getMapper(deserialize, typeOrMap) {
|
|
20
|
-
const nullableFactory = getNullableMapper(deserialize, typeOrMap);
|
|
21
|
-
return (x) => {
|
|
22
|
-
const result = nullableFactory(x);
|
|
23
|
-
if (result === null) {
|
|
24
|
-
throw Error("The model factory created a null result");
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function isZeroArgumentFunction(typeCtor) {
|
|
30
|
-
return typeCtor.length === 0;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=mapping.js.map
|
package/src/mapping.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mapping.js","sourceRoot":"","sources":["mapping.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,iBAAiB,CAAI,WAA6B,EAAE,SAA0C;IAC1G,IAAI,CAAC,SAAS,EAAE;QACZ,OAAO,CAAC,CAAM,EAAE,EAAE,CAAI,CAAC,CAAC;KAC3B;IAED,IAAI,sBAAsB,CAAC,SAAS,CAAC,EAAE;QACnC,4DAA4D;QAC5D,qDAAqD;QACrD,OAAO,CAAC,CAAM,EAAE,EAAE;YACd,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;YAExC,iDAAiD;YACjD,IAAI,KAAK,KAAK,SAAS,EAAE;gBACrB,MAAM,KAAK,CAAC,8CAA8C,CAAC,CAAC;aAC/D;YAED,OAAO,KAAK,CAAC;QACjB,CAAC,CAAA;KACJ;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,SAAS,CAAI,WAA6B,EAAE,SAA0C;IAClG,MAAM,eAAe,GAAG,iBAAiB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAClE,OAAO,CAAC,CAAM,EAAE,EAAE;QACd,MAAM,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;QAElC,IAAI,MAAM,KAAK,IAAI,EAAE;YACjB,MAAM,KAAK,CAAC,yCAAyC,CAAC,CAAC;SAC1D;QAED,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAED,SAAS,sBAAsB,CAAI,QAAkB;IACjD,OAAO,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;AACjC,CAAC"}
|