@outfoxx/sunday 1.1.0-alpha.13 → 1.1.0-alpha.16
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/fetch-event-source.d.ts +4 -0
- package/dist/fetch-event-source.js.map +1 -1
- package/dist/fetch.js +6 -1
- package/dist/fetch.js.map +1 -1
- package/dist/media-type-codecs/media-type-decoders.js.map +1 -1
- package/dist/media-type.d.ts +1 -1
- package/dist/media-type.js +10 -4
- package/dist/media-type.js.map +1 -1
- package/package.json +1 -1
- package/src/class-type.ts +2 -2
- package/src/event-parser.ts +4 -4
- package/src/fetch-event-source.ts +22 -7
- package/src/fetch-request-factory.ts +23 -23
- package/src/fetch.ts +8 -4
- package/src/header-parameters.ts +2 -2
- package/src/media-type-codecs/binary-decoder.ts +1 -1
- package/src/media-type-codecs/binary-encoder.ts +1 -1
- package/src/media-type-codecs/cbor-decoder.ts +16 -16
- package/src/media-type-codecs/cbor-encoder.ts +14 -14
- package/src/media-type-codecs/json-decoder.ts +15 -15
- package/src/media-type-codecs/json-encoder.ts +7 -7
- package/src/media-type-codecs/media-type-decoder.ts +1 -1
- package/src/media-type-codecs/media-type-decoders.ts +4 -5
- package/src/media-type-codecs/media-type-encoder.ts +3 -3
- package/src/media-type-codecs/media-type-encoders.ts +4 -4
- package/src/media-type-codecs/www-form-url-encoder.ts +15 -15
- package/src/media-type.ts +17 -10
- package/src/problem.ts +1 -1
- package/src/request-factory.ts +7 -7
- package/src/sunday-error.ts +4 -4
- package/src/url-template.ts +1 -1
- package/src/util/base64.ts +1 -1
- package/src/util/rxjs.ts +3 -3
- package/src/util/stream-rxjs.ts +1 -1
package/src/media-type.ts
CHANGED
|
@@ -35,7 +35,7 @@ export class MediaType {
|
|
|
35
35
|
obj[name.toLowerCase()] = value.toLowerCase();
|
|
36
36
|
return obj;
|
|
37
37
|
},
|
|
38
|
-
{} as Record<string, string
|
|
38
|
+
{} as Record<string, string>,
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -61,7 +61,7 @@ export class MediaType {
|
|
|
61
61
|
|
|
62
62
|
withParameter(
|
|
63
63
|
parameter: MediaType.ParameterName | string,
|
|
64
|
-
value: string
|
|
64
|
+
value: string,
|
|
65
65
|
): MediaType {
|
|
66
66
|
const parameters = Object.assign({}, this.parameters, {
|
|
67
67
|
[parameter]: value,
|
|
@@ -195,28 +195,35 @@ export namespace MediaType {
|
|
|
195
195
|
CharSet = 'charset',
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
export function from(value?: string | null): MediaType
|
|
198
|
+
export function from(value?: string | null): MediaType;
|
|
199
199
|
export function from(
|
|
200
200
|
value: string | null | undefined,
|
|
201
|
-
def: MediaType
|
|
201
|
+
def: MediaType,
|
|
202
202
|
): MediaType;
|
|
203
203
|
export function from(
|
|
204
204
|
value?: string | null,
|
|
205
|
-
def: MediaType | undefined = undefined
|
|
206
|
-
): MediaType
|
|
207
|
-
|
|
205
|
+
def: MediaType | undefined = undefined,
|
|
206
|
+
): MediaType {
|
|
207
|
+
const reqDef = () => {
|
|
208
|
+
if (!def) {
|
|
209
|
+
throw Error('Invalid media type');
|
|
210
|
+
}
|
|
208
211
|
return def;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
if (!value) {
|
|
215
|
+
return reqDef();
|
|
209
216
|
}
|
|
210
217
|
|
|
211
218
|
fullRegex.lastIndex = 0;
|
|
212
219
|
const match = fullRegex.exec(value);
|
|
213
220
|
if (match?.[0] != value) {
|
|
214
|
-
return
|
|
221
|
+
return reqDef();
|
|
215
222
|
}
|
|
216
223
|
|
|
217
224
|
const type = MediaType.Type.from(match[1]?.toLowerCase());
|
|
218
225
|
if (!type) {
|
|
219
|
-
return
|
|
226
|
+
return reqDef();
|
|
220
227
|
}
|
|
221
228
|
|
|
222
229
|
const tree =
|
|
@@ -224,7 +231,7 @@ export namespace MediaType {
|
|
|
224
231
|
|
|
225
232
|
const subtype = match[3]?.toLowerCase();
|
|
226
233
|
if (!subtype) {
|
|
227
|
-
return
|
|
234
|
+
return reqDef();
|
|
228
235
|
}
|
|
229
236
|
|
|
230
237
|
const suffix = MediaType.Suffix.from(match[4]?.toLowerCase());
|
package/src/problem.ts
CHANGED
|
@@ -132,7 +132,7 @@ export class Problem extends Error implements Problem {
|
|
|
132
132
|
static async fromResponse(response: Response): Promise<Problem> {
|
|
133
133
|
const [bodyExcerpt, body] = await ResponseExample.bodyExcerpt(
|
|
134
134
|
response,
|
|
135
|
-
256
|
|
135
|
+
256,
|
|
136
136
|
);
|
|
137
137
|
|
|
138
138
|
return new Problem({
|
package/src/request-factory.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface RequestFactory {
|
|
|
26
26
|
|
|
27
27
|
registerProblem(
|
|
28
28
|
type: URL | string,
|
|
29
|
-
problemType: ConstructableClassType<Problem
|
|
29
|
+
problemType: ConstructableClassType<Problem>,
|
|
30
30
|
): void;
|
|
31
31
|
|
|
32
32
|
request(requestSpec: RequestSpec<unknown>): Observable<Request>;
|
|
@@ -35,22 +35,22 @@ export interface RequestFactory {
|
|
|
35
35
|
|
|
36
36
|
response<B>(
|
|
37
37
|
requestSpec: RequestSpec<B>,
|
|
38
|
-
dataExpected?: boolean
|
|
38
|
+
dataExpected?: boolean,
|
|
39
39
|
): Observable<Response>;
|
|
40
40
|
|
|
41
41
|
result<B, R>(
|
|
42
42
|
requestSpec: RequestSpec<B>,
|
|
43
|
-
resultType: [ClassType<R>]
|
|
43
|
+
resultType: [ClassType<R>],
|
|
44
44
|
): Observable<R>;
|
|
45
45
|
|
|
46
46
|
result<B, R>(
|
|
47
47
|
requestSpec: RequestSpec<B>,
|
|
48
|
-
resultType: [ClassType<Array<unknown>>, ClassType<R>]
|
|
48
|
+
resultType: [ClassType<Array<unknown>>, ClassType<R>],
|
|
49
49
|
): Observable<Array<R>>;
|
|
50
50
|
|
|
51
51
|
result<B, R>(
|
|
52
52
|
requestSpec: RequestSpec<B>,
|
|
53
|
-
resultType: [ClassType<Set<unknown>>, ClassType<R>]
|
|
53
|
+
resultType: [ClassType<Set<unknown>>, ClassType<R>],
|
|
54
54
|
): Observable<Set<R>>;
|
|
55
55
|
|
|
56
56
|
result<B, R>(requestSpec: RequestSpec<B>, resultType: AnyType): Observable<R>;
|
|
@@ -66,8 +66,8 @@ export interface RequestFactory {
|
|
|
66
66
|
event: string | undefined,
|
|
67
67
|
id: string | undefined,
|
|
68
68
|
data: string,
|
|
69
|
-
logger?: Logger
|
|
70
|
-
) => E | undefined
|
|
69
|
+
logger?: Logger,
|
|
70
|
+
) => E | undefined,
|
|
71
71
|
): Observable<E>;
|
|
72
72
|
}
|
|
73
73
|
|
package/src/sunday-error.ts
CHANGED
|
@@ -23,18 +23,18 @@ export class SundayError extends Error {
|
|
|
23
23
|
public statusText: string,
|
|
24
24
|
public headers: Headers,
|
|
25
25
|
public body: unknown | undefined,
|
|
26
|
-
public responseExample: string
|
|
26
|
+
public responseExample: string,
|
|
27
27
|
) {
|
|
28
28
|
super(message);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
static async fromResponse(
|
|
32
32
|
message: string,
|
|
33
|
-
response: Response
|
|
33
|
+
response: Response,
|
|
34
34
|
): Promise<SundayError> {
|
|
35
35
|
const [bodyExcerpt, body] = await ResponseExample.bodyExcerpt(
|
|
36
36
|
response,
|
|
37
|
-
256
|
|
37
|
+
256,
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
return new SundayError(
|
|
@@ -45,7 +45,7 @@ export class SundayError extends Error {
|
|
|
45
45
|
response.statusText,
|
|
46
46
|
response.headers,
|
|
47
47
|
body,
|
|
48
|
-
ResponseExample.build(response, bodyExcerpt)
|
|
48
|
+
ResponseExample.build(response, bodyExcerpt),
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/url-template.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { URI } from 'uri-template-lite';
|
|
|
17
17
|
export class URLTemplate {
|
|
18
18
|
constructor(
|
|
19
19
|
public template: string,
|
|
20
|
-
public parameters: Record<string, unknown> = {}
|
|
20
|
+
public parameters: Record<string, unknown> = {},
|
|
21
21
|
) {}
|
|
22
22
|
|
|
23
23
|
complete(relativeTemplate: string, parameters: Record<string, unknown>): URL {
|
package/src/util/base64.ts
CHANGED
package/src/util/rxjs.ts
CHANGED
|
@@ -17,14 +17,14 @@ import { ClassType } from '../class-type';
|
|
|
17
17
|
import { Problem } from '../problem';
|
|
18
18
|
|
|
19
19
|
export function nullifyNotFound<T>(): (
|
|
20
|
-
source: Observable<T
|
|
20
|
+
source: Observable<T>,
|
|
21
21
|
) => Observable<T | null> {
|
|
22
22
|
return nullifyResponse([404], []);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function nullifyResponse<T>(
|
|
26
26
|
statuses: number[],
|
|
27
|
-
problemTypes: ClassType<Problem>[]
|
|
27
|
+
problemTypes: ClassType<Problem>[],
|
|
28
28
|
): (source: Observable<T>) => Observable<T | null> {
|
|
29
29
|
return function <T>(source: Observable<T>): Observable<T | null> {
|
|
30
30
|
return source.pipe(
|
|
@@ -37,7 +37,7 @@ export function nullifyResponse<T>(
|
|
|
37
37
|
return from([null]);
|
|
38
38
|
}
|
|
39
39
|
return throwError(error);
|
|
40
|
-
})
|
|
40
|
+
}),
|
|
41
41
|
);
|
|
42
42
|
};
|
|
43
43
|
}
|
package/src/util/stream-rxjs.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { Observable } from 'rxjs';
|
|
16
16
|
|
|
17
17
|
export function fromStream(
|
|
18
|
-
stream: ReadableStream<Uint8Array
|
|
18
|
+
stream: ReadableStream<Uint8Array>,
|
|
19
19
|
): Observable<ArrayBuffer> {
|
|
20
20
|
return new Observable((subscriber) => {
|
|
21
21
|
let reader: ReadableStreamDefaultReader | undefined;
|