@infineit-nestjs/services 1.0.46 → 1.0.48

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.
@@ -12,3 +12,4 @@ export * from './services/resource.fetch.service';
12
12
  export * from './services/redis.service';
13
13
  export * from './services/util.service';
14
14
  export * from './services/validator.service';
15
+ export * from './services/decimal.utils.service';
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=require("tslib");e.__exportStar(require("./services/argon2.service"),exports),e.__exportStar(require("./services/data.transformer.service"),exports),e.__exportStar(require("./services/entity.action.service"),exports),e.__exportStar(require("./services/http.client.service"),exports),e.__exportStar(require("./services/kafka.microservice"),exports),e.__exportStar(require("./services/logger.service"),exports),e.__exportStar(require("./services/merge.service"),exports),e.__exportStar(require("./services/message.formatter.service"),exports),e.__exportStar(require("./services/pagination.service"),exports),e.__exportStar(require("./services/prisma.service"),exports),e.__exportStar(require("./services/resource.fetch.service"),exports),e.__exportStar(require("./services/redis.service"),exports),e.__exportStar(require("./services/util.service"),exports),e.__exportStar(require("./services/validator.service"),exports);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=require("tslib");e.__exportStar(require("./services/argon2.service"),exports),e.__exportStar(require("./services/data.transformer.service"),exports),e.__exportStar(require("./services/entity.action.service"),exports),e.__exportStar(require("./services/http.client.service"),exports),e.__exportStar(require("./services/kafka.microservice"),exports),e.__exportStar(require("./services/logger.service"),exports),e.__exportStar(require("./services/merge.service"),exports),e.__exportStar(require("./services/message.formatter.service"),exports),e.__exportStar(require("./services/pagination.service"),exports),e.__exportStar(require("./services/prisma.service"),exports),e.__exportStar(require("./services/resource.fetch.service"),exports),e.__exportStar(require("./services/redis.service"),exports),e.__exportStar(require("./services/util.service"),exports),e.__exportStar(require("./services/validator.service"),exports),e.__exportStar(require("./services/decimal.utils.service"),exports);
@@ -0,0 +1,23 @@
1
+ import Decimal from 'decimal.js';
2
+ export type DecimalLike = Decimal | number | string | null | undefined | {
3
+ d?: string | number | number[];
4
+ value?: string | number;
5
+ };
6
+ export type JsonValue = string | number | boolean | null | Date | JsonValue[] | {
7
+ [key: string]: JsonValue;
8
+ };
9
+ export type DecimalPrecisionMap = Record<string, number>;
10
+ export declare class DecimalUtilsService {
11
+ private readonly precisionMap;
12
+ constructor(precisionMap?: DecimalPrecisionMap);
13
+ private toDecimal;
14
+ private isDecimalObject;
15
+ normalizeValue(key: string, value: DecimalLike): number;
16
+ normalizeRow(row: JsonValue): JsonValue;
17
+ normalize<T extends JsonValue | JsonValue[]>(data: T): T;
18
+ private zeroSafeDecimal;
19
+ add(a: DecimalLike, b: DecimalLike, precision?: number): number;
20
+ subtract(a: DecimalLike, b: DecimalLike, precision?: number): number;
21
+ multiply(a: DecimalLike, b: DecimalLike, precision?: number): number;
22
+ divide(a: DecimalLike, b: DecimalLike, precision?: number): number;
23
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DecimalUtilsService=void 0;const e=require("tslib"),t=require("@nestjs/common"),r=e.__importDefault(require("decimal.js"));let i=class{constructor(e={}){this.precisionMap=e}toDecimal(e){if(e instanceof r.default)return e;if(null==e)return new r.default(0);if("object"==typeof e){const t=e;if("value"in t&&null!=t.value)return new r.default(t.value);if("d"in t){if(Array.isArray(t.d)&&2===t.d.length){const[e,i]=t.d,a=`${e}.${String(i).padStart(String(i).length,"0").replace(/0+$/,"")}`;return new r.default(a)}if("string"==typeof t.d||"number"==typeof t.d)return new r.default(t.d)}return new r.default(0)}return"string"==typeof e||"number"==typeof e?new r.default(e):new r.default(0)}isDecimalObject(e){if(e instanceof r.default)return!0;if("object"==typeof e&&null!==e){return"d"in e||"value"in e}return!1}normalizeValue(e,t){const r=this.toDecimal(t),i=this.precisionMap[e]??2;return r.toDecimalPlaces(i).toNumber()}normalizeRow(e){if(null==e)return e;if("object"!=typeof e)return e;if(e instanceof Date)return e;if(Array.isArray(e))return e.map(e=>this.normalizeRow(e));const t={};for(const r of Object.keys(e)){const i=e[r];null==i?t[r]=i:Array.isArray(i)?t[r]=i.map(e=>this.normalizeRow(e)):i instanceof Date?t[r]=i:this.isDecimalObject(i)||"number"==typeof i||"string"==typeof i?t[r]=this.normalizeValue(r,i):t[r]="object"==typeof i?this.normalizeRow(i):i}return t}normalize(e){return e?Array.isArray(e)?e.map(e=>this.normalizeRow(e)):this.normalizeRow(e):e}zeroSafeDecimal(e){const t=this.toDecimal(e);return t.isNaN()?new r.default(0):t}add(e,t,r=8){return this.zeroSafeDecimal(e).add(this.zeroSafeDecimal(t)).toDecimalPlaces(r).toNumber()}subtract(e,t,r=8){return this.zeroSafeDecimal(e).sub(this.zeroSafeDecimal(t)).toDecimalPlaces(r).toNumber()}multiply(e,t,r=8){return this.zeroSafeDecimal(e).mul(this.zeroSafeDecimal(t)).toDecimalPlaces(r).toNumber()}divide(e,t,i=8){const a=this.zeroSafeDecimal(t).equals(0)?new r.default(1):this.zeroSafeDecimal(t);return this.zeroSafeDecimal(e).div(a).toDecimalPlaces(i).toNumber()}};exports.DecimalUtilsService=i,exports.DecimalUtilsService=i=e.__decorate([(0,t.Injectable)(),e.__metadata("design:paramtypes",[Object])],i);
@@ -12,3 +12,4 @@ export * from './resource.fetch.service';
12
12
  export * from './redis.service';
13
13
  export * from './util.service';
14
14
  export * from './validator.service';
15
+ export * from './decimal.utils.service';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=require("tslib");e.__exportStar(require("./argon2.service"),exports),e.__exportStar(require("./data.transformer.service"),exports),e.__exportStar(require("./entity.action.service"),exports),e.__exportStar(require("./http.client.service"),exports),e.__exportStar(require("./kafka.microservice"),exports),e.__exportStar(require("./logger.service"),exports),e.__exportStar(require("./merge.service"),exports),e.__exportStar(require("./message.formatter.service"),exports),e.__exportStar(require("./pagination.service"),exports),e.__exportStar(require("./prisma.service"),exports),e.__exportStar(require("./resource.fetch.service"),exports),e.__exportStar(require("./redis.service"),exports),e.__exportStar(require("./util.service"),exports),e.__exportStar(require("./validator.service"),exports);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=require("tslib");e.__exportStar(require("./argon2.service"),exports),e.__exportStar(require("./data.transformer.service"),exports),e.__exportStar(require("./entity.action.service"),exports),e.__exportStar(require("./http.client.service"),exports),e.__exportStar(require("./kafka.microservice"),exports),e.__exportStar(require("./logger.service"),exports),e.__exportStar(require("./merge.service"),exports),e.__exportStar(require("./message.formatter.service"),exports),e.__exportStar(require("./pagination.service"),exports),e.__exportStar(require("./prisma.service"),exports),e.__exportStar(require("./resource.fetch.service"),exports),e.__exportStar(require("./redis.service"),exports),e.__exportStar(require("./util.service"),exports),e.__exportStar(require("./validator.service"),exports),e.__exportStar(require("./decimal.utils.service"),exports);
@@ -12,3 +12,4 @@ export * from './services/resource.fetch.service';
12
12
  export * from './services/redis.service';
13
13
  export * from './services/util.service';
14
14
  export * from './services/validator.service';
15
+ export * from './services/decimal.utils.service';
package/dist/es/index.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});const e=require("tslib");e.__exportStar(require("./services/argon2.service"),exports),e.__exportStar(require("./services/data.transformer.service"),exports),e.__exportStar(require("./services/entity.action.service"),exports),e.__exportStar(require("./services/http.client.service"),exports),e.__exportStar(require("./services/kafka.microservice"),exports),e.__exportStar(require("./services/logger.service"),exports),e.__exportStar(require("./services/merge.service"),exports),e.__exportStar(require("./services/message.formatter.service"),exports),e.__exportStar(require("./services/pagination.service"),exports),e.__exportStar(require("./services/prisma.service"),exports),e.__exportStar(require("./services/resource.fetch.service"),exports),e.__exportStar(require("./services/redis.service"),exports),e.__exportStar(require("./services/util.service"),exports),e.__exportStar(require("./services/validator.service"),exports);
1
+ Object.defineProperty(exports,"__esModule",{value:!0});const e=require("tslib");e.__exportStar(require("./services/argon2.service"),exports),e.__exportStar(require("./services/data.transformer.service"),exports),e.__exportStar(require("./services/entity.action.service"),exports),e.__exportStar(require("./services/http.client.service"),exports),e.__exportStar(require("./services/kafka.microservice"),exports),e.__exportStar(require("./services/logger.service"),exports),e.__exportStar(require("./services/merge.service"),exports),e.__exportStar(require("./services/message.formatter.service"),exports),e.__exportStar(require("./services/pagination.service"),exports),e.__exportStar(require("./services/prisma.service"),exports),e.__exportStar(require("./services/resource.fetch.service"),exports),e.__exportStar(require("./services/redis.service"),exports),e.__exportStar(require("./services/util.service"),exports),e.__exportStar(require("./services/validator.service"),exports),e.__exportStar(require("./services/decimal.utils.service"),exports);
@@ -0,0 +1,23 @@
1
+ import Decimal from 'decimal.js';
2
+ export type DecimalLike = Decimal | number | string | null | undefined | {
3
+ d?: string | number | number[];
4
+ value?: string | number;
5
+ };
6
+ export type JsonValue = string | number | boolean | null | Date | JsonValue[] | {
7
+ [key: string]: JsonValue;
8
+ };
9
+ export type DecimalPrecisionMap = Record<string, number>;
10
+ export declare class DecimalUtilsService {
11
+ private readonly precisionMap;
12
+ constructor(precisionMap?: DecimalPrecisionMap);
13
+ private toDecimal;
14
+ private isDecimalObject;
15
+ normalizeValue(key: string, value: DecimalLike): number;
16
+ normalizeRow(row: JsonValue): JsonValue;
17
+ normalize<T extends JsonValue | JsonValue[]>(data: T): T;
18
+ private zeroSafeDecimal;
19
+ add(a: DecimalLike, b: DecimalLike, precision?: number): number;
20
+ subtract(a: DecimalLike, b: DecimalLike, precision?: number): number;
21
+ multiply(a: DecimalLike, b: DecimalLike, precision?: number): number;
22
+ divide(a: DecimalLike, b: DecimalLike, precision?: number): number;
23
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.DecimalUtilsService=void 0;const e=require("tslib"),t=require("@nestjs/common"),r=e.__importDefault(require("decimal.js"));let i=class{constructor(e={}){this.precisionMap=e}toDecimal(e){if(e instanceof r.default)return e;if(null==e)return new r.default(0);if("object"==typeof e){const t=e;if("value"in t&&null!=t.value)return new r.default(t.value);if("d"in t){if(Array.isArray(t.d)&&2===t.d.length){const[e,i]=t.d,a=`${e}.${String(i).padStart(String(i).length,"0").replace(/0+$/,"")}`;return new r.default(a)}if("string"==typeof t.d||"number"==typeof t.d)return new r.default(t.d)}return new r.default(0)}return"string"==typeof e||"number"==typeof e?new r.default(e):new r.default(0)}isDecimalObject(e){if(e instanceof r.default)return!0;if("object"==typeof e&&null!==e){return"d"in e||"value"in e}return!1}normalizeValue(e,t){const r=this.toDecimal(t),i=this.precisionMap[e]??2;return r.toDecimalPlaces(i).toNumber()}normalizeRow(e){if(null==e)return e;if("object"!=typeof e)return e;if(e instanceof Date)return e;if(Array.isArray(e))return e.map(e=>this.normalizeRow(e));const t={};for(const r of Object.keys(e)){const i=e[r];null==i?t[r]=i:Array.isArray(i)?t[r]=i.map(e=>this.normalizeRow(e)):i instanceof Date?t[r]=i:this.isDecimalObject(i)||"number"==typeof i||"string"==typeof i?t[r]=this.normalizeValue(r,i):t[r]="object"==typeof i?this.normalizeRow(i):i}return t}normalize(e){return e?Array.isArray(e)?e.map(e=>this.normalizeRow(e)):this.normalizeRow(e):e}zeroSafeDecimal(e){const t=this.toDecimal(e);return t.isNaN()?new r.default(0):t}add(e,t,r=8){return this.zeroSafeDecimal(e).add(this.zeroSafeDecimal(t)).toDecimalPlaces(r).toNumber()}subtract(e,t,r=8){return this.zeroSafeDecimal(e).sub(this.zeroSafeDecimal(t)).toDecimalPlaces(r).toNumber()}multiply(e,t,r=8){return this.zeroSafeDecimal(e).mul(this.zeroSafeDecimal(t)).toDecimalPlaces(r).toNumber()}divide(e,t,i=8){const a=this.zeroSafeDecimal(t).equals(0)?new r.default(1):this.zeroSafeDecimal(t);return this.zeroSafeDecimal(e).div(a).toDecimalPlaces(i).toNumber()}};exports.DecimalUtilsService=i,exports.DecimalUtilsService=i=e.__decorate([(0,t.Injectable)(),e.__metadata("design:paramtypes",[Object])],i);
@@ -12,3 +12,4 @@ export * from './resource.fetch.service';
12
12
  export * from './redis.service';
13
13
  export * from './util.service';
14
14
  export * from './validator.service';
15
+ export * from './decimal.utils.service';
@@ -1 +1 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});const e=require("tslib");e.__exportStar(require("./argon2.service"),exports),e.__exportStar(require("./data.transformer.service"),exports),e.__exportStar(require("./entity.action.service"),exports),e.__exportStar(require("./http.client.service"),exports),e.__exportStar(require("./kafka.microservice"),exports),e.__exportStar(require("./logger.service"),exports),e.__exportStar(require("./merge.service"),exports),e.__exportStar(require("./message.formatter.service"),exports),e.__exportStar(require("./pagination.service"),exports),e.__exportStar(require("./prisma.service"),exports),e.__exportStar(require("./resource.fetch.service"),exports),e.__exportStar(require("./redis.service"),exports),e.__exportStar(require("./util.service"),exports),e.__exportStar(require("./validator.service"),exports);
1
+ Object.defineProperty(exports,"__esModule",{value:!0});const e=require("tslib");e.__exportStar(require("./argon2.service"),exports),e.__exportStar(require("./data.transformer.service"),exports),e.__exportStar(require("./entity.action.service"),exports),e.__exportStar(require("./http.client.service"),exports),e.__exportStar(require("./kafka.microservice"),exports),e.__exportStar(require("./logger.service"),exports),e.__exportStar(require("./merge.service"),exports),e.__exportStar(require("./message.formatter.service"),exports),e.__exportStar(require("./pagination.service"),exports),e.__exportStar(require("./prisma.service"),exports),e.__exportStar(require("./resource.fetch.service"),exports),e.__exportStar(require("./redis.service"),exports),e.__exportStar(require("./util.service"),exports),e.__exportStar(require("./validator.service"),exports),e.__exportStar(require("./decimal.utils.service"),exports);
@@ -12,3 +12,4 @@ export { IResourceConfig, MissingDataError, ResourceFetchService } from './servi
12
12
  export { RedisService } from './services/redis.service.js';
