mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor(core): Refactor custom config types, add additional tests (no-changelog) (#14083)
This commit is contained in:
committed by
GitHub
parent
5aacc2e0c2
commit
c34ffd0e7c
@@ -1,14 +1,6 @@
|
|||||||
|
import { ColonSeparatedStringArray } from '../custom-types';
|
||||||
import { Config, Env } from '../decorators';
|
import { Config, Env } from '../decorators';
|
||||||
|
|
||||||
class ColonSeparatedStringArray<T extends string = string> extends Array<T> {
|
|
||||||
constructor(str: string) {
|
|
||||||
super();
|
|
||||||
const parsed = str.split(':') as this;
|
|
||||||
const filtered = parsed.filter((i) => typeof i === 'string' && i.length);
|
|
||||||
return filtered.length ? filtered : [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Config
|
@Config
|
||||||
export class ExternalHooksConfig {
|
export class ExternalHooksConfig {
|
||||||
/** Files containing external hooks. Multiple files can be separated by colon (":") */
|
/** Files containing external hooks. Multiple files can be separated by colon (":") */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
import { CommaSeperatedStringArray } from '../custom-types';
|
||||||
import { Config, Env, Nested } from '../decorators';
|
import { Config, Env, Nested } from '../decorators';
|
||||||
import { StringArray } from '../utils';
|
|
||||||
|
|
||||||
/** Scopes (areas of functionality) to filter logs by. */
|
/** Scopes (areas of functionality) to filter logs by. */
|
||||||
export const LOG_SCOPES = [
|
export const LOG_SCOPES = [
|
||||||
@@ -14,6 +14,7 @@ export const LOG_SCOPES = [
|
|||||||
'scaling',
|
'scaling',
|
||||||
'waiting-executions',
|
'waiting-executions',
|
||||||
'task-runner',
|
'task-runner',
|
||||||
|
'insights',
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export type LogScope = (typeof LOG_SCOPES)[number];
|
export type LogScope = (typeof LOG_SCOPES)[number];
|
||||||
@@ -57,7 +58,7 @@ export class LoggingConfig {
|
|||||||
* @example `N8N_LOG_OUTPUT=console,file` will output to both console and file.
|
* @example `N8N_LOG_OUTPUT=console,file` will output to both console and file.
|
||||||
*/
|
*/
|
||||||
@Env('N8N_LOG_OUTPUT')
|
@Env('N8N_LOG_OUTPUT')
|
||||||
outputs: StringArray<'console' | 'file'> = ['console'];
|
outputs: CommaSeperatedStringArray<'console' | 'file'> = ['console'];
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
file: FileLoggingConfig;
|
file: FileLoggingConfig;
|
||||||
@@ -84,5 +85,5 @@ export class LoggingConfig {
|
|||||||
* `N8N_LOG_SCOPES=license,waiting-executions`
|
* `N8N_LOG_SCOPES=license,waiting-executions`
|
||||||
*/
|
*/
|
||||||
@Env('N8N_LOG_SCOPES')
|
@Env('N8N_LOG_SCOPES')
|
||||||
scopes: StringArray<LogScope> = [];
|
scopes: CommaSeperatedStringArray<LogScope> = [];
|
||||||
}
|
}
|
||||||
|
|||||||
19
packages/@n8n/config/src/custom-types.ts
Normal file
19
packages/@n8n/config/src/custom-types.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
abstract class StringArray<T extends string> extends Array<T> {
|
||||||
|
constructor(str: string, delimiter: string) {
|
||||||
|
super();
|
||||||
|
const parsed = str.split(delimiter) as this;
|
||||||
|
return parsed.filter((i) => typeof i === 'string' && i.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CommaSeperatedStringArray<T extends string> extends StringArray<T> {
|
||||||
|
constructor(str: string) {
|
||||||
|
super(str, ',');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ColonSeparatedStringArray<T extends string = string> extends StringArray<T> {
|
||||||
|
constructor(str: string) {
|
||||||
|
super(str, ':');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,7 @@ export { S3Config } from './configs/external-storage.config';
|
|||||||
export { LOG_SCOPES } from './configs/logging.config';
|
export { LOG_SCOPES } from './configs/logging.config';
|
||||||
export type { LogScope } from './configs/logging.config';
|
export type { LogScope } from './configs/logging.config';
|
||||||
export { WorkflowsConfig } from './configs/workflows.config';
|
export { WorkflowsConfig } from './configs/workflows.config';
|
||||||
|
export * from './custom-types';
|
||||||
|
|
||||||
@Config
|
@Config
|
||||||
export class GlobalConfig {
|
export class GlobalConfig {
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
export class StringArray<T extends string> extends Array<T> {
|
|
||||||
constructor(str: string) {
|
|
||||||
super();
|
|
||||||
const parsed = str.split(',') as StringArray<T>;
|
|
||||||
return parsed.every((i) => typeof i === 'string') ? parsed : [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
25
packages/@n8n/config/test/custom-types.test.ts
Normal file
25
packages/@n8n/config/test/custom-types.test.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { CommaSeperatedStringArray, ColonSeparatedStringArray } from '../src/custom-types';
|
||||||
|
|
||||||
|
describe('CommaSeperatedStringArray', () => {
|
||||||
|
it('should parse comma-separated string into array', () => {
|
||||||
|
const result = new CommaSeperatedStringArray('a,b,c');
|
||||||
|
expect(result).toEqual(['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle empty strings', () => {
|
||||||
|
const result = new CommaSeperatedStringArray('a,b,,,');
|
||||||
|
expect(result).toEqual(['a', 'b']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ColonSeparatedStringArray', () => {
|
||||||
|
it('should parse colon-separated string into array', () => {
|
||||||
|
const result = new ColonSeparatedStringArray('a:b:c');
|
||||||
|
expect(result).toEqual(['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle empty strings', () => {
|
||||||
|
const result = new ColonSeparatedStringArray('a::b:::');
|
||||||
|
expect(result).toEqual(['a', 'b']);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user