Skip to content

Commit 9b6b3a1

Browse files
author
Mert Kirbuga
committed
Remove decodeDatesAsIso param entirely
1 parent 4233997 commit 9b6b3a1

File tree

2 files changed

+3
-42
lines changed

2 files changed

+3
-42
lines changed

source/session.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export class Session<
6767
serverInformation?: QueryServerInformationResponse;
6868
serverVersion?: string;
6969
private ensureSerializableResponse: boolean;
70-
private decodeDatesAsIso: boolean;
7170
private schemasPromise?: Promise<Schema<TEntityTypeMap>[]>;
7271
private serverInformationPromise?: Promise<ServerInformation>;
7372
private serverInformationValues?: string[];
@@ -89,7 +88,6 @@ export class Session<
8988
* @param {string} [options.apiEndpoint=/api] - API endpoint.
9089
* @param {object} [options.headers] - Additional headers to send with the request
9190
* @param {object} [options.strictApi] - Turn on strict API mode
92-
* @param {object} [options.decodeDatesAsIso] - Decode dates as ISO strings instead of dayjs objects
9391
* @param {object} [options.ensureSerializableResponse] - Disable normalization of response data
9492
*
9593
* @constructs Session
@@ -106,7 +104,6 @@ export class Session<
106104
apiEndpoint = "/api",
107105
additionalHeaders = {},
108106
strictApi = false,
109-
decodeDatesAsIso = true,
110107
ensureSerializableResponse = false,
111108
}: SessionOptions = {},
112109
) {
@@ -205,8 +202,6 @@ export class Session<
205202
{ action: "query_schemas" },
206203
];
207204

208-
this.decodeDatesAsIso = decodeDatesAsIso;
209-
210205
/**
211206
* By default the API server will return normalized responses, and we denormalize them in the client.
212207
* This might cause cyclical references in the response data, making it non-JSON serializable.
@@ -389,31 +384,26 @@ export class Session<
389384
data: any,
390385
identityMap: Data = {},
391386
{
392-
decodeDatesAsIso = true,
393387
ensureSerializableResponse = false,
394388
}: {
395-
decodeDatesAsIso?: boolean;
396389
ensureSerializableResponse?: boolean;
397390
} = {},
398391
): any {
399392
if (Array.isArray(data)) {
400393
return this._decodeArray(data, identityMap, {
401-
decodeDatesAsIso,
402394
ensureSerializableResponse,
403395
});
404396
}
405397
if (!!data && typeof data === "object") {
406398
if (data.__entity_type__ && !ensureSerializableResponse) {
407399
return this._mergeEntity(data, identityMap, {
408-
decodeDatesAsIso,
409400
ensureSerializableResponse,
410401
});
411402
}
412-
if (data.__type__ === "datetime" && decodeDatesAsIso) {
403+
if (data.__type__ === "datetime") {
413404
return this._decodeDateTimeAsIso(data);
414405
}
415406
return this._decodePlainObject(data, identityMap, {
416-
decodeDatesAsIso,
417407
ensureSerializableResponse,
418408
});
419409
}
@@ -452,16 +442,13 @@ export class Session<
452442
object: Data,
453443
identityMap: Data,
454444
{
455-
decodeDatesAsIso,
456445
ensureSerializableResponse,
457446
}: {
458-
decodeDatesAsIso?: boolean;
459447
ensureSerializableResponse?: boolean;
460448
} = {},
461449
) {
462450
return Object.keys(object).reduce<Data>((previous, key) => {
463451
previous[key] = this.decode(object[key], identityMap, {
464-
decodeDatesAsIso,
465452
ensureSerializableResponse,
466453
});
467454
return previous;
@@ -476,16 +463,13 @@ export class Session<
476463
collection: any[],
477464
identityMap: Data,
478465
{
479-
decodeDatesAsIso = true,
480466
ensureSerializableResponse = false,
481467
}: {
482-
decodeDatesAsIso?: boolean;
483468
ensureSerializableResponse?: boolean;
484469
} = {},
485470
): any[] {
486471
return collection.map((item) =>
487472
this.decode(item, identityMap, {
488-
decodeDatesAsIso,
489473
ensureSerializableResponse,
490474
}),
491475
);
@@ -499,10 +483,8 @@ export class Session<
499483
entity: Data,
500484
identityMap: Data,
501485
{
502-
decodeDatesAsIso,
503486
ensureSerializableResponse,
504487
}: {
505-
decodeDatesAsIso?: boolean;
506488
ensureSerializableResponse?: boolean;
507489
} = {},
508490
) {
@@ -527,7 +509,6 @@ export class Session<
527509
for (const key in entity) {
528510
if (Object.hasOwn(entity, key)) {
529511
mergedEntity[key] = this.decode(entity[key], identityMap, {
530-
decodeDatesAsIso,
531512
ensureSerializableResponse,
532513
});
533514
}
@@ -610,7 +591,6 @@ export class Session<
610591
* @param {AbortSignal} options.signal - Abort signal
611592
* @param {string} options.pushToken - push token to associate with the request
612593
* @param {object} options.headers - Additional headers to send with the request
613-
* @param {string} options.decodeDatesAsIso - Return dates as ISO strings instead of dayjs objects
614594
*
615595
*/
616596
async call<T = ActionResponse<keyof TEntityTypeMap>>(
@@ -620,7 +600,6 @@ export class Session<
620600
pushToken,
621601
signal,
622602
additionalHeaders = {},
623-
decodeDatesAsIso = this.decodeDatesAsIso,
624603
ensureSerializableResponse = this.ensureSerializableResponse,
625604
}: CallOptions = {},
626605
): Promise<IsTuple<T> extends true ? T : T[]> {
@@ -670,11 +649,7 @@ export class Session<
670649
throw this.getErrorFromResponse(response);
671650
}
672651
try {
673-
return this.decode(
674-
response,
675-
{},
676-
{ decodeDatesAsIso, ensureSerializableResponse },
677-
);
652+
return this.decode(response, {}, { ensureSerializableResponse });
678653
} catch (reason) {
679654
logger.warn("Server reported error in unexpected format. ", reason);
680655
throw this.getErrorFromResponse({
@@ -836,7 +811,6 @@ export class Session<
836811
* @param {object} options.abortController - Deprecated in favour of options.signal
837812
* @param {object} options.signal - Abort signal user for aborting requests prematurely
838813
* @param {object} options.headers - Additional headers to send with the request
839-
* @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects
840814
* @param {object} options.ensureSerializableResponse - Disable normalization of response data
841815
* @return {Promise} Promise which will be resolved with an object
842816
* containing action, data and metadata
@@ -865,7 +839,6 @@ export class Session<
865839
* @param {object} options.abortController - Deprecated in favour of options.signal
866840
* @param {object} options.signal - Abort signal user for aborting requests prematurely
867841
* @param {object} options.headers - Additional headers to send with the request
868-
* @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects
869842
* @param {object} options.ensureSerializableResponse - Disable normalization of response data
870843
* @return {Promise} Promise which will be resolved with an object
871844
* containing data and metadata
@@ -911,7 +884,6 @@ export class Session<
911884
* @param {Object} options
912885
* @param {string} options.pushToken - push token to associate with the request
913886
* @param {object} options.headers - Additional headers to send with the request
914-
* @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects
915887
* @param {object} options.ensureSerializableResponse - Disable normalization of response data
916888
* @return {Promise} Promise which will be resolved with the response.
917889
*/
@@ -937,7 +909,6 @@ export class Session<
937909
* @param {Object} options
938910
* @param {string} options.pushToken - push token to associate with the request
939911
* @param {object} options.headers - Additional headers to send with the request
940-
* @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects
941912
* @param {object} options.ensureSerializableResponse - Disable normalization of response data
942913
* @return {Promise} Promise resolved with the response.
943914
*/
@@ -963,7 +934,6 @@ export class Session<
963934
* @param {Object} options
964935
* @param {string} options.pushToken - push token to associate with the request
965936
* @param {object} options.headers - Additional headers to send with the request
966-
* @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects
967937
* @return {Promise} Promise resolved with the response.
968938
*/
969939
async delete<TEntityType extends keyof TEntityTypeMap>(

test/session.test.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ beforeAll(async () => {
4242
credentials.apiKey,
4343
{
4444
autoConnectEventHub: false,
45-
decodeDatesAsIso: false,
4645
},
4746
);
4847
await session.initializing;
@@ -134,7 +133,6 @@ describe("Session", () => {
134133
it("Should allow querying with datetimes decoded as ISO objects", async () => {
135134
const result = await session.query(
136135
"select name, created_at from Task limit 1",
137-
{ decodeDatesAsIso: true },
138136
);
139137
expect(result.data[0].created_at).toEqual("2022-10-10T10:12:09.000Z");
140138
});
@@ -143,9 +141,6 @@ describe("Session", () => {
143141
credentials.serverUrl,
144142
credentials.apiUser,
145143
credentials.apiKey,
146-
{
147-
decodeDatesAsIso: true,
148-
},
149144
);
150145
await decodeDatesAsIsoSession.initializing;
151146
const result = await decodeDatesAsIsoSession.query(
@@ -178,7 +173,6 @@ describe("Session", () => {
178173
await timezoneDisabledSession.initializing;
179174
const result = await timezoneDisabledSession.query(
180175
"select name, created_at from Task limit 1",
181-
{ decodeDatesAsIso: true },
182176
);
183177
expect(result.data[0].created_at).toEqual("2022-10-10T08:12:09.000Z");
184178
});
@@ -607,9 +601,7 @@ describe("Session", () => {
607601
);
608602

609603
await expect(() =>
610-
session.call([{ action: "configure_totp", secret, code }], {
611-
decodeDatesAsIso: true,
612-
}),
604+
session.call([{ action: "configure_totp", secret, code }]),
613605
).rejects.toThrowError("Code must be provided to enable totp.");
614606
});
615607

@@ -815,7 +807,6 @@ describe("Encoding entities", () => {
815807
},
816808
},
817809
{},
818-
{ decodeDatesAsIso: true },
819810
);
820811
expect(output.foo).toEqual(now.toISOString());
821812
});

0 commit comments

Comments
 (0)