Skip to content

Commit

Permalink
fix(core): Use explicit types in configs to ensure valid decorator me…
Browse files Browse the repository at this point in the history
…tadata (#10433)
  • Loading branch information
netroy committed Aug 15, 2024
1 parent a5cbc99 commit b5b5295
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 82 deletions.
8 changes: 4 additions & 4 deletions packages/@n8n/config/src/configs/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import { Config, Env, Nested } from '../decorators';
class MemoryConfig {
/** Max size of memory cache in bytes */
@Env('N8N_CACHE_MEMORY_MAX_SIZE')
maxSize = 3 * 1024 * 1024; // 3 MiB
maxSize: number = 3 * 1024 * 1024; // 3 MiB

/** Time to live (in milliseconds) for data cached in memory. */
@Env('N8N_CACHE_MEMORY_TTL')
ttl = 3600 * 1000; // 1 hour
ttl: number = 3600 * 1000; // 1 hour
}

@Config
class RedisConfig {
/** Prefix for cache keys in Redis. */
@Env('N8N_CACHE_REDIS_KEY_PREFIX')
prefix = 'redis';
prefix: string = 'redis';

/** Time to live (in milliseconds) for data cached in Redis. 0 for no TTL. */
@Env('N8N_CACHE_REDIS_TTL')
ttl = 3600 * 1000; // 1 hour
ttl: number = 3600 * 1000; // 1 hour
}

@Config
Expand Down
6 changes: 3 additions & 3 deletions packages/@n8n/config/src/configs/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ class CredentialsOverwrite {
* Format: { CREDENTIAL_NAME: { PARAMETER: VALUE }}
*/
@Env('CREDENTIALS_OVERWRITE_DATA')
data = '{}';
data: string = '{}';

/** Internal API endpoint to fetch overwritten credential types from. */
@Env('CREDENTIALS_OVERWRITE_ENDPOINT')
endpoint = '';
endpoint: string = '';
}

@Config
export class CredentialsConfig {
/** Default name for credentials */
@Env('CREDENTIALS_DEFAULT_NAME')
defaultName = 'My credentials';
defaultName: string = 'My credentials';

@Nested
overwrite: CredentialsOverwrite;
Expand Down
42 changes: 21 additions & 21 deletions packages/@n8n/config/src/configs/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Config, Env, Nested } from '../decorators';
class LoggingConfig {
/** Whether database logging is enabled. */
@Env('DB_LOGGING_ENABLED')
enabled = false;
enabled: boolean = false;

/**
* Database logging level. Requires `DB_LOGGING_MAX_EXECUTION_TIME` to be higher than `0`.
Expand All @@ -16,7 +16,7 @@ class LoggingConfig {
* Only queries that exceed this time (ms) will be logged. Set `0` to disable.
*/
@Env('DB_LOGGING_MAX_EXECUTION_TIME')
maxQueryExecutionTime = 0;
maxQueryExecutionTime: number = 0;
}

@Config
Expand All @@ -26,54 +26,54 @@ class PostgresSSLConfig {
* If `DB_POSTGRESDB_SSL_CA`, `DB_POSTGRESDB_SSL_CERT`, or `DB_POSTGRESDB_SSL_KEY` are defined, `DB_POSTGRESDB_SSL_ENABLED` defaults to `true`.
*/
@Env('DB_POSTGRESDB_SSL_ENABLED')
enabled = false;
enabled: boolean = false;

/** SSL certificate authority */
@Env('DB_POSTGRESDB_SSL_CA')
ca = '';
ca: string = '';

/** SSL certificate */
@Env('DB_POSTGRESDB_SSL_CERT')
cert = '';
cert: string = '';

/** SSL key */
@Env('DB_POSTGRESDB_SSL_KEY')
key = '';
key: string = '';

/** If unauthorized SSL connections should be rejected */
@Env('DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED')
rejectUnauthorized = true;
rejectUnauthorized: boolean = true;
}

@Config
class PostgresConfig {
/** Postgres database name */
@Env('DB_POSTGRESDB_DATABASE')
database = 'n8n';
database: string = 'n8n';

/** Postgres database host */
@Env('DB_POSTGRESDB_HOST')
host = 'localhost';
host: string = 'localhost';

/** Postgres database password */
@Env('DB_POSTGRESDB_PASSWORD')
password = '';
password: string = '';

/** Postgres database port */
@Env('DB_POSTGRESDB_PORT')
port: number = 5432;

/** Postgres database user */
@Env('DB_POSTGRESDB_USER')
user = 'postgres';
user: string = 'postgres';

/** Postgres database schema */
@Env('DB_POSTGRESDB_SCHEMA')
schema = 'public';
schema: string = 'public';

/** Postgres database pool size */
@Env('DB_POSTGRESDB_POOL_SIZE')
poolSize = 2;
poolSize: number = 2;

@Nested
ssl: PostgresSSLConfig;
Expand All @@ -83,30 +83,30 @@ class PostgresConfig {
class MysqlConfig {
/** @deprecated MySQL database name */
@Env('DB_MYSQLDB_DATABASE')
database = 'n8n';
database: string = 'n8n';

/** MySQL database host */
@Env('DB_MYSQLDB_HOST')
host = 'localhost';
host: string = 'localhost';

/** MySQL database password */
@Env('DB_MYSQLDB_PASSWORD')
password = '';
password: string = '';

/** MySQL database port */
@Env('DB_MYSQLDB_PORT')
port: number = 3306;

/** MySQL database user */
@Env('DB_MYSQLDB_USER')
user = 'root';
user: string = 'root';
}

@Config
class SqliteConfig {
/** SQLite database file name */
@Env('DB_SQLITE_DATABASE')
database = 'database.sqlite';
database: string = 'database.sqlite';

/** SQLite database pool size. Set to `0` to disable pooling. */
@Env('DB_SQLITE_POOL_SIZE')
Expand All @@ -116,15 +116,15 @@ class SqliteConfig {
* Enable SQLite WAL mode.
*/
@Env('DB_SQLITE_ENABLE_WAL')
enableWAL = this.poolSize > 1;
enableWAL: boolean = this.poolSize > 1;

/**
* Run `VACUUM` on startup to rebuild the database, reducing file size and optimizing indexes.
*
* @warning Long-running blocking operation that will increase startup time.
*/
@Env('DB_SQLITE_VACUUM_ON_STARTUP')
executeVacuumOnStartup = false;
executeVacuumOnStartup: boolean = false;
}

@Config
Expand All @@ -135,7 +135,7 @@ export class DatabaseConfig {

/** Prefix for table names */
@Env('DB_TABLE_PREFIX')
tablePrefix = '';
tablePrefix: string = '';

@Nested
logging: LoggingConfig;
Expand Down
20 changes: 10 additions & 10 deletions packages/@n8n/config/src/configs/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import { Config, Env, Nested } from '../decorators';
export class SmtpAuth {
/** SMTP login username */
@Env('N8N_SMTP_USER')
user = '';
user: string = '';

/** SMTP login password */
@Env('N8N_SMTP_PASS')
pass = '';
pass: string = '';

/** SMTP OAuth Service Client */
@Env('N8N_SMTP_OAUTH_SERVICE_CLIENT')
serviceClient = '';
serviceClient: string = '';

/** SMTP OAuth Private Key */
@Env('N8N_SMTP_OAUTH_PRIVATE_KEY')
privateKey = '';
privateKey: string = '';
}

@Config
export class SmtpConfig {
/** SMTP server host */
@Env('N8N_SMTP_HOST')
host = '';
host: string = '';

/** SMTP server port */
@Env('N8N_SMTP_PORT')
Expand All @@ -39,7 +39,7 @@ export class SmtpConfig {

/** How to display sender name */
@Env('N8N_SMTP_SENDER')
sender = '';
sender: string = '';

@Nested
auth: SmtpAuth;
Expand All @@ -49,19 +49,19 @@ export class SmtpConfig {
export class TemplateConfig {
/** Overrides default HTML template for inviting new people (use full path) */
@Env('N8N_UM_EMAIL_TEMPLATES_INVITE')
invite = '';
invite: string = '';

/** Overrides default HTML template for resetting password (use full path) */
@Env('N8N_UM_EMAIL_TEMPLATES_PWRESET')
passwordReset = '';
passwordReset: string = '';

/** Overrides default HTML template for notifying that a workflow was shared (use full path) */
@Env('N8N_UM_EMAIL_TEMPLATES_WORKFLOW_SHARED')
workflowShared = '';
workflowShared: string = '';

/** Overrides default HTML template for notifying that credentials were shared (use full path) */
@Env('N8N_UM_EMAIL_TEMPLATES_CREDENTIALS_SHARED')
credentialsShared = '';
credentialsShared: string = '';
}

@Config
Expand Down
44 changes: 22 additions & 22 deletions packages/@n8n/config/src/configs/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,51 @@ import { Config, Env, Nested } from '../decorators';
class PrometheusMetricsConfig {
/** Whether to enable the `/metrics` endpoint to expose Prometheus metrics. */
@Env('N8N_METRICS')
enable = false;
enable: boolean = false;

/** Prefix for Prometheus metric names. */
@Env('N8N_METRICS_PREFIX')
prefix = 'n8n_';
prefix: string = 'n8n_';

/** Whether to expose system and Node.js metrics. See: https://www.npmjs.com/package/prom-client */
@Env('N8N_METRICS_INCLUDE_DEFAULT_METRICS')
includeDefaultMetrics = true;
includeDefaultMetrics: boolean = true;

/** Whether to include a label for workflow ID on workflow metrics. */
@Env('N8N_METRICS_INCLUDE_WORKFLOW_ID_LABEL')
includeWorkflowIdLabel = false;
includeWorkflowIdLabel: boolean = false;

/** Whether to include a label for node type on node metrics. */
@Env('N8N_METRICS_INCLUDE_NODE_TYPE_LABEL')
includeNodeTypeLabel = false;
includeNodeTypeLabel: boolean = false;

/** Whether to include a label for credential type on credential metrics. */
@Env('N8N_METRICS_INCLUDE_CREDENTIAL_TYPE_LABEL')
includeCredentialTypeLabel = false;
includeCredentialTypeLabel: boolean = false;

/** Whether to expose metrics for API endpoints. See: https://www.npmjs.com/package/express-prom-bundle */
@Env('N8N_METRICS_INCLUDE_API_ENDPOINTS')
includeApiEndpoints = false;
includeApiEndpoints: boolean = false;

/** Whether to include a label for the path of API endpoint calls. */
@Env('N8N_METRICS_INCLUDE_API_PATH_LABEL')
includeApiPathLabel = false;
includeApiPathLabel: boolean = false;

/** Whether to include a label for the HTTP method of API endpoint calls. */
@Env('N8N_METRICS_INCLUDE_API_METHOD_LABEL')
includeApiMethodLabel = false;
includeApiMethodLabel: boolean = false;

/** Whether to include a label for the status code of API endpoint calls. */
@Env('N8N_METRICS_INCLUDE_API_STATUS_CODE_LABEL')
includeApiStatusCodeLabel = false;
includeApiStatusCodeLabel: boolean = false;

/** Whether to include metrics for cache hits and misses. */
@Env('N8N_METRICS_INCLUDE_CACHE_METRICS')
includeCacheMetrics = false;
includeCacheMetrics: boolean = false;

/** Whether to include metrics derived from n8n's internal events */
@Env('N8N_METRICS_INCLUDE_MESSAGE_EVENT_BUS_METRICS')
includeMessageEventBusMetrics = false;
includeMessageEventBusMetrics: boolean = false;
}

@Config
Expand All @@ -62,41 +62,41 @@ export class EndpointsConfig {

/** Path segment for REST API endpoints. */
@Env('N8N_ENDPOINT_REST')
rest = 'rest';
rest: string = 'rest';

/** Path segment for form endpoints. */
@Env('N8N_ENDPOINT_FORM')
form = 'form';
form: string = 'form';

/** Path segment for test form endpoints. */
@Env('N8N_ENDPOINT_FORM_TEST')
formTest = 'form-test';
formTest: string = 'form-test';

/** Path segment for waiting form endpoints. */
@Env('N8N_ENDPOINT_FORM_WAIT')
formWaiting = 'form-waiting';
formWaiting: string = 'form-waiting';

/** Path segment for webhook endpoints. */
@Env('N8N_ENDPOINT_WEBHOOK')
webhook = 'webhook';
webhook: string = 'webhook';

/** Path segment for test webhook endpoints. */
@Env('N8N_ENDPOINT_WEBHOOK_TEST')
webhookTest = 'webhook-test';
webhookTest: string = 'webhook-test';

/** Path segment for waiting webhook endpoints. */
@Env('N8N_ENDPOINT_WEBHOOK_WAIT')
webhookWaiting = 'webhook-waiting';
webhookWaiting: string = 'webhook-waiting';

/** Whether to disable n8n's UI (frontend). */
@Env('N8N_DISABLE_UI')
disableUi = false;
disableUi: boolean = false;

/** Whether to disable production webhooks on the main process, when using webhook-specific processes. */
@Env('N8N_DISABLE_PRODUCTION_MAIN_PROCESS')
disableProductionWebhooksOnMainProcess = false;
disableProductionWebhooksOnMainProcess: boolean = false;

/** Colon-delimited list of additional endpoints to not open the UI on. */
@Env('N8N_ADDITIONAL_NON_UI_ROUTES')
additionalNonUIRoutes = '';
additionalNonUIRoutes: string = '';
}
Loading

0 comments on commit b5b5295

Please sign in to comment.