@infineit-nestjs/services 1.0.46 → 1.0.47

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;
4
+ value?: string | number;
5
+ };
6
+ export type JsonValue = string | number | boolean | null | 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
+ multiply(a: DecimalLike, b: DecimalLike, precision?: number): number;
20
+ add(a: DecimalLike, b: DecimalLike, precision?: number): number;
21
+ subtract(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){return e instanceof r.default?e:null==e?new r.default(0):"object"==typeof e?"d"in e&&null!=e.d?new r.default(e.d):"value"in e&&null!=e.value?new r.default(e.value):new r.default(0):new r.default(e)}isDecimalObject(e){if(e instanceof r.default)return!0;if("object"==typeof e&&null!==e){const t=e;return"string"==typeof t.d||"number"==typeof t.d||"string"==typeof t.value||"number"==typeof t.value}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(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?Array.isArray(i)?t[r]=i.map(e=>this.normalizeRow(e)):"object"!=typeof i||this.isDecimalObject(i)?t[r]=this.normalizeValue(r,i):t[r]=this.normalizeRow(i):t[r]=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}multiply(e,t,r=8){return this.zeroSafeDecimal(e).mul(this.zeroSafeDecimal(t)).toDecimalPlaces(r).toNumber()}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()}divide(e,t,i=8){const a=this.zeroSafeDecimal(e);let l=this.zeroSafeDecimal(t);return l.equals(0)&&(l=new r.default(1)),a.div(l).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;
4
+ value?: string | number;
5
+ };
6
+ export type JsonValue = string | number | boolean | null | 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
+ multiply(a: DecimalLike, b: DecimalLike, precision?: number): number;
20
+ add(a: DecimalLike, b: DecimalLike, precision?: number): number;
21
+ subtract(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 a=class{constructor(e={}){this.precisionMap=e}toDecimal(e){return e instanceof r.default?e:null==e?new r.default(0):"object"==typeof e?"d"in e&&null!=e.d?new r.default(e.d):"value"in e&&null!=e.value?new r.default(e.value):new r.default(0):new r.default(e)}isDecimalObject(e){if(e instanceof r.default)return!0;if("object"==typeof e&&null!==e){const t=e;return"string"==typeof t.d||"number"==typeof t.d||"string"==typeof t.value||"number"==typeof t.value}return!1}normalizeValue(e,t){const r=this.toDecimal(t),a=this.precisionMap[e]??2;return r.toDecimalPlaces(a).toNumber()}normalizeRow(e){if(null==e)return e;if("object"!=typeof e)return e;if(Array.isArray(e))return e.map(e=>this.normalizeRow(e));const t={};for(const r of Object.keys(e)){const a=e[r];null!=a?Array.isArray(a)?t[r]=a.map(e=>this.normalizeRow(e)):"object"!=typeof a||this.isDecimalObject(a)?t[r]=this.normalizeValue(r,a):t[r]=this.normalizeRow(a):t[r]=a}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}multiply(e,t,r=8){return this.zeroSafeDecimal(e).mul(this.zeroSafeDecimal(t)).toDecimalPlaces(r).toNumber()}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()}divide(e,t,a=8){const i=this.zeroSafeDecimal(e);let l=this.zeroSafeDecimal(t);return l.equals(0)&&(l=new r.default(1)),i.div(l).toDecimalPlaces(a).toNumber()}};exports.DecimalUtilsService=a,exports.DecimalUtilsService=a=e.__decorate([(0,t.Injectable)(),e.__metadata("design:paramtypes",[Object])],a);
@@ -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;
5
+ value?: string | number;
6
+ };
7
+ type JsonValue = string | number | boolean | null | 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
+ multiply(a: DecimalLike, b: DecimalLike, precision?: number): number;
21
+ add(a: DecimalLike, b: DecimalLike, precision?: number): number;
22
+ subtract(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.47",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -114,5 +114,5 @@
114
114
  "node": ">=18.0.0",
115
115
  "npm": ">=9.0.0"
116
116
  },
117
- "gitHead": "d8c19cb68f4bbad7494c2ccd92db3a56b6d0f643"
117
+ "gitHead": "423537e93c19b90c26a760f82ebc6165d487b27d"
118
118
  }