pangea-server 1.0.1 → 1.0.4

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.
@@ -26,13 +26,9 @@ function initDatabase(models, seeds, config = {}) {
26
26
  const dbClient = getDbClient();
27
27
  await dbClient.authenticate();
28
28
  (0, helpers_1.printSuccess)('database', 'database connected');
29
- if ((0, helpers_1.getEnvStr)('ENVIRONMENT') !== 'production') {
30
- if ((0, helpers_1.getEnvBool)('DB_DROP_TABLES'))
31
- await (0, seed_helpers_1.dropTables)();
32
- await (0, seed_helpers_1.syncTables)();
33
- if ((0, helpers_1.getEnvBool)('DB_SEED_TABLES'))
34
- await (0, seed_helpers_1.seedTables)(models, seeds);
35
- }
29
+ if ((0, helpers_1.getEnvStr)('ENVIRONMENT') !== 'development')
30
+ return;
31
+ await buildDatabase(models, seeds);
36
32
  }
37
33
  catch (err) {
38
34
  (0, helpers_1.printDanger)('database', err);
@@ -67,3 +63,10 @@ function logQuery(sql, timing) {
67
63
  const level = timing <= 50 ? 'success' : timing <= 200 ? 'warning' : 'danger';
68
64
  logFns[level]('timing', `${timing} ms`);
69
65
  }
66
+ async function buildDatabase(models, seeds) {
67
+ if ((0, helpers_1.getEnvBool)('DB_DROP_TABLES'))
68
+ await (0, seed_helpers_1.dropTables)();
69
+ await (0, seed_helpers_1.syncTables)();
70
+ if ((0, helpers_1.getEnvBool)('DB_SEED_TABLES'))
71
+ await (0, seed_helpers_1.seedTables)(models, seeds);
72
+ }
@@ -1,4 +1,5 @@
1
1
  import type { Models, Seeds } from './database.types';
2
2
  export declare function dropTables(): Promise<void>;
3
+ export declare function emptyTables(): Promise<void>;
3
4
  export declare function syncTables(): Promise<void>;
4
5
  export declare function seedTables<M extends Models>(models: M, seeds: Seeds<M>): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.seedTables = exports.syncTables = exports.dropTables = void 0;
3
+ exports.seedTables = exports.syncTables = exports.emptyTables = exports.dropTables = void 0;
4
4
  const db_client_1 = require("./db-client");
5
5
  const db_class_1 = require("./db.class");
6
6
  // helpers
@@ -12,6 +12,13 @@ async function dropTables() {
12
12
  (0, helpers_1.printSuccess)('database', 'tables dropped');
13
13
  }
14
14
  exports.dropTables = dropTables;
15
+ async function emptyTables() {
16
+ (0, helpers_1.printInfo)('database', 'emptying tables...');
17
+ const dbClient = (0, db_client_1.getDbClient)();
18
+ await dbClient.truncate({ truncate: true, cascade: true });
19
+ (0, helpers_1.printSuccess)('database', 'tables emptied');
20
+ }
21
+ exports.emptyTables = emptyTables;
15
22
  async function syncTables() {
16
23
  const dbClient = (0, db_client_1.getDbClient)();
17
24
  await dbClient.sync();
@@ -27,10 +34,7 @@ async function seedTables(models, seeds) {
27
34
  const db = new db_class_1.Db(tx);
28
35
  try {
29
36
  await db.disableForeignKeyChecks();
30
- await Promise.all(modelsWithData.map(async (modelName) => {
31
- const data = seeds[modelName];
32
- await db.insertMany(models[modelName], data);
33
- }));
37
+ await Promise.all(modelsWithData.map((modelName) => db.insertMany(models[modelName], seeds[modelName])));
34
38
  await db.enableForeignKeyChecks();
35
39
  await tx.commit();
36
40
  }
@@ -13,13 +13,7 @@ const error_helpers_1 = require("./error.helpers");
13
13
  const print_helpers_1 = require("./print.helpers");
14
14
  const env_helpers_1 = require("./env.helpers");
15
15
  const random_helpers_1 = require("./random.helpers");
16
- const bucketName = (() => {
17
- const appName = (0, env_helpers_1.getEnvStr)('APP_NAME');
18
- const environment = (0, env_helpers_1.getEnvStr)('ENVIRONMENT');
19
- if (environment === 'production')
20
- return appName;
21
- return `${appName}-${environment}`;
22
- })();
16
+ const bucketName = (0, env_helpers_1.getEnvStr)('DIGITAL_OCEAN_SPACES_BUCKET');
23
17
  const endpointUrl = 'nyc3.digitaloceanspaces.com';
24
18
  const s3 = new aws_sdk_1.default.S3({
25
19
  endpoint: new aws_sdk_1.default.Endpoint(endpointUrl),
@@ -29,12 +23,7 @@ const s3 = new aws_sdk_1.default.S3({
29
23
  async function deleteFile(fileName) {
30
24
  if (!fileName)
31
25
  return;
32
- await s3
33
- .deleteObject({
34
- Bucket: bucketName,
35
- Key: fileName,
36
- })
37
- .promise();
26
+ await s3.deleteObject({ Bucket: bucketName, Key: fileName }).promise();
38
27
  (0, print_helpers_1.printInfo)('file', `file deleted from ${fileName}`);
39
28
  }
40
29
  exports.deleteFile = deleteFile;
@@ -53,11 +42,7 @@ async function uploadImage(image, previousImage, ...folders) {
53
42
  const qualityMultiplier = 2;
54
43
  const targetQuality = Math.floor(qualityRatio * 100 * qualityMultiplier);
55
44
  const quality = Math.max(10, Math.min(100, targetQuality));
56
- const bufferCompressed = await (0, sharp_1.default)(imageBuffer)
57
- .png({
58
- quality,
59
- })
60
- .toBuffer();
45
+ const bufferCompressed = await (0, sharp_1.default)(imageBuffer).png({ quality }).toBuffer();
61
46
  const params = {
62
47
  Bucket: bucketName,
63
48
  Key: `${folders.join('/')}/${(0, random_helpers_1.getRandomString)('short')}`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "1.0.1",
4
+ "version": "1.0.4",
5
5
  "files": [
6
6
  "dist"
7
7
  ],