From 9e766f39fa9ae846164ba57fa111f975b68faa5e Mon Sep 17 00:00:00 2001 From: waiting <1661926154@qq.com> Date: Fri, 22 Mar 2024 21:42:56 +0800 Subject: [PATCH] chore(mwcp): lint fix --- eslint.config.mjs | 2 ++ .../src/configuration.ts | 1 + .../src/decorator/decorator.helper.ts | 14 ++++----- .../src/decorator/index.decorator.ts | 2 ++ .../src/lib/db-manager.ts | 17 +++++------ .../src/lib/db-source-manager-base.ts | 11 ++----- .../src/lib/db-source-manager.ts | 12 ++++---- .../src/lib/propagation/trx-status.base.ts | 2 +- .../src/lib/proxy/db-manager.knex.ts | 4 +-- .../src/lib/proxy/db-manager.ref.ts | 7 +++-- .../src/lib/proxy/db-manager.types.ts | 2 +- .../src/lib/tracer-helper.ts | 12 ++------ .../test/cache/70.cache.test.ts | 3 +- .../test/cache/71.ext-cache.test.ts | 3 +- .../test/cache/transacional.helper.ts | 4 ++- .../test/decorator/60.transacional.test.ts | 2 +- .../test/decorator/61.transacional.test.ts | 3 +- .../decorator/62.transacional-class.test.ts | 3 +- .../test/decorator/63.args.test.ts | 3 +- .../decorator/64.propagate.supports.test.ts | 3 +- .../test/decorator/65.deep.test.ts | 3 +- .../test/decorator/66.deep.test.ts | 3 +- .../test/decorator/67.cross.test.ts | 3 +- .../test/decorator/transacional.helper.ts | 4 ++- .../fixtures/base-app/src/10.user-auto-ctx.ts | 1 + .../fixtures/base-app/src/cache/70.helper.ts | 2 ++ .../base-app/src/cache/70c.cache.repo.ts | 1 + .../base-app/src/cache/70d.cache.repo.ts | 1 + .../src/cache/71b.ext-cache.service.ts | 9 +++--- .../base-app/src/cache/71c.ext-cache.repo.ts | 1 + .../61a.method-decorator.controller.ts | 1 + .../61a.method-decorator.service.ts | 1 + .../62a.class-decorator.controller.ts | 1 + .../62a.class-decorator.service.ts | 1 + .../src/transactional/64a.supports.service.ts | 1 + .../src/transactional/65c.deep.repo.ts | 1 + .../src/transactional/67c.cross.repo.ts | 1 + .../src/transactional/67d.cross.repo.ts | 1 + .../fixtures/base-app/src/user-manaul-ctx.ts | 1 + .../midway-component-kmore/test/helper.ts | 30 ++++++++++++------- packages/midway-component-kmore/test/setup.ts | 3 +- .../midway-component-kmore/test/test.model.ts | 8 +++++ 42 files changed, 110 insertions(+), 78 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index a70842da7..d96213dc2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -11,6 +11,7 @@ const CI = !! ((process.env['CI'] ) const srcRules = { + '@typescript-eslint/prefer-ts-expect-error': 0, 'import/no-extraneous-dependencies': [2, { devDependencies: false, optionalDependencies: false, @@ -22,6 +23,7 @@ const srcRules = { }], } const testRules = { + '@typescript-eslint/prefer-ts-expect-error': 0, } if (CI) { diff --git a/packages/midway-component-kmore/src/configuration.ts b/packages/midway-component-kmore/src/configuration.ts index 069d11095..1e8737ebe 100644 --- a/packages/midway-component-kmore/src/configuration.ts +++ b/packages/midway-component-kmore/src/configuration.ts @@ -119,5 +119,6 @@ export class AutoConfiguration implements ILifeCycle { }) this.logger.info(`[${ConfigKey.componentName}] onStop() done`) } + } diff --git a/packages/midway-component-kmore/src/decorator/decorator.helper.ts b/packages/midway-component-kmore/src/decorator/decorator.helper.ts index 89d5fdde7..3a483c6b2 100644 --- a/packages/midway-component-kmore/src/decorator/decorator.helper.ts +++ b/packages/midway-component-kmore/src/decorator/decorator.helper.ts @@ -23,8 +23,8 @@ import { ConfigKey, KmorePropagationConfig, Msg, TransactionalOptions } from '## export const TRX_CLASS_KEY = 'decorator:kmore_trxnal_class_decorator_key' export const METHOD_KEY_Transactional = 'decorator:kmore_trxnal_decorator_key' -export const classDecoratorKeyMap = new Map([ [TRX_CLASS_KEY, 'Transactional'] ]) -export const methodDecoratorKeyMap = new Map([ [METHOD_KEY_Transactional, 'Transactional'] ]) +export const classDecoratorKeyMap = new Map([[TRX_CLASS_KEY, 'Transactional']]) +export const methodDecoratorKeyMap = new Map([[METHOD_KEY_Transactional, 'Transactional']]) // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-redundant-type-constituents export type MethodType = (...input: any[]) => (any | Promise) @@ -46,7 +46,7 @@ export interface TransactionalArgs /** * @default undefined (no cache) */ - cacheOptions: (Partial> & { op: 'Cacheable' | 'CacheEvict' | 'CachePut'}) | false | undefined + cacheOptions: (Partial> & { op: 'Cacheable' | 'CacheEvict' | 'CachePut' }) | false | undefined } export type Method = (...args: unknown[]) => Promise @@ -68,9 +68,7 @@ export interface TrxDecoratorExecutorOptions extends DecoratorExecutorParamBase< } -export function genDecoratorExecutorOptions( - options: DecoratorExecutorParamBase, -): TrxDecoratorExecutorOptions { +export function genDecoratorExecutorOptions(options: DecoratorExecutorParamBase): TrxDecoratorExecutorOptions { const { decoratorKey, @@ -115,9 +113,7 @@ export function genDecoratorExecutorOptions( } -export async function transactionalDecoratorExecutor( - options: TrxDecoratorExecutorOptions, -): Promise { +export async function transactionalDecoratorExecutor(options: TrxDecoratorExecutorOptions): Promise { const { instanceName, diff --git a/packages/midway-component-kmore/src/decorator/index.decorator.ts b/packages/midway-component-kmore/src/decorator/index.decorator.ts index ed4203195..5d4ec4569 100644 --- a/packages/midway-component-kmore/src/decorator/index.decorator.ts +++ b/packages/midway-component-kmore/src/decorator/index.decorator.ts @@ -77,9 +77,11 @@ export function Transactional( case 'Cacheable': dkey = METHOD_KEY_Cacheable break + case 'CacheEvict': dkey = METHOD_KEY_CacheEvict break + case 'CachePut': dkey = METHOD_KEY_CachePut break diff --git a/packages/midway-component-kmore/src/lib/db-manager.ts b/packages/midway-component-kmore/src/lib/db-manager.ts index 9454edd41..dcf30f19a 100644 --- a/packages/midway-component-kmore/src/lib/db-manager.ts +++ b/packages/midway-component-kmore/src/lib/db-manager.ts @@ -85,9 +85,7 @@ export class DbManager { + protected async builderPropagating(builder: KmoreQueryBuilder): ReturnType { const { trxPropagateOptions } = builder if (! trxPropagateOptions) { @@ -103,9 +101,7 @@ export class DbManager { + protected async builderResultPreProcessor(options: CtxBuilderResultPreProcessorOptions): ReturnType { if (options.kmoreTrxId && options.trxPropagated && options.trxPropagateOptions) { const { kmoreQueryId, rowLockLevel } = options @@ -123,9 +119,7 @@ export class DbManager { + protected async exceptionHandler(options: CtxExceptionHandlerOptions): ReturnType { if (options.trxPropagated && options.trxPropagateOptions) { const { kmoreQueryId, rowLockLevel } = options @@ -142,7 +136,10 @@ export class DbManager { diff --git a/packages/midway-component-kmore/src/lib/db-source-manager-base.ts b/packages/midway-component-kmore/src/lib/db-source-manager-base.ts index 075e1097b..93bf82c49 100644 --- a/packages/midway-component-kmore/src/lib/db-source-manager-base.ts +++ b/packages/midway-component-kmore/src/lib/db-source-manager-base.ts @@ -1,9 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { - DataSourceManager, - Config as _Config, - Logger as _Logger, -} from '@midwayjs/core' +import { DataSourceManager } from '@midwayjs/core' import { Attributes, Span, @@ -19,8 +15,7 @@ import { import { DbConfig } from './types.js' -export abstract class AbstractDbSourceManager - +export abstract class AbstractDbSourceManager extends DataSourceManager { // kmoreQueryId => QuerySpanInfo @@ -37,7 +32,7 @@ export abstract class AbstractDbSourceManager config: DbConfig, clientName: SourceName, options?: CreateInstanceOptions, - ) => Promise | void> + ) => Promise | undefined> abstract getDbConfigByDbId(dbId: SourceName): DbConfig | undefined diff --git a/packages/midway-component-kmore/src/lib/db-source-manager.ts b/packages/midway-component-kmore/src/lib/db-source-manager.ts index 2bec86898..bf839d8c0 100644 --- a/packages/midway-component-kmore/src/lib/db-source-manager.ts +++ b/packages/midway-component-kmore/src/lib/db-source-manager.ts @@ -122,9 +122,9 @@ export class DbSourceManager { const globalEventCbs: EventCallbacks = { - start: (event: KmoreEvent, ctx?: Ctx) => this.cbOnStart(config, event, ctx), - query: (event: KmoreEvent, ctx?: Ctx) => this.cbOnQuery(config, event, ctx), - queryResponse: (event: KmoreEvent, ctx?: Ctx) => this.cbOnResp(config, event, ctx), + start: (event: KmoreEvent, ctx?: Ctx) => { this.cbOnStart(config, event, ctx) }, + query: (event: KmoreEvent, ctx?: Ctx) => { this.cbOnQuery(config, event, ctx) }, + queryResponse: (event: KmoreEvent, ctx?: Ctx) => { this.cbOnResp(config, event, ctx) }, queryError: (event: KmoreEvent, ctx?: Ctx) => this.cbOnError(config, event, ctx), } const opts: KmoreFactoryOpts = { @@ -185,10 +185,8 @@ export class DbSourceManager - abstract getPropagationOptions(key: CallerKey): RegisterTrxPropagateOptions| undefined + abstract getPropagationOptions(key: CallerKey): RegisterTrxPropagateOptions | undefined } diff --git a/packages/midway-component-kmore/src/lib/proxy/db-manager.knex.ts b/packages/midway-component-kmore/src/lib/proxy/db-manager.knex.ts index 09ed8206d..01e162c0b 100644 --- a/packages/midway-component-kmore/src/lib/proxy/db-manager.knex.ts +++ b/packages/midway-component-kmore/src/lib/proxy/db-manager.knex.ts @@ -46,9 +46,7 @@ export function proxyKnex(options: ProxyKnexOptions): ProxyKnexOptions['targetPr interface ProxyOptionsKnexTransaction extends ProxyKnexOptions { targetProperty: Kmore['transaction'] } -function knexTransactionTracing( - options: ProxyOptionsKnexTransaction, -): ProxyOptionsKnexTransaction['targetProperty'] { +function knexTransactionTracing(options: ProxyOptionsKnexTransaction): ProxyOptionsKnexTransaction['targetProperty'] { const { dbSourceManager, traceSvc, targetProperty } = options assert(typeof targetProperty === 'function', 'targetProperty is not a function transaction()') diff --git a/packages/midway-component-kmore/src/lib/proxy/db-manager.ref.ts b/packages/midway-component-kmore/src/lib/proxy/db-manager.ref.ts index 8cf76f3dc..43061daaf 100644 --- a/packages/midway-component-kmore/src/lib/proxy/db-manager.ref.ts +++ b/packages/midway-component-kmore/src/lib/proxy/db-manager.ref.ts @@ -130,7 +130,10 @@ function proxyRefTableFn( const globalExceptionHandler: CtxExceptionHandler = async (options2: CtxExceptionHandlerOptions) => { - let pm = Promise.reject(options2.exception) + const { exception } = options2 + let pm = Promise.reject(exception instanceof Error + ? exception + : new Error('[kmore-component] globalExceptionHandler error:', { cause: exception })) if (ctxExceptionHandler) { pm = pm.catch(ex => ctxExceptionHandler({ ...options2, exception: ex })) } @@ -210,7 +213,7 @@ function transacting(key: string, options: ProxyBuilderOptions): KmoreQueryBuild assert(trx, 'trx is empty when calling builder.transacting()') assert(trx.kmoreTrxId, 'trx.kmoreTrxId is empty when calling builder.transacting(). May calling db.dbh.transaction(), use db.transaction() instead') - const builder = Reflect.apply(target, thisBinding, args) as KmoreQueryBuilder + const builder = Reflect.apply(target, thisBinding, args) const querySpanInfo = dbSourceManager.trxSpanMap.get(trx.kmoreTrxId) if (querySpanInfo) { diff --git a/packages/midway-component-kmore/src/lib/proxy/db-manager.types.ts b/packages/midway-component-kmore/src/lib/proxy/db-manager.types.ts index e37bf67ce..3dc006412 100644 --- a/packages/midway-component-kmore/src/lib/proxy/db-manager.types.ts +++ b/packages/midway-component-kmore/src/lib/proxy/db-manager.types.ts @@ -7,7 +7,7 @@ import { export enum BuilderKeys { - 'transacting' = 'transacting', + transacting = 'transacting', transaction = 'transaction', _ctxBuilderPreProcessor = '_ctxBuilderPreProcessor', } diff --git a/packages/midway-component-kmore/src/lib/tracer-helper.ts b/packages/midway-component-kmore/src/lib/tracer-helper.ts index 670906c77..86c23d4fa 100644 --- a/packages/midway-component-kmore/src/lib/tracer-helper.ts +++ b/packages/midway-component-kmore/src/lib/tracer-helper.ts @@ -30,9 +30,7 @@ export interface TraceStartEventOptions extends TraceEventOptions { span: Span } -export function traceStartEvent( - options: TraceStartEventOptions, -): void { +export function traceStartEvent(options: TraceStartEventOptions): void { const { dbConfig, @@ -58,9 +56,7 @@ export function traceStartEvent( queryUidSpanMap.set(ev.kmoreQueryId, spanInfo) } -export function TraceQueryEvent( - options: TraceEventOptions, -): void { +export function TraceQueryEvent(options: TraceEventOptions): void { const { dbConfig, traceSvc, queryUidSpanMap } = options if (! dbConfig.traceEvent) { return } @@ -112,9 +108,7 @@ export function TraceQueryEvent( .catch(console.error) } -export function TraceQueryRespEvent( - options: TraceEventOptions, -): void { +export function TraceQueryRespEvent(options: TraceEventOptions): void { const { dbConfig, traceSvc, queryUidSpanMap } = options if (! dbConfig.traceEvent) { return } diff --git a/packages/midway-component-kmore/test/cache/70.cache.test.ts b/packages/midway-component-kmore/test/cache/70.cache.test.ts index 13c1b2866..2e1bda6e8 100644 --- a/packages/midway-component-kmore/test/cache/70.cache.test.ts +++ b/packages/midway-component-kmore/test/cache/70.cache.test.ts @@ -1,11 +1,12 @@ import { fileShortPath } from '@waiting/shared-core' -import { validateRespOK } from './transacional.helper.js' import { apiPrefix, apiRoute } from '#@/fixtures/base-app/src/api-route.js' import { initDb } from '#@/helper.js' import { testConfig } from '#@/root.config.js' +import { validateRespOK } from './transacional.helper.js' + describe(fileShortPath(import.meta.url), () => { beforeEach(async () => { diff --git a/packages/midway-component-kmore/test/cache/71.ext-cache.test.ts b/packages/midway-component-kmore/test/cache/71.ext-cache.test.ts index 9413e22eb..e0f139609 100644 --- a/packages/midway-component-kmore/test/cache/71.ext-cache.test.ts +++ b/packages/midway-component-kmore/test/cache/71.ext-cache.test.ts @@ -1,11 +1,12 @@ import { fileShortPath } from '@waiting/shared-core' -import { validateRespOK } from './transacional.helper.js' import { apiPrefix, apiRoute } from '#@/fixtures/base-app/src/api-route.js' import { initDb } from '#@/helper.js' import { testConfig } from '#@/root.config.js' +import { validateRespOK } from './transacional.helper.js' + describe(fileShortPath(import.meta.url), () => { beforeEach(async () => { diff --git a/packages/midway-component-kmore/test/cache/transacional.helper.ts b/packages/midway-component-kmore/test/cache/transacional.helper.ts index a8cb301d1..d841cc858 100644 --- a/packages/midway-component-kmore/test/cache/transacional.helper.ts +++ b/packages/midway-component-kmore/test/cache/transacional.helper.ts @@ -1,8 +1,10 @@ import assert from 'node:assert/strict' -export function validateRespOK(resp: any): void { +export function validateRespOK(resp: unknown): void { assert(resp) + // @ts-expect-error assert(typeof resp.text === 'string') + // @ts-expect-error assert(resp.text === 'OK') } diff --git a/packages/midway-component-kmore/test/decorator/60.transacional.test.ts b/packages/midway-component-kmore/test/decorator/60.transacional.test.ts index 749fe801d..1280bb369 100644 --- a/packages/midway-component-kmore/test/decorator/60.transacional.test.ts +++ b/packages/midway-component-kmore/test/decorator/60.transacional.test.ts @@ -19,7 +19,7 @@ describe(fileShortPath(import.meta.url), () => { .expect(200) assert(resp) - const data = resp.text as string + const data = resp.text assert(data === 'OK') }) diff --git a/packages/midway-component-kmore/test/decorator/61.transacional.test.ts b/packages/midway-component-kmore/test/decorator/61.transacional.test.ts index 743355b1c..3d90eda5d 100644 --- a/packages/midway-component-kmore/test/decorator/61.transacional.test.ts +++ b/packages/midway-component-kmore/test/decorator/61.transacional.test.ts @@ -1,11 +1,12 @@ import { fileShortPath } from '@waiting/shared-core' -import { validateRespOK } from './transacional.helper.js' import { apiPrefix, apiRoute } from '#@/fixtures/base-app/src/api-route.js' import { initDb } from '#@/helper.js' import { testConfig } from '#@/root.config.js' +import { validateRespOK } from './transacional.helper.js' + describe(fileShortPath(import.meta.url), () => { diff --git a/packages/midway-component-kmore/test/decorator/62.transacional-class.test.ts b/packages/midway-component-kmore/test/decorator/62.transacional-class.test.ts index dee2511d5..390dc2441 100644 --- a/packages/midway-component-kmore/test/decorator/62.transacional-class.test.ts +++ b/packages/midway-component-kmore/test/decorator/62.transacional-class.test.ts @@ -1,11 +1,12 @@ import { fileShortPath } from '@waiting/shared-core' -import { validateRespOK } from './transacional.helper.js' import { apiPrefix, apiRoute } from '#@/fixtures/base-app/src/api-route.js' import { initDb } from '#@/helper.js' import { testConfig } from '#@/root.config.js' +import { validateRespOK } from './transacional.helper.js' + describe(fileShortPath(import.meta.url), () => { diff --git a/packages/midway-component-kmore/test/decorator/63.args.test.ts b/packages/midway-component-kmore/test/decorator/63.args.test.ts index f19dc3db8..e425520ae 100644 --- a/packages/midway-component-kmore/test/decorator/63.args.test.ts +++ b/packages/midway-component-kmore/test/decorator/63.args.test.ts @@ -2,11 +2,12 @@ import assert from 'node:assert/strict' import { fileShortPath } from '@waiting/shared-core' -import { validateRespOK } from './transacional.helper.js' import { apiPrefix, apiRoute } from '#@/fixtures/base-app/src/api-route.js' import { testConfig } from '#@/root.config.js' +import { validateRespOK } from './transacional.helper.js' + describe(fileShortPath(import.meta.url), () => { diff --git a/packages/midway-component-kmore/test/decorator/64.propagate.supports.test.ts b/packages/midway-component-kmore/test/decorator/64.propagate.supports.test.ts index 9457367f4..061b333a7 100644 --- a/packages/midway-component-kmore/test/decorator/64.propagate.supports.test.ts +++ b/packages/midway-component-kmore/test/decorator/64.propagate.supports.test.ts @@ -1,10 +1,11 @@ import { fileShortPath } from '@waiting/shared-core' -import { validateRespOK } from './transacional.helper.js' import { apiPrefix, apiRoute } from '#@/fixtures/base-app/src/api-route.js' import { testConfig } from '#@/root.config.js' +import { validateRespOK } from './transacional.helper.js' + describe(fileShortPath(import.meta.url), () => { diff --git a/packages/midway-component-kmore/test/decorator/65.deep.test.ts b/packages/midway-component-kmore/test/decorator/65.deep.test.ts index f76e208db..6776c73d2 100644 --- a/packages/midway-component-kmore/test/decorator/65.deep.test.ts +++ b/packages/midway-component-kmore/test/decorator/65.deep.test.ts @@ -1,11 +1,12 @@ import { fileShortPath } from '@waiting/shared-core' -import { validateRespOK } from './transacional.helper.js' import { apiPrefix, apiRoute } from '#@/fixtures/base-app/src/api-route.js' import { initDb } from '#@/helper.js' import { testConfig } from '#@/root.config.js' +import { validateRespOK } from './transacional.helper.js' + describe(fileShortPath(import.meta.url), () => { diff --git a/packages/midway-component-kmore/test/decorator/66.deep.test.ts b/packages/midway-component-kmore/test/decorator/66.deep.test.ts index 58f70eda9..3bc17c76c 100644 --- a/packages/midway-component-kmore/test/decorator/66.deep.test.ts +++ b/packages/midway-component-kmore/test/decorator/66.deep.test.ts @@ -1,11 +1,12 @@ import { fileShortPath } from '@waiting/shared-core' -import { validateRespOK } from './transacional.helper.js' import { apiPrefix, apiRoute } from '#@/fixtures/base-app/src/api-route.js' import { initDb } from '#@/helper.js' import { testConfig } from '#@/root.config.js' +import { validateRespOK } from './transacional.helper.js' + describe(fileShortPath(import.meta.url), () => { beforeEach(async () => { diff --git a/packages/midway-component-kmore/test/decorator/67.cross.test.ts b/packages/midway-component-kmore/test/decorator/67.cross.test.ts index 88615715e..8929ffb28 100644 --- a/packages/midway-component-kmore/test/decorator/67.cross.test.ts +++ b/packages/midway-component-kmore/test/decorator/67.cross.test.ts @@ -1,11 +1,12 @@ import { fileShortPath } from '@waiting/shared-core' -import { validateRespOK } from './transacional.helper.js' import { apiPrefix, apiRoute } from '#@/fixtures/base-app/src/api-route.js' import { initDb } from '#@/helper.js' import { testConfig } from '#@/root.config.js' +import { validateRespOK } from './transacional.helper.js' + describe(fileShortPath(import.meta.url), () => { beforeEach(async () => { diff --git a/packages/midway-component-kmore/test/decorator/transacional.helper.ts b/packages/midway-component-kmore/test/decorator/transacional.helper.ts index a8cb301d1..d841cc858 100644 --- a/packages/midway-component-kmore/test/decorator/transacional.helper.ts +++ b/packages/midway-component-kmore/test/decorator/transacional.helper.ts @@ -1,8 +1,10 @@ import assert from 'node:assert/strict' -export function validateRespOK(resp: any): void { +export function validateRespOK(resp: unknown): void { assert(resp) + // @ts-expect-error assert(typeof resp.text === 'string') + // @ts-expect-error assert(resp.text === 'OK') } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/10.user-auto-ctx.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/10.user-auto-ctx.ts index 155d742a4..ac1853a38 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/10.user-auto-ctx.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/10.user-auto-ctx.ts @@ -62,6 +62,7 @@ export class UserController { const user = await ref_tb_user() .select('fake') + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return user } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70.helper.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70.helper.ts index 945ad6cf3..020d1d137 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70.helper.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70.helper.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ import assert from 'node:assert' import { diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70c.cache.repo.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70c.cache.repo.ts index 8b3e2abf1..013992956 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70c.cache.repo.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70c.cache.repo.ts @@ -181,5 +181,6 @@ export class UserRepo6 { assert(kmoreTrxId, 'kmoreTrxId not found') return kmoreTrxId } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70d.cache.repo.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70d.cache.repo.ts index f9fe26b1f..8d8d934f8 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70d.cache.repo.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/70d.cache.repo.ts @@ -159,5 +159,6 @@ export class UserRepo7 { assert(kmoreTrxId, 'kmoreTrxId not found') return kmoreTrxId } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/71b.ext-cache.service.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/71b.ext-cache.service.ts index e31f4bc46..5fb8e89df 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/71b.ext-cache.service.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/71b.ext-cache.service.ts @@ -24,14 +24,14 @@ export class UserService { const ret = await this.repo8.getUserByUidWithCacheableAfter(uid) const [user] = ret - assert(user && user.uid) + assert(user?.uid) // @ts-ignore assert(! ret[CacheConfigKey.CacheMetaType]) const cacheKey = `${this.repo8.name}.getUserByUidWithCacheableAfter:${uid}` const ret2 = await this.repo8.getUserByUidWithCacheableAfter(uid) const [user2] = ret2 - assert(user2 && user2.uid) + assert(user2?.uid) validateMeta(ret2, cacheKey, initCacheManagerOptions.options.ttl) } @@ -40,14 +40,14 @@ export class UserService { const ret = await this.repo8.getUserByUidWithCacheableBefore(uid) const [user] = ret - assert(user && user.uid) + assert(user?.uid) // @ts-ignore assert(! user[CacheConfigKey.CacheMetaType]) const cacheKey = `${this.repo8.name}.getUserByUidWithCacheableBefore:${uid}` const ret2 = await this.repo8.getUserByUidWithCacheableBefore(uid) const [user2] = ret2 - assert(user2 && user2.uid) + assert(user2?.uid) validateMeta(ret2, cacheKey, initCacheManagerOptions.options.ttl) const ret3 = await this.repo8.getUserByUidWithCacheableBefore(uid) @@ -55,5 +55,6 @@ export class UserService { assert(user3 && user2.uid) validateMeta(ret3, cacheKey, initCacheManagerOptions.options.ttl) } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/71c.ext-cache.repo.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/71c.ext-cache.repo.ts index 5754d243a..a41367562 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/cache/71c.ext-cache.repo.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/cache/71c.ext-cache.repo.ts @@ -144,5 +144,6 @@ export class UserRepo8 { assert(kmoreTrxId, 'kmoreTrxId not found') return kmoreTrxId } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/61a.method-decorator.controller.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/61a.method-decorator.controller.ts index e8edbe852..4e79ab45f 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/61a.method-decorator.controller.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/61a.method-decorator.controller.ts @@ -156,5 +156,6 @@ export class TrxDecoratorController { return 'OK' } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/61a.method-decorator.service.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/61a.method-decorator.service.ts index 41f971c63..0a4f02d01 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/61a.method-decorator.service.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/61a.method-decorator.service.ts @@ -456,5 +456,6 @@ export class UserService { assert(kmoreTrxId, 'kmoreTrxId not found') return kmoreTrxId } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/62a.class-decorator.controller.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/62a.class-decorator.controller.ts index 1ba04b119..a21371ae5 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/62a.class-decorator.controller.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/62a.class-decorator.controller.ts @@ -147,5 +147,6 @@ export class ClassDecoratorController { return 'OK' } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/62a.class-decorator.service.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/62a.class-decorator.service.ts index 5ee9db941..cd22f3c84 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/62a.class-decorator.service.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/62a.class-decorator.service.ts @@ -380,5 +380,6 @@ export class UserService2 { assert(kmoreTrxId, 'kmoreTrxId not found') return kmoreTrxId } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/64a.supports.service.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/64a.supports.service.ts index fa1e5fa15..19c8074d3 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/64a.supports.service.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/64a.supports.service.ts @@ -113,6 +113,7 @@ export class PropagationOverrideService { } return trx?.kmoreTrxId } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/65c.deep.repo.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/65c.deep.repo.ts index ad4bda0e6..7f12e8191 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/65c.deep.repo.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/65c.deep.repo.ts @@ -380,5 +380,6 @@ export class UserRepo3 { assert(kmoreTrxId, 'kmoreTrxId not found') return kmoreTrxId } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/67c.cross.repo.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/67c.cross.repo.ts index 4eedede9e..8a88f3405 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/67c.cross.repo.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/67c.cross.repo.ts @@ -159,5 +159,6 @@ export class UserRepo4 { assert(kmoreTrxId, 'kmoreTrxId not found') return kmoreTrxId } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/67d.cross.repo.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/67d.cross.repo.ts index 67efac9a9..e2f9d73a4 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/67d.cross.repo.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/transactional/67d.cross.repo.ts @@ -159,5 +159,6 @@ export class UserRepo5 { assert(kmoreTrxId, 'kmoreTrxId not found') return kmoreTrxId } + } diff --git a/packages/midway-component-kmore/test/fixtures/base-app/src/user-manaul-ctx.ts b/packages/midway-component-kmore/test/fixtures/base-app/src/user-manaul-ctx.ts index d76213e0c..7dbad4f30 100644 --- a/packages/midway-component-kmore/test/fixtures/base-app/src/user-manaul-ctx.ts +++ b/packages/midway-component-kmore/test/fixtures/base-app/src/user-manaul-ctx.ts @@ -60,6 +60,7 @@ export class User2Controller { const user = await ref_tb_user({ ctx: this.ctx }) .select('fake') + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return user } diff --git a/packages/midway-component-kmore/test/helper.ts b/packages/midway-component-kmore/test/helper.ts index 2eba6a671..d5a0af3e4 100644 --- a/packages/midway-component-kmore/test/helper.ts +++ b/packages/midway-component-kmore/test/helper.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ import assert from 'assert/strict' import { KmoreFactory, Kmore, getCurrentTime, EnumClient, KmoreFactoryOpts } from 'kmore' @@ -43,7 +45,7 @@ async function initTable(km: Kmore): Promise { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const time = await getCurrentTime(km.dbh, config.client) assert(time) - console.info(`CurrrentTime: ${time}`) + console.info(`CurrentTime: ${time}`) const { tables, scoped } = km.dict const { tb_user, tb_user_ext } = dict.columns @@ -58,7 +60,8 @@ async function initTable(km: Kmore): Promise { .createTable(tables.tb_user_ext, (tb) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison config.client === EnumClient.mysql || config.client === EnumClient.mysql2 - ? tb.integer(tb_user_ext.uid).unsigned().primary() + ? tb.integer(tb_user_ext.uid).unsigned() + .primary() : tb.integer(tb_user_ext.uid).primary() tb.foreign(tb_user_ext.uid) .references(scoped.tb_user.uid) // 'tb_user.uid' @@ -104,7 +107,7 @@ export function validateUserRows(rows: Partial[]): void { assert(Array.isArray(rows) && rows.length > 0) rows.forEach((row) => { - assert(row && row.uid) + assert(row?.uid) assert(typeof row.ctime === 'object') switch (row.uid) { @@ -112,18 +115,20 @@ export function validateUserRows(rows: Partial[]): void { assert(row.name === 'user1', JSON.stringify(row)) assert(row.real_name === 'rn1', JSON.stringify(row)) break + case 2: assert(row.name === 'user2', JSON.stringify(row)) assert(row.real_name === 'rn2', JSON.stringify(row)) break + case 3: assert(row.name === 'user3', JSON.stringify(row)) assert(row.real_name === 'rn3', JSON.stringify(row)) break + default: // eslint-disable-next-line @typescript-eslint/restrict-template-expressions assert(false, `Should row.uid be 1 or 2, but got ${row.uid}`) - break } }) } @@ -159,7 +164,7 @@ export function validateUserRowsDTO(rows: Partial[]): void { assert(Array.isArray(rows) && rows.length > 0) rows.forEach((row) => { - assert(row && row.uid) + assert(row?.uid) assert(typeof row.ctime === 'object') switch (row.uid) { @@ -167,18 +172,20 @@ export function validateUserRowsDTO(rows: Partial[]): void { assert(row.name === 'user1', JSON.stringify(row)) assert(row.realName === 'rn1', JSON.stringify(row)) break + case 2: assert(row.name === 'user2', JSON.stringify(row)) assert(row.realName === 'rn2', JSON.stringify(row)) break + case 3: assert(row.name === 'user3', JSON.stringify(row)) assert(row.realName === 'rn3', JSON.stringify(row)) break + default: // eslint-disable-next-line @typescript-eslint/restrict-template-expressions assert(false, `Should row.uid be 1 or 2, but got ${row.uid}`) - break } }) } @@ -203,7 +210,7 @@ async function initUserExt(km: Kmore): Promise { const countRes = await km.refTables.ref_tb_user_ext().count() assert( - countRes && countRes[0] && countRes[0]['count'] === '2', + countRes?.[0] && countRes[0]['count'] === '2', 'Should count be "2"', ) @@ -223,7 +230,7 @@ export function validateUserExtRows(rows: Partial[]): void { assert(Array.isArray(rows) && rows.length > 0) rows.forEach((row) => { - assert(row && row.uid) + assert(row?.uid) switch (row.uid) { case 1: @@ -231,22 +238,23 @@ export function validateUserExtRows(rows: Partial[]): void { assert(typeof row.salary === 'string', JSON.stringify(row)) assert(row.salary === '1000.1234', JSON.stringify(row)) break + case 2: assert(row.age === 10, JSON.stringify(row)) assert(typeof row.salary === 'string', JSON.stringify(row)) assert(row.salary === '1000.1200', JSON.stringify(row)) break + default: // eslint-disable-next-line @typescript-eslint/restrict-template-expressions assert(false, `Should row.uid be 1 or 2, but got ${row.uid}`) - break } }) } async function getTransactionIsolation(dbh: Knex): Promise { - return await dbh.raw('SHOW TRANSACTION ISOLATION LEVEL') + return dbh.raw('SHOW TRANSACTION ISOLATION LEVEL') .then((rows) => { return rows.rows[0] ? rows.rows[0].transaction_isolation : 'N/A' }) @@ -258,7 +266,7 @@ async function setTimeZone(dbh: Knex, zone: string): Promise { .then((rows) => { return rows.rows[0] ? rows.rows[0].transaction_isolation : 'N/A' }) - return await dbh.raw('SHOW TIME ZONE') + return dbh.raw('SHOW TIME ZONE') .then((rows) => { return rows.rows[0] ? rows.rows[0].TimeZone : 'N/A' }) diff --git a/packages/midway-component-kmore/test/setup.ts b/packages/midway-component-kmore/test/setup.ts index f3ee742fa..6def8328e 100644 --- a/packages/midway-component-kmore/test/setup.ts +++ b/packages/midway-component-kmore/test/setup.ts @@ -6,10 +6,11 @@ import { createApp, close, createHttpRequest } from '@midwayjs/mock' import { Application } from '@mwcp/share' import type { Suite } from 'mocha' +import { ConfigKey } from '##/index.js' + import { kmoreConfig } from './config.unittest.js' import { TestConfig, testConfig } from './root.config.js' -import { ConfigKey } from '##/index.js' const globalConfig = { diff --git a/packages/midway-component-kmore/test/test.model.ts b/packages/midway-component-kmore/test/test.model.ts index 71b43b751..9f6e69e40 100644 --- a/packages/midway-component-kmore/test/test.model.ts +++ b/packages/midway-component-kmore/test/test.model.ts @@ -2,28 +2,36 @@ import { RecordCamelKeys } from '@waiting/shared-types' export class Db { + tb_user: UserDO tb_user_ext: UserExtDO + } export class Db2 { + tb_user_ext: UserExtDO + } /** * @description User用户表字段定义 */ export class UserDO { + uid: number name: string real_name: string ctime: Date | 'now()' + } export class UserExtDO { + uid: number age: number address: string | number salary: string | number + }