Skip to content

Commit

Permalink
Merge pull request #7309 from ever-co/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
evereq authored Dec 15, 2023
2 parents 98d700c + 24434c4 commit 992b807
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 152 deletions.
4 changes: 4 additions & 0 deletions .env.compose
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ DB_PORT=5432
DB_NAME=gauzy
DB_USER=postgres
DB_PASS=gauzy_password
DB_LOGGING=all
DB_POOL_SIZE=20
DB_CONNECTION_TIMEOUT=1000
DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

EXPRESS_SESSION_SECRET=gauzy

Expand Down
4 changes: 4 additions & 0 deletions .env.demo.compose
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ DB_PORT=5432
DB_NAME=gauzy
DB_USER=postgres
DB_PASS=gauzy_password
DB_LOGGING=all
DB_POOL_SIZE=20
DB_CONNECTION_TIMEOUT=1000
DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

EXPRESS_SESSION_SECRET=gauzy

Expand Down
4 changes: 4 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ DB_PORT=5432
DB_NAME=gauzy
DB_USER=postgres
DB_PASS=root
DB_LOGGING=all
DB_POOL_SIZE=20
DB_CONNECTION_TIMEOUT=1000
DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

EXPRESS_SESSION_SECRET=gauzy

Expand Down
4 changes: 4 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ DB_PORT=5432
DB_NAME=gauzy
DB_USER=postgres
DB_PASS=root
DB_LOGGING=all
DB_POOL_SIZE=20
DB_CONNECTION_TIMEOUT=1000
DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

EXPRESS_SESSION_SECRET=gauzy

Expand Down
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ DB_TYPE=better-sqlite3
# DB_NAME=gauzy
# DB_USER=postgres
# DB_PASS=root
# DB_LOGGING=all
# DB_POOL_SIZE=20
# DB_CONNECTION_TIMEOUT=1000
# DB_SLOW_QUERY_LOGGING_TIMEOUT=3000

EXPRESS_SESSION_SECRET=gauzy

Expand Down
22 changes: 18 additions & 4 deletions apps/api/src/plugin-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,30 @@ function getDbConfig(): DataSourceOptions {

const postgresConnectionOptions: PostgresConnectionOptions = {
type: dbType,
ssl: ssl ? sslParams : undefined,
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT ? parseInt(process.env.DB_PORT, 10) : 5432,
database: process.env.DB_NAME || 'postgres',
username: process.env.DB_USER || 'postgres',
password: process.env.DB_PASS || 'root',
ssl: ssl ? sslParams : undefined,
logging: 'all',
logger: 'file', // Removes console logging, instead logs all queries in a file ormlogs.log
logging: process.env.DB_LOGGING == 'all' ? 'all' : ['query', 'error'],
logger: 'advanced-console',
// log queries that take more than 3 sec as warnings
maxQueryExecutionTime: process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT
? parseInt(process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT)
: 3000,
synchronize: process.env.DB_SYNCHRONIZE === 'true' ? true : false, // We are using migrations, synchronize should be set to false.
uuidExtension: 'pgcrypto'
uuidExtension: 'pgcrypto',
// NOTE: in new TypeORM version this unified too `poolSize` in the root of connections option object.
// See https://typeorm.io/data-source-options#common-data-source-options
extra: {
// based on https://node-postgres.com/api/pool max connection pool size
max: process.env.DB_POOL_SIZE || 20,
// connection timeout
connectionTimeoutMillis: process.env.DB_CONNECTION_TIMEOUT
? parseInt(process.env.DB_CONNECTION_TIMEOUT)
: 1000
}
};

return postgresConnectionOptions;
Expand Down
33 changes: 11 additions & 22 deletions packages/common/src/utils/shared-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import slugify from 'slugify';
* @returns {boolean}
*/
export function isFunction(item: any): boolean {
return (item && typeof item === 'function' && !Array.isArray(item));
return item && typeof item === 'function' && !Array.isArray(item);
}

/**
Expand All @@ -16,7 +16,7 @@ export function isFunction(item: any): boolean {
* From https://stackoverflow.com/a/34749873/772859
*/
export function isObject(item: any) {
return (item && typeof item === 'object' && !Array.isArray(item));
return item && typeof item === 'object' && !Array.isArray(item);
}

/**
Expand Down Expand Up @@ -57,28 +57,18 @@ export function isEmpty(item: any) {
return item.length === 0;
} else if (item && typeof item === 'object') {
for (var key in item) {
if (
item[key] === null ||
item[key] === undefined ||
item[key] === ''
) {
if (item[key] === null || item[key] === undefined || item[key] === '') {
delete item[key];
}
}
return Object.keys(item).length === 0;
} else {
return (
!item ||
(item + '').toLocaleLowerCase() === 'null' ||
(item + '').toLocaleLowerCase() === 'undefined'
);
return !item || (item + '').toLocaleLowerCase() === 'null' || (item + '').toLocaleLowerCase() === 'undefined';
}
}

export function isJsObject(object: any) {
return (
object !== null && object !== undefined && typeof object === 'object'
);
return object !== null && object !== undefined && typeof object === 'object';
}

/*
Expand Down Expand Up @@ -136,7 +126,7 @@ export function removeDuplicates(data: string[]) {
* @returns
*/
export function isNullOrUndefined<T>(string: T | null | undefined): string is null | undefined {
return typeof string === "undefined" || string === null
return typeof string === 'undefined' || string === null;
}

/**
Expand All @@ -151,9 +141,7 @@ export function chunks(items: any[], size: number): any[] {
const chunks = [];
items = [].concat(...items);
while (items.length) {
chunks.push(
items.splice(0, size)
)
chunks.push(items.splice(0, size));
}
return chunks;
}
Expand Down Expand Up @@ -199,16 +187,17 @@ export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
*/
export const trimAndGetValue = (value?: string): string | undefined => {
return isNotEmpty(value) ? value.trim() : undefined;
}
};

