@freshpointcz/fresh-core 0.0.20 → 0.0.21

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
@@ -495,6 +495,9 @@ __export(index_exports, {
495
495
  UpgradeRequiredError: () => UpgradeRequiredError,
496
496
  UriTooLongError: () => UriTooLongError,
497
497
  VariantAlsoNegotiatesError: () => VariantAlsoNegotiatesError,
498
+ buildDateRange: () => buildDateRange,
499
+ buildOrder: () => buildOrder,
500
+ buildPagination: () => buildPagination,
498
501
  buildPatch: () => buildPatch,
499
502
  constructTypeormPagination: () => constructTypeormPagination,
500
503
  createDeferred: () => createDeferred,
@@ -755,70 +758,37 @@ var _StatusDto = class _StatusDto {
755
758
  __name(_StatusDto, "StatusDto");
756
759
  var StatusDto = _StatusDto;
757
760
 
758
- // src/common/pagination/constructors.ts
759
- function constructTypeormPagination(params) {
760
- return {
761
- take: params.limit,
762
- skip: params.skip
763
- };
764
- }
765
- __name(constructTypeormPagination, "constructTypeormPagination");
766
- function parsePaginationFromURL(searchParams) {
767
- var _a, _b;
768
- const page = Math.max(1, parseInt((_a = searchParams.get("page")) != null ? _a : "1", 10));
769
- const limit = Math.min(100, Math.max(1, parseInt((_b = searchParams.get("limit")) != null ? _b : "20", 10)));
770
- return {
771
- page,
772
- limit,
773
- skip: (page - 1) * limit
774
- };
775
- }
776
- __name(parsePaginationFromURL, "parsePaginationFromURL");
777
-
778
- // src/common/pagination/pagination-meta.ts
779
- function getPaginationMeta(total, page, limit) {
780
- return {
781
- total,
782
- page,
783
- limit,
784
- totalPages: Math.ceil(total / limit)
785
- };
761
+ // src/common/pagination/find-options/date-range.ts
762
+ var import_typeorm = require("typeorm");
763
+ function buildDateRange(from, to) {
764
+ const f = from ? new Date(from) : void 0;
765
+ const t = to ? new Date(to) : void 0;
766
+ if (f && t) {
767
+ return (0, import_typeorm.Between)(f, t);
768
+ }
769
+ if (f) {
770
+ return (0, import_typeorm.MoreThanOrEqual)(f);
771
+ }
772
+ if (t) {
773
+ return (0, import_typeorm.LessThanOrEqual)(t);
774
+ }
775
+ return void 0;
786
776
  }
787
- __name(getPaginationMeta, "getPaginationMeta");
777
+ __name(buildDateRange, "buildDateRange");
788
778
 
789
- // src/common/pagination/pagination-params.ts
790
- function getPaginationParams(params) {
779
+ // src/common/pagination/find-options/order.ts
780
+ function buildOrder(sortBy, sortOrder) {
781
+ if (!sortBy) {
782
+ return void 0;
783
+ }
791
784
  return {
792
- ...DEFAULT_PAGINATION_PARAMS,
793
- ...params
785
+ [sortBy]: sortOrder != null ? sortOrder : "ASC"
794
786
  };
795
787
  }
796
- __name(getPaginationParams, "getPaginationParams");
797
- var DEFAULT_PAGINATION_PARAMS = {
798
- page: 1,
799
- limit: 1e3,
800
- skip: 0
801
- };
788
+ __name(buildOrder, "buildOrder");
802
789
 
803
- // src/common/pagination/scrapper.ts
804
- async function listAll(fetchPage, batchSize = 1e3) {
805
- const results = [];
806
- let page = 1;
807
- while (true) {
808
- const { data, meta } = await fetchPage({
809
- page,
810
- limit: batchSize,
811
- skip: (page - 1) * batchSize
812
- });
813
- results.push(...data);
814
- if (page >= meta.totalPages) {
815
- break;
816
- }
817
- page++;
818
- }
819
- return results;
820
- }
821
- __name(listAll, "listAll");
790
+ // src/core/class/fresh-job.ts
791
+ var import_node_schedule = require("node-schedule");
822
792
 
823
793
  // src/common/patterns/singleton.ts
824
794
  var _Singleton = class _Singleton {
@@ -871,236 +841,173 @@ __name(_Singleton, "Singleton");
871
841
  __publicField(_Singleton, "instances", /* @__PURE__ */ new Map());
872
842
  var Singleton = _Singleton;
873
843
 
874
- // src/common/promise-magic/deferred.ts
875
- function createDeferred() {
876
- let resolve;
877
- let reject;
878
- const promise = new Promise((res, rej) => {
879
- resolve = res;
880
- reject = rej;
881
- });
882
- return {
883
- promise,
884
- resolve,
885
- reject
886
- };
887
- }
888
- __name(createDeferred, "createDeferred");
889
-
890
- // src/common/promise-magic/single-promise-waiter.ts
891
- var _SinglePromiseWaiter = class _SinglePromiseWaiter {
892
- constructor() {
893
- __publicField(this, "_promise", null);
844
+ // src/core/class/fresh-job.ts
845
+ var _FreshJob = class _FreshJob extends Singleton {
846
+ /**
847
+ * Creates and optionally schedules a singleton cron job.
848
+ *
849
+ * @param jobName - Logical name of the job (used in logs and errors).
850
+ * @param cronExpression - Cron expression consisting of numeric fields only.
851
+ * Example: `0 5 * * 4`
852
+ * The timezone `"Europe/Prague"` is applied automatically.
853
+ *
854
+ * @param jobEnabled - Whether the job should be scheduled immediately.
855
+ * If `false`, the instance exists but no cron trigger is registered.
856
+ *
857
+ * @throws Error If the cron expression is invalid.
858
+ * @throws Error If the job cannot be scheduled.
859
+ */
860
+ constructor(jobName, cronExpression, jobEnabled) {
861
+ super(false);
862
+ /** Human-readable job identifier (used for logs and errors). */
863
+ __publicField(this, "_jobName");
864
+ /**
865
+ * Cron expression defining when the job runs.
866
+ *
867
+ * Must contain numeric cron fields only.
868
+ * Example: `0 5 * * 4`
869
+ *
870
+ * Timezone is always forced to `"Europe/Prague"`.
871
+ * If you need another timezone, this class is not your friend.
872
+ */
873
+ __publicField(this, "_cronExpression");
874
+ /** Scheduled job instance, or `null` if the job is disabled. */
875
+ __publicField(this, "_job", null);
876
+ this._jobName = jobName;
877
+ if (!isValidCron(cronExpression)) {
878
+ throw new Error(`Job ${this.jobName} cannot be constructed with invalid cron: "${cronExpression}"`);
879
+ }
880
+ this._cronExpression = cronExpression;
881
+ if (jobEnabled) {
882
+ this._job = (0, import_node_schedule.scheduleJob)({
883
+ rule: this._cronExpression,
884
+ tz: "Europe/Prague"
885
+ }, async () => {
886
+ await this.invoke();
887
+ });
888
+ if (!this._job) {
889
+ throw new Error(`Job ${this._jobName} could not be scheduled`);
890
+ }
891
+ }
892
+ this.onInit();
894
893
  }
895
- static getInstance() {
896
- if (!_SinglePromiseWaiter._instance) {
897
- _SinglePromiseWaiter._instance = new _SinglePromiseWaiter();
894
+ /**
895
+ * Initialization hook.
896
+ *
897
+ * Called once during construction and used primarily for logging.
898
+ * Can also be reused by subclasses if manual rescheduling is implemented.
899
+ *
900
+ * @param rescheduled - Indicates whether the job was reconfigured
901
+ * after initial creation.
902
+ */
903
+ onInit(rescheduled) {
904
+ console.log(`Job ${this.jobName} ${rescheduled ? "rescheduled" : "initialized"} with cron rule: "${this.cronExpression}"`);
905
+ }
906
+ /** @returns The logical name of the job. */
907
+ get jobName() {
908
+ return this._jobName;
909
+ }
910
+ /** Allows subclasses to rename the job if absolutely necessary. */
911
+ set jobName(value) {
912
+ this._jobName = value;
913
+ }
914
+ /** @returns The cron expression used to schedule the job. */
915
+ get cronExpression() {
916
+ return this._cronExpression;
917
+ }
918
+ /**
919
+ * Allows subclasses to update the cron expression internally.
920
+ * Does reschedule of job if exists
921
+ */
922
+ set cronExpression(value) {
923
+ if (!isValidCron(value)) {
924
+ throw new Error(`Job ${this._jobName} cannot be re-scheduled with invalid cron: "${value}"`);
898
925
  }
899
- return _SinglePromiseWaiter._instance;
926
+ this._cronExpression = value;
900
927
  }
901
- get promise() {
902
- return this._promise;
928
+ /** @returns The underlying scheduled job instance, or `null` if disabled. */
929
+ get job() {
930
+ return this._job;
903
931
  }
904
- set promise(promise) {
905
- if (promise !== null) {
906
- this._promise = promise;
907
- this._promise.finally(() => {
908
- this._promise = null;
932
+ /** Allows subclasses to manage the scheduled job instance. */
933
+ set job(value) {
934
+ this._job = value;
935
+ }
936
+ reschedule(newCronExpression) {
937
+ let result = false;
938
+ if (!isValidCron(newCronExpression)) {
939
+ throw new Error(`Job ${this._jobName} cannot be re-scheduled with invalid cron: "${newCronExpression}"`);
940
+ }
941
+ this._cronExpression = newCronExpression;
942
+ if (this._job) {
943
+ const rescheduleSuccess = this._job.reschedule({
944
+ rule: this._cronExpression,
945
+ tz: "Europe/Prague"
909
946
  });
947
+ if (!rescheduleSuccess) {
948
+ throw new Error(`Job ${this._jobName} could not be re-scheduled`);
949
+ } else {
950
+ this.onInit(true);
951
+ }
952
+ result = rescheduleSuccess;
910
953
  }
911
- }
912
- get hasPromise() {
913
- return this._promise !== null;
954
+ return result;
914
955
  }
915
956
  };
916
- __name(_SinglePromiseWaiter, "SinglePromiseWaiter");
917
- __publicField(_SinglePromiseWaiter, "_instance");
918
- var SinglePromiseWaiter = _SinglePromiseWaiter;
919
-
920
- // src/common/schema/entities/category.entity.ts
921
- var import_typeorm5 = require("typeorm");
922
-
923
- // src/database/entities/fresh-entity.ts
924
- var import_typeorm = require("typeorm");
925
-
926
- // ../../node_modules/uuid/dist/esm/stringify.js
927
- var byteToHex = [];
928
- for (let i = 0; i < 256; ++i) {
929
- byteToHex.push((i + 256).toString(16).slice(1));
930
- }
931
- function unsafeStringify(arr, offset = 0) {
932
- 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();
933
- }
934
- __name(unsafeStringify, "unsafeStringify");
957
+ __name(_FreshJob, "FreshJob");
958
+ var FreshJob = _FreshJob;
935
959
 
936
- // ../../node_modules/uuid/dist/esm/rng.js
937
- var import_crypto = require("crypto");
938
- var rnds8Pool = new Uint8Array(256);
939
- var poolPtr = rnds8Pool.length;
940
- function rng() {
941
- if (poolPtr > rnds8Pool.length - 16) {
942
- (0, import_crypto.randomFillSync)(rnds8Pool);
943
- poolPtr = 0;
960
+ // src/core/errors/api-error.ts
961
+ var _ApiError = class _ApiError extends Error {
962
+ constructor(statusCode, status, detail) {
963
+ super();
964
+ __publicField(this, "_statusCode");
965
+ __publicField(this, "_statusDto");
966
+ this._statusCode = statusCode;
967
+ this._statusDto = new StatusDto(status, detail);
968
+ }
969
+ get statusCode() {
970
+ return this._statusCode;
971
+ }
972
+ get statusDto() {
973
+ return this._statusDto;
944
974
  }
945
- return rnds8Pool.slice(poolPtr, poolPtr += 16);
946
- }
947
- __name(rng, "rng");
948
-
949
- // ../../node_modules/uuid/dist/esm/native.js
950
- var import_crypto2 = require("crypto");
951
- var native_default = {
952
- randomUUID: import_crypto2.randomUUID
953
975
  };
976
+ __name(_ApiError, "ApiError");
977
+ var ApiError = _ApiError;
954
978
 
955
- // ../../node_modules/uuid/dist/esm/v4.js
956
- function v4(options, buf, offset) {
957
- var _a, _b, _c;
958
- if (native_default.randomUUID && !buf && !options) {
959
- return native_default.randomUUID();
960
- }
961
- options = options || {};
962
- const rnds = (_c = (_b = options.random) != null ? _b : (_a = options.rng) == null ? void 0 : _a.call(options)) != null ? _c : rng();
963
- if (rnds.length < 16) {
964
- throw new Error("Random bytes length must be >= 16");
965
- }
966
- rnds[6] = rnds[6] & 15 | 64;
967
- rnds[8] = rnds[8] & 63 | 128;
968
- if (buf) {
969
- offset = offset || 0;
970
- if (offset < 0 || offset + 16 > buf.length) {
971
- throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
972
- }
973
- for (let i = 0; i < 16; ++i) {
974
- buf[offset + i] = rnds[i];
975
- }
976
- return buf;
977
- }
978
- return unsafeStringify(rnds);
979
- }
980
- __name(v4, "v4");
981
- var v4_default = v4;
982
-
983
- // src/database/entities/fresh-entity.ts
984
- function _ts_decorate(decorators, target, key, desc) {
985
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
986
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
987
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
988
- return c > 3 && r && Object.defineProperty(target, key, r), r;
989
- }
990
- __name(_ts_decorate, "_ts_decorate");
991
- function _ts_metadata(k, v) {
992
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
993
- }
994
- __name(_ts_metadata, "_ts_metadata");
995
- var _FreshEntity = class _FreshEntity extends import_typeorm.BaseEntity {
996
- /** After manual construction `id` is irrelevant. Refer to `uuid` only, because that will be inserted into DB */
997
- constructor() {
998
- super();
999
- __publicField(this, "id");
1000
- __publicField(this, "uuid");
1001
- __publicField(this, "created_at");
1002
- __publicField(this, "updated_at");
1003
- // for soft delete methods by typeorm
1004
- __publicField(this, "deleted_at");
1005
- this.id = 0;
1006
- this.uuid = v4_default();
1007
- const newDate = /* @__PURE__ */ new Date();
1008
- this.created_at = newDate;
1009
- this.updated_at = newDate;
1010
- this.deleted_at = null;
979
+ // src/core/errors/business-warning.ts
980
+ var _BusinessWarning = class _BusinessWarning extends Error {
981
+ constructor(code, message) {
982
+ super(message);
983
+ __publicField(this, "code");
984
+ this.code = code;
985
+ this.name = "BusinessWarning";
1011
986
  }
1012
987
  };
1013
- __name(_FreshEntity, "FreshEntity");
1014
- var FreshEntity = _FreshEntity;
1015
- _ts_decorate([
1016
- (0, import_typeorm.PrimaryGeneratedColumn)("increment"),
1017
- _ts_metadata("design:type", Number)
1018
- ], FreshEntity.prototype, "id", void 0);
1019
- _ts_decorate([
1020
- (0, import_typeorm.Index)({
1021
- unique: true
1022
- }),
1023
- (0, import_typeorm.Column)({
1024
- type: "uuid",
1025
- default: /* @__PURE__ */ __name(() => "gen_random_uuid()", "default")
1026
- }),
1027
- _ts_metadata("design:type", String)
1028
- ], FreshEntity.prototype, "uuid", void 0);
1029
- _ts_decorate([
1030
- (0, import_typeorm.CreateDateColumn)({
1031
- type: "timestamptz"
1032
- }),
1033
- _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
1034
- ], FreshEntity.prototype, "created_at", void 0);
1035
- _ts_decorate([
1036
- (0, import_typeorm.UpdateDateColumn)({
1037
- type: "timestamptz"
1038
- }),
1039
- _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
1040
- ], FreshEntity.prototype, "updated_at", void 0);
1041
- _ts_decorate([
1042
- (0, import_typeorm.DeleteDateColumn)({
1043
- type: "timestamptz",
1044
- nullable: true
1045
- }),
1046
- _ts_metadata("design:type", Object)
1047
- ], FreshEntity.prototype, "deleted_at", void 0);
1048
-
1049
- // src/database/entities/fresh-hyper-entity.ts
1050
- var import_typeorm3 = require("typeorm");
1051
-
1052
- // src/database/decorators/timestamp-column.ts
1053
- var import_typeorm2 = require("typeorm");
1054
- function TimestampColumn(options = {}) {
1055
- const defaultOptions = {
1056
- type: "timestamptz",
1057
- nullable: false,
1058
- default: /* @__PURE__ */ __name(() => "CURRENT_TIMESTAMP", "default"),
1059
- ...options
1060
- };
1061
- return (0, import_typeorm2.Column)(defaultOptions);
1062
- }
1063
- __name(TimestampColumn, "TimestampColumn");
988
+ __name(_BusinessWarning, "BusinessWarning");
989
+ var BusinessWarning = _BusinessWarning;
1064
990
 
1065
- // src/database/entities/fresh-hyper-entity.ts
1066
- function _ts_decorate2(decorators, target, key, desc) {
1067
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1068
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1069
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1070
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1071
- }
1072
- __name(_ts_decorate2, "_ts_decorate");
1073
- function _ts_metadata2(k, v) {
1074
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1075
- }
1076
- __name(_ts_metadata2, "_ts_metadata");
1077
- var _FreshHyperEntity = class _FreshHyperEntity extends import_typeorm3.BaseEntity {
1078
- /** After manual construction `id` is irrelevant */
1079
- constructor(timestamp) {
1080
- super();
1081
- // input timestamp as PK
1082
- __publicField(this, "timestamp");
1083
- // just info column about time of insert
1084
- __publicField(this, "created_at");
1085
- this.timestamp = timestamp != null ? timestamp : /* @__PURE__ */ new Date();
1086
- this.created_at = /* @__PURE__ */ new Date();
991
+ // src/core/errors/fresh-error.ts
992
+ var _FreshError = class _FreshError extends Error {
993
+ constructor(statusCode, status, detail, options) {
994
+ super(detail != null ? detail : status);
995
+ /** HTTP status code sent in the response. */
996
+ // eslint-disable-next-line @typescript-eslint/naming-convention
997
+ __publicField(this, "statusCode");
998
+ /** Structured response body describing the error. */
999
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1000
+ __publicField(this, "statusDto");
1001
+ this.name = this.constructor.name;
1002
+ if ((options == null ? void 0 : options.cause) !== void 0) {
1003
+ this.cause = options.cause;
1004
+ }
1005
+ this.statusCode = statusCode;
1006
+ this.statusDto = new StatusDto(status, detail);
1087
1007
  }
1088
1008
  };
1089
- __name(_FreshHyperEntity, "FreshHyperEntity");
1090
- var FreshHyperEntity = _FreshHyperEntity;
1091
- _ts_decorate2([
1092
- (0, import_typeorm3.PrimaryColumn)({
1093
- type: "timestamptz"
1094
- }),
1095
- _ts_metadata2("design:type", typeof Date === "undefined" ? Object : Date)
1096
- ], FreshHyperEntity.prototype, "timestamp", void 0);
1097
- _ts_decorate2([
1098
- TimestampColumn(),
1099
- _ts_metadata2("design:type", typeof Date === "undefined" ? Object : Date)
1100
- ], FreshHyperEntity.prototype, "created_at", void 0);
1101
-
1102
- // src/database/entities/fresh-translation-entity.ts
1103
- var import_typeorm4 = require("typeorm");
1009
+ __name(_FreshError, "FreshError");
1010
+ var FreshError = _FreshError;
1104
1011
 
1105
1012
  // src/enums/action-command-code.ts
1106
1013
  var ActionCommandCode = /* @__PURE__ */ (function(ActionCommandCode2) {
@@ -1225,853 +1132,996 @@ var TransactionType = /* @__PURE__ */ (function(TransactionType2) {
1225
1132
  return TransactionType2;
1226
1133
  })({});
1227
1134
 
1228
- // src/database/entities/fresh-translation-entity.ts
1229
- function _ts_decorate3(decorators, target, key, desc) {
1230
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1231
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1232
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1233
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1234
- }
1235
- __name(_ts_decorate3, "_ts_decorate");
1236
- function _ts_metadata3(k, v) {
1237
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1238
- }
1239
- __name(_ts_metadata3, "_ts_metadata");
1240
- var languageValues = Object.values(LanguageCode).map((v) => `'${v}'`).join(",");
1241
- var _FreshTranslationBase = class _FreshTranslationBase extends import_typeorm4.BaseEntity {
1242
- constructor() {
1243
- super();
1244
- __publicField(this, "id");
1245
- __publicField(this, "languageCode");
1246
- this.id = 0;
1247
- this.languageCode = LanguageCode.CS;
1135
+ // src/core/errors/errors.ts
1136
+ var _BadRequestError = class _BadRequestError extends FreshError {
1137
+ constructor(detail, options) {
1138
+ super(HttpStatus.BAD_REQUEST, "validation-error", detail, options);
1248
1139
  }
1249
1140
  };
1250
- __name(_FreshTranslationBase, "FreshTranslationBase");
1251
- var FreshTranslationBase = _FreshTranslationBase;
1252
- _ts_decorate3([
1253
- (0, import_typeorm4.PrimaryGeneratedColumn)(),
1254
- _ts_metadata3("design:type", Number)
1255
- ], FreshTranslationBase.prototype, "id", void 0);
1256
- _ts_decorate3([
1257
- (0, import_typeorm4.Column)({
1258
- type: "varchar",
1259
- length: 3,
1260
- nullable: false
1261
- }),
1262
- (0, import_typeorm4.Check)(`"languageCode" IN (${languageValues})`),
1263
- _ts_metadata3("design:type", typeof LanguageCode === "undefined" ? Object : LanguageCode)
1264
- ], FreshTranslationBase.prototype, "languageCode", void 0);
1265
-
1266
- // src/database/dao/fresh-dao.ts
1267
- var _FreshDao = class _FreshDao {
1268
- getRepo(manager, entity = this.entity) {
1269
- return manager ? manager.getRepository(entity) : this.repo;
1141
+ __name(_BadRequestError, "BadRequestError");
1142
+ var BadRequestError = _BadRequestError;
1143
+ var _UnauthorizedError = class _UnauthorizedError extends FreshError {
1144
+ constructor(detail, options) {
1145
+ super(HttpStatus.UNAUTHORIZED, "not-authenticated", detail, options);
1270
1146
  }
1271
1147
  };
1272
- __name(_FreshDao, "FreshDao");
1273
- var FreshDao = _FreshDao;
1274
-
1275
- // src/database/subscribers/base-entity-change.subscriber.ts
1276
- var _BaseEntityChangeSubscriber = class _BaseEntityChangeSubscriber {
1277
- // ─── TypeORM lifecycle hooks ────────────────────────────────────────
1278
- afterInsert(event) {
1279
- var _a;
1280
- const id = (_a = event.entity) == null ? void 0 : _a.id;
1281
- if (!id) {
1282
- return;
1283
- }
1284
- if (event.queryRunner.isTransactionActive) {
1285
- this.addPending(event, id, "created");
1286
- } else {
1287
- console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
1288
- this.sendNotification(id, "created", event.queryRunner.manager);
1289
- }
1148
+ __name(_UnauthorizedError, "UnauthorizedError");
1149
+ var UnauthorizedError = _UnauthorizedError;
1150
+ var _PaymentRequiredError = class _PaymentRequiredError extends FreshError {
1151
+ constructor(detail, options) {
1152
+ super(HttpStatus.PAYMENT_REQUIRED, "error", detail, options);
1290
1153
  }
1291
- afterUpdate(event) {
1292
- var _a, _b, _c;
1293
- const id = (_c = (_a = event.entity) == null ? void 0 : _a.id) != null ? _c : (_b = event.databaseEntity) == null ? void 0 : _b.id;
1294
- if (!id) {
1295
- return;
1296
- }
1297
- if (event.queryRunner.isTransactionActive) {
1298
- this.addPending(event, id, "updated");
1299
- } else {
1300
- console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
1301
- this.sendNotification(id, "updated", event.queryRunner.manager);
1302
- }
1154
+ };
1155
+ __name(_PaymentRequiredError, "PaymentRequiredError");
1156
+ var PaymentRequiredError = _PaymentRequiredError;
1157
+ var _ForbiddenError = class _ForbiddenError extends FreshError {
1158
+ constructor(detail, options) {
1159
+ super(HttpStatus.FORBIDDEN, "not-authorized", detail, options);
1303
1160
  }
1304
- afterSoftRemove(event) {
1305
- var _a, _b, _c;
1306
- const id = (_c = (_a = event.entity) == null ? void 0 : _a.id) != null ? _c : (_b = event.databaseEntity) == null ? void 0 : _b.id;
1307
- if (!id) {
1308
- return;
1309
- }
1310
- if (event.queryRunner.isTransactionActive) {
1311
- this.addPending(event, id, "deleted");
1312
- } else {
1313
- console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
1314
- this.sendNotification(id, "deleted", event.queryRunner.manager);
1315
- }
1161
+ };
1162
+ __name(_ForbiddenError, "ForbiddenError");
1163
+ var ForbiddenError = _ForbiddenError;
1164
+ var _NotFoundError = class _NotFoundError extends FreshError {
1165
+ constructor(detail, options) {
1166
+ super(HttpStatus.NOT_FOUND, "error", detail, options);
1316
1167
  }
1317
- async afterTransactionCommit(event) {
1318
- var _a;
1319
- const pending = (_a = event.queryRunner.data) == null ? void 0 : _a[this.PENDING_KEY];
1320
- if (!pending || pending.size === 0) {
1321
- return;
1322
- }
1323
- event.queryRunner.data[this.PENDING_KEY] = /* @__PURE__ */ new Map();
1324
- for (const [id, changeEvent] of pending) {
1325
- await this.sendNotification(id, changeEvent, event.connection.manager);
1326
- }
1168
+ };
1169
+ __name(_NotFoundError, "NotFoundError");
1170
+ var NotFoundError = _NotFoundError;
1171
+ var _MethodNotAllowedError = class _MethodNotAllowedError extends FreshError {
1172
+ constructor(detail, options) {
1173
+ super(HttpStatus.METHOD_NOT_ALLOWED, "error", detail, options);
1327
1174
  }
1328
- // ─── Private helpers ───────────────────────────────────────────────
1329
- addPending(event, id, changeEvent) {
1330
- if (!event.queryRunner.data) {
1331
- event.queryRunner.data = {};
1332
- }
1333
- if (!event.queryRunner.data[this.PENDING_KEY]) {
1334
- event.queryRunner.data[this.PENDING_KEY] = /* @__PURE__ */ new Map();
1335
- }
1336
- const existing = event.queryRunner.data[this.PENDING_KEY].get(id);
1337
- if (!existing || changeEvent === "created" || changeEvent === "deleted") {
1338
- event.queryRunner.data[this.PENDING_KEY].set(id, changeEvent);
1339
- }
1175
+ };
1176
+ __name(_MethodNotAllowedError, "MethodNotAllowedError");
1177
+ var MethodNotAllowedError = _MethodNotAllowedError;
1178
+ var _NotAcceptableError = class _NotAcceptableError extends FreshError {
1179
+ constructor(detail, options) {
1180
+ super(HttpStatus.NOT_ACCEPTABLE, "error", detail, options);
1340
1181
  }
1341
- async sendNotification(id, changeEvent, manager) {
1342
- try {
1343
- await this.handleNotification(id, changeEvent, manager);
1344
- } catch (error) {
1345
- console.error(`${this.SUBSCRIBER_NAME} - Failed to send notification: ${error instanceof Error ? error.message : error}`);
1346
- }
1182
+ };
1183
+ __name(_NotAcceptableError, "NotAcceptableError");
1184
+ var NotAcceptableError = _NotAcceptableError;
1185
+ var _ProxyAuthenticationRequiredError = class _ProxyAuthenticationRequiredError extends FreshError {
1186
+ constructor(detail, options) {
1187
+ super(HttpStatus.PROXY_AUTHENTICATION_REQUIRED, "not-authenticated", detail, options);
1347
1188
  }
1348
1189
  };
1349
- __name(_BaseEntityChangeSubscriber, "BaseEntityChangeSubscriber");
1350
- var BaseEntityChangeSubscriber = _BaseEntityChangeSubscriber;
1351
-
1352
- // src/common/schema/entities/category.entity.ts
1353
- function _ts_decorate4(decorators, target, key, desc) {
1354
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1355
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1356
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1357
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1358
- }
1359
- __name(_ts_decorate4, "_ts_decorate");
1360
- var _Category = class _Category extends FreshEntity {
1190
+ __name(_ProxyAuthenticationRequiredError, "ProxyAuthenticationRequiredError");
1191
+ var ProxyAuthenticationRequiredError = _ProxyAuthenticationRequiredError;
1192
+ var _RequestTimeoutError = class _RequestTimeoutError extends FreshError {
1193
+ constructor(detail, options) {
1194
+ super(HttpStatus.REQUEST_TIMEOUT, "error", detail, options);
1195
+ }
1361
1196
  };
1362
- __name(_Category, "Category");
1363
- var Category = _Category;
1364
- Category = _ts_decorate4([
1365
- (0, import_typeorm5.Entity)()
1366
- ], Category);
1367
-
1368
- // src/common/schema/entities/device.entity.ts
1369
- var import_typeorm6 = require("typeorm");
1370
- function _ts_decorate5(decorators, target, key, desc) {
1371
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1372
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1373
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1374
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1375
- }
1376
- __name(_ts_decorate5, "_ts_decorate");
1377
- var _Device = class _Device extends FreshEntity {
1197
+ __name(_RequestTimeoutError, "RequestTimeoutError");
1198
+ var RequestTimeoutError = _RequestTimeoutError;
1199
+ var _ConflictError = class _ConflictError extends FreshError {
1200
+ constructor(detail, options) {
1201
+ super(HttpStatus.CONFLICT, "error", detail, options);
1202
+ }
1378
1203
  };
1379
- __name(_Device, "Device");
1380
- var Device = _Device;
1381
- Device = _ts_decorate5([
1382
- (0, import_typeorm6.Entity)()
1383
- ], Device);
1384
-
1385
- // src/common/schema/entities/manufacturer.entity.ts
1386
- var import_typeorm7 = require("typeorm");
1387
- function _ts_decorate6(decorators, target, key, desc) {
1388
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1389
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1390
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1391
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1392
- }
1393
- __name(_ts_decorate6, "_ts_decorate");
1394
- var _Manufacturer = class _Manufacturer extends FreshEntity {
1204
+ __name(_ConflictError, "ConflictError");
1205
+ var ConflictError = _ConflictError;
1206
+ var _GoneError = class _GoneError extends FreshError {
1207
+ constructor(detail, options) {
1208
+ super(HttpStatus.GONE, "error", detail, options);
1209
+ }
1395
1210
  };
1396
- __name(_Manufacturer, "Manufacturer");
1397
- var Manufacturer = _Manufacturer;
1398
- Manufacturer = _ts_decorate6([
1399
- (0, import_typeorm7.Entity)()
1400
- ], Manufacturer);
1401
-
1402
- // src/common/schema/entities/product.entity.ts
1403
- var import_typeorm8 = require("typeorm");
1404
- function _ts_decorate7(decorators, target, key, desc) {
1405
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1406
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1407
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1408
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1409
- }
1410
- __name(_ts_decorate7, "_ts_decorate");
1411
- var _Product = class _Product extends FreshEntity {
1211
+ __name(_GoneError, "GoneError");
1212
+ var GoneError = _GoneError;
1213
+ var _LengthRequiredError = class _LengthRequiredError extends FreshError {
1214
+ constructor(detail, options) {
1215
+ super(HttpStatus.LENGTH_REQUIRED, "error", detail, options);
1216
+ }
1412
1217
  };
1413
- __name(_Product, "Product");
1414
- var Product = _Product;
1415
- Product = _ts_decorate7([
1416
- (0, import_typeorm8.Entity)()
1417
- ], Product);
1418
-
1419
- // src/common/schema/entities/subcategory.entity.ts
1420
- var import_typeorm9 = require("typeorm");
1421
- function _ts_decorate8(decorators, target, key, desc) {
1422
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1423
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1424
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1425
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1426
- }
1427
- __name(_ts_decorate8, "_ts_decorate");
1428
- var _Subcategory = class _Subcategory extends FreshEntity {
1218
+ __name(_LengthRequiredError, "LengthRequiredError");
1219
+ var LengthRequiredError = _LengthRequiredError;
1220
+ var _PreconditionFailedError = class _PreconditionFailedError extends FreshError {
1221
+ constructor(detail, options) {
1222
+ super(HttpStatus.PRECONDITION_FAILED, "error", detail, options);
1223
+ }
1429
1224
  };
1430
- __name(_Subcategory, "Subcategory");
1431
- var Subcategory = _Subcategory;
1432
- Subcategory = _ts_decorate8([
1433
- (0, import_typeorm9.Entity)()
1434
- ], Subcategory);
1435
-
1436
- // src/common/typeguards/decimal.ts
1437
- function toDecimal(num, precision = 9, scale = 2) {
1438
- const limit = Math.pow(10, precision - scale);
1439
- if (Math.abs(num) >= limit) {
1440
- throw new Error(`Value ${num} exceeds the allowed precision of ${precision} and scale of ${scale}.`);
1225
+ __name(_PreconditionFailedError, "PreconditionFailedError");
1226
+ var PreconditionFailedError = _PreconditionFailedError;
1227
+ var _PayloadTooLargeError = class _PayloadTooLargeError extends FreshError {
1228
+ constructor(detail, options) {
1229
+ super(HttpStatus.PAYLOAD_TOO_LARGE, "error", detail, options);
1441
1230
  }
1442
- return num.toFixed(scale);
1443
- }
1444
- __name(toDecimal, "toDecimal");
1445
- function isDecimal(v, options) {
1446
- var _a, _b, _c;
1447
- const type = typeof v;
1448
- if ((options == null ? void 0 : options.allowedType) !== void 0 && type !== options.allowedType) {
1449
- return false;
1231
+ };
1232
+ __name(_PayloadTooLargeError, "PayloadTooLargeError");
1233
+ var PayloadTooLargeError = _PayloadTooLargeError;
1234
+ var _UriTooLongError = class _UriTooLongError extends FreshError {
1235
+ constructor(detail, options) {
1236
+ super(HttpStatus.URI_TOO_LONG, "error", detail, options);
1450
1237
  }
1451
- if (type !== "number" && type !== "string") {
1452
- return false;
1238
+ };
1239
+ __name(_UriTooLongError, "UriTooLongError");
1240
+ var UriTooLongError = _UriTooLongError;
1241
+ var _UnsupportedMediaTypeError = class _UnsupportedMediaTypeError extends FreshError {
1242
+ constructor(detail, options) {
1243
+ super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "error", detail, options);
1453
1244
  }
1454
- const sep = (_a = options == null ? void 0 : options.decimalPoint) != null ? _a : ".";
1455
- let intPart;
1456
- let fracPart;
1457
- if (type === "number") {
1458
- const n = v;
1459
- if (!Number.isFinite(n)) {
1460
- return false;
1461
- }
1462
- const str = n.toString();
1463
- if (str.includes("e") || str.includes("E")) {
1464
- return false;
1465
- }
1466
- const parts = str.replace("-", "").split(".");
1467
- intPart = parts[0];
1468
- fracPart = (_b = parts[1]) != null ? _b : "";
1469
- } else {
1470
- const s = v;
1471
- const escapedSep = sep === "." ? "\\." : ",";
1472
- const pattern = new RegExp(`^-?\\d+(?:${escapedSep}\\d+)?$`);
1473
- if (!pattern.test(s)) {
1474
- return false;
1475
- }
1476
- const parts = s.replace("-", "").split(sep);
1477
- intPart = parts[0];
1478
- fracPart = (_c = parts[1]) != null ? _c : "";
1245
+ };
1246
+ __name(_UnsupportedMediaTypeError, "UnsupportedMediaTypeError");
1247
+ var UnsupportedMediaTypeError = _UnsupportedMediaTypeError;
1248
+ var _RangeNotSatisfiableError = class _RangeNotSatisfiableError extends FreshError {
1249
+ constructor(detail, options) {
1250
+ super(HttpStatus.RANGE_NOT_SATISFIABLE, "error", detail, options);
1479
1251
  }
1480
- if ((options == null ? void 0 : options.scale) !== void 0 && fracPart.length > options.scale) {
1481
- return false;
1252
+ };
1253
+ __name(_RangeNotSatisfiableError, "RangeNotSatisfiableError");
1254
+ var RangeNotSatisfiableError = _RangeNotSatisfiableError;
1255
+ var _ExpectationFailedError = class _ExpectationFailedError extends FreshError {
1256
+ constructor(detail, options) {
1257
+ super(HttpStatus.EXPECTATION_FAILED, "error", detail, options);
1482
1258
  }
1483
- return (options == null ? void 0 : options.precision) === void 0 || intPart.length + fracPart.length <= options.precision;
1484
- }
1485
- __name(isDecimal, "isDecimal");
1486
-
1487
- // src/common/typeguards/enums.ts
1488
- function isEnumValue(enumObj, v) {
1489
- if (!enumObj) {
1490
- return typeof v === "string" || typeof v === "number";
1259
+ };
1260
+ __name(_ExpectationFailedError, "ExpectationFailedError");
1261
+ var ExpectationFailedError = _ExpectationFailedError;
1262
+ var _ImATeapotError = class _ImATeapotError extends FreshError {
1263
+ constructor(detail, options) {
1264
+ super(HttpStatus.IM_A_TEAPOT, "error", detail, options);
1491
1265
  }
1492
- const values = new Set(Object.values(enumObj));
1493
- return (typeof v === "string" || typeof v === "number") && values.has(v);
1494
- }
1495
- __name(isEnumValue, "isEnumValue");
1496
-
1497
- // src/common/typeguards/objects.ts
1498
- function isObject(v) {
1499
- return typeof v === "object" && v !== null;
1500
- }
1501
- __name(isObject, "isObject");
1502
- function hasOwn(obj, key) {
1503
- return Object.prototype.hasOwnProperty.call(obj, key);
1504
- }
1505
- __name(hasOwn, "hasOwn");
1506
-
1507
- // src/common/typeguards/primitives.ts
1508
- function isNumber(v) {
1509
- return typeof v === "number" && Number.isFinite(v);
1510
- }
1511
- __name(isNumber, "isNumber");
1512
- function isString(v) {
1513
- return typeof v === "string";
1514
- }
1515
- __name(isString, "isString");
1516
- function isFlag01(v) {
1517
- return v === 0 || v === 1;
1518
- }
1519
- __name(isFlag01, "isFlag01");
1520
- function isNumberInRange(v, min, max, options) {
1521
- var _a, _b;
1522
- if (!isNumber(v)) {
1523
- return false;
1524
- }
1525
- const includeMin = (_a = options == null ? void 0 : options.includeMin) != null ? _a : true;
1526
- const includeMax = (_b = options == null ? void 0 : options.includeMax) != null ? _b : true;
1527
- if (includeMin ? v < min : v <= min) {
1528
- return false;
1529
- }
1530
- if (includeMax ? v > max : v >= max) {
1531
- return false;
1532
- }
1533
- return true;
1534
- }
1535
- __name(isNumberInRange, "isNumberInRange");
1536
- var TO_BINARY_FLAG = /* @__PURE__ */ __name((v) => v === 1 || v === true ? 1 : 0, "TO_BINARY_FLAG");
1537
-
1538
- // src/common/utils/async.utils.ts
1539
- async function runWithConcurrency(items, concurrency, worker) {
1540
- const queue = [
1541
- ...items
1542
- ];
1543
- const runNext = /* @__PURE__ */ __name(async () => {
1544
- const item = queue.shift();
1545
- if (!item) {
1546
- return;
1547
- }
1548
- await worker(item);
1549
- await runNext();
1550
- }, "runNext");
1551
- await Promise.all(Array.from({
1552
- length: Math.min(concurrency, items.length)
1553
- }, runNext));
1554
- }
1555
- __name(runWithConcurrency, "runWithConcurrency");
1556
-
1557
- // src/common/utils/id-path-param-resolver.utils.ts
1558
- function resolvePathParameterId(id) {
1559
- return /^\d+$/.test(id) ? parseInt(id, 10) : id;
1560
- }
1561
- __name(resolvePathParameterId, "resolvePathParameterId");
1562
-
1563
- // src/common/utils/is-cron-valid.ts
1564
- function isValidCron(expr) {
1565
- const parts = expr.trim().split(/\s+/);
1566
- if (parts.length < 5 || parts.length > 6) {
1567
- return false;
1568
- }
1569
- const cronPart = /^(\*|\d+|\d+\-\d+|\d+\/\d+|\*\/\d+)(,\d+)*$/;
1570
- return parts.every((part) => cronPart.test(part));
1571
- }
1572
- __name(isValidCron, "isValidCron");
1573
-
1574
- // src/common/utils/patch.utils.ts
1575
- function buildPatch(data, keys, transforms) {
1576
- const patch = {};
1577
- for (const k of keys) {
1578
- const value = data[k];
1579
- if (value === void 0) {
1580
- continue;
1581
- }
1582
- patch[k] = (transforms == null ? void 0 : transforms[k]) ? transforms[k](value) : value;
1583
- }
1584
- return patch;
1585
- }
1586
- __name(buildPatch, "buildPatch");
1587
-
1588
- // src/core/class/fresh-job.ts
1589
- var import_node_schedule = require("node-schedule");
1590
- var _FreshJob = class _FreshJob extends Singleton {
1591
- /**
1592
- * Creates and optionally schedules a singleton cron job.
1593
- *
1594
- * @param jobName - Logical name of the job (used in logs and errors).
1595
- * @param cronExpression - Cron expression consisting of numeric fields only.
1596
- * Example: `0 5 * * 4`
1597
- * The timezone `"Europe/Prague"` is applied automatically.
1598
- *
1599
- * @param jobEnabled - Whether the job should be scheduled immediately.
1600
- * If `false`, the instance exists but no cron trigger is registered.
1601
- *
1602
- * @throws Error If the cron expression is invalid.
1603
- * @throws Error If the job cannot be scheduled.
1604
- */
1605
- constructor(jobName, cronExpression, jobEnabled) {
1606
- super(false);
1607
- /** Human-readable job identifier (used for logs and errors). */
1608
- __publicField(this, "_jobName");
1609
- /**
1610
- * Cron expression defining when the job runs.
1611
- *
1612
- * Must contain numeric cron fields only.
1613
- * Example: `0 5 * * 4`
1614
- *
1615
- * Timezone is always forced to `"Europe/Prague"`.
1616
- * If you need another timezone, this class is not your friend.
1617
- */
1618
- __publicField(this, "_cronExpression");
1619
- /** Scheduled job instance, or `null` if the job is disabled. */
1620
- __publicField(this, "_job", null);
1621
- this._jobName = jobName;
1622
- if (!isValidCron(cronExpression)) {
1623
- throw new Error(`Job ${this.jobName} cannot be constructed with invalid cron: "${cronExpression}"`);
1624
- }
1625
- this._cronExpression = cronExpression;
1626
- if (jobEnabled) {
1627
- this._job = (0, import_node_schedule.scheduleJob)({
1628
- rule: this._cronExpression,
1629
- tz: "Europe/Prague"
1630
- }, async () => {
1631
- await this.invoke();
1632
- });
1633
- if (!this._job) {
1634
- throw new Error(`Job ${this._jobName} could not be scheduled`);
1635
- }
1636
- }
1637
- this.onInit();
1638
- }
1639
- /**
1640
- * Initialization hook.
1641
- *
1642
- * Called once during construction and used primarily for logging.
1643
- * Can also be reused by subclasses if manual rescheduling is implemented.
1644
- *
1645
- * @param rescheduled - Indicates whether the job was reconfigured
1646
- * after initial creation.
1647
- */
1648
- onInit(rescheduled) {
1649
- console.log(`Job ${this.jobName} ${rescheduled ? "rescheduled" : "initialized"} with cron rule: "${this.cronExpression}"`);
1650
- }
1651
- /** @returns The logical name of the job. */
1652
- get jobName() {
1653
- return this._jobName;
1654
- }
1655
- /** Allows subclasses to rename the job if absolutely necessary. */
1656
- set jobName(value) {
1657
- this._jobName = value;
1266
+ };
1267
+ __name(_ImATeapotError, "ImATeapotError");
1268
+ var ImATeapotError = _ImATeapotError;
1269
+ var _MisdirectedRequestError = class _MisdirectedRequestError extends FreshError {
1270
+ constructor(detail, options) {
1271
+ super(HttpStatus.MISDIRECTED_REQUEST, "error", detail, options);
1658
1272
  }
1659
- /** @returns The cron expression used to schedule the job. */
1660
- get cronExpression() {
1661
- return this._cronExpression;
1273
+ };
1274
+ __name(_MisdirectedRequestError, "MisdirectedRequestError");
1275
+ var MisdirectedRequestError = _MisdirectedRequestError;
1276
+ var _UnprocessableEntityError = class _UnprocessableEntityError extends FreshError {
1277
+ constructor(detail, options) {
1278
+ super(HttpStatus.UNPROCESSABLE_ENTITY, "validation-error", detail, options);
1662
1279
  }
1663
- /**
1664
- * Allows subclasses to update the cron expression internally.
1665
- * Does reschedule of job if exists
1666
- */
1667
- set cronExpression(value) {
1668
- if (!isValidCron(value)) {
1669
- throw new Error(`Job ${this._jobName} cannot be re-scheduled with invalid cron: "${value}"`);
1670
- }
1671
- this._cronExpression = value;
1280
+ };
1281
+ __name(_UnprocessableEntityError, "UnprocessableEntityError");
1282
+ var UnprocessableEntityError = _UnprocessableEntityError;
1283
+ var _LockedError = class _LockedError extends FreshError {
1284
+ constructor(detail, options) {
1285
+ super(HttpStatus.LOCKED, "error", detail, options);
1672
1286
  }
1673
- /** @returns The underlying scheduled job instance, or `null` if disabled. */
1674
- get job() {
1675
- return this._job;
1287
+ };
1288
+ __name(_LockedError, "LockedError");
1289
+ var LockedError = _LockedError;
1290
+ var _FailedDependencyError = class _FailedDependencyError extends FreshError {
1291
+ constructor(detail, options) {
1292
+ super(HttpStatus.FAILED_DEPENDENCY, "error", detail, options);
1676
1293
  }
1677
- /** Allows subclasses to manage the scheduled job instance. */
1678
- set job(value) {
1679
- this._job = value;
1294
+ };
1295
+ __name(_FailedDependencyError, "FailedDependencyError");
1296
+ var FailedDependencyError = _FailedDependencyError;
1297
+ var _TooEarlyError = class _TooEarlyError extends FreshError {
1298
+ constructor(detail, options) {
1299
+ super(HttpStatus.TOO_EARLY, "error", detail, options);
1680
1300
  }
1681
- reschedule(newCronExpression) {
1682
- let result = false;
1683
- if (!isValidCron(newCronExpression)) {
1684
- throw new Error(`Job ${this._jobName} cannot be re-scheduled with invalid cron: "${newCronExpression}"`);
1685
- }
1686
- this._cronExpression = newCronExpression;
1687
- if (this._job) {
1688
- const rescheduleSuccess = this._job.reschedule({
1689
- rule: this._cronExpression,
1690
- tz: "Europe/Prague"
1691
- });
1692
- if (!rescheduleSuccess) {
1693
- throw new Error(`Job ${this._jobName} could not be re-scheduled`);
1694
- } else {
1695
- this.onInit(true);
1696
- }
1697
- result = rescheduleSuccess;
1698
- }
1699
- return result;
1301
+ };
1302
+ __name(_TooEarlyError, "TooEarlyError");
1303
+ var TooEarlyError = _TooEarlyError;
1304
+ var _UpgradeRequiredError = class _UpgradeRequiredError extends FreshError {
1305
+ constructor(detail, options) {
1306
+ super(HttpStatus.UPGRADE_REQUIRED, "error", detail, options);
1700
1307
  }
1701
1308
  };
1702
- __name(_FreshJob, "FreshJob");
1703
- var FreshJob = _FreshJob;
1704
-
1705
- // src/core/errors/api-error.ts
1706
- var _ApiError = class _ApiError extends Error {
1707
- constructor(statusCode, status, detail) {
1708
- super();
1709
- __publicField(this, "_statusCode");
1710
- __publicField(this, "_statusDto");
1711
- this._statusCode = statusCode;
1712
- this._statusDto = new StatusDto(status, detail);
1309
+ __name(_UpgradeRequiredError, "UpgradeRequiredError");
1310
+ var UpgradeRequiredError = _UpgradeRequiredError;
1311
+ var _PreconditionRequiredError = class _PreconditionRequiredError extends FreshError {
1312
+ constructor(detail, options) {
1313
+ super(HttpStatus.PRECONDITION_REQUIRED, "error", detail, options);
1713
1314
  }
1714
- get statusCode() {
1715
- return this._statusCode;
1315
+ };
1316
+ __name(_PreconditionRequiredError, "PreconditionRequiredError");
1317
+ var PreconditionRequiredError = _PreconditionRequiredError;
1318
+ var _TooManyRequestsError = class _TooManyRequestsError extends FreshError {
1319
+ constructor(detail, options) {
1320
+ super(HttpStatus.TOO_MANY_REQUESTS, "error", detail, options);
1716
1321
  }
1717
- get statusDto() {
1718
- return this._statusDto;
1322
+ };
1323
+ __name(_TooManyRequestsError, "TooManyRequestsError");
1324
+ var TooManyRequestsError = _TooManyRequestsError;
1325
+ var _RequestHeaderFieldsTooLargeError = class _RequestHeaderFieldsTooLargeError extends FreshError {
1326
+ constructor(detail, options) {
1327
+ super(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, "error", detail, options);
1719
1328
  }
1720
1329
  };
1721
- __name(_ApiError, "ApiError");
1722
- var ApiError = _ApiError;
1723
-
1724
- // src/core/errors/business-warning.ts
1725
- var _BusinessWarning = class _BusinessWarning extends Error {
1726
- constructor(code, message) {
1727
- super(message);
1728
- __publicField(this, "code");
1729
- this.code = code;
1730
- this.name = "BusinessWarning";
1330
+ __name(_RequestHeaderFieldsTooLargeError, "RequestHeaderFieldsTooLargeError");
1331
+ var RequestHeaderFieldsTooLargeError = _RequestHeaderFieldsTooLargeError;
1332
+ var _UnavailableForLegalReasonsError = class _UnavailableForLegalReasonsError extends FreshError {
1333
+ constructor(detail, options) {
1334
+ super(HttpStatus.UNAVAILABLE_FOR_LEGAL_REASONS, "error", detail, options);
1731
1335
  }
1732
1336
  };
1733
- __name(_BusinessWarning, "BusinessWarning");
1734
- var BusinessWarning = _BusinessWarning;
1735
-
1736
- // src/core/errors/fresh-error.ts
1737
- var _FreshError = class _FreshError extends Error {
1738
- constructor(statusCode, status, detail, options) {
1739
- super(detail != null ? detail : status);
1740
- /** HTTP status code sent in the response. */
1741
- // eslint-disable-next-line @typescript-eslint/naming-convention
1742
- __publicField(this, "statusCode");
1743
- /** Structured response body describing the error. */
1744
- // eslint-disable-next-line @typescript-eslint/naming-convention
1745
- __publicField(this, "statusDto");
1746
- this.name = this.constructor.name;
1747
- if ((options == null ? void 0 : options.cause) !== void 0) {
1748
- this.cause = options.cause;
1749
- }
1750
- this.statusCode = statusCode;
1751
- this.statusDto = new StatusDto(status, detail);
1337
+ __name(_UnavailableForLegalReasonsError, "UnavailableForLegalReasonsError");
1338
+ var UnavailableForLegalReasonsError = _UnavailableForLegalReasonsError;
1339
+ var _InternalServerError = class _InternalServerError extends FreshError {
1340
+ constructor(detail, options) {
1341
+ super(HttpStatus.INTERNAL_SERVER_ERROR, "internal-server-error", detail, options);
1752
1342
  }
1753
1343
  };
1754
- __name(_FreshError, "FreshError");
1755
- var FreshError = _FreshError;
1756
-
1757
- // src/core/errors/errors.ts
1758
- var _BadRequestError = class _BadRequestError extends FreshError {
1344
+ __name(_InternalServerError, "InternalServerError");
1345
+ var InternalServerError = _InternalServerError;
1346
+ var _NotImplementedError = class _NotImplementedError extends FreshError {
1759
1347
  constructor(detail, options) {
1760
- super(HttpStatus.BAD_REQUEST, "validation-error", detail, options);
1348
+ super(HttpStatus.NOT_IMPLEMENTED, "internal-server-error", detail, options);
1761
1349
  }
1762
1350
  };
1763
- __name(_BadRequestError, "BadRequestError");
1764
- var BadRequestError = _BadRequestError;
1765
- var _UnauthorizedError = class _UnauthorizedError extends FreshError {
1351
+ __name(_NotImplementedError, "NotImplementedError");
1352
+ var NotImplementedError = _NotImplementedError;
1353
+ var _BadGatewayError = class _BadGatewayError extends FreshError {
1766
1354
  constructor(detail, options) {
1767
- super(HttpStatus.UNAUTHORIZED, "not-authenticated", detail, options);
1355
+ super(HttpStatus.BAD_GATEWAY, "internal-server-error", detail, options);
1768
1356
  }
1769
1357
  };
1770
- __name(_UnauthorizedError, "UnauthorizedError");
1771
- var UnauthorizedError = _UnauthorizedError;
1772
- var _PaymentRequiredError = class _PaymentRequiredError extends FreshError {
1358
+ __name(_BadGatewayError, "BadGatewayError");
1359
+ var BadGatewayError = _BadGatewayError;
1360
+ var _ServiceUnavailableError = class _ServiceUnavailableError extends FreshError {
1773
1361
  constructor(detail, options) {
1774
- super(HttpStatus.PAYMENT_REQUIRED, "error", detail, options);
1362
+ super(HttpStatus.SERVICE_UNAVAILABLE, "internal-server-error", detail, options);
1775
1363
  }
1776
1364
  };
1777
- __name(_PaymentRequiredError, "PaymentRequiredError");
1778
- var PaymentRequiredError = _PaymentRequiredError;
1779
- var _ForbiddenError = class _ForbiddenError extends FreshError {
1365
+ __name(_ServiceUnavailableError, "ServiceUnavailableError");
1366
+ var ServiceUnavailableError = _ServiceUnavailableError;
1367
+ var _GatewayTimeoutError = class _GatewayTimeoutError extends FreshError {
1780
1368
  constructor(detail, options) {
1781
- super(HttpStatus.FORBIDDEN, "not-authorized", detail, options);
1369
+ super(HttpStatus.GATEWAY_TIMEOUT, "internal-server-error", detail, options);
1782
1370
  }
1783
1371
  };
1784
- __name(_ForbiddenError, "ForbiddenError");
1785
- var ForbiddenError = _ForbiddenError;
1786
- var _NotFoundError = class _NotFoundError extends FreshError {
1372
+ __name(_GatewayTimeoutError, "GatewayTimeoutError");
1373
+ var GatewayTimeoutError = _GatewayTimeoutError;
1374
+ var _HttpVersionNotSupportedError = class _HttpVersionNotSupportedError extends FreshError {
1787
1375
  constructor(detail, options) {
1788
- super(HttpStatus.NOT_FOUND, "error", detail, options);
1376
+ super(HttpStatus.HTTP_VERSION_NOT_SUPPORTED, "internal-server-error", detail, options);
1789
1377
  }
1790
1378
  };
1791
- __name(_NotFoundError, "NotFoundError");
1792
- var NotFoundError = _NotFoundError;
1793
- var _MethodNotAllowedError = class _MethodNotAllowedError extends FreshError {
1379
+ __name(_HttpVersionNotSupportedError, "HttpVersionNotSupportedError");
1380
+ var HttpVersionNotSupportedError = _HttpVersionNotSupportedError;
1381
+ var _VariantAlsoNegotiatesError = class _VariantAlsoNegotiatesError extends FreshError {
1794
1382
  constructor(detail, options) {
1795
- super(HttpStatus.METHOD_NOT_ALLOWED, "error", detail, options);
1383
+ super(HttpStatus.VARIANT_ALSO_NEGOTIATES, "internal-server-error", detail, options);
1796
1384
  }
1797
1385
  };
1798
- __name(_MethodNotAllowedError, "MethodNotAllowedError");
1799
- var MethodNotAllowedError = _MethodNotAllowedError;
1800
- var _NotAcceptableError = class _NotAcceptableError extends FreshError {
1386
+ __name(_VariantAlsoNegotiatesError, "VariantAlsoNegotiatesError");
1387
+ var VariantAlsoNegotiatesError = _VariantAlsoNegotiatesError;
1388
+ var _InsufficientStorageError = class _InsufficientStorageError extends FreshError {
1801
1389
  constructor(detail, options) {
1802
- super(HttpStatus.NOT_ACCEPTABLE, "error", detail, options);
1390
+ super(HttpStatus.INSUFFICIENT_STORAGE, "internal-server-error", detail, options);
1803
1391
  }
1804
1392
  };
1805
- __name(_NotAcceptableError, "NotAcceptableError");
1806
- var NotAcceptableError = _NotAcceptableError;
1807
- var _ProxyAuthenticationRequiredError = class _ProxyAuthenticationRequiredError extends FreshError {
1393
+ __name(_InsufficientStorageError, "InsufficientStorageError");
1394
+ var InsufficientStorageError = _InsufficientStorageError;
1395
+ var _LoopDetectedError = class _LoopDetectedError extends FreshError {
1808
1396
  constructor(detail, options) {
1809
- super(HttpStatus.PROXY_AUTHENTICATION_REQUIRED, "not-authenticated", detail, options);
1397
+ super(HttpStatus.LOOP_DETECTED, "internal-server-error", detail, options);
1810
1398
  }
1811
1399
  };
1812
- __name(_ProxyAuthenticationRequiredError, "ProxyAuthenticationRequiredError");
1813
- var ProxyAuthenticationRequiredError = _ProxyAuthenticationRequiredError;
1814
- var _RequestTimeoutError = class _RequestTimeoutError extends FreshError {
1400
+ __name(_LoopDetectedError, "LoopDetectedError");
1401
+ var LoopDetectedError = _LoopDetectedError;
1402
+ var _NotExtendedError = class _NotExtendedError extends FreshError {
1815
1403
  constructor(detail, options) {
1816
- super(HttpStatus.REQUEST_TIMEOUT, "error", detail, options);
1404
+ super(HttpStatus.NOT_EXTENDED, "internal-server-error", detail, options);
1817
1405
  }
1818
1406
  };
1819
- __name(_RequestTimeoutError, "RequestTimeoutError");
1820
- var RequestTimeoutError = _RequestTimeoutError;
1821
- var _ConflictError = class _ConflictError extends FreshError {
1407
+ __name(_NotExtendedError, "NotExtendedError");
1408
+ var NotExtendedError = _NotExtendedError;
1409
+ var _NetworkAuthenticationRequiredError = class _NetworkAuthenticationRequiredError extends FreshError {
1822
1410
  constructor(detail, options) {
1823
- super(HttpStatus.CONFLICT, "error", detail, options);
1411
+ super(HttpStatus.NETWORK_AUTHENTICATION_REQUIRED, "internal-server-error", detail, options);
1824
1412
  }
1825
1413
  };
1826
- __name(_ConflictError, "ConflictError");
1827
- var ConflictError = _ConflictError;
1828
- var _GoneError = class _GoneError extends FreshError {
1829
- constructor(detail, options) {
1830
- super(HttpStatus.GONE, "error", detail, options);
1414
+ __name(_NetworkAuthenticationRequiredError, "NetworkAuthenticationRequiredError");
1415
+ var NetworkAuthenticationRequiredError = _NetworkAuthenticationRequiredError;
1416
+
1417
+ // src/core/data-helper.ts
1418
+ var _DataHelper = class _DataHelper {
1419
+ constructor(startDataRetrieve = true, deviceIds) {
1420
+ __publicField(this, "_data");
1421
+ __publicField(this, "_dataPromise", null);
1422
+ __publicField(this, "deviceIds");
1423
+ this.deviceIds = deviceIds;
1424
+ if (startDataRetrieve) {
1425
+ this._dataPromise = this.startDataRetrieval();
1426
+ }
1427
+ }
1428
+ get data() {
1429
+ return this._data;
1430
+ }
1431
+ set data(value) {
1432
+ this._data = value;
1433
+ }
1434
+ get dataPromise() {
1435
+ return this._dataPromise;
1436
+ }
1437
+ set dataPromise(value) {
1438
+ this._dataPromise = value;
1439
+ }
1440
+ async getData() {
1441
+ if (this._dataPromise) {
1442
+ return await this._dataPromise;
1443
+ }
1444
+ if (this._data === void 0) {
1445
+ this._dataPromise = this.startDataRetrieval();
1446
+ return this._dataPromise;
1447
+ }
1448
+ return this._data;
1449
+ }
1450
+ };
1451
+ __name(_DataHelper, "DataHelper");
1452
+ var DataHelper = _DataHelper;
1453
+
1454
+ // src/common/pagination/find-options/pagination.ts
1455
+ function buildPagination(page, limit) {
1456
+ if (page === void 0 && limit === void 0) {
1457
+ return void 0;
1458
+ }
1459
+ if (page !== void 0 && page < 1 || limit !== void 0 && limit < 0) {
1460
+ throw new ApiError(HttpStatus.BAD_REQUEST, "validation-error", "Pagination parameters cannot be negative");
1461
+ }
1462
+ const p = page != null ? page : 1;
1463
+ const l = limit != null ? limit : 1e3;
1464
+ return {
1465
+ page: p,
1466
+ limit: l,
1467
+ skip: (p - 1) * l
1468
+ };
1469
+ }
1470
+ __name(buildPagination, "buildPagination");
1471
+
1472
+ // src/common/pagination/constructors.ts
1473
+ function constructTypeormPagination(params) {
1474
+ return {
1475
+ take: params.limit,
1476
+ skip: params.skip
1477
+ };
1478
+ }
1479
+ __name(constructTypeormPagination, "constructTypeormPagination");
1480
+ function parsePaginationFromURL(searchParams) {
1481
+ var _a, _b;
1482
+ const page = Math.max(1, parseInt((_a = searchParams.get("page")) != null ? _a : "1", 10));
1483
+ const limit = Math.min(100, Math.max(1, parseInt((_b = searchParams.get("limit")) != null ? _b : "20", 10)));
1484
+ return {
1485
+ page,
1486
+ limit,
1487
+ skip: (page - 1) * limit
1488
+ };
1489
+ }
1490
+ __name(parsePaginationFromURL, "parsePaginationFromURL");
1491
+
1492
+ // src/common/pagination/pagination-meta.ts
1493
+ function getPaginationMeta(total, page, limit) {
1494
+ return {
1495
+ total,
1496
+ page,
1497
+ limit,
1498
+ totalPages: Math.ceil(total / limit)
1499
+ };
1500
+ }
1501
+ __name(getPaginationMeta, "getPaginationMeta");
1502
+
1503
+ // src/common/pagination/pagination-params.ts
1504
+ function getPaginationParams(params) {
1505
+ return {
1506
+ ...DEFAULT_PAGINATION_PARAMS,
1507
+ ...params
1508
+ };
1509
+ }
1510
+ __name(getPaginationParams, "getPaginationParams");
1511
+ var DEFAULT_PAGINATION_PARAMS = {
1512
+ page: 1,
1513
+ limit: 1e3,
1514
+ skip: 0
1515
+ };
1516
+
1517
+ // src/common/pagination/scrapper.ts
1518
+ async function listAll(fetchPage, batchSize = 1e3) {
1519
+ const results = [];
1520
+ let page = 1;
1521
+ while (true) {
1522
+ const { data, meta } = await fetchPage({
1523
+ page,
1524
+ limit: batchSize,
1525
+ skip: (page - 1) * batchSize
1526
+ });
1527
+ results.push(...data);
1528
+ if (page >= meta.totalPages) {
1529
+ break;
1530
+ }
1531
+ page++;
1831
1532
  }
1832
- };
1833
- __name(_GoneError, "GoneError");
1834
- var GoneError = _GoneError;
1835
- var _LengthRequiredError = class _LengthRequiredError extends FreshError {
1836
- constructor(detail, options) {
1837
- super(HttpStatus.LENGTH_REQUIRED, "error", detail, options);
1533
+ return results;
1534
+ }
1535
+ __name(listAll, "listAll");
1536
+
1537
+ // src/common/promise-magic/deferred.ts
1538
+ function createDeferred() {
1539
+ let resolve;
1540
+ let reject;
1541
+ const promise = new Promise((res, rej) => {
1542
+ resolve = res;
1543
+ reject = rej;
1544
+ });
1545
+ return {
1546
+ promise,
1547
+ resolve,
1548
+ reject
1549
+ };
1550
+ }
1551
+ __name(createDeferred, "createDeferred");
1552
+
1553
+ // src/common/promise-magic/single-promise-waiter.ts
1554
+ var _SinglePromiseWaiter = class _SinglePromiseWaiter {
1555
+ constructor() {
1556
+ __publicField(this, "_promise", null);
1838
1557
  }
1839
- };
1840
- __name(_LengthRequiredError, "LengthRequiredError");
1841
- var LengthRequiredError = _LengthRequiredError;
1842
- var _PreconditionFailedError = class _PreconditionFailedError extends FreshError {
1843
- constructor(detail, options) {
1844
- super(HttpStatus.PRECONDITION_FAILED, "error", detail, options);
1558
+ static getInstance() {
1559
+ if (!_SinglePromiseWaiter._instance) {
1560
+ _SinglePromiseWaiter._instance = new _SinglePromiseWaiter();
1561
+ }
1562
+ return _SinglePromiseWaiter._instance;
1845
1563
  }
1846
- };
1847
- __name(_PreconditionFailedError, "PreconditionFailedError");
1848
- var PreconditionFailedError = _PreconditionFailedError;
1849
- var _PayloadTooLargeError = class _PayloadTooLargeError extends FreshError {
1850
- constructor(detail, options) {
1851
- super(HttpStatus.PAYLOAD_TOO_LARGE, "error", detail, options);
1564
+ get promise() {
1565
+ return this._promise;
1852
1566
  }
1853
- };
1854
- __name(_PayloadTooLargeError, "PayloadTooLargeError");
1855
- var PayloadTooLargeError = _PayloadTooLargeError;
1856
- var _UriTooLongError = class _UriTooLongError extends FreshError {
1857
- constructor(detail, options) {
1858
- super(HttpStatus.URI_TOO_LONG, "error", detail, options);
1567
+ set promise(promise) {
1568
+ if (promise !== null) {
1569
+ this._promise = promise;
1570
+ this._promise.finally(() => {
1571
+ this._promise = null;
1572
+ });
1573
+ }
1859
1574
  }
1860
- };
1861
- __name(_UriTooLongError, "UriTooLongError");
1862
- var UriTooLongError = _UriTooLongError;
1863
- var _UnsupportedMediaTypeError = class _UnsupportedMediaTypeError extends FreshError {
1864
- constructor(detail, options) {
1865
- super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "error", detail, options);
1575
+ get hasPromise() {
1576
+ return this._promise !== null;
1866
1577
  }
1867
1578
  };
1868
- __name(_UnsupportedMediaTypeError, "UnsupportedMediaTypeError");
1869
- var UnsupportedMediaTypeError = _UnsupportedMediaTypeError;
1870
- var _RangeNotSatisfiableError = class _RangeNotSatisfiableError extends FreshError {
1871
- constructor(detail, options) {
1872
- super(HttpStatus.RANGE_NOT_SATISFIABLE, "error", detail, options);
1579
+ __name(_SinglePromiseWaiter, "SinglePromiseWaiter");
1580
+ __publicField(_SinglePromiseWaiter, "_instance");
1581
+ var SinglePromiseWaiter = _SinglePromiseWaiter;
1582
+
1583
+ // src/common/schema/entities/category.entity.ts
1584
+ var import_typeorm6 = require("typeorm");
1585
+
1586
+ // src/database/entities/fresh-entity.ts
1587
+ var import_typeorm2 = require("typeorm");
1588
+
1589
+ // ../../node_modules/uuid/dist/esm/stringify.js
1590
+ var byteToHex = [];
1591
+ for (let i = 0; i < 256; ++i) {
1592
+ byteToHex.push((i + 256).toString(16).slice(1));
1593
+ }
1594
+ function unsafeStringify(arr, offset = 0) {
1595
+ 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();
1596
+ }
1597
+ __name(unsafeStringify, "unsafeStringify");
1598
+
1599
+ // ../../node_modules/uuid/dist/esm/rng.js
1600
+ var import_crypto = require("crypto");
1601
+ var rnds8Pool = new Uint8Array(256);
1602
+ var poolPtr = rnds8Pool.length;
1603
+ function rng() {
1604
+ if (poolPtr > rnds8Pool.length - 16) {
1605
+ (0, import_crypto.randomFillSync)(rnds8Pool);
1606
+ poolPtr = 0;
1873
1607
  }
1608
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
1609
+ }
1610
+ __name(rng, "rng");
1611
+
1612
+ // ../../node_modules/uuid/dist/esm/native.js
1613
+ var import_crypto2 = require("crypto");
1614
+ var native_default = {
1615
+ randomUUID: import_crypto2.randomUUID
1874
1616
  };
1875
- __name(_RangeNotSatisfiableError, "RangeNotSatisfiableError");
1876
- var RangeNotSatisfiableError = _RangeNotSatisfiableError;
1877
- var _ExpectationFailedError = class _ExpectationFailedError extends FreshError {
1878
- constructor(detail, options) {
1879
- super(HttpStatus.EXPECTATION_FAILED, "error", detail, options);
1617
+
1618
+ // ../../node_modules/uuid/dist/esm/v4.js
1619
+ function v4(options, buf, offset) {
1620
+ var _a, _b, _c;
1621
+ if (native_default.randomUUID && !buf && !options) {
1622
+ return native_default.randomUUID();
1880
1623
  }
1881
- };
1882
- __name(_ExpectationFailedError, "ExpectationFailedError");
1883
- var ExpectationFailedError = _ExpectationFailedError;
1884
- var _ImATeapotError = class _ImATeapotError extends FreshError {
1885
- constructor(detail, options) {
1886
- super(HttpStatus.IM_A_TEAPOT, "error", detail, options);
1624
+ options = options || {};
1625
+ const rnds = (_c = (_b = options.random) != null ? _b : (_a = options.rng) == null ? void 0 : _a.call(options)) != null ? _c : rng();
1626
+ if (rnds.length < 16) {
1627
+ throw new Error("Random bytes length must be >= 16");
1887
1628
  }
1888
- };
1889
- __name(_ImATeapotError, "ImATeapotError");
1890
- var ImATeapotError = _ImATeapotError;
1891
- var _MisdirectedRequestError = class _MisdirectedRequestError extends FreshError {
1892
- constructor(detail, options) {
1893
- super(HttpStatus.MISDIRECTED_REQUEST, "error", detail, options);
1629
+ rnds[6] = rnds[6] & 15 | 64;
1630
+ rnds[8] = rnds[8] & 63 | 128;
1631
+ if (buf) {
1632
+ offset = offset || 0;
1633
+ if (offset < 0 || offset + 16 > buf.length) {
1634
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
1635
+ }
1636
+ for (let i = 0; i < 16; ++i) {
1637
+ buf[offset + i] = rnds[i];
1638
+ }
1639
+ return buf;
1894
1640
  }
1895
- };
1896
- __name(_MisdirectedRequestError, "MisdirectedRequestError");
1897
- var MisdirectedRequestError = _MisdirectedRequestError;
1898
- var _UnprocessableEntityError = class _UnprocessableEntityError extends FreshError {
1899
- constructor(detail, options) {
1900
- super(HttpStatus.UNPROCESSABLE_ENTITY, "validation-error", detail, options);
1641
+ return unsafeStringify(rnds);
1642
+ }
1643
+ __name(v4, "v4");
1644
+ var v4_default = v4;
1645
+
1646
+ // src/database/entities/fresh-entity.ts
1647
+ function _ts_decorate(decorators, target, key, desc) {
1648
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1649
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1650
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1651
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1652
+ }
1653
+ __name(_ts_decorate, "_ts_decorate");
1654
+ function _ts_metadata(k, v) {
1655
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1656
+ }
1657
+ __name(_ts_metadata, "_ts_metadata");
1658
+ var _FreshEntity = class _FreshEntity extends import_typeorm2.BaseEntity {
1659
+ /** After manual construction `id` is irrelevant. Refer to `uuid` only, because that will be inserted into DB */
1660
+ constructor() {
1661
+ super();
1662
+ __publicField(this, "id");
1663
+ __publicField(this, "uuid");
1664
+ __publicField(this, "created_at");
1665
+ __publicField(this, "updated_at");
1666
+ // for soft delete methods by typeorm
1667
+ __publicField(this, "deleted_at");
1668
+ this.id = 0;
1669
+ this.uuid = v4_default();
1670
+ const newDate = /* @__PURE__ */ new Date();
1671
+ this.created_at = newDate;
1672
+ this.updated_at = newDate;
1673
+ this.deleted_at = null;
1901
1674
  }
1902
1675
  };
1903
- __name(_UnprocessableEntityError, "UnprocessableEntityError");
1904
- var UnprocessableEntityError = _UnprocessableEntityError;
1905
- var _LockedError = class _LockedError extends FreshError {
1906
- constructor(detail, options) {
1907
- super(HttpStatus.LOCKED, "error", detail, options);
1676
+ __name(_FreshEntity, "FreshEntity");
1677
+ var FreshEntity = _FreshEntity;
1678
+ _ts_decorate([
1679
+ (0, import_typeorm2.PrimaryGeneratedColumn)("increment"),
1680
+ _ts_metadata("design:type", Number)
1681
+ ], FreshEntity.prototype, "id", void 0);
1682
+ _ts_decorate([
1683
+ (0, import_typeorm2.Index)({
1684
+ unique: true
1685
+ }),
1686
+ (0, import_typeorm2.Column)({
1687
+ type: "uuid",
1688
+ default: /* @__PURE__ */ __name(() => "gen_random_uuid()", "default")
1689
+ }),
1690
+ _ts_metadata("design:type", String)
1691
+ ], FreshEntity.prototype, "uuid", void 0);
1692
+ _ts_decorate([
1693
+ (0, import_typeorm2.CreateDateColumn)({
1694
+ type: "timestamptz"
1695
+ }),
1696
+ _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
1697
+ ], FreshEntity.prototype, "created_at", void 0);
1698
+ _ts_decorate([
1699
+ (0, import_typeorm2.UpdateDateColumn)({
1700
+ type: "timestamptz"
1701
+ }),
1702
+ _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
1703
+ ], FreshEntity.prototype, "updated_at", void 0);
1704
+ _ts_decorate([
1705
+ (0, import_typeorm2.DeleteDateColumn)({
1706
+ type: "timestamptz",
1707
+ nullable: true
1708
+ }),
1709
+ _ts_metadata("design:type", Object)
1710
+ ], FreshEntity.prototype, "deleted_at", void 0);
1711
+
1712
+ // src/database/entities/fresh-hyper-entity.ts
1713
+ var import_typeorm4 = require("typeorm");
1714
+
1715
+ // src/database/decorators/timestamp-column.ts
1716
+ var import_typeorm3 = require("typeorm");
1717
+ function TimestampColumn(options = {}) {
1718
+ const defaultOptions = {
1719
+ type: "timestamptz",
1720
+ nullable: false,
1721
+ default: /* @__PURE__ */ __name(() => "CURRENT_TIMESTAMP", "default"),
1722
+ ...options
1723
+ };
1724
+ return (0, import_typeorm3.Column)(defaultOptions);
1725
+ }
1726
+ __name(TimestampColumn, "TimestampColumn");
1727
+
1728
+ // src/database/entities/fresh-hyper-entity.ts
1729
+ function _ts_decorate2(decorators, target, key, desc) {
1730
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1731
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1732
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1733
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1734
+ }
1735
+ __name(_ts_decorate2, "_ts_decorate");
1736
+ function _ts_metadata2(k, v) {
1737
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1738
+ }
1739
+ __name(_ts_metadata2, "_ts_metadata");
1740
+ var _FreshHyperEntity = class _FreshHyperEntity extends import_typeorm4.BaseEntity {
1741
+ /** After manual construction `id` is irrelevant */
1742
+ constructor(timestamp) {
1743
+ super();
1744
+ // input timestamp as PK
1745
+ __publicField(this, "timestamp");
1746
+ // just info column about time of insert
1747
+ __publicField(this, "created_at");
1748
+ this.timestamp = timestamp != null ? timestamp : /* @__PURE__ */ new Date();
1749
+ this.created_at = /* @__PURE__ */ new Date();
1908
1750
  }
1909
1751
  };
1910
- __name(_LockedError, "LockedError");
1911
- var LockedError = _LockedError;
1912
- var _FailedDependencyError = class _FailedDependencyError extends FreshError {
1913
- constructor(detail, options) {
1914
- super(HttpStatus.FAILED_DEPENDENCY, "error", detail, options);
1752
+ __name(_FreshHyperEntity, "FreshHyperEntity");
1753
+ var FreshHyperEntity = _FreshHyperEntity;
1754
+ _ts_decorate2([
1755
+ (0, import_typeorm4.PrimaryColumn)({
1756
+ type: "timestamptz"
1757
+ }),
1758
+ _ts_metadata2("design:type", typeof Date === "undefined" ? Object : Date)
1759
+ ], FreshHyperEntity.prototype, "timestamp", void 0);
1760
+ _ts_decorate2([
1761
+ TimestampColumn(),
1762
+ _ts_metadata2("design:type", typeof Date === "undefined" ? Object : Date)
1763
+ ], FreshHyperEntity.prototype, "created_at", void 0);
1764
+
1765
+ // src/database/entities/fresh-translation-entity.ts
1766
+ var import_typeorm5 = require("typeorm");
1767
+ function _ts_decorate3(decorators, target, key, desc) {
1768
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1769
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1770
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1771
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1772
+ }
1773
+ __name(_ts_decorate3, "_ts_decorate");
1774
+ function _ts_metadata3(k, v) {
1775
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1776
+ }
1777
+ __name(_ts_metadata3, "_ts_metadata");
1778
+ var languageValues = Object.values(LanguageCode).map((v) => `'${v}'`).join(",");
1779
+ var _FreshTranslationBase = class _FreshTranslationBase extends import_typeorm5.BaseEntity {
1780
+ constructor() {
1781
+ super();
1782
+ __publicField(this, "id");
1783
+ __publicField(this, "languageCode");
1784
+ this.id = 0;
1785
+ this.languageCode = LanguageCode.CS;
1915
1786
  }
1916
1787
  };
1917
- __name(_FailedDependencyError, "FailedDependencyError");
1918
- var FailedDependencyError = _FailedDependencyError;
1919
- var _TooEarlyError = class _TooEarlyError extends FreshError {
1920
- constructor(detail, options) {
1921
- super(HttpStatus.TOO_EARLY, "error", detail, options);
1788
+ __name(_FreshTranslationBase, "FreshTranslationBase");
1789
+ var FreshTranslationBase = _FreshTranslationBase;
1790
+ _ts_decorate3([
1791
+ (0, import_typeorm5.PrimaryGeneratedColumn)(),
1792
+ _ts_metadata3("design:type", Number)
1793
+ ], FreshTranslationBase.prototype, "id", void 0);
1794
+ _ts_decorate3([
1795
+ (0, import_typeorm5.Column)({
1796
+ type: "varchar",
1797
+ length: 3,
1798
+ nullable: false
1799
+ }),
1800
+ (0, import_typeorm5.Check)(`"languageCode" IN (${languageValues})`),
1801
+ _ts_metadata3("design:type", typeof LanguageCode === "undefined" ? Object : LanguageCode)
1802
+ ], FreshTranslationBase.prototype, "languageCode", void 0);
1803
+
1804
+ // src/database/dao/fresh-dao.ts
1805
+ var _FreshDao = class _FreshDao {
1806
+ getRepo(manager, entity = this.entity) {
1807
+ return manager ? manager.getRepository(entity) : this.repo;
1922
1808
  }
1923
1809
  };
1924
- __name(_TooEarlyError, "TooEarlyError");
1925
- var TooEarlyError = _TooEarlyError;
1926
- var _UpgradeRequiredError = class _UpgradeRequiredError extends FreshError {
1927
- constructor(detail, options) {
1928
- super(HttpStatus.UPGRADE_REQUIRED, "error", detail, options);
1810
+ __name(_FreshDao, "FreshDao");
1811
+ var FreshDao = _FreshDao;
1812
+
1813
+ // src/database/subscribers/base-entity-change.subscriber.ts
1814
+ var _BaseEntityChangeSubscriber = class _BaseEntityChangeSubscriber {
1815
+ // ─── TypeORM lifecycle hooks ────────────────────────────────────────
1816
+ afterInsert(event) {
1817
+ var _a;
1818
+ const id = (_a = event.entity) == null ? void 0 : _a.id;
1819
+ if (!id) {
1820
+ return;
1821
+ }
1822
+ if (event.queryRunner.isTransactionActive) {
1823
+ this.addPending(event, id, "created");
1824
+ } else {
1825
+ console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
1826
+ this.sendNotification(id, "created", event.queryRunner.manager);
1827
+ }
1929
1828
  }
1930
- };
1931
- __name(_UpgradeRequiredError, "UpgradeRequiredError");
1932
- var UpgradeRequiredError = _UpgradeRequiredError;
1933
- var _PreconditionRequiredError = class _PreconditionRequiredError extends FreshError {
1934
- constructor(detail, options) {
1935
- super(HttpStatus.PRECONDITION_REQUIRED, "error", detail, options);
1829
+ afterUpdate(event) {
1830
+ var _a, _b, _c;
1831
+ const id = (_c = (_a = event.entity) == null ? void 0 : _a.id) != null ? _c : (_b = event.databaseEntity) == null ? void 0 : _b.id;
1832
+ if (!id) {
1833
+ return;
1834
+ }
1835
+ if (event.queryRunner.isTransactionActive) {
1836
+ this.addPending(event, id, "updated");
1837
+ } else {
1838
+ console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
1839
+ this.sendNotification(id, "updated", event.queryRunner.manager);
1840
+ }
1936
1841
  }
1937
- };
1938
- __name(_PreconditionRequiredError, "PreconditionRequiredError");
1939
- var PreconditionRequiredError = _PreconditionRequiredError;
1940
- var _TooManyRequestsError = class _TooManyRequestsError extends FreshError {
1941
- constructor(detail, options) {
1942
- super(HttpStatus.TOO_MANY_REQUESTS, "error", detail, options);
1842
+ afterSoftRemove(event) {
1843
+ var _a, _b, _c;
1844
+ const id = (_c = (_a = event.entity) == null ? void 0 : _a.id) != null ? _c : (_b = event.databaseEntity) == null ? void 0 : _b.id;
1845
+ if (!id) {
1846
+ return;
1847
+ }
1848
+ if (event.queryRunner.isTransactionActive) {
1849
+ this.addPending(event, id, "deleted");
1850
+ } else {
1851
+ console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
1852
+ this.sendNotification(id, "deleted", event.queryRunner.manager);
1853
+ }
1943
1854
  }
1944
- };
1945
- __name(_TooManyRequestsError, "TooManyRequestsError");
1946
- var TooManyRequestsError = _TooManyRequestsError;
1947
- var _RequestHeaderFieldsTooLargeError = class _RequestHeaderFieldsTooLargeError extends FreshError {
1948
- constructor(detail, options) {
1949
- super(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE, "error", detail, options);
1855
+ async afterTransactionCommit(event) {
1856
+ var _a;
1857
+ const pending = (_a = event.queryRunner.data) == null ? void 0 : _a[this.PENDING_KEY];
1858
+ if (!pending || pending.size === 0) {
1859
+ return;
1860
+ }
1861
+ event.queryRunner.data[this.PENDING_KEY] = /* @__PURE__ */ new Map();
1862
+ for (const [id, changeEvent] of pending) {
1863
+ await this.sendNotification(id, changeEvent, event.connection.manager);
1864
+ }
1950
1865
  }
1951
- };
1952
- __name(_RequestHeaderFieldsTooLargeError, "RequestHeaderFieldsTooLargeError");
1953
- var RequestHeaderFieldsTooLargeError = _RequestHeaderFieldsTooLargeError;
1954
- var _UnavailableForLegalReasonsError = class _UnavailableForLegalReasonsError extends FreshError {
1955
- constructor(detail, options) {
1956
- super(HttpStatus.UNAVAILABLE_FOR_LEGAL_REASONS, "error", detail, options);
1866
+ // ─── Private helpers ───────────────────────────────────────────────
1867
+ addPending(event, id, changeEvent) {
1868
+ if (!event.queryRunner.data) {
1869
+ event.queryRunner.data = {};
1870
+ }
1871
+ if (!event.queryRunner.data[this.PENDING_KEY]) {
1872
+ event.queryRunner.data[this.PENDING_KEY] = /* @__PURE__ */ new Map();
1873
+ }
1874
+ const existing = event.queryRunner.data[this.PENDING_KEY].get(id);
1875
+ if (!existing || changeEvent === "created" || changeEvent === "deleted") {
1876
+ event.queryRunner.data[this.PENDING_KEY].set(id, changeEvent);
1877
+ }
1957
1878
  }
1958
- };
1959
- __name(_UnavailableForLegalReasonsError, "UnavailableForLegalReasonsError");
1960
- var UnavailableForLegalReasonsError = _UnavailableForLegalReasonsError;
1961
- var _InternalServerError = class _InternalServerError extends FreshError {
1962
- constructor(detail, options) {
1963
- super(HttpStatus.INTERNAL_SERVER_ERROR, "internal-server-error", detail, options);
1879
+ async sendNotification(id, changeEvent, manager) {
1880
+ try {
1881
+ await this.handleNotification(id, changeEvent, manager);
1882
+ } catch (error) {
1883
+ console.error(`${this.SUBSCRIBER_NAME} - Failed to send notification: ${error instanceof Error ? error.message : error}`);
1884
+ }
1964
1885
  }
1965
1886
  };
1966
- __name(_InternalServerError, "InternalServerError");
1967
- var InternalServerError = _InternalServerError;
1968
- var _NotImplementedError = class _NotImplementedError extends FreshError {
1969
- constructor(detail, options) {
1970
- super(HttpStatus.NOT_IMPLEMENTED, "internal-server-error", detail, options);
1971
- }
1887
+ __name(_BaseEntityChangeSubscriber, "BaseEntityChangeSubscriber");
1888
+ var BaseEntityChangeSubscriber = _BaseEntityChangeSubscriber;
1889
+
1890
+ // src/common/schema/entities/category.entity.ts
1891
+ function _ts_decorate4(decorators, target, key, desc) {
1892
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1893
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1894
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1895
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1896
+ }
1897
+ __name(_ts_decorate4, "_ts_decorate");
1898
+ var _Category = class _Category extends FreshEntity {
1972
1899
  };
1973
- __name(_NotImplementedError, "NotImplementedError");
1974
- var NotImplementedError = _NotImplementedError;
1975
- var _BadGatewayError = class _BadGatewayError extends FreshError {
1976
- constructor(detail, options) {
1977
- super(HttpStatus.BAD_GATEWAY, "internal-server-error", detail, options);
1978
- }
1900
+ __name(_Category, "Category");
1901
+ var Category = _Category;
1902
+ Category = _ts_decorate4([
1903
+ (0, import_typeorm6.Entity)()
1904
+ ], Category);
1905
+
1906
+ // src/common/schema/entities/device.entity.ts
1907
+ var import_typeorm7 = require("typeorm");
1908
+ function _ts_decorate5(decorators, target, key, desc) {
1909
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1910
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1911
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1912
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1913
+ }
1914
+ __name(_ts_decorate5, "_ts_decorate");
1915
+ var _Device = class _Device extends FreshEntity {
1979
1916
  };
1980
- __name(_BadGatewayError, "BadGatewayError");
1981
- var BadGatewayError = _BadGatewayError;
1982
- var _ServiceUnavailableError = class _ServiceUnavailableError extends FreshError {
1983
- constructor(detail, options) {
1984
- super(HttpStatus.SERVICE_UNAVAILABLE, "internal-server-error", detail, options);
1985
- }
1917
+ __name(_Device, "Device");
1918
+ var Device = _Device;
1919
+ Device = _ts_decorate5([
1920
+ (0, import_typeorm7.Entity)()
1921
+ ], Device);
1922
+
1923
+ // src/common/schema/entities/manufacturer.entity.ts
1924
+ var import_typeorm8 = require("typeorm");
1925
+ function _ts_decorate6(decorators, target, key, desc) {
1926
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1927
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1928
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1929
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1930
+ }
1931
+ __name(_ts_decorate6, "_ts_decorate");
1932
+ var _Manufacturer = class _Manufacturer extends FreshEntity {
1986
1933
  };
1987
- __name(_ServiceUnavailableError, "ServiceUnavailableError");
1988
- var ServiceUnavailableError = _ServiceUnavailableError;
1989
- var _GatewayTimeoutError = class _GatewayTimeoutError extends FreshError {
1990
- constructor(detail, options) {
1991
- super(HttpStatus.GATEWAY_TIMEOUT, "internal-server-error", detail, options);
1992
- }
1934
+ __name(_Manufacturer, "Manufacturer");
1935
+ var Manufacturer = _Manufacturer;
1936
+ Manufacturer = _ts_decorate6([
1937
+ (0, import_typeorm8.Entity)()
1938
+ ], Manufacturer);
1939
+
1940
+ // src/common/schema/entities/product.entity.ts
1941
+ var import_typeorm9 = require("typeorm");
1942
+ function _ts_decorate7(decorators, target, key, desc) {
1943
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1944
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1945
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1946
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1947
+ }
1948
+ __name(_ts_decorate7, "_ts_decorate");
1949
+ var _Product = class _Product extends FreshEntity {
1993
1950
  };
1994
- __name(_GatewayTimeoutError, "GatewayTimeoutError");
1995
- var GatewayTimeoutError = _GatewayTimeoutError;
1996
- var _HttpVersionNotSupportedError = class _HttpVersionNotSupportedError extends FreshError {
1997
- constructor(detail, options) {
1998
- super(HttpStatus.HTTP_VERSION_NOT_SUPPORTED, "internal-server-error", detail, options);
1999
- }
1951
+ __name(_Product, "Product");
1952
+ var Product = _Product;
1953
+ Product = _ts_decorate7([
1954
+ (0, import_typeorm9.Entity)()
1955
+ ], Product);
1956
+
1957
+ // src/common/schema/entities/subcategory.entity.ts
1958
+ var import_typeorm10 = require("typeorm");
1959
+ function _ts_decorate8(decorators, target, key, desc) {
1960
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1961
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1962
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1963
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1964
+ }
1965
+ __name(_ts_decorate8, "_ts_decorate");
1966
+ var _Subcategory = class _Subcategory extends FreshEntity {
2000
1967
  };
2001
- __name(_HttpVersionNotSupportedError, "HttpVersionNotSupportedError");
2002
- var HttpVersionNotSupportedError = _HttpVersionNotSupportedError;
2003
- var _VariantAlsoNegotiatesError = class _VariantAlsoNegotiatesError extends FreshError {
2004
- constructor(detail, options) {
2005
- super(HttpStatus.VARIANT_ALSO_NEGOTIATES, "internal-server-error", detail, options);
1968
+ __name(_Subcategory, "Subcategory");
1969
+ var Subcategory = _Subcategory;
1970
+ Subcategory = _ts_decorate8([
1971
+ (0, import_typeorm10.Entity)()
1972
+ ], Subcategory);
1973
+
1974
+ // src/common/typeguards/decimal.ts
1975
+ function toDecimal(num, precision = 9, scale = 2) {
1976
+ const limit = Math.pow(10, precision - scale);
1977
+ if (Math.abs(num) >= limit) {
1978
+ throw new Error(`Value ${num} exceeds the allowed precision of ${precision} and scale of ${scale}.`);
2006
1979
  }
2007
- };
2008
- __name(_VariantAlsoNegotiatesError, "VariantAlsoNegotiatesError");
2009
- var VariantAlsoNegotiatesError = _VariantAlsoNegotiatesError;
2010
- var _InsufficientStorageError = class _InsufficientStorageError extends FreshError {
2011
- constructor(detail, options) {
2012
- super(HttpStatus.INSUFFICIENT_STORAGE, "internal-server-error", detail, options);
1980
+ return num.toFixed(scale);
1981
+ }
1982
+ __name(toDecimal, "toDecimal");
1983
+ function isDecimal(v, options) {
1984
+ var _a, _b, _c;
1985
+ const type = typeof v;
1986
+ if ((options == null ? void 0 : options.allowedType) !== void 0 && type !== options.allowedType) {
1987
+ return false;
2013
1988
  }
2014
- };
2015
- __name(_InsufficientStorageError, "InsufficientStorageError");
2016
- var InsufficientStorageError = _InsufficientStorageError;
2017
- var _LoopDetectedError = class _LoopDetectedError extends FreshError {
2018
- constructor(detail, options) {
2019
- super(HttpStatus.LOOP_DETECTED, "internal-server-error", detail, options);
1989
+ if (type !== "number" && type !== "string") {
1990
+ return false;
2020
1991
  }
2021
- };
2022
- __name(_LoopDetectedError, "LoopDetectedError");
2023
- var LoopDetectedError = _LoopDetectedError;
2024
- var _NotExtendedError = class _NotExtendedError extends FreshError {
2025
- constructor(detail, options) {
2026
- super(HttpStatus.NOT_EXTENDED, "internal-server-error", detail, options);
1992
+ const sep = (_a = options == null ? void 0 : options.decimalPoint) != null ? _a : ".";
1993
+ let intPart;
1994
+ let fracPart;
1995
+ if (type === "number") {
1996
+ const n = v;
1997
+ if (!Number.isFinite(n)) {
1998
+ return false;
1999
+ }
2000
+ const str = n.toString();
2001
+ if (str.includes("e") || str.includes("E")) {
2002
+ return false;
2003
+ }
2004
+ const parts = str.replace("-", "").split(".");
2005
+ intPart = parts[0];
2006
+ fracPart = (_b = parts[1]) != null ? _b : "";
2007
+ } else {
2008
+ const s = v;
2009
+ const escapedSep = sep === "." ? "\\." : ",";
2010
+ const pattern = new RegExp(`^-?\\d+(?:${escapedSep}\\d+)?$`);
2011
+ if (!pattern.test(s)) {
2012
+ return false;
2013
+ }
2014
+ const parts = s.replace("-", "").split(sep);
2015
+ intPart = parts[0];
2016
+ fracPart = (_c = parts[1]) != null ? _c : "";
2027
2017
  }
2028
- };
2029
- __name(_NotExtendedError, "NotExtendedError");
2030
- var NotExtendedError = _NotExtendedError;
2031
- var _NetworkAuthenticationRequiredError = class _NetworkAuthenticationRequiredError extends FreshError {
2032
- constructor(detail, options) {
2033
- super(HttpStatus.NETWORK_AUTHENTICATION_REQUIRED, "internal-server-error", detail, options);
2018
+ if ((options == null ? void 0 : options.scale) !== void 0 && fracPart.length > options.scale) {
2019
+ return false;
2034
2020
  }
2035
- };
2036
- __name(_NetworkAuthenticationRequiredError, "NetworkAuthenticationRequiredError");
2037
- var NetworkAuthenticationRequiredError = _NetworkAuthenticationRequiredError;
2021
+ return (options == null ? void 0 : options.precision) === void 0 || intPart.length + fracPart.length <= options.precision;
2022
+ }
2023
+ __name(isDecimal, "isDecimal");
2038
2024
 
2039
- // src/core/data-helper.ts
2040
- var _DataHelper = class _DataHelper {
2041
- constructor(startDataRetrieve = true, deviceIds) {
2042
- __publicField(this, "_data");
2043
- __publicField(this, "_dataPromise", null);
2044
- __publicField(this, "deviceIds");
2045
- this.deviceIds = deviceIds;
2046
- if (startDataRetrieve) {
2047
- this._dataPromise = this.startDataRetrieval();
2048
- }
2049
- }
2050
- get data() {
2051
- return this._data;
2025
+ // src/common/typeguards/enums.ts
2026
+ function isEnumValue(enumObj, v) {
2027
+ if (!enumObj) {
2028
+ return typeof v === "string" || typeof v === "number";
2052
2029
  }
2053
- set data(value) {
2054
- this._data = value;
2030
+ const values = new Set(Object.values(enumObj));
2031
+ return (typeof v === "string" || typeof v === "number") && values.has(v);
2032
+ }
2033
+ __name(isEnumValue, "isEnumValue");
2034
+
2035
+ // src/common/typeguards/objects.ts
2036
+ function isObject(v) {
2037
+ return typeof v === "object" && v !== null;
2038
+ }
2039
+ __name(isObject, "isObject");
2040
+ function hasOwn(obj, key) {
2041
+ return Object.prototype.hasOwnProperty.call(obj, key);
2042
+ }
2043
+ __name(hasOwn, "hasOwn");
2044
+
2045
+ // src/common/typeguards/primitives.ts
2046
+ function isNumber(v) {
2047
+ return typeof v === "number" && Number.isFinite(v);
2048
+ }
2049
+ __name(isNumber, "isNumber");
2050
+ function isString(v) {
2051
+ return typeof v === "string";
2052
+ }
2053
+ __name(isString, "isString");
2054
+ function isFlag01(v) {
2055
+ return v === 0 || v === 1;
2056
+ }
2057
+ __name(isFlag01, "isFlag01");
2058
+ function isNumberInRange(v, min, max, options) {
2059
+ var _a, _b;
2060
+ if (!isNumber(v)) {
2061
+ return false;
2055
2062
  }
2056
- get dataPromise() {
2057
- return this._dataPromise;
2063
+ const includeMin = (_a = options == null ? void 0 : options.includeMin) != null ? _a : true;
2064
+ const includeMax = (_b = options == null ? void 0 : options.includeMax) != null ? _b : true;
2065
+ if (includeMin ? v < min : v <= min) {
2066
+ return false;
2058
2067
  }
2059
- set dataPromise(value) {
2060
- this._dataPromise = value;
2068
+ if (includeMax ? v > max : v >= max) {
2069
+ return false;
2061
2070
  }
2062
- async getData() {
2063
- if (this._dataPromise) {
2064
- return await this._dataPromise;
2071
+ return true;
2072
+ }
2073
+ __name(isNumberInRange, "isNumberInRange");
2074
+ var TO_BINARY_FLAG = /* @__PURE__ */ __name((v) => v === 1 || v === true ? 1 : 0, "TO_BINARY_FLAG");
2075
+
2076
+ // src/common/utils/async.utils.ts
2077
+ async function runWithConcurrency(items, concurrency, worker) {
2078
+ const queue = [
2079
+ ...items
2080
+ ];
2081
+ const runNext = /* @__PURE__ */ __name(async () => {
2082
+ const item = queue.shift();
2083
+ if (!item) {
2084
+ return;
2065
2085
  }
2066
- if (this._data === void 0) {
2067
- this._dataPromise = this.startDataRetrieval();
2068
- return this._dataPromise;
2086
+ await worker(item);
2087
+ await runNext();
2088
+ }, "runNext");
2089
+ await Promise.all(Array.from({
2090
+ length: Math.min(concurrency, items.length)
2091
+ }, runNext));
2092
+ }
2093
+ __name(runWithConcurrency, "runWithConcurrency");
2094
+
2095
+ // src/common/utils/id-path-param-resolver.utils.ts
2096
+ function resolvePathParameterId(id) {
2097
+ return /^\d+$/.test(id) ? parseInt(id, 10) : id;
2098
+ }
2099
+ __name(resolvePathParameterId, "resolvePathParameterId");
2100
+
2101
+ // src/common/utils/is-cron-valid.ts
2102
+ function isValidCron(expr) {
2103
+ const parts = expr.trim().split(/\s+/);
2104
+ if (parts.length < 5 || parts.length > 6) {
2105
+ return false;
2106
+ }
2107
+ const cronPart = /^(\*|\d+|\d+\-\d+|\d+\/\d+|\*\/\d+)(,\d+)*$/;
2108
+ return parts.every((part) => cronPart.test(part));
2109
+ }
2110
+ __name(isValidCron, "isValidCron");
2111
+
2112
+ // src/common/utils/patch.utils.ts
2113
+ function buildPatch(data, keys, transforms) {
2114
+ const patch = {};
2115
+ for (const k of keys) {
2116
+ const value = data[k];
2117
+ if (value === void 0) {
2118
+ continue;
2069
2119
  }
2070
- return this._data;
2120
+ patch[k] = (transforms == null ? void 0 : transforms[k]) ? transforms[k](value) : value;
2071
2121
  }
2072
- };
2073
- __name(_DataHelper, "DataHelper");
2074
- var DataHelper = _DataHelper;
2122
+ return patch;
2123
+ }
2124
+ __name(buildPatch, "buildPatch");
2075
2125
 
2076
2126
  // src/types/maybe-type.ts
2077
2127
  function isMaybe(v, inner) {
@@ -2333,6 +2383,9 @@ var datasource_default = PG_DATA_SOURCE_OPTIONS;
2333
2383
  UpgradeRequiredError,
2334
2384
  UriTooLongError,
2335
2385
  VariantAlsoNegotiatesError,
2386
+ buildDateRange,
2387
+ buildOrder,
2388
+ buildPagination,
2336
2389
  buildPatch,
2337
2390
  constructTypeormPagination,
2338
2391
  createDeferred,