@freshpointcz/fresh-core 0.0.17 → 0.0.18

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/index.d.mts CHANGED
@@ -474,6 +474,46 @@ declare function isNumberInRange(v: unknown, min: number, max: number, options?:
474
474
  includeMin?: boolean;
475
475
  includeMax?: boolean;
476
476
  }): v is number;
477
+ /**
478
+ * Numeric boolean flag type — either 0 or 1
479
+ */
480
+ type BinaryFlag = 0 | 1;
481
+ /**
482
+ * Converts a number, boolean, null, or undefined to a BinaryFlag (0 or 1)
483
+ *
484
+ * @example
485
+ * TO_BINARY_FLAG(true) // 1
486
+ * TO_BINARY_FLAG(1) // 1
487
+ * TO_BINARY_FLAG(false) // 0
488
+ * TO_BINARY_FLAG(null) // 0
489
+ */
490
+ declare const TO_BINARY_FLAG: (v: number | boolean | null | undefined) => BinaryFlag;
491
+
492
+ /**
493
+ * Runs async worker functions over items with a concurrency limit.
494
+ *
495
+ * @param items - Array of items to process
496
+ * @param concurrency - Maximum number of concurrent workers
497
+ * @param worker - Async function to run for each item
498
+ *
499
+ * @example
500
+ * await runWithConcurrency(productIds, 5, async (id) => {
501
+ * await processProduct(id);
502
+ * });
503
+ */
504
+ declare function runWithConcurrency<T>(items: T[], concurrency: number, worker: (item: T) => Promise<void>): Promise<void>;
505
+
506
+ type TransformMap<TIn, TOut, K extends keyof TIn & keyof TOut> = Partial<{
507
+ [P in K]: (val: TIn[P]) => TOut[P];
508
+ }>;
509
+ /**
510
+ * Builds a partial patch object from an input DTO, only including keys that are defined.
511
+ * Optionally applies transform functions to specific keys.
512
+ *
513
+ * @example
514
+ * const patch = buildPatch(data, ["name", "active"], { active: (v) => v ? 1 : 0 });
515
+ */
516
+ declare function buildPatch<TOut extends Record<string, any>, TIn extends Record<string, any>, K extends keyof TIn & keyof TOut = keyof TIn & keyof TOut>(data: Partial<TIn>, keys: readonly K[], transforms?: TransformMap<TIn, TOut, K>): Partial<Pick<TOut, K>>;
477
517
 
478
518
  type Maybe<T> = T | null;
479
519
  /**
@@ -605,6 +645,18 @@ declare class ApiError extends Error {
605
645
  constructor(statusCode: number, status: Status, detail?: string);
606
646
  }
607
647
 
648
+ /**
649
+ * Represents a non-fatal business rule violation that should be
650
+ * communicated to the caller without being treated as a system error.
651
+ *
652
+ * @example
653
+ * throw new BusinessWarning("ORDER_ALREADY_SENT", "Tato objednávka již byla odeslána.");
654
+ */
655
+ declare class BusinessWarning extends Error {
656
+ readonly code: string;
657
+ constructor(code: string, message: string);
658
+ }
659
+
608
660
  declare const FRESH_ESLINT_CONFIG: {
609
661
  files: string[];
610
662
  ignores: string[];
@@ -682,4 +734,4 @@ interface HealthCheckResult {
682
734
  };
683
735
  }
684
736
 
