@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.
Files changed (106) hide show
  1. package/.dockerignore +25 -0
  2. package/.env.test +7 -0
  3. package/.eslintignore +7 -0
  4. package/.eslintrc.js +11 -0
  5. package/.gitlab-ci.yml +125 -0
  6. package/.mocharc.js +8 -0
  7. package/.nvrm +1 -0
  8. package/.nycrc +15 -0
  9. package/Dockerfile +17 -0
  10. package/cleanup-docker.sh +4 -0
  11. package/commitlint.config.js +1 -0
  12. package/database/index.ts +76 -0
  13. package/database/migrations/001.do.init.sql +53 -0
  14. package/database/migrations/002.do.add-aggregated-sites.sql +16 -0
  15. package/database/migrations/003.do.add-generated-period-cols.sql +7 -0
  16. package/database/migrations/index.ts +36 -0
  17. package/database/seed/common.ts +7 -0
  18. package/database/seed/index.ts +55 -0
  19. package/database/seed/local/index.ts +28 -0
  20. package/database/seed/production/index.ts +3 -0
  21. package/database/seed/staging/index.ts +5 -0
  22. package/database/seed/test/index.ts +28 -0
  23. package/dev.ts +3 -0
  24. package/dist/aggregated-nodes/model/index.d.ts +25 -0
  25. package/dist/aggregated-nodes/model/index.js +11 -0
  26. package/dist/models.d.ts +1 -0
  27. package/dist/models.js +17 -0
  28. package/docker-compose.yml +42 -0
  29. package/envs/.master.env +7 -0
  30. package/envs/.staging.env +7 -0
  31. package/index.js +3 -0
  32. package/package.json +105 -0
  33. package/run-docker.sh +14 -0
  34. package/run-test.sh +5 -0
  35. package/scripts/run-lambda.ts +10 -0
  36. package/scripts/run-migrations.ts +18 -0
  37. package/scripts/run-resetdb.ts +18 -0
  38. package/scripts/run-seed.ts +18 -0
  39. package/serverless.yml +76 -0
  40. package/src/aggregated-nodes/model/index.ts +37 -0
  41. package/src/aggregated-nodes/routes/pg-get-filters.ts +44 -0
  42. package/src/aggregated-nodes/routes/pg-get.ts +50 -0
  43. package/src/aggregated-nodes/routes.spec.ts +242 -0
  44. package/src/aggregated-nodes/routes.ts +56 -0
  45. package/src/aggregated-nodes/services/pg-get-filters.ts +52 -0
  46. package/src/aggregated-nodes/services/pg-get.ts +77 -0
  47. package/src/app.spec.ts +34 -0
  48. package/src/app.ts +59 -0
  49. package/src/config.ts +21 -0
  50. package/src/cors.spec.ts +32 -0
  51. package/src/cors.ts +7 -0
  52. package/src/errors.spec.ts +114 -0
  53. package/src/errors.ts +121 -0
  54. package/src/index.spec.ts +94 -0
  55. package/src/index.ts +14 -0
  56. package/src/lambdas/sentry.ts +12 -0
  57. package/src/lambdas/update-aggregated-nodes/handler.spec.ts +86 -0
  58. package/src/lambdas/update-aggregated-nodes/handler.ts +141 -0
  59. package/src/logger.spec.ts +20 -0
  60. package/src/logger.ts +45 -0
  61. package/src/maintenance.spec.ts +76 -0
  62. package/src/maintenance.ts +19 -0
  63. package/src/models.ts +1 -0
  64. package/src/routes.spec.ts +33 -0
  65. package/src/routes.ts +9 -0
  66. package/src/settings/model/index.ts +21 -0
  67. package/src/settings/routes/get.spec.ts +33 -0
  68. package/src/settings/routes/get.ts +3 -0
  69. package/src/settings/routes/update.spec.ts +33 -0
  70. package/src/settings/routes/update.ts +5 -0
  71. package/src/settings/routes.spec.ts +75 -0
  72. package/src/settings/routes.ts +21 -0
  73. package/src/settings/services/get.spec.ts +62 -0
  74. package/src/settings/services/get.ts +18 -0
  75. package/src/settings/services/update.spec.ts +118 -0
  76. package/src/settings/services/update.ts +47 -0
  77. package/src/slack.spec.ts +42 -0
  78. package/src/slack.ts +17 -0
  79. package/src/swagger/routes.ts +57 -0
  80. package/src/types/async-express-errors/index.d.ts +1 -0
  81. package/src/types/express/index.d.ts +10 -0
  82. package/src/utils/endpoint-wrapper.spec.ts +80 -0
  83. package/src/utils/endpoint-wrapper.ts +16 -0
  84. package/src/utils/middleware.spec.ts +154 -0
  85. package/src/utils/middleware.ts +33 -0
  86. package/test/Dockerfile +13 -0
  87. package/test/docker-compose.yml +40 -0
  88. package/test/fixtures/aggregated-nodes/get.ts +184 -0
  89. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-cycle_pivoted.csv +5 -0
  90. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-cycle_pivoted.csv.cycle.json +458 -0
  91. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-cycle_pivoted.csv.site.json +182 -0
  92. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-impactassessment_pivoted.csv +3 -0
  93. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-impactassessment_pivoted.csv.impactAssessment.json +988 -0
  94. package/test/fixtures/update-aggregated-nodes/abyssinianKaleStraw-impactassessment_pivoted.csv +3 -0
  95. package/test/fixtures/update-aggregated-nodes/cycle-missing-impactassessment_pivoted.csv +3 -0
  96. package/test/fixtures/update-aggregated-nodes/tomatoFruit-cycle_pivoted.csv +5 -0
  97. package/test/fixtures/update-aggregated-nodes/tomatoFruit-cycle_pivoted.csv.cycle.json +584 -0
  98. package/test/fixtures/update-aggregated-nodes/tomatoFruit-cycle_pivoted.csv.site.json +212 -0
  99. package/test/fixtures/update-aggregated-nodes/tomatoFruit-impactassessment_pivoted.csv +3 -0
  100. package/test/fixtures/update-aggregated-nodes/tomatoFruit-impactassessment_pivoted.csv.impactAssessment.json +1002 -0
  101. package/test/prepare.ts +15 -0
  102. package/test/utils.ts +33 -0
  103. package/tsconfig.build.json +13 -0
  104. package/tsconfig.dist.json +14 -0
  105. package/tsconfig.json +37 -0
  106. package/tsconfig.lambdas.json +13 -0
@@ -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
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "es2019",
5
+ "rootDir": ".",
6
+ "outDir": "build",
7
+ "sourceMap": true,
8
+ "allowJs": true
9
+ },
10
+ "include": [
11
+ "src/index.ts"
12
+ ]
13
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "dist",
6
+ "sourceMap": false,
7
+ "declaration": true,
8
+ "removeComments": true
9
+ },
10
+ "include": [
11
+ "src/models.ts"
12
+ ]
13
+ }
14
+
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
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "es2019",
5
+ "rootDir": ".",
6
+ "outDir": "build",
7
+ "sourceMap": true,
8
+ "allowJs": true
9
+ },
10
+ "include": [
11
+ "src/lambdas/**/handler.ts"
12
+ ]
13
+ }