refactor(core): Port nodes config (no-changelog) (#10140)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
46
packages/@n8n/config/src/configs/nodes.ts
Normal file
46
packages/@n8n/config/src/configs/nodes.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Config, Env, Nested } from '../decorators';
|
||||
|
||||
function isStringArray(input: unknown): input is string[] {
|
||||
return Array.isArray(input) && input.every((item) => typeof item === 'string');
|
||||
}
|
||||
|
||||
class JsonStringArray extends Array<string> {
|
||||
constructor(str: string) {
|
||||
super();
|
||||
|
||||
let parsed: unknown;
|
||||
|
||||
try {
|
||||
parsed = JSON.parse(str);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
|
||||
return isStringArray(parsed) ? parsed : [];
|
||||
}
|
||||
}
|
||||
|
||||
@Config
|
||||
class CommunityPackagesConfig {
|
||||
/** Whether to enable community packages */
|
||||
@Env('N8N_COMMUNITY_PACKAGES_ENABLED')
|
||||
enabled: boolean = true;
|
||||
}
|
||||
|
||||
@Config
|
||||
export class NodesConfig {
|
||||
/** Node types to load. Includes all if unspecified. @example '["n8n-nodes-base.hackerNews"]' */
|
||||
@Env('NODES_INCLUDE')
|
||||
readonly include: JsonStringArray = [];
|
||||
|
||||
/** Node types not to load. Excludes none if unspecified. @example '["n8n-nodes-base.hackerNews"]' */
|
||||
@Env('NODES_EXCLUDE')
|
||||
readonly exclude: JsonStringArray = [];
|
||||
|
||||
/** Node type to use as error trigger */
|
||||
@Env('NODES_ERROR_TRIGGER_TYPE')
|
||||
readonly errorTriggerType: string = 'n8n-nodes-base.errorTrigger';
|
||||
|
||||
@Nested
|
||||
readonly communityPackages: CommunityPackagesConfig;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { Container, Service } from 'typedi';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
type Class = Function;
|
||||
type Constructable<T = unknown> = new (rawValue: string) => T;
|
||||
type PropertyKey = string | symbol;
|
||||
interface PropertyMetadata {
|
||||
type: unknown;
|
||||
@@ -46,6 +47,8 @@ export const Config: ClassDecorator = (ConfigClass: Class) => {
|
||||
} else {
|
||||
value = value === 'true';
|
||||
}
|
||||
} else if (type !== String && type !== Object) {
|
||||
value = new (type as Constructable)(value as string);
|
||||
}
|
||||
|
||||
if (value !== undefined) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { PublicApiConfig } from './configs/public-api';
|
||||
import { ExternalSecretsConfig } from './configs/external-secrets';
|
||||
import { TemplatesConfig } from './configs/templates';
|
||||
import { EventBusConfig } from './configs/event-bus';
|
||||
import { NodesConfig } from './configs/nodes';
|
||||
|
||||
@Config
|
||||
class UserManagementConfig {
|
||||
@@ -39,4 +40,7 @@ export class GlobalConfig {
|
||||
|
||||
@Nested
|
||||
eventBus: EventBusConfig;
|
||||
|
||||
@Nested
|
||||
readonly nodes: NodesConfig;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user