@outfoxx/sunday 1.1.0-alpha.9 → 1.1.0-beta.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/LICENSE.txt +203 -0
- package/README.md +6 -7
- package/dist/any-type.js +13 -0
- package/dist/any-type.js.map +1 -1
- package/dist/class-type.js +13 -0
- package/dist/class-type.js.map +1 -1
- package/dist/date-time-types.js +13 -0
- package/dist/date-time-types.js.map +1 -1
- package/dist/event-parser.js +13 -0
- package/dist/event-parser.js.map +1 -1
- package/dist/fetch-event-source.d.ts +4 -0
- package/dist/fetch-event-source.js +13 -0
- package/dist/fetch-event-source.js.map +1 -1
- package/dist/fetch-request-factory.d.ts +3 -0
- package/dist/fetch-request-factory.js +42 -2
- package/dist/fetch-request-factory.js.map +1 -1
- package/dist/fetch.js +24 -5
- package/dist/fetch.js.map +1 -1
- package/dist/header-parameters.js +13 -0
- package/dist/header-parameters.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/logger.js +13 -0
- package/dist/logger.js.map +1 -1
- package/dist/media-type-codecs/any-text-decoder.d.ts +7 -0
- package/dist/media-type-codecs/any-text-decoder.js +29 -0
- package/dist/media-type-codecs/any-text-decoder.js.map +1 -0
- package/dist/media-type-codecs/any-text-encoder.d.ts +5 -0
- package/dist/media-type-codecs/any-text-encoder.js +23 -0
- package/dist/media-type-codecs/any-text-encoder.js.map +1 -0
- package/dist/media-type-codecs/binary-decoder.js +13 -0
- package/dist/media-type-codecs/binary-decoder.js.map +1 -1
- package/dist/media-type-codecs/binary-encoder.js +13 -0
- package/dist/media-type-codecs/binary-encoder.js.map +1 -1
- package/dist/media-type-codecs/cbor-decoder.js +13 -0
- package/dist/media-type-codecs/cbor-decoder.js.map +1 -1
- package/dist/media-type-codecs/cbor-encoder.js +13 -0
- package/dist/media-type-codecs/cbor-encoder.js.map +1 -1
- package/dist/media-type-codecs/cbor-tags.js +13 -0
- package/dist/media-type-codecs/cbor-tags.js.map +1 -1
- package/dist/media-type-codecs/json-decoder.js +13 -0
- package/dist/media-type-codecs/json-decoder.js.map +1 -1
- package/dist/media-type-codecs/json-encoder.js +13 -0
- package/dist/media-type-codecs/json-encoder.js.map +1 -1
- package/dist/media-type-codecs/media-type-decoder.js +13 -0
- package/dist/media-type-codecs/media-type-decoder.js.map +1 -1
- package/dist/media-type-codecs/media-type-decoders.js +21 -3
- package/dist/media-type-codecs/media-type-decoders.js.map +1 -1
- package/dist/media-type-codecs/media-type-encoder.js +13 -0
- package/dist/media-type-codecs/media-type-encoder.js.map +1 -1
- package/dist/media-type-codecs/media-type-encoders.js +21 -3
- package/dist/media-type-codecs/media-type-encoders.js.map +1 -1
- package/dist/media-type-codecs/www-form-url-encoder.js +56 -6
- package/dist/media-type-codecs/www-form-url-encoder.js.map +1 -1
- package/dist/media-type.d.ts +4 -2
- package/dist/media-type.js +34 -5
- package/dist/media-type.js.map +1 -1
- package/dist/problem.js +19 -2
- package/dist/problem.js.map +1 -1
- package/dist/request-factory.d.ts +6 -0
- package/dist/request-factory.js +13 -0
- package/dist/request-factory.js.map +1 -1
- package/dist/result-response.d.ts +4 -0
- package/dist/result-response.js +15 -0
- package/dist/result-response.js.map +1 -0
- package/dist/sunday-error.js +13 -0
- package/dist/sunday-error.js.map +1 -1
- package/dist/url-template.js +13 -0
- package/dist/url-template.js.map +1 -1
- package/dist/util/any.js +13 -0
- package/dist/util/any.js.map +1 -1
- package/dist/util/base64.js +13 -0
- package/dist/util/base64.js.map +1 -1
- package/dist/util/error.d.ts +2 -0
- package/dist/util/error.js +26 -0
- package/dist/util/error.js.map +1 -0
- package/dist/util/hex.js +13 -0
- package/dist/util/hex.js.map +1 -1
- package/dist/util/rxjs.js +13 -0
- package/dist/util/rxjs.js.map +1 -1
- package/dist/util/stream-rxjs.js +13 -0
- package/dist/util/stream-rxjs.js.map +1 -1
- package/dist/util/temporal.js +13 -0
- package/dist/util/temporal.js.map +1 -1
- package/package.json +31 -28
- package/src/any-type.ts +14 -0
- package/src/class-type.ts +16 -2
- package/src/date-time-types.ts +14 -0
- package/src/event-parser.ts +18 -4
- package/src/fetch-event-source.ts +36 -7
- package/src/fetch-request-factory.ts +87 -24
- package/src/fetch.ts +27 -8
- package/src/header-parameters.ts +16 -2
- package/src/index.ts +15 -0
- package/src/logger.ts +14 -0
- package/src/media-type-codecs/any-text-decoder.ts +34 -0
- package/src/media-type-codecs/any-text-encoder.ts +26 -0
- package/src/media-type-codecs/binary-decoder.ts +15 -1
- package/src/media-type-codecs/binary-encoder.ts +15 -1
- package/src/media-type-codecs/cbor-decoder.ts +30 -16
- package/src/media-type-codecs/cbor-encoder.ts +28 -14
- package/src/media-type-codecs/cbor-tags.ts +14 -0
- package/src/media-type-codecs/json-decoder.ts +29 -15
- package/src/media-type-codecs/json-encoder.ts +21 -7
- package/src/media-type-codecs/media-type-decoder.ts +15 -1
- package/src/media-type-codecs/media-type-decoders.ts +26 -7
- package/src/media-type-codecs/media-type-encoder.ts +17 -3
- package/src/media-type-codecs/media-type-encoders.ts +26 -7
- package/src/media-type-codecs/www-form-url-encoder.ts +81 -17
- package/src/media-type.ts +44 -11
- package/src/problem.ts +21 -3
- package/src/request-factory.ts +46 -7
- package/src/result-response.ts +18 -0
- package/src/sunday-error.ts +18 -4
- package/src/url-template.ts +15 -1
- package/src/util/any.ts +14 -0
- package/src/util/base64.ts +15 -1
- package/src/util/error.ts +28 -0
- package/src/util/hex.ts +14 -0
- package/src/util/rxjs.ts +17 -3
- package/src/util/stream-rxjs.ts +15 -1
- package/src/util/temporal.ts +14 -0
package/src/fetch.ts
CHANGED
|
@@ -1,27 +1,46 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
import { ConstructableClassType } from './class-type';
|
|
2
16
|
import { MediaType } from './media-type';
|
|
3
17
|
import { Problem } from './problem';
|
|
4
18
|
import { SundayError } from './sunday-error';
|
|
5
19
|
import { Base64 } from './util/base64';
|
|
20
|
+
import { errorToMessage } from './util/error';
|
|
6
21
|
|
|
7
22
|
export async function validate(
|
|
8
23
|
response: Response,
|
|
9
24
|
dataExpected: boolean,
|
|
10
|
-
problemTypes?: Map<string, ConstructableClassType<Problem
|
|
25
|
+
problemTypes?: Map<string, ConstructableClassType<Problem>>,
|
|
11
26
|
): Promise<Response> {
|
|
12
27
|
if (response.status < 200 || response.status >= 300) {
|
|
13
28
|
const mediaType = MediaType.from(
|
|
14
29
|
response.headers.get('content-type'),
|
|
15
|
-
MediaType.OctetStream
|
|
30
|
+
MediaType.OctetStream,
|
|
16
31
|
);
|
|
17
|
-
const
|
|
18
|
-
if (!
|
|
32
|
+
const isProblem = mediaType?.compatible(MediaType.Problem) ?? false;
|
|
33
|
+
if (!isProblem) {
|
|
19
34
|
throw await Problem.fromResponse(response);
|
|
20
35
|
}
|
|
21
36
|
|
|
22
37
|
const problemData = await response.json();
|
|
23
38
|
const problemType = problemTypes?.get(problemData.type) ?? Problem;
|
|
24
|
-
|
|
39
|
+
if (problemType.name === 'Problem') {
|
|
40
|
+
throw new Problem(problemData);
|
|
41
|
+
} else {
|
|
42
|
+
throw new problemType(problemData?.instance);
|
|
43
|
+
}
|
|
25
44
|
}
|
|
26
45
|
|
|
27
46
|
if (dataExpected && (response.status === 204 || response.status === 205)) {
|
|
@@ -45,7 +64,7 @@ export namespace ResponseExample {
|
|
|
45
64
|
|
|
46
65
|
export async function bodyExcerpt(
|
|
47
66
|
response: Response,
|
|
48
|
-
maxLength: number
|
|
67
|
+
maxLength: number,
|
|
49
68
|
): Promise<[string, unknown]> {
|
|
50
69
|
let body: unknown;
|
|
51
70
|
let bodyExcerpt: string;
|
|
@@ -70,9 +89,9 @@ export namespace ResponseExample {
|
|
|
70
89
|
bodyExcerpt = Base64.encode(dataSlice);
|
|
71
90
|
}
|
|
72
91
|
}
|
|
73
|
-
} catch (
|
|
92
|
+
} catch (error) {
|
|
74
93
|
// ignore errors
|
|
75
|
-
const message =
|
|
94
|
+
const message = errorToMessage(error);
|
|
76
95
|
body = bodyExcerpt = `<<error displaying response data: ${message}>>`;
|
|
77
96
|
}
|
|
78
97
|
return [bodyExcerpt, body];
|
package/src/header-parameters.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
export namespace HeaderParameters {
|
|
2
16
|
export function encode(
|
|
3
|
-
parameters?: Record<string, unknown
|
|
17
|
+
parameters?: Record<string, unknown>,
|
|
4
18
|
): [string, string][] {
|
|
5
19
|
if (parameters == null) {
|
|
6
20
|
return [];
|
|
@@ -44,7 +58,7 @@ export namespace HeaderParameters {
|
|
|
44
58
|
function validate(name: string, value: string): string {
|
|
45
59
|
if (!asciiRegex.test(value)) {
|
|
46
60
|
throw new Error(
|
|
47
|
-
`The encoded header value contains one or more invalid characters: header=${name}, value=${value}
|
|
61
|
+
`The encoded header value contains one or more invalid characters: header=${name}, value=${value}`,
|
|
48
62
|
);
|
|
49
63
|
}
|
|
50
64
|
return value;
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
export * from './any-type';
|
|
2
16
|
export * from './class-type';
|
|
3
17
|
export * from './request-factory';
|
|
@@ -20,6 +34,7 @@ export * from './logger';
|
|
|
20
34
|
export * from './sunday-error';
|
|
21
35
|
export * from './problem';
|
|
22
36
|
export * from './date-time-types';
|
|
37
|
+
export * from './result-response';
|
|
23
38
|
|
|
24
39
|
export * from './util/base64';
|
|
25
40
|
export * from './util/hex';
|
package/src/logger.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
export interface Logger {
|
|
2
16
|
trace?(...data: unknown[]): void;
|
|
3
17
|
debug?(...data: unknown[]): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { AnyType } from '../any-type';
|
|
16
|
+
import { TextMediaTypeDecoder } from './media-type-decoder';
|
|
17
|
+
|
|
18
|
+
export class AnyTextDecoder implements TextMediaTypeDecoder {
|
|
19
|
+
static default = new AnyTextDecoder();
|
|
20
|
+
|
|
21
|
+
async decode<T>(response: Response, type: AnyType): Promise<T> {
|
|
22
|
+
if (type[0] != String) {
|
|
23
|
+
throw Error('Invalid type, expected String');
|
|
24
|
+
}
|
|
25
|
+
return (await response.text()) as unknown as T;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
decodeText<T>(text: string, type: AnyType): T {
|
|
29
|
+
if (type[0] != String) {
|
|
30
|
+
throw Error('Invalid type, expected String');
|
|
31
|
+
}
|
|
32
|
+
return text as unknown as T;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { MediaTypeEncoder } from './media-type-encoder';
|
|
16
|
+
|
|
17
|
+
export class AnyTextEncoder implements MediaTypeEncoder {
|
|
18
|
+
static default = new AnyTextEncoder();
|
|
19
|
+
|
|
20
|
+
encode(value: unknown): BodyInit {
|
|
21
|
+
if (typeof value != 'string') {
|
|
22
|
+
throw Error('Invalid value, expected string');
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
import { MediaTypeDecoder } from './media-type-decoder';
|
|
2
16
|
import { AnyConstructableType } from '../any-type';
|
|
3
17
|
|
|
@@ -18,7 +32,7 @@ export class BinaryDecoder implements MediaTypeDecoder {
|
|
|
18
32
|
}
|
|
19
33
|
|
|
20
34
|
throw Error(
|
|
21
|
-
'Invalid value, expected ArrayBuffer, (Int|Uint)Array or DataView'
|
|
35
|
+
'Invalid value, expected ArrayBuffer, (Int|Uint)Array or DataView',
|
|
22
36
|
);
|
|
23
37
|
}
|
|
24
38
|
}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
import { MediaTypeEncoder } from './media-type-encoder';
|
|
2
16
|
|
|
3
17
|
export class BinaryEncoder implements MediaTypeEncoder {
|
|
@@ -11,7 +25,7 @@ export class BinaryEncoder implements MediaTypeEncoder {
|
|
|
11
25
|
!(value instanceof ReadableStream)
|
|
12
26
|
) {
|
|
13
27
|
throw Error(
|
|
14
|
-
'Invalid value, expected BufferSource, Blob or ReadableStream'
|
|
28
|
+
'Invalid value, expected BufferSource, Blob or ReadableStream',
|
|
15
29
|
);
|
|
16
30
|
}
|
|
17
31
|
return value;
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
import {
|
|
2
16
|
DateTimeFormatter,
|
|
3
17
|
DateTimeFormatterBuilder,
|
|
@@ -25,7 +39,7 @@ import { MediaTypeDecoder } from './media-type-decoder';
|
|
|
25
39
|
export class CBORDecoder implements MediaTypeDecoder {
|
|
26
40
|
static get default(): CBORDecoder {
|
|
27
41
|
return new CBORDecoder(
|
|
28
|
-
CBORDecoder.NumericDateDecoding.DECIMAL_SECONDS_SINCE_EPOCH
|
|
42
|
+
CBORDecoder.NumericDateDecoding.DECIMAL_SECONDS_SINCE_EPOCH,
|
|
29
43
|
);
|
|
30
44
|
}
|
|
31
45
|
|
|
@@ -156,7 +170,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
156
170
|
|
|
157
171
|
private zonedDateTimeDeserializer: Deserializer = (
|
|
158
172
|
key: string,
|
|
159
|
-
value: unknown
|
|
173
|
+
value: unknown,
|
|
160
174
|
) => {
|
|
161
175
|
if (value == null) {
|
|
162
176
|
return value;
|
|
@@ -185,7 +199,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
185
199
|
const duration = Duration.parse(`PT${value}S`);
|
|
186
200
|
const instant = Instant.ofEpochSecond(
|
|
187
201
|
duration.seconds(),
|
|
188
|
-
duration.nano()
|
|
202
|
+
duration.nano(),
|
|
189
203
|
);
|
|
190
204
|
return ZonedDateTime.ofInstant(instant, ZoneId.UTC);
|
|
191
205
|
} else {
|
|
@@ -194,7 +208,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
194
208
|
}
|
|
195
209
|
if (typeof value === 'string') {
|
|
196
210
|
return ZonedDateTime.from(
|
|
197
|
-
DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(value)
|
|
211
|
+
DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(value),
|
|
198
212
|
);
|
|
199
213
|
}
|
|
200
214
|
throw new Error(`Invalid date value for property ${key}`);
|
|
@@ -202,7 +216,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
202
216
|
|
|
203
217
|
private offsetDateTimeDeserializer: Deserializer = (
|
|
204
218
|
key: string,
|
|
205
|
-
value: unknown
|
|
219
|
+
value: unknown,
|
|
206
220
|
) => {
|
|
207
221
|
if (value == null) {
|
|
208
222
|
return value;
|
|
@@ -234,7 +248,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
234
248
|
const duration = Duration.parse(`PT${value}S`);
|
|
235
249
|
const instant = Instant.ofEpochSecond(
|
|
236
250
|
duration.seconds(),
|
|
237
|
-
duration.nano()
|
|
251
|
+
duration.nano(),
|
|
238
252
|
);
|
|
239
253
|
return OffsetDateTime.ofInstant(instant, ZoneId.UTC);
|
|
240
254
|
} else {
|
|
@@ -243,7 +257,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
243
257
|
}
|
|
244
258
|
if (typeof value === 'string') {
|
|
245
259
|
return OffsetDateTime.from(
|
|
246
|
-
DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(value)
|
|
260
|
+
DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(value),
|
|
247
261
|
);
|
|
248
262
|
}
|
|
249
263
|
throw new Error(`Invalid date value for property ${key}`);
|
|
@@ -257,7 +271,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
257
271
|
|
|
258
272
|
private offsetTimeDeserializer: Deserializer = (
|
|
259
273
|
key: string,
|
|
260
|
-
value: unknown
|
|
274
|
+
value: unknown,
|
|
261
275
|
) => {
|
|
262
276
|
if (value == null) {
|
|
263
277
|
return value;
|
|
@@ -290,7 +304,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
290
304
|
minute,
|
|
291
305
|
second,
|
|
292
306
|
nanoOfSecond,
|
|
293
|
-
ZoneOffset.of(offset)
|
|
307
|
+
ZoneOffset.of(offset),
|
|
294
308
|
);
|
|
295
309
|
}
|
|
296
310
|
if (typeof value === 'string') {
|
|
@@ -301,7 +315,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
301
315
|
|
|
302
316
|
private localDateTimeDeserializer: Deserializer = (
|
|
303
317
|
key: string,
|
|
304
|
-
value: unknown
|
|
318
|
+
value: unknown,
|
|
305
319
|
) => {
|
|
306
320
|
if (value == null) {
|
|
307
321
|
return value;
|
|
@@ -342,12 +356,12 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
342
356
|
hour,
|
|
343
357
|
minute,
|
|
344
358
|
second,
|
|
345
|
-
nanoOfSecond
|
|
359
|
+
nanoOfSecond,
|
|
346
360
|
);
|
|
347
361
|
}
|
|
348
362
|
if (typeof value === 'string') {
|
|
349
363
|
return LocalDateTime.from(
|
|
350
|
-
DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(value)
|
|
364
|
+
DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(value),
|
|
351
365
|
);
|
|
352
366
|
}
|
|
353
367
|
throw new Error(`Invalid date value for property ${key}`);
|
|
@@ -355,7 +369,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
355
369
|
|
|
356
370
|
private localDateDeserializer: Deserializer = (
|
|
357
371
|
key: string,
|
|
358
|
-
value: unknown
|
|
372
|
+
value: unknown,
|
|
359
373
|
) => {
|
|
360
374
|
if (value == null) {
|
|
361
375
|
return value;
|
|
@@ -384,7 +398,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
384
398
|
|
|
385
399
|
private localTimeDeserializer: Deserializer = (
|
|
386
400
|
key: string,
|
|
387
|
-
value: unknown
|
|
401
|
+
value: unknown,
|
|
388
402
|
) => {
|
|
389
403
|
if (value == null) {
|
|
390
404
|
return value;
|
|
@@ -475,7 +489,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
475
489
|
|
|
476
490
|
private arrayBufferDeserializer: Deserializer = (
|
|
477
491
|
key: string,
|
|
478
|
-
value: unknown
|
|
492
|
+
value: unknown,
|
|
479
493
|
) => {
|
|
480
494
|
if (value == null) {
|
|
481
495
|
return value;
|
|
@@ -486,7 +500,7 @@ export class CBORDecoder implements MediaTypeDecoder {
|
|
|
486
500
|
if (ArrayBuffer.isView(value)) {
|
|
487
501
|
return value.buffer.slice(
|
|
488
502
|
value.byteOffset,
|
|
489
|
-
value.byteOffset + value.byteLength
|
|
503
|
+
value.byteOffset + value.byteLength,
|
|
490
504
|
);
|
|
491
505
|
}
|
|
492
506
|
if (typeof value === 'string') {
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
import {
|
|
2
16
|
ChronoField,
|
|
3
17
|
DateTimeFormatter,
|
|
@@ -24,7 +38,7 @@ import { MediaTypeEncoder } from './media-type-encoder';
|
|
|
24
38
|
export class CBOREncoder implements MediaTypeEncoder {
|
|
25
39
|
static get default(): CBOREncoder {
|
|
26
40
|
return new CBOREncoder(
|
|
27
|
-
CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH
|
|
41
|
+
CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH,
|
|
28
42
|
);
|
|
29
43
|
}
|
|
30
44
|
|
|
@@ -82,7 +96,7 @@ export class CBOREncoder implements MediaTypeEncoder {
|
|
|
82
96
|
Reflect.hasMetadata(
|
|
83
97
|
'jackson:defaultContextGroup:JsonSubTypes',
|
|
84
98
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
-
(value as any).constructor ?? {}
|
|
99
|
+
(value as any).constructor ?? {},
|
|
86
100
|
)
|
|
87
101
|
) {
|
|
88
102
|
type = [Object];
|
|
@@ -103,16 +117,16 @@ export class CBOREncoder implements MediaTypeEncoder {
|
|
|
103
117
|
case CBOREncoder.DateEncoding.ISO8601:
|
|
104
118
|
return new TaggedValue(
|
|
105
119
|
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(
|
|
106
|
-
value.atZone(ZoneId.UTC)
|
|
120
|
+
value.atZone(ZoneId.UTC),
|
|
107
121
|
),
|
|
108
|
-
isoDateTimeTag
|
|
122
|
+
isoDateTimeTag,
|
|
109
123
|
);
|
|
110
124
|
case CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH:
|
|
111
125
|
return new TaggedValue(value.toEpochMilli(), epochDateTimeTag);
|
|
112
126
|
case CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH:
|
|
113
127
|
return new TaggedValue(
|
|
114
128
|
secondsToNumber(value.epochSecond(), value.nano()),
|
|
115
|
-
epochDateTimeTag
|
|
129
|
+
epochDateTimeTag,
|
|
116
130
|
);
|
|
117
131
|
}
|
|
118
132
|
};
|
|
@@ -126,18 +140,18 @@ export class CBOREncoder implements MediaTypeEncoder {
|
|
|
126
140
|
case CBOREncoder.DateEncoding.ISO8601:
|
|
127
141
|
return new TaggedValue(
|
|
128
142
|
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value),
|
|
129
|
-
isoDateTimeTag
|
|
143
|
+
isoDateTimeTag,
|
|
130
144
|
);
|
|
131
145
|
case CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH:
|
|
132
146
|
return new TaggedValue(
|
|
133
147
|
value.toInstant().toEpochMilli(),
|
|
134
|
-
epochDateTimeTag
|
|
148
|
+
epochDateTimeTag,
|
|
135
149
|
);
|
|
136
150
|
case CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH:
|
|
137
151
|
const instant = value.toInstant();
|
|
138
152
|
return new TaggedValue(
|
|
139
153
|
secondsToNumber(instant.epochSecond(), instant.nano()),
|
|
140
|
-
epochDateTimeTag
|
|
154
|
+
epochDateTimeTag,
|
|
141
155
|
);
|
|
142
156
|
}
|
|
143
157
|
};
|
|
@@ -151,18 +165,18 @@ export class CBOREncoder implements MediaTypeEncoder {
|
|
|
151
165
|
case CBOREncoder.DateEncoding.ISO8601:
|
|
152
166
|
return new TaggedValue(
|
|
153
167
|
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value),
|
|
154
|
-
isoDateTimeTag
|
|
168
|
+
isoDateTimeTag,
|
|
155
169
|
);
|
|
156
170
|
case CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH:
|
|
157
171
|
return new TaggedValue(
|
|
158
172
|
value.toInstant().toEpochMilli(),
|
|
159
|
-
epochDateTimeTag
|
|
173
|
+
epochDateTimeTag,
|
|
160
174
|
);
|
|
161
175
|
case CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH:
|
|
162
176
|
const instant = value.toInstant();
|
|
163
177
|
return new TaggedValue(
|
|
164
178
|
secondsToNumber(instant.epochSecond(), instant.nano()),
|
|
165
|
-
epochDateTimeTag
|
|
179
|
+
epochDateTimeTag,
|
|
166
180
|
);
|
|
167
181
|
}
|
|
168
182
|
};
|
|
@@ -189,7 +203,7 @@ export class CBOREncoder implements MediaTypeEncoder {
|
|
|
189
203
|
this.dateEncoding ==
|
|
190
204
|
CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH
|
|
191
205
|
? value.get(ChronoField.MILLI_OF_SECOND)
|
|
192
|
-
: value.nano()
|
|
206
|
+
: value.nano(),
|
|
193
207
|
),
|
|
194
208
|
value.offset().toString(),
|
|
195
209
|
];
|
|
@@ -216,7 +230,7 @@ export class CBOREncoder implements MediaTypeEncoder {
|
|
|
216
230
|
this.dateEncoding ==
|
|
217
231
|
CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH
|
|
218
232
|
? value.get(ChronoField.MILLI_OF_SECOND)
|
|
219
|
-
: value.nano()
|
|
233
|
+
: value.nano(),
|
|
220
234
|
),
|
|
221
235
|
];
|
|
222
236
|
}
|
|
@@ -252,7 +266,7 @@ export class CBOREncoder implements MediaTypeEncoder {
|
|
|
252
266
|
this.dateEncoding ==
|
|
253
267
|
CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH
|
|
254
268
|
? value.get(ChronoField.MILLI_OF_SECOND)
|
|
255
|
-
: value.nano()
|
|
269
|
+
: value.nano(),
|
|
256
270
|
),
|
|
257
271
|
];
|
|
258
272
|
}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// Copyright 2020 Outfox, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
1
15
|
export const isoDateTimeTag = 0;
|
|
2
16
|
export const epochDateTimeTag = 1;
|
|
3
17
|
export const uriTag = 32;
|