Skip to content

Commit

Permalink
chore(mwcp): lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Mar 22, 2024
1 parent 3d8610e commit 9e766f3
Show file tree
Hide file tree
Showing 42 changed files with 110 additions and 78 deletions.
2 changes: 2 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,6 +23,7 @@ const srcRules = {
}],
}
const testRules = {
'@typescript-eslint/prefer-ts-expect-error': 0,
}

if (CI) {
Expand Down
1 change: 1 addition & 0 deletions packages/midway-component-kmore/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,6 @@ export class AutoConfiguration implements ILifeCycle {
})
this.logger.info(`[${ConfigKey.componentName}] onStop() done`)
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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<any>)
Expand All @@ -46,7 +46,7 @@ export interface TransactionalArgs<M extends MethodType | undefined = undefined>
/**
* @default undefined (no cache)
*/
cacheOptions: (Partial<CacheOptions<M>> & { op: 'Cacheable' | 'CacheEvict' | 'CachePut'}) | false | undefined
cacheOptions: (Partial<CacheOptions<M>> & { op: 'Cacheable' | 'CacheEvict' | 'CachePut' }) | false | undefined
}

export type Method = (...args: unknown[]) => Promise<unknown>
Expand All @@ -68,9 +68,7 @@ export interface TrxDecoratorExecutorOptions extends DecoratorExecutorParamBase<
}


export function genDecoratorExecutorOptions(
options: DecoratorExecutorParamBase<TransactionalArgs>,
): TrxDecoratorExecutorOptions {
export function genDecoratorExecutorOptions(options: DecoratorExecutorParamBase<TransactionalArgs>): TrxDecoratorExecutorOptions {

const {
decoratorKey,
Expand Down Expand Up @@ -115,9 +113,7 @@ export function genDecoratorExecutorOptions(
}


export async function transactionalDecoratorExecutor(
options: TrxDecoratorExecutorOptions,
): Promise<unknown> {
export async function transactionalDecoratorExecutor(options: TrxDecoratorExecutorOptions): Promise<unknown> {

const {
instanceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ export function Transactional<M extends MethodType | undefined = undefined>(
case 'Cacheable':
dkey = METHOD_KEY_Cacheable
break

case 'CacheEvict':
dkey = METHOD_KEY_CacheEvict
break

case 'CachePut':
dkey = METHOD_KEY_CachePut
break
Expand Down
17 changes: 7 additions & 10 deletions packages/midway-component-kmore/src/lib/db-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ export class DbManager<SourceName extends string = string, D = unknown, Ctx exte
return ret
}

protected async builderPropagating(
builder: KmoreQueryBuilder,
): ReturnType<CtxBuilderPreProcessor> {
protected async builderPropagating(builder: KmoreQueryBuilder): ReturnType<CtxBuilderPreProcessor> {

const { trxPropagateOptions } = builder
if (! trxPropagateOptions) {
Expand All @@ -103,9 +101,7 @@ export class DbManager<SourceName extends string = string, D = unknown, Ctx exte
return resp
}

protected async builderResultPreProcessor(
options: CtxBuilderResultPreProcessorOptions,
): ReturnType<CtxBuilderResultPreProcessor> {
protected async builderResultPreProcessor(options: CtxBuilderResultPreProcessorOptions): ReturnType<CtxBuilderResultPreProcessor> {

if (options.kmoreTrxId && options.trxPropagated && options.trxPropagateOptions) {
const { kmoreQueryId, rowLockLevel } = options
Expand All @@ -123,9 +119,7 @@ export class DbManager<SourceName extends string = string, D = unknown, Ctx exte
return options.response
}

protected async exceptionHandler(
options: CtxExceptionHandlerOptions,
): ReturnType<CtxExceptionHandler> {
protected async exceptionHandler(options: CtxExceptionHandlerOptions): ReturnType<CtxExceptionHandler> {

if (options.trxPropagated && options.trxPropagateOptions) {
const { kmoreQueryId, rowLockLevel } = options
Expand All @@ -142,7 +136,10 @@ export class DbManager<SourceName extends string = string, D = unknown, Ctx exte
// }
}

return Promise.reject(options.exception)
const ex = options.exception
return Promise.reject(ex instanceof Error
? ex
: new Error('[kmore-component] DbManager#exceptionHandler error:', { cause: ex }))
}

protected createProxy(db: Kmore, reqCtx: Ctx): Kmore<any, Ctx> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -19,8 +15,7 @@ import {
import { DbConfig } from './types.js'


export abstract class AbstractDbSourceManager
<SourceName extends string = string, D = unknown, Ctx extends Context = Context>
export abstract class AbstractDbSourceManager<SourceName extends string = string, D = unknown, Ctx extends Context = Context>
extends DataSourceManager<Kmore | undefined> {

// kmoreQueryId => QuerySpanInfo
Expand All @@ -37,7 +32,7 @@ export abstract class AbstractDbSourceManager
config: DbConfig<D, Ctx>,
clientName: SourceName,
options?: CreateInstanceOptions,
) => Promise<Kmore<Db, Ctx> | void>
) => Promise<Kmore<Db, Ctx> | undefined>


abstract getDbConfigByDbId(dbId: SourceName): DbConfig | undefined
Expand Down
12 changes: 5 additions & 7 deletions packages/midway-component-kmore/src/lib/db-source-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ export class DbSourceManager<SourceName extends string = string, D = unknown, Ct
): Promise<Kmore | undefined> {

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<unknown> = {
Expand Down Expand Up @@ -185,10 +185,8 @@ export class DbSourceManager<SourceName extends string = string, D = unknown, Ct
this.dataSource.delete(dataSource.dbId)
}
catch (ex: unknown) {
this.logger.error(
`Destroy knex connection failed with identifier: "${dataSource.instanceId.toString()}" :
\n${(ex as Error).message}`,
)
this.logger.error(`Destroy knex connection failed with identifier: "${dataSource.instanceId.toString()}" :
\n${(ex as Error).message}`)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export abstract class TrxStatusServiceBase {

abstract startNewTrx(db: Kmore, callerKey: CallerKey): Promise<KmoreTransaction>

abstract getPropagationOptions(key: CallerKey): RegisterTrxPropagateOptions| undefined
abstract getPropagationOptions(key: CallerKey): RegisterTrxPropagateOptions | undefined

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {


export enum BuilderKeys {
'transacting' = 'transacting',
transacting = 'transacting',
transaction = 'transaction',
_ctxBuilderPreProcessor = '_ctxBuilderPreProcessor',
}
Expand Down
12 changes: 3 additions & 9 deletions packages/midway-component-kmore/src/lib/tracer-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion packages/midway-component-kmore/test/cache/70.cache.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

Expand Down
Original file line number Diff line number Diff line change
@@ -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), () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -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), () => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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), () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -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), () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -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), () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
Loading

0 comments on commit 9e766f3

Please sign in to comment.