Skip to content

Commit 4233997

Browse files
author
Mert Kirbuga
committed
Set decodeDatesAsIso as true by default
1 parent ca51125 commit 4233997

File tree

2 files changed

+3
-74
lines changed

2 files changed

+3
-74
lines changed

source/session.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class Session<
106106
apiEndpoint = "/api",
107107
additionalHeaders = {},
108108
strictApi = false,
109-
decodeDatesAsIso = false,
109+
decodeDatesAsIso = true,
110110
ensureSerializableResponse = false,
111111
}: SessionOptions = {},
112112
) {
@@ -389,7 +389,7 @@ export class Session<
389389
data: any,
390390
identityMap: Data = {},
391391
{
392-
decodeDatesAsIso = false,
392+
decodeDatesAsIso = true,
393393
ensureSerializableResponse = false,
394394
}: {
395395
decodeDatesAsIso?: boolean;
@@ -411,8 +411,6 @@ export class Session<
411411
}
412412
if (data.__type__ === "datetime" && decodeDatesAsIso) {
413413
return this._decodeDateTimeAsIso(data);
414-
} else if (data.__type__ === "datetime") {
415-
return this._decodeDateTimeAsDayJs(data);
416414
}
417415
return this._decodePlainObject(data, identityMap, {
418416
decodeDatesAsIso,
@@ -446,27 +444,6 @@ export class Session<
446444
return new Date(dateValue).toISOString();
447445
}
448446

449-
/**
450-
* Decode datetime *data* into dayjs objects.
451-
*
452-
* Translate objects with __type__ equal to 'datetime' into dayjs
453-
* datetime objects. If time zone support is enabled on the server the date
454-
* will be assumed to be UTC and the dayjs will be in utc.
455-
* @private
456-
*/
457-
private _decodeDateTimeAsDayJs(data: any) {
458-
if (
459-
this.serverInformation &&
460-
this.serverInformation.is_timezone_support_enabled
461-
) {
462-
// Return date as dayjs object with UTC set to true.
463-
return dayjs.utc(data.value);
464-
}
465-
466-
// Return date as local dayjs object.
467-
return dayjs(data.value);
468-
}
469-
470447
/**
471448
* Return new object where all values have been decoded.
472449
* @private
@@ -499,7 +476,7 @@ export class Session<
499476
collection: any[],
500477
identityMap: Data,
501478
{
502-
decodeDatesAsIso = false,
479+
decodeDatesAsIso = true,
503480
ensureSerializableResponse = false,
504481
}: {
505482
decodeDatesAsIso?: boolean;

test/session.test.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,6 @@ describe("Session", () => {
131131
return expect((await headers).get("ftrack-strict-api")).toEqual("true");
132132
});
133133

134-
it("Should allow querying with datetimes decoded as dayjs objects (default)", async () => {
135-
const result = await session.query(
136-
"select name, created_at from Task limit 1",
137-
);
138-
expect(result.data[0].created_at).toBeInstanceOf(dayjs);
139-
expect(result.data[0].created_at.toISOString()).toEqual(
140-
"2022-10-10T10:12:09.000Z",
141-
);
142-
});
143-
144134
it("Should allow querying with datetimes decoded as ISO objects", async () => {
145135
const result = await session.query(
146136
"select name, created_at from Task limit 1",
@@ -163,30 +153,6 @@ describe("Session", () => {
163153
);
164154
expect(result.data[0].created_at).toEqual("2022-10-10T10:12:09.000Z");
165155
});
166-
it("Should allow overriding session decodeDatesAsIso when querying", async () => {
167-
const decodeDatesAsIsoSession = new Session(
168-
credentials.serverUrl,
169-
credentials.apiUser,
170-
credentials.apiKey,
171-
{
172-
decodeDatesAsIso: true,
173-
},
174-
);
175-
await decodeDatesAsIsoSession.initializing;
176-
const result = await decodeDatesAsIsoSession.query(
177-
"select name, created_at from Task limit 1",
178-
{ decodeDatesAsIso: false },
179-
);
180-
expect(result.data[0].created_at).toBeInstanceOf(dayjs);
181-
expect(result.data[0].created_at.toISOString()).toEqual(
182-
"2022-10-10T10:12:09.000Z",
183-
);
184-
const result2 = await session.query(
185-
"select name, created_at from Task limit 1",
186-
{ decodeDatesAsIso: true },
187-
);
188-
expect(result2.data[0].created_at).toEqual("2022-10-10T10:12:09.000Z");
189-
});
190156

191157
it("Should allow querying with datetimes decoded as ISO objects with timezone support disabled", async () => {
192158
server.use(
@@ -837,20 +803,6 @@ describe("Encoding entities", () => {
837803
expect(data[2].status.state.short).toEqual("DONE");
838804
});
839805

840-
it("Should support decoding datetime as dayjs (default)", () => {
841-
const now = dayjs();
842-
843-
//@ts-ignore - Otherwise internal method used for testing purposes
844-
const output = session.decode({
845-
foo: {
846-
__type__: "datetime",
847-
value: now.toISOString(),
848-
},
849-
});
850-
expect(output.foo).toBeInstanceOf(dayjs);
851-
expect(output.foo.toISOString()).toEqual(now.toISOString());
852-
});
853-
854806
it("Should support decoding datetime as ISO string", () => {
855807
const now = new Date();
856808

0 commit comments

Comments
 (0)