1
1
// :copyright: Copyright (c) 2016 ftrack
2
- import moment from "moment" ;
3
2
import loglevel from "loglevel" ;
4
3
import { v4 as uuidV4 } from "uuid" ;
5
4
@@ -41,8 +40,6 @@ import getSchemaMappingFromSchemas from "./util/get_schema_mapping.js";
41
40
42
41
const logger = loglevel . getLogger ( "ftrack_api" ) ;
43
42
44
- const ENCODE_DATETIME_FORMAT = "YYYY-MM-DDTHH:mm:ss" ;
45
-
46
43
/**
47
44
* ftrack API session
48
45
* @class Session
@@ -64,7 +61,6 @@ export class Session<
64
61
serverInformation ?: QueryServerInformationResponse ;
65
62
serverVersion ?: string ;
66
63
private ensureSerializableResponse : boolean ;
67
- private decodeDatesAsIso : boolean ;
68
64
private schemasPromise ?: Promise < Schema < TEntityTypeMap > [ ] > ;
69
65
private serverInformationPromise ?: Promise < ServerInformation > ;
70
66
private serverInformationValues ?: string [ ] ;
@@ -86,7 +82,6 @@ export class Session<
86
82
* @param {string } [options.apiEndpoint=/api] - API endpoint.
87
83
* @param {object } [options.headers] - Additional headers to send with the request
88
84
* @param {object } [options.strictApi] - Turn on strict API mode
89
- * @param {object } [options.decodeDatesAsIso] - Decode dates as ISO strings instead of moment objects
90
85
* @param {object } [options.ensureSerializableResponse] - Disable normalization of response data
91
86
*
92
87
* @constructs Session
@@ -103,7 +98,6 @@ export class Session<
103
98
apiEndpoint = "/api" ,
104
99
additionalHeaders = { } ,
105
100
strictApi = false ,
106
- decodeDatesAsIso = false ,
107
101
ensureSerializableResponse = false ,
108
102
} : SessionOptions = { } ,
109
103
) {
@@ -181,15 +175,6 @@ export class Session<
181
175
this . clientToken = `ftrack-javascript-api--${ uuidV4 ( ) } ` ;
182
176
}
183
177
184
- // Always include is_timezone_support_enabled as required by API.
185
- // TODO: Remove this in next major.
186
- if (
187
- serverInformationValues &&
188
- ! serverInformationValues . includes ( "is_timezone_support_enabled" )
189
- ) {
190
- serverInformationValues . push ( "is_timezone_support_enabled" ) ;
191
- }
192
-
193
178
// TODO: remove these operations from session initialization in next major
194
179
const operations : [
195
180
operation . QueryServerInformationOperation ,
@@ -202,8 +187,6 @@ export class Session<
202
187
{ action : "query_schemas" } ,
203
188
] ;
204
189
205
- this . decodeDatesAsIso = decodeDatesAsIso ;
206
-
207
190
/**
208
191
* By default the API server will return normalized responses, and we denormalize them in the client.
209
192
* This might cause cyclical references in the response data, making it non-JSON serializable.
@@ -292,7 +275,7 @@ export class Session<
292
275
/**
293
276
* Return encoded *data* as JSON string.
294
277
*
295
- * This will translate date, moment, and dayjs objects into ISO8601 string representation in UTC.
278
+ * This will translate date and dayjs objects into ISO8601 string representation in UTC.
296
279
*
297
280
* @private
298
281
* @param {* } data The data to encode.
@@ -316,23 +299,9 @@ export class Session<
316
299
317
300
const date = convertToIsoString ( data ) ;
318
301
if ( date ) {
319
- if (
320
- this . serverInformation &&
321
- this . serverInformation . is_timezone_support_enabled
322
- ) {
323
- // Ensure that the moment object is in UTC and format
324
- // to timezone naive string.
325
- return {
326
- __type__ : "datetime" ,
327
- value : date ,
328
- } ;
329
- }
330
-
331
- // Ensure that the moment object is in local time zone and format
332
- // to timezone naive string.
333
302
return {
334
303
__type__ : "datetime" ,
335
- value : moment ( date ) . local ( ) . format ( ENCODE_DATETIME_FORMAT ) ,
304
+ value : date ,
336
305
} ;
337
306
}
338
307
@@ -375,7 +344,7 @@ export class Session<
375
344
* de-duplicated in the back end and point them to a single object in
376
345
* *identityMap*.
377
346
*
378
- * datetime objects will be converted to timezone-aware moment objects.
347
+ * datetime objects will be converted to timezone-aware dayjs objects.
379
348
*
380
349
* @private
381
350
* @param {* } data The data to decode.
@@ -386,33 +355,26 @@ export class Session<
386
355
data : any ,
387
356
identityMap : Data = { } ,
388
357
{
389
- decodeDatesAsIso = false ,
390
358
ensureSerializableResponse = false ,
391
359
} : {
392
- decodeDatesAsIso ?: boolean ;
393
360
ensureSerializableResponse ?: boolean ;
394
361
} = { } ,
395
362
) : any {
396
363
if ( Array . isArray ( data ) ) {
397
364
return this . _decodeArray ( data , identityMap , {
398
- decodeDatesAsIso,
399
365
ensureSerializableResponse,
400
366
} ) ;
401
367
}
402
368
if ( ! ! data && typeof data === "object" ) {
403
369
if ( data . __entity_type__ && ! ensureSerializableResponse ) {
404
370
return this . _mergeEntity ( data , identityMap , {
405
- decodeDatesAsIso,
406
371
ensureSerializableResponse,
407
372
} ) ;
408
373
}
409
- if ( data . __type__ === "datetime" && decodeDatesAsIso ) {
374
+ if ( data . __type__ === "datetime" ) {
410
375
return this . _decodeDateTimeAsIso ( data ) ;
411
- } else if ( data . __type__ === "datetime" ) {
412
- return this . _decodeDateTimeAsMoment ( data ) ;
413
376
}
414
377
return this . _decodePlainObject ( data , identityMap , {
415
- decodeDatesAsIso,
416
378
ensureSerializableResponse,
417
379
} ) ;
418
380
}
@@ -422,19 +384,14 @@ export class Session<
422
384
/**
423
385
* Decode datetime *data* into ISO 8601 strings.
424
386
*
425
- * Translate objects with __type__ equal to 'datetime' into moment
387
+ * Translate objects with __type__ equal to 'datetime' into dayjs
426
388
* datetime objects. If time zone support is enabled on the server the date
427
- * will be assumed to be UTC and the moment will be in utc.
389
+ * will be assumed to be UTC and the dayjs will be in utc.
428
390
* @private
429
391
*/
430
392
private _decodeDateTimeAsIso ( data : any ) {
431
393
let dateValue = data . value ;
432
- if (
433
- this . serverInformation &&
434
- this . serverInformation . is_timezone_support_enabled &&
435
- ! dateValue . endsWith ( "Z" ) &&
436
- ! dateValue . includes ( "+" )
437
- ) {
394
+ if ( ! dateValue . endsWith ( "Z" ) && ! dateValue . includes ( "+" ) ) {
438
395
// Server responds with timezone naive strings, add Z to indicate UTC.
439
396
// If the string somehow already contains a timezone offset, do not add Z.
440
397
dateValue += "Z" ;
@@ -443,27 +400,6 @@ export class Session<
443
400
return new Date ( dateValue ) . toISOString ( ) ;
444
401
}
445
402
446
- /**
447
- * Decode datetime *data* into moment objects.
448
- *
449
- * Translate objects with __type__ equal to 'datetime' into moment
450
- * datetime objects. If time zone support is enabled on the server the date
451
- * will be assumed to be UTC and the moment will be in utc.
452
- * @private
453
- */
454
- private _decodeDateTimeAsMoment ( data : any ) {
455
- if (
456
- this . serverInformation &&
457
- this . serverInformation . is_timezone_support_enabled
458
- ) {
459
- // Return date as moment object with UTC set to true.
460
- return moment . utc ( data . value ) ;
461
- }
462
-
463
- // Return date as local moment object.
464
- return moment ( data . value ) ;
465
- }
466
-
467
403
/**
468
404
* Return new object where all values have been decoded.
469
405
* @private
@@ -472,16 +408,13 @@ export class Session<
472
408
object : Data ,
473
409
identityMap : Data ,
474
410
{
475
- decodeDatesAsIso,
476
411
ensureSerializableResponse,
477
412
} : {
478
- decodeDatesAsIso ?: boolean ;
479
413
ensureSerializableResponse ?: boolean ;
480
414
} = { } ,
481
415
) {
482
416
return Object . keys ( object ) . reduce < Data > ( ( previous , key ) => {
483
417
previous [ key ] = this . decode ( object [ key ] , identityMap , {
484
- decodeDatesAsIso,
485
418
ensureSerializableResponse,
486
419
} ) ;
487
420
return previous ;
@@ -496,16 +429,13 @@ export class Session<
496
429
collection : any [ ] ,
497
430
identityMap : Data ,
498
431
{
499
- decodeDatesAsIso = false ,
500
432
ensureSerializableResponse = false ,
501
433
} : {
502
- decodeDatesAsIso ?: boolean ;
503
434
ensureSerializableResponse ?: boolean ;
504
435
} = { } ,
505
436
) : any [ ] {
506
437
return collection . map ( ( item ) =>
507
438
this . decode ( item , identityMap , {
508
- decodeDatesAsIso,
509
439
ensureSerializableResponse,
510
440
} ) ,
511
441
) ;
@@ -519,10 +449,8 @@ export class Session<
519
449
entity : Data ,
520
450
identityMap : Data ,
521
451
{
522
- decodeDatesAsIso,
523
452
ensureSerializableResponse,
524
453
} : {
525
- decodeDatesAsIso ?: boolean ;
526
454
ensureSerializableResponse ?: boolean ;
527
455
} = { } ,
528
456
) {
@@ -547,7 +475,6 @@ export class Session<
547
475
for ( const key in entity ) {
548
476
if ( Object . hasOwn ( entity , key ) ) {
549
477
mergedEntity [ key ] = this . decode ( entity [ key ] , identityMap , {
550
- decodeDatesAsIso,
551
478
ensureSerializableResponse,
552
479
} ) ;
553
480
}
@@ -630,7 +557,6 @@ export class Session<
630
557
* @param {AbortSignal } options.signal - Abort signal
631
558
* @param {string } options.pushToken - push token to associate with the request
632
559
* @param {object } options.headers - Additional headers to send with the request
633
- * @param {string } options.decodeDatesAsIso - Return dates as ISO strings instead of moment objects
634
560
*
635
561
*/
636
562
async call < T = ActionResponse < keyof TEntityTypeMap > > (
@@ -640,7 +566,6 @@ export class Session<
640
566
pushToken,
641
567
signal,
642
568
additionalHeaders = { } ,
643
- decodeDatesAsIso = this . decodeDatesAsIso ,
644
569
ensureSerializableResponse = this . ensureSerializableResponse ,
645
570
} : CallOptions = { } ,
646
571
) : Promise < IsTuple < T > extends true ? T : T [ ] > {
@@ -690,11 +615,7 @@ export class Session<
690
615
throw this . getErrorFromResponse ( response ) ;
691
616
}
692
617
try {
693
- return this . decode (
694
- response ,
695
- { } ,
696
- { decodeDatesAsIso, ensureSerializableResponse } ,
697
- ) ;
618
+ return this . decode ( response , { } , { ensureSerializableResponse } ) ;
698
619
} catch ( reason ) {
699
620
logger . warn ( "Server reported error in unexpected format. " , reason ) ;
700
621
throw this . getErrorFromResponse ( {
@@ -856,7 +777,6 @@ export class Session<
856
777
* @param {object } options.abortController - Deprecated in favour of options.signal
857
778
* @param {object } options.signal - Abort signal user for aborting requests prematurely
858
779
* @param {object } options.headers - Additional headers to send with the request
859
- * @param {object } options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects
860
780
* @param {object } options.ensureSerializableResponse - Disable normalization of response data
861
781
* @return {Promise } Promise which will be resolved with an object
862
782
* containing action, data and metadata
@@ -885,7 +805,6 @@ export class Session<
885
805
* @param {object } options.abortController - Deprecated in favour of options.signal
886
806
* @param {object } options.signal - Abort signal user for aborting requests prematurely
887
807
* @param {object } options.headers - Additional headers to send with the request
888
- * @param {object } options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects
889
808
* @param {object } options.ensureSerializableResponse - Disable normalization of response data
890
809
* @return {Promise } Promise which will be resolved with an object
891
810
* containing data and metadata
@@ -931,7 +850,6 @@ export class Session<
931
850
* @param {Object } options
932
851
* @param {string } options.pushToken - push token to associate with the request
933
852
* @param {object } options.headers - Additional headers to send with the request
934
- * @param {object } options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects
935
853
* @param {object } options.ensureSerializableResponse - Disable normalization of response data
936
854
* @return {Promise } Promise which will be resolved with the response.
937
855
*/
@@ -957,7 +875,6 @@ export class Session<
957
875
* @param {Object } options
958
876
* @param {string } options.pushToken - push token to associate with the request
959
877
* @param {object } options.headers - Additional headers to send with the request
960
- * @param {object } options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects
961
878
* @param {object } options.ensureSerializableResponse - Disable normalization of response data
962
879
* @return {Promise } Promise resolved with the response.
963
880
*/
@@ -983,7 +900,6 @@ export class Session<
983
900
* @param {Object } options
984
901
* @param {string } options.pushToken - push token to associate with the request
985
902
* @param {object } options.headers - Additional headers to send with the request
986
- * @param {object } options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects
987
903
* @return {Promise } Promise resolved with the response.
988
904
*/
989
905
async delete < TEntityType extends keyof TEntityTypeMap > (
0 commit comments