13
13
  export { UtilsService } from './services/util.service.js';
14
14
  export { ValidatorService } from './services/validator.service.js';
15
+ export { DecimalLike, DecimalPrecisionMap, DecimalUtilsService, JsonValue } from './services/decimal.utils.service.js';
@@ -0,0 +1,27 @@
1
+ import Decimal from 'decimal.js';
2
+
3
+ type DecimalLike = Decimal | number | string | null | undefined | {
4
+ d?: string | number | number[];
5
+ value?: string | number;
6
+ };
7
+ type JsonValue = string | number | boolean | null | Date | JsonValue[] | {
8
+ [key: string]: JsonValue;
9
+ };
10
+ type DecimalPrecisionMap = Record<string, number>;
11
+ declare class DecimalUtilsService {
12
+ private readonly precisionMap;
13
+ constructor(precisionMap?: DecimalPrecisionMap);
14
+ private toDecimal;
15
+ private isDecimalObject;
16
+ normalizeValue(key: string, value: DecimalLike): number;
17
+ normalizeRow(row: JsonValue): JsonValue;
18
+ normalize<T extends JsonValue | JsonValue[]>(data: T): T;
19
+ private zeroSafeDecimal;
20
+ add(a: DecimalLike, b: DecimalLike, precision?: number): number;
21
+ subtract(a: DecimalLike, b: DecimalLike, precision?: number): number;
22
+ multiply(a: DecimalLike, b: DecimalLike, precision?: number): number;
23
+ divide(a: DecimalLike, b: DecimalLike, precision?: number): number;
24
+ }
25
+
26
+ export { DecimalUtilsService };
27
+ export type { DecimalLike, DecimalPrecisionMap, JsonValue };
@@ -12,3 +12,4 @@ export { IResourceConfig, MissingDataError, ResourceFetchService } from './resou
12
12
  export { RedisService } from './redis.service.js';
13
13
  export { UtilsService } from './util.service.js';
14
14
  export { ValidatorService } from './validator.service.js';
15
+ export { DecimalLike, DecimalPrecisionMap, DecimalUtilsService, JsonValue } from './decimal.utils.service.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infineit-nestjs/services",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@infineit-nestjs/types": "1.0.11",
52
- "@infineit-nestjs/utils": "1.0.38",
52
+ "@infineit-nestjs/utils": "1.0.39",
53
53
  "@infineit/winston-logger": "^1.0.30",
54
54
  "@nestjs/axios": "^4.0.0",
55
55
  "@nestjs/microservices": "^11.1.2",
@@ -114,5 +114,5 @@
114
114
  "node": ">=18.0.0",
115
115
  "npm": ">=9.0.0"
116
116
  },
117
- "gitHead": "d8c19cb68f4bbad7494c2ccd92db3a56b6d0f643"
117
+ "gitHead": "f6ab81f8881c0e0e3fb6ce9dfe67c9261a75afe3"
118
118
  }