Skip to content
This repository has been archived by the owner on Oct 29, 2020. It is now read-only.

Commit

Permalink
chore: Removed package 'core'
Browse files Browse the repository at this point in the history
- Nest doesn't support composite in TypeScript (Project References)
  nestjs/nest-cli#392
- Moved providers + tests under 'api' project
- Moved Cheerio library dependency (for scraping) under 'api' project
- Duplicated schema (typings) in both 'api' and 'app' projects
  • Loading branch information
gaui committed Aug 16, 2020
1 parent 8a4d885 commit 54ae53b
Show file tree
Hide file tree
Showing 34 changed files with 68 additions and 103 deletions.
4 changes: 4 additions & 0 deletions packages/api/modules.d.ts
@@ -0,0 +1,4 @@
declare module '*.html' {
const content: string;
export default content;
}
10 changes: 4 additions & 6 deletions packages/api/package.json
Expand Up @@ -41,13 +41,10 @@
"reflect-metadata": "0.1.13",
"rimraf": "3.0.2",
"rxjs": "6.5.4",
"apollo-server-express": "2.14.2"
},
"peerDependencies": {
"@gaui/covid19-core": "1.0.0"
"apollo-server-express": "2.14.2",
"cheerio": "1.0.0-rc.3"
},
"devDependencies": {
"@gaui/covid19-core": "*",
"@nestjs/cli": "7.1.1",
"@nestjs/schematics": "7.0.0",
"@nestjs/testing": "7.0.7",
Expand All @@ -67,6 +64,7 @@
"ts-loader": "6.2.2",
"ts-node": "8.8.1",
"tsconfig-paths": "3.9.0",
"typescript": "3.9.3"
"typescript": "3.9.3",
"@types/cheerio": "0.22.18"
}
}
2 changes: 1 addition & 1 deletion packages/api/src/app.module.ts
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { join } from 'path';
import { provider } from '../../core';
import { getData as provider } from './providers';
import { CountryStatsResolver } from './resolvers/stats';

