Skip to content

Commit

Permalink
chore(mwcp): update codes
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jan 28, 2024
1 parent 32474e2 commit b655426
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {


export const kmoreConfig: Config = {
enableDefaultRoute: false,
dataSource: {},
default: {
...initDbConfig,
},
}


export const kmoreMiddlewareConfig: Readonly<Omit<MiddlewareConfig, 'match'>> = {
...initialMiddlewareConfig,
ignore: [],
Expand Down
4 changes: 4 additions & 0 deletions packages/midway-component-kmore/src/config/config.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { initDbConfig } from '##/lib/config.js'
import { Config } from '##/lib/index.js'


export const keys = 123456
export const koa = {
port: 7001,
}
export const kmoreConfig: Config = {
enableDefaultRoute: true,
dataSource: {},
Expand Down
4 changes: 4 additions & 0 deletions packages/midway-component-kmore/src/config/config.unittest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { initDbConfig } from '##/lib/config.js'
import { Config } from '##/lib/index.js'


export const keys = Date.now().toString()
export const koa = {
port: 7001,
}
export const kmoreConfig: Config = {
enableDefaultRoute: true,
dataSource: {},
Expand Down
27 changes: 19 additions & 8 deletions packages/midway-component-kmore/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import assert from 'node:assert'

import {
App,
Config,
Config as _Config,
Configuration,
MidwayEnvironmentService,
MidwayInformationService,
ILifeCycle,
ILogger,
Inject,
Logger,
MidwayDecoratorService,
MidwayEnvironmentService,
MidwayInformationService,
MidwayWebRouterService,
} from '@midwayjs/core'
import { CacheManager } from '@mwcp/cache'
import { TraceInit } from '@mwcp/otel'
Expand All @@ -20,11 +21,12 @@ import {
RegisterDecoratorHandlerParam,
registerDecoratorHandler,
registerMiddleware,
deleteRouter,
} from '@mwcp/share'
import { sleep } from '@waiting/shared-core'


import * as DefulatConfig from './config/config.default.js'
import * as DefaultConfig from './config/config.default.js'
import * as LocalConfig from './config/config.local.js'
import * as UnittestConfig from './config/config.unittest.js'
import {
Expand All @@ -34,15 +36,15 @@ import {
} from './decorator/decorator.helper.js'
import { useComponents } from './imports.js'
import { DbSourceManager } from './lib/db-source-manager.js'
import { ConfigKey, KmorePropagationConfig, KmoreSourceConfig } from './lib/index.js'
import { Config, ConfigKey, KmorePropagationConfig, KmoreSourceConfig } from './lib/index.js'
import { KmoreMiddleware } from './middleware/index.middleware.js'


@Configuration({
namespace: ConfigKey.namespace,
importConfigs: [
{
default: DefulatConfig,
default: DefaultConfig,
local: LocalConfig,
unittest: UnittestConfig,
},
Expand All @@ -55,18 +57,27 @@ export class AutoConfiguration implements ILifeCycle {

@Inject() protected readonly environmentService: MidwayEnvironmentService
@Inject() protected readonly informationService: MidwayInformationService
@Inject() protected readonly webRouterService: MidwayWebRouterService

@Logger() protected readonly logger: ILogger

@Config() readonly kmoreSourceConfig: KmoreSourceConfig
@_Config(ConfigKey.config) readonly config: Config
@_Config() readonly kmoreSourceConfig: KmoreSourceConfig

@Config(ConfigKey.propagationConfig) protected readonly propagationConfig: KmorePropagationConfig
@_Config(ConfigKey.propagationConfig) protected readonly propagationConfig: KmorePropagationConfig

@Inject() readonly dbSManager: DbSourceManager

@Inject() decoratorService: MidwayDecoratorService

@Inject() cacheManager: CacheManager

async onConfigLoad(): Promise<void> {
if (! this.config.enableDefaultRoute) {
await deleteRouter(`/_${ConfigKey.namespace}`, this.webRouterService)
}
}

@TraceInit({ namespace: ConfigKey.namespace })
async onReady(container: IMidwayContainer): Promise<void> {
void container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { sleep } from '@waiting/shared-core'
import { PropagationType } from 'kmore'

import { initTransactionalOptons } from '##/lib/config.js'
import { initTransactionalOptions } from '##/lib/config.js'
import { CallerKey, RegisterTrxPropagateOptions } from '##/lib/propagation/trx-status.base.js'
import { genCallerKey } from '##/lib/propagation/trx-status.helper.js'
import { TrxStatusService } from '##/lib/trx-status.service.js'
Expand Down Expand Up @@ -88,7 +88,7 @@ export function genDecoratorExecutorOptions(
const initArgs = {
propagationType: PropagationType.REQUIRED,
propagationOptions: {
...initTransactionalOptons,
...initTransactionalOptions,
},
cacheOptions: false,
}
Expand Down
13 changes: 5 additions & 8 deletions packages/midway-component-kmore/src/imports.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as info from '@midwayjs/info'
import * as koa from '@midwayjs/koa'
import * as swagger from '@midwayjs/swagger'
import * as cache from '@mwcp/cache'
Expand All @@ -13,14 +14,10 @@ const CI = !! (process.env['MIDWAY_SERVER_ENV'] === 'unittest'

export const useComponents: IComponentInfo[] = [otel]
if (CI) {
if ( ! useComponents.includes(koa)) {
useComponents.push(koa)
useComponents.push(info)
useComponents.push(cache)
}
if ( ! useComponents.includes(swagger)) {
useComponents.push(swagger)
}
useComponents.push(koa)
useComponents.push(info)
useComponents.push(cache)
useComponents.push(swagger)
}

export interface IComponentInfo {
Expand Down
4 changes: 2 additions & 2 deletions packages/midway-component-kmore/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const initDbConfig: DbConfig = {
traceResponse: true,
}

export const initTransactionalOptons: TransactionalOptions = {
export const initTransactionalOptions: TransactionalOptions = {
/**
* @default {@link RowLockLevel.ForShare}
*/
Expand All @@ -46,6 +46,6 @@ export const initPropagationConfig: PropagationConfig = {
* @default PropagationType.REQUIRED,
*/
propagationType: PropagationType.REQUIRED,
...initTransactionalOptons,
...initTransactionalOptions,
}

6 changes: 5 additions & 1 deletion packages/midway-component-kmore/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export enum Msg {

export interface Config<SourceName extends string = string>
extends BaseConfig, KmoreSourceConfig<SourceName> {
// void 0

/**
* @default false
*/
enableDefaultRoute: boolean
}

export interface MiddlewareOptions {
Expand Down
5 changes: 4 additions & 1 deletion packages/midway-component-kmore/test/config.unittest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EventCallbacks } from 'kmore'
import { genDbDict } from 'kmore-types'

import {
Config,
initialMiddlewareConfig,
initMiddlewareOptions,
MiddlewareConfig,
Expand All @@ -17,6 +18,7 @@ import {
import { Db } from '#@/test.model.js'



export const mwConfig: Readonly<Omit<MiddlewareConfig, 'match'>> = {
...initialMiddlewareConfig,
ignore: [], // !
Expand Down Expand Up @@ -62,7 +64,8 @@ export const master: DbConfig<Db> = {
eventCallbacks: eventCbs,
traceInitConnection: true,
}
export const kmoreConfig: KmoreSourceConfig<'master'> = {
export const kmoreConfig: Config<'master'> = {
enableDefaultRoute: true,
dataSource: {
master,
},
Expand Down
50 changes: 0 additions & 50 deletions packages/midway-component-kmore/test/root.hooks.ts

This file was deleted.

0 comments on commit b655426

Please sign in to comment.