mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(n8n Evaluation Node): Add pre-defined metrics to the "Set Metrics" operation (#17127)
This commit is contained in:
@@ -15,6 +15,7 @@ export * from './expression';
|
||||
export * from './expressions/expression-helpers';
|
||||
export * from './from-ai-parse-utils';
|
||||
export * from './node-helpers';
|
||||
export * from './tool-helpers';
|
||||
export * from './node-reference-parser-utils';
|
||||
export * from './metadata-utils';
|
||||
export * from './workflow';
|
||||
|
||||
10
packages/workflow/src/tool-helpers.ts
Normal file
10
packages/workflow/src/tool-helpers.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { INode } from './interfaces';
|
||||
|
||||
/**
|
||||
* Converts a node name to a valid tool name by replacing special characters with underscores
|
||||
* and collapsing consecutive underscores into a single one.
|
||||
*/
|
||||
export function nodeNameToToolName(nodeOrName: INode | string): string {
|
||||
const name = typeof nodeOrName === 'string' ? nodeOrName : nodeOrName.name;
|
||||
return name.replace(/[\s.?!=+#@&*()[\]{}:;,<>\/\\'"^%$_]+/g, '_');
|
||||
}
|
||||
75
packages/workflow/test/tool-helpers.test.ts
Normal file
75
packages/workflow/test/tool-helpers.test.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import type { INode } from '../src/interfaces';
|
||||
import { nodeNameToToolName } from '../src/tool-helpers';
|
||||
|
||||
describe('nodeNameToToolName', () => {
|
||||
const getNodeWithName = (name: string): INode => ({
|
||||
id: 'test-node',
|
||||
name,
|
||||
type: 'test',
|
||||
typeVersion: 1,
|
||||
position: [0, 0] as [number, number],
|
||||
parameters: {},
|
||||
});
|
||||
|
||||
it('should replace spaces with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace dots with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test.Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace question marks with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test?Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace exclamation marks with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test!Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace equals signs with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test=Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace multiple special characters with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test.Node?With!Special=Chars'))).toBe(
|
||||
'Test_Node_With_Special_Chars',
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle names that already have underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test_Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should handle names with consecutive special characters', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test..!!??==Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace various special characters with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test#+*()[]{}:;,<>/\\\'"%$Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
describe('when passed a string directly', () => {
|
||||
it('should replace spaces with underscores', () => {
|
||||
expect(nodeNameToToolName('Test Node')).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace dots with underscores', () => {
|
||||
expect(nodeNameToToolName('Test.Node')).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace multiple special characters with underscores', () => {
|
||||
expect(nodeNameToToolName('Test.Node?With!Special=Chars')).toBe(
|
||||
'Test_Node_With_Special_Chars',
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle consecutive special characters', () => {
|
||||
expect(nodeNameToToolName('Test..!!??==Node')).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace various special characters with underscores', () => {
|
||||
expect(nodeNameToToolName('Test#+*()[]{}:;,<>/\\\'"%$Node')).toBe('Test_Node');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user