@spytecgps/nova-orm 1.3.1-rc3 → 1.3.1-rc4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +159 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  var typeorm = require('typeorm');
4
4
  var uuid = require('uuid');
5
5
  var dayjs = require('dayjs');
6
- var utc = require('dayjs/plugin/utc');
7
6
 
8
7
  function _interopNamespaceDefault(e) {
9
8
  var n = Object.create(null);
@@ -23,7 +22,6 @@ function _interopNamespaceDefault(e) {
23
22
  }
24
23
 
25
24
  var dayjs__namespace = /*#__PURE__*/_interopNamespaceDefault(dayjs);
26
- var utc__namespace = /*#__PURE__*/_interopNamespaceDefault(utc);
27
25
 
28
26
  /******************************************************************************
29
27
  Copyright (c) Microsoft Corporation.
@@ -16384,9 +16382,165 @@ class DevicePairingsRepository extends BaseRepository {
16384
16382
  }
16385
16383
  }
16386
16384
 
16387
- dayjs__namespace.extend(utc__namespace);
16388
- const now = () => dayjs__namespace.utc().toDate();
16389
- const addMonthsToNow = (months) => dayjs__namespace
16385
+ const SECONDS_A_MINUTE = 60;
16386
+ const MILLISECONDS_A_SECOND = 1000;
16387
+ const MILLISECONDS_A_MINUTE = SECONDS_A_MINUTE * MILLISECONDS_A_SECOND;
16388
+ const MIN = 'minute';
16389
+
16390
+
16391
+ const REGEX_VALID_OFFSET_FORMAT = /[+-]\d\d(?::?\d\d)?/g;
16392
+ const REGEX_OFFSET_HOURS_MINUTES_FORMAT = /([+-]|\d\d)/g;
16393
+
16394
+ function offsetFromString(value = '') {
16395
+ const offset = value.match(REGEX_VALID_OFFSET_FORMAT);
16396
+
16397
+ if (!offset) {
16398
+ return null
16399
+ }
16400
+
16401
+ const [indicator, hoursOffset, minutesOffset] = `${offset[0]}`.match(REGEX_OFFSET_HOURS_MINUTES_FORMAT) || ['-', 0, 0];
16402
+ const totalOffsetInMinutes = (+hoursOffset * 60) + (+minutesOffset);
16403
+
16404
+ if (totalOffsetInMinutes === 0) {
16405
+ return 0
16406
+ }
16407
+
16408
+ return indicator === '+' ? totalOffsetInMinutes : -totalOffsetInMinutes
16409
+ }
16410
+
16411
+
16412
+ var utc = (option, Dayjs, dayjs) => {
16413
+ const proto = Dayjs.prototype;
16414
+ dayjs.utc = function (date) {
16415
+ const cfg = { date, utc: true, args: arguments }; // eslint-disable-line prefer-rest-params
16416
+ return new Dayjs(cfg) // eslint-disable-line no-use-before-define
16417
+ };
16418
+
16419
+ proto.utc = function (keepLocalTime) {
16420
+ const ins = dayjs(this.toDate(), { locale: this.$L, utc: true });
16421
+ if (keepLocalTime) {
16422
+ return ins.add(this.utcOffset(), MIN)
16423
+ }
16424
+ return ins
16425
+ };
16426
+
16427
+ proto.local = function () {
16428
+ return dayjs(this.toDate(), { locale: this.$L, utc: false })
16429
+ };
16430
+
16431
+ const oldParse = proto.parse;
16432
+ proto.parse = function (cfg) {
16433
+ if (cfg.utc) {
16434
+ this.$u = true;
16435
+ }
16436
+ if (!this.$utils().u(cfg.$offset)) {
16437
+ this.$offset = cfg.$offset;
16438
+ }
16439
+ oldParse.call(this, cfg);
16440
+ };
16441
+
16442
+ const oldInit = proto.init;
16443
+ proto.init = function () {
16444
+ if (this.$u) {
16445
+ const { $d } = this;
16446
+ this.$y = $d.getUTCFullYear();
16447
+ this.$M = $d.getUTCMonth();
16448
+ this.$D = $d.getUTCDate();
16449
+ this.$W = $d.getUTCDay();
16450
+ this.$H = $d.getUTCHours();
16451
+ this.$m = $d.getUTCMinutes();
16452
+ this.$s = $d.getUTCSeconds();
16453
+ this.$ms = $d.getUTCMilliseconds();
16454
+ } else {
16455
+ oldInit.call(this);
16456
+ }
16457
+ };
16458
+
16459
+ const oldUtcOffset = proto.utcOffset;
16460
+ proto.utcOffset = function (input, keepLocalTime) {
16461
+ const { u } = this.$utils();
16462
+ if (u(input)) {
16463
+ if (this.$u) {
16464
+ return 0
16465
+ }
16466
+ if (!u(this.$offset)) {
16467
+ return this.$offset
16468
+ }
16469
+ return oldUtcOffset.call(this)
16470
+ }
16471
+ if (typeof input === 'string') {
16472
+ input = offsetFromString(input);
16473
+ if (input === null) {
16474
+ return this
16475
+ }
16476
+ }
16477
+ const offset = Math.abs(input) <= 16 ? input * 60 : input;
16478
+ let ins = this;
16479
+ if (keepLocalTime) {
16480
+ ins.$offset = offset;
16481
+ ins.$u = input === 0;
16482
+ return ins
16483
+ }
16484
+ if (input !== 0) {
16485
+ const localTimezoneOffset = this.$u
16486
+ ? this.toDate().getTimezoneOffset() : -1 * this.utcOffset();
16487
+ ins = this.local().add(offset + localTimezoneOffset, MIN);
16488
+ ins.$offset = offset;
16489
+ ins.$x.$localOffset = localTimezoneOffset;
16490
+ } else {
16491
+ ins = this.utc();
16492
+ }
16493
+ return ins
16494
+ };
16495
+
16496
+ const oldFormat = proto.format;
16497
+ const UTC_FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ss[Z]';
16498
+ proto.format = function (formatStr) {
16499
+ const str = formatStr || (this.$u ? UTC_FORMAT_DEFAULT : '');
16500
+ return oldFormat.call(this, str)
16501
+ };
16502
+
16503
+ proto.valueOf = function () {
16504
+ const addedOffset = !this.$utils().u(this.$offset)
16505
+ ? this.$offset + (this.$x.$localOffset || this.$d.getTimezoneOffset()) : 0;
16506
+ return this.$d.valueOf() - (addedOffset * MILLISECONDS_A_MINUTE)
16507
+ };
16508
+
16509
+ proto.isUTC = function () {
16510
+ return !!this.$u
16511
+ };
16512
+
16513
+ proto.toISOString = function () {
16514
+ return this.toDate().toISOString()
16515
+ };
16516
+
16517
+ proto.toString = function () {
16518
+ return this.toDate().toUTCString()
16519
+ };
16520
+
16521
+ const oldToDate = proto.toDate;
16522
+ proto.toDate = function (type) {
16523
+ if (type === 's' && this.$offset) {
16524
+ return dayjs(this.format('YYYY-MM-DD HH:mm:ss:SSS')).toDate()
16525
+ }
16526
+ return oldToDate.call(this)
16527
+ };
16528
+ const oldDiff = proto.diff;
16529
+ proto.diff = function (input, units, float) {
16530
+ if (input && this.$u === input.$u) {
16531
+ return oldDiff.call(this, input, units, float)
16532
+ }
16533
+ const localThis = this.local();
16534
+ const localInput = dayjs(input).local();
16535
+ return oldDiff.call(localThis, localInput, units, float)
16536
+ };
16537
+ };
16538
+
16539
+ dayjs__namespace.extend(utc);
16540
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16541
+ const extendedDayjs = dayjs__namespace;
16542
+ const now = () => extendedDayjs.utc().toDate();
16543
+ const addMonthsToNow = (months) => extendedDayjs
16390
16544
  .utc()
16391
16545
  .add(months, 'month')
16392
16546
  .toDate();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spytecgps/nova-orm",
3
- "version": "1.3.1-rc3",
3
+ "version": "1.3.1-rc4",
4
4
  "description": "ORM with PlanetScale",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",