Skip to content

Commit

Permalink
feat: update npm dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscon committed May 12, 2021
1 parent 8a9a3bb commit cdb6b83
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ test.ts
!/bin
.env
package-lock.json
/yalc.lock
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ providing a powerful abstraction layer for geocoding manipulations.

## Installation

$ npm i @goparrot/geocoder reflect-metadata axios class-transformer class-validator
$ npm i @goparrot/geocoder reflect-metadata axios

<sub>⚠️️ Each reflect-metadata installation has its own metadata storage, from which it reads and writes from.
So if you had a project with multiple reflect-metadata packages, it could happen that in one file you write metadata in one reflect-metadata package and in another file you’re trying to retrieve this metadata accidently from the other reflect-metadata package, which of course doesn’t exist there.</sub>
Expand Down Expand Up @@ -137,13 +137,11 @@ axios.interceptors.request.use((request: AxiosRequestConfig) => {
});

// You can log all responses
axios.interceptors.response.use(
(response: AxiosResponse): AxiosResponse => {
logger.debug(`api response ${response.status}`, response.data);
axios.interceptors.response.use((response: AxiosResponse): AxiosResponse => {
logger.debug(`api response ${response.status}`, response.data);

return response;
},
);
return response;
});

/**
* Caching adapter for axios. Store request results in a configurable store to prevent unneeded network requests.
Expand Down Expand Up @@ -298,12 +296,9 @@ geocoder.registerProvider(new GoogleMapsProvider(axios, 'YOUR_API_KEY'));
The `ProviderAggregator`'s API is fluent, meaning you can write:

```typescript
const locations: Location[] = geocoder
.registerProvider(new MyCustomProvider(axios))
.using(MyCustomProvider)
.geocode({
// ...
});
const locations: Location[] = geocoder.registerProvider(new MyCustomProvider(axios)).using(MyCustomProvider).geocode({
// ...
});
```

The `using()` method allows you to choose the `provider` to use by its class name.
Expand Down
13 changes: 10 additions & 3 deletions bin/prepublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import path from 'path';

async function run(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { scripts, devDependencies, husky, files, 'lint-staged': lintStaged, directories, config, ...packageJson } = JSON.parse(
fs.readFileSync(path.join(process.cwd(), 'package.json')).toString(),
);
const {
scripts,
devDependencies,
husky,
files,
'lint-staged': lintStaged,
directories,
config,
...packageJson
} = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json')).toString());

packageJson.main = './cjs/index.js';
packageJson.module = './esm/index.js';
Expand Down
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@
},
"peerDependencies": {
"axios": ">=0.21.1",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
"reflect-metadata": ">=0.1.13"
},
"dependencies": {
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"lodash.isempty": "^4.4.0",
"world-countries": "^4.0.0"
},
Expand All @@ -110,26 +110,24 @@
"@types/lodash.isempty": "^4.4.6",
"@types/mocha": "^8.2.1",
"@types/node": "^14.14.33",
"@types/sinon": "^9.0.11",
"@types/sinon": "^10.0.0",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"axios": "^0.21.1",
"axios-mock-adapter": "^1.19.0",
"chai": "^4.3.3",
"chai-as-promised": "^7.1.1",
"class-transformer": "^0.3.1",
"class-validator": "^0.12.2",
"commitizen": "^4.2.3",
"conventional-github-releaser": "^3.1.5",
"dotenv": "^8.2.0",
"dotenv": "^9.0.2",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^5.1.3",
"lint-staged": "^10.5.4",
"husky": "^6.0.0",
"lint-staged": "^11.0.0",
"mocha": "^8.3.1",
"mocha-junit-reporter": "^2.0.0",
"npm-run-all": "^4.1.5",
Expand All @@ -142,7 +140,7 @@
"remark-lint-emphasis-marker": "^2.0.1",
"remark-lint-strong-marker": "^2.0.1",
"rimraf": "^3.0.2",
"sinon": "^9.2.4",
"sinon": "^10.0.0",
"source-map-support": "^0.5.19",
"standard-version": "^9.1.1",
"supertest": "^6.1.3",
Expand Down
2 changes: 1 addition & 1 deletion src/command/abstract-location.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AbstractCommand } from './abstract.command';
export abstract class AbstractLocationCommand<
GeocoderQueryType extends QueryInterface = any,
ProviderRequestType = any,
ProviderResponseType = any
ProviderResponseType = any,
> extends AbstractCommand<GeocoderQueryType, Location, AbstractLocationTransformer, ProviderRequestType, ProviderResponseType> {
protected async parseResponse(_response: AxiosResponse<ProviderResponseType>, _query: GeocoderQueryType): Promise<AbstractLocationTransformer[]> {
throw new Error('AbstractLocationCommand.parseResponse: not implemented');
Expand Down
2 changes: 1 addition & 1 deletion src/command/abstract-suggest.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AbstractCommand } from './abstract.command';
export abstract class AbstractSuggestCommand<
GeocoderQueryType extends QueryInterface = any,
ProviderRequestType = any,
ProviderResponseType = any
ProviderResponseType = any,
> extends AbstractCommand<GeocoderQueryType, Suggestion, AbstractSuggestionTransformer, ProviderRequestType, ProviderResponseType> {
protected async parseResponse(_response: AxiosResponse<ProviderResponseType>, _query: GeocoderQueryType): Promise<AbstractSuggestionTransformer[]> {
throw new Error('AbstractSuggestCommand.parseResponse: not implemented');
Expand Down
14 changes: 6 additions & 8 deletions src/command/abstract.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export abstract class AbstractCommand<
GeocoderResponseType = any,
GeocoderTransformerType extends AbstractTransformer = any,
ProviderRequestType = any,
ProviderResponseType = any
ProviderResponseType = any,
> extends LoggableMixin(Function) {
['constructor']: Pick<typeof AbstractCommand, keyof typeof AbstractCommand> & { name: string } & LoggableInterface;

Expand Down Expand Up @@ -117,13 +117,11 @@ export abstract class AbstractCommand<
const transformers: GeocoderTransformerType[] = await this.parseResponse(response, query);

return Promise.all<GeocoderResponseType>(
transformers.map(
async (transformer: GeocoderTransformerType): Promise<GeocoderResponseType> => {
return transformer.transform({
groups: query.withRaw ? ['raw'] : undefined,
});
},
),
transformers.map(async (transformer: GeocoderTransformerType): Promise<GeocoderResponseType> => {
return transformer.transform({
groups: query.withRaw ? ['raw'] : undefined,
});
}),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/transformer/abstract-suggestion-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AbstractTransformer } from './abstract-transformer';

export abstract class AbstractSuggestionTransformer<
HttpProviderClass extends AbstractHttpProvider = any,
ProviderRawEntryType = any
ProviderRawEntryType = any,
> extends AbstractTransformer<HttpProviderClass, ProviderRawEntryType> {
abstract getFormattedAddress(): Promise<SuggestionInterface['formattedAddress']>;
abstract getPlaceId(): Promise<SuggestionInterface['placeId']>;
Expand Down
2 changes: 1 addition & 1 deletion src/util/transformer/to-boolean.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Transform } from 'class-transformer';

export function ToBoolean(): (target: any, key: string) => void {
return Transform((value: any) => value === 'true' || value === true || value === 1 || value === '1');
return Transform(({ value }) => value === 'true' || value === true || value === 1 || value === '1');
}
6 changes: 3 additions & 3 deletions src/util/world-country-state/world-country-state-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ export class WorldCountryStateQuery implements WorldCountryStateQueryInterface {
@IsString()
@MinLength(2)
@MaxLength(2)
@Transform((v: string) => v.trim())
@Transform(({ value }) => value?.trim())
@Expose()
countryCode: string;

@IsOptional()
@IsString()
@MinLength(2)
@MaxLength(100)
@Transform((v: string) => (v ? v.toString().trim().toUpperCase() : undefined))
@Transform(({ value }) => value?.toString().trim().toUpperCase())
@Expose()
stateCode?: string;

@IsString()
@IsOptional()
@MinLength(1)
@Transform((v: string) => (v ? v.trim() : undefined))
@Transform(({ value }) => value?.trim())
@Expose()
name?: string;
}
2 changes: 1 addition & 1 deletion src/util/world-country-state/world-country-state-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class WorldCountryStateUtil {

static async find(_query: WorldCountryStateQueryInterface): Promise<WorldCountryState | undefined> {
const query: WorldCountryStateQuery = plainToClass<WorldCountryStateQuery, WorldCountryStateQueryInterface>(WorldCountryStateQuery, _query);
const keys: Array<keyof WorldCountryStateQuery> = (Object.keys(query) as unknown) as Array<keyof WorldCountryStateQuery>;
const keys: Array<keyof WorldCountryStateQuery> = Object.keys(query) as unknown as Array<keyof WorldCountryStateQuery>;

// clear undefined/empty values
for (const key of keys) {
Expand Down
6 changes: 3 additions & 3 deletions src/util/world-country-state/world-country-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ export class WorldCountryState implements WorldCountryStateInterface {
@IsString()
@MinLength(2)
@MaxLength(2)
@Transform((v: string) => v.toString().trim().toUpperCase())
@Transform(({ value }) => value?.toString().trim().toUpperCase())
@Expose()
countryCode: string;

@IsOptional()
@IsString()
@MinLength(2)
@MaxLength(100)
@Transform((v: string) => v.toString().trim().toUpperCase())
@Transform(({ value }) => value?.toString().trim().toUpperCase())
@Expose()
stateCode: string;

@IsOptional()
@IsString()
@Transform((v: string) => v.toString().trim())
@Transform(({ value }) => value?.toString().trim())
@Expose()
name: string;
}
8 changes: 4 additions & 4 deletions src/util/world-country/world-country-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ export class WorldCountryQuery implements WorldCountryQueryInterface {
@IsString()
@IsOptional()
@MinLength(1)
@Transform((v: string) => (v ? v.trim() : undefined))
@Transform(({ value }) => value?.trim())
@Expose()
name?: string;

@IsOptional()
@IsString()
@MinLength(2)
@MaxLength(2)
@Transform((v: string) => (v ? v.toString().trim().toUpperCase() : undefined))
@Transform(({ value }) => value?.toString().trim().toUpperCase())
@Expose()
cca2?: string;

@IsOptional()
@IsString()
@MinLength(3)
@MaxLength(3)
@Transform((v: string) => (v ? v.toString().trim().toUpperCase() : undefined))
@Transform(({ value }) => value?.toString().trim().toUpperCase())
@Expose()
cca3?: string;

Expand All @@ -32,7 +32,7 @@ export class WorldCountryQuery implements WorldCountryQueryInterface {
@IsNumberString()
@MinLength(3)
@MaxLength(3)
@Transform((v: number | string) => (v ? (+v).toString().trim().padStart(3, '0') : undefined))
@Transform(({ value }) => (value ? (+value).toString().trim().padStart(3, '0') : undefined))
@Expose()
ccn3?: string | number;
}
6 changes: 3 additions & 3 deletions src/util/world-country/world-country-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class WorldCountryUtil {
* Returns the result if at least one of the fields matches
*/
private static match(country: WorldCountry, filters: WorldCountryQuery): boolean {
const keys: Array<keyof WorldCountryQuery> = (Object.keys(filters) as unknown) as Array<keyof WorldCountryQuery>;
const keys: Array<keyof WorldCountryQuery> = Object.keys(filters) as unknown as Array<keyof WorldCountryQuery>;

for (const key of keys) {
const searchValue: unknown = filters[key]?.toString().toLowerCase();
Expand All @@ -31,7 +31,7 @@ export class WorldCountryUtil {

static async find(_query: WorldCountryQueryInterface): Promise<WorldCountry | undefined> {
const query: WorldCountryQuery = plainToClass<WorldCountryQuery, WorldCountryQueryInterface>(WorldCountryQuery, _query);
const keys: Array<keyof WorldCountryQueryInterface> = (Object.keys(query) as unknown) as Array<keyof WorldCountryQueryInterface>;
const keys: Array<keyof WorldCountryQueryInterface> = Object.keys(query) as unknown as Array<keyof WorldCountryQueryInterface>;

// clear undefined/empty values
for (const key of keys) {
Expand All @@ -50,7 +50,7 @@ export class WorldCountryUtil {
return;
}

const countryData: Country | undefined = ((countries as unknown) as Countries).find((plainCountry: Country) => {
const countryData: Country | undefined = (countries as unknown as Countries).find((plainCountry: Country) => {
const country: WorldCountry = plainToClass<WorldCountry, Country>(WorldCountry, plainCountry);

return WorldCountryUtil.match(country, query);
Expand Down

0 comments on commit cdb6b83

Please sign in to comment.