-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Remove moment js #302
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
Changes from 2 commits
ca51125
4233997
9b6b3a1
f71e035
a237893
149e04f
b4c3917
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // :copyright: Copyright (c) 2016 ftrack | ||
| import moment from "moment"; | ||
| import dayjs from "dayjs"; | ||
| import utc from "dayjs/plugin/utc.js"; | ||
| import loglevel from "loglevel"; | ||
| import { v4 as uuidV4 } from "uuid"; | ||
|
|
||
|
|
@@ -39,6 +40,8 @@ import { convertToIsoString } from "./util/convert_to_iso_string.js"; | |
| import { Uploader } from "./uploader.js"; | ||
| import getSchemaMappingFromSchemas from "./util/get_schema_mapping.js"; | ||
|
|
||
| dayjs.extend(utc); | ||
|
|
||
| const logger = loglevel.getLogger("ftrack_api"); | ||
|
|
||
| const ENCODE_DATETIME_FORMAT = "YYYY-MM-DDTHH:mm:ss"; | ||
|
|
@@ -86,7 +89,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 dayjs objects | ||
| * @param {object} [options.ensureSerializableResponse] - Disable normalization of response data | ||
| * | ||
| * @constructs Session | ||
|
|
@@ -103,7 +106,7 @@ export class Session< | |
| apiEndpoint = "/api", | ||
| additionalHeaders = {}, | ||
| strictApi = false, | ||
| decodeDatesAsIso = false, | ||
| decodeDatesAsIso = true, | ||
| ensureSerializableResponse = false, | ||
| }: SessionOptions = {}, | ||
| ) { | ||
|
|
@@ -292,7 +295,7 @@ export class Session< | |
| /** | ||
| * Return encoded *data* as JSON string. | ||
| * | ||
| * This will translate date, moment, and dayjs objects into ISO8601 string representation in UTC. | ||
| * This will translate date and dayjs objects into ISO8601 string representation in UTC. | ||
| * | ||
| * @private | ||
| * @param {*} data The data to encode. | ||
|
|
@@ -320,19 +323,19 @@ export class Session< | |
| this.serverInformation && | ||
| this.serverInformation.is_timezone_support_enabled | ||
| ) { | ||
| // Ensure that the moment object is in UTC and format | ||
| // Ensure that the dayjs object is in UTC and format | ||
| // to timezone naive string. | ||
| return { | ||
| __type__: "datetime", | ||
| value: date, | ||
| }; | ||
| } | ||
|
|
||
| // Ensure that the moment object is in local time zone and format | ||
| // Ensure that the dayjs object is in local time zone and format | ||
| // to timezone naive string. | ||
| return { | ||
| __type__: "datetime", | ||
| value: moment(date).local().format(ENCODE_DATETIME_FORMAT), | ||
| value: dayjs.utc(date).local().format(ENCODE_DATETIME_FORMAT), | ||
|
||
| }; | ||
| } | ||
|
|
||
|
|
@@ -375,7 +378,7 @@ export class Session< | |
| * de-duplicated in the back end and point them to a single object in | ||
| * *identityMap*. | ||
| * | ||
| * datetime objects will be converted to timezone-aware moment objects. | ||
| * datetime objects will be converted to timezone-aware dayjs objects. | ||
| * | ||
| * @private | ||
| * @param {*} data The data to decode. | ||
|
|
@@ -386,7 +389,7 @@ export class Session< | |
| data: any, | ||
| identityMap: Data = {}, | ||
| { | ||
| decodeDatesAsIso = false, | ||
| decodeDatesAsIso = true, | ||
| ensureSerializableResponse = false, | ||
| }: { | ||
| decodeDatesAsIso?: boolean; | ||
|
|
@@ -408,8 +411,6 @@ export class Session< | |
| } | ||
| if (data.__type__ === "datetime" && decodeDatesAsIso) { | ||
| return this._decodeDateTimeAsIso(data); | ||
| } else if (data.__type__ === "datetime") { | ||
| return this._decodeDateTimeAsMoment(data); | ||
| } | ||
| return this._decodePlainObject(data, identityMap, { | ||
| decodeDatesAsIso, | ||
|
|
@@ -422,9 +423,9 @@ export class Session< | |
| /** | ||
| * Decode datetime *data* into ISO 8601 strings. | ||
| * | ||
| * Translate objects with __type__ equal to 'datetime' into moment | ||
| * Translate objects with __type__ equal to 'datetime' into dayjs | ||
| * datetime objects. If time zone support is enabled on the server the date | ||
| * will be assumed to be UTC and the moment will be in utc. | ||
| * will be assumed to be UTC and the dayjs will be in utc. | ||
| * @private | ||
| */ | ||
| private _decodeDateTimeAsIso(data: any) { | ||
|
|
@@ -443,27 +444,6 @@ export class Session< | |
| return new Date(dateValue).toISOString(); | ||
| } | ||
|
|
||
| /** | ||
| * Decode datetime *data* into moment objects. | ||
| * | ||
| * Translate objects with __type__ equal to 'datetime' into moment | ||
| * datetime objects. If time zone support is enabled on the server the date | ||
| * will be assumed to be UTC and the moment will be in utc. | ||
| * @private | ||
| */ | ||
| private _decodeDateTimeAsMoment(data: any) { | ||
| if ( | ||
| this.serverInformation && | ||
| this.serverInformation.is_timezone_support_enabled | ||
| ) { | ||
| // Return date as moment object with UTC set to true. | ||
| return moment.utc(data.value); | ||
| } | ||
|
|
||
| // Return date as local moment object. | ||
| return moment(data.value); | ||
| } | ||
|
|
||
| /** | ||
| * Return new object where all values have been decoded. | ||
| * @private | ||
|
|
@@ -496,7 +476,7 @@ export class Session< | |
| collection: any[], | ||
| identityMap: Data, | ||
| { | ||
| decodeDatesAsIso = false, | ||
| decodeDatesAsIso = true, | ||
| ensureSerializableResponse = false, | ||
| }: { | ||
| decodeDatesAsIso?: boolean; | ||
|
|
@@ -630,7 +610,7 @@ export class Session< | |
| * @param {AbortSignal} options.signal - Abort signal | ||
| * @param {string} options.pushToken - push token to associate with the request | ||
| * @param {object} options.headers - Additional headers to send with the request | ||
| * @param {string} options.decodeDatesAsIso - Return dates as ISO strings instead of moment objects | ||
| * @param {string} options.decodeDatesAsIso - Return dates as ISO strings instead of dayjs objects | ||
| * | ||
| */ | ||
| async call<T = ActionResponse<keyof TEntityTypeMap>>( | ||
|
|
@@ -856,7 +836,7 @@ export class Session< | |
| * @param {object} options.abortController - Deprecated in favour of options.signal | ||
| * @param {object} options.signal - Abort signal user for aborting requests prematurely | ||
| * @param {object} options.headers - Additional headers to send with the request | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects | ||
| * @param {object} options.ensureSerializableResponse - Disable normalization of response data | ||
| * @return {Promise} Promise which will be resolved with an object | ||
| * containing action, data and metadata | ||
|
|
@@ -885,7 +865,7 @@ export class Session< | |
| * @param {object} options.abortController - Deprecated in favour of options.signal | ||
| * @param {object} options.signal - Abort signal user for aborting requests prematurely | ||
| * @param {object} options.headers - Additional headers to send with the request | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects | ||
| * @param {object} options.ensureSerializableResponse - Disable normalization of response data | ||
| * @return {Promise} Promise which will be resolved with an object | ||
| * containing data and metadata | ||
|
|
@@ -931,7 +911,7 @@ export class Session< | |
| * @param {Object} options | ||
| * @param {string} options.pushToken - push token to associate with the request | ||
| * @param {object} options.headers - Additional headers to send with the request | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects | ||
| * @param {object} options.ensureSerializableResponse - Disable normalization of response data | ||
| * @return {Promise} Promise which will be resolved with the response. | ||
| */ | ||
|
|
@@ -957,7 +937,7 @@ export class Session< | |
| * @param {Object} options | ||
| * @param {string} options.pushToken - push token to associate with the request | ||
| * @param {object} options.headers - Additional headers to send with the request | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects | ||
| * @param {object} options.ensureSerializableResponse - Disable normalization of response data | ||
| * @return {Promise} Promise resolved with the response. | ||
| */ | ||
|
|
@@ -983,7 +963,7 @@ export class Session< | |
| * @param {Object} options | ||
| * @param {string} options.pushToken - push token to associate with the request | ||
| * @param {object} options.headers - Additional headers to send with the request | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of moment objects | ||
| * @param {object} options.decodeDatesAsIso - Decode dates as ISO strings instead of dayjs objects | ||
| * @return {Promise} Promise resolved with the response. | ||
| */ | ||
| async delete<TEntityType extends keyof TEntityTypeMap>( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.