From 44da18cebab24885088877f5a7ef4f18aae7e2d4 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 11 Jun 2024 11:01:17 +0530 Subject: [PATCH] test: fix broken types --- src/connection/index.ts | 5 +++-- src/connection/manager.ts | 28 ---------------------------- src/database/main.ts | 25 ------------------------- src/types/database.ts | 24 +++++------------------- test/orm/base_model.spec.ts | 12 ++++++------ 5 files changed, 14 insertions(+), 80 deletions(-) diff --git a/src/connection/index.ts b/src/connection/index.ts index 1e4688aa..04e6a87c 100644 --- a/src/connection/index.ts +++ b/src/connection/index.ts @@ -12,9 +12,10 @@ import knex, { Knex } from 'knex' import { EventEmitter } from 'node:events' import { patchKnex } from 'knex-dynamic-connection' import type { Logger } from '@adonisjs/core/logger' +import { HealthCheckResult } from '@adonisjs/core/types/health' // @ts-expect-error import { resolveClientNameWithAliases } from 'knex/lib/util/helpers.js' -import { ConnectionConfig, ConnectionContract, ReportNode } from '../types/database.js' +import { ConnectionConfig, ConnectionContract } from '../types/database.js' import { Logger as ConnectionLogger } from './logger.js' import * as errors from '../errors.js' @@ -392,7 +393,7 @@ export class Connection extends EventEmitter implements ConnectionContract { /** * Returns the healthcheck report for the connection */ - async getReport(): Promise { + async getReport(): Promise { const error = await this.checkWriteHost() let readError: Error | undefined diff --git a/src/connection/manager.ts b/src/connection/manager.ts index e6cfd020..5318e50d 100644 --- a/src/connection/manager.ts +++ b/src/connection/manager.ts @@ -11,7 +11,6 @@ import type { Emitter } from '@adonisjs/core/events' import type { Logger } from '@adonisjs/core/logger' import { - ReportNode, ConnectionNode, ConnectionConfig, ConnectionContract, @@ -244,31 +243,4 @@ export class ConnectionManager implements ConnectionManagerContract { this.connections.delete(connectionName) } } - - /** - * Returns the report for all the connections marked for healthChecks. - */ - async report(): Promise { - const reports = await Promise.all( - Array.from(this.connections.keys()) - .filter((one) => this.get(one)!.config.healthCheck) - .map((one) => { - this.connect(one) - return this.get(one)!.connection!.getReport() - }) - ) - - const healthy = !reports.find((report) => !!report.error) - - return { - displayName: 'Database', - health: { - healthy, - message: healthy - ? 'All connections are healthy' - : 'One or more connections are not healthy', - }, - meta: reports, - } - } } diff --git a/src/database/main.ts b/src/database/main.ts index bfc40548..3ea6b920 100644 --- a/src/database/main.ts +++ b/src/database/main.ts @@ -53,7 +53,6 @@ export class Database extends Macroable { * A store of global transactions */ connectionGlobalTransactions: Map = new Map() - hasHealthChecksEnabled = false prettyPrint = prettyPrint constructor( @@ -66,23 +65,6 @@ export class Database extends Macroable { this.primaryConnectionName = this.config.connection this.registerConnections() - this.findIfHealthChecksAreEnabled() - } - - /** - * Compute whether health check is enabled or not after registering the connections. - * There are chances that all pre-registered connections are not using health - * checks but a dynamic connection is using it. We don't support that use case - * for now, since it complicates things a lot and forces us to register the - * health checker on demand. - */ - private findIfHealthChecksAreEnabled() { - for (let [, conn] of this.manager.connections) { - if (conn.config.healthCheck) { - this.hasHealthChecksEnabled = true - break - } - } } /** @@ -254,13 +236,6 @@ export class Database extends Macroable { : client.transaction(callbackOrOptions) } - /** - * Invokes `manager.report` - */ - report() { - return this.manager.report() - } - /** * Begin a new global transaction */ diff --git a/src/types/database.ts b/src/types/database.ts index 7faf184d..8fd837bf 100644 --- a/src/types/database.ts +++ b/src/types/database.ts @@ -12,15 +12,16 @@ import type { Pool } from 'tarn' import type { EventEmitter } from 'node:events' import type { ConnectionOptions } from 'node:tls' import type { Emitter } from '@adonisjs/core/events' +import type { HealthCheckResult } from '@adonisjs/core/types/health' import { LucidModel, ModelQueryBuilderContract } from './model.js' import { - DatabaseQueryBuilderContract, FromTable, - InsertQueryBuilderContract, - RawBuilderContract, RawQueryBindings, + RawBuilderContract, RawQueryBuilderContract, ReferenceBuilderContract, + InsertQueryBuilderContract, + DatabaseQueryBuilderContract, } from './querybuilder.js' /** @@ -309,15 +310,6 @@ type SharedConnectionNode = { port?: number } -/** - * Shape of the report node for the database connection report - */ -export type ReportNode = { - connection: string - message: string - error: any -} - /** * Migrations config */ @@ -344,7 +336,6 @@ export type SharedConfigNode = { debug?: boolean asyncStackTraces?: boolean revision?: number - healthCheck?: boolean migrations?: MigratorConfig seeders?: SeedersConfig wipe?: { ignoreTables?: string[] } @@ -638,11 +629,6 @@ export interface ConnectionManagerContract { * re-add it using the `add` method */ release(connectionName: string): Promise - - /** - * Returns the health check report for registered connections - */ - report(): Promise } /** @@ -712,7 +698,7 @@ export interface ConnectionContract extends EventEmitter { /** * Returns the connection report */ - getReport(): Promise + getReport(): Promise } /** diff --git a/test/orm/base_model.spec.ts b/test/orm/base_model.spec.ts index 5079910e..1feddbbb 100644 --- a/test/orm/base_model.spec.ts +++ b/test/orm/base_model.spec.ts @@ -6029,7 +6029,7 @@ test.group('Base Model | date', (group) => { User.$adapter = adapter adapter.on('insert', (model: LucidRow, _: any) => { - assert.instanceOf((model as User).dob, DateTime) + assert.instanceOf((model as User).dob, DateTime as any) }) user.username = 'virk' @@ -6066,7 +6066,7 @@ test.group('Base Model | date', (group) => { User.$adapter = adapter adapter.on('insert', (model: LucidRow, _: any) => { - assert.instanceOf((model as User).dob, DateTime) + assert.instanceOf((model as User).dob, DateTime as any) assert.isUndefined((model as User).createdAt) }) @@ -6097,7 +6097,7 @@ test.group('Base Model | date', (group) => { const user = new User() User.$adapter = adapter adapter.on('update', (model: LucidRow) => { - assert.instanceOf((model as User).updatedAt, DateTime) + assert.instanceOf((model as User).updatedAt, DateTime as any) }) user.username = 'virk' @@ -6320,7 +6320,7 @@ test.group('Base Model | date', (group) => { await db.insertQuery().table('users').insert({ username: 'virk' }) const user = await User.find(1) - assert.instanceOf(user!.createdAt, DateTime) + assert.instanceOf(user!.createdAt, DateTime as any) }) test('ignore null or empty values during fetch', async ({ fs, assert }) => { @@ -6520,7 +6520,7 @@ test.group('Base Model | datetime', (group) => { const user = new User() user.username = 'virk' await user.save() - assert.instanceOf(user.joinedAt, DateTime) + assert.instanceOf(user.joinedAt, DateTime as any) const createdUser = await db.from('users').select('*').first() @@ -6688,7 +6688,7 @@ test.group('Base Model | datetime', (group) => { await db.insertQuery().table('users').insert({ username: 'virk' }) const user = await User.find(1) - assert.instanceOf(user!.createdAt, DateTime) + assert.instanceOf(user!.createdAt, DateTime as any) }) test('ignore null or empty values during fetch', async ({ fs, assert }) => {