685
- export { AMOUNT_UNIT, ActionCommandCode, ApiError, BaseEntityChangeSubscriber, type CardNumber, Category, DataHelper, DateUtils, type Deferred, DepotPoolStatus, Device, type EntityChangeEvent, FreshDao, FreshEntity, FreshHyperEntity, FreshJob, FreshTranslationBase, type HealthCheckResult, HttpStatus, LanguageCode, Manufacturer, type Maybe, PaymentMethod, PG_DATA_SOURCE_OPTIONS as PgDataSourceOptions, Product, SinglePromiseWaiter, Singleton, type Status, StatusDto, Subcategory, TimestampColumn, TransactionType, createDeferred, FRESH_ESLINT_CONFIG as freshEslintConfig, hasOwn, isEnumValue, isFlag01, isMaybe, isNumber, isNumberInRange, isObject, isString, isValidCron };
737
+ export { AMOUNT_UNIT, ActionCommandCode, ApiError, BaseEntityChangeSubscriber, type BinaryFlag, BusinessWarning, type CardNumber, Category, DataHelper, DateUtils, type Deferred, DepotPoolStatus, Device, type EntityChangeEvent, FreshDao, FreshEntity, FreshHyperEntity, FreshJob, FreshTranslationBase, type HealthCheckResult, HttpStatus, LanguageCode, Manufacturer, type Maybe, PaymentMethod, PG_DATA_SOURCE_OPTIONS as PgDataSourceOptions, Product, SinglePromiseWaiter, Singleton, type Status, StatusDto, Subcategory, TO_BINARY_FLAG, TimestampColumn, TransactionType, buildPatch, createDeferred, FRESH_ESLINT_CONFIG as freshEslintConfig, hasOwn, isEnumValue, isFlag01, isMaybe, isNumber, isNumberInRange, isObject, isString, isValidCron, runWithConcurrency };
package/dist/index.d.ts CHANGED
@@ -474,6 +474,46 @@ declare function isNumberInRange(v: unknown, min: number, max: number, options?:
474
474
  includeMin?: boolean;
475
475
  includeMax?: boolean;
476
476
  }): v is number;
477
+ /**
478
+ * Numeric boolean flag type — either 0 or 1
479
+ */
480
+ type BinaryFlag = 0 | 1;
481
+ /**
482
+ * Converts a number, boolean, null, or undefined to a BinaryFlag (0 or 1)
483
+ *
484
+ * @example
485
+ * TO_BINARY_FLAG(true) // 1
486
+ * TO_BINARY_FLAG(1) // 1
487
+ * TO_BINARY_FLAG(false) // 0
488
+ * TO_BINARY_FLAG(null) // 0
489
+ */
490
+ declare const TO_BINARY_FLAG: (v: number | boolean | null | undefined) => BinaryFlag;
491
+
492
+ /**
493
+ * Runs async worker functions over items with a concurrency limit.
494
+ *
495
+ * @param items - Array of items to process
496
+ * @param concurrency - Maximum number of concurrent workers
497
+ * @param worker - Async function to run for each item
498
+ *
499
+ * @example
500
+ * await runWithConcurrency(productIds, 5, async (id) => {
501
+ * await processProduct(id);
502
+ * });
503
+ */
504
+ declare function runWithConcurrency<T>(items: T[], concurrency: number, worker: (item: T) => Promise<void>): Promise<void>;
505
+
506
+ type TransformMap<TIn, TOut, K extends keyof TIn & keyof TOut> = Partial<{
507
+ [P in K]: (val: TIn[P]) => TOut[P];
508
+ }>;
509
+ /**
510
+ * Builds a partial patch object from an input DTO, only including keys that are defined.
511
+ * Optionally applies transform functions to specific keys.
512
+ *
513
+ * @example
514
+ * const patch = buildPatch(data, ["name", "active"], { active: (v) => v ? 1 : 0 });
515
+ */
516
+ declare function buildPatch<TOut extends Record<string, any>, TIn extends Record<string, any>, K extends keyof TIn & keyof TOut = keyof TIn & keyof TOut>(data: Partial<TIn>, keys: readonly K[], transforms?: TransformMap<TIn, TOut, K>): Partial<Pick<TOut, K>>;
477
517
 
478
518
  type Maybe<T> = T | null;