@Module({
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/app.service.ts
@@ -1,5 +1,6 @@
import { Injectable, Inject } from '@nestjs/common';
import { provider, Covid19ProviderCountryStats } from '../../core';
import { Covid19ProviderCountryStats } from './schema';
import { getData as provider } from './providers';

@Injectable()
export class AppService {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/models/CountryStats.ts
@@ -1,5 +1,5 @@
import { Field, Int, ObjectType } from '@nestjs/graphql';
import { Covid19ProviderCountryStats } from '../../../core';
import { Covid19ProviderCountryStats } from '../schema';

@ObjectType({ description: 'Country statistics' })
export class CountryStats implements Covid19ProviderCountryStats {
Expand Down
7 changes: 7 additions & 0 deletions packages/api/src/providers/covid-ext/config.ts
@@ -0,0 +1,7 @@
import { Covid19ProviderConfig } from '../../schema';

const config: Covid19ProviderConfig = {
url: 'https://corona.lmao.ninja/v2/countries/iceland',
};

export default config;
@@ -1,9 +1,9 @@
import config from './config';
import * as R from 'ramda';
import { Covid19Stats } from './types';
import { Covid19ProviderCountryStats } from '../../types/schemas';
import { Covid19ProviderCountryStats } from '../../schema';

const getRemoteData = () => fetch(config.url).then(r => r.json());
const getRemoteData = () => fetch(config.url).then((r) => r.json());

const filter: (data: Covid19Stats) => Covid19ProviderCountryStats = (
data: Covid19Stats
Expand All @@ -15,7 +15,7 @@ const filter: (data: Covid19Stats) => Covid19ProviderCountryStats = (
'todayDeaths',
'recovered',
'active',
'critical'
'critical',
])(data);

export const getData = async (): Promise<Covid19ProviderCountryStats> =>
Expand Down
@@ -1,5 +1,5 @@
import fetchMock from 'fetch-mock';
import { Covid19ProviderConfig } from '../../types/schemas';
import { Covid19ProviderConfig } from '../../schema';

describe('Provider (ext)', () => {
let config: Covid19ProviderConfig;
Expand Down Expand Up @@ -27,7 +27,7 @@ describe('Provider (ext)', () => {
flag:
'https://raw.githubusercontent.com/NovelCOVID/API/master/assets/flags/is.png',
iso3: 'ISL',
iso2: 'IS'
iso2: 'IS',
},
cases: 890,
todayCases: 88,
Expand All @@ -37,7 +37,7 @@ describe('Provider (ext)', () => {
active: 791,
critical: 18,
casesPerOneMillion: 2608,
deathsPerOneMillion: 6
deathsPerOneMillion: 6,
});

// Act
Expand All @@ -51,7 +51,7 @@ describe('Provider (ext)', () => {
todayDeaths: 0,
recovered: 97,
active: 791,
critical: 18
critical: 18,
});
});
});
@@ -1,7 +1,7 @@
import { Covid19ProviderConfig } from '../../types/schemas';
import { Covid19ProviderConfig } from '../../schema';

const config: Covid19ProviderConfig = {
url: 'https://infogram.com/covid-19-tolfraedi-1h1749mm0jyl6zj'
url: 'https://infogram.com/covid-19-tolfraedi-1h1749mm0jyl6zj',
};

export default config;
@@ -1,9 +1,9 @@
import 'isomorphic-unfetch';
import config from './config';
import { Covid19ProviderCountryStats } from '../../types/schemas';
import { Covid19ProviderCountryStats } from '../../schema';
import { parse, filter, labelMapper } from './utils';

const getRemoteData = () => fetch(config.url).then(r => r.text());
const getRemoteData = () => fetch(config.url).then((r) => r.text());

export const getData = async (): Promise<Covid19ProviderCountryStats> =>
getRemoteData()
Expand Down
@@ -1,8 +1,8 @@
import fetchMock from 'fetch-mock';
import {
Covid19ProviderConfig,
Covid19ProviderCountryStats
} from '../../types/schemas';
Covid19ProviderCountryStats,
} from '../../schema';

describe('Provider (is)', () => {
let config: Covid19ProviderConfig;
Expand All @@ -12,7 +12,8 @@ describe('Provider (is)', () => {
beforeAll(async () => {
config = (await import('./config')).default;
getData = (await import('.')).getData;
mockData = (await import('./__mocks__/covid-is.data.html')).default;
mockData = (await import('./__mocks__/covid-is.data.html'))
.default;
});

beforeEach(() => {
Expand All @@ -31,7 +32,7 @@ describe('Provider (is)', () => {
quarantineIn: 5275,
quarantinePost: 11679,
recovered: 396,
samples: 23640
samples: 23640,
});
});
});
@@ -1,11 +1,13 @@
import '@babel/polyfill';
import 'isomorphic-unfetch';
import { getData as covidIs } from './covid-is';
import { getData as covidExt } from './covid-ext';
import * as R from 'ramda';

const providers = [covidExt, covidIs];

const getData = async () => {
const providerData = await Promise.all(providers.map(p => p()));
const providerData = await Promise.all(providers.map((p) => p()));
return R.mergeAll(providerData);
};

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/resolvers/stats.ts
@@ -1,7 +1,8 @@
import { Resolver, Query } from '@nestjs/graphql';
import { Inject } from '@nestjs/common';
import { CountryStats } from '../models/CountryStats';
import { provider, Covid19ProviderCountryStats } from '../../../core';
import { Covid19ProviderCountryStats } from '../schema';
import { getData as provider } from '../providers';

@Resolver(() => CountryStats)
export class CountryStatsResolver {
Expand Down
File renamed without changes.
7 changes: 1 addition & 6 deletions packages/api/tsconfig.json
Expand Up @@ -8,10 +8,5 @@
"module": "commonjs",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"references": [
{
"path": "../core"
}
]
}
}
1 change: 0 additions & 1 deletion packages/app/package.json
Expand Up @@ -27,7 +27,6 @@
"dependencies": {
"@apollo/react-hooks": "3.1.5",
"apollo-boost": "0.4.9",
"@gaui/covid19-core": "*",
"@reduxjs/toolkit": "1.3.6",
"react-redux": "7.2.0",
"react": "16.13.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/redux/slices/stats.ts
@@ -1,6 +1,6 @@
import { createSlice, Dispatch, PayloadAction } from '@reduxjs/toolkit';
import { StatsState } from '../../types/components';
import { Covid19ProviderCountryStats } from '../../../../core';
import { Covid19ProviderCountryStats } from '../../types/schema';
import { gql } from 'apollo-boost';
import { createApolloClient } from '../../utils/createApolloClient';

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/types/components.ts
@@ -1,4 +1,4 @@
import { Covid19ProviderCountryStats } from '../../../core';
import { Covid19ProviderCountryStats } from './schema';

export type StatsState = {
loading: boolean;
Expand Down
18 changes: 18 additions & 0 deletions packages/app/src/types/schema.ts
@@ -0,0 +1,18 @@
export interface Covid19ProviderCountryStats {
active: number;
cases: number;
todayCases: number;
deaths: number;
todayDeaths: number;
recovered: number;
critical: number;
quarantineIn?: number;
quarantinePost?: number;
isolated?: number;
hospitalized?: number;
samples?: number;
}

export interface Covid19ProviderConfig {
url: string;
}
6 changes: 1 addition & 5 deletions packages/app/tsconfig.json
Expand Up @@ -4,9 +4,5 @@
"rootDir": "./src",
"outDir": "./dist"
},
"references": [
{
"path": "../core"
}
]
"references": []
}
8 changes: 0 additions & 8 deletions packages/core/jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/core/jest.setup.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/core/modules.d.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/core/package.json

This file was deleted.

5 changes: 0 additions & 5 deletions packages/core/src/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/core/src/providers/covid-ext/config.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/core/tsconfig.json

This file was deleted.

3 changes: 0 additions & 3 deletions tsconfig.json
Expand Up @@ -3,9 +3,6 @@
"include": [],
"compileOnSave": true,
"references": [
{
"path": "./packages/core"
},
{
"path": "./packages/app"
},
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Expand Up @@ -10172,11 +10172,16 @@ lodash.xorby@^4.7.0:
resolved "https://registry.yarnpkg.com/lodash.xorby/-/lodash.xorby-4.7.0.tgz#9c19a6f9f063a6eb53dd03c1b6871799801463d7"
integrity sha1-nBmm+fBjputT3QPBtocXmYAUY9c=

lodash@4.17.15, lodash@^4.15.0, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.2.1:
lodash@4.17.15, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.2.1:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==

lodash@^4.15.0:
version "4.17.19"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==

log-symbols@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-3.0.0.tgz#f3a08516a5dea893336a7dee14d18a1cfdab77c4"
Expand Down

0 comments on commit 54ae53b

Please sign in to comment.