mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-18 05:59:42 +02:00
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import type { INodeCredentials } from 'n8n-workflow';
|
|
|
|
import type { TriggerStepConfig, V1NodeStepConfig } from './types';
|
|
|
|
export const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
|
|
export function isTriggerStepConfig(config: unknown): config is TriggerStepConfig {
|
|
if (!isRecord(config)) return false;
|
|
return (
|
|
typeof config.nodeType === 'string' &&
|
|
config.nodeType.length > 0 &&
|
|
typeof config.typeVersion === 'number' &&
|
|
isRecord(config.parameters)
|
|
);
|
|
}
|
|
|
|
export function isV1NodeStepConfig(config: unknown): config is V1NodeStepConfig {
|
|
if (!isRecord(config)) return false;
|
|
return (
|
|
typeof config.nodeType === 'string' &&
|
|
config.nodeType.length > 0 &&
|
|
typeof config.typeVersion === 'number' &&
|
|
isRecord(config.parameters) &&
|
|
typeof config.continueOnFail === 'boolean' &&
|
|
(config.credentials === undefined || isNodeCredentials(config.credentials))
|
|
);
|
|
}
|
|
|
|
/** Every entry must have the shape of `INodeCredentialsDetails`, not only the outer map. */
|
|
function isNodeCredentials(value: unknown): value is INodeCredentials {
|
|
if (!isRecord(value)) return false;
|
|
return Object.values(value).every(
|
|
(details) =>
|
|
isRecord(details) &&
|
|
(typeof details.id === 'string' || details.id === null) &&
|
|
typeof details.name === 'string',
|
|
);
|
|
}
|