@hestia-earth/data-api 0.0.2-1
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.
- package/.dockerignore +25 -0
- package/.env.test +7 -0
- package/.eslintignore +7 -0
- package/.eslintrc.js +11 -0
- package/.gitlab-ci.yml +125 -0
- package/.mocharc.js +8 -0
- package/.nvrm +1 -0
- package/.nycrc +15 -0
- package/Dockerfile +17 -0
- package/cleanup-docker.sh +4 -0
- package/commitlint.config.js +1 -0
- package/database/index.ts +76 -0
- package/database/migrations/001.do.init.sql +53 -0
- package/database/migrations/002.do.add-aggregated-sites.sql +16 -0
- package/database/migrations/003.do.add-generated-period-cols.sql +7 -0
- package/database/migrations/index.ts +36 -0
- package/database/seed/common.ts +7 -0
- package/database/seed/index.ts +55 -0
- package/database/seed/local/index.ts +28 -0
- package/database/seed/production/index.ts +3 -0
- package/database/seed/staging/index.ts +5 -0
- package/database/seed/test/index.ts +28 -0
- package/dev.ts +3 -0
- package/dist/aggregated-nodes/model/index.d.ts +25 -0
- package/dist/aggregated-nodes/model/index.js +11 -0
- package/dist/models.d.ts +1 -0
- package/dist/models.js +17 -0
- package/docker-compose.yml +42 -0
- package/envs/.master.env +7 -0
- package/envs/.staging.env +7 -0
- package/index.js +3 -0
- package/package.json +105 -0
- package/run-docker.sh +14 -0
- package/run-test.sh +5 -0
- package/scripts/run-lambda.ts +10 -0
- package/scripts/run-migrations.ts +18 -0
- package/scripts/run-resetdb.ts +18 -0
- package/scripts/run-seed.ts +18 -0
- package/serverless.yml +76 -0
- package/src/aggregated-nodes/model/index.ts +37 -0
- package/src/aggregated-nodes/routes/pg-get-filters.ts +44 -0
- package/src/aggregated-nodes/routes/pg-get.ts +50 -0
- package/src/aggregated-nodes/routes.spec.ts +242 -0
- package/src/aggregated-nodes/routes.ts +56 -0
- package/src/aggregated-nodes/services/pg-get-filters.ts +52 -0
- package/src/aggregated-nodes/services/pg-get.ts +77 -0
- package/src/app.spec.ts +34 -0
- package/src/app.ts +59 -0
- package/src/config.ts +21 -0
- package/src/cors.spec.ts +32 -0
- package/src/cors.ts +7 -0
- package/src/errors.spec.ts +114 -0
- package/src/errors.ts +121 -0
- package/src/index.spec.ts +94 -0
- package/src/index.ts +14 -0
- package/src/lambdas/sentry.ts +12 -0
- package/src/lambdas/update-aggregated-nodes/handler.spec.ts +86 -0
- package/src/lambdas/update-aggregated-nodes/handler.ts +141 -0
- package/src/logger.spec.ts +20 -0
- package/src/logger.ts +45 -0
- package/src/maintenance.spec.ts +76 -0
- package/src/maintenance.ts +19 -0
- package/src/models.ts +1 -0
- package/src/routes.spec.ts +33 -0
- package/src/routes.ts +9 -0
- package/src/settings/model/index.ts +21 -0
- package/src/settings/routes/get.spec.ts +33 -0
- package/src/settings/routes/get.ts +3 -0
- package/src/settings/routes/update.spec.ts +33 -0
- package/src/settings/routes/update.ts +5 -0
- package/src/settings/routes.spec.ts +75 -0
- package/src/settings/routes.ts +21 -0
- package/src/settings/services/get.spec.ts +62 -0
- package/src/settings/services/get.ts +18 -0
- package/src/settings/services/update.spec.ts +118 -0
- package/src/settings/services/update.ts +47 -0
- package/src/slack.spec.ts +42 -0
- package/src/slack.ts +17 -0
- package/src/swagger/routes.ts +57 -0
- package/src/types/async-express-errors/index.d.ts +1 -0
- package/src/types/express/index.d.ts +10 -0
- package/src/utils/endpoint-wrapper.spec.ts +80 -0
- package/src/utils/endpoint-wrapper.ts +16 -0
- package/src/utils/middleware.spec.ts +154 -0
- package/src/utils/middleware.ts +33 -0
- package/test/Dockerfile +13 -0
- package/test/docker-compose.yml +40 -0
- package/test/fixtures/aggregated-nodes/get.ts +184 -0
- package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-cycle_pivoted.csv +5 -0
- package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-cycle_pivoted.csv.cycle.json +458 -0
- package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-cycle_pivoted.csv.site.json +182 -0
- package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-impactassessment_pivoted.csv +3 -0
- package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-impactassessment_pivoted.csv.impactAssessment.json +988 -0
- package/test/fixtures/update-aggregated-nodes/abyssinianKaleStraw-impactassessment_pivoted.csv +3 -0
- package/test/fixtures/update-aggregated-nodes/cycle-missing-impactassessment_pivoted.csv +3 -0
- package/test/fixtures/update-aggregated-nodes/tomatoFruit-cycle_pivoted.csv +5 -0
- package/test/fixtures/update-aggregated-nodes/tomatoFruit-cycle_pivoted.csv.cycle.json +584 -0
- package/test/fixtures/update-aggregated-nodes/tomatoFruit-cycle_pivoted.csv.site.json +212 -0
- package/test/fixtures/update-aggregated-nodes/tomatoFruit-impactassessment_pivoted.csv +3 -0
- package/test/fixtures/update-aggregated-nodes/tomatoFruit-impactassessment_pivoted.csv.impactAssessment.json +1002 -0
- package/test/prepare.ts +15 -0
- package/test/utils.ts +33 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.dist.json +14 -0
- package/tsconfig.json +37 -0
- package/tsconfig.lambdas.json +13 -0
package/test/prepare.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import prepare from 'mocha-prepare';
|
|
2
|
+
import * as dotenv from 'dotenv';
|
|
3
|
+
dotenv.config({ path: '.env.test' });
|
|
4
|
+
|
|
5
|
+
let endPool: () => Promise<void>;
|
|
6
|
+
|
|
7
|
+
prepare(
|
|
8
|
+
(done) => {
|
|
9
|
+
({ endPool } = require('../database/'));
|
|
10
|
+
done();
|
|
11
|
+
},
|
|
12
|
+
(done) => {
|
|
13
|
+
endPool().finally(() => done());
|
|
14
|
+
}
|
|
15
|
+
);
|
package/test/utils.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resolve, join } from 'path';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { query } from '../database';
|
|
4
|
+
import { seed } from '../database/seed';
|
|
5
|
+
import * as testSeeds from '../database/seed/test';
|
|
6
|
+
import * as commonSeeds from '../database/seed/common';
|
|
7
|
+
import { runMigrations } from '../database/migrations';
|
|
8
|
+
|
|
9
|
+
export const fixtures = Object.freeze({ ...commonSeeds, ...testSeeds });
|
|
10
|
+
|
|
11
|
+
export const FIXTURES_DIR = resolve(join(__dirname, 'fixtures'));
|
|
12
|
+
|
|
13
|
+
export const loadFixture = (path: string) => readFileSync(join(FIXTURES_DIR, path), 'utf-8');
|
|
14
|
+
|
|
15
|
+
const dbResetQuery = `
|
|
16
|
+
DROP SCHEMA public CASCADE;
|
|
17
|
+
CREATE SCHEMA public;
|
|
18
|
+
GRANT ALL ON SCHEMA public TO postgres;
|
|
19
|
+
GRANT ALL ON SCHEMA public TO public;
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const resetDb = async () => {
|
|
23
|
+
if (!['localhost', 'hestia-data-api-test-db', 'postgres'].includes(process.env.PGHOST || '')) {
|
|
24
|
+
throw new Error(`PGHOST=${process.env.PGHOST}: don't destroy remote DB!`);
|
|
25
|
+
}
|
|
26
|
+
await query(dbResetQuery);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const initDb = async () => {
|
|
30
|
+
await resetDb();
|
|
31
|
+
await runMigrations();
|
|
32
|
+
await seed({ ...commonSeeds, ...testSeeds });
|
|
33
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2017",
|
|
4
|
+
"module": "node16",
|
|
5
|
+
"moduleResolution": "node16",
|
|
6
|
+
"stripInternal": true,
|
|
7
|
+
"emitDecoratorMetadata": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"allowSyntheticDefaultImports": true,
|
|
10
|
+
"removeComments": false,
|
|
11
|
+
"noImplicitAny": false,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"lib": [
|
|
15
|
+
"es2019"
|
|
16
|
+
],
|
|
17
|
+
"baseUrl": ".",
|
|
18
|
+
"typeRoots": [
|
|
19
|
+
"./src/types",
|
|
20
|
+
"./node_modules/@types"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
"include": [
|
|
24
|
+
"dev.ts",
|
|
25
|
+
"index.js",
|
|
26
|
+
"scripts/**/*.ts",
|
|
27
|
+
"database/**/*.ts",
|
|
28
|
+
"test/**/*.ts",
|
|
29
|
+
"src/**/*.ts"
|
|
30
|
+
],
|
|
31
|
+
"exclude": [
|
|
32
|
+
"node_modules"
|
|
33
|
+
],
|
|
34
|
+
"atom": {
|
|
35
|
+
"rewriteTsconfig": false
|
|
36
|
+
}
|
|
37
|
+
}
|