nestjs-telegraf-i18n
Version:
I18n integration for NestJS Telegraf
58 lines (57 loc) • 2.9 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TelegrafI18nContextGetterPatcher = exports.I18nContextGetterPatcher = void 0;
const common_1 = require("@nestjs/common");
const i18nUtils = require("nestjs-i18n/dist/utils/context");
let I18nContextGetterPatcher = class I18nContextGetterPatcher {
constructor(suppressedTypes) {
this.suppressedTypes = suppressedTypes;
this.logger = new common_1.Logger(this.constructor.name);
if (typeof suppressedTypes === "string") {
this._suppressedTypes = new Set([suppressedTypes]);
}
else if (Array.isArray(suppressedTypes)) {
this._suppressedTypes = new Set(suppressedTypes);
}
else {
this._suppressedTypes = suppressedTypes;
}
}
onModuleInit() {
this.logger.log(`Patching nestjs-i18n getContextObject to suppress warnings for context types: "${[...this._suppressedTypes].join('", "')}"`);
if (i18nUtils && i18nUtils.getContextObject) {
const originalGetContextObject = i18nUtils.getContextObject;
i18nUtils.getContextObject = (...args) => {
const contextType = args[1]?.getType?.() ?? "undefined";
if (this._suppressedTypes.has(contextType)) {
return undefined;
}
return originalGetContextObject.apply(this, args);
};
}
}
};
exports.I18nContextGetterPatcher = I18nContextGetterPatcher;
exports.I18nContextGetterPatcher = I18nContextGetterPatcher = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [Object])
], I18nContextGetterPatcher);
let TelegrafI18nContextGetterPatcher = class TelegrafI18nContextGetterPatcher extends I18nContextGetterPatcher {
constructor() {
super("telegraf");
}
};
exports.TelegrafI18nContextGetterPatcher = TelegrafI18nContextGetterPatcher;
exports.TelegrafI18nContextGetterPatcher = TelegrafI18nContextGetterPatcher = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [])
], TelegrafI18nContextGetterPatcher);