@outfoxx/sunday 1.0.8 → 1.1.0-alpha.10
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/README.md +35 -2
- package/dist/any-type.d.ts +2 -0
- package/dist/class-type.d.ts +2 -2
- package/dist/date-time-types.d.ts +2 -7
- package/dist/date-time-types.js +2 -4
- package/dist/date-time-types.js.map +1 -1
- package/dist/event-parser.d.ts +17 -0
- package/dist/event-parser.js +140 -0
- package/dist/event-parser.js.map +1 -0
- package/dist/fetch-event-source.d.ts +12 -10
- package/dist/fetch-event-source.js +141 -138
- package/dist/fetch-event-source.js.map +1 -1
- package/dist/fetch-request-factory.d.ts +10 -5
- package/dist/fetch-request-factory.js +87 -71
- package/dist/fetch-request-factory.js.map +1 -1
- package/dist/fetch.d.ts +7 -1
- package/dist/fetch.js +61 -8
- package/dist/fetch.js.map +1 -1
- package/dist/header-parameters.d.ts +3 -0
- package/dist/header-parameters.js +40 -0
- package/dist/header-parameters.js.map +1 -0
- package/dist/index.d.ts +12 -12
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/{binary-decoder.d.ts → media-type-codecs/binary-decoder.d.ts} +2 -2
- package/dist/{binary-decoder.js → media-type-codecs/binary-decoder.js} +0 -0
- package/dist/media-type-codecs/binary-decoder.js.map +1 -0
- package/dist/{binary-encoder.d.ts → media-type-codecs/binary-encoder.d.ts} +0 -0
- package/dist/{binary-encoder.js → media-type-codecs/binary-encoder.js} +0 -0
- package/dist/media-type-codecs/binary-encoder.js.map +1 -0
- package/dist/media-type-codecs/cbor-decoder.d.ts +39 -0
- package/dist/media-type-codecs/cbor-decoder.js +413 -0
- package/dist/media-type-codecs/cbor-decoder.js.map +1 -0
- package/dist/media-type-codecs/cbor-encoder.d.ts +43 -0
- package/dist/media-type-codecs/cbor-encoder.js +226 -0
- package/dist/media-type-codecs/cbor-encoder.js.map +1 -0
- package/dist/media-type-codecs/cbor-tags.d.ts +4 -0
- package/dist/media-type-codecs/cbor-tags.js +5 -0
- package/dist/media-type-codecs/cbor-tags.js.map +1 -0
- package/dist/media-type-codecs/json-decoder.d.ts +39 -0
- package/dist/media-type-codecs/json-decoder.js +367 -0
- package/dist/media-type-codecs/json-decoder.js.map +1 -0
- package/dist/media-type-codecs/json-encoder.d.ts +44 -0
- package/dist/media-type-codecs/json-encoder.js +263 -0
- package/dist/media-type-codecs/json-encoder.js.map +1 -0
- package/dist/media-type-codecs/media-type-decoder.d.ts +11 -0
- package/dist/media-type-codecs/media-type-decoder.js +6 -0
- package/dist/media-type-codecs/media-type-decoder.js.map +1 -0
- package/dist/{media-type-decoders.d.ts → media-type-codecs/media-type-decoders.d.ts} +5 -4
- package/dist/{media-type-decoders.js → media-type-codecs/media-type-decoders.js} +6 -6
- package/dist/media-type-codecs/media-type-decoders.js.map +1 -0
- package/dist/{media-type-encoder.d.ts → media-type-codecs/media-type-encoder.d.ts} +5 -1
- package/dist/media-type-codecs/media-type-encoder.js +11 -0
- package/dist/media-type-codecs/media-type-encoder.js.map +1 -0
- package/dist/{media-type-encoders.d.ts → media-type-codecs/media-type-encoders.d.ts} +5 -4
- package/dist/{media-type-encoders.js → media-type-codecs/media-type-encoders.js} +8 -8
- package/dist/media-type-codecs/media-type-encoders.js.map +1 -0
- package/dist/{url-encoder.d.ts → media-type-codecs/www-form-url-encoder.d.ts} +8 -8
- package/dist/{url-encoder.js → media-type-codecs/www-form-url-encoder.js} +38 -37
- package/dist/media-type-codecs/www-form-url-encoder.js.map +1 -0
- package/dist/media-type.d.ts +91 -13
- package/dist/media-type.js +273 -15
- package/dist/media-type.js.map +1 -1
- package/dist/problem.d.ts +24 -9
- package/dist/problem.js +140 -6
- package/dist/problem.js.map +1 -1
- package/dist/request-factory.d.ts +10 -10
- package/dist/sunday-error.d.ts +11 -0
- package/dist/sunday-error.js +18 -0
- package/dist/sunday-error.js.map +1 -0
- package/dist/util/any.d.ts +2 -0
- package/dist/util/any.js +11 -0
- package/dist/util/any.js.map +1 -0
- package/dist/util/error.d.ts +2 -0
- package/dist/util/error.js +13 -0
- package/dist/util/error.js.map +1 -0
- package/dist/util/hex.js +3 -2
- package/dist/util/hex.js.map +1 -1
- package/dist/util/rxjs.d.ts +3 -0
- package/dist/util/rxjs.js +9 -5
- package/dist/util/rxjs.js.map +1 -1
- package/dist/util/temporal.d.ts +2 -0
- package/dist/util/temporal.js +18 -0
- package/dist/util/temporal.js.map +1 -0
- package/package.json +27 -21
- package/src/any-type.ts +4 -0
- package/src/class-type.ts +6 -2
- package/src/date-time-types.ts +22 -9
- package/src/event-parser.ts +190 -0
- package/src/fetch-event-source.ts +149 -159
- package/src/fetch-request-factory.ts +129 -101
- package/src/fetch.ts +65 -14
- package/src/header-parameters.ts +52 -0
- package/src/index.ts +12 -12
- package/src/{binary-decoder.ts → media-type-codecs/binary-decoder.ts} +3 -3
- package/src/{binary-encoder.ts → media-type-codecs/binary-encoder.ts} +0 -0
- package/src/media-type-codecs/cbor-decoder.ts +515 -0
- package/src/media-type-codecs/cbor-encoder.ts +307 -0
- package/src/media-type-codecs/cbor-tags.ts +4 -0
- package/src/media-type-codecs/json-decoder.ts +470 -0
- package/src/media-type-codecs/json-encoder.ts +328 -0
- package/src/media-type-codecs/media-type-decoder.ts +20 -0
- package/src/{media-type-decoders.ts → media-type-codecs/media-type-decoders.ts} +21 -13
- package/src/media-type-codecs/media-type-encoder.ts +31 -0
- package/src/{media-type-encoders.ts → media-type-codecs/media-type-encoders.ts} +23 -15
- package/src/{url-encoder.ts → media-type-codecs/www-form-url-encoder.ts} +53 -47
- package/src/media-type.ts +326 -22
- package/src/problem.ts +144 -12
- package/src/request-factory.ts +21 -12
- package/src/sunday-error.ts +37 -0
- package/src/util/any.ts +10 -0
- package/src/util/error.ts +14 -0
- package/src/util/hex.ts +3 -2
- package/src/util/rxjs.ts +16 -5
- package/src/util/temporal.ts +18 -0
- package/dist/binary-decoder.js.map +0 -1
- package/dist/binary-encoder.js.map +0 -1
- package/dist/cbor-decoder.d.ts +0 -15
- package/dist/cbor-decoder.js +0 -126
- package/dist/cbor-decoder.js.map +0 -1
- package/dist/cbor-encoder.d.ts +0 -29
- package/dist/cbor-encoder.js +0 -81
- package/dist/cbor-encoder.js.map +0 -1
- package/dist/cbor-tags.d.ts +0 -3
- package/dist/cbor-tags.js +0 -4
- package/dist/cbor-tags.js.map +0 -1
- package/dist/http-error.d.ts +0 -10
- package/dist/http-error.js +0 -45
- package/dist/http-error.js.map +0 -1
- package/dist/json-decoder.d.ts +0 -31
- package/dist/json-decoder.js +0 -139
- package/dist/json-decoder.js.map +0 -1
- package/dist/json-encoder.d.ts +0 -35
- package/dist/json-encoder.js +0 -116
- package/dist/json-encoder.js.map +0 -1
- package/dist/media-type-decoder.d.ts +0 -4
- package/dist/media-type-decoder.js +0 -2
- package/dist/media-type-decoder.js.map +0 -1
- package/dist/media-type-decoders.js.map +0 -1
- package/dist/media-type-encoder.js +0 -6
- package/dist/media-type-encoder.js.map +0 -1
- package/dist/media-type-encoders.js.map +0 -1
- package/dist/url-encoder.js.map +0 -1
- package/src/cbor-decoder.ts +0 -148
- package/src/cbor-encoder.ts +0 -95
- package/src/cbor-tags.ts +0 -3
- package/src/http-error.ts +0 -55
- package/src/json-decoder.ts +0 -164
- package/src/json-encoder.ts +0 -144
- package/src/media-type-decoder.ts +0 -5
- package/src/media-type-encoder.ts +0 -16
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { ChronoField, DateTimeFormatter, DateTimeFormatterBuilder, Instant, LocalDate, LocalDateTime, LocalTime, OffsetDateTime, OffsetTime, ResolverStyle, ZonedDateTime, ZoneId, } from '@js-joda/core';
|
|
2
|
+
import { CBOR, TaggedValue } from '@outfoxx/cbor-redux';
|
|
3
|
+
import { JsonStringifier } from '@outfoxx/jackson-js';
|
|
4
|
+
import 'reflect-metadata';
|
|
5
|
+
import { encodeSeconds, secondsToNumber } from '../util/temporal';
|
|
6
|
+
import { epochDateTimeTag, isoDateTimeTag, uriTag } from './cbor-tags';
|
|
7
|
+
export class CBOREncoder {
|
|
8
|
+
constructor(dateEncoding) {
|
|
9
|
+
this.dateEncoding = dateEncoding;
|
|
10
|
+
this.stringifier = new JsonStringifier();
|
|
11
|
+
this.instantSerializer = (_, value) => {
|
|
12
|
+
if (value == null) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
switch (this.dateEncoding) {
|
|
16
|
+
case CBOREncoder.DateEncoding.ISO8601:
|
|
17
|
+
return new TaggedValue(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value.atZone(ZoneId.UTC)), isoDateTimeTag);
|
|
18
|
+
case CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH:
|
|
19
|
+
return new TaggedValue(value.toEpochMilli(), epochDateTimeTag);
|
|
20
|
+
case CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH:
|
|
21
|
+
return new TaggedValue(secondsToNumber(value.epochSecond(), value.nano()), epochDateTimeTag);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
this.zonedDateTimeSerializer = (_, value) => {
|
|
25
|
+
if (value == null) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
switch (this.dateEncoding) {
|
|
29
|
+
case CBOREncoder.DateEncoding.ISO8601:
|
|
30
|
+
return new TaggedValue(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value), isoDateTimeTag);
|
|
31
|
+
case CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH:
|
|
32
|
+
return new TaggedValue(value.toInstant().toEpochMilli(), epochDateTimeTag);
|
|
33
|
+
case CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH:
|
|
34
|
+
const instant = value.toInstant();
|
|
35
|
+
return new TaggedValue(secondsToNumber(instant.epochSecond(), instant.nano()), epochDateTimeTag);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
this.offsetDateTimeSerializer = (_, value) => {
|
|
39
|
+
if (value == null) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
switch (this.dateEncoding) {
|
|
43
|
+
case CBOREncoder.DateEncoding.ISO8601:
|
|
44
|
+
return new TaggedValue(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(value), isoDateTimeTag);
|
|
45
|
+
case CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH:
|
|
46
|
+
return new TaggedValue(value.toInstant().toEpochMilli(), epochDateTimeTag);
|
|
47
|
+
case CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH:
|
|
48
|
+
const instant = value.toInstant();
|
|
49
|
+
return new TaggedValue(secondsToNumber(instant.epochSecond(), instant.nano()), epochDateTimeTag);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.offsetTimeFormatter = new DateTimeFormatterBuilder()
|
|
53
|
+
.parseCaseInsensitive()
|
|
54
|
+
.append(DateTimeFormatter.ISO_LOCAL_TIME)
|
|
55
|
+
.appendOffsetId()
|
|
56
|
+
.toFormatter(ResolverStyle.STRICT);
|
|
57
|
+
this.offsetTimeSerializer = (_, value) => {
|
|
58
|
+
if (value == null) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
switch (this.dateEncoding) {
|
|
62
|
+
case CBOREncoder.DateEncoding.ISO8601:
|
|
63
|
+
return this.offsetTimeFormatter.format(value);
|
|
64
|
+
default:
|
|
65
|
+
return [
|
|
66
|
+
value.hour(),
|
|
67
|
+
value.minute(),
|
|
68
|
+
...encodeSeconds(value.second(), this.dateEncoding ==
|
|
69
|
+
CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH
|
|
70
|
+
? value.get(ChronoField.MILLI_OF_SECOND)
|
|
71
|
+
: value.nano()),
|
|
72
|
+
value.offset().toString(),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
this.localDateTimeSerializer = (_, value) => {
|
|
77
|
+
if (value == null) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
switch (this.dateEncoding) {
|
|
81
|
+
case CBOREncoder.DateEncoding.ISO8601:
|
|
82
|
+
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value);
|
|
83
|
+
default:
|
|
84
|
+
return [
|
|
85
|
+
value.year(),
|
|
86
|
+
value.monthValue(),
|
|
87
|
+
value.dayOfMonth(),
|
|
88
|
+
value.hour(),
|
|
89
|
+
value.minute(),
|
|
90
|
+
...encodeSeconds(value.second(), this.dateEncoding ==
|
|
91
|
+
CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH
|
|
92
|
+
? value.get(ChronoField.MILLI_OF_SECOND)
|
|
93
|
+
: value.nano()),
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
this.localDateSerializer = (_, value) => {
|
|
98
|
+
if (value == null) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
switch (this.dateEncoding) {
|
|
102
|
+
case CBOREncoder.DateEncoding.ISO8601:
|
|
103
|
+
return DateTimeFormatter.ISO_LOCAL_DATE.format(value);
|
|
104
|
+
default:
|
|
105
|
+
return [value.year(), value.monthValue(), value.dayOfMonth()];
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
this.localTimeSerializer = (_, value) => {
|
|
109
|
+
if (value == null) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
switch (this.dateEncoding) {
|
|
113
|
+
case CBOREncoder.DateEncoding.ISO8601:
|
|
114
|
+
return DateTimeFormatter.ISO_LOCAL_TIME.format(value);
|
|
115
|
+
default:
|
|
116
|
+
return [
|
|
117
|
+
value.hour(),
|
|
118
|
+
value.minute(),
|
|
119
|
+
...encodeSeconds(value.second(), this.dateEncoding ==
|
|
120
|
+
CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH
|
|
121
|
+
? value.get(ChronoField.MILLI_OF_SECOND)
|
|
122
|
+
: value.nano()),
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
this.dateSerializer = (_, value) => {
|
|
127
|
+
if (value == null) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
switch (this.dateEncoding) {
|
|
131
|
+
case CBOREncoder.DateEncoding.ISO8601:
|
|
132
|
+
return new TaggedValue(value.toISOString(), isoDateTimeTag);
|
|
133
|
+
case CBOREncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH:
|
|
134
|
+
return new TaggedValue(value.getTime(), epochDateTimeTag);
|
|
135
|
+
case CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH:
|
|
136
|
+
return new TaggedValue(value.getTime() / 1000.0, epochDateTimeTag);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
this.urlSerializer = (_, value) => {
|
|
140
|
+
if (value == null) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return new TaggedValue(value.toString(), uriTag);
|
|
144
|
+
};
|
|
145
|
+
this.customSerializers = [
|
|
146
|
+
{
|
|
147
|
+
type: () => Date,
|
|
148
|
+
mapper: this.dateSerializer,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
type: () => Instant,
|
|
152
|
+
mapper: this.instantSerializer,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
type: () => ZonedDateTime,
|
|
156
|
+
mapper: this.zonedDateTimeSerializer,
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
type: () => OffsetDateTime,
|
|
160
|
+
mapper: this.offsetDateTimeSerializer,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
type: () => OffsetTime,
|
|
164
|
+
mapper: this.offsetTimeSerializer,
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
type: () => LocalDateTime,
|
|
168
|
+
mapper: this.localDateTimeSerializer,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
type: () => LocalDate,
|
|
172
|
+
mapper: this.localDateSerializer,
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
type: () => LocalTime,
|
|
176
|
+
mapper: this.localTimeSerializer,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
type: () => URL,
|
|
180
|
+
mapper: this.urlSerializer,
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
static get default() {
|
|
185
|
+
return new CBOREncoder(CBOREncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH);
|
|
186
|
+
}
|
|
187
|
+
encode(value, type) {
|
|
188
|
+
return CBOR.encode(this.encodeJSON(value, type));
|
|
189
|
+
}
|
|
190
|
+
encodeJSON(value, type) {
|
|
191
|
+
var _a;
|
|
192
|
+
// Use natural type when subtypes exist
|
|
193
|
+
if (Reflect.hasMetadata('jackson:defaultContextGroup:JsonSubTypes',
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
195
|
+
(_a = value.constructor) !== null && _a !== void 0 ? _a : {})) {
|
|
196
|
+
type = [Object];
|
|
197
|
+
}
|
|
198
|
+
return this.stringifier.transform(value, {
|
|
199
|
+
serializers: this.customSerializers,
|
|
200
|
+
mainCreator: () => type !== null && type !== void 0 ? type : [Object],
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
(function (CBOREncoder) {
|
|
205
|
+
/**
|
|
206
|
+
* Configures how temporal values are encoded.
|
|
207
|
+
*/
|
|
208
|
+
let DateEncoding;
|
|
209
|
+
(function (DateEncoding) {
|
|
210
|
+
/**
|
|
211
|
+
* Encode temporal values numerically using seconds with decimal
|
|
212
|
+
* sub-second precision.
|
|
213
|
+
*/
|
|
214
|
+
DateEncoding[DateEncoding["DECIMAL_SECONDS_SINCE_EPOCH"] = 0] = "DECIMAL_SECONDS_SINCE_EPOCH";
|
|
215
|
+
/**
|
|
216
|
+
* Encode temporal values numerically using integer milliseconds.
|
|
217
|
+
*/
|
|
218
|
+
DateEncoding[DateEncoding["MILLISECONDS_SINCE_EPOCH"] = 1] = "MILLISECONDS_SINCE_EPOCH";
|
|
219
|
+
/**
|
|
220
|
+
* Encode temporal values values as an ISO-8601-formatted string (in
|
|
221
|
+
* RFC 3339 format). This is the default behavior.
|
|
222
|
+
*/
|
|
223
|
+
DateEncoding[DateEncoding["ISO8601"] = 2] = "ISO8601";
|
|
224
|
+
})(DateEncoding = CBOREncoder.DateEncoding || (CBOREncoder.DateEncoding = {}));
|
|
225
|
+
})(CBOREncoder || (CBOREncoder = {}));
|
|
226
|
+
//# sourceMappingURL=cbor-encoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cbor-encoder.js","sourceRoot":"","sources":["../../src/media-type-codecs/cbor-encoder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,wBAAwB,EACxB,OAAO,EACP,SAAS,EACT,aAAa,EACb,SAAS,EACT,cAAc,EACd,UAAU,EACV,aAAa,EACb,aAAa,EACb,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGvE,MAAM,OAAO,WAAW;IAUtB,YAAqB,YAAsC;QAAtC,iBAAY,GAAZ,YAAY,CAA0B;QAFnD,gBAAW,GAAG,IAAI,eAAe,EAAE,CAAC;QAiEpC,sBAAiB,GAAe,CAAC,CAAC,EAAE,KAAc,EAAE,EAAE;YAC5D,IAAI,KAAK,IAAI,IAAI,EAAE;gBACjB,OAAO,IAAI,CAAC;aACb;YAED,QAAQ,IAAI,CAAC,YAAY,EAAE;gBACzB,KAAK,WAAW,CAAC,YAAY,CAAC,OAAO;oB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zB,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AnyType } from '../any-type';
|
|
2
|
+
import { StructuredMediaTypeDecoder, TextMediaTypeDecoder } from './media-type-decoder';
|
|
3
|
+
export declare class JSONDecoder implements TextMediaTypeDecoder, StructuredMediaTypeDecoder {
|
|
4
|
+
readonly numericDateDecoding: JSONDecoder.NumericDateDecoding;
|
|
5
|
+
static get default(): JSONDecoder;
|
|
6
|
+
private readonly customDeserializers;
|
|
7
|
+
private readonly parser;
|
|
8
|
+
constructor(numericDateDecoding: JSONDecoder.NumericDateDecoding);
|
|
9
|
+
decode<T>(response: Response, type: AnyType): Promise<T>;
|
|
10
|
+
decodeText<T>(text: string, type: AnyType): T;
|
|
11
|
+
decodeObject<T>(value: unknown, type: AnyType): T;
|
|
12
|
+
private instantDeserializer;
|
|
13
|
+
private zonedDateTimeDeserializer;
|
|
14
|
+
private offsetDateTimeDeserializer;
|
|
15
|
+
private offsetTimeFormatter;
|
|
16
|
+
private offsetTimeDeserializer;
|
|
17
|
+
private localDateTimeDeserializer;
|
|
18
|
+
private localDateDeserializer;
|
|
19
|
+
private localTimeDeserializer;
|
|
20
|
+
private dateDeserializer;
|
|
21
|
+
private urlDeserializer;
|
|
22
|
+
private arrayBufferDeserializer;
|
|
23
|
+
}
|
|
24
|
+
export declare namespace JSONDecoder {
|
|
25
|
+
/**
|
|
26
|
+
* Configures how numeric temporal values are decoded.
|
|
27
|
+
*/
|
|
28
|
+
enum NumericDateDecoding {
|
|
29
|
+
/**
|
|
30
|
+
* Decode numeric temporal values assuming they are seconds with decimal
|
|
31
|
+
* sub-second precision.
|
|
32
|
+
*/
|
|
33
|
+
DECIMAL_SECONDS_SINCE_EPOCH = 0,
|
|
34
|
+
/**
|
|
35
|
+
* Decode numeric temporal values assuming they are integer milliseconds.
|
|
36
|
+
*/
|
|
37
|
+
MILLISECONDS_SINCE_EPOCH = 1
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { DateTimeFormatter, DateTimeFormatterBuilder, Duration, Instant, LocalDate, LocalDateTime, LocalTime, nativeJs, OffsetDateTime, OffsetTime, ResolverStyle, ZonedDateTime, ZoneId, ZoneOffset, } from '@js-joda/core';
|
|
2
|
+
import { JsonParser } from '@outfoxx/jackson-js';
|
|
3
|
+
import { Base64 } from '../util/base64';
|
|
4
|
+
export class JSONDecoder {
|
|
5
|
+
constructor(numericDateDecoding) {
|
|
6
|
+
this.numericDateDecoding = numericDateDecoding;
|
|
7
|
+
this.parser = new JsonParser();
|
|
8
|
+
this.instantDeserializer = (key, value) => {
|
|
9
|
+
if (value == null) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
if (value instanceof Instant) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
if (value instanceof Date) {
|
|
16
|
+
return Instant.from(nativeJs(value));
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === 'number') {
|
|
19
|
+
if (this.numericDateDecoding ===
|
|
20
|
+
JSONDecoder.NumericDateDecoding.MILLISECONDS_SINCE_EPOCH) {
|
|
21
|
+
return Instant.ofEpochMilli(value);
|
|
22
|
+
}
|
|
23
|
+
else if (this.numericDateDecoding ===
|
|
24
|
+
JSONDecoder.NumericDateDecoding.DECIMAL_SECONDS_SINCE_EPOCH) {
|
|
25
|
+
const duration = Duration.parse(`PT${value}S`);
|
|
26
|
+
return Instant.ofEpochSecond(duration.seconds(), duration.nano());
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw Error('Unsupported date decoding format');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'string') {
|
|
33
|
+
return Instant.from(DateTimeFormatter.ISO_INSTANT.parse(value));
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`Invalid date value for property ${key}`);
|
|
36
|
+
};
|
|
37
|
+
this.zonedDateTimeDeserializer = (key, value) => {
|
|
38
|
+
if (value == null) {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
if (value instanceof ZonedDateTime) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
if (value instanceof Date) {
|
|
45
|
+
const instant = Instant.from(nativeJs(value));
|
|
46
|
+
return ZonedDateTime.ofInstant(instant, ZoneId.UTC);
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'number') {
|
|
49
|
+
if (this.numericDateDecoding ===
|
|
50
|
+
JSONDecoder.NumericDateDecoding.MILLISECONDS_SINCE_EPOCH) {
|
|
51
|
+
const instant = Instant.ofEpochMilli(value);
|
|
52
|
+
return ZonedDateTime.ofInstant(instant, ZoneId.UTC);
|
|
53
|
+
}
|
|
54
|
+
else if (this.numericDateDecoding ===
|
|
55
|
+
JSONDecoder.NumericDateDecoding.DECIMAL_SECONDS_SINCE_EPOCH) {
|
|
56
|
+
const duration = Duration.parse(`PT${value}S`);
|
|
57
|
+
const instant = Instant.ofEpochSecond(duration.seconds(), duration.nano());
|
|
58
|
+
return ZonedDateTime.ofInstant(instant, ZoneId.UTC);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw Error('Unsupported date decoding format');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (typeof value === 'string') {
|
|
65
|
+
return ZonedDateTime.from(DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(value));
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`Invalid date value for property ${key}`);
|
|
68
|
+
};
|
|
69
|
+
this.offsetDateTimeDeserializer = (key, value) => {
|
|
70
|
+
if (value == null) {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
if (value instanceof OffsetDateTime) {
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
if (value instanceof Date) {
|
|
77
|
+
const instant = Instant.from(nativeJs(value));
|
|
78
|
+
return OffsetDateTime.ofInstant(instant, ZoneId.UTC);
|
|
79
|
+
}
|
|
80
|
+
if (typeof value === 'number') {
|
|
81
|
+
if (this.numericDateDecoding ===
|
|
82
|
+
JSONDecoder.NumericDateDecoding.MILLISECONDS_SINCE_EPOCH) {
|
|
83
|
+
const instant = Instant.ofEpochMilli(value);
|
|
84
|
+
return OffsetDateTime.ofInstant(instant, ZoneId.UTC);
|
|
85
|
+
}
|
|
86
|
+
else if (this.numericDateDecoding ===
|
|
87
|
+
JSONDecoder.NumericDateDecoding.DECIMAL_SECONDS_SINCE_EPOCH) {
|
|
88
|
+
const duration = Duration.parse(`PT${value}S`);
|
|
89
|
+
const instant = Instant.ofEpochSecond(duration.seconds(), duration.nano());
|
|
90
|
+
return OffsetDateTime.ofInstant(instant, ZoneId.UTC);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw Error('Unsupported date decoding format');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (typeof value === 'string') {
|
|
97
|
+
return OffsetDateTime.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(value));
|
|
98
|
+
}
|
|
99
|
+
throw new Error(`Invalid date value for property ${key}`);
|
|
100
|
+
};
|
|
101
|
+
this.offsetTimeFormatter = new DateTimeFormatterBuilder()
|
|
102
|
+
.parseCaseInsensitive()
|
|
103
|
+
.append(DateTimeFormatter.ISO_LOCAL_TIME)
|
|
104
|
+
.appendOffsetId()
|
|
105
|
+
.toFormatter(ResolverStyle.STRICT);
|
|
106
|
+
this.offsetTimeDeserializer = (key, value) => {
|
|
107
|
+
if (value == null) {
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
if (value instanceof OffsetTime) {
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
if (value instanceof Array) {
|
|
114
|
+
let idx = 0;
|
|
115
|
+
const hour = value[idx++];
|
|
116
|
+
const minute = value[idx++];
|
|
117
|
+
let second = 0;
|
|
118
|
+
let nanoOfSecond = 0;
|
|
119
|
+
if (value.length > 3) {
|
|
120
|
+
second = value[idx++];
|
|
121
|
+
if (value.length > 4) {
|
|
122
|
+
nanoOfSecond = value[idx++];
|
|
123
|
+
if (this.numericDateDecoding ==
|
|
124
|
+
JSONDecoder.NumericDateDecoding.MILLISECONDS_SINCE_EPOCH) {
|
|
125
|
+
// millis to nanos
|
|
126
|
+
nanoOfSecond *= 1000000;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const offset = value[idx++];
|
|
131
|
+
return OffsetTime.of(hour, minute, second, nanoOfSecond, ZoneOffset.of(offset));
|
|
132
|
+
}
|
|
133
|
+
if (typeof value === 'string') {
|
|
134
|
+
return OffsetTime.from(this.offsetTimeFormatter.parse(value));
|
|
135
|
+
}
|
|
136
|
+
throw new Error(`Invalid date value for property ${key}`);
|
|
137
|
+
};
|
|
138
|
+
this.localDateTimeDeserializer = (key, value) => {
|
|
139
|
+
if (value == null) {
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
if (value instanceof LocalDateTime) {
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
if (value instanceof Date) {
|
|
146
|
+
const instant = Instant.ofEpochMilli(value.getTime());
|
|
147
|
+
return LocalDateTime.ofInstant(instant, ZoneId.UTC);
|
|
148
|
+
}
|
|
149
|
+
if (value instanceof Array) {
|
|
150
|
+
let idx = 0;
|
|
151
|
+
const year = value[idx++];
|
|
152
|
+
const month = value[idx++];
|
|
153
|
+
const day = value[idx++];
|
|
154
|
+
const hour = value[idx++];
|
|
155
|
+
const minute = value[idx++];
|
|
156
|
+
let second = 0;
|
|
157
|
+
let nanoOfSecond = 0;
|
|
158
|
+
if (value.length > 5) {
|
|
159
|
+
second = value[idx++];
|
|
160
|
+
if (value.length > 6) {
|
|
161
|
+
nanoOfSecond = value[idx++];
|
|
162
|
+
if (this.numericDateDecoding ==
|
|
163
|
+
JSONDecoder.NumericDateDecoding.MILLISECONDS_SINCE_EPOCH) {
|
|
164
|
+
// millis to nanos
|
|
165
|
+
nanoOfSecond *= 1000000;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return LocalDateTime.of(year, month, day, hour, minute, second, nanoOfSecond);
|
|
170
|
+
}
|
|
171
|
+
if (typeof value === 'string') {
|
|
172
|
+
return LocalDateTime.from(DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(value));
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`Invalid date value for property ${key}`);
|
|
175
|
+
};
|
|
176
|
+
this.localDateDeserializer = (key, value) => {
|
|
177
|
+
if (value == null) {
|
|
178
|
+
return value;
|
|
179
|
+
}
|
|
180
|
+
if (value instanceof LocalDate) {
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
if (value instanceof Date) {
|
|
184
|
+
const instant = Instant.ofEpochMilli(value.getTime());
|
|
185
|
+
return LocalDate.ofInstant(instant, ZoneId.UTC);
|
|
186
|
+
}
|
|
187
|
+
if (value instanceof Array) {
|
|
188
|
+
const year = value[0];
|
|
189
|
+
const month = value[1];
|
|
190
|
+
const day = value[2];
|
|
191
|
+
return LocalDate.of(year, month, day);
|
|
192
|
+
}
|
|
193
|
+
if (typeof value === 'number') {
|
|
194
|
+
return LocalDate.ofEpochDay(value);
|
|
195
|
+
}
|
|
196
|
+
if (typeof value === 'string') {
|
|
197
|
+
return LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse(value));
|
|
198
|
+
}
|
|
199
|
+
throw new Error(`Invalid date value for property ${key}`);
|
|
200
|
+
};
|
|
201
|
+
this.localTimeDeserializer = (key, value) => {
|
|
202
|
+
if (value == null) {
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
if (value instanceof LocalTime) {
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
if (value instanceof Date) {
|
|
209
|
+
const instant = Instant.ofEpochMilli(value.getTime());
|
|
210
|
+
return LocalTime.ofInstant(instant, ZoneId.UTC);
|
|
211
|
+
}
|
|
212
|
+
if (value instanceof Array) {
|
|
213
|
+
let idx = 0;
|
|
214
|
+
const hour = value[idx++];
|
|
215
|
+
const minute = value[idx++];
|
|
216
|
+
let second = 0;
|
|
217
|
+
let nanoOfSecond = 0;
|
|
218
|
+
if (value.length > 2) {
|
|
219
|
+
second = value[idx++];
|
|
220
|
+
if (value.length > 3) {
|
|
221
|
+
nanoOfSecond = value[idx++];
|
|
222
|
+
if (this.numericDateDecoding ==
|
|
223
|
+
JSONDecoder.NumericDateDecoding.MILLISECONDS_SINCE_EPOCH) {
|
|
224
|
+
// millis to nanos
|
|
225
|
+
nanoOfSecond *= 1000000;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return LocalTime.of(hour, minute, second, nanoOfSecond);
|
|
230
|
+
}
|
|
231
|
+
if (typeof value === 'number') {
|
|
232
|
+
return LocalTime.ofNanoOfDay(value);
|
|
233
|
+
}
|
|
234
|
+
if (typeof value === 'string') {
|
|
235
|
+
return LocalTime.from(DateTimeFormatter.ISO_LOCAL_TIME.parse(value));
|
|
236
|
+
}
|
|
237
|
+
throw new Error(`Invalid date value for property ${key}`);
|
|
238
|
+
};
|
|
239
|
+
this.dateDeserializer = (key, value) => {
|
|
240
|
+
if (value == null) {
|
|
241
|
+
return value;
|
|
242
|
+
}
|
|
243
|
+
if (value instanceof Date) {
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
246
|
+
if (typeof value === 'number') {
|
|
247
|
+
if (this.numericDateDecoding ===
|
|
248
|
+
JSONDecoder.NumericDateDecoding.MILLISECONDS_SINCE_EPOCH) {
|
|
249
|
+
return new Date(value);
|
|
250
|
+
}
|
|
251
|
+
else if (this.numericDateDecoding ===
|
|
252
|
+
JSONDecoder.NumericDateDecoding.DECIMAL_SECONDS_SINCE_EPOCH) {
|
|
253
|
+
return new Date(value * 1000);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
throw Error('Unsupported date decoding format');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (typeof value === 'string') {
|
|
260
|
+
return new Date(value);
|
|
261
|
+
}
|
|
262
|
+
throw new Error(`Invalid date value for property ${key}`);
|
|
263
|
+
};
|
|
264
|
+
this.urlDeserializer = (key, value) => {
|
|
265
|
+
if (value == null) {
|
|
266
|
+
return value;
|
|
267
|
+
}
|
|
268
|
+
if (value instanceof URL) {
|
|
269
|
+
return value;
|
|
270
|
+
}
|
|
271
|
+
if (typeof value === 'string') {
|
|
272
|
+
return new URL(value);
|
|
273
|
+
}
|
|
274
|
+
throw Error(`Invalid URL value for property ${key}`);
|
|
275
|
+
};
|
|
276
|
+
this.arrayBufferDeserializer = (key, value) => {
|
|
277
|
+
if (value == null) {
|
|
278
|
+
return value;
|
|
279
|
+
}
|
|
280
|
+
if (value instanceof ArrayBuffer) {
|
|
281
|
+
return value;
|
|
282
|
+
}
|
|
283
|
+
if (typeof value === 'string') {
|
|
284
|
+
return Base64.decode(value);
|
|
285
|
+
}
|
|
286
|
+
throw Error(`Invalid ArrayBuffer value for property ${key}`);
|
|
287
|
+
};
|
|
288
|
+
this.customDeserializers = [
|
|
289
|
+
{
|
|
290
|
+
type: () => Date,
|
|
291
|
+
mapper: this.dateDeserializer,
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
type: () => Instant,
|
|
295
|
+
mapper: this.instantDeserializer,
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
type: () => ZonedDateTime,
|
|
299
|
+
mapper: this.zonedDateTimeDeserializer,
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
type: () => OffsetDateTime,
|
|
303
|
+
mapper: this.offsetDateTimeDeserializer,
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
type: () => OffsetTime,
|
|
307
|
+
mapper: this.offsetTimeDeserializer,
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
type: () => LocalDateTime,
|
|
311
|
+
mapper: this.localDateTimeDeserializer,
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
type: () => LocalDate,
|
|
315
|
+
mapper: this.localDateDeserializer,
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
type: () => LocalTime,
|
|
319
|
+
mapper: this.localTimeDeserializer,
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
type: () => URL,
|
|
323
|
+
mapper: this.urlDeserializer,
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
type: () => ArrayBuffer,
|
|
327
|
+
mapper: this.arrayBufferDeserializer,
|
|
328
|
+
},
|
|
329
|
+
];
|
|
330
|
+
}
|
|
331
|
+
static get default() {
|
|
332
|
+
return new JSONDecoder(JSONDecoder.NumericDateDecoding.DECIMAL_SECONDS_SINCE_EPOCH);
|
|
333
|
+
}
|
|
334
|
+
async decode(response, type) {
|
|
335
|
+
return Promise.resolve(this.decodeObject(await response.json(), type));
|
|
336
|
+
}
|
|
337
|
+
decodeText(text, type) {
|
|
338
|
+
return this.parser.parse(text, {
|
|
339
|
+
deserializers: this.customDeserializers,
|
|
340
|
+
mainCreator: () => type,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
decodeObject(value, type) {
|
|
344
|
+
return this.parser.transform(value, {
|
|
345
|
+
deserializers: this.customDeserializers,
|
|
346
|
+
mainCreator: () => type,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
(function (JSONDecoder) {
|
|
351
|
+
/**
|
|
352
|
+
* Configures how numeric temporal values are decoded.
|
|
353
|
+
*/
|
|
354
|
+
let NumericDateDecoding;
|
|
355
|
+
(function (NumericDateDecoding) {
|
|
356
|
+
/**
|
|
357
|
+
* Decode numeric temporal values assuming they are seconds with decimal
|
|
358
|
+
* sub-second precision.
|
|
359
|
+
*/
|
|
360
|
+
NumericDateDecoding[NumericDateDecoding["DECIMAL_SECONDS_SINCE_EPOCH"] = 0] = "DECIMAL_SECONDS_SINCE_EPOCH";
|
|
361
|
+
/**
|
|
362
|
+
* Decode numeric temporal values assuming they are integer milliseconds.
|
|
363
|
+
*/
|
|
364
|
+
NumericDateDecoding[NumericDateDecoding["MILLISECONDS_SINCE_EPOCH"] = 1] = "MILLISECONDS_SINCE_EPOCH";
|
|
365
|
+
})(NumericDateDecoding = JSONDecoder.NumericDateDecoding || (JSONDecoder.NumericDateDecoding = {}));
|
|
366
|
+
})(JSONDecoder || (JSONDecoder = {}));
|
|
367
|
+
//# sourceMappingURL=json-decoder.js.map
|