diff --git a/package.json b/package.json index 670c139..354c34d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "*.{ts,tsx,json,js,jsx}": [ "npm run format:base" ], - "*.{md}": [ + "*.md": [ "npm run prettier:base" ] }, @@ -96,21 +96,21 @@ }, "dependencies": { "@types/heremaps": "^3.1.5", - "class-transformer": "^0.4.0", - "class-validator": "^0.13.1", + "class-transformer": "^0.5.1", + "class-validator": "^0.13.2", "lodash.isempty": "^4.4.0", "world-countries": "^4.0.0" }, "devDependencies": { - "@commitlint/cli": "^14.1.0", - "@commitlint/config-conventional": "^14.1.0", - "@commitlint/travis-cli": "^14.1.0", + "@commitlint/cli": "^15.0.0", + "@commitlint/config-conventional": "^15.0.0", + "@commitlint/travis-cli": "^15.0.0", "@goparrot/eslint-config": "^1.0.1", "@types/chai": "^4.2.15", "@types/chai-as-promised": "^7.1.3", "@types/lodash.isempty": "^4.4.6", "@types/mocha": "^9.0.0", - "@types/node": "^16.11.7", + "@types/node": "^16.11.10", "@types/semver": "^7.3.9", "@types/sinon": "^10.0.6", "@types/supertest": "^2.0.10", @@ -122,14 +122,14 @@ "conventional-github-releaser": "^3.1.5", "dotenv": "^10.0.0", "husky": "^7.0.4", - "lint-staged": "^12.0.2", + "lint-staged": "^12.1.2", "mocha": "^9.1.3", "mocha-junit-reporter": "^2.0.0", "npm-run-all": "^4.1.5", "nyc": "^15.1.0", - "prettier": "^2.2.1", + "prettier": "^2.5.0", "reflect-metadata": ">=0.1.13", - "remark-cli": "^10.0.0", + "remark-cli": "^10.0.1", "remark-frontmatter": "^4.0.1", "remark-github": "^11.2.2", "remark-lint-emphasis-marker": "^3.1.0", @@ -137,11 +137,11 @@ "rimraf": "^3.0.2", "semver": "^7.3.5", "sinon": "^12.0.1", - "source-map-support": "^0.5.19", + "source-map-support": "^0.5.21", "standard-version": "^9.3.2", "supertest": "^6.1.3", "ts-node": "^10.4.0", - "tsconfig-paths": "^3.9.0", - "typescript": "^4.4.4" + "tsconfig-paths": "^3.12.0", + "typescript": "^4.5.2" } } diff --git a/src/command/abstract.command.ts b/src/command/abstract.command.ts index fc4b913..f3ac09f 100644 --- a/src/command/abstract.command.ts +++ b/src/command/abstract.command.ts @@ -1,4 +1,4 @@ -import { plainToClass } from 'class-transformer'; +import { plainToInstance } from 'class-transformer'; import { validateOrReject } from 'class-validator'; import isEmpty from 'lodash.isempty'; import type { AxiosInstance, AxiosResponse } from 'axios'; @@ -67,7 +67,7 @@ export abstract class AbstractCommand< } async execute(_query: GeocoderQueryType): Promise { - const query: GeocoderQueryType = plainToClass(this.constructor.queryClass(), _query); + const query: GeocoderQueryType = plainToInstance(this.constructor.queryClass(), _query); try { await validateOrReject(query, { diff --git a/src/model/distance.ts b/src/model/distance.ts index 0a5722f..26b283e 100644 --- a/src/model/distance.ts +++ b/src/model/distance.ts @@ -1,4 +1,4 @@ -import { classToPlain, Exclude, Expose } from 'class-transformer'; +import { instanceToPlain, Exclude, Expose } from 'class-transformer'; import type { ClassTransformOptions } from 'class-transformer'; import type { DistanceDetailsInterface } from '../interface'; @@ -17,6 +17,6 @@ export class Distance implements DistanceDetailsInte raw?: ProviderRawEntryType; toObject(options?: ClassTransformOptions): DistanceDetailsInterface { - return classToPlain>(this, options) as DistanceDetailsInterface; + return instanceToPlain>(this, options) as DistanceDetailsInterface; } } diff --git a/src/model/location.ts b/src/model/location.ts index a38f7a1..655a87c 100644 --- a/src/model/location.ts +++ b/src/model/location.ts @@ -1,4 +1,4 @@ -import { classToPlain, Exclude, Expose } from 'class-transformer'; +import { instanceToPlain, Exclude, Expose } from 'class-transformer'; import type { ClassTransformOptions } from 'class-transformer'; import type { LocationInterface } from '../interface'; @@ -72,6 +72,6 @@ export class Location implements LocationInterface

{ - return classToPlain>(this, options) as LocationInterface; + return instanceToPlain>(this, options) as LocationInterface; } } diff --git a/src/model/suggestion.ts b/src/model/suggestion.ts index c6aa061..675e713 100644 --- a/src/model/suggestion.ts +++ b/src/model/suggestion.ts @@ -1,4 +1,4 @@ -import { classToPlain, Exclude, Expose } from 'class-transformer'; +import { instanceToPlain, Exclude, Expose } from 'class-transformer'; import type { ClassTransformOptions } from 'class-transformer'; import type { SuggestionInterface } from '../interface'; @@ -17,6 +17,6 @@ export class Suggestion implements SuggestionInterfa raw?: ProviderRawEntryType; toObject(options?: ClassTransformOptions): SuggestionInterface { - return classToPlain>(this, options) as SuggestionInterface; + return instanceToPlain>(this, options) as SuggestionInterface; } } diff --git a/src/transformer/abstract-distance-transformer.ts b/src/transformer/abstract-distance-transformer.ts index 96f69bf..cd80764 100644 --- a/src/transformer/abstract-distance-transformer.ts +++ b/src/transformer/abstract-distance-transformer.ts @@ -1,4 +1,4 @@ -import { plainToClass } from 'class-transformer'; +import { plainToInstance } from 'class-transformer'; import type { ClassTransformOptions } from 'class-transformer'; import { Distance } from '../model/distance'; import type { DistanceDetailsInterface } from '../interface'; @@ -20,6 +20,6 @@ export abstract class AbstractDistanceTransformer, DistanceDetailsInterface>(Distance, distance, options); + return plainToInstance, DistanceDetailsInterface>(Distance, distance, options); } } diff --git a/src/transformer/abstract-location-transformer.ts b/src/transformer/abstract-location-transformer.ts index 64edbfa..054f38c 100644 --- a/src/transformer/abstract-location-transformer.ts +++ b/src/transformer/abstract-location-transformer.ts @@ -1,4 +1,4 @@ -import { plainToClass } from 'class-transformer'; +import { plainToInstance } from 'class-transformer'; import type { ClassTransformOptions } from 'class-transformer'; import { WorldCountryUtil } from '../util/world-country'; import { Location } from '../model'; @@ -46,7 +46,7 @@ export abstract class AbstractLocationTransformer, LocationInterface>(Location, location, options); + return plainToInstance, LocationInterface>(Location, location, options); } protected async getWorldCountry(query: WorldCountryQueryInterface): Promise { diff --git a/src/transformer/abstract-suggestion-transformer.ts b/src/transformer/abstract-suggestion-transformer.ts index a4ce7e1..9da2e45 100644 --- a/src/transformer/abstract-suggestion-transformer.ts +++ b/src/transformer/abstract-suggestion-transformer.ts @@ -1,4 +1,4 @@ -import { plainToClass } from 'class-transformer'; +import { plainToInstance } from 'class-transformer'; import type { ClassTransformOptions } from 'class-transformer'; import { Suggestion } from '../model'; import type { SuggestionInterface } from '../interface'; @@ -20,6 +20,6 @@ export abstract class AbstractSuggestionTransformer< suggestion.placeId = await this.getPlaceId(); suggestion.raw = this.raw; - return plainToClass, SuggestionInterface>(Suggestion, suggestion, options); + return plainToInstance, SuggestionInterface>(Suggestion, suggestion, options); } } diff --git a/src/util/world-country-state/world-country-state-util.ts b/src/util/world-country-state/world-country-state-util.ts index e91e3b7..4e82782 100644 --- a/src/util/world-country-state/world-country-state-util.ts +++ b/src/util/world-country-state/world-country-state-util.ts @@ -1,4 +1,4 @@ -import { plainToClass } from 'class-transformer'; +import { plainToInstance } from 'class-transformer'; import { validateOrReject } from 'class-validator'; import countryStates from '../../data/country-states/country-states.json'; import { WorldCountryState } from './world-country-state'; @@ -23,7 +23,7 @@ export class WorldCountryStateUtil { } static async find(_query: WorldCountryStateQueryInterface): Promise { - const query: WorldCountryStateQuery = plainToClass(WorldCountryStateQuery, _query); + const query: WorldCountryStateQuery = plainToInstance(WorldCountryStateQuery, _query); const keys: Array = Object.keys(query) as unknown as Array; // clear undefined/empty values @@ -45,7 +45,7 @@ export class WorldCountryStateUtil { const stateData: WorldCountryStateInterface | undefined = (countryStates as WorldCountryStateInterface[]).find( (plainState: WorldCountryStateInterface) => { - const state: WorldCountryState = plainToClass(WorldCountryState, plainState); + const state: WorldCountryState = plainToInstance(WorldCountryState, plainState); return WorldCountryStateUtil.match(state, query); }, @@ -55,6 +55,6 @@ export class WorldCountryStateUtil { return; } - return plainToClass(WorldCountryState, stateData); + return plainToInstance(WorldCountryState, stateData); } } diff --git a/src/util/world-country/world-country-util.ts b/src/util/world-country/world-country-util.ts index d9b00f0..4ae9f09 100644 --- a/src/util/world-country/world-country-util.ts +++ b/src/util/world-country/world-country-util.ts @@ -1,4 +1,4 @@ -import { plainToClass } from 'class-transformer'; +import { plainToInstance } from 'class-transformer'; import { validateOrReject } from 'class-validator'; import countries from 'world-countries/dist/countries-unescaped.json'; import type { Countries, Country } from 'world-countries'; @@ -30,7 +30,7 @@ export class WorldCountryUtil { } static async find(_query: WorldCountryQueryInterface): Promise { - const query: WorldCountryQuery = plainToClass(WorldCountryQuery, _query); + const query: WorldCountryQuery = plainToInstance(WorldCountryQuery, _query); const keys: Array = Object.keys(query) as unknown as Array; // clear undefined/empty values @@ -51,7 +51,7 @@ export class WorldCountryUtil { } const countryData: Country | undefined = (countries as unknown as Countries).find((plainCountry: Country) => { - const country: WorldCountry = plainToClass(WorldCountry, plainCountry); + const country: WorldCountry = plainToInstance(WorldCountry, plainCountry); return WorldCountryUtil.match(country, query); }); @@ -60,6 +60,6 @@ export class WorldCountryUtil { return; } - return plainToClass(WorldCountry, countryData); + return plainToInstance(WorldCountry, countryData); } } diff --git a/test/unit/model/location.model.spec.ts b/test/unit/model/location.model.spec.ts index bfbdeac..4296cf6 100644 --- a/test/unit/model/location.model.spec.ts +++ b/test/unit/model/location.model.spec.ts @@ -1,4 +1,4 @@ -import { classToPlain, plainToClass } from 'class-transformer'; +import { instanceToPlain, plainToClass } from 'class-transformer'; import { Location } from '../../../src/model'; import { locationFixture } from '../../fixture/model/address.fixture'; import type { LocationInterface } from '../../../src/interface'; @@ -72,19 +72,19 @@ describe('Location (unit)', () => { }); }); - describe('classToPlain', () => { + describe('instanceToPlain', () => { it('should use #generateFormattedAddress if formattedAddress is empty', async () => { delete location.formattedAddress; delete location.postalCode; delete location.country; - const addressPlainObject: LocationInterface = classToPlain(location) as LocationInterface; + const addressPlainObject: LocationInterface = instanceToPlain(location) as LocationInterface; return (addressPlainObject.formattedAddress as string).should.be.deep.eq('1158 E 89th St, Chicago, IL, US'); }); it('should not generate street property', async () => { - const addressPlainObject: any = classToPlain(location) as LocationInterface; + const addressPlainObject: any = instanceToPlain(location) as LocationInterface; return (typeof addressPlainObject.street).should.be.eq('undefined'); });