@freshpointcz/fresh-core 0.0.17 → 0.0.19

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.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,7 +429,9 @@ __export(index_exports, {
429
429
  ActionCommandCode: () => ActionCommandCode,
430
430
  ApiError: () => ApiError,
431
431
  BaseEntityChangeSubscriber: () => BaseEntityChangeSubscriber,
432
+ BusinessWarning: () => BusinessWarning,
432
433
  Category: () => Category,
434
+ DEFAULT_PAGINATION_PARAMS: () => DEFAULT_PAGINATION_PARAMS,
433
435
  DataHelper: () => DataHelper,
434
436
  DateUtils: () => DateUtils,
435
437
  DepotPoolStatus: () => DepotPoolStatus,
@@ -449,11 +451,17 @@ __export(index_exports, {
449
451
  Singleton: () => Singleton,
450
452
  StatusDto: () => StatusDto,
451
453
  Subcategory: () => Subcategory,
454
+ TO_BINARY_FLAG: () => TO_BINARY_FLAG,
452
455
  TimestampColumn: () => TimestampColumn,
453
456
  TransactionType: () => TransactionType,
457
+ buildPatch: () => buildPatch,
458
+ constructTypeormPagination: () => constructTypeormPagination,
454
459
  createDeferred: () => createDeferred,
455
460
  freshEslintConfig: () => eslint_config_default,
461
+ getPaginationMeta: () => getPaginationMeta,
462
+ getPaginationParams: () => getPaginationParams,
456
463
  hasOwn: () => hasOwn,
464
+ isDecimal: () => isDecimal,
457
465
  isEnumValue: () => isEnumValue,
458
466
  isFlag01: () => isFlag01,
459
467
  isMaybe: () => isMaybe,
@@ -461,7 +469,11 @@ __export(index_exports, {
461
469
  isNumberInRange: () => isNumberInRange,
462
470
  isObject: () => isObject,
463
471
  isString: () => isString,
464
- isValidCron: () => isValidCron
472
+ isValidCron: () => isValidCron,
473
+ listAll: () => listAll,
474
+ parsePaginationFromURL: () => parsePaginationFromURL,
475
+ runWithConcurrency: () => runWithConcurrency,
476
+ toDecimal: () => toDecimal
465
477
  });
466
478
  module.exports = __toCommonJS(index_exports);
467
479
 
@@ -777,6 +789,71 @@ var _StatusDto = class _StatusDto {
777
789
  __name(_StatusDto, "StatusDto");
778
790
  var StatusDto = _StatusDto;
779
791
 
792
+ // src/common/pagination/constructors.ts
793
+ function constructTypeormPagination(params) {
794
+ return {
795
+ take: params.limit,
796
+ skip: params.skip
797
+ };
798
+ }
799
+ __name(constructTypeormPagination, "constructTypeormPagination");
800
+ function parsePaginationFromURL(searchParams) {
801
+ var _a, _b;
802
+ const page = Math.max(1, parseInt((_a = searchParams.get("page")) != null ? _a : "1", 10));
803
+ const limit = Math.min(100, Math.max(1, parseInt((_b = searchParams.get("limit")) != null ? _b : "20", 10)));
804
+ return {
805
+ page,
806
+ limit,
807
+ skip: (page - 1) * limit
808
+ };
809
+ }
810
+ __name(parsePaginationFromURL, "parsePaginationFromURL");
811
+
812
+ // src/common/pagination/pagination-meta.ts
813
+ function getPaginationMeta(total, page, limit) {
814
+ return {
815
+ total,
816
+ page,
817
+ limit,
818
+ totalPages: Math.ceil(total / limit)
819
+ };
820
+ }
821
+ __name(getPaginationMeta, "getPaginationMeta");
822
+
823
+ // src/common/pagination/pagination-params.ts
824
+ function getPaginationParams(params) {
825
+ return {
826
+ ...DEFAULT_PAGINATION_PARAMS,
827
+ ...params
828
+ };
829
+ }
830
+ __name(getPaginationParams, "getPaginationParams");
831
+ var DEFAULT_PAGINATION_PARAMS = {
832
+ page: 1,
833
+ limit: 1e3,
834
+ skip: 0
835
+ };
836
+
837
+ // src/common/pagination/scrapper.ts
838
+ async function listAll(fetchPage, batchSize = 1e3) {
839
+ const results = [];
840
+ let page = 1;
841
+ while (true) {
842
+ const { data, meta } = await fetchPage({
843
+ page,
844
+ limit: batchSize,
845
+ skip: (page - 1) * batchSize
846
+ });
847
+ results.push(...data);
848
+ if (page >= meta.totalPages) {
849
+ break;
850
+ }
851
+ page++;
852
+ }
853
+ return results;
854
+ }
855
+ __name(listAll, "listAll");
856
+
780
857
  // src/common/constants/amount-unit.ts
781
858
  var AMOUNT_UNIT = {
782
859
  1: {
@@ -815,46 +892,53 @@ var import_typeorm5 = require("typeorm");
815
892
  // src/database/entities/fresh-entity.ts
816
893
  var import_typeorm = require("typeorm");
817
894
 
818
- // ../../node_modules/uuid/dist/esm-node/rng.js
819
- var import_crypto = __toESM(require("crypto"));
895
+ // ../../node_modules/uuid/dist/esm/stringify.js
896
+ var byteToHex = [];
897
+ for (let i = 0; i < 256; ++i) {
898
+ byteToHex.push((i + 256).toString(16).slice(1));
899
+ }
900
+ function unsafeStringify(arr, offset = 0) {
901
+ 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();
902
+ }
903
+ __name(unsafeStringify, "unsafeStringify");
904
+
905
+ // ../../node_modules/uuid/dist/esm/rng.js
906
+ var import_crypto = require("crypto");
820
907
  var rnds8Pool = new Uint8Array(256);
821
908
  var poolPtr = rnds8Pool.length;
822
909
  function rng() {
823
910
  if (poolPtr > rnds8Pool.length - 16) {
824
- import_crypto.default.randomFillSync(rnds8Pool);
911
+ (0, import_crypto.randomFillSync)(rnds8Pool);
825
912
  poolPtr = 0;
826
913
  }
827
914
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
828
915
  }
829
916
  __name(rng, "rng");
830
917
 
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"));
918
+ // ../../node_modules/uuid/dist/esm/native.js
919
+ var import_crypto2 = require("crypto");
843
920
  var native_default = {
844
- randomUUID: import_crypto2.default.randomUUID
921
+ randomUUID: import_crypto2.randomUUID
845
922
  };
846
923
 
847
- // ../../node_modules/uuid/dist/esm-node/v4.js
924
+ // ../../node_modules/uuid/dist/esm/v4.js
848
925
  function v4(options, buf, offset) {
926
+ var _a, _b, _c;
849
927
  if (native_default.randomUUID && !buf && !options) {
850
928
  return native_default.randomUUID();
851
929
  }
852
930
  options = options || {};
853
- const rnds = options.random || (options.rng || rng)();
931
+ const rnds = (_c = (_b = options.random) != null ? _b : (_a = options.rng) == null ? void 0 : _a.call(options)) != null ? _c : rng();
932
+ if (rnds.length < 16) {
933
+ throw new Error("Random bytes length must be >= 16");
934
+ }
854
935
  rnds[6] = rnds[6] & 15 | 64;
855
936
  rnds[8] = rnds[8] & 63 | 128;
856
937
  if (buf) {
857
938
  offset = offset || 0;
939
+ if (offset < 0 || offset + 16 > buf.length) {
940
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
941
+ }
858
942
  for (let i = 0; i < 16; ++i) {
859
943
  buf[offset + i] = rnds[i];
860
944
  }
@@ -1318,6 +1402,57 @@ Subcategory = _ts_decorate8([
1318
1402
  (0, import_typeorm9.Entity)()
1319
1403
  ], Subcategory);
1320
1404
 
1405
+ // src/common/typeguards/decimal.ts
1406
+ function toDecimal(num, precision = 9, scale = 2) {
1407
+ const limit = Math.pow(10, precision - scale);
1408
+ if (Math.abs(num) >= limit) {
1409
+ throw new Error(`Value ${num} exceeds the allowed precision of ${precision} and scale of ${scale}.`);
1410
+ }
1411
+ return num.toFixed(scale);
1412
+ }
1413
+ __name(toDecimal, "toDecimal");
1414
+ function isDecimal(v, options) {
1415
+ var _a, _b, _c;
1416
+ const type = typeof v;
1417
+ if ((options == null ? void 0 : options.allowedType) !== void 0 && type !== options.allowedType) {
1418
+ return false;
1419
+ }
1420
+ if (type !== "number" && type !== "string") {
1421
+ return false;
1422
+ }
1423
+ const sep = (_a = options == null ? void 0 : options.decimalPoint) != null ? _a : ".";
1424
+ let intPart;
1425
+ let fracPart;
1426
+ if (type === "number") {
1427
+ const n = v;
1428
+ if (!Number.isFinite(n)) {
1429
+ return false;
1430
+ }
1431
+ const str = n.toString();
1432
+ if (str.includes("e") || str.includes("E")) {
1433
+ return false;
1434
+ }
1435
+ const parts = str.replace("-", "").split(".");
1436
+ intPart = parts[0];
1437
+ fracPart = (_b = parts[1]) != null ? _b : "";
1438
+ } else {
1439
+ const s = v;
1440
+ const escapedSep = sep === "." ? "\\." : ",";
1441
+ const pattern = new RegExp(`^-?\\d+(?:${escapedSep}\\d+)?$`);
1442
+ if (!pattern.test(s)) {
1443
+ return false;
1444
+ }
1445
+ const parts = s.replace("-", "").split(sep);
1446
+ intPart = parts[0];
1447
+ fracPart = (_c = parts[1]) != null ? _c : "";
1448
+ }
1449
+ if ((options == null ? void 0 : options.scale) !== void 0 && fracPart.length > options.scale) {
1450
+ return false;
1451
+ }
1452
+ return (options == null ? void 0 : options.precision) === void 0 || intPart.length + fracPart.length <= options.precision;
1453
+ }
1454
+ __name(isDecimal, "isDecimal");
1455
+
1321
1456
  // src/common/typeguards/enums.ts
1322
1457
  function isEnumValue(enumObj, v) {
1323
1458
  if (!enumObj) {
@@ -1367,6 +1502,40 @@ function isNumberInRange(v, min, max, options) {
1367
1502
  return true;
1368
1503
  }
1369
1504
  __name(isNumberInRange, "isNumberInRange");
1505
+ var TO_BINARY_FLAG = /* @__PURE__ */ __name((v) => v === 1 || v === true ? 1 : 0, "TO_BINARY_FLAG");
1506
+
1507
+ // src/common/utils/async.utils.ts
1508
+ async function runWithConcurrency(items, concurrency, worker) {
1509
+ const queue = [
1510
+ ...items
1511
+ ];
1512
+ const runNext = /* @__PURE__ */ __name(async () => {
1513
+ const item = queue.shift();
1514
+ if (!item) {
1515
+ return;
1516
+ }
1517
+ await worker(item);
1518
+ await runNext();
1519
+ }, "runNext");
1520
+ await Promise.all(Array.from({
1521
+ length: Math.min(concurrency, items.length)
1522
+ }, runNext));
1523
+ }
1524
+ __name(runWithConcurrency, "runWithConcurrency");
1525
+
1526
+ // src/common/utils/patch.utils.ts
1527
+ function buildPatch(data, keys, transforms) {
1528
+ const patch = {};
1529
+ for (const k of keys) {
1530
+ const value = data[k];
1531
+ if (value === void 0) {
1532
+ continue;
1533
+ }
1534
+ patch[k] = (transforms == null ? void 0 : transforms[k]) ? transforms[k](value) : value;
1535
+ }
1536
+ return patch;
1537
+ }
1538
+ __name(buildPatch, "buildPatch");
1370
1539
 
1371
1540
  // src/core/data-helper.ts
1372
1541
  var _DataHelper = class _DataHelper {
@@ -1541,6 +1710,18 @@ var _ApiError = class _ApiError extends Error {
1541
1710
  __name(_ApiError, "ApiError");
1542
1711
  var ApiError = _ApiError;
1543
1712
 
1713
+ // src/core/errors/business-warning.ts
1714
+ var _BusinessWarning = class _BusinessWarning extends Error {
1715
+ constructor(code, message) {
1716
+ super(message);
1717
+ __publicField(this, "code");
1718
+ this.code = code;
1719
+ this.name = "BusinessWarning";
1720
+ }
1721
+ };
1722
+ __name(_BusinessWarning, "BusinessWarning");
1723
+ var BusinessWarning = _BusinessWarning;
1724
+
1544
1725
  // src/types/maybe-type.ts
1545
1726
  function isMaybe(v, inner) {
1546
1727
  return v === null || inner(v);
@@ -1735,7 +1916,9 @@ var datasource_default = PG_DATA_SOURCE_OPTIONS;
1735
1916
  ActionCommandCode,
1736
1917
  ApiError,
1737
1918
  BaseEntityChangeSubscriber,
1919
+ BusinessWarning,
1738
1920
  Category,
1921
+ DEFAULT_PAGINATION_PARAMS,
1739
1922
  DataHelper,
1740
1923
  DateUtils,
1741
1924
  DepotPoolStatus,
@@ -1755,11 +1938,17 @@ var datasource_default = PG_DATA_SOURCE_OPTIONS;
1755
1938
  Singleton,
1756
1939
  StatusDto,
1757
1940
  Subcategory,
1941
+ TO_BINARY_FLAG,
1758
1942
  TimestampColumn,
1759
1943
  TransactionType,
1944
+ buildPatch,
1945
+ constructTypeormPagination,
1760
1946
  createDeferred,
1761
1947
  freshEslintConfig,
1948
+ getPaginationMeta,
1949
+ getPaginationParams,
1762
1950
  hasOwn,
1951
+ isDecimal,
1763
1952
  isEnumValue,
1764
1953
  isFlag01,
1765
1954
  isMaybe,
@@ -1767,6 +1956,10 @@ var datasource_default = PG_DATA_SOURCE_OPTIONS;
1767
1956
  isNumberInRange,
1768
1957
  isObject,
1769
1958
  isString,
1770
- isValidCron
1959
+ isValidCron,
1960
+ listAll,
1961
+ parsePaginationFromURL,
1962
+ runWithConcurrency,
1963
+ toDecimal
1771
1964
  });
1772
1965
  //# sourceMappingURL=index.js.map