479
519
  /**
@@ -605,6 +645,18 @@ declare class ApiError extends Error {
605
645
  constructor(statusCode: number, status: Status, detail?: string);
606
646
  }
607
647
 
648
+ /**
649
+ * Represents a non-fatal business rule violation that should be
650
+ * communicated to the caller without being treated as a system error.
651
+ *
652
+ * @example
653
+ * throw new BusinessWarning("ORDER_ALREADY_SENT", "Tato objednávka již byla odeslána.");
654
+ */
655
+ declare class BusinessWarning extends Error {
656
+ readonly code: string;
657
+ constructor(code: string, message: string);
658
+ }
659
+
608
660
  declare const FRESH_ESLINT_CONFIG: {
609
661
  files: string[];
610
662
  ignores: string[];
@@ -682,4 +734,4 @@ interface HealthCheckResult {
682
734
  };
683
735
  }
684
736
 
685
- export { AMOUNT_UNIT, ActionCommandCode, ApiError, BaseEntityChangeSubscriber, type CardNumber, Category, DataHelper, DateUtils, type Deferred, DepotPoolStatus, Device, type EntityChangeEvent, FreshDao, FreshEntity, FreshHyperEntity, FreshJob, FreshTranslationBase, type HealthCheckResult, HttpStatus, LanguageCode, Manufacturer, type Maybe, PaymentMethod, PG_DATA_SOURCE_OPTIONS as PgDataSourceOptions, Product, SinglePromiseWaiter, Singleton, type Status, StatusDto, Subcategory, TimestampColumn, TransactionType, createDeferred, FRESH_ESLINT_CONFIG as freshEslintConfig, hasOwn, isEnumValue, isFlag01, isMaybe, isNumber, isNumberInRange, isObject, isString, isValidCron };
737
+ export { AMOUNT_UNIT, ActionCommandCode, ApiError, BaseEntityChangeSubscriber, type BinaryFlag, BusinessWarning, type CardNumber, Category, DataHelper, DateUtils, type Deferred, DepotPoolStatus, Device, type EntityChangeEvent, FreshDao, FreshEntity, FreshHyperEntity, FreshJob, FreshTranslationBase, type HealthCheckResult, HttpStatus, LanguageCode, Manufacturer, type Maybe, PaymentMethod, PG_DATA_SOURCE_OPTIONS as PgDataSourceOptions, Product, SinglePromiseWaiter, Singleton, type Status, StatusDto, Subcategory, TO_BINARY_FLAG, TimestampColumn, TransactionType, buildPatch, createDeferred, FRESH_ESLINT_CONFIG as freshEslintConfig, hasOwn, isEnumValue, isFlag01, isMaybe, isNumber, isNumberInRange, isObject, isString, isValidCron, runWithConcurrency };
package/dist/index.js CHANGED
@@ -108,7 +108,7 @@ var require_main = __commonJS({
108
108
  var fs = require("fs");
109
109
  var path2 = require("path");
110
110
  var os = require("os");
111
- var crypto3 = require("crypto");
111
+ var crypto = require("crypto");
112
112
  var packageJson = require_package();
113
113
  var version = packageJson.version;
114
114
  var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
@@ -355,7 +355,7 @@ var require_main = __commonJS({
355
355
  const authTag = ciphertext.subarray(-16);
356
356
  ciphertext = ciphertext.subarray(12, -16);
357
357
  try {
358
- const aesgcm = crypto3.createDecipheriv("aes-256-gcm", key, nonce);
358
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
359
359
  aesgcm.setAuthTag(authTag);
360
360
  return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
361
361
  } catch (error) {
@@ -429,6 +429,7 @@ __export(index_exports, {
429
429
  ActionCommandCode: () => ActionCommandCode,
430
430
  ApiError: () => ApiError,
431
431
  BaseEntityChangeSubscriber: () => BaseEntityChangeSubscriber,
432
+ BusinessWarning: () => BusinessWarning,
432
433
  Category: () => Category,
433
434
  DataHelper: () => DataHelper,
434
435
  DateUtils: () => DateUtils,
@@ -449,8 +450,10 @@ __export(index_exports, {
449
450
  Singleton: () => Singleton,
450
451
  StatusDto: () => StatusDto,
451
452
  Subcategory: () => Subcategory,
453
+ TO_BINARY_FLAG: () => TO_BINARY_FLAG,
452
454
  TimestampColumn: () => TimestampColumn,
453
455
  TransactionType: () => TransactionType,
456
+ buildPatch: () => buildPatch,
454
457
  createDeferred: () => createDeferred,
455
458
  freshEslintConfig: () => eslint_config_default,
456
459
  hasOwn: () => hasOwn,
@@ -461,7 +464,8 @@ __export(index_exports, {
461
464
  isNumberInRange: () => isNumberInRange,
462
465
  isObject: () => isObject,
463
466
  isString: () => isString,
464
- isValidCron: () => isValidCron
467
+ isValidCron: () => isValidCron,
468
+ runWithConcurrency: () => runWithConcurrency
465
469
  });
466
470
  module.exports = __toCommonJS(index_exports);
467
471
 
@@ -815,46 +819,53 @@ var import_typeorm5 = require("typeorm");
815
819
  // src/database/entities/fresh-entity.ts
816
820
  var import_typeorm = require("typeorm");
817
821
 
818
- // ../../node_modules/uuid/dist/esm-node/rng.js
819
- var import_crypto = __toESM(require("crypto"));
822
+ // ../../node_modules/uuid/dist/esm/stringify.js
823
+ var byteToHex = [];
824
+ for (let i = 0; i < 256; ++i) {
825
+ byteToHex.push((i + 256).toString(16).slice(1));
826
+ }
827
+ function unsafeStringify(arr, offset = 0) {
828
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
829
+ }
830
+ __name(unsafeStringify, "unsafeStringify");
831
+
832
+ // ../../node_modules/uuid/dist/esm/rng.js
833
+ var import_crypto = require("crypto");
820
834
  var rnds8Pool = new Uint8Array(256);
821
835
  var poolPtr = rnds8Pool.length;
822
836
  function rng() {
823
837
  if (poolPtr > rnds8Pool.length - 16) {
824
- import_crypto.default.randomFillSync(rnds8Pool);
838
+ (0, import_crypto.randomFillSync)(rnds8Pool);
825
839
  poolPtr = 0;
826
840
  }
827
841
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
828
842
  }
829
843
  __name(rng, "rng");
830
844
 
831
- // ../../node_modules/uuid/dist/esm-node/stringify.js
832
- var byteToHex = [];
833
- for (let i = 0; i < 256; ++i) {
834
- byteToHex.push((i + 256).toString(16).slice(1));
835
- }
836
- function unsafeStringify(arr, offset = 0) {
837
- return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
838
- }
839
- __name(unsafeStringify, "unsafeStringify");
840
-
841
- // ../../node_modules/uuid/dist/esm-node/native.js
842
- var import_crypto2 = __toESM(require("crypto"));
845
+ // ../../node_modules/uuid/dist/esm/native.js
846
+ var import_crypto2 = require("crypto");
843
847
  var native_default = {
844
- randomUUID: import_crypto2.default.randomUUID
848
+ randomUUID: import_crypto2.randomUUID
845
849
  };
846
850
 
847
- // ../../node_modules/uuid/dist/esm-node/v4.js
851
+ // ../../node_modules/uuid/dist/esm/v4.js
848
852
  function v4(options, buf, offset) {
853
+ var _a, _b, _c;
849
854
  if (native_default.randomUUID && !buf && !options) {
850
855
  return native_default.randomUUID();
851
856
  }
852
857
  options = options || {};
853
- const rnds = options.random || (options.rng || rng)();
858
+ const rnds = (_c = (_b = options.random) != null ? _b : (_a = options.rng) == null ? void 0 : _a.call(options)) != null ? _c : rng();
859
+ if (rnds.length < 16) {
860
+ throw new Error("Random bytes length must be >= 16");
861
+ }
854
862
  rnds[6] = rnds[6] & 15 | 64;
855
863
  rnds[8] = rnds[8] & 63 | 128;
856
864
  if (buf) {
857
865
  offset = offset || 0;
866
+ if (offset < 0 || offset + 16 > buf.length) {
867
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
868
+ }
858
869
  for (let i = 0; i < 16; ++i) {
859
870
  buf[offset + i] = rnds[i];
860
871
  }
@@ -1367,6 +1378,40 @@ function isNumberInRange(v, min, max, options) {
1367
1378
  return true;
1368
1379
  }
1369
1380
  __name(isNumberInRange, "isNumberInRange");
1381
+ var TO_BINARY_FLAG = /* @__PURE__ */ __name((v) => v === 1 || v === true ? 1 : 0, "TO_BINARY_FLAG");
1382
+
1383
+ // src/common/utils/async.utils.ts
1384
+ async function runWithConcurrency(items, concurrency, worker) {
1385
+ const queue = [
1386
+ ...items
1387
+ ];
1388
+ const runNext = /* @__PURE__ */ __name(async () => {
1389
+ const item = queue.shift();
1390
+ if (!item) {
1391
+ return;
1392
+ }
1393
+ await worker(item);
1394
+ await runNext();
1395
+ }, "runNext");
1396
+ await Promise.all(Array.from({
1397
+ length: Math.min(concurrency, items.length)
1398
+ }, runNext));
1399
+ }
1400
+ __name(runWithConcurrency, "runWithConcurrency");
1401
+
1402
+ // src/common/utils/patch.utils.ts
1403
+ function buildPatch(data, keys, transforms) {
1404
+ const patch = {};
1405
+ for (const k of keys) {
1406
+ const value = data[k];
1407
+ if (value === void 0) {
1408
+ continue;
1409
+ }
1410
+ patch[k] = (transforms == null ? void 0 : transforms[k]) ? transforms[k](value) : value;
1411
+ }
1412
+ return patch;
1413
+ }
1414
+ __name(buildPatch, "buildPatch");
1370
1415
 
1371
1416
  // src/core/data-helper.ts
1372
1417
  var _DataHelper = class _DataHelper {
@@ -1541,6 +1586,18 @@ var _ApiError = class _ApiError extends Error {
1541
1586
  __name(_ApiError, "ApiError");
1542
1587
  var ApiError = _ApiError;
1543
1588
 
1589
+ // src/core/errors/business-warning.ts
1590
+ var _BusinessWarning = class _BusinessWarning extends Error {
1591
+ constructor(code, message) {
1592
+ super(message);
1593
+ __publicField(this, "code");
1594
+ this.code = code;
1595
+ this.name = "BusinessWarning";
1596
+ }
1597
+ };
1598
+ __name(_BusinessWarning, "BusinessWarning");
1599
+ var BusinessWarning = _BusinessWarning;
1600
+
1544
1601
  // src/types/maybe-type.ts
1545
1602
  function isMaybe(v, inner) {
1546
1603
  return v === null || inner(v);
@@ -1735,6 +1792,7 @@ var datasource_default = PG_DATA_SOURCE_OPTIONS;
1735
1792
  ActionCommandCode,
1736
1793
  ApiError,
1737
1794
  BaseEntityChangeSubscriber,
1795
+ BusinessWarning,
1738
1796
  Category,
1739
1797
  DataHelper,
1740
1798
  DateUtils,
@@ -1755,8 +1813,10 @@ var datasource_default = PG_DATA_SOURCE_OPTIONS;
1755
1813
  Singleton,
1756
1814
  StatusDto,
1757
1815
  Subcategory,
1816
+ TO_BINARY_FLAG,
1758
1817
  TimestampColumn,
1759
1818
  TransactionType,
1819
+ buildPatch,
1760
1820
  createDeferred,
1761
1821
  freshEslintConfig,
1762
1822
  hasOwn,
@@ -1767,6 +1827,7 @@ var datasource_default = PG_DATA_SOURCE_OPTIONS;
1767
1827
  isNumberInRange,
1768
1828
  isObject,
1769
1829
  isString,
1770
- isValidCron
1830
+ isValidCron,
1831
+ runWithConcurrency
1771
1832
  });
1772
1833
  //# sourceMappingURL=index.js.map