@freshpointcz/fresh-core 0.0.18 → 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.d.mts +362 -1
- package/dist/index.d.ts +362 -1
- package/dist/index.js +134 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -734,6 +734,71 @@ var _StatusDto = class _StatusDto {
|
|
|
734
734
|
__name(_StatusDto, "StatusDto");
|
|
735
735
|
var StatusDto = _StatusDto;
|
|
736
736
|
|
|
737
|
+
// src/common/pagination/constructors.ts
|
|
738
|
+
function constructTypeormPagination(params) {
|
|
739
|
+
return {
|
|
740
|
+
take: params.limit,
|
|
741
|
+
skip: params.skip
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
__name(constructTypeormPagination, "constructTypeormPagination");
|
|
745
|
+
function parsePaginationFromURL(searchParams) {
|
|
746
|
+
var _a, _b;
|
|
747
|
+
const page = Math.max(1, parseInt((_a = searchParams.get("page")) != null ? _a : "1", 10));
|
|
748
|
+
const limit = Math.min(100, Math.max(1, parseInt((_b = searchParams.get("limit")) != null ? _b : "20", 10)));
|
|
749
|
+
return {
|
|
750
|
+
page,
|
|
751
|
+
limit,
|
|
752
|
+
skip: (page - 1) * limit
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
__name(parsePaginationFromURL, "parsePaginationFromURL");
|
|
756
|
+
|
|
757
|
+
// src/common/pagination/pagination-meta.ts
|
|
758
|
+
function getPaginationMeta(total, page, limit) {
|
|
759
|
+
return {
|
|
760
|
+
total,
|
|
761
|
+
page,
|
|
762
|
+
limit,
|
|
763
|
+
totalPages: Math.ceil(total / limit)
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
__name(getPaginationMeta, "getPaginationMeta");
|
|
767
|
+
|
|
768
|
+
// src/common/pagination/pagination-params.ts
|
|
769
|
+
function getPaginationParams(params) {
|
|
770
|
+
return {
|
|
771
|
+
...DEFAULT_PAGINATION_PARAMS,
|
|
772
|
+
...params
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
__name(getPaginationParams, "getPaginationParams");
|
|
776
|
+
var DEFAULT_PAGINATION_PARAMS = {
|
|
777
|
+
page: 1,
|
|
778
|
+
limit: 1e3,
|
|
779
|
+
skip: 0
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
// src/common/pagination/scrapper.ts
|
|
783
|
+
async function listAll(fetchPage, batchSize = 1e3) {
|
|
784
|
+
const results = [];
|
|
785
|
+
let page = 1;
|
|
786
|
+
while (true) {
|
|
787
|
+
const { data, meta } = await fetchPage({
|
|
788
|
+
page,
|
|
789
|
+
limit: batchSize,
|
|
790
|
+
skip: (page - 1) * batchSize
|
|
791
|
+
});
|
|
792
|
+
results.push(...data);
|
|
793
|
+
if (page >= meta.totalPages) {
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
page++;
|
|
797
|
+
}
|
|
798
|
+
return results;
|
|
799
|
+
}
|
|
800
|
+
__name(listAll, "listAll");
|
|
801
|
+
|
|
737
802
|
// src/common/constants/amount-unit.ts
|
|
738
803
|
var AMOUNT_UNIT = {
|
|
739
804
|
1: {
|
|
@@ -1282,6 +1347,57 @@ Subcategory = _ts_decorate8([
|
|
|
1282
1347
|
Entity5()
|
|
1283
1348
|
], Subcategory);
|
|
1284
1349
|
|
|
1350
|
+
// src/common/typeguards/decimal.ts
|
|
1351
|
+
function toDecimal(num, precision = 9, scale = 2) {
|
|
1352
|
+
const limit = Math.pow(10, precision - scale);
|
|
1353
|
+
if (Math.abs(num) >= limit) {
|
|
1354
|
+
throw new Error(`Value ${num} exceeds the allowed precision of ${precision} and scale of ${scale}.`);
|
|
1355
|
+
}
|
|
1356
|
+
return num.toFixed(scale);
|
|
1357
|
+
}
|
|
1358
|
+
__name(toDecimal, "toDecimal");
|
|
1359
|
+
function isDecimal(v, options) {
|
|
1360
|
+
var _a, _b, _c;
|
|
1361
|
+
const type = typeof v;
|
|
1362
|
+
if ((options == null ? void 0 : options.allowedType) !== void 0 && type !== options.allowedType) {
|
|
1363
|
+
return false;
|
|
1364
|
+
}
|
|
1365
|
+
if (type !== "number" && type !== "string") {
|
|
1366
|
+
return false;
|
|
1367
|
+
}
|
|
1368
|
+
const sep = (_a = options == null ? void 0 : options.decimalPoint) != null ? _a : ".";
|
|
1369
|
+
let intPart;
|
|
1370
|
+
let fracPart;
|
|
1371
|
+
if (type === "number") {
|
|
1372
|
+
const n = v;
|
|
1373
|
+
if (!Number.isFinite(n)) {
|
|
1374
|
+
return false;
|
|
1375
|
+
}
|
|
1376
|
+
const str = n.toString();
|
|
1377
|
+
if (str.includes("e") || str.includes("E")) {
|
|
1378
|
+
return false;
|
|
1379
|
+
}
|
|
1380
|
+
const parts = str.replace("-", "").split(".");
|
|
1381
|
+
intPart = parts[0];
|
|
1382
|
+
fracPart = (_b = parts[1]) != null ? _b : "";
|
|
1383
|
+
} else {
|
|
1384
|
+
const s = v;
|
|
1385
|
+
const escapedSep = sep === "." ? "\\." : ",";
|
|
1386
|
+
const pattern = new RegExp(`^-?\\d+(?:${escapedSep}\\d+)?$`);
|
|
1387
|
+
if (!pattern.test(s)) {
|
|
1388
|
+
return false;
|
|
1389
|
+
}
|
|
1390
|
+
const parts = s.replace("-", "").split(sep);
|
|
1391
|
+
intPart = parts[0];
|
|
1392
|
+
fracPart = (_c = parts[1]) != null ? _c : "";
|
|
1393
|
+
}
|
|
1394
|
+
if ((options == null ? void 0 : options.scale) !== void 0 && fracPart.length > options.scale) {
|
|
1395
|
+
return false;
|
|
1396
|
+
}
|
|
1397
|
+
return (options == null ? void 0 : options.precision) === void 0 || intPart.length + fracPart.length <= options.precision;
|
|
1398
|
+
}
|
|
1399
|
+
__name(isDecimal, "isDecimal");
|
|
1400
|
+
|
|
1285
1401
|
// src/common/typeguards/enums.ts
|
|
1286
1402
|
function isEnumValue(enumObj, v) {
|
|
1287
1403
|
if (!enumObj) {
|
|
@@ -1746,6 +1862,7 @@ export {
|
|
|
1746
1862
|
BaseEntityChangeSubscriber,
|
|
1747
1863
|
BusinessWarning,
|
|
1748
1864
|
Category,
|
|
1865
|
+
DEFAULT_PAGINATION_PARAMS,
|
|
1749
1866
|
DataHelper,
|
|
1750
1867
|
DateUtils,
|
|
1751
1868
|
DepotPoolStatus,
|
|
@@ -1769,9 +1886,13 @@ export {
|
|
|
1769
1886
|
TimestampColumn,
|
|
1770
1887
|
TransactionType,
|
|
1771
1888
|
buildPatch,
|
|
1889
|
+
constructTypeormPagination,
|
|
1772
1890
|
createDeferred,
|
|
1773
1891
|
eslint_config_default as freshEslintConfig,
|
|
1892
|
+
getPaginationMeta,
|
|
1893
|
+
getPaginationParams,
|
|
1774
1894
|
hasOwn,
|
|
1895
|
+
isDecimal,
|
|
1775
1896
|
isEnumValue,
|
|
1776
1897
|
isFlag01,
|
|
1777
1898
|
isMaybe,
|
|
@@ -1780,6 +1901,9 @@ export {
|
|
|
1780
1901
|
isObject,
|
|
1781
1902
|
isString,
|
|
1782
1903
|
isValidCron,
|
|
1783
|
-
|
|
1904
|
+
listAll,
|
|
1905
|
+
parsePaginationFromURL,
|
|
1906
|
+
runWithConcurrency,
|
|
1907
|
+
toDecimal
|
|
1784
1908
|
};
|
|
1785
1909
|
//# sourceMappingURL=index.mjs.map
|