@cdaxfx/tools-misc
Advanced tools
Comparing version 1.0.6 to 1.0.7
"use strict"; | ||
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { | ||
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } | ||
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; | ||
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; | ||
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); | ||
var _, done = false; | ||
for (var i = decorators.length - 1; i >= 0; i--) { | ||
var context = {}; | ||
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; | ||
for (var p in contextIn.access) context.access[p] = contextIn.access[p]; | ||
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; | ||
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); | ||
if (kind === "accessor") { | ||
if (result === void 0) continue; | ||
if (result === null || typeof result !== "object") throw new TypeError("Object expected"); | ||
if (_ = accept(result.get)) descriptor.get = _; | ||
if (_ = accept(result.set)) descriptor.set = _; | ||
if (_ = accept(result.init)) initializers.unshift(_); | ||
} | ||
else if (_ = accept(result)) { | ||
if (kind === "field") initializers.unshift(_); | ||
else descriptor[key] = _; | ||
} | ||
} | ||
if (target) Object.defineProperty(target, contextIn.name, descriptor); | ||
done = true; | ||
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 __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
var useValue = arguments.length > 2; | ||
for (var i = 0; i < initializers.length; i++) { | ||
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); | ||
} | ||
return useValue ? value : void 0; | ||
}; | ||
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) { | ||
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; | ||
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -44,46 +12,34 @@ exports.HttpExceptionFilter = void 0; | ||
const common_1 = require("@nestjs/common"); | ||
let HttpExceptionFilter = (() => { | ||
let _classDecorators = [(0, common_1.Catch)(common_1.HttpException, core_1.ValidationError)]; | ||
let _classDescriptor; | ||
let _classExtraInitializers = []; | ||
let _classThis; | ||
var HttpExceptionFilter = _classThis = class { | ||
catch(exception, host) { | ||
var _a; | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse(); | ||
const status = exception instanceof common_1.HttpException ? exception.getStatus() : 400; | ||
let messages = 'An unexpected error occurred'; | ||
if (exception instanceof core_1.ValidationError) { | ||
messages = exception.message; | ||
if ('errors' in exception && Array.isArray(exception.errors)) { | ||
const validationErrors = exception.errors; | ||
response.status(status).json({ | ||
data: validationErrors.map((err) => ({ | ||
property: err.property, | ||
message: err.constraints ? Object.values(err.constraints)[0] : 'Validation error' | ||
})) | ||
}); | ||
} | ||
let HttpExceptionFilter = class HttpExceptionFilter { | ||
catch(exception, host) { | ||
var _a; | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse(); | ||
const status = exception instanceof common_1.HttpException ? exception.getStatus() : 400; | ||
let messages = 'An unexpected error occurred'; | ||
if (exception instanceof core_1.ValidationError) { | ||
messages = exception.message; | ||
if ('errors' in exception && Array.isArray(exception.errors)) { | ||
const validationErrors = exception.errors; | ||
response.status(status).json({ | ||
data: validationErrors.map((err) => ({ | ||
property: err.property, | ||
message: err.constraints ? Object.values(err.constraints)[0] : 'Validation error' | ||
})) | ||
}); | ||
} | ||
else if (exception instanceof common_1.HttpException) { | ||
const exceptionResponse = exception.getResponse(); | ||
messages = typeof exceptionResponse === 'string' ? exceptionResponse : (_a = exceptionResponse['message']) !== null && _a !== void 0 ? _a : exceptionResponse['messages']; | ||
response.status(status).json({ messages }); | ||
} | ||
else { | ||
response.status(status).json({ data: [{ messages }] }); | ||
} | ||
} | ||
}; | ||
__setFunctionName(_classThis, "HttpExceptionFilter"); | ||
(() => { | ||
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; | ||
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); | ||
HttpExceptionFilter = _classThis = _classDescriptor.value; | ||
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); | ||
__runInitializers(_classThis, _classExtraInitializers); | ||
})(); | ||
return HttpExceptionFilter = _classThis; | ||
})(); | ||
else if (exception instanceof common_1.HttpException) { | ||
const exceptionResponse = exception.getResponse(); | ||
messages = typeof exceptionResponse === 'string' ? exceptionResponse : (_a = exceptionResponse['message']) !== null && _a !== void 0 ? _a : exceptionResponse['messages']; | ||
response.status(status).json({ messages }); | ||
} | ||
else { | ||
response.status(status).json({ data: [{ messages }] }); | ||
} | ||
} | ||
}; | ||
exports.HttpExceptionFilter = HttpExceptionFilter; | ||
exports.HttpExceptionFilter = HttpExceptionFilter = __decorate([ | ||
(0, common_1.Catch)(common_1.HttpException, core_1.ValidationError) | ||
], HttpExceptionFilter); |
"use strict"; | ||
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { | ||
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } | ||
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; | ||
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; | ||
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); | ||
var _, done = false; | ||
for (var i = decorators.length - 1; i >= 0; i--) { | ||
var context = {}; | ||
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; | ||
for (var p in contextIn.access) context.access[p] = contextIn.access[p]; | ||
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; | ||
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); | ||
if (kind === "accessor") { | ||
if (result === void 0) continue; | ||
if (result === null || typeof result !== "object") throw new TypeError("Object expected"); | ||
if (_ = accept(result.get)) descriptor.get = _; | ||
if (_ = accept(result.set)) descriptor.set = _; | ||
if (_ = accept(result.init)) initializers.unshift(_); | ||
} | ||
else if (_ = accept(result)) { | ||
if (kind === "field") initializers.unshift(_); | ||
else descriptor[key] = _; | ||
} | ||
} | ||
if (target) Object.defineProperty(target, contextIn.name, descriptor); | ||
done = true; | ||
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 __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
var useValue = arguments.length > 2; | ||
for (var i = 0; i < initializers.length; i++) { | ||
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); | ||
} | ||
return useValue ? value : void 0; | ||
}; | ||
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) { | ||
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; | ||
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -44,27 +12,15 @@ exports.ResponseTransformInterceptor = void 0; | ||
const operators_1 = require("rxjs/operators"); | ||
let ResponseTransformInterceptor = (() => { | ||
let _classDecorators = [(0, common_1.Injectable)()]; | ||
let _classDescriptor; | ||
let _classExtraInitializers = []; | ||
let _classThis; | ||
var ResponseTransformInterceptor = _classThis = class { | ||
intercept(context, next) { | ||
return next.handle().pipe((0, operators_1.map)((data) => { | ||
const pagination = data['pagination'] ? data['pagination'] : undefined; | ||
if (pagination) | ||
delete data['pagination']; | ||
return { data, pagination }; | ||
})); | ||
} | ||
}; | ||
__setFunctionName(_classThis, "ResponseTransformInterceptor"); | ||
(() => { | ||
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; | ||
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); | ||
ResponseTransformInterceptor = _classThis = _classDescriptor.value; | ||
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); | ||
__runInitializers(_classThis, _classExtraInitializers); | ||
})(); | ||
return ResponseTransformInterceptor = _classThis; | ||
})(); | ||
let ResponseTransformInterceptor = class ResponseTransformInterceptor { | ||
intercept(context, next) { | ||
return next.handle().pipe((0, operators_1.map)((data) => { | ||
const pagination = data['pagination'] ? data['pagination'] : undefined; | ||
if (pagination) | ||
delete data['pagination']; | ||
return { data, pagination }; | ||
})); | ||
} | ||
}; | ||
exports.ResponseTransformInterceptor = ResponseTransformInterceptor; | ||
exports.ResponseTransformInterceptor = ResponseTransformInterceptor = __decorate([ | ||
(0, common_1.Injectable)() | ||
], ResponseTransformInterceptor); |
"use strict"; | ||
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { | ||
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } | ||
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; | ||
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; | ||
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); | ||
var _, done = false; | ||
for (var i = decorators.length - 1; i >= 0; i--) { | ||
var context = {}; | ||
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; | ||
for (var p in contextIn.access) context.access[p] = contextIn.access[p]; | ||
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; | ||
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); | ||
if (kind === "accessor") { | ||
if (result === void 0) continue; | ||
if (result === null || typeof result !== "object") throw new TypeError("Object expected"); | ||
if (_ = accept(result.get)) descriptor.get = _; | ||
if (_ = accept(result.set)) descriptor.set = _; | ||
if (_ = accept(result.init)) initializers.unshift(_); | ||
} | ||
else if (_ = accept(result)) { | ||
if (kind === "field") initializers.unshift(_); | ||
else descriptor[key] = _; | ||
} | ||
} | ||
if (target) Object.defineProperty(target, contextIn.name, descriptor); | ||
done = true; | ||
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 __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
var useValue = arguments.length > 2; | ||
for (var i = 0; i < initializers.length; i++) { | ||
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); | ||
} | ||
return useValue ? value : void 0; | ||
}; | ||
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) { | ||
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; | ||
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RequestLoggingMiddleware = void 0; | ||
const common_1 = require("@nestjs/common"); | ||
let RequestLoggingMiddleware = (() => { | ||
let _classDecorators = [(0, common_1.Injectable)()]; | ||
let _classDescriptor; | ||
let _classExtraInitializers = []; | ||
let _classThis; | ||
var RequestLoggingMiddleware = _classThis = class { | ||
constructor() { | ||
this.logger = new common_1.Logger('RequestLoggingMiddleware'); | ||
} | ||
use(req, res, next) { | ||
this.logger.log(`[${req.method}] ${req.baseUrl}`); | ||
next(); | ||
} | ||
}; | ||
__setFunctionName(_classThis, "RequestLoggingMiddleware"); | ||
(() => { | ||
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; | ||
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); | ||
RequestLoggingMiddleware = _classThis = _classDescriptor.value; | ||
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); | ||
__runInitializers(_classThis, _classExtraInitializers); | ||
})(); | ||
return RequestLoggingMiddleware = _classThis; | ||
})(); | ||
let RequestLoggingMiddleware = class RequestLoggingMiddleware { | ||
constructor() { | ||
this.logger = new common_1.Logger('RequestLoggingMiddleware'); | ||
} | ||
use(req, res, next) { | ||
this.logger.log(`[${req.method}] ${req.baseUrl}`); | ||
next(); | ||
} | ||
}; | ||
exports.RequestLoggingMiddleware = RequestLoggingMiddleware; | ||
exports.RequestLoggingMiddleware = RequestLoggingMiddleware = __decorate([ | ||
(0, common_1.Injectable)() | ||
], RequestLoggingMiddleware); |
{ | ||
"name": "@cdaxfx/tools-misc", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
51742
1779