@outfoxx/sunday 1.1.0-alpha.8 → 1.1.0-beta.1

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.
Files changed (123) hide show
  1. package/LICENSE.txt +203 -0
  2. package/README.md +6 -7
  3. package/dist/any-type.js +13 -0
  4. package/dist/any-type.js.map +1 -1
  5. package/dist/class-type.js +13 -0
  6. package/dist/class-type.js.map +1 -1
  7. package/dist/date-time-types.js +13 -0
  8. package/dist/date-time-types.js.map +1 -1
  9. package/dist/event-parser.d.ts +1 -1
  10. package/dist/event-parser.js +17 -4
  11. package/dist/event-parser.js.map +1 -1
  12. package/dist/fetch-event-source.d.ts +5 -1
  13. package/dist/fetch-event-source.js +15 -3
  14. package/dist/fetch-event-source.js.map +1 -1
  15. package/dist/fetch-request-factory.d.ts +3 -0
  16. package/dist/fetch-request-factory.js +47 -9
  17. package/dist/fetch-request-factory.js.map +1 -1
  18. package/dist/fetch.js +24 -5
  19. package/dist/fetch.js.map +1 -1
  20. package/dist/header-parameters.js +13 -0
  21. package/dist/header-parameters.js.map +1 -1
  22. package/dist/index.js +13 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/logger.js +13 -0
  25. package/dist/logger.js.map +1 -1
  26. package/dist/media-type-codecs/any-text-decoder.d.ts +7 -0
  27. package/dist/media-type-codecs/any-text-decoder.js +29 -0
  28. package/dist/media-type-codecs/any-text-decoder.js.map +1 -0
  29. package/dist/media-type-codecs/any-text-encoder.d.ts +5 -0
  30. package/dist/media-type-codecs/any-text-encoder.js +23 -0
  31. package/dist/media-type-codecs/any-text-encoder.js.map +1 -0
  32. package/dist/media-type-codecs/binary-decoder.js +13 -0
  33. package/dist/media-type-codecs/binary-decoder.js.map +1 -1
  34. package/dist/media-type-codecs/binary-encoder.js +13 -0
  35. package/dist/media-type-codecs/binary-encoder.js.map +1 -1
  36. package/dist/media-type-codecs/cbor-decoder.js +13 -0
  37. package/dist/media-type-codecs/cbor-decoder.js.map +1 -1
  38. package/dist/media-type-codecs/cbor-encoder.js +13 -0
  39. package/dist/media-type-codecs/cbor-encoder.js.map +1 -1
  40. package/dist/media-type-codecs/cbor-tags.js +13 -0
  41. package/dist/media-type-codecs/cbor-tags.js.map +1 -1
  42. package/dist/media-type-codecs/json-decoder.js +13 -0
  43. package/dist/media-type-codecs/json-decoder.js.map +1 -1
  44. package/dist/media-type-codecs/json-encoder.js +13 -0
  45. package/dist/media-type-codecs/json-encoder.js.map +1 -1
  46. package/dist/media-type-codecs/media-type-decoder.js +13 -0
  47. package/dist/media-type-codecs/media-type-decoder.js.map +1 -1
  48. package/dist/media-type-codecs/media-type-decoders.js +21 -3
  49. package/dist/media-type-codecs/media-type-decoders.js.map +1 -1
  50. package/dist/media-type-codecs/media-type-encoder.js +13 -0
  51. package/dist/media-type-codecs/media-type-encoder.js.map +1 -1
  52. package/dist/media-type-codecs/media-type-encoders.js +21 -3
  53. package/dist/media-type-codecs/media-type-encoders.js.map +1 -1
  54. package/dist/media-type-codecs/www-form-url-encoder.js +56 -6
  55. package/dist/media-type-codecs/www-form-url-encoder.js.map +1 -1
  56. package/dist/media-type.d.ts +4 -2
  57. package/dist/media-type.js +34 -5
  58. package/dist/media-type.js.map +1 -1
  59. package/dist/problem.js +19 -2
  60. package/dist/problem.js.map +1 -1
  61. package/dist/request-factory.d.ts +6 -0
  62. package/dist/request-factory.js +13 -0
  63. package/dist/request-factory.js.map +1 -1
  64. package/dist/result-response.d.ts +4 -0
  65. package/dist/result-response.js +15 -0
  66. package/dist/result-response.js.map +1 -0
  67. package/dist/sunday-error.js +13 -0
  68. package/dist/sunday-error.js.map +1 -1
  69. package/dist/url-template.js +13 -0
  70. package/dist/url-template.js.map +1 -1
  71. package/dist/util/any.js +13 -0
  72. package/dist/util/any.js.map +1 -1
  73. package/dist/util/base64.js +13 -0
  74. package/dist/util/base64.js.map +1 -1
  75. package/dist/util/error.d.ts +2 -0
  76. package/dist/util/error.js +26 -0
  77. package/dist/util/error.js.map +1 -0
  78. package/dist/util/hex.js +13 -0
  79. package/dist/util/hex.js.map +1 -1
  80. package/dist/util/rxjs.js +14 -2
  81. package/dist/util/rxjs.js.map +1 -1
  82. package/dist/util/stream-rxjs.js +13 -0
  83. package/dist/util/stream-rxjs.js.map +1 -1
  84. package/dist/util/temporal.js +13 -0
  85. package/dist/util/temporal.js.map +1 -1
  86. package/package.json +33 -28
  87. package/src/any-type.ts +14 -0
  88. package/src/class-type.ts +16 -2
  89. package/src/date-time-types.ts +14 -0
  90. package/src/event-parser.ts +22 -10
  91. package/src/fetch-event-source.ts +39 -11
  92. package/src/fetch-request-factory.ts +92 -32
  93. package/src/fetch.ts +27 -8
  94. package/src/header-parameters.ts +16 -2
  95. package/src/index.ts +14 -0
  96. package/src/logger.ts +14 -0
  97. package/src/media-type-codecs/any-text-decoder.ts +34 -0
  98. package/src/media-type-codecs/any-text-encoder.ts +26 -0
  99. package/src/media-type-codecs/binary-decoder.ts +16 -2
  100. package/src/media-type-codecs/binary-encoder.ts +15 -1
  101. package/src/media-type-codecs/cbor-decoder.ts +30 -16
  102. package/src/media-type-codecs/cbor-encoder.ts +28 -14
  103. package/src/media-type-codecs/cbor-tags.ts +14 -0
  104. package/src/media-type-codecs/json-decoder.ts +31 -16
  105. package/src/media-type-codecs/json-encoder.ts +21 -7
  106. package/src/media-type-codecs/media-type-decoder.ts +16 -2
  107. package/src/media-type-codecs/media-type-decoders.ts +28 -8
  108. package/src/media-type-codecs/media-type-encoder.ts +19 -5
  109. package/src/media-type-codecs/media-type-encoders.ts +28 -8
  110. package/src/media-type-codecs/www-form-url-encoder.ts +81 -17
  111. package/src/media-type.ts +46 -12
  112. package/src/problem.ts +22 -4
  113. package/src/request-factory.ts +46 -7
  114. package/src/result-response.ts +18 -0
  115. package/src/sunday-error.ts +18 -4
  116. package/src/url-template.ts +15 -1
  117. package/src/util/any.ts +14 -0
  118. package/src/util/base64.ts +15 -1
  119. package/src/util/error.ts +28 -0
  120. package/src/util/hex.ts +14 -0
  121. package/src/util/rxjs.ts +18 -5
  122. package/src/util/stream-rxjs.ts +15 -1
  123. package/src/util/temporal.ts +14 -0
