UNPKG

@tunnel-cast/nestjs

Version:

## About This is a Tunnel-Cast - NestJS integration package, wrap the `cast` application into the `NestJS` building blocks.

44 lines 2.26 kB
"use strict"; 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); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CastPipeFactory = void 0; const common_1 = require("@nestjs/common"); const constants_1 = require("../constants"); const storage_1 = require("../storage"); const cast_value_1 = require("./cast-value"); function CastPipeFactory(model) { let MixinPipe = class MixinPipe { constructor(storage, options) { this.storage = storage; this.options = options; } transform(value, metadata) { var _a; const { extractedValue } = value; let appliedModel = typeof model == "string" ? (_a = this.storage.map.get(model)) === null || _a === void 0 ? void 0 : _a.model : model; appliedModel = appliedModel || metadata.metatype; return cast_value_1.castValue(extractedValue, appliedModel, this.options); } }; MixinPipe = __decorate([ __param(0, common_1.Inject(constants_1.CAST_METADATA_STORAGE)), __param(1, common_1.Optional()), __param(1, common_1.Inject(constants_1.CAST_MODULE_OPTIONS)), __metadata("design:paramtypes", [storage_1.MetadataStorage, Object]) ], MixinPipe); const Pipe = common_1.mixin(MixinPipe); return Pipe; } exports.CastPipeFactory = CastPipeFactory; //# sourceMappingURL=cast.pipe.factory.js.map