@nathapp/nestjs-common 1.0.1-rc.16 → 1.0.1-rc.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.
@@ -0,0 +1 @@
1
+ export declare const REFLECTOR = "Reflector";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REFLECTOR = void 0;
4
+ exports.REFLECTOR = 'Reflector';
5
+ //# sourceMappingURL=common-constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-constant.js","sourceRoot":"","sources":["../../lib/constant/common-constant.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { REFLECTOR } from "./common-constant";
2
+ export { REFLECTOR };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REFLECTOR = void 0;
4
+ const common_constant_1 = require("./common-constant");
5
+ Object.defineProperty(exports, "REFLECTOR", { enumerable: true, get: function () { return common_constant_1.REFLECTOR; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/constant/index.ts"],"names":[],"mappings":";;;AAAA,uDAA8C;AAG5C,0FAHO,2BAAS,OAGP"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./decorator";
2
2
  export * from "./exception";
3
3
  export * from "./i18n";
4
+ export * from "./interceptor";
4
5
  export * from "./config";
6
+ export * from "./constant";
5
7
  export * from "./logging";
6
8
  export * from "./serialize";
7
9
  export * from "./middleware";
package/dist/index.js CHANGED
@@ -17,7 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./decorator"), exports);
18
18
  __exportStar(require("./exception"), exports);
19
19
  __exportStar(require("./i18n"), exports);
20
+ __exportStar(require("./interceptor"), exports);
20
21
  __exportStar(require("./config"), exports);
22
+ __exportStar(require("./constant"), exports);
21
23
  __exportStar(require("./logging"), exports);
22
24
  __exportStar(require("./serialize"), exports);
23
25
  __exportStar(require("./middleware"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8CAA4B;AAC5B,yCAAuB;AACvB,2CAAyB;AACzB,4CAA0B;AAC1B,8CAA4B;AAC5B,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8CAA4B;AAC5B,yCAAuB;AACvB,gDAA8B;AAC9B,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,8CAA4B;AAC5B,+CAA6B"}
@@ -0,0 +1,2 @@
1
+ import { SerializableInterceptor } from "./serializable.interceptor";
2
+ export { SerializableInterceptor };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializableInterceptor = void 0;
4
+ const serializable_interceptor_1 = require("./serializable.interceptor");
5
+ Object.defineProperty(exports, "SerializableInterceptor", { enumerable: true, get: function () { return serializable_interceptor_1.SerializableInterceptor; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/interceptor/index.ts"],"names":[],"mappings":";;;AAAA,yEAAqE;AAGnE,wGAHO,kDAAuB,OAGP"}
@@ -0,0 +1,18 @@
1
+ import { CallHandler, ClassSerializerInterceptor, ClassSerializerInterceptorOptions, ExecutionContext, PlainLiteralObject } from "@nestjs/common";
2
+ import { ClassTransformOptions } from "class-transformer";
3
+ import { Observable } from "rxjs";
4
+ import { LocaleString } from "../serialize";
5
+ export declare class SerializableInterceptor extends ClassSerializerInterceptor {
6
+ protected readonly reflector: any;
7
+ protected readonly defaultOptions: ClassSerializerInterceptorOptions;
8
+ private fallbackLanguage;
9
+ constructor(reflector: any, defaultOptions?: ClassSerializerInterceptorOptions);
10
+ intercept(context: ExecutionContext, next: CallHandler<any>): Observable<any>;
11
+ customSerialize(response: PlainLiteralObject | Array<PlainLiteralObject>, options: ClassTransformOptions, lang: string): PlainLiteralObject;
12
+ serializeObject(obj: PlainLiteralObject, options: ClassTransformOptions, lang: string): PlainLiteralObject;
13
+ transformObject(obj: PlainLiteralObject, lang: string): PlainLiteralObject;
14
+ transformLocaleString(obj: LocaleString, lang: string): string;
15
+ isObject: (fn: any) => fn is object;
16
+ isNil: (val: any) => val is null;
17
+ isUndefined: (obj: any) => obj is undefined;
18
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SerializableInterceptor = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const class_transformer_1 = require("class-transformer");
18
+ const rxjs_1 = require("rxjs");
19
+ const serialize_1 = require("../serialize");
20
+ const constant_1 = require("../constant");
21
+ let SerializableInterceptor = class SerializableInterceptor extends common_1.ClassSerializerInterceptor {
22
+ constructor(reflector, defaultOptions = {}) {
23
+ super(reflector, defaultOptions);
24
+ this.reflector = reflector;
25
+ this.defaultOptions = defaultOptions;
26
+ this.fallbackLanguage = "en_US";
27
+ this.isObject = (fn) => !this.isNil(fn) && typeof fn === 'object';
28
+ this.isNil = (val) => this.isUndefined(val) || val === null;
29
+ this.isUndefined = (obj) => typeof obj === 'undefined';
30
+ }
31
+ intercept(context, next) {
32
+ const ctx = context.switchToHttp();
33
+ const lang = ctx.getRequest().i18nLang;
34
+ const contextOptions = this.getContextOptions(context);
35
+ return next
36
+ .handle()
37
+ .pipe((0, rxjs_1.map)((res) => this.customSerialize(res, contextOptions, lang)));
38
+ }
39
+ customSerialize(response, options, lang) {
40
+ if (!this.isObject(response) || response instanceof common_1.StreamableFile) {
41
+ return response;
42
+ }
43
+ return Array.isArray(response)
44
+ ? response.map(item => this.serializeObject(item, options, lang))
45
+ : this.serializeObject(response, options, lang);
46
+ }
47
+ serializeObject(obj, options, lang) {
48
+ const data = obj instanceof serialize_1.Serializable ? (0, class_transformer_1.instanceToInstance)(obj, options) : obj;
49
+ return this.transformToPlain(this.transformObject(data, lang), options);
50
+ }
51
+ transformObject(obj, lang) {
52
+ for (const [key, value] of Object.entries(obj)) {
53
+ if (this.isObject(value)) {
54
+ if (value instanceof serialize_1.LocaleString) {
55
+ obj[key] = this.transformLocaleString(value, lang);
56
+ }
57
+ else {
58
+ obj[key] = this.transformObject(value, lang);
59
+ }
60
+ }
61
+ else if (Array.isArray(obj)) {
62
+ obj[key] = value.map(item => this.transformObject(item, lang));
63
+ }
64
+ }
65
+ return obj;
66
+ }
67
+ transformLocaleString(obj, lang) {
68
+ if (!obj)
69
+ return "";
70
+ if (obj[lang])
71
+ return obj[lang];
72
+ if (obj[this.fallbackLanguage])
73
+ return obj[this.fallbackLanguage];
74
+ return "";
75
+ }
76
+ };
77
+ SerializableInterceptor = __decorate([
78
+ (0, common_1.Injectable)(),
79
+ __param(0, (0, common_1.Inject)(constant_1.REFLECTOR)),
80
+ __param(1, (0, common_1.Optional)()),
81
+ __metadata("design:paramtypes", [Object, Object])
82
+ ], SerializableInterceptor);
83
+ exports.SerializableInterceptor = SerializableInterceptor;
84
+ //# sourceMappingURL=serializable.interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializable.interceptor.js","sourceRoot":"","sources":["../../lib/interceptor/serializable.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAgM;AAChM,yDAA8E;AAE9E,+BAAuC;AACvC,4CAA0D;AAC1D,0CAAwC;AAIjC,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,mCAA0B;IAIrE,YACwC,SAAc,EAEjC,iBAAoD,EAAE;QAEzE,KAAK,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QAJK,cAAS,GAAT,SAAS,CAAK;QAEjC,mBAAc,GAAd,cAAc,CAAwC;QALnE,qBAAgB,GAAG,OAAO,CAAC;QA6DnC,aAAQ,GAAG,CAAC,EAAO,EAAgB,EAAE,CACnC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,OAAO,EAAE,KAAK,QAAQ,CAAC;QAE5C,UAAK,GAAG,CAAC,GAAQ,EAA2B,EAAE,CAC5C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,IAAI,CAAC;QAExC,gBAAW,GAAG,CAAC,GAAQ,EAAoB,EAAE,CAC3C,OAAO,GAAG,KAAK,WAAW,CAAC;IA5D7B,CAAC;IAED,SAAS,CAAC,OAAyB,EAAE,IAAsB;QACzD,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC;QACvC,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACvD,OAAO,IAAI;aACR,MAAM,EAAE;aACR,IAAI,CAAC,IA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;oBACL,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;iBAC9C;aACF;iBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBAC7B,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;aAChE;SACF;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,qBAAqB,CAAC,GAAiB,EAAE,IAAY;QAEnD,IAAI,CAAC,GAAG;YAAE,OAAO,EAAE,CAAC;QAEpB,IAAI,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;QAEhC,IAAI,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC;YAAE,OAAO,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAElE,OAAO,EAAE,CAAC;IACZ,CAAC;CAUF,CAAA;AAvEY,uBAAuB;IADnC,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,oBAAS,CAAC,CAAA;IACjB,WAAA,IAAA,iBAAQ,GAAE,CAAA;;GANF,uBAAuB,CAuEnC;AAvEY,0DAAuB"}
@@ -1,2 +1,3 @@
1
1
  import { EmptyLogger } from "./empty-logger";
2
- export { EmptyLogger };
2
+ import { getLoggerLevel } from "./logger-utils";
3
+ export { EmptyLogger, getLoggerLevel };
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmptyLogger = void 0;
3
+ exports.getLoggerLevel = exports.EmptyLogger = void 0;
4
4
  const empty_logger_1 = require("./empty-logger");
5
5
  Object.defineProperty(exports, "EmptyLogger", { enumerable: true, get: function () { return empty_logger_1.EmptyLogger; } });
6
+ const logger_utils_1 = require("./logger-utils");
7
+ Object.defineProperty(exports, "getLoggerLevel", { enumerable: true, get: function () { return logger_utils_1.getLoggerLevel; } });
6
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/logging/index.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAI3C,4FAJO,0BAAW,OAIP"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/logging/index.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAK3C,4FALO,0BAAW,OAKP;AAJb,iDAAgD;AAK9C,+FALO,6BAAc,OAKP"}
@@ -0,0 +1 @@
1
+ export declare const getLoggerLevel: (debugMode?: boolean) => string[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLoggerLevel = void 0;
4
+ const getLoggerLevel = (debugMode) => {
5
+ const isDebugMode = debugMode || process.env.DEBUG_MODE == "1";
6
+ return isDebugMode ? ['log', 'error', 'warn', 'debug', 'verbose'] :
7
+ ['log', 'error', 'warn'];
8
+ };
9
+ exports.getLoggerLevel = getLoggerLevel;
10
+ //# sourceMappingURL=logger-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-utils.js","sourceRoot":"","sources":["../../lib/logging/logger-utils.ts"],"names":[],"mappings":";;;AACO,MAAM,cAAc,GAAG,CAAC,SAAmB,EAAY,EAAE;IAC9D,MAAM,WAAW,GAAG,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IAE/D,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;QACjE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAC5B,CAAC,CAAA;AALY,QAAA,cAAc,kBAK1B"}
@@ -1,3 +1,4 @@
1
1
  import { JsonResponse } from "./json-response";
2
2
  import { LocaleString } from "./localize.string";
3
- export { LocaleString, JsonResponse };
3
+ import { Serializable } from "./serializable";
4
+ export { LocaleString, JsonResponse, Serializable };
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JsonResponse = exports.LocaleString = void 0;
3
+ exports.Serializable = exports.JsonResponse = exports.LocaleString = void 0;
4
4
  const json_response_1 = require("./json-response");
5
5
  Object.defineProperty(exports, "JsonResponse", { enumerable: true, get: function () { return json_response_1.JsonResponse; } });
6
6
  const localize_string_1 = require("./localize.string");
7
7
  Object.defineProperty(exports, "LocaleString", { enumerable: true, get: function () { return localize_string_1.LocaleString; } });
8
+ const serializable_1 = require("./serializable");
9
+ Object.defineProperty(exports, "Serializable", { enumerable: true, get: function () { return serializable_1.Serializable; } });
8
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/serialize/index.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAGxB,6FAHd,4BAAY,OAGc;AAFnC,uDAAiD;AAExC,6FAFA,8BAAY,OAEA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/serialize/index.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAIxB,6FAJd,4BAAY,OAIc;AAHnC,uDAAiD;AAGxC,6FAHA,8BAAY,OAGA;AAFrB,iDAA8C;AAET,6FAF5B,2BAAY,OAE4B"}
@@ -0,0 +1,2 @@
1
+ export declare abstract class Serializable {
2
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Serializable = void 0;
4
+ class Serializable {
5
+ }
6
+ exports.Serializable = Serializable;
7
+ //# sourceMappingURL=serializable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializable.js","sourceRoot":"","sources":["../../lib/serialize/serializable.ts"],"names":[],"mappings":";;;AAKA,MAAsB,YAAY;CAEjC;AAFD,oCAEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathapp/nestjs-common",
3
- "version": "1.0.1-rc.16",
3
+ "version": "1.0.1-rc.17",
4
4
  "description": "NestJs Common Library",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && tsc -p tsconfig.json",