Skip to content

Commit

Permalink
refactor: Remove reintroduced non-null assertions in Db calls (n8n-…
Browse files Browse the repository at this point in the history
…io#3162)

* 🔥 Remove reintroduced non-null assertions

* 🔥 Remove duplicate cred references

* 🔥 Remove unneeded `@ts-ignore`

* 🔥 Remove another `@ts-ignore`

* 🔥 Remove outdated suite version

* 🔥 Remove leftover non-null assertion

Co-authored-by: Ben Hesseldieck <[email protected]>

* 🔥 Remove more leftovers

* 🔥 Remove unneeded optional chaining operators

Co-authored-by: Ben Hesseldieck <[email protected]>
  • Loading branch information
ivov and BHesseldieck authored Apr 28, 2022
1 parent 2b00881 commit 5e2589e
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 299 deletions.
2 changes: 1 addition & 1 deletion packages/cli/commands/db/revert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class DbRevertMigrationCommand extends Command {
let connection: Connection | undefined;
try {
await Db.init();
connection = Db.collections.Credentials?.manager.connection;
connection = Db.collections.Credentials.manager.connection;

if (!connection) {
throw new Error(`No database connection available.`);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/commands/import/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ImportWorkflowsCommand extends Command {

// Make sure the settings exist
await UserSettings.prepareUserSettings();
const credentials = (await Db.collections.Credentials?.find()) ?? [];
const credentials = (await Db.collections.Credentials.find()) ?? [];

let totalImported = 0;

Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/ActiveExecutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export class ActiveExecutions {

const execution = ResponseHelper.flattenExecutionData(fullExecutionData);

const executionResult = await Db.collections.Execution!.save(
execution as IExecutionFlattedDb,
);
const executionResult = await Db.collections.Execution.save(execution as IExecutionFlattedDb);
executionId =
typeof executionResult.id === 'object'
? // @ts-ignore
Expand All @@ -87,8 +85,7 @@ export class ActiveExecutions {
waitTill: null,
};

// @ts-ignore
await Db.collections.Execution!.update(executionId, execution);
await Db.collections.Execution.update(executionId, execution);
}

// @ts-ignore
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/ActiveWorkflowRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class ActiveWorkflowRunner {
// This is not officially supported but there is no reason
// it should not work.
// Clear up active workflow table
await Db.collections.Webhook?.clear();
await Db.collections.Webhook.clear();
}

this.activeWorkflows = new ActiveWorkflows();
Expand Down Expand Up @@ -189,7 +189,7 @@ export class ActiveWorkflowRunner {
path = path.slice(0, -1);
}

let webhook = (await Db.collections.Webhook?.findOne({
let webhook = (await Db.collections.Webhook.findOne({
webhookPath: path,
method: httpMethod,
})) as IWebhookDb;
Expand All @@ -200,7 +200,7 @@ export class ActiveWorkflowRunner {
// check if a dynamic webhook path exists
const pathElements = path.split('/');
webhookId = pathElements.shift();
const dynamicWebhooks = await Db.collections.Webhook?.find({
const dynamicWebhooks = await Db.collections.Webhook.find({
webhookId,
method: httpMethod,
pathLength: pathElements.length,
Expand Down Expand Up @@ -332,7 +332,7 @@ export class ActiveWorkflowRunner {
* @memberof ActiveWorkflowRunner
*/
async getWebhookMethods(path: string): Promise<string[]> {
const webhooks = await Db.collections.Webhook?.find({ webhookPath: path });
const webhooks = await Db.collections.Webhook.find({ webhookPath: path });

// Gather all request methods in string array
const webhookMethods: string[] = webhooks.map((webhook) => webhook.method);
Expand Down Expand Up @@ -443,7 +443,7 @@ export class ActiveWorkflowRunner {

try {
// eslint-disable-next-line no-await-in-loop
await Db.collections.Webhook?.insert(webhook);
await Db.collections.Webhook.insert(webhook);
const webhookExists = await workflow.runWebhookMethod(
'checkExists',
webhookData,
Expand Down Expand Up @@ -556,7 +556,7 @@ export class ActiveWorkflowRunner {
workflowId: workflowData.id,
} as IWebhookDb;

await Db.collections.Webhook?.delete(webhook);
await Db.collections.Webhook.delete(webhook);
}

/**
Expand Down
Loading

0 comments on commit 5e2589e

Please sign in to comment.