From 8deedc851f78d936179ca27b86bed43ecd6e6b54 Mon Sep 17 00:00:00 2001 From: Carson Full Date: Fri, 20 Sep 2024 14:37:08 -0500 Subject: [PATCH] Bump Luxon Needed to account for polymorphic validity type changes upstream --- package.json | 4 +- src/common/luxon.graphql.ts | 2 +- src/common/temporal/calendar-date.ts | 63 +++++++++++-------- src/common/temporal/date-interval.ts | 14 ++--- .../database/parameter-transformer.service.ts | 4 +- yarn.lock | 20 +++--- 6 files changed, 58 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index de858b12a9..c35bea1f34 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "lazy-get-decorator": "^2.2.1", "lodash": "npm:lodash-es@^4.17.21", "lru-cache": "^7.18.3", - "luxon": "^3.4.3", + "luxon": "^3.5.0", "mime": "beta", "nanoid": "^4.0.2", "neo4j-driver": "^5.20.0", @@ -122,7 +122,7 @@ "@types/jest": "^29.5.7", "@types/jsonwebtoken": "^9.0.4", "@types/lodash": "^4.14.200", - "@types/luxon": "^3.3.3", + "@types/luxon": "^3.4.2", "@types/node": "^20.12.5", "@types/prismjs": "^1.26.2", "@types/react": "^18.2.33", diff --git a/src/common/luxon.graphql.ts b/src/common/luxon.graphql.ts index f0c6535df7..633906e040 100644 --- a/src/common/luxon.graphql.ts +++ b/src/common/luxon.graphql.ts @@ -73,7 +73,7 @@ export class DateTimeScalar } serialize(value: unknown): string { - if (value instanceof DateTime) { + if (DateTime.isDateTime(value)) { return value.toISO(); } if (typeof value === 'string') { diff --git a/src/common/temporal/calendar-date.ts b/src/common/temporal/calendar-date.ts index 9823b64114..24635134f5 100644 --- a/src/common/temporal/calendar-date.ts +++ b/src/common/temporal/calendar-date.ts @@ -10,6 +10,7 @@ import { Zone, ZoneOptions, } from 'luxon'; +import type { DefaultValidity, IfValid } from 'luxon/src/_util'; import { inspect } from 'util'; import { DateInterval } from './date-interval'; @@ -21,17 +22,19 @@ import { DateInterval } from './date-interval'; * Whether or not we need/want it to be type compatible with DateTime has yet to * be determined - currently it is. */ -export class CalendarDate +export class CalendarDate // @ts-expect-error library doesn't explicitly support extension - extends DateTime + extends DateTime { static isDate(o: any): o is CalendarDate { return o instanceof CalendarDate; } - static fromDateTime(dt: DateTime): CalendarDate { + static fromDateTime( + dt: DateTime, + ): CalendarDate { return Object.assign( - new CalendarDate(), + new CalendarDate(), dt instanceof CalendarDate ? dt : dt.startOf('day'), ); } @@ -44,7 +47,7 @@ export class CalendarDate super({}); } - toISO(_options?: ToISOTimeOptions): string { + toISO(_options?: ToISOTimeOptions) { return this.toISODate(); } @@ -88,7 +91,7 @@ export class CalendarDate return CalendarDate.fromDateTime(super.fromFormat(text, format, opts)); } - static invalid(reason: any): CalendarDate { + static invalid(reason: any) { return CalendarDate.fromDateTime(super.invalid(reason)); } @@ -207,52 +210,60 @@ export class CalendarDate return CalendarDate.fromDateTime(super.utc(...args)); } - until(other: CalendarDate): DateInterval { - return DateInterval.fromDateTimes(this, other); + until(other: CalendarDate): IfValid, IsValid> { + return DateInterval.fromDateTimes(this as DateTime, other) as IfValid< + DateInterval, + DateTime, + IsValid + >; } - endOf(unit: DateTimeUnit): CalendarDate { - return CalendarDate.fromDateTime(super.endOf(unit)); + endOf(unit: DateTimeUnit): this { + return CalendarDate.fromDateTime(super.endOf(unit) as DateTime) as this; } - minus(duration: DurationLike): CalendarDate { - return CalendarDate.fromDateTime(super.minus(duration)); + minus(duration: DurationLike): this { + return CalendarDate.fromDateTime(super.minus(duration) as DateTime) as this; } - plus(duration: DurationLike): CalendarDate { - return CalendarDate.fromDateTime(super.plus(duration)); + plus(duration: DurationLike): this { + return CalendarDate.fromDateTime(super.plus(duration) as DateTime) as this; } - reconfigure(properties: LocaleOptions): CalendarDate { - return CalendarDate.fromDateTime(super.reconfigure(properties)); + reconfigure(properties: LocaleOptions): this { + return CalendarDate.fromDateTime( + super.reconfigure(properties) as DateTime, + ) as this; } - set(values: DateObjectUnits): CalendarDate { - return CalendarDate.fromDateTime(super.set(values)); + set(values: DateObjectUnits): this { + return CalendarDate.fromDateTime(super.set(values) as DateTime) as this; } - setLocale(locale: string): CalendarDate { - return CalendarDate.fromDateTime(super.setLocale(locale)); + setLocale(locale: string): this { + return CalendarDate.fromDateTime( + super.setLocale(locale) as DateTime, + ) as this; } setZone(_zone: string | Zone, _options?: ZoneOptions): CalendarDate { - return this; // noop + return this as CalendarDate; // noop } - startOf(unit: DateTimeUnit): CalendarDate { - return CalendarDate.fromDateTime(super.startOf(unit)); + startOf(unit: DateTimeUnit): this { + return CalendarDate.fromDateTime(super.startOf(unit) as DateTime) as this; } - toLocal(): CalendarDate { + toLocal() { return this; // noop } - toUTC(): CalendarDate { + toUTC() { return this; // noop } toPostgres() { - return this.toSQLDate(); + return this.toSQLDate()!; } [inspect.custom]() { diff --git a/src/common/temporal/date-interval.ts b/src/common/temporal/date-interval.ts index 769b48a9aa..0d8908d085 100644 --- a/src/common/temporal/date-interval.ts +++ b/src/common/temporal/date-interval.ts @@ -37,14 +37,12 @@ export class DateInterval } protected constructor(config: Required) { - config.start = - config.start instanceof CalendarDate - ? config.start - : CalendarDate.fromDateTime(config.start); - config.end = - config.end instanceof CalendarDate - ? config.end - : CalendarDate.fromDateTime(config.end); + config.start = CalendarDate.isDate(config.start) + ? config.start + : CalendarDate.fromDateTime(config.start); + config.end = CalendarDate.isDate(config.end) + ? config.end + : CalendarDate.fromDateTime(config.end); super(config); } diff --git a/src/core/database/parameter-transformer.service.ts b/src/core/database/parameter-transformer.service.ts index ac8db6a74f..557be50d39 100644 --- a/src/core/database/parameter-transformer.service.ts +++ b/src/core/database/parameter-transformer.service.ts @@ -33,11 +33,11 @@ export class ParameterTransformer { return value; } - if (value instanceof CalendarDate) { + if (CalendarDate.isDate(value)) { return value.toNeo4JDate(); } - if (value instanceof DateTime) { + if (DateTime.isDateTime(value)) { return value.toNeo4JDateTime(); } diff --git a/yarn.lock b/yarn.lock index 16507a6747..8c5b2df0d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3628,10 +3628,10 @@ __metadata: languageName: node linkType: hard -"@types/luxon@npm:^3.3.3": - version: 3.3.3 - resolution: "@types/luxon@npm:3.3.3" - checksum: 10c0/169ce8eb8860f3ad9ef146c2c7a2d9bc09775b8af93fb346f1222e67e4f98559201cf38ed6d8dc9a72d9535b1cf9a46415cf95591e56d2d72101babce2996de3 +"@types/luxon@npm:^3.4.2": + version: 3.4.2 + resolution: "@types/luxon@npm:3.4.2" + checksum: 10c0/d835467de3daf7e17ba78b50bb5a14efd94272439ca067990d71332a54b311544459c69623eddd243b511b28d70194c9591a9ee8cf9c038962c965f991affd7e languageName: node linkType: hard @@ -5370,7 +5370,7 @@ __metadata: "@types/jest": "npm:^29.5.7" "@types/jsonwebtoken": "npm:^9.0.4" "@types/lodash": "npm:^4.14.200" - "@types/luxon": "npm:^3.3.3" + "@types/luxon": "npm:^3.4.2" "@types/node": "npm:^20.12.5" "@types/prismjs": "npm:^1.26.2" "@types/react": "npm:^18.2.33" @@ -5420,7 +5420,7 @@ __metadata: lint-staged: "npm:^14.0.1" lodash: "npm:lodash-es@^4.17.21" lru-cache: "npm:^7.18.3" - luxon: "npm:^3.4.3" + luxon: "npm:^3.5.0" mime: "npm:beta" nanoid: "npm:^4.0.2" neo4j-driver: "npm:^5.20.0" @@ -9416,10 +9416,10 @@ __metadata: languageName: node linkType: hard -"luxon@npm:^3.4.3": - version: 3.4.3 - resolution: "luxon@npm:3.4.3" - checksum: 10c0/65ad727684d367af9c8fcbde05ad7989ef2436a4496b62d993059baaa641e90a5fa74e98f34ee2ff29f7af7f2b27238ca78b87834f9068624e4133d786f87bc7 +"luxon@npm:^3.5.0": + version: 3.5.0 + resolution: "luxon@npm:3.5.0" + checksum: 10c0/335789bba95077db831ef99894edadeb23023b3eb2137a1b56acd0d290082b691cf793143d69e30bc069ec95f0b49f36419f48e951c68014f19ffe12045e3494 languageName: node linkType: hard