n8n/packages/workflow/test/Helpers.ts

119 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-06-23 03:35:23 -07:00
import {
INodeType,
INodeTypes,
2019-08-09 03:19:28 -07:00
INodeTypeData,
2019-06-23 03:35:23 -07:00
} from '../src';
2019-08-09 03:19:28 -07:00
export interface INodeTypesObject {
[key: string]: INodeType;
}
2019-06-23 03:35:23 -07:00
class NodeTypesClass implements INodeTypes {
2019-08-09 03:19:28 -07:00
nodeTypes: INodeTypeData = {
2019-06-23 03:35:23 -07:00
'test.set': {
2019-08-09 03:19:28 -07:00
sourcePath: '',
type: {
description: {
displayName: 'Set',
name: 'set',
group: ['input'],
version: 1,
description: 'Sets a value',
defaults: {
name: 'Set',
color: '#0000FF',
2019-06-23 03:35:23 -07:00
},
2019-08-09 03:19:28 -07:00
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Value1',
name: 'value1',
type: 'string',
default: 'default-value1',
},
{
displayName: 'Value2',
name: 'value2',
type: 'string',
default: 'default-value2',
}
]
}
2019-06-23 03:35:23 -07:00
}
},
'test.setMulti': {
2019-08-09 03:19:28 -07:00
sourcePath: '',
type: {
description: {
displayName: 'Set Multi',
name: 'setMulti',
group: ['input'],
version: 1,
description: 'Sets multiple values',
defaults: {
name: 'Set Multi',
color: '#0000FF',
2019-06-23 03:35:23 -07:00
},
2019-08-09 03:19:28 -07:00
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Values',
name: 'values',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'string',
displayName: 'String',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: 'propertyName',
placeholder: 'Name of the property to write data to.',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
placeholder: 'The string value to write in the property.',
},
]
},
],
},
]
}
2019-06-23 03:35:23 -07:00
}
},
};
2019-08-09 03:19:28 -07:00
async init(nodeTypes: INodeTypeData): Promise<void> { }
2019-06-23 03:35:23 -07:00
getAll(): INodeType[] {
2019-08-09 03:19:28 -07:00
return Object.values(this.nodeTypes).map((data) => data.type);
2019-06-23 03:35:23 -07:00
}
getByName(nodeType: string): INodeType {
2019-08-09 03:19:28 -07:00
return this.nodeTypes[nodeType].type;
2019-06-23 03:35:23 -07:00
}
}
let nodeTypesInstance: NodeTypesClass | undefined;
export function NodeTypes(): NodeTypesClass {
if (nodeTypesInstance === undefined) {
nodeTypesInstance = new NodeTypesClass();
}
return nodeTypesInstance;
}