@punks/backend-entity-manager 0.0.365 → 0.0.366
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.
- package/dist/cjs/index.js +133 -96
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/serializer.d.ts +2 -0
- package/dist/esm/index.js +133 -96
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/serializer.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -231,8 +231,10 @@ class EntitySerializer {
|
|
|
231
231
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
232
232
|
}
|
|
233
233
|
parseXlsx(data, definition) {
|
|
234
|
+
const dateColumns = definition.columns.filter((x) => x.sheetParser === "date");
|
|
234
235
|
const records = backendCore.excelParse(data, {
|
|
235
236
|
keysTransform: backendCore.ExcelKeyTransform.Lower,
|
|
237
|
+
dateColumns: dateColumns.map((x) => x.name),
|
|
236
238
|
});
|
|
237
239
|
return records.map((x, i) => this.convertSheetRecord(x, definition, i));
|
|
238
240
|
}
|
|
@@ -22235,26 +22237,6 @@ exports.MediaLibraryService = __decorate([
|
|
|
22235
22237
|
__metadata("design:paramtypes", [exports.EntityManagerRegistry])
|
|
22236
22238
|
], exports.MediaLibraryService);
|
|
22237
22239
|
|
|
22238
|
-
function toInteger(dirtyNumber) {
|
|
22239
|
-
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
|
22240
|
-
return NaN;
|
|
22241
|
-
}
|
|
22242
|
-
|
|
22243
|
-
var number = Number(dirtyNumber);
|
|
22244
|
-
|
|
22245
|
-
if (isNaN(number)) {
|
|
22246
|
-
return number;
|
|
22247
|
-
}
|
|
22248
|
-
|
|
22249
|
-
return number < 0 ? Math.ceil(number) : Math.floor(number);
|
|
22250
|
-
}
|
|
22251
|
-
|
|
22252
|
-
function requiredArgs(required, args) {
|
|
22253
|
-
if (args.length < required) {
|
|
22254
|
-
throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
|
|
22255
|
-
}
|
|
22256
|
-
}
|
|
22257
|
-
|
|
22258
22240
|
/**
|
|
22259
22241
|
* @name toDate
|
|
22260
22242
|
* @category Common Helpers
|
|
@@ -22271,9 +22253,11 @@ function requiredArgs(required, args) {
|
|
|
22271
22253
|
*
|
|
22272
22254
|
* **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
|
|
22273
22255
|
*
|
|
22274
|
-
* @
|
|
22275
|
-
*
|
|
22276
|
-
* @
|
|
22256
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22257
|
+
*
|
|
22258
|
+
* @param argument - The value to convert
|
|
22259
|
+
*
|
|
22260
|
+
* @returns The parsed date in the local time zone
|
|
22277
22261
|
*
|
|
22278
22262
|
* @example
|
|
22279
22263
|
* // Clone the date:
|
|
@@ -22285,28 +22269,68 @@ function requiredArgs(required, args) {
|
|
|
22285
22269
|
* const result = toDate(1392098430000)
|
|
22286
22270
|
* //=> Tue Feb 11 2014 11:30:30
|
|
22287
22271
|
*/
|
|
22288
|
-
|
|
22289
22272
|
function toDate(argument) {
|
|
22290
|
-
|
|
22291
|
-
var argStr = Object.prototype.toString.call(argument); // Clone the date
|
|
22273
|
+
const argStr = Object.prototype.toString.call(argument);
|
|
22292
22274
|
|
|
22293
|
-
|
|
22275
|
+
// Clone the date
|
|
22276
|
+
if (
|
|
22277
|
+
argument instanceof Date ||
|
|
22278
|
+
(typeof argument === "object" && argStr === "[object Date]")
|
|
22279
|
+
) {
|
|
22294
22280
|
// Prevent the date to lose the milliseconds when passed to new Date() in IE10
|
|
22295
|
-
return new
|
|
22296
|
-
} else if (
|
|
22281
|
+
return new argument.constructor(+argument);
|
|
22282
|
+
} else if (
|
|
22283
|
+
typeof argument === "number" ||
|
|
22284
|
+
argStr === "[object Number]" ||
|
|
22285
|
+
typeof argument === "string" ||
|
|
22286
|
+
argStr === "[object String]"
|
|
22287
|
+
) {
|
|
22288
|
+
// TODO: Can we get rid of as?
|
|
22297
22289
|
return new Date(argument);
|
|
22298
22290
|
} else {
|
|
22299
|
-
|
|
22300
|
-
// eslint-disable-next-line no-console
|
|
22301
|
-
console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://git.io/fjule"); // eslint-disable-next-line no-console
|
|
22302
|
-
|
|
22303
|
-
console.warn(new Error().stack);
|
|
22304
|
-
}
|
|
22305
|
-
|
|
22291
|
+
// TODO: Can we get rid of as?
|
|
22306
22292
|
return new Date(NaN);
|
|
22307
22293
|
}
|
|
22308
22294
|
}
|
|
22309
22295
|
|
|
22296
|
+
/**
|
|
22297
|
+
* @name constructFrom
|
|
22298
|
+
* @category Generic Helpers
|
|
22299
|
+
* @summary Constructs a date using the reference date and the value
|
|
22300
|
+
*
|
|
22301
|
+
* @description
|
|
22302
|
+
* The function constructs a new date using the constructor from the reference
|
|
22303
|
+
* date and the given value. It helps to build generic functions that accept
|
|
22304
|
+
* date extensions.
|
|
22305
|
+
*
|
|
22306
|
+
* It defaults to `Date` if the passed reference date is a number or a string.
|
|
22307
|
+
*
|
|
22308
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22309
|
+
*
|
|
22310
|
+
* @param date - The reference date to take constructor from
|
|
22311
|
+
* @param value - The value to create the date
|
|
22312
|
+
*
|
|
22313
|
+
* @returns Date initialized using the given date and value
|
|
22314
|
+
*
|
|
22315
|
+
* @example
|
|
22316
|
+
* import { constructFrom } from 'date-fns'
|
|
22317
|
+
*
|
|
22318
|
+
* // A function that clones a date preserving the original type
|
|
22319
|
+
* function cloneDate<DateType extends Date(date: DateType): DateType {
|
|
22320
|
+
* return constructFrom(
|
|
22321
|
+
* date, // Use contrustor from the given date
|
|
22322
|
+
* date.getTime() // Use the date value to create a new date
|
|
22323
|
+
* )
|
|
22324
|
+
* }
|
|
22325
|
+
*/
|
|
22326
|
+
function constructFrom(date, value) {
|
|
22327
|
+
if (date instanceof Date) {
|
|
22328
|
+
return new date.constructor(value);
|
|
22329
|
+
} else {
|
|
22330
|
+
return new Date(value);
|
|
22331
|
+
}
|
|
22332
|
+
}
|
|
22333
|
+
|
|
22310
22334
|
/**
|
|
22311
22335
|
* @name addDays
|
|
22312
22336
|
* @category Day Helpers
|
|
@@ -22315,37 +22339,60 @@ function toDate(argument) {
|
|
|
22315
22339
|
* @description
|
|
22316
22340
|
* Add the specified number of days to the given date.
|
|
22317
22341
|
*
|
|
22318
|
-
*
|
|
22342
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22319
22343
|
*
|
|
22320
|
-
*
|
|
22344
|
+
* @param date - The date to be changed
|
|
22345
|
+
* @param amount - The amount of days to be added.
|
|
22321
22346
|
*
|
|
22322
|
-
* @
|
|
22323
|
-
* @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
|
|
22324
|
-
* @returns {Date} the new date with the days added
|
|
22325
|
-
* @throws {TypeError} 2 arguments required
|
|
22347
|
+
* @returns The new date with the days added
|
|
22326
22348
|
*
|
|
22327
22349
|
* @example
|
|
22328
22350
|
* // Add 10 days to 1 September 2014:
|
|
22329
|
-
*
|
|
22351
|
+
* const result = addDays(new Date(2014, 8, 1), 10)
|
|
22330
22352
|
* //=> Thu Sep 11 2014 00:00:00
|
|
22331
22353
|
*/
|
|
22332
|
-
|
|
22333
|
-
|
|
22334
|
-
|
|
22335
|
-
var date = toDate(dirtyDate);
|
|
22336
|
-
var amount = toInteger(dirtyAmount);
|
|
22337
|
-
|
|
22338
|
-
if (isNaN(amount)) {
|
|
22339
|
-
return new Date(NaN);
|
|
22340
|
-
}
|
|
22341
|
-
|
|
22354
|
+
function addDays(date, amount) {
|
|
22355
|
+
const _date = toDate(date);
|
|
22356
|
+
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
22342
22357
|
if (!amount) {
|
|
22343
22358
|
// If 0 days, no-op to avoid changing times in the hour before end of DST
|
|
22344
|
-
return
|
|
22359
|
+
return _date;
|
|
22345
22360
|
}
|
|
22361
|
+
_date.setDate(_date.getDate() + amount);
|
|
22362
|
+
return _date;
|
|
22363
|
+
}
|
|
22364
|
+
|
|
22365
|
+
/**
|
|
22366
|
+
* @module constants
|
|
22367
|
+
* @summary Useful constants
|
|
22368
|
+
* @description
|
|
22369
|
+
* Collection of useful date constants.
|
|
22370
|
+
*
|
|
22371
|
+
* The constants could be imported from `date-fns/constants`:
|
|
22372
|
+
*
|
|
22373
|
+
* ```ts
|
|
22374
|
+
* import { maxTime, minTime } from "./constants/date-fns/constants";
|
|
22375
|
+
*
|
|
22376
|
+
* function isAllowedTime(time) {
|
|
22377
|
+
* return time <= maxTime && time >= minTime;
|
|
22378
|
+
* }
|
|
22379
|
+
* ```
|
|
22380
|
+
*/
|
|
22346
22381
|
|
|
22347
|
-
|
|
22348
|
-
|
|
22382
|
+
/**
|
|
22383
|
+
* @constant
|
|
22384
|
+
* @name millisecondsInMinute
|
|
22385
|
+
* @summary Milliseconds in 1 minute
|
|
22386
|
+
*/
|
|
22387
|
+
const millisecondsInMinute = 60000;
|
|
22388
|
+
|
|
22389
|
+
function getRoundingMethod(method) {
|
|
22390
|
+
return (number) => {
|
|
22391
|
+
const round = method ? Math[method] : Math.trunc;
|
|
22392
|
+
const result = round(number);
|
|
22393
|
+
// Prevent negative zero
|
|
22394
|
+
return result === 0 ? 0 : result;
|
|
22395
|
+
};
|
|
22349
22396
|
}
|
|
22350
22397
|
|
|
22351
22398
|
/**
|
|
@@ -22356,33 +22403,30 @@ function addDays(dirtyDate, dirtyAmount) {
|
|
|
22356
22403
|
* @description
|
|
22357
22404
|
* Get the number of milliseconds between the given dates.
|
|
22358
22405
|
*
|
|
22359
|
-
*
|
|
22406
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22360
22407
|
*
|
|
22361
|
-
*
|
|
22408
|
+
* @param dateLeft - The later date
|
|
22409
|
+
* @param dateRight - The earlier date
|
|
22362
22410
|
*
|
|
22363
|
-
* @
|
|
22364
|
-
* @param {Date|Number} dateRight - the earlier date
|
|
22365
|
-
* @returns {Number} the number of milliseconds
|
|
22366
|
-
* @throws {TypeError} 2 arguments required
|
|
22411
|
+
* @returns The number of milliseconds
|
|
22367
22412
|
*
|
|
22368
22413
|
* @example
|
|
22369
22414
|
* // How many milliseconds are between
|
|
22370
22415
|
* // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
|
|
22371
|
-
*
|
|
22416
|
+
* const result = differenceInMilliseconds(
|
|
22372
22417
|
* new Date(2014, 6, 2, 12, 30, 21, 700),
|
|
22373
22418
|
* new Date(2014, 6, 2, 12, 30, 20, 600)
|
|
22374
22419
|
* )
|
|
22375
22420
|
* //=> 1100
|
|
22376
22421
|
*/
|
|
22377
|
-
|
|
22378
|
-
|
|
22379
|
-
requiredArgs(2, arguments);
|
|
22380
|
-
var dateLeft = toDate(dirtyDateLeft);
|
|
22381
|
-
var dateRight = toDate(dirtyDateRight);
|
|
22382
|
-
return dateLeft.getTime() - dateRight.getTime();
|
|
22422
|
+
function differenceInMilliseconds(dateLeft, dateRight) {
|
|
22423
|
+
return +toDate(dateLeft) - +toDate(dateRight);
|
|
22383
22424
|
}
|
|
22384
22425
|
|
|
22385
|
-
|
|
22426
|
+
/**
|
|
22427
|
+
* The {@link differenceInMinutes} function options.
|
|
22428
|
+
*/
|
|
22429
|
+
|
|
22386
22430
|
/**
|
|
22387
22431
|
* @name differenceInMinutes
|
|
22388
22432
|
* @category Minute Helpers
|
|
@@ -22391,36 +22435,34 @@ var MILLISECONDS_IN_MINUTE = 60000;
|
|
|
22391
22435
|
* @description
|
|
22392
22436
|
* Get the signed number of full (rounded towards 0) minutes between the given dates.
|
|
22393
22437
|
*
|
|
22394
|
-
*
|
|
22438
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22395
22439
|
*
|
|
22396
|
-
*
|
|
22440
|
+
* @param dateLeft - The later date
|
|
22441
|
+
* @param dateRight - The earlier date
|
|
22442
|
+
* @param options - An object with options.
|
|
22397
22443
|
*
|
|
22398
|
-
* @
|
|
22399
|
-
* @param {Date|Number} dateRight - the earlier date
|
|
22400
|
-
* @returns {Number} the number of minutes
|
|
22401
|
-
* @throws {TypeError} 2 arguments required
|
|
22444
|
+
* @returns The number of minutes
|
|
22402
22445
|
*
|
|
22403
22446
|
* @example
|
|
22404
22447
|
* // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
|
|
22405
|
-
*
|
|
22448
|
+
* const result = differenceInMinutes(
|
|
22406
22449
|
* new Date(2014, 6, 2, 12, 20, 0),
|
|
22407
22450
|
* new Date(2014, 6, 2, 12, 7, 59)
|
|
22408
22451
|
* )
|
|
22409
22452
|
* //=> 12
|
|
22410
22453
|
*
|
|
22411
22454
|
* @example
|
|
22412
|
-
* // How many minutes are
|
|
22413
|
-
*
|
|
22455
|
+
* // How many minutes are between 10:01:59 and 10:00:00
|
|
22456
|
+
* const result = differenceInMinutes(
|
|
22414
22457
|
* new Date(2000, 0, 1, 10, 0, 0),
|
|
22415
22458
|
* new Date(2000, 0, 1, 10, 1, 59)
|
|
22416
22459
|
* )
|
|
22417
22460
|
* //=> -1
|
|
22418
22461
|
*/
|
|
22419
|
-
|
|
22420
|
-
|
|
22421
|
-
|
|
22422
|
-
|
|
22423
|
-
return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
|
|
22462
|
+
function differenceInMinutes(dateLeft, dateRight, options) {
|
|
22463
|
+
const diff =
|
|
22464
|
+
differenceInMilliseconds(dateLeft, dateRight) / millisecondsInMinute;
|
|
22465
|
+
return getRoundingMethod(options?.roundingMethod)(diff);
|
|
22424
22466
|
}
|
|
22425
22467
|
|
|
22426
22468
|
/**
|
|
@@ -22431,25 +22473,20 @@ function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {
|
|
|
22431
22473
|
* @description
|
|
22432
22474
|
* Subtract the specified number of days from the given date.
|
|
22433
22475
|
*
|
|
22434
|
-
*
|
|
22476
|
+
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
22435
22477
|
*
|
|
22436
|
-
*
|
|
22478
|
+
* @param date - The date to be changed
|
|
22479
|
+
* @param amount - The amount of days to be subtracted.
|
|
22437
22480
|
*
|
|
22438
|
-
* @
|
|
22439
|
-
* @param {Number} amount - the amount of days to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
|
|
22440
|
-
* @returns {Date} the new date with the days subtracted
|
|
22441
|
-
* @throws {TypeError} 2 arguments required
|
|
22481
|
+
* @returns The new date with the days subtracted
|
|
22442
22482
|
*
|
|
22443
22483
|
* @example
|
|
22444
22484
|
* // Subtract 10 days from 1 September 2014:
|
|
22445
|
-
*
|
|
22485
|
+
* const result = subDays(new Date(2014, 8, 1), 10)
|
|
22446
22486
|
* //=> Fri Aug 22 2014 00:00:00
|
|
22447
22487
|
*/
|
|
22448
|
-
|
|
22449
|
-
|
|
22450
|
-
requiredArgs(2, arguments);
|
|
22451
|
-
var amount = toInteger(dirtyAmount);
|
|
22452
|
-
return addDays(dirtyDate, -amount);
|
|
22488
|
+
function subDays(date, amount) {
|
|
22489
|
+
return addDays(date, -amount);
|
|
22453
22490
|
}
|
|
22454
22491
|
|
|
22455
22492
|
const WpOperationLockService = (props = {}) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.OperationLockService, {
|