/**
* Adds "http://" prefix to a URL if it's missing.
* @param url - The URL to ensure has the "http://" prefix.
* @returns The URL with the "http://" prefix.
*/
export const addHttpsPrefix = (url: string, prefix = 'https'): string => {
if (!url.startsWith('http://') && !url.startsWith('https://')) {
if (url && !url.startsWith('http://') && !url.startsWith('https://')) {
return `${prefix}://${url}`;
}

return url;
}
};
54 changes: 27 additions & 27 deletions packages/config/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConne

let dbType: string;

if (process.env.DB_TYPE)
dbType = process.env.DB_TYPE;
else
dbType = 'sqlite';
if (process.env.DB_TYPE) dbType = process.env.DB_TYPE;
else dbType = 'sqlite';

console.log(`Selected DB Type (DB_TYPE env var): ${dbType}`);

Expand All @@ -20,12 +18,10 @@ console.log(chalk.magenta(`Currently running Node.js version %s`), process.versi
let connectionConfig: TypeOrmModuleOptions;

switch (dbType) {

case 'mongodb':
throw "MongoDB not supported yet";
throw 'MongoDB not supported yet';

case 'postgres':

const ssl = process.env.DB_SSL_MODE === 'true' ? true : undefined;

let sslParams: TlsOptions;
Expand All @@ -38,36 +34,45 @@ switch (dbType) {
sslParams = {
rejectUnauthorized: true,
ca: sslCert
}
};
}

const postgresConnectionOptions: PostgresConnectionOptions = {
type: dbType,
ssl: ssl ? sslParams : undefined,
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT ? parseInt(process.env.DB_PORT, 10) : 5432,
database: process.env.DB_NAME || 'postgres',
username: process.env.DB_USER || 'postgres',
password: process.env.DB_PASS || 'root',
database: process.env.DB_NAME || 'postgres',
port: process.env.DB_PORT
? parseInt(process.env.DB_PORT, 10)
: 5432,
logging: 'all',
logger: 'file', // Removes console logging, instead logs all queries in a file ormlogs.log
logging: process.env.DB_LOGGING == 'all' ? 'all' : ['query', 'error'],
logger: 'advanced-console',
// log queries that take more than 3 sec as warnings
maxQueryExecutionTime: process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT
? parseInt(process.env.DB_SLOW_QUERY_LOGGING_TIMEOUT)
: 3000,
synchronize: process.env.DB_SYNCHRONIZE === 'true' ? true : false, // We are using migrations, synchronize should be set to false.
uuidExtension: 'pgcrypto',
migrations: ["src/modules/not-exists/*.migration{.ts,.js}"],
entities: ["src/modules/not-exists/*.entity{.ts,.js}"],
migrations: ['src/modules/not-exists/*.migration{.ts,.js}'],
entities: ['src/modules/not-exists/*.entity{.ts,.js}'],
// NOTE: in new TypeORM version this unified too `poolSize` in the root of connections option object.
// See https://typeorm.io/data-source-options#common-data-source-options
extra: {
// based on https://node-postgres.com/api/pool max connection pool size
max: process.env.DB_POOL_SIZE || 20,
// connection timeout
connectionTimeoutMillis: process.env.DB_CONNECTION_TIMEOUT
? parseInt(process.env.DB_CONNECTION_TIMEOUT)
: 1000
}
};

connectionConfig = postgresConnectionOptions;

break;

case 'sqlite':

const dbPath =
process.env.DB_PATH ||
path.join(process.cwd(), ...['apps', 'api', 'data'], 'gauzy.sqlite3');
const dbPath = process.env.DB_PATH || path.join(process.cwd(), ...['apps', 'api', 'data'], 'gauzy.sqlite3');

console.log('Sqlite DB Path: ' + dbPath);

Expand All @@ -76,7 +81,7 @@ switch (dbType) {
database: dbPath,
logging: 'all',
logger: 'file', //Removes console logging, instead logs all queries in a file ormlogs.log
synchronize: process.env.DB_SYNCHRONIZE === 'true' ? true : false, // We are using migrations, synchronize should be set to false.
synchronize: process.env.DB_SYNCHRONIZE === 'true' ? true : false // We are using migrations, synchronize should be set to false.
};

connectionConfig = sqliteConfig;
Expand All @@ -85,12 +90,7 @@ switch (dbType) {

case 'better-sqlite3':
const betterSqlitePath =
process.env.DB_PATH ||
path.join(
process.cwd(),
...['apps', 'api', 'data'],
'gauzy.sqlite3'
);
process.env.DB_PATH || path.join(process.cwd(), ...['apps', 'api', 'data'], 'gauzy.sqlite3');

console.log('Better Sqlite DB Path: ' + betterSqlitePath);

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function bootstrap(pluginConfig?: Partial<IPluginConfig>): Promise<
});

// Enable Express behind proxies (https://expressjs.com/en/guide/behind-proxies.html)
app.set('trust proxy', 1);
app.set('trust proxy', true);

// Starts listening for shutdown hooks
app.enableShutdownHooks();
Expand Down
Loading

0 comments on commit 992b807

Please sign in to comment.