Skip to content

Commit

Permalink
refactor: Enable import/order rule for n8n-core (n8n-io#11016)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi authored Sep 30, 2024
1 parent e54a396 commit d2238b9
Show file tree
Hide file tree
Showing 48 changed files with 125 additions and 95 deletions.
1 change: 0 additions & 1 deletion packages/core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {
complexity: 'error',

// TODO: Remove this
'import/order': 'off',
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': true }],
},
};
5 changes: 2 additions & 3 deletions packages/core/src/ActiveWorkflows.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Service } from 'typedi';

import type {
IGetExecutePollFunctions,
IGetExecuteTriggerFunctions,
Expand All @@ -20,9 +18,10 @@ import {
WorkflowActivationError,
WorkflowDeactivationError,
} from 'n8n-workflow';
import { Service } from 'typedi';

import { ScheduledTaskManager } from './ScheduledTaskManager';
import type { IWorkflowData } from './Interfaces';
import { ScheduledTaskManager } from './ScheduledTaskManager';

@Service()
export class ActiveWorkflows {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/BinaryData/BinaryData.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BINARY_ENCODING } from 'n8n-workflow';
import type { INodeExecutionData, IBinaryData } from 'n8n-workflow';
import { readFile, stat } from 'node:fs/promises';
import prettyBytes from 'pretty-bytes';
import type { Readable } from 'stream';
import Container, { Service } from 'typedi';
import { BINARY_ENCODING } from 'n8n-workflow';
import { InvalidModeError } from '../errors/invalid-mode.error';
import { areConfigModes, binaryToBuffer } from './utils';

import type { Readable } from 'stream';
import type { BinaryData } from './types';
import type { INodeExecutionData, IBinaryData } from 'n8n-workflow';
import { areConfigModes, binaryToBuffer } from './utils';
import { InvalidManagerError } from '../errors/invalid-manager.error';
import { InvalidModeError } from '../errors/invalid-mode.error';

@Service()
export class BinaryDataService {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/BinaryData/FileSystem.manager.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { jsonParse } from 'n8n-workflow';
import { createReadStream } from 'node:fs';
import fs from 'node:fs/promises';
import path from 'node:path';
import type { Readable } from 'stream';
import { v4 as uuid } from 'uuid';
import { jsonParse } from 'n8n-workflow';
import { assertDir, doesNotExist } from './utils';
import { DisallowedFilepathError } from '../errors/disallowed-filepath.error';

import type { Readable } from 'stream';
import type { BinaryData } from './types';
import { assertDir, doesNotExist } from './utils';
import { DisallowedFilepathError } from '../errors/disallowed-filepath.error';
import { FileNotFoundError } from '../errors/file-not-found.error';

const EXECUTION_ID_EXTRACTOR =
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/BinaryData/ObjectStore.manager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fs from 'node:fs/promises';
import type { Readable } from 'node:stream';
import { Service } from 'typedi';
import { v4 as uuid } from 'uuid';
import { binaryToBuffer } from './utils';
import { ObjectStoreService } from '../ObjectStore/ObjectStore.service.ee';

import type { Readable } from 'node:stream';
import type { BinaryData } from './types';
import { binaryToBuffer } from './utils';
import { ObjectStoreService } from '../ObjectStore/ObjectStore.service.ee';

@Service()
export class ObjectStoreManager implements BinaryData.Manager {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/BinaryData/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import concatStream from 'concat-stream';
import fs from 'node:fs/promises';
import type { Readable } from 'node:stream';

import type { BinaryData } from './types';
import concatStream from 'concat-stream';

export const CONFIG_MODES = ['default', 'filesystem', 's3'] as const;

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/Cipher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Service } from 'typedi';
import { createHash, createCipheriv, createDecipheriv, randomBytes } from 'crypto';
import { Service } from 'typedi';

import { InstanceSettings } from './InstanceSettings';

// Data encrypted by CryptoJS always starts with these bytes
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/Credentials.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Container } from 'typedi';
import type { ICredentialDataDecryptedObject, ICredentialsEncrypted } from 'n8n-workflow';
import { ApplicationError, ICredentials, jsonParse } from 'n8n-workflow';
import { Container } from 'typedi';

import { Cipher } from './Cipher';

export class Credentials<
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/DirectoryLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import glob from 'fast-glob';
import { readFileSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import type {
CodexData,
DocumentationLink,
Expand All @@ -21,7 +19,10 @@ import {
getVersionedNodeTypeAll,
jsonParse,
} from 'n8n-workflow';
import { readFileSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import * as path from 'path';

import { loadClassInIsolation } from './ClassLoader';
import { CUSTOM_NODES_CATEGORY } from './Constants';
import type { n8n } from './Interfaces';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/ExecutionMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IRunExecutionData } from 'n8n-workflow';
import { LoggerProxy as Logger } from 'n8n-workflow';

import { InvalidExecutionMetadataError } from './errors/invalid-execution-metadata.error';

export const KV_LIMIT = 10;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/InstanceSettings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { createHash, randomBytes } from 'crypto';
import { Service } from 'typedi';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { ApplicationError, jsonParse } from 'n8n-workflow';
import path from 'path';
import { Service } from 'typedi';

interface ReadOnlySettings {
encryptionKey: string;
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { IncomingMessage, type IncomingHttpHeaders } from 'http';
import { Agent, type AgentOptions } from 'https';
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import merge from 'lodash/merge';
import pick from 'lodash/pick';
import { DateTime } from 'luxon';
import { extension, lookup } from 'mime-types';
Expand Down Expand Up @@ -128,9 +129,12 @@ import clientOAuth1 from 'oauth-1.0a';
import path from 'path';
import { stringify } from 'qs';
import { Readable } from 'stream';
import Container from 'typedi';
import url, { URL, URLSearchParams } from 'url';

import { BinaryDataService } from './BinaryData/BinaryData.service';
import type { BinaryData } from './BinaryData/types';
import { binaryToBuffer } from './BinaryData/utils';
import {
BINARY_DATA_STORAGE_PATH,
BLOCK_FILE_ACCESS_TO_N8N_FILES,
Expand All @@ -143,23 +147,19 @@ import {
UM_EMAIL_TEMPLATES_INVITE,
UM_EMAIL_TEMPLATES_PWRESET,
} from './Constants';
import { extractValue } from './ExtractValue';
import type { ExtendedValidationResult, IResponseError } from './Interfaces';
import { getNodeAsTool } from './CreateNodeAsTool';
import {
getAllWorkflowExecutionMetadata,
getWorkflowExecutionMetadata,
setAllWorkflowExecutionMetadata,
setWorkflowExecutionMetadata,
} from './ExecutionMetadata';
import { getSecretsProxy } from './Secrets';
import Container from 'typedi';
import type { BinaryData } from './BinaryData/types';
import merge from 'lodash/merge';
import { extractValue } from './ExtractValue';
import { InstanceSettings } from './InstanceSettings';
import type { ExtendedValidationResult, IResponseError } from './Interfaces';
import { ScheduledTaskManager } from './ScheduledTaskManager';
import { getSecretsProxy } from './Secrets';
import { SSHClientsManager } from './SSHClientsManager';
import { binaryToBuffer } from './BinaryData/utils';
import { getNodeAsTool } from './CreateNodeAsTool';

axios.defaults.timeout = 300000;
// Prevent axios from adding x-form-www-urlencoded headers by default
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/ObjectStore/ObjectStore.service.ee.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createHash } from 'node:crypto';
import axios from 'axios';
import { Service } from 'typedi';
import { sign } from 'aws4';
import { isStream, parseXml, writeBlockedMessage } from './utils';
import type { Request as Aws4Options, Credentials as Aws4Credentials } from 'aws4';
import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, Method } from 'axios';
import { ApplicationError, LoggerProxy as Logger } from 'n8n-workflow';
import { createHash } from 'node:crypto';
import type { Readable } from 'stream';
import { Service } from 'typedi';

import type { AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, Method } from 'axios';
import type { Request as Aws4Options, Credentials as Aws4Credentials } from 'aws4';
import type {
Bucket,
ConfigSchemaCredentials,
Expand All @@ -15,7 +15,7 @@ import type {
RawListPage,
RequestOptions,
} from './types';
import type { Readable } from 'stream';
import { isStream, parseXml, writeBlockedMessage } from './utils';
import type { BinaryData } from '../BinaryData/types';

@Service()
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/ObjectStore/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AxiosResponseHeaders, ResponseType } from 'axios';

import type { BinaryData } from '../BinaryData/types';

export type RawListPage = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// XX denotes that the node is disabled
// PD denotes that the node has pinned data

import { DirectedGraph } from '../DirectedGraph';
import { createNodeData, defaultWorkflowParameter } from './helpers';
import { DirectedGraph } from '../DirectedGraph';

describe('DirectedGraph', () => {
// ┌─────┐ ┌─────┐ ┌─────┐
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { IRunData } from 'n8n-workflow';

import { createNodeData, toITaskData } from './helpers';
import { cleanRunData } from '../cleanRunData';
import { DirectedGraph } from '../DirectedGraph';
import { createNodeData, toITaskData } from './helpers';

describe('cleanRunData', () => {
// ┌─────┐ ┌─────┐ ┌─────┐
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
// PD denotes that the node has pinned data

import { type IPinData, type IRunData } from 'n8n-workflow';

import { createNodeData, toITaskData } from './helpers';
import { findStartNodes, isDirty } from '../findStartNodes';
import { DirectedGraph } from '../DirectedGraph';
import { findStartNodes, isDirty } from '../findStartNodes';

describe('isDirty', () => {
test("if the node has pinned data it's not dirty", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// XX denotes that the node is disabled
// PD denotes that the node has pinned data

import { createNodeData } from './helpers';
import { DirectedGraph } from '../DirectedGraph';
import { findSubgraph } from '../findSubgraph';
import { createNodeData } from './helpers';

describe('findSubgraph2', () => {
// ►►
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

import type { IPinData } from 'n8n-workflow';
import { NodeConnectionType, type IRunData } from 'n8n-workflow';
import { DirectedGraph } from '../DirectedGraph';

import { createNodeData, toITaskData } from './helpers';
import { DirectedGraph } from '../DirectedGraph';
import { getSourceDataGroups } from '../getSourceDataGroups';

describe('getSourceDataGroups', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
// XX denotes that the node is disabled
// PD denotes that the node has pinned data

import { recreateNodeExecutionStack } from '@/PartialExecutionUtils/recreateNodeExecutionStack';
import { type IPinData, type IRunData } from 'n8n-workflow';
import { AssertionError } from 'assert';
import { type IPinData, type IRunData } from 'n8n-workflow';

import { recreateNodeExecutionStack } from '@/PartialExecutionUtils/recreateNodeExecutionStack';

import { createNodeData, toITaskData } from './helpers';
import { DirectedGraph } from '../DirectedGraph';
import { findSubgraph } from '../findSubgraph';
import { createNodeData, toITaskData } from './helpers';

describe('recreateNodeExecutionStack', () => {
// ►►
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NodeConnectionType } from 'n8n-workflow';

import { createNodeData, toIConnections } from './helpers';

test('toIConnections', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NodeConnectionType } from 'n8n-workflow';

import { toITaskData } from './helpers';

test('toITaskData', function () {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/PartialExecutionUtils/cleanRunData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { INode, IRunData } from 'n8n-workflow';

import type { DirectedGraph } from './DirectedGraph';

/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/PartialExecutionUtils/findStartNodes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { INode, IPinData, IRunData } from 'n8n-workflow';

import type { DirectedGraph } from './DirectedGraph';
import { getIncomingData } from './getIncomingData';

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/PartialExecutionUtils/findSubgraph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { INode } from 'n8n-workflow';

import type { GraphConnection } from './DirectedGraph';
import { DirectedGraph } from './DirectedGraph';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { INode, Workflow } from 'n8n-workflow';
import * as assert from 'assert/strict';
import type { INode, Workflow } from 'n8n-workflow';

function findAllParentTriggers(workflow: Workflow, destinationNodeName: string) {
const parentNodes = workflow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as a from 'assert/strict';
import {
NodeConnectionType,
type IExecuteData,
Expand All @@ -11,7 +12,6 @@ import {
type IWaitingForExecutionSource,
} from 'n8n-workflow';

import * as a from 'assert/strict';
import type { DirectedGraph } from './DirectedGraph';
import { getIncomingData } from './getIncomingData';
import { getSourceDataGroups } from './getSourceDataGroups';
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/SSHClientsManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Service } from 'typedi';
import { Client, type ConnectConfig } from 'ssh2';
import { createHash } from 'node:crypto';
import type { SSHCredentials } from 'n8n-workflow';
import { createHash } from 'node:crypto';
import { Client, type ConnectConfig } from 'ssh2';
import { Service } from 'typedi';

@Service()
export class SSHClientsManager {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/ScheduledTaskManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Service } from 'typedi';
import { CronJob } from 'cron';
import type { CronExpression, Workflow } from 'n8n-workflow';
import { Service } from 'typedi';

import { InstanceSettings } from './InstanceSettings';

@Service()
Expand Down
Loading

0 comments on commit d2238b9

Please sign in to comment.