@punks/backend-entity-manager 0.0.364 → 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 CHANGED
@@ -192,6 +192,7 @@ class EntitySeeder {
192
192
  }
193
193
  }
194
194
 
195
+ const normalizeSheetColumn = (column) => column.replace(/ /g, "").toLowerCase();
195
196
  const DEFAULT_DELIMITER = ";";
196
197
  class EntitySerializer {
197
198
  constructor(services, options) {
@@ -230,7 +231,11 @@ class EntitySerializer {
230
231
  return records.map((x, i) => this.convertSheetRecord(x, definition, i));
231
232
  }
232
233
  parseXlsx(data, definition) {
233
- const records = backendCore.excelParse(data);
234
+ const dateColumns = definition.columns.filter((x) => x.sheetParser === "date");
235
+ const records = backendCore.excelParse(data, {
236
+ keysTransform: backendCore.ExcelKeyTransform.Lower,
237
+ dateColumns: dateColumns.map((x) => x.name),
238
+ });
234
239
  return records.map((x, i) => this.convertSheetRecord(x, definition, i));
235
240
  }
236
241
  convertSheetRecord(record, definition, rowIndex) {
@@ -240,8 +245,9 @@ class EntitySerializer {
240
245
  }
241
246
  const entity = {};
242
247
  for (const column of definition.columns) {
248
+ const columnName = normalizeSheetColumn(column.name);
243
249
  if (column.parseAction) {
244
- column.parseAction(record[column.name], entity);
250
+ column.parseAction(record[columnName], entity);
245
251
  continue;
246
252
  }
247
253
  if (typeof column.selector === "function") {
@@ -278,7 +284,8 @@ class EntitySerializer {
278
284
  };
279
285
  }
280
286
  parseColumnValue(row, definition) {
281
- const rawValue = row[definition.name];
287
+ const columnName = normalizeSheetColumn(definition.name);
288
+ const rawValue = row[columnName];
282
289
  return definition.parser ? definition.parser(rawValue) : rawValue;
283
290
  }
284
291
  async createSample(format) {
@@ -22230,26 +22237,6 @@ exports.MediaLibraryService = __decorate([
22230
22237
  __metadata("design:paramtypes", [exports.EntityManagerRegistry])
22231
22238
  ], exports.MediaLibraryService);
22232
22239
 
22233
- function toInteger(dirtyNumber) {
22234
- if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
22235
- return NaN;
22236
- }
22237
-
22238
- var number = Number(dirtyNumber);
22239
-
22240
- if (isNaN(number)) {
22241
- return number;
22242
- }
22243
-
22244
- return number < 0 ? Math.ceil(number) : Math.floor(number);
22245
- }
22246
-
22247
- function requiredArgs(required, args) {
22248
- if (args.length < required) {
22249
- throw new TypeError(required + ' argument' + (required > 1 ? 's' : '') + ' required, but only ' + args.length + ' present');
22250
- }
22251
- }
22252
-
22253
22240
  /**
22254
22241
  * @name toDate
22255
22242
  * @category Common Helpers
@@ -22266,9 +22253,11 @@ function requiredArgs(required, args) {
22266
22253
  *
22267
22254
  * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
22268
22255
  *
22269
- * @param {Date|Number} argument - the value to convert
22270
- * @returns {Date} the parsed date in the local time zone
22271
- * @throws {TypeError} 1 argument required
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
22272
22261
  *
22273
22262
  * @example
22274
22263
  * // Clone the date:
@@ -22280,28 +22269,68 @@ function requiredArgs(required, args) {
22280
22269
  * const result = toDate(1392098430000)
22281
22270
  * //=> Tue Feb 11 2014 11:30:30
22282
22271
  */
22283
-
22284
22272
  function toDate(argument) {
22285
- requiredArgs(1, arguments);
22286
- var argStr = Object.prototype.toString.call(argument); // Clone the date
22273
+ const argStr = Object.prototype.toString.call(argument);
22287
22274
 
22288
- if (argument instanceof Date || typeof argument === 'object' && argStr === '[object Date]') {
22275
+ // Clone the date
22276
+ if (
22277
+ argument instanceof Date ||
22278
+ (typeof argument === "object" && argStr === "[object Date]")
22279
+ ) {
22289
22280
  // Prevent the date to lose the milliseconds when passed to new Date() in IE10
22290
- return new Date(argument.getTime());
22291
- } else if (typeof argument === 'number' || argStr === '[object Number]') {
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?
22292
22289
  return new Date(argument);
22293
22290
  } else {
22294
- if ((typeof argument === 'string' || argStr === '[object String]') && typeof console !== 'undefined') {
22295
- // eslint-disable-next-line no-console
22296
- 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
22297
-
22298
- console.warn(new Error().stack);
22299
- }
22300
-
22291
+ // TODO: Can we get rid of as?
22301
22292
  return new Date(NaN);
22302
22293
  }
22303
22294
  }
22304
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
+
22305
22334
  /**
22306
22335
  * @name addDays
22307
22336
  * @category Day Helpers
@@ -22310,37 +22339,60 @@ function toDate(argument) {
22310
22339
  * @description
22311
22340
  * Add the specified number of days to the given date.
22312
22341
  *
22313
- * ### v2.0.0 breaking changes:
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).
22314
22343
  *
22315
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
22344
+ * @param date - The date to be changed
22345
+ * @param amount - The amount of days to be added.
22316
22346
  *
22317
- * @param {Date|Number} date - the date to be changed
22318
- * @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`.
22319
- * @returns {Date} the new date with the days added
22320
- * @throws {TypeError} 2 arguments required
22347
+ * @returns The new date with the days added
22321
22348
  *
22322
22349
  * @example
22323
22350
  * // Add 10 days to 1 September 2014:
22324
- * var result = addDays(new Date(2014, 8, 1), 10)
22351
+ * const result = addDays(new Date(2014, 8, 1), 10)
22325
22352
  * //=> Thu Sep 11 2014 00:00:00
22326
22353
  */
22327
-
22328
- function addDays(dirtyDate, dirtyAmount) {
22329
- requiredArgs(2, arguments);
22330
- var date = toDate(dirtyDate);
22331
- var amount = toInteger(dirtyAmount);
22332
-
22333
- if (isNaN(amount)) {
22334
- return new Date(NaN);
22335
- }
22336
-
22354
+ function addDays(date, amount) {
22355
+ const _date = toDate(date);
22356
+ if (isNaN(amount)) return constructFrom(date, NaN);
22337
22357
  if (!amount) {
22338
22358
  // If 0 days, no-op to avoid changing times in the hour before end of DST
22339
- return date;
22359
+ return _date;
22340
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
+ */
22341
22381
 
22342
- date.setDate(date.getDate() + amount);
22343
- return date;
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
+ };
22344
22396
  }
22345
22397
 
22346
22398
  /**
@@ -22351,33 +22403,30 @@ function addDays(dirtyDate, dirtyAmount) {
22351
22403
  * @description
22352
22404
  * Get the number of milliseconds between the given dates.
22353
22405
  *
22354
- * ### v2.0.0 breaking changes:
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).
22355
22407
  *
22356
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
22408
+ * @param dateLeft - The later date
22409
+ * @param dateRight - The earlier date
22357
22410
  *
22358
- * @param {Date|Number} dateLeft - the later date
22359
- * @param {Date|Number} dateRight - the earlier date
22360
- * @returns {Number} the number of milliseconds
22361
- * @throws {TypeError} 2 arguments required
22411
+ * @returns The number of milliseconds
22362
22412
  *
22363
22413
  * @example
22364
22414
  * // How many milliseconds are between
22365
22415
  * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
22366
- * var result = differenceInMilliseconds(
22416
+ * const result = differenceInMilliseconds(
22367
22417
  * new Date(2014, 6, 2, 12, 30, 21, 700),
22368
22418
  * new Date(2014, 6, 2, 12, 30, 20, 600)
22369
22419
  * )
22370
22420
  * //=> 1100
22371
22421
  */
22372
-
22373
- function differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) {
22374
- requiredArgs(2, arguments);
22375
- var dateLeft = toDate(dirtyDateLeft);
22376
- var dateRight = toDate(dirtyDateRight);
22377
- return dateLeft.getTime() - dateRight.getTime();
22422
+ function differenceInMilliseconds(dateLeft, dateRight) {
22423
+ return +toDate(dateLeft) - +toDate(dateRight);
22378
22424
  }
22379
22425
 
22380
- var MILLISECONDS_IN_MINUTE = 60000;
22426
+ /**
22427
+ * The {@link differenceInMinutes} function options.
22428
+ */
22429
+
22381
22430
  /**
22382
22431
  * @name differenceInMinutes
22383
22432
  * @category Minute Helpers
@@ -22386,36 +22435,34 @@ var MILLISECONDS_IN_MINUTE = 60000;
22386
22435
  * @description
22387
22436
  * Get the signed number of full (rounded towards 0) minutes between the given dates.
22388
22437
  *
22389
- * ### v2.0.0 breaking changes:
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).
22390
22439
  *
22391
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
22440
+ * @param dateLeft - The later date
22441
+ * @param dateRight - The earlier date
22442
+ * @param options - An object with options.
22392
22443
  *
22393
- * @param {Date|Number} dateLeft - the later date
22394
- * @param {Date|Number} dateRight - the earlier date
22395
- * @returns {Number} the number of minutes
22396
- * @throws {TypeError} 2 arguments required
22444
+ * @returns The number of minutes
22397
22445
  *
22398
22446
  * @example
22399
22447
  * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?
22400
- * var result = differenceInMinutes(
22448
+ * const result = differenceInMinutes(
22401
22449
  * new Date(2014, 6, 2, 12, 20, 0),
22402
22450
  * new Date(2014, 6, 2, 12, 7, 59)
22403
22451
  * )
22404
22452
  * //=> 12
22405
22453
  *
22406
22454
  * @example
22407
- * // How many minutes are from 10:01:59 to 10:00:00
22408
- * var result = differenceInMinutes(
22455
+ * // How many minutes are between 10:01:59 and 10:00:00
22456
+ * const result = differenceInMinutes(
22409
22457
  * new Date(2000, 0, 1, 10, 0, 0),
22410
22458
  * new Date(2000, 0, 1, 10, 1, 59)
22411
22459
  * )
22412
22460
  * //=> -1
22413
22461
  */
22414
-
22415
- function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {
22416
- requiredArgs(2, arguments);
22417
- var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_MINUTE;
22418
- 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);
22419
22466
  }
22420
22467
 
22421
22468
  /**
@@ -22426,25 +22473,20 @@ function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {
22426
22473
  * @description
22427
22474
  * Subtract the specified number of days from the given date.
22428
22475
  *
22429
- * ### v2.0.0 breaking changes:
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).
22430
22477
  *
22431
- * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
22478
+ * @param date - The date to be changed
22479
+ * @param amount - The amount of days to be subtracted.
22432
22480
  *
22433
- * @param {Date|Number} date - the date to be changed
22434
- * @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`.
22435
- * @returns {Date} the new date with the days subtracted
22436
- * @throws {TypeError} 2 arguments required
22481
+ * @returns The new date with the days subtracted
22437
22482
  *
22438
22483
  * @example
22439
22484
  * // Subtract 10 days from 1 September 2014:
22440
- * var result = subDays(new Date(2014, 8, 1), 10)
22485
+ * const result = subDays(new Date(2014, 8, 1), 10)
22441
22486
  * //=> Fri Aug 22 2014 00:00:00
22442
22487
  */
22443
-
22444
- function subDays(dirtyDate, dirtyAmount) {
22445
- requiredArgs(2, arguments);
22446
- var amount = toInteger(dirtyAmount);
22447
- return addDays(dirtyDate, -amount);
22488
+ function subDays(date, amount) {
22489
+ return addDays(date, -amount);
22448
22490
  }
22449
22491
 
22450
22492
  const WpOperationLockService = (props = {}) => common.applyDecorators(common.Injectable(), common.SetMetadata(EntityManagerSymbols.OperationLockService, {