@@ -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;
@@ -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,
@@ -24,10 +38,11 @@ import {
24
38
  import { Base64 } from '../util/base64';
25
39
 
26
40
  export class JSONDecoder
27
- implements TextMediaTypeDecoder, StructuredMediaTypeDecoder {
41
+ implements TextMediaTypeDecoder, StructuredMediaTypeDecoder
42
+ {
28
43
  static get default(): JSONDecoder {
29
44
  return new JSONDecoder(
30
- JSONDecoder.NumericDateDecoding.DECIMAL_SECONDS_SINCE_EPOCH
45
+ JSONDecoder.NumericDateDecoding.DECIMAL_SECONDS_SINCE_EPOCH,
31
46
  );
32
47
  }
33
48
 
@@ -131,7 +146,7 @@ export class JSONDecoder
131
146
 
132
147
  private zonedDateTimeDeserializer: Deserializer = (
133
148
  key: string,
134
- value: unknown
149
+ value: unknown,
135
150
  ) => {
136
151
  if (value == null) {
137
152
  return value;
@@ -157,7 +172,7 @@ export class JSONDecoder
157
172
  const duration = Duration.parse(`PT${value}S`);
158
173
  const instant = Instant.ofEpochSecond(
159
174
  duration.seconds(),
160
- duration.nano()
175
+ duration.nano(),
161
176
  );
162
177
  return ZonedDateTime.ofInstant(instant, ZoneId.UTC);
163
178
  } else {
@@ -166,7 +181,7 @@ export class JSONDecoder
166
181
  }
167
182
  if (typeof value === 'string') {
168
183
  return ZonedDateTime.from(
169
- DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(value)
184
+ DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(value),
170
185
  );
171
186
  }
172
187
  throw new Error(`Invalid date value for property ${key}`);
@@ -174,7 +189,7 @@ export class JSONDecoder
174
189
 
175
190
  private offsetDateTimeDeserializer: Deserializer = (
176
191
  key: string,
177
- value: unknown
192
+ value: unknown,
178
193
  ) => {
179
194
  if (value == null) {
180
195
  return value;
@@ -200,7 +215,7 @@ export class JSONDecoder
200
215
  const duration = Duration.parse(`PT${value}S`);
201
216
  const instant = Instant.ofEpochSecond(
202
217
  duration.seconds(),
203
- duration.nano()
218
+ duration.nano(),
204
219
  );
205
220
  return OffsetDateTime.ofInstant(instant, ZoneId.UTC);
206
221
  } else {
@@ -209,7 +224,7 @@ export class JSONDecoder
209
224
  }
210
225
  if (typeof value === 'string') {
211
226
  return OffsetDateTime.from(
212
- DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(value)
227
+ DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(value),
213
228
  );
214
229
  }
215
230
  throw new Error(`Invalid date value for property ${key}`);
@@ -223,7 +238,7 @@ export class JSONDecoder
223
238
 
224
239
  private offsetTimeDeserializer: Deserializer = (
225
240
  key: string,
226
- value: unknown
241
+ value: unknown,
227
242
  ) => {
228
243
  if (value == null) {
229
244
  return value;
@@ -256,7 +271,7 @@ export class JSONDecoder
256
271
  minute,
257
272
  second,
258
273
  nanoOfSecond,
259
- ZoneOffset.of(offset)
274
+ ZoneOffset.of(offset),
260
275
  );
261
276
  }
262
277
  if (typeof value === 'string') {
@@ -267,7 +282,7 @@ export class JSONDecoder
267
282
 
268
283
  private localDateTimeDeserializer: Deserializer = (
269
284
  key: string,
270
- value: unknown
285
+ value: unknown,
271
286
  ) => {
272
287
  if (value == null) {
273
288
  return value;
@@ -308,12 +323,12 @@ export class JSONDecoder
308
323
  hour,
309
324
  minute,
310
325
  second,
311
- nanoOfSecond
326
+ nanoOfSecond,
312
327
  );
313
328
  }
314
329
  if (typeof value === 'string') {
315
330
  return LocalDateTime.from(
316
- DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(value)
331
+ DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(value),
317
332
  );
318
333
  }
319
334
  throw new Error(`Invalid date value for property ${key}`);
@@ -321,7 +336,7 @@ export class JSONDecoder
321
336
 
322
337
  private localDateDeserializer: Deserializer = (
323
338
  key: string,
324
- value: unknown
339
+ value: unknown,
325
340
  ) => {
326
341
  if (value == null) {
327
342
  return value;
@@ -350,7 +365,7 @@ export class JSONDecoder
350
365
 
351
366
  private localTimeDeserializer: Deserializer = (
352
367
  key: string,
353
- value: unknown
368
+ value: unknown,
354
369
  ) => {
355
370
  if (value == null) {
356
371
  return value;
@@ -435,7 +450,7 @@ export class JSONDecoder
435
450
 
436
451
  private arrayBufferDeserializer: Deserializer = (
437
452
  key: string,
438
- value: unknown
453
+ value: unknown,
439
454
  ) => {
440
455
  if (value == null) {
441
456
  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
  ChronoField,
3
17
  DateTimeFormatter,
@@ -22,7 +36,7 @@ import { StructuredMediaTypeEncoder } from './media-type-encoder';
22
36
  export class JSONEncoder implements StructuredMediaTypeEncoder {
23
37
  static get default(): JSONEncoder {
24
38
  return new JSONEncoder(
25
- JSONEncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH
39
+ JSONEncoder.DateEncoding.DECIMAL_SECONDS_SINCE_EPOCH,
26
40
  );
27
41
  }
28
42
 
@@ -80,7 +94,7 @@ export class JSONEncoder implements StructuredMediaTypeEncoder {
80
94
  Reflect.hasMetadata(
81
95
  'jackson:defaultContextGroup:JsonSubTypes',
82
96
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
- (value as any).constructor ?? {}
97
+ (value as any).constructor ?? {},
84
98
  )
85
99
  ) {
86
100
  type = [Object];
@@ -104,14 +118,14 @@ export class JSONEncoder implements StructuredMediaTypeEncoder {
104
118
  encodeObject<T>(
105
119
  value: T,
106
120
  type?: AnyType,
107
- includeNulls = false
121
+ includeNulls = false,
108
122
  ): Record<string, unknown> {
109
123
  // Use natural type when subtypes exist
110
124
  if (
111
125
  Reflect.hasMetadata(
112
126
  'jackson:defaultContextGroup:JsonSubTypes',
113
127
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
- (value as any).constructor ?? {}
128
+ (value as any).constructor ?? {},
115
129
  )
116
130
  ) {
117
131
  type = [Object];
@@ -202,7 +216,7 @@ export class JSONEncoder implements StructuredMediaTypeEncoder {
202
216
  this.dateEncoding ==
203
217
  JSONEncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH
204
218
  ? value.get(ChronoField.MILLI_OF_SECOND)
205
- : value.nano()
219
+ : value.nano(),
206
220
  ),
207
221
  value.offset().toString(),
208
222
  ];
@@ -229,7 +243,7 @@ export class JSONEncoder implements StructuredMediaTypeEncoder {
229
243
  this.dateEncoding ==
230
244
  JSONEncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH
231
245
  ? value.get(ChronoField.MILLI_OF_SECOND)
232
- : value.nano()
246
+ : value.nano(),
233
247
  ),
234
248
  ];
235
249
  }
@@ -265,7 +279,7 @@ export class JSONEncoder implements StructuredMediaTypeEncoder {
265
279
  this.dateEncoding ==
266
280
  JSONEncoder.DateEncoding.MILLISECONDS_SINCE_EPOCH
267
281
  ? value.get(ChronoField.MILLI_OF_SECOND)
268
- : value.nano()
282
+ : value.nano(),
269
283
  ),
270
284
  ];
271
285
  }
@@ -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 { AnyType } from '../any-type';
2
16
 
3
17
  export interface MediaTypeDecoder {
@@ -13,8 +27,8 @@ export interface StructuredMediaTypeDecoder extends MediaTypeDecoder {
13
27
  }
14
28
 
15
29
  export function isStructuredMediaTypeDecoder(
16
- decoder: MediaTypeDecoder | StructuredMediaTypeDecoder | undefined
30
+ decoder: MediaTypeDecoder | StructuredMediaTypeDecoder | undefined,
17
31
  ): decoder is StructuredMediaTypeDecoder {
18
- const rec = (decoder as unknown) as Record<string, unknown>;
32
+ const rec = decoder as unknown as Record<string, unknown>;
19
33
  return !!rec.decodeObject ?? false;
20
34
  }
@@ -1,3 +1,18 @@
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 { AnyTextDecoder } from './any-text-decoder';
1
16
  import { BinaryDecoder } from './binary-decoder';
2
17
  import { CBORDecoder } from './cbor-decoder';
3
18
  import { JSONDecoder } from './json-decoder';
@@ -9,7 +24,7 @@ export interface MediaTypeDecodersBuilder {
9
24
 
10
25
  add(
11
26
  mediaType: MediaType,
12
- decoder: MediaTypeDecoder
27
+ decoder: MediaTypeDecoder,
13
28
  ): MediaTypeDecodersBuilder;
14
29
 
15
30
  build(): MediaTypeDecoders;
@@ -20,21 +35,26 @@ export interface MediaTypeDecodersBuilderConstructor {
20
35
 
21
36
  export class MediaTypeDecoders {
22
37
  static Builder: MediaTypeDecodersBuilderConstructor = class Builder
23
- implements MediaTypeDecodersBuilder {
38
+ implements MediaTypeDecodersBuilder
39
+ {
24
40
  decoders = new Map<MediaType, MediaTypeDecoder>();
25
41
 
26
42
  add(
27
43
  mediaType: MediaType,
28
- decoder: MediaTypeDecoder
44
+ decoder: MediaTypeDecoder,
29
45
  ): MediaTypeDecodersBuilder {
30
46
  this.decoders.set(mediaType, decoder);
31
47
  return this;
32
48
  }
33
49
 
34
50
  addDefaults(): MediaTypeDecodersBuilder {
35
- return this.add(MediaType.JSON, JSONDecoder.default)
36
- .add(MediaType.OctetStream, new BinaryDecoder())
37
- .add(MediaType.CBOR, CBORDecoder.default);
51
+ return this.add(MediaType.OctetStream, BinaryDecoder.default)
52
+ .add(MediaType.JSON, JSONDecoder.default)
53
+ .add(MediaType.CBOR, CBORDecoder.default)
54
+ .add(MediaType.EventStream, BinaryDecoder.default)
55
+ .add(MediaType.AnyText, AnyTextDecoder.default)
56
+ .add(MediaType.X509CACert, BinaryDecoder.default)
57
+ .add(MediaType.X509UserCert, BinaryDecoder.default);
38
58
  }
39
59
 
40
60
  build(): MediaTypeDecoders {
@@ -50,13 +70,13 @@ export class MediaTypeDecoders {
50
70
 
51
71
  supports(mediaType: MediaType): boolean {
52
72
  return Array.from(this.decoders.keys()).some((key) =>
53
- key.compatible(mediaType)
73
+ key.compatible(mediaType),
54
74
  );
55
75
  }
56
76
 
57
77
  find(mediaType: MediaType): MediaTypeDecoder {
58
78
  const found = Array.from(this.decoders.entries()).find(([type]) =>
59
- type.compatible(mediaType)
79
+ type.compatible(mediaType),
60
80
  );
61
81
  if (!found) {
62
82
  throw Error(`Unsupported media type - ${mediaType}`);
@@ -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 { AnyType } from '../any-type';
2
16
 
3
17
  export interface MediaTypeEncoder {
@@ -9,9 +23,9 @@ export interface URLQueryParamsEncoder extends MediaTypeEncoder {
9
23
  }
10
24
 
11
25
  export function isURLQueryParamsEncoder(
12
- encoder: MediaTypeEncoder | URLQueryParamsEncoder | undefined
26
+ encoder: MediaTypeEncoder | URLQueryParamsEncoder | undefined,
13
27
  ): encoder is URLQueryParamsEncoder {
14
- const rec = (encoder as unknown) as Record<string, unknown>;
28
+ const rec = encoder as unknown as Record<string, unknown>;
15
29
  return !!rec.encodeQueryString ?? false;
16
30
  }
17
31
 
@@ -19,13 +33,13 @@ export interface StructuredMediaTypeEncoder extends MediaTypeEncoder {
19
33
  encodeObject<T = unknown>(
20
34
  value: T,
21
35
  type?: AnyType,
22
- includeNulls?: boolean
36
+ includeNulls?: boolean,
23
37
  ): Record<string, unknown>;
24
38
  }
25
39
 
26
40
  export function isStructuredMediaTypeEncoder(
27
- encoder: MediaTypeEncoder | StructuredMediaTypeEncoder | undefined
41
+ encoder: MediaTypeEncoder | StructuredMediaTypeEncoder | undefined,
28
42
  ): encoder is StructuredMediaTypeEncoder {
29
- const rec = (encoder as unknown) as Record<string, unknown>;
43
+ const rec = encoder as unknown as Record<string, unknown>;
30
44
  return !!rec.encodeObject ?? false;
31
45
  }