Skip to content

Commit

Permalink
fix type errors in workflow, core, nodes-langchain, and nodes-base
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed May 21, 2024
1 parent 5ef45e8 commit 15d81bd
Show file tree
Hide file tree
Showing 100 changed files with 130 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function getInputs(
[NodeConnectionType.AiOutputParser]: 'Output Parser',
};

return inputs.map(({ type, filter, required }) => {
return inputs.map(({ type, filter }) => {
const input: INodeInputConfiguration = {
type,
displayName: type in displayNames ? displayNames[type] : undefined,
Expand Down Expand Up @@ -370,13 +370,13 @@ export class Agent implements INodeType {
if (agentType === 'conversationalAgent') {
return await conversationalAgentExecute.call(this, nodeVersion);
} else if (agentType === 'toolsAgent') {
return await toolsAgentExecute.call(this, nodeVersion);
return await toolsAgentExecute.call(this);
} else if (agentType === 'openAiFunctionsAgent') {
return await openAiFunctionsAgentExecute.call(this, nodeVersion);
} else if (agentType === 'reActAgent') {
return await reActAgentAgentExecute.call(this, nodeVersion);
} else if (agentType === 'sqlAgent') {
return await sqlAgentAgentExecute.call(this, nodeVersion);
return await sqlAgentAgentExecute.call(this);
} else if (agentType === 'planAndExecuteAgent') {
return await planAndExecuteAgentExecute.call(this, nodeVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ export async function conversationalAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ export async function openAiFunctionsAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ export async function planAndExecuteAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ export async function reActAgentAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const parseTablesString = (tablesString: string) =>

export async function sqlAgentAgentExecute(
this: IExecuteFunctions,
nodeVersion: number,
): Promise<INodeExecutionData[][]> {
this.logger.verbose('Executing SQL Agent');

Expand Down Expand Up @@ -152,5 +151,5 @@ export async function sqlAgentAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ function getOutputParserSchema(outputParser: BaseOutputParser): ZodObject<any, a
return schema;
}

export async function toolsAgentExecute(
this: IExecuteFunctions,
nodeVersion: number,
): Promise<INodeExecutionData[][]> {
export async function toolsAgentExecute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
this.logger.verbose('Executing Tools Agent');
const model = await this.getInputConnectionData(NodeConnectionType.AiLanguageModel, 0);

Expand Down Expand Up @@ -185,5 +182,5 @@ export async function toolsAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,6 @@ export class OpenAiAssistant implements INodeType {
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@ export class ChainRetrievalQa implements INodeType {
throw error;
}
}
return await this.prepareOutputData(returnData);
return [returnData];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,6 @@ export class ChainSummarizationV1 implements INodeType {
returnData.push({ json: { response } });
}

return await this.prepareOutputData(returnData);
return [returnData];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,6 @@ export class ChainSummarizationV2 implements INodeType {
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class MemoryChatRetriever implements INodeType {
const messages = await memory?.chatHistory.getMessages();

if (simplifyOutput && messages) {
return await this.prepareOutputData(simplifyMessages(messages));
return [simplifyMessages(messages)];
}

const serializedMessages =
Expand All @@ -107,6 +107,6 @@ export class MemoryChatRetriever implements INodeType {
return { json: serializedMessage as unknown as IDataObject };
}) ?? [];

return await this.prepareOutputData(serializedMessages);
return [serializedMessages];
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IExecuteFunctions, IWorkflowDataProxyData } from 'n8n-workflow';
import type { IExecuteFunctions, INode, IWorkflowDataProxyData } from 'n8n-workflow';
import { mock } from 'jest-mock-extended';
import { normalizeItems } from 'n8n-core';
import type { z } from 'zod';
Expand All @@ -12,7 +12,7 @@ describe('OutputParserStructured', () => {
});
const workflowDataProxy = mock<IWorkflowDataProxyData>({ $input: mock() });
thisArg.getWorkflowDataProxy.mockReturnValue(workflowDataProxy);
thisArg.getNode.mockReturnValue({ typeVersion: 1.1 });
thisArg.getNode.mockReturnValue(mock<INode>({ typeVersion: 1.1 }));
thisArg.addInputData.mockReturnValue({ index: 0 });
thisArg.addOutputData.mockReturnValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ export class VectorStoreInMemoryInsert implements INodeType {
clearStore,
);

return await this.prepareOutputData(serializedDocuments);
return [serializedDocuments];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ export class VectorStorePineconeInsert implements INodeType {
pineconeIndex,
});

return await this.prepareOutputData(serializedDocuments);
return [serializedDocuments];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const VectorStoreQdrant = createVectorStoreNode({
methods: { listSearch: { qdrantCollectionsSearch } },
insertFields,
sharedFields,
async getVectorStoreClient(context, filter, embeddings, itemIndex) {
async getVectorStoreClient(context, _, embeddings, itemIndex) {
const collection = context.getNodeParameter('qdrantCollection', itemIndex, '', {
extractValue: true,
}) as string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ export class VectorStoreSupabaseInsert implements INodeType {
queryName,
});

return await this.prepareOutputData(serializedDocuments);
return [serializedDocuments];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ export class VectorStoreZepInsert implements INodeType {

await ZepVectorStore.fromDocuments(processedDocuments, embeddings, zepConfig);

return await this.prepareOutputData(serializedDocuments);
return [serializedDocuments];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
void logAiEvent(this, 'n8n.ai.vector.store.searched', { query: prompt });
}

return await this.prepareOutputData(resultData);
return [resultData];
}

if (mode === 'insert') {
Expand Down Expand Up @@ -270,7 +270,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
}
}

return await this.prepareOutputData(resultData);
return [resultData];
}

throw new NodeOperationError(
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExpressionError } from 'n8n-workflow';

function buildSecretsValueProxy(value: IDataObject): unknown {
return new Proxy(value, {
get(target, valueName) {
get(_target, valueName) {
if (typeof valueName !== 'string') {
return;
}
Expand All @@ -27,15 +27,15 @@ export function getSecretsProxy(additionalData: IWorkflowExecuteAdditionalData):
return new Proxy(
{},
{
get(target, providerName) {
get(_target, providerName) {
if (typeof providerName !== 'string') {
return {};
}
if (secretsHelpers.hasProvider(providerName)) {
return new Proxy(
{},
{
get(target2, secretName) {
get(_target2, secretName) {
if (typeof secretName !== 'string') {
return;
}
Expand Down
14 changes: 9 additions & 5 deletions packages/core/test/ObjectStore.manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import fs from 'node:fs/promises';
import { mock } from 'jest-mock-extended';
import { ObjectStoreManager } from '@/BinaryData/ObjectStore.manager';
import { ObjectStoreService } from '@/ObjectStore/ObjectStore.service.ee';
import { isStream } from '@/ObjectStore/utils';
import type { MetadataResponseHeaders } from '@/ObjectStore/types';
import { mockInstance, toFileId, toStream } from './utils';

jest.mock('fs/promises');
Expand Down Expand Up @@ -74,11 +76,13 @@ describe('getMetadata()', () => {
const mimeType = 'text/plain';
const fileName = 'file.txt';

objectStoreService.getMetadata.mockResolvedValue({
'content-length': '1',
'content-type': mimeType,
'x-amz-meta-filename': fileName,
});
objectStoreService.getMetadata.mockResolvedValue(
mock<MetadataResponseHeaders>({
'content-length': '1',
'content-type': mimeType,
'x-amz-meta-filename': fileName,
}),
);

const metadata = await objectStoreManager.getMetadata(fileId);

Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/AgileCrm/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function agileCrmApiRequestAllItems(
export async function agileCrmApiRequestUpdate(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
method: IHttpRequestMethods = 'PUT',
endpoint?: string,
_endpoint?: string,
body: any = {},
_query: IDataObject = {},
uri?: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Clockify/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function clockifyApiRequest(

body: any = {},
qs: IDataObject = {},
uri?: string,
_uri?: string,
_option: IDataObject = {},
): Promise<any> {
const BASE_URL = 'https://api.clockify.me/api/v1';
Expand Down
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Cloudflare/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function cloudflareApiRequest(
resource: string,
body = {},
qs: IDataObject = {},
uri?: string,
_uri?: string,
headers: IDataObject = {},
): Promise<any> {
const options: IRequestOptions = {
Expand Down
3 changes: 1 addition & 2 deletions packages/nodes-base/nodes/Code/test/Code.node.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { anyNumber, mock } from 'jest-mock-extended';
import { NodeVM } from '@n8n/vm2';
import type { IExecuteFunctions, IWorkflowDataProxyData } from 'n8n-workflow';
import { ApplicationError, NodeHelpers } from 'n8n-workflow';
import { ApplicationError } from 'n8n-workflow';
import { normalizeItems } from 'n8n-core';
import { Code } from '../Code.node';
import { ValidationError } from '../ValidationError';
Expand All @@ -22,7 +22,6 @@ describe('Code Node unit test', () => {
const thisArg = mock<IExecuteFunctions>({
getNode: () => mock(),
helpers: { normalizeItems },
prepareOutputData: NodeHelpers.prepareOutputData,
});
const workflowDataProxy = mock<IWorkflowDataProxyData>({ $input: mock() });
thisArg.getWorkflowDataProxy.mockReturnValue(workflowDataProxy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');

discordApiRequestSpy.mockImplementation(async (method: string, endpoint) => {
discordApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'POST') {
return {
id: '1168528323006181417',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');

discordApiRequestSpy.mockImplementation(async (method: string, endpoint) => {
discordApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'DELETE') {
return {
id: '1168528323006181417',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
import type { WorkflowTestData } from '@test/nodes/types';
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

// TODO: use nock
const requestApiSpy = jest.spyOn(transport, 'requestApi');

requestApiSpy.mockImplementation(
async (options: IRequestOptions, credentialType: string, endpoint: string) => {
async (_options: IRequestOptions, _credentialType: string, endpoint: string) => {
if (endpoint === '/users/@me/guilds') {
return {
headers: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');

discordApiRequestSpy.mockImplementation(async (method: string, endpoint) => {
discordApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'GET') {
return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');

discordApiRequestSpy.mockImplementation(async (method: string, endpoint) => {
discordApiRequestSpy.mockImplementation(async (method: string, _) => {
if (method === 'PATCH') {
return {
id: '1168516240332034067',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');

discordApiRequestSpy.mockImplementation(async (method: string, endpoint) => {
discordApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'GET') {
return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');

discordApiRequestSpy.mockImplementation(async (method: string, endpoint) => {
discordApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'PUT') {
return {
success: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');

discordApiRequestSpy.mockImplementation(async (method: string, endpoint) => {
discordApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'DELETE') {
return {
success: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

const discordApiRequestSpy = jest.spyOn(transport, 'discordApiRequest');

discordApiRequestSpy.mockImplementation(async (method: string, endpoint) => {
discordApiRequestSpy.mockImplementation(async (method: string) => {
if (method === 'DELETE') {
return {
success: true,
Expand Down
Loading

0 comments on commit 15d81bd

Please sign in to comment.