@freshpointcz/fresh-core 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +46 -5
- package/dist/index.d.ts +46 -5
- package/dist/index.js +81 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -648,56 +648,6 @@ __name(_SinglePromiseWaiter, "SinglePromiseWaiter");
|
|
|
648
648
|
__publicField(_SinglePromiseWaiter, "_instance");
|
|
649
649
|
var SinglePromiseWaiter = _SinglePromiseWaiter;
|
|
650
650
|
|
|
651
|
-
// src/common/winston.ts
|
|
652
|
-
import winston from "winston";
|
|
653
|
-
var SERVICE = process.env.SERVICE_NAME || "depot-ordering-service";
|
|
654
|
-
var ENV = process.env.NODE_ENV || "localhost";
|
|
655
|
-
var levelToSeverity = {
|
|
656
|
-
silly: "debug",
|
|
657
|
-
verbose: "debug",
|
|
658
|
-
debug: "debug",
|
|
659
|
-
http: "info",
|
|
660
|
-
info: "info",
|
|
661
|
-
warn: "warn",
|
|
662
|
-
error: "error"
|
|
663
|
-
};
|
|
664
|
-
var baseFormat = winston.format.combine(winston.format.timestamp({
|
|
665
|
-
format: /* @__PURE__ */ __name(() => (/* @__PURE__ */ new Date()).toISOString(), "format")
|
|
666
|
-
}), winston.format.errors({
|
|
667
|
-
stack: true
|
|
668
|
-
}), winston.format.printf((info) => {
|
|
669
|
-
const payload = {
|
|
670
|
-
ts: info.timestamp,
|
|
671
|
-
level: info.level,
|
|
672
|
-
severity: levelToSeverity[info.level] || info.level,
|
|
673
|
-
message: info.message,
|
|
674
|
-
service: SERVICE,
|
|
675
|
-
env: ENV,
|
|
676
|
-
process_name: process.title || process.argv[1] || "node",
|
|
677
|
-
pid: process.pid,
|
|
678
|
-
device: process.env.DEVICE_ID || void 0,
|
|
679
|
-
traceId: info.traceId,
|
|
680
|
-
spanId: info.spanId,
|
|
681
|
-
extra: info.extra || info.meta || void 0,
|
|
682
|
-
stack: info.stack
|
|
683
|
-
};
|
|
684
|
-
return JSON.stringify(payload);
|
|
685
|
-
}));
|
|
686
|
-
var transports = [
|
|
687
|
-
new winston.transports.Console({
|
|
688
|
-
level: process.env.LOG_LEVEL || "info"
|
|
689
|
-
})
|
|
690
|
-
];
|
|
691
|
-
var logger = winston.createLogger({
|
|
692
|
-
level: process.env.LOG_LEVEL || "info",
|
|
693
|
-
format: baseFormat,
|
|
694
|
-
transports,
|
|
695
|
-
exitOnError: false
|
|
696
|
-
});
|
|
697
|
-
logger.stream = {
|
|
698
|
-
write: /* @__PURE__ */ __name((message) => logger.info(message.trim()), "write")
|
|
699
|
-
};
|
|
700
|
-
|
|
701
651
|
// src/common/utils/is-cron-valid.ts
|
|
702
652
|
function isValidCron(expr) {
|
|
703
653
|
const parts = expr.trim().split(/\s+/);
|
|
@@ -1164,6 +1114,83 @@ var _FreshDao = class _FreshDao {
|
|
|
1164
1114
|
__name(_FreshDao, "FreshDao");
|
|
1165
1115
|
var FreshDao = _FreshDao;
|
|
1166
1116
|
|
|
1117
|
+
// src/database/subscribers/base-entity-change.subscriber.ts
|
|
1118
|
+
var _BaseEntityChangeSubscriber = class _BaseEntityChangeSubscriber {
|
|
1119
|
+
// ─── TypeORM lifecycle hooks ────────────────────────────────────────
|
|
1120
|
+
afterInsert(event) {
|
|
1121
|
+
var _a;
|
|
1122
|
+
const id = (_a = event.entity) == null ? void 0 : _a.id;
|
|
1123
|
+
if (!id) {
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
if (event.queryRunner.isTransactionActive) {
|
|
1127
|
+
this.addPending(event, id, "created");
|
|
1128
|
+
} else {
|
|
1129
|
+
console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
|
|
1130
|
+
this.sendNotification(id, "created", event.queryRunner.manager);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
afterUpdate(event) {
|
|
1134
|
+
var _a, _b, _c;
|
|
1135
|
+
const id = (_c = (_a = event.entity) == null ? void 0 : _a.id) != null ? _c : (_b = event.databaseEntity) == null ? void 0 : _b.id;
|
|
1136
|
+
if (!id) {
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
if (event.queryRunner.isTransactionActive) {
|
|
1140
|
+
this.addPending(event, id, "updated");
|
|
1141
|
+
} else {
|
|
1142
|
+
console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
|
|
1143
|
+
this.sendNotification(id, "updated", event.queryRunner.manager);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
afterSoftRemove(event) {
|
|
1147
|
+
var _a, _b, _c;
|
|
1148
|
+
const id = (_c = (_a = event.entity) == null ? void 0 : _a.id) != null ? _c : (_b = event.databaseEntity) == null ? void 0 : _b.id;
|
|
1149
|
+
if (!id) {
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
if (event.queryRunner.isTransactionActive) {
|
|
1153
|
+
this.addPending(event, id, "deleted");
|
|
1154
|
+
} else {
|
|
1155
|
+
console.warn(`${this.SUBSCRIBER_NAME} - Notification sent outside transaction for id=${id}`);
|
|
1156
|
+
this.sendNotification(id, "deleted", event.queryRunner.manager);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
async afterTransactionCommit(event) {
|
|
1160
|
+
var _a;
|
|
1161
|
+
const pending = (_a = event.queryRunner.data) == null ? void 0 : _a[this.PENDING_KEY];
|
|
1162
|
+
if (!pending || pending.size === 0) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
event.queryRunner.data[this.PENDING_KEY] = /* @__PURE__ */ new Map();
|
|
1166
|
+
for (const [id, changeEvent] of pending) {
|
|
1167
|
+
await this.sendNotification(id, changeEvent, event.connection.manager);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
// ─── Private helpers ───────────────────────────────────────────────
|
|
1171
|
+
addPending(event, id, changeEvent) {
|
|
1172
|
+
if (!event.queryRunner.data) {
|
|
1173
|
+
event.queryRunner.data = {};
|
|
1174
|
+
}
|
|
1175
|
+
if (!event.queryRunner.data[this.PENDING_KEY]) {
|
|
1176
|
+
event.queryRunner.data[this.PENDING_KEY] = /* @__PURE__ */ new Map();
|
|
1177
|
+
}
|
|
1178
|
+
const existing = event.queryRunner.data[this.PENDING_KEY].get(id);
|
|
1179
|
+
if (!existing || changeEvent === "created" || changeEvent === "deleted") {
|
|
1180
|
+
event.queryRunner.data[this.PENDING_KEY].set(id, changeEvent);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
async sendNotification(id, changeEvent, manager) {
|
|
1184
|
+
try {
|
|
1185
|
+
await this.handleNotification(id, changeEvent, manager);
|
|
1186
|
+
} catch (error) {
|
|
1187
|
+
console.error(`${this.SUBSCRIBER_NAME} - Failed to send notification: ${error instanceof Error ? error.message : error}`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
__name(_BaseEntityChangeSubscriber, "BaseEntityChangeSubscriber");
|
|
1192
|
+
var BaseEntityChangeSubscriber = _BaseEntityChangeSubscriber;
|
|
1193
|
+
|
|
1167
1194
|
// src/common/schema/entities/category.entity.ts
|
|
1168
1195
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
1169
1196
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1663,6 +1690,7 @@ export {
|
|
|
1663
1690
|
AMOUNT_UNIT,
|
|
1664
1691
|
ActionCommandCode,
|
|
1665
1692
|
ApiError,
|
|
1693
|
+
BaseEntityChangeSubscriber,
|
|
1666
1694
|
Category,
|
|
1667
1695
|
DataHelper,
|
|
1668
1696
|
DateUtils,
|
|
@@ -1695,7 +1723,6 @@ export {
|
|
|
1695
1723
|
isNumberInRange,
|
|
1696
1724
|
isObject,
|
|
1697
1725
|
isString,
|
|
1698
|
-
isValidCron
|
|
1699
|
-
logger
|
|
1726
|
+
isValidCron
|
|
1700
1727
|
};
|
|
1701
1728
|
//# sourceMappingURL=index.mjs.map
|