Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support setting decodeDatesAsIso globally #159

Merged
merged 9 commits into from
Oct 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions source/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class Session {
schemas?: Schema[];
serverInformation?: QueryServerInformationResponse;
serverVersion?: string;
private decodeDatesAsIso: boolean;
private schemasPromise?: Promise<Schema[]>;
private serverInformationPromise?: Promise<ServerInformation>;
private serverInformationValues?: string[];
Expand All @@ -80,7 +81,7 @@ export class Session {
* @param {string} [options.apiEndpoint=/api] - API endpoint.
* @param {object} [options.headers] - Additional headers to send with the request
* @param {object} [options.strictApi] - Turn on strict API mode
* @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects
* @param {object} [options.decodeDatesAsIso] - Decode dates as ISO strings instead of moment objects
*
* @constructs Session
*/
Expand All @@ -96,6 +97,7 @@ export class Session {
apiEndpoint = "/api",
additionalHeaders = {},
strictApi = false,
decodeDatesAsIso = false
}: SessionOptions = {},
) {
if (!serverUrl || !apiUser || !apiKey) {
Expand Down Expand Up @@ -190,6 +192,8 @@ export class Session {
{ action: "query_schemas" },
];

this.decodeDatesAsIso = decodeDatesAsIso;

/**
* true if session is initialized
* @memberof Session
Expand Down Expand Up @@ -788,7 +792,10 @@ export class Session {
logger.debug("Query", expression);
const responses = await this.call<[QueryResponse<T>]>(
[operation.query(expression)],
options,
{
decodeDatesAsIso: this.decodeDatesAsIso,
...(options || {})
},
ffMathy marked this conversation as resolved.
Show resolved Hide resolved
);
return responses[0];
}
